看一下Oracle的审计功能(包括FGA细粒度审计)能给我们带来些什么的强悍效果。我将通过这个小文儿向您展示一下Oracle很牛的审计功
看一下Oracle的审计功能(包括FGA细粒度审计)能给我们带来些什么的强悍效果。
我将通过这个小文儿向您展示一下Oracle很牛的审计功能。Follow me.
1.使用审计,需要先激活审计功能
1)查看系统中默认的与审计相关的参数设置
sys@ora10g> conn / as sysdba
Connected.
sys@ora10g> show parameter audit
NAME TYPE VALUE
--------------------- --------- --------------------------------------
audit_file_dest string /oracle/app/oracle/admin/ora10g/adump
audit_sys_operations boolean FALSE
audit_syslog_level string
audit_trail string NONE
2)对上面所列的参数进行一下解释
(1)AUDIT_FILE_DEST = 路径
指示出审计的文件存放的路径信息,我们这里显示的是“/oracle/app/oracle/admin/ora10g/adump”
不管打开还是不打开审计功能,这个目录项都会记录以sysdba身份的每次登录信息,,有兴趣的朋友可以到这个目录中查看一下。
例如:
$ cat ora_9915.aud
Audit file /oracle/app/oracle/admin/ora10g/adump/ora_9915.aud
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
ORACLE_HOME = /oracle/app/oracle/product/10.2.0/db_1
System name: Linux
Node name: testdb183
Release: 2.6.18-128.el5
Version: #1 SMP Wed Dec 17 11:41:38 EST 2008
Machine: x86_64
Instance name: ora10g
Redo thread mounted by this instance: 1
Oracle process number: 13
Unix process pid: 9915, image: oracle@testdb183 (TNS V1-V3)
Wed Aug 26 19:24:11 2009
ACTION : 'CONNECT'
DATABASE USER: '/'
PRIVILEGE : SYSDBA
CLIENT USER: oracle
CLIENT TERMINAL: pts/1
STATUS: 0
(2)audit_sys_operations
默认值是FALSE,如果开启审计功能,这个参数需要修改为TRUE。
(3)audit_syslog_level
语句:指定审计语句或特定类型的语句组,象审计表的语句 CREATE TABLE, TRUNCATE TABLE, COMMENT ON TABLE, and DELETE [FROM] TABLE
权限:使用审计语句指定系统权限,象AUDIT CREATE ANY TRIGGER
对象:在指定对象上指定审计语句,象ALTER TABLE on the emp table
(4)AUDIT_TRAIL = NONE|DB|OS
DB--审计信息记录到数据库中
OS--审计信息记录到操作系统文件中
NONE--关闭审计(默认值)
3)修改参数audit_sys_operations为“TRUE”,开启审计的功能
sys@ora10g> alter system set audit_sys_operatiOns=TRUE scope=spfile;
System altered.
4)修改参数audit_trail为“db”,审计信息记录到数据库中
sys@ora10g> alter system set audit_trail=db scope=spfile;
System altered.
5)注意,到这里如果需要使这些参数生效,必须重新启动一下数据库
sys@ora10g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@ora10g> startup;
ORACLE instance started.
Total System Global Area 1073741824 bytes
Fixed Size 2078264 bytes
Variable Size 293603784 bytes
Database Buffers 771751936 bytes
Redo Buffers 6307840 bytes
Database mounted.
Database opened.
6)验证一些参数修改后的结果,这里显示已经修改完成
sys@ora10g> show parameter audit;
NAME TYPE VALUE
--------------------- -------- --------------------------------------
audit_file_dest string /oracle/app/oracle/admin/ora10g/adump
audit_sys_operations boolean TRUE
audit_syslog_level string
audit_trail string DB
2.开启了审计功能后,这里有一个有趣的效果,就是所有sysdba权限下的操作都会被记录到这个/oracle/app/oracle/admin/ora10g/adump审计目录下。这也是为什么开启了审计功能后会存在一些开销和风险。
1)假如我们在sysdba权限用户下执行下面三条命令
sys@ora10g> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
sys@ora10g> select * From dual;
D
-
X
sys@ora10g> show parameter spfile
NAME TYPE VALUE
------ ------ ------------------------------------------------------------
spfile string /oracle/app/oracle/product/10.2.0/db_1/dbs/spfileora10g.ora
2)使用tail命令可以看到在相应的trace文件中有如下的详细记录信息,有点意思的发现,可以看到“show parameter spfile”命令背后真正执行了什么样的SQL语句
Wed Aug 26 20:04:03 2009
ACTION : 'alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss''
DATABASE USER: '/'
PRIVILEGE : SYSDBA
CLIENT USER: oracle
CLIENT TERMINAL: pts/2
STATUS: 0
Wed Aug 26 20:04:03 2009
ACTION : 'BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;'
DATABASE USER: '/'
PRIVILEGE : SYSDBA
CLIENT USER: oracle
CLIENT TERMINAL: pts/2
STATUS: 0
Wed Aug 26 20:04:16 2009
ACTION : 'select * From dual'
DATABASE USER: '/'
PRIVILEGE : SYSDBA
CLIENT USER: oracle
CLIENT TERMINAL: pts/2
STATUS: 0
Wed Aug 26 20:04:16 2009
ACTION : 'BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;'
DATABASE USER: '/'
PRIVILEGE : SYSDBA
CLIENT USER: oracle
CLIENT TERMINAL: pts/2
STATUS: 0
Wed Aug 26 20:07:21 2009
ACTION : 'SELECT NAME NAME_COL_PLUS_SHOW_PARAM,DECODE(TYPE,1,'boolean',2,'string',3,'integer',4,'file',5,'number', 6,'big integer', 'unknown') TYPE,DISPLAY_VALUE VALUE_COL_PLUS_SHOW_PARAM FROM V$PARAMETER WHERE UPPER(NAME) LIKE UPPER('%spfile%') ORDER BY NAME_COL_PLUS_SHOW_PARAM,ROWNUM'
DATABASE USER: '/'
PRIVILEGE : SYSDBA
CLIENT USER: oracle
CLIENT TERMINAL: pts/2
STATUS: 0
3.演示一下对sec用户的t_audit表delete操作的审计效果
1)表t_audit信息如下
@ora10g> select * from t_audit order by 1;
X
----------
1
2
3
4
5
6
6 rows selected.
2)这里仅仅开启对表t_audit的delete操作的审计
sec@ora10> audit delete on t_audit;
Audit succeeded.
3)查看审计设置可以通过查询dba_obj_audit_opts视图来完成
@ora10g> select OWNER,OBJECT_NAME,OBJECT_TYPE,DEL,INS,SEL,UPD from dba_obj_audit_opts;
OWNER OBJECT_NAME OBJECT_TYPE DEL INS SEL UPD
------ ------------ ------------ --------- --------- --------- ---------
SEC T_AUDIT TABLE S/S -/- -/- -/-
4)尝试插入数据
@ora10g> insert into t_audit values (7);
1 row created.
5)因为我们没有对insert语句进行审计,所以没有审计信息可以得到
@ora10g> select count(*) from dba_audit_trail;
COUNT(*)
----------
0
6)再尝试delete操作
@ora10g> delete from t_audit where x=1;
1 row deleted.
7)不出所料,delete操作被数据库捕获
这里可以通过查询dba_audit_trail视图或者sys.aud$视图得到详细的审计信息,这种审计方法可以得到操作的时间,操作用户等较粗的信息(相对后面介绍的细粒度审计来说)
@ora10g> select count(*) from dba_audit_trail;
COUNT(*)
----------
1
select * from dba_audit_trail;
select * from sys.aud$;
4.如想要取消对表t_audit的全部审计,需要使用手工方式来完成
sec@ora10> noaudit all on t_audit;
Noaudit succeeded.
通过查询dba_obj_audit_opts视图,确认确实已经取消的审计
@ora10g> select * from dba_obj_audit_opts;
no rows selected