技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> Oracle --> 使用审计功能记录错误密码登陆信息

使用审计功能记录错误密码登陆信息

浏览:1029次  出处信息

恢复完UAT环境,发现业务用户总被锁定,问谁都说自己的程序密码是对的,本来想写个触发器记录是谁总用错误的密码登陆数据库,发现这个数据库的审计没有关闭(11g默认审计功能是开启的),是打开的。数据库版本11.2.0.4。

1SQL> show parameter audit
2
3NAME                                 TYPE        VALUE
4------------------------------------ ----------- ------------------------------
5audit_file_dest                      string      /u01/app/oracle/admin/PROD/adu
6                                                 mp
7audit_sys_operations                 boolean     FALSE
8audit_syslog_level                   string
9audit_trail                          string      DB

在11g如果没有关闭掉审计的功能,默认是可以记录错误密码登陆信息的,很幸运的是,这个功能并没有被禁掉。那么查询AUD$表就能查询到错误密码登陆信息。以下是在没有做过任何设置的11.2.0.4.0版本的数据库中做的测试,先使用错误密码登陆数据库。

01[oracle@secdb1 admin]$ sqlplus dbdream/oracle@localhost/PROD
02
03SQL*Plus: Release 11.2.0.4.0 Production on Thu Jul 16 11:48:17 2015
04
05Copyright (c) 1982, 2013, Oracle.  All rights reserved.
06
07ERROR:
08ORA-01017: invalid username/password; logon denied
09
10Enter user-name:
11ERROR:
12ORA-01017: invalid username/password; logon denied
13
14Enter user-name:
15ERROR:
16ORA-01017: invalid username/password; logon denied
17
18SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

查询AUD$表,其中returncode字段记录的就是用户登录信息,1017位密码错误,登录失败,0为正常登录数据库。

1SQL> select userid,userhost,terminal,returncode,spare1 from aud$;
2
3USERID     USERHOST   TERMINAL   RETURNCODE SPARE1
4---------- ---------- ---------- ---------- ----------
5DBDREAM    secdb1     pts/1            1017 oracle

11g默认不止开启了错误密码登陆的审计,正常登录到数据库的连接也会被审计到,下面先通过正确的密码登陆数据库。

01[oracle@secdb1 ~]$ sqlplus dbdream/dbdream@localhost/PROD
02
03SQL*Plus: Release 11.2.0.4.0 Production on Thu Jul 16 11:54:21 2015
04
05Copyright (c) 1982, 2013, Oracle.  All rights reserved.
06
07Connected to:
08Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
09With the Partitioning, OLAP, Data Mining and Real Application Testing options
10
11SQL>

查询AUD$表会发现,这个连接也被记录了。

1SQL> select userid,userhost,terminal,returncode,spare1 from aud$;
2
3USERID     USERHOST   TERMINAL   RETURNCODE SPARE1
4---------- ---------- ---------- ---------- ----------
5DBDREAM    secdb1     pts/1            1017 oracle
6DBDREAM    secdb1     pts/1               0 oracle

在10g版本,审计默认是关闭的,下面是10.2.0.1.0版本的数据库,审计默认关闭。

01SYS@EMREP> select * from v$version;
02
03BANNER
04----------------------------------------------------------------
05Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
06PL/SQL Release 10.2.0.1.0 - Production
07CORE    10.2.0.1.0      Production
08TNS for Linux: Version 10.2.0.1.0 - Production
09NLSRTL Version 10.2.0.1.0 - Production
10
11SYS@EMREP> show parameter audit
12
13NAME                                 TYPE        VALUE
14------------------------------------ ----------- ------------------------------
15audit_file_dest                      string      /u01/app/oracle/admin/EMREP/ad
16                                                 ump
17audit_sys_operations                 boolean     FALSE
18audit_syslog_level                   string
19audit_trail                          string      NONE

打开审计功能,看看是否可以审计到用户登录信息。

01YS@EMREP> alter system set audit_trail=db scope=spfile;
02
03System altered.
04
05SYS@EMREP> startup force
06ORACLE instance started.
07
08Total System Global Area  587202560 bytes
09Fixed Size                  1220724 bytes
10Variable Size             188747660 bytes
11Database Buffers          394264576 bytes
12Redo Buffers                2969600 bytes
13Database mounted.
14Database opened.
15SYS@EMREP> show parameter audit
16
17NAME                                 TYPE        VALUE
18------------------------------------ ----------- ------------------------------
19audit_file_dest                      string      /u01/app/oracle/admin/EMREP/ad
20                                                 ump
21audit_sys_operations                 boolean     FALSE
22audit_syslog_level                   string
23audit_trail                          string      DB

audit_trail是静态参数,修改后需要重启数据库才能生效。使用错误的密码登陆数据库,看看是否会被审计到。

01[oracle@dbdream admin]$ sqlplus dbdream/oracle@localhost/EMREP
02
03SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jul 16 13:13:57 2015
04
05Copyright (c) 1982, 2005, Oracle.  All rights reserved.
06
07ERROR:
08ORA-01017: invalid username/password; logon denied
09
10Enter user-name:
11ERROR:
12ORA-01017: invalid username/password; logon denied
13
14Enter user-name:
15ERROR:
16ORA-01017: invalid username/password; logon denied
17
18SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

查询AUD$表,看看是否记录错误密码登陆的信息。

1SYS@EMREP> select userid,userhost,terminal,returncode,spare1 from aud$;
2
3no rows selected

10g版本的审计默认是不记录错误密码登陆的信息,需要手动设置。

1SYS@EMREP> audit session whenever not successful;
2
3Audit succeeded.

再次使用错误密码登陆数据库,此时就会被记录下来。

01Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
02With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
03[oracle@dbdream admin]$ sqlplus dbdream/oracle@localhost/EMREP
04
05SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jul 16 13:15:04 2015
06
07Copyright (c) 1982, 2005, Oracle.  All rights reserved.
08
09ERROR:
10ORA-01017: invalid username/password; logon denied
11
12Enter user-name:
13ERROR:
14ORA-01017: invalid username/password; logon denied
15
16Enter user-name:
17ERROR:
18ORA-01017: invalid username/password; logon denied
19
20SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
21
22SYS@EMREP> select userid,userhost,terminal,returncode,spare1 from aud$;
23
24USERID     USERHOST   TERMINAL   RETURNCODE SPARE1
25---------- ---------- ---------- ---------- ----------
26DBDREAM    dbdream    pts/2            1017 oracle

那么正常登录到数据库是否会被审计记录下来呢?下面使用正确的密码登陆数据库。

01[oracle@dbdream admin]$ sqlplus dbdream/dbdream@localhost/EMREP
02
03SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jul 16 13:16:07 2015
04
05Copyright (c) 1982, 2005, Oracle.  All rights reserved.
06
07Connected to:
08Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
09With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
10
11DBDREAM@localhost/EMREP>
12
13SYS@EMREP> select userid,userhost,terminal,returncode,spare1 from aud$;
14
15USERID     USERHOST   TERMINAL   RETURNCODE SPARE1
16---------- ---------- ---------- ---------- ----------
17DBDREAM    dbdream    pts/2            1017 oracle

查询发现正常登录数据库的操作并没有被记录下来,要想记录正常登录的信息,也需要手动配置。

01SYS@EMREP> audit session whenever successful;
02
03Audit succeeded.
04
05SYS@EMREP> !
06[oracle@dbdream admin]$ sqlplus dbdream/dbdream@localhost/EMREP
07
08SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jul 16 13:17:51 2015
09
10Copyright (c) 1982, 2005, Oracle.  All rights reserved.
11
12Connected to:
13Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
14With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
15
16DBDREAM@localhost/EMREP> exit
17Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
18With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
19[oracle@dbdream admin]$ exit
20exit
21
22SYS@EMREP> select userid,userhost,terminal,returncode,spare1 from aud$;
23
24USERID     USERHOST   TERMINAL   RETURNCODE SPARE1
25---------- ---------- ---------- ---------- ----------
26DBDREAM    dbdream    pts/2            1017 oracle
27DBDREAM    dbdream    pts/2               0 oracle

11g简化了审计的配置,但是AUD$表会越来越大,需要定期清理,而很多人是不会注意这些的,就会导致system表空间使用率很高。


建议继续学习:

  1. 一个登陆认证系统    (阅读:3450)
  2. Oracle中审计删除(DELETE)操作的触发器    (阅读:1788)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1