oracle aduit,10g_audit

042audit

1)audit relative importment parameter and tables

SQL> conn /as sysdba

Connected.

SQL> show parameter o7

NAME                                 TYPE        VALUE

O7_DICTIONARY_ACCESSIBILITY          boolean     FALSE

#####the parameter is very importment for you oracle database,

#####if you set it true.user hr would select the tables of sys.

SQL> show parameter audit;

NAME                                 TYPE        VALUE

audit_file_dest                      string      /u01/app/oracle/admin/orcl/adump

audit_sys_operations                 boolean     FALSE

audit_syslog_level                   string

audit_trail                          string      NONE

SQL> alter system set audit_trail='db_extended' scope=spfile;

SQL> shutdown immediate;

SQL> startup

#####it must restart the database.

SQL> show parameter audit_trail

NAME                                 TYPE        VALUE

audit_trail                          string      DB_EXTENDED

#####all audit information in the following tables#################

select * from dict where table_name like '%AUDIT%OPTS'

select * from DBA_OBJ_AUDIT_OPTS;

select * from DBA_STMT_AUDIT_OPTS;

select * from DBA_FGA_AUDIT_TRAIL;

select * from DBA_COMMON_AUDIT_TRAIL;

select * from DBA_AUDIT_TRAIL;

###########################################################

2)audit file location

[oracle@station23 orcl]$ pwd

/u01/app/oracle/admin/orcl

[oracle@station23 orcl]$ ls

adump  bdump  cdump  dpdump  pfile  udump

[oracle@station23 orcl]$ cd adump/

[oracle@station23 adump]$ ls

ora_18302.aud  ora_3261.aud  ora_3519.aud  ora_6669.aud  ora_6868.aud

.......ignore

3)the audit how to work

SQL> !ps

PID TTY          TIME CMD

4192 pts/3    00:00:00 sqlplus

4194 pts/3    00:00:00 ps

select spid from v$session s, v$process p where s.paddr=p.addr and s.terminal='pts/3'

SPID

------------

4193

[oracle@station23 orcl]$ pwd

/u01/app/oracle/admin/orcl

[root@station60 adump]# ls *4193*

ora_4193.aud

[root@station60 adump]# cat *4193*

Audit file /u01/app/oracle/admin/orcl/adump/ora_4193.aud

......ignore

#####it is the file to trail the terminal and sqlplus.

#####the audit keep watch on process

4)write trigger to audit user register.

1@@@@create a tbsaudit tablespace,then create a table audit on it

SQL> conn /as sysdba;

Connected.

SQL> create tablespace tbsaudit datafile '/u01/app/oracle/oradata/orcl/tbsaudit.dbf' size 200M autoextend on maxsize 500M;

Tablespace created.

SQL> create table audit1(a varchar2(2000)) tablespace tbsaudit;

Table created.

2@@@@write trigger to register logined user.

###############################################

create or replace  trigger trg04210

after logon on database

when (user='SYS' or user like 'OPS$%')

begin

insert into audit1 values('OS_USER is ' ||sys_context('USERENV','OS_USER')|| '. SESSION_USER is '

||sys_context('USERENV','SESSION_USER')|| '. SYSDATE is '|| to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss')

|| '. REMOTE LOGIN IP is '||sys_context('USERENV','IP_ADDRESS'));

commit;

end;

################################################

3@@@@test the trigger by sys

SQL> select * from audit1;

no rows selected

SQL> conn /as sysdba;

Connected.

SQL> select * from audit1;

A

--------------------------------------------------------------------------------

OS_USER is oracle. SESSION_USER is SYS. SYSDATE is 2011-09-15 17:26:54

4@@@@test the trigger by ops$*

5@@@@ create user ops$oracle to test

SQL> create user ops$oracle identified externally;

User created.

SQL> grant connect to ops$oracle;

Grant succeeded.

SQL> conn /

Connected.

SQL> show user

USER is "OPS$ORACLE"

SQL> conn /@orcl      #####@orcl would be record the ip_address.

Connected.

SQL> show user

USER is "OPS$ORACLE"

6@@@@ login by @orcl.check the table aduit1

SQL> conn /@orcl

Connected.

SQL> conn /as sysdba; #####would not be return ip_address

Connected.

SQL> select * from audit1;

A

--------------------------------------------------------------------------------

OS_USER is oracle. SESSION_USER is OPS$ORACLE. SYSDATE is 2011-09-15 17:40:57. REMOTE LOGIN IP is 192.168.0.60

OS_USER is oracle. SESSION_USER is SYS. SYSDATE is 2011-09-15 17:40:59. REMOTE LOGIN IP is

5)audit a appointed table

#####the parameter audit must be 'db_extended',or no audit.

SQL> audit select on hr.employees;

Audit succeeded.

SQL> select SCN ,USERNAME,OBJ_NAME from  DBA_AUDIT_TRAIL;

SCN     USERNAME    OBJ_NAME

507462  HR          EMPLOYEES

SQL> select object_name, owner from dba_obj_audit_opts;

OBJECT_NAME                    OWNER

EMPLOYEES                      HR

SQL> noaudit select on hr.employees;

Noaudit succeeded.

SQL> select object_name, owner from dba_obj_audit_opts;

no rows selected

#####if you audit someone user. dba_obj_audit_opts would be

#####register that one.or remove

SQL> conn system/oracle

Connected.

SQL> audit table;

Audit succeeded.

SQL> noaudit table;

Noaudit succeeded.

#####current user is sys.

#####audit update on hr.employees;

#####audit select any table by hr by access whenever successful;

#####audit select any table by hr by session whenever successful;

#####noaudit select any table by hr;

#####audit drop any table by hr by access whenever successful;

#####audit drop any table by hr by session whenever successful;

#####noaudit drop any table by hr;

#####current user is user.

#####audit table;

#####noaudit table;

6)cancel audit

SQL> alter system set audit_trail=none scope=spfile;

SQL> shutdown immediate;

SQL> startup

SQL> show parameter audit_trail

NAME                                 TYPE        VALUE

audit_trail                          string      NONE

7)write a trigger to record the update employees

1@@@@ create a tbsaudit tablespace,then create a table audit on it

SQL> conn /as sysdba;

Connected.

SQL> create tablespace tbsaudit datafile '/u01/app/oracle/oradata/orcl/tbsaudit.dbf' size 200M autoextend on maxsize 500M;

Tablespace created.

SQL> conn hr/hr

SQL> create table audit_u(a varchar2(2000)) tablespace tbsaudit;

Table created.

2@@@@ create a trigger to audit the update.

#############################################################

create or replace trigger trig04210_value

after update of salary on hr.employees

referencing new as new old as old

for each row

begin

if :old.salary != :new.salary then

insert into audit_u values('OS_USER: '||sys_context('userenv','os_user')

||' ORACLE_USER: '||user||' at '||''||

to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')||''||

sys_context('userenv','ip_address')||' modified '||

'ORIGINAL_VALUE: '||:old.salary || ', NEW VALUE: '|| :new.salary );

end if;

end;

###############################################################

SQL> select * from user_errors;

SQL> select * from user_source where name='TRIG04210_VALUE';

3@@@@test the trigger

SQL> update employees set salary=50000 where employee_id=100;

1 row updated.

SQL> update employees set salary=50  where employee_id=100;

1 row updated.

SQL> select * from audit_u;

A

--------------------------------------------------------------------------------

OS_USER: oracle ORACLE_USER: HR at 2011-09-16 14:01:34 modified ORIGINAL_VALUE:

50000, NEW VALUE: 50

8)audit policies

SQL> select * from dba_audit_policies;

SQL> select * from dba_views v where v.view_name='DBA_FGA_AUIDT_TRIAL';

SQL> conn hr/hr

Connected.

SQL> create table audit3(a varchar2(2000)) tablespace tbsaudit;

Table created.

####################################################

create or replace procedure proc04210_fga(

object_schema VARCHAR2, object_name VARCHAR2, policy_name VARCHAR2)

AS

begin

insert into audit3 values('OS_USER: '||sys_context('userenv','os_user')||

'ORACLE_USER: '|| user || 'at'||' '|| to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')||' '||

sys_context('userenv','ip_address')||

'ORIGINAL_OBJECT:' ||object_schema||','||

object_name||

' FGA_POLICYNAME: '||policy_name);

end;

#####################################################

begin

dbms_fga.drop_policy(object_schema=>'HR',

object_name=>'EMPLOYEES',

policy_name=>'POLICY2');

end;

#####################################################

begin

dbms_fga.add_policy(

object_schema=>'HR',

object_name=>'EMPLOYEES',

policy_name=>'POLICY2',

audit_condition=>'department_id=20',

audit_column=>'salary',

handler_schema=>'SYS',

handler_module=>'PROC04210_FGA',

enable=>true,

statement_types=>'SELECT');

end;

9)audit sys

SQL> conn /as sysdba;

Connected.

SQL> show parameter sys

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

audit_sys_operations                 boolean     FALSE

audit_syslog_level                   string

filesystemio_options                 string      none

SQL> alter system set audit_sys_operations=true scope=spfile;

SQL> shutdown immediate;

SQL> startup;

#####it could audit sys.

SQL> !ps

PID TTY          TIME CMD

21137 pts/2    00:00:00 ps

30542 pts/2    00:00:00 bash

30570 pts/2    00:00:02 sqlplus

SQL> select spid from v$session s, v$process p where s.paddr=p.addr and s.terminal='pts/2'

2  and s.username='SYS';

SPID

------------

21114

[oracle@station3 adump]$ ls *21114*

ora_21114.aud

[oracle@station3 adump]$ pwd

/u01/app/oracle/admin/orcl/adump

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值