Chinaunix首页 | 论坛 | 博客
  • 博客访问: 80648
  • 博文数量: 22
  • 博客积分: 241
  • 博客等级: 二等列兵
  • 技术积分: 273
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-23 18:30
文章分类

全部博文(22)

文章存档

2014年(22)

我的朋友

分类: Oracle

2014-06-28 10:49:51

一 审计功能的参数控制

audit_trail 参数的值可以设置为以下几种

1. NONE:不开启

2. DB:开启审计功能

3. OS:审计记录写入一个操作系统文件。

4. TRUE:与参数DB一样

5. FALSE:不开启审计功能。

这个参数是写道spfile里面的,需要重启

一 审计功能的参数控制

audit_trail 参数的值可以设置为以下几种

二 查看是否审计功能是否启动

SQL> show parameter audit

三 开启审计

SQL> conn /as sysdba

SQL> show parameter 

SQL> alter system set audit_sys_operations=TRUE scope=spfile;–审计管理用户(以sysdba/sysoper角色登陆)

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

四 关闭审计

SQL> conn /as sysdba

SQL> show parameter audit

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

二. Audit说明

2.1 审计

审计(Audit)用于监视用户所执行的操作,审计记录可存在数据字典表(称为审计记录:在system表空间中的 SYS.AUD$表中,可通过视图dba_audit_trail查看)或操作系统审计记录中(默认位置为$ORACLE_BASE/admin/$ORACLE_SID/adump/).。默认情况下审计是没有开启的。

当的审计是使能的,在语句执行阶段产生审计记录。审计记录包含有审计的操作、用户执行的操作、操作的日期和时间等信息。

不管你是否打开的审计功能,以下这些操作系统会强制记录:用管理员权限连接Instance;启动;关闭。

2.1.1 审计功能

审计是对选定的用户动作的和记录,通常用于:

审查可疑的活动。例如:数据被非授权用户所删除,此时安全管理员可决定对该的所有连接进行审计,以及对的所有表的成功地或不成功地删除进行审计。

监视和收集关于指定活动的数据。例如:DBA可收集哪些被修改、执行了多少次逻辑的I/O等统计数据。

2.1.2 ORACLE所允许的审计选择限于下列方面:

审计语句的成功执行、不成功执行,或者其两者。

对每一用户会话审计语句执行一次或者对语句每次执行审计一次。

对全部用户或指定用户的活动的审计。

2.1.3 审计相关的表安装

SQLPLUS> connect / AS SYSDBA

SQLPLUS> select * from sys.aud$; –没有记录返回

SQLPLUS> select * from dba_audit_trail; – 没有记录返回

如果做上述查询的时候发现表不存在,说明审计相关的表还没有安装,需要安装。

SQLPLUS> connect / as sysdba

SQLPLUS> @$ORACLE_HOME/rdbms/admin/cataudit.sql

审计表安装在SYSTEM表空间。所以要确保SYSTEM表空间又足够的空间存放审计信息。

安装后要重启

2.1.4 将审计相关的表移动到其他表空间

由于AUD$表等审计相关的表存放在SYSTEM表空间,因此为了不影响系统的性能,保护SYSTEM表空间,最好把AUD$移动到其他的表空间上。可以使用下面的语句来进行移动:

sql>connect / as sysdba;

sql>alter table aud$ move tablespace;

sql>alter index I_aud1 rebuild onlinetablespace ;

SQL> alter table audit$ move tablespace;

SQL> alter index i_audit rebuild onlinetablespace ;

SQL> alter table audit_actions movetablespace ;

SQL> alter index i_audit_actions rebuildonline tablespace ;

2.1.5 truncate 或者 delete sys.aud$ 表

在delete 之前,可以先把aud$表exp备份一下,注意,不要直接exp,先创建一张临时表,然后将临时表exp。

sql>createtable audit_record tablespace users as select * from sys.aud$;

然后exp:

exptables=AUDIT_RECORD file=audit_record.dmp

最后delete 数据:

sql>delete from sys.aud$;

或者删除指定表的审计:

sql>delete from sys.aud$ whereobj$name='&table_nmae';

注意,delete 不会释放system表空间。 可以使用truncate table:

sql>truncate table sys.aud$

2.2 和审计相关的两个主要参数

2.2.1 Audit_sys_operations

AUDIT_SYS_OPERATIONSenables or disables the auditing of top-level operations, which are SQL statementsdirectly issued by users when connecting with SYSDBA or SYSOPER privileges.(SQL statements run from within PL/SQL procedures or functions are notconsidered top-level.) The audit records are written to the operating system'saudit trail. The audit records will be written in XML format if the AUDIT_TRAILinitialization parameter is set to xml or xml, extended.

OnUNIX platforms, if the AUDIT_SYSLOG_LEVEL parameter has also been set, then itoverrides the AUDIT_TRAIL parameter and SYS audit records are written to thesystem audit log using the SYSLOG utility.

默认为false,当设置为true时,所有sys用户(包括以sysdba, sysoper身份登录的用户)的操作都会被记录,audit trail不会写在aud$表中,这个很好理解,如果还未启动aud$不可用,那么像conn /as sysdba这样的连接信息,只能记录在其它地方。如果是windows平台,audti trail会记录在windows的事件管理中,如果是/unix平台则会记录在audit_file_dest参数指定的文件中。

)> show parameteraudit_file_dest

NAME TYPE VALUE

———————————————– ——————————

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

2.2.2 Audit_trail

AUDIT_TRAIL enables or disables databaseauditing.

Values:

(1)none:Disables standard auditing. This value is thedefault if the AUDIT_TRAIL parameter was not set in the initializationparameter file or if you created the database using a method other thanDatabase Configuration Assistant. If you created the database using DatabaseConfiguration Assistant, then the default is db.

(2)os:Directs all audit records to an operating system file. recommends that you use the os setting, particularly if you are using anultra-secure database configuration.

(3)db:Directs audit records to the database audit trail (the SYS.AUD$table), except for records that are always written to the operating systemaudit trail. Use this setting for a general database for manageability.

If the database was started in read-onlymode with AUDIT_TRAIL set to db, then Database internally sets AUDIT_TRAILto os. Check the alert log for details.

(4)db, extended:Performs all actions of AUDIT_TRAIL=db,and also populates the SQL bind and SQL text CLOB-type columns of the SYS.AUD$table, when available. These two columns are populated only when this parameteris specified.

If the database was started in read-onlymode with AUDIT_TRAIL set to db, extended, then Oracle Database internally setsAUDIT_TRAIL to os. Check the alert log for details.

(5)xml:Writes to the operating system audit record file in XML format.Records all elements of the AuditRecord node except Sql_Text and Sql_Bind tothe operating system XML audit file.

(6)xml, extended:Performs all actions of AUDIT_TRAIL=xml,and populates the SQL bind and SQL text CLOB-type columns of the SYS.AUD$table, wherever possible. These columns are populated only when this parameteris specified.

Youcan use the SQL AUDIT statement to set auditing options regardless of thesetting of this parameter.

None:是默认值,不做审计;

DB:将audit trail 记录在的审计相关表中,如aud$,审计的结果只有连接信息;

DB,Extended:这样审计结果里面除了连接信息还包含了当时执行的具体语句;

OS:将audit trail 记录在操作系统文件中,文件名由audit_file_dest参数指定;

XML:10g里新增的。

注:这两个参数是static参数,需要重新启动才能生效。

2.3审计级别

当开启审计功能后,可在三个级别对进行审计:Statement(语句)、Privilege(权限)、object(对象)。

2.3.1 Statement

语句审计,对某种类型的SQL语句审计,不指定结构或对象。比如audit table 会审计中所有的create table,droptable,truncate table语句,alter session by cmy会审计cmy用户所有的连接。

2.3.2 Privilege

权限审计,当用户使用了该权限则被审计,如执行grant selectany table to a,当执行了auditselect any table语句后,当用户a 访问了用户b的表时(如select * from b.t)会用到select any table权限,故会被审计。注意用户是自己表的所有者,所以用户访问自己的表不会被审计。

2.3.3 Object

对象审计,对一特殊模式对象上的指定语句的审计. 如审计on关键字指定对象的相关操作,如aduitalter,delete,drop,insert on cmy.t by scott; 这里会对cmy用户的t表进行审计,但同时使用了by子句,所以只会对scott用户发起的操作进行审计。

注意:Oracle没有提供对schema中所有对象的审计功能,只能一个一个对象审计,对于后面创建的对象,Oracle则提供on default子句来实现自动审计,比如执行audit drop on defaultby access;后,对于随后创建的对象的drop操作都会审计。但这个default会对之后创建的所有对象有效,似乎没办法指定只对某个用户创建的对象有效,想比 trigger可以对schema的DDL进行“审计”,这个功能稍显不足。

2.4审计的一些其他选项

2.4.1 by access / by session

by access 每一个被审计的操作都会生成一条audit trail。

by session 一个会话里面同类型的操作只会生成一条audit trail,默认为by session。

2.4.2 whenever [not] successful

whenever successful 操作成功(dba_audit_trail中returncode字段为0) 才审计,

whenever not successful 反之。省略该子句的话,不管操作成功与否都会审计。

2.5 和审计相关的视图

2.5.1 dba_audit_trail:保存所有的audit trail,实际上它只是一个基于aud$的视图。其它的视图dba_audit_session,dba_audit_object,dba_audit_statement都只是dba_audit_trail的一个子集。

2.5.2 dba_stmt_audit_opts:可以用来查看statement审计级别的audit options,即设置过哪些statement级别的审计。dba_obj_audit_opts,dba_priv_audit_opts视图功能与之类似

2.5.3 all_def_audit_opts:用来查看用on default子句设置了哪些默认对象审计。

2.6取消审计

将对应审计语句的audit改为noaudit即可,

如audit sessionwhenever successful

对应的取消审计语句为noauditsession whenever successful;

三. Fine-grainedauditing(FGA) 细粒度审计

细粒度审计(FGA):精细审计 ,是在 Oracle 9i 中引入的,能够记录 SCN 号和行级的更改以重建旧的数据,但是它们只能用于 select 语句,而不能用于 DML ,如 update 、insert 和delete 语句。因此,对于 Oracle  10g 之前的版本,使用触发器虽然对于以行级跟踪用户初始的更改是没有吸引力的选择,但它也是唯一可靠的方法。 10g 之后版本可以audit 所有DML。FGA的实现基于DBMS_FGA包。它属于SYS用户。

3.1 增加 FGA 策略

– 审计表

SQL>grant resource,connect to bank identified by bank;
来源:

阅读(2943) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~