Audit 功能的使用方法介紹

zhulch發表於2007-02-28

收藏...

[@more@]

一. 檢視說明:
1. SYS.AUD$
審計功能的底層檢視,如果需要對資料進行刪除,只需要對aud$檢視進行刪除既可,其他檢視裡的資料都是由aud$所得.
2. DBA_AUDIT_EXISTS
列出audit not exists和audit exists產生的審計跟蹤,我們預設的都是audit exists.
3. DBA_AUDIT_TRAIL
可以在裡面查處所有審計所跟蹤的資訊.
4. DBA_AUDIT_OBJECT
可以查詢所有物件跟蹤資訊.(例如,對grant,revoke等不記錄),他的資訊完全包含於dba_audit_trail
5. DBA_AUDIT_SESSION
所得到的資料都是有關logon或者logoff的資訊.
6. DBA_AUDIT_STATEMENT
列出grant ,revoke ,audit ,noaudit ,alter system語句的審計跟蹤資訊.
7. DBA_PRIV_AUDIT_OPTS
透過系統和由使用者審計的當前系統特權
8. DBA_OBJ_AUDIT_OPTS
可以查詢到所有使用者所有物件的設計選項
9. ALL_DEF_AUDIT_OPTS
(還沒明白出其確切意義)
10. AUDIT_ACTIONS
可以查詢出在aud$等檢視中actions列的含義
11. SYSTEM_PRIVILEGE_MAP
可以查詢出aud$等檢視中priv$used列的含義(注意前面加’-‘)
12.
二. 對audit的設定
1.需要對audit_trail引數進行設定.該引數有三個值可以設定,預設為false,為不進行審計.當設定為OS時,對資料庫進行設計的資訊記錄到作業系統中,當為DB時記錄入sys.aud$中.
2.需要對sys使用者進行審計,需要設定AUDIT_SYS_OPERATIONS = TRUE,該引數預設值為false,為不進行審計.當對其設計時,所有的資訊將記錄入作業系統中而不記錄入SYS.AUD$
注:當記錄入作業系統中時,其引數控制為AUDIT_FILE_DEST
三. 審計
1. by session與by access
當設定為by session時,對每個session下每條審計記錄只出現一次,by access對每次操作都進行記錄,by access將會帶來大量的記錄.
2. by user
如果在命令後面新增by user則只對user的操作進行審計,如果省去by 使用者,則對系統中所有的使用者進行審計(不包含sys使用者).

四. 測試情況
Session1設定設計選項(sys),簡寫為S1, session2查詢結果(user),簡稱S2,其他為測試連線session(user),為sessionn(n >2)
1. 對錶的審計
對create table進行審計(需要對成功與失敗兩種情況進行測試)
S1:
SQL> audit create table by user;
S3:
SQL>create table test (id number);
SQL>create table test (id number);(要報錯)
S2:
SQL>select username,returncode,action_name from dba_audit_trail;
user 955 CREATE TABLE
user 0 CREATE TABLE
S1:
SQL>truncate table aud$
對修改表(alter table)進行審計
S1:
SQL> audit alter table by user;
S3:
SQL> alter table test add( col number);
SQL> alter table test add( col number); (要報錯)
S2:
SQL>select username,returncode,action_name from dba_audit_trail;
user 0 ALTER TABLE
user 1430 ALTER TABLE
S1:
SQL>truncate table aud$
對刪除表(drop table)進行審計 由於沒有對drop table進行單獨審計的操作,需要新增audit table by user(此命令將對create table ,drop table, truncate table 進行審計)
S1:
SQL> audit table by user;
S3:
SQL> drop table test;
SQL> drop table test;(將報錯)
SQL>create table test(id number);
SQL> truncate table test;
S2:
SQL>select username,returncode,action_name from dba_audit_trail;
1 user 0 DROP TABLE
2 user 942 DROP TABLE
3 user 0 CREATE TABLE
4 user 0 TRUNCATE TABLE
S1:
SQL>truncate table aud$

2. 對檢視的審計
對建立檢視(create view)進行審計
S1:
SQL> audit create view by user;
S3:
SQL> create view test0 as select * from test;
SQL> create view test0 as select * from test;(要報錯)
S2:
SQL>select username,returncode,action_name from dba_audit_trail;
1 user 955 CREATE VIEW
2 user 0 CREATE VIEW
S1:
SQL>truncate table aud$

對修改檢視(alter view)進行審計 沒有對檢視進行修改的操作,所以審計修改檢視也就不存在.
對刪除檢視(drop view)進行審計 由於沒有對drop view進行單獨審計的操作,需要新增audit view by user(此命令將對create view ,drop view進行審計)
S1:
SQL> audit view by user;
S3:
SQL> drop view test0;
SQL> drop view test0; (將報錯)
SQL> create view test0 as select * from test;;
S2:
SQL>select username,returncode,action_name from dba_audit_trail;
1 user 0 DROP VIEW
2 user 942 DROP VIEW
3 user 0 CREATE VIEWS1:
SQL>truncate table aud$

3. 對程式包的審計
目前沒有對程式包的重新編譯進行審計.對包,函式以及儲存過程的審計都可以透過audit procedure by user進行審計.
S1:
SQL> audit procedure by user;
S3:
SQL> create procedure test1
2 as
3 begin
4 null;
5 end;
6 /
SQL> drop procedure test1;
SQL> drop procedure test1;

S2:
SQL>select username,returncode,action_name from dba_audit_trail;
1 user 0 CREATE PROCEDURE
2 user 0 DROP PROCEDURE
3 user 4043 DROP PROCEDURE
SQL>truncate table aud$

4. 對使用者的審計
對使用者的審計可以有audit user來實現,該命令可以審計create user,alter user,drop user.
S1:
SQL> audit user by user;
S3:
SQL> create user zyc identified by zyc;
SQL> alter user zyc identified by 000; (要報錯)
SQL> alter user zyc identified by zyc; (要報錯)
SQL> alter user zyc identified by aaa;
SQL> drop user zyc;
SQL> drop user zyc; (要報錯)

S2:
SQL>select username,returncode,action_name from dba_audit_trail;
1 user 0 CREATE USER
2 user 988 ALTER USER
3 user 28007 ALTER USER
4 user 0 ALTER USER
5 user 0 DROP USER
6 user 1918 DROP USERS1:
SQL>truncate table aud$

綜上所述:
1. 對錶的審計:可以單獨對錶的create,alter進行審計,如果要對drop操作進行審計需要對錶加audit table(該命令包含有create table,drop table,truncate table).
2. 對檢視的審計:可以單獨對檢視的create進行審計,如果要對drop操作進行審計需要對檢視加audit view(該命令包含有create view,drop view).
3. 對程式包的審計:可以對包(函式,儲存過程等)的create進行審計,如果需要對drop操作進行審計需要加audit procedure(該命令對CREATE FUNCTION, CREATE LIBRARY , CREATE PACKAGE, CREATE PACKAGE BODY, CREATE PROCEDURE, DROP FUNCTION, DROP LIBRARY, DROP PACKAGE, DROP PROCEDURE進行審計)
4. 對使用者的審計:可以透過audit user(該命令包含 create user,alter user,drop user)進行審計,

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7318139/viewspace-900946/,如需轉載,請註明出處,否則將追究法律責任。

相關文章