2011-01-19

ORACLE AUDIT

1 Init params

initoptionvaluesdesc
AUDIT_TRAILNONE/DB/OS/DB,EXTENDED/XML/XML,EXTENDEDturn on audit and set type
AUDIT_FILE_DESTset directory for audit files when AUDIT_TRAIL=OS, default: $ORACLE_HOME/rdbms/audit
AUDIT_SYS_OPERATIONSTRUE/FALSEfor sys operations

1.1 AUDIT_TRAIL

  • in 11g audyt is set default on DB value
none or falseAuditing is disabled.
db or trueAuditing is enabled, with all audit records stored in the database audit trial (SYS.AUD$).
db,extendedAs db, but the SQL_BIND and SQL_TEXT columns are also populated.
xmlAuditing is enabled, with all audit records stored as XML format OS files.
xml,extendedAs xml, but the SQL_BIND and SQL_TEXT columns are also populated.
osAuditing is enabled, with all audit records directed to the operating system's audit trail.

2 Turn on

  • set param audit_trail

Commands:

AUDITturn on audit
NOAUDIT ALLturn off all audit operations for current user
NOAUDIT ALL BY [username]
NOAUDIT SELECT TABLE BY [username]
AUDIT ALL BY [username] BY ACCESS/SESSIONACCESS - log everytime the event heppen, SESSION - log only at first time
NOAUDIT TABLE BY [username]
AUDIT select table, insert table, delete table, update table BY [username] BY ACCESS

Views:
STMT_AUDIT_OPTION_MAPContains information about auditing option type codes. Created by the SQL.BSQ script at CREATE DATABASE time.
AUDIT_ACTIONSContains descriptions for audit trail action type codes
ALL_DEF_AUDIT_OPTSContains default object-auditing options that will be applied when objects are created

3 VIEWS for SYS.AUD$

DBA_STMT_AUDIT_OPTSshow running audits for user
DBA_PRIV_AUDIT_OPTSDescribes current system privileges being audited across the system and by user
DBA_OBJ_AUDIT_OPTSDescribes auditing options on all objects. USER view describes auditing options on all objects owned by the current user.
DBA_AUDIT_TRAILLists all audit trail entries USER view shows audit trail entries relating to current user.
DBA_AUDIT_STATEMENTLists audit trail records concerning GRANT, REVOKE, AUDIT, NOAUDIT, and ALTER SYSTEM statements throughout the database, or for the USER view, issued by the user
DBA_AUDIT_EXISTSLists audit trail entries produced BY AUDIT NOT EXISTS
DBA_AUDIT_SESSIONLists all audit trail records concerning CONNECT and DISCONNECT. USER view lists all audit trail records concerning connections and disconnections for the current user.
DBA_AUDIT_OBJECTContains audit trail records for all objects in the database. USER view lists audit trail records for statements concerning objects that are accessible to the current user.

  • DDL (CREATE, ALTER & DROP of objects)
  • DML (INSERT UPDATE, DELETE, SELECT, EXECUTE).
  • SYSTEM EVENTS (LOGON, LOGOFF etc.)
  • SELECT * FROM dba_stmt_audit_opts ORDER BY 1,3;
col obj_name format a30
col owner format a15
col username format a15
SELECT owner,username,obj_name,action_name,to_char(timestamp,'YYYY-MM-DD HH24:MI:SS') FROM dba_audit_trail 
  WHERE timestamp >= trunc(sysdate-1) and username='CCI' order by timestamp;
prompt ###zajetosc_tabeli_audytu
SELECT sum(bytes)/1024/1024 as MB FROM dba_segments WHERE segment_name='AUD$';

4 Options

4.1 default audit options

  • rdbms/admin/secconf.sql
  • rdbms/admin/undoaud.sql #wylaczenie

4.2 ALL

ObjectSQL Statements and Operations Audited
ALTER SYSTEMALTER SYSTEM
CLUSTERCREATE, ALTER, DROP, TRUNCATE
CONTEXTCREATE, DROP
DATABASE LINKCREATE, ALTER, ALTER PUBLIC DATABASE LINK, DROP DATABASE LINK
DIMENSIONCREATE, ALTER, DROP
DIRECTORYCREATE, DROP
INDEXCREATE INDEX, ALTER, ANALYZE INDEX, DROP
MATERIALIZED VIEWCREATE, ALTER, DROP
NOT EXISTSAll SQL statements that fail because a specified object does not exist.
OUTLINECREATE, ALTER, DROP
PROCEDURECREATE FUNCTION, CREATE LIBRARY, CREATE PACKAGE, CREATE PACKAGE BODY
CREATE PROCEDURE, DROP FUNCTION, DROP LIBRARY, DROP PACKAGE, DROP PROCEDURE
PROFILECREATE, ALTER, DROP
PUBLIC DATABASE LINKCREATE, DROP
PUBLIC SYNONYMCREATE, DROP
ROLECREATE, ALTER, DROP, SET
ROLLBACK SEGMENTCREATE, ALTER, DROP
SEQUENCECREATE, DROP
SESSIONLogons
SYNONYMCREATE, DROP
SYSTEM AUDITAUDIT sql_statements, NOAUDIT sql_statements
SYSTEM GRANTGRANT system_privileges_and_roles, REVOKE system_privileges_and_roles
TABLECREATE, DROP,TRUNCATE TABLE
TABLESPACECREATE, TABLESPACE, ALTER, DROP
TRIGGERCREATE, ALTER with ENABLE and DISABLE clauses, DROP, ALTER TABLE with ENABLE ALL TRIGGERS clause and DISABLE ALL TRIGGERS clause
TYPECREATE, CREATE TYPE BODY,ALTER,DROP,DROP TYPE BODY
USERCREATE, ALTER, DROP
VIEWCREATE, DROP

Notes:
  • AUDIT USER #audits three SQL statements: CREATE, ALTER, DROP Use AUDIT ALTER USER to audit statements that require the ALTER USER system privilege. An AUDIT ALTER USER statement does not audit a user changing his or her own password, as this activity does not require the ALTER USER system privilege.

4.3 ADDITIONAL

ALTER SEQUENCEALTER SEQUENCE
ALTER TABLEALTER TABLE
COMMENT TABLECOMMENT ON TABLE table, view, materialized view,COMMENT ON COLUMN table.column, view.column, materialized view.column
DELETE TABLEDELETE FROM table, view
EXECUTE PROCEDURECALL
Execution of any procedure or function or access to any variable, library, or cursor inside a package.
GRANT DIRECTORYGRANT privilege ON directory,REVOKE privilege ON directory
GRANT PROCEDUREGRANT privilege ON procedure, function, package,REVOKE privilege ON procedure, function, package
GRANT SEQUENCEGRANT privilege ON sequence,REVOKE privilege ON sequence
GRANT TABLEGRANT privilege ON table, view, materialized view,REVOKE privilege ON table, view, materialized view
GRANT TYPEGRANT privilege ON TYPE,REVOKE privilege ON TYPE
INSERT TABLEINSERT INTO table, view
LOCK TABLELOCK TABLE table, view
SELECT SEQUENCEAny statement containing sequence.CURRVAL or sequence.NEXTVAL
SELECT TABLESELECT FROM table, view, materialized view
UPDATE TABLEUPDATE table, view

4.4 Objects available to audit

ObjectSQL Operations
TableALTER, AUDIT, COMMENT, DELETE, FLASHBACK, GRANT, INDEX, INSERT, LOCK, RENAME, SELECT, UPDATE
ViewAUDIT, COMMENT, DELETE, FLASHBACK, GRANT, INSERT, LOCK, RENAME, SELECT, UPDATE
SequenceALTER, AUDIT, GRANT, SELECT
Procedure, Function, PackageAUDIT, EXECUTE,GRANT
Materialized ViewALTER, AUDIT, COMMENT, DELETE, INDEX, INSERT, LOCK, SELECT, UPDATE
Mining ModelAUDIT, COMMENT, GRANT, RENAME, SELECT
DirectoryAUDIT, GRANT, READ
LibraryEXECUTE, GRANT
Object TypeALTER, AUDIT, GRANT

5 Truncate audit table

  • truncate table SYS.AUD$;

5.1 DBMS_AUDIT_MGMT

  • DBA_AUDIT_MGMT_CONFIG_PARAMS;