DM7审计之语句级审计

审计机制是DM数据库管理系统安全管理的重要组成部分之一。DM数据库除了提供数据安全保护措施外,还提供对日常事件的事后审计监督。DM具有一个灵活的审计子系统,可以通过它来记录系统级事件、个别用户的行为以及对数据库对象的访问。通过考察、跟踪审计信息,数据库审计员可以查看用户访问的形式以及曾试图对该系统进行的操作,从而采取积极、有效的应对措施。

审计开关
在DM系统中,专门为审计设置了开关,要使用审计功能首先要打开审计开关。审计开关由DM的INI参数ENABLE_AUDIT控制,有三种取值:
0:关闭审计
1:打开普通审计
2:打开普通审计和实时审计
在普通版本中,ENABLE_AUDIT的缺省值为0;在安全版本中,ENABLE_AUDIT的缺省值为2。审计开关必须由具有DBA权限的管理员进行设置。

系统管理员可通过查询V$PARAMETER动态视图查询ENABLE_AUDIT的当前值。

SQL> select * from v$parameter where name='ENABLE_AUDIT';

LINEID     ID          NAME         TYPE VALUE SYS_VALUE FILE_VALUE DESCRIPTION                                                                            
---------- ----------- ------------ ---- ----- --------- ---------- ---------------------------------------------------------------------------------------
1          385         ENABLE_AUDIT SYS  0     0         0          Flag For Allowing Audit, 0: no audit 1: normal audit  2:normal audit and realtime audit

used time: 8.170(ms). Execute id is 24948.

SQL> sp_set_para_value(1,'ENABLE_AUDIT',2);
DMSQL executed successfully
used time: 80.901(ms). Execute id is 24968.
SQL> select * from v$parameter where name='ENABLE_AUDIT';

LINEID     ID          NAME         TYPE VALUE SYS_VALUE FILE_VALUE DESCRIPTION                                                                            
---------- ----------- ------------ ---- ----- --------- ---------- ---------------------------------------------------------------------------------------
1          385         ENABLE_AUDIT SYS  2     2         2          Flag For Allowing Audit, 0: no audit 1: normal audit  2:normal audit and realtime audit

used time: 6.829(ms). Execute id is 24969.
SQL> select * from v$dm_ini where para_name='ENABLE_AUDIT';

LINEID     PARA_NAME    PARA_VALUE MIN_VALUE MAX_VALUE MPP_CHK SESS_VALUE FILE_VALUE DESCRIPTION                                                                             PARA_TYPE
---------- ------------ ---------- --------- --------- ------- ---------- ---------- --------------------------------------------------------------------------------------- ---------
1          ENABLE_AUDIT 2          0         2         N       2          2          Flag For Allowing Audit, 0: no audit 1: normal audit  2:normal audit and realtime audit SYS

used time: 7.090(ms). Execute id is 24970.
SQL> 

也可以通过使用客户端工具Console或调用系统过程SP_SET_PARA_VALUE重新设置ENABLE_AUDIT的值,ENABLE_AUDIT为动态INI参数。

审计的设置与取消
数据库审计员指定被审计对象的活动称为审计设置,只有具有AUDIT DATABASE权限的审计员才能进行审计设置。DM提供审计设置系统过程来实现这种设置,被审计的对象可以是某类操作,也可以是某些用户在数据库中的全部行踪。只有预先设置的操作和用户才能被DM系统自动进行审计。

DM允许在三个级别上进行审计设置
系统级:系统的启动与关闭,此级别的审计无法也无需由用户进行设置,只要审计开关打开就会自动生成对应审计记录
语句级:导致影响特定类型数据库对象的特殊SQL或语句组的审计。如AUDIT TABLE 将审计CREATE TABLE、ALTER TABLE和DROP TABLE等语句
对象级:审计作用在特殊对象上的语句。如test表上的INSERT语句

审计设置存放于DM字典表SYSAUDIT中,进行一次审计设置就在SYSAUDIT中增加一条对应的记录,取消审计则删除SYSAUDIT中相应的记录。

语句级审计
语句级审计的动作是全局的,不对应具体的数据库对象
ALL: 所有的语句级审计选项 所有可审计操作
USER:CREATE USER,ALTER USER,DROP USER 创建/修改/删除用户操作
ROLE: CREATE ROLE,DROP ROLE 创建/删除角色操作
TABLESPACE:CREATE TABLESPACE,ALTER TABLESPACE,DROP TABLESPACE, 创建/修改/删除表空间操作
SCHEMA:CREATE SCHEMA,DROP SCHEMA,SET SCHEMA 创建/删除/设置当前模式操作
TABLE:CREATE TABLE,ALTER TABLE,DROP TABLE,TRUNCATE TABLE 创建/修改/删除/清空基表操作
VIEW:CREATE VIEW, ALTER VIEW,DROP VIEW 创建/修改/删除视图操作
INDEX:CREATE INDEX,DROP INDEX 创建/删除索引操作
PROCEDURE:CREATE PROCEDURE,ALTER PROCEDURE,DROP PROCEDURE 创建/修改/删除存储模块操作
TRIGGER:CREATE TRIGGER,ALTER TRIGGER,DROP TRIGGER 创建/修改/删除触发器操作
SEQUENCE:CREATE SEQUENCE,ALTER SEQUENCE,DROP SEQUENCE 创建/修改/删除序列操作
CONTEXT:CREATE CONTEXT INDEX,ALTER CONTEXT INDEX,DROP CONTEXT INDEX 创建/修改/删除全文索引操作
SYNONYM:CREATE SYNONYM,DROP SYNONYM 创建/删除同义词
GRANT:GRANT 授予权限操作

设置语句级审计的系统过程如下:

VOID
SP_AUDIT_STMT(
TYPE VARCHAR(30),
USERNAME VARCHAR (128),
WHENEVER VARCHAR (20)
)

参数说明:
TYPE 语句级审计选项,即上表中的第一列
USERNAME 用户名,NULL表示不限制
WHENEVER 审计时机,可选的取值为:
ALL:所有的
SUCCESSFUL:操作成功时
FAIL:操作失败时

例1,审计表的创建、修改和删除。

SQL> sp_audit_stmt('table','null','all');
DMSQL executed successfully
used time: 10.709(ms). Execute id is 24979.
SQL> select * from sysaudit;

LINEID     LEVEL       UID         TVPID       COLID       TYPE        WHENEVER   
---------- ----------- ----------- ----------- ----------- ----------- -----------
1          1           -1          -1          -1          15          3

used time: 0.955(ms). Execute id is 24980.

SQL> drop table cs purge;
executed successfully
used time: 138.141(ms). Execute id is 24994.
SQL> create table cs(id int,name varchar(20));
executed successfully
used time: 31.431(ms). Execute id is 24996.

SQL> select * from v$auditrecords;

LINEID     USERID      USERNAME ROLEID      ROLENAME IP               SCHID       SCHNAME OBJID       OBJNAME OPERATION    SUCC_FLAG SQL_TEXT                                  DESCRIBTION OPTIME                      MAC              
---------- ----------- -------- ----------- -------- ---------------- ----------- ------- ----------- ------- ------------ --------- ----------------------------------------- ----------- --------------------------- -----------------
1          50331649    SYSDBA   67108864    DBA      ::ffff:127.0.0.1 -1                  -1                  DROP TABLE   Y         drop table cs purge;                                  2020-05-27 19:28:06.000000  00:00:00:00:00:00
2          50331649    SYSDBA   67108864    DBA      ::ffff:127.0.0.1 -1                  -1                  CREATE TABLE Y         create table cs(id int,name varchar(20));             2020-05-27 19:28:19.000000  00:00:00:00:00:00

used time: 0.891(ms). Execute id is 24997.

例2,对SYSDBA创建用户成功进行审计。

SQL> sp_audit_stmt('user','sysdba','successful');
DMSQL executed successfully
used time: 22.858(ms). Execute id is 25029.
SQL> select * from v$auditrecords;

LINEID     USERID      USERNAME ROLEID      ROLENAME IP               SCHID       SCHNAME OBJID       OBJNAME OPERATION    SUCC_FLAG SQL_TEXT                                  DESCRIBTION OPTIME                      MAC              
---------- ----------- -------- ----------- -------- ---------------- ----------- ------- ----------- ------- ------------ --------- ----------------------------------------- ----------- --------------------------- -----------------
1          50331649    SYSDBA   67108864    DBA      ::ffff:127.0.0.1 -1                  -1                  DROP TABLE   Y         drop table cs purge;                                  2020-05-27 19:28:06.000000  00:00:00:00:00:00
2          50331649    SYSDBA   67108864    DBA      ::ffff:127.0.0.1 -1                  -1                  CREATE TABLE Y         create table cs(id int,name varchar(20));             2020-05-27 19:28:19.000000  00:00:00:00:00:00
3          50331649    SYSDBA   67108864    DBA      ::ffff:127.0.0.1 -1                  -1                  CREATE USER  Y         create user cs2 identified by ******;                 2020-05-27 19:32:18.000000  00:00:00:00:00:00

used time: 1.650(ms). Execute id is 25032.

例3,对用户jy进行的表的修改和删除进行审计,不管失败和成功。

SQL> sp_audit_stmt('update table','jy','all');
DMSQL executed successfully
used time: 15.729(ms). Execute id is 25037.
SQL> sp_audit_stmt('delete table','jy','all');
DMSQL executed successfully
used time: 13.254(ms). Execute id is 25038.

SQL> update t1 set c2='WY' where c1=2;
affect rows 1

used time: 17.490(ms). Execute id is 25043.
SQL> rollback;
executed successfully
used time: 1.001(ms). Execute id is 25045.
SQL> delete from t1;
affect rows 2

used time: 27.257(ms). Execute id is 25046.
SQL> rollback;
executed successfully
used time: 0.831(ms). Execute id is 25049.

SQL> select * from v$auditrecords;

LINEID     USERID      USERNAME ROLEID      ROLENAME IP               SCHID       SCHNAME OBJID       OBJNAME OPERATION    SUCC_FLAG SQL_TEXT                                  DESCRIBTION OPTIME                      MAC              
---------- ----------- -------- ----------- -------- ---------------- ----------- ------- ----------- ------- ------------ --------- ----------------------------------------- ----------- --------------------------- -----------------
1          50331649    SYSDBA   67108864    DBA      ::ffff:127.0.0.1 -1                  -1                  DROP TABLE   Y         drop table cs purge;                                  2020-05-27 19:28:06.000000  00:00:00:00:00:00
2          50331649    SYSDBA   67108864    DBA      ::ffff:127.0.0.1 -1                  -1                  CREATE TABLE Y         create table cs(id int,name varchar(20));             2020-05-27 19:28:19.000000  00:00:00:00:00:00
3          50331649    SYSDBA   67108864    DBA      ::ffff:127.0.0.1 -1                  -1                  CREATE USER  Y         create user cs2 identified by ******;                 2020-05-27 19:32:18.000000  00:00:00:00:00:00
4          50331750    JY       67108864    DBA      ::ffff:127.0.0.1 150995951   JY      1454        T1      UPDATE       Y         update t1 set c2='WY' where c1=2;                     2020-05-27 19:36:39.000000  00:00:00:00:00:00
5          50331750    JY       67108864    DBA      ::ffff:127.0.0.1 150995951   JY      1454        T1      DELETE       Y         delete from t1;                                       2020-05-27 19:37:08.000000  00:00:00:00:00:00

used time: 1.242(ms). Execute id is 25047.

取消语句级审计的系统过程如下:

VOID
SP_NOAUDIT_STMT(
TYPE VARCHAR(30),
USERNAME VARCHAR (128),
WHENEVER VARCHAR (20)
)

参数说明:
TYPE 语句级审计选项,即上表中的第一列
USERNAME 用户名,NULL表示不限制
WHENEVER 审计时机,可选的取值为:
ALL:所有的
SUCCESSFUL:操作成功时
FAIL:操作失败时

使用说明:
取消审计语句和设置审计语句进行匹配,只有完全匹配的才可以取消审计,否则无法取消审计。
例1,取消对表的创建、修改和删除的审计。

SQL> sp_noaudit_stmt('table','null','all');
DMSQL executed successfully
used time: 64.146(ms). Execute id is 25059.

例2,取消对SYSDBA创建用户成功进行审计。

SQL> sp_noaudit_stmt('user','sysdba','successful');
DMSQL executed successfully
used time: 11.380(ms). Execute id is 25060.

例3,取消对用户jy进行的表的修改和删除的审计。

SQL> sp_noaudit_stmt('update table','jy','all');
DMSQL executed successfully
used time: 18.614(ms). Execute id is 25062.
SQL> sp_noaudit_stmt('delete table','jy','all');
DMSQL executed successfully
used time: 15.548(ms). Execute id is 25064.

Leave a Reply

Your email address will not be published.

Proudly powered by WordPress | Indrajeet by Sus Hill.