环境:oracle 11.2.0.4
客户需求:主要背景是数据库中有很多业务用户名,且由于部分用户缺乏安全意识,甚至直接将自己的密码设置为和用户名一样,目前客户期望密码设置不要过于简单,最起码别和用户名一致或相似就好。
1.官方解决方案
实际上oracle提供有一个非常好用的安全校验函数,来提升用户密码的复杂性。这个在之前的文章《oracle 11g 安全加固》中的“1.8.数据库密码安全性校验函数”章节就已经有了确切的解决方案,核心内容如下:
select limit from dba_profiles where profile='default' and resource_name='password_verify_function'; prompt ============================= prompt == 8.数据库密码安全性校验函数 prompt ============================= prompt 执行创建安全性校验函数的脚本 @?/rdbms/admin/utlpwdmg.sql select limit from dba_profiles where profile='default' and resource_name='password_verify_function';
2.删减版解决方案
上面这个自带的安全性校验函数对检查过于严苛,而客户目前的需求就只有一个,不允许密码和用户名完全一样或过于相似就可以了。于是乎,我就从这个脚本中找到这项需求,把其他暂时不需要的部分全部去掉。这样,就得到了如下的删减版脚本:
rem rem $header: rdbms/admin/utlpwdmg1.sql /st_rdbms_11.2.0/1 2013/01/31 01:34:11 skayoor exp $ rem rem utlpwdmg.sql rem rem copyright (c) 2006, 2013, oracle and/or its affiliates. rem all rights reserved. rem rem name rem utlpwdmg.sql - script for default password resource limits rem rem description rem this is a script for enabling the password management features rem by setting the default password resource limits. rem rem notes rem this file contains a function for minimum checking of password rem complexity. this is more of a sample function that the customer rem can use to develop the function for actual complexity checks that the rem customer wants to make on the new password. rem rem modified (mm/dd/yy) rem skayoor 01/17/13 - backport skayoor_bug-14671375 from main rem asurpur 05/30/06 - fix - 5246666 beef up password complexity check rem nireland 08/31/00 - improve check for username=password. #1390553 rem nireland 06/28/00 - fix null old password test. #1341892 rem asurpur 04/17/97 - fix for bug479763 rem asurpur 12/12/96 - changing the name of password_verify_function rem asurpur 05/30/96 - new script for default password management rem asurpur 05/30/96 - created rem -- this script sets the default password resource parameters -- this script needs to be run to enable the password features. -- however the default resource parameters can be changed based -- on the need. -- a default password complexity function is also provided. -- this function makes the minimum complexity checks like -- the minimum length of the password, password not same as the -- username, etc. the user may enhance this function according to -- the need. -- this function must be created in sys schema. -- connect sys/<password> as sysdba before running the script create or replace function verify_function_11g_wjzyy (username varchar2, password varchar2, old_password varchar2) return boolean is n boolean; m integer; differ integer; isdigit boolean; ischar boolean; ispunct boolean; db_name varchar2(40); digitarray varchar2(20); punctarray varchar2(25); chararray varchar2(52); i_char varchar2(10); simple_password varchar2(10); reverse_user varchar2(32); begin digitarray:= '0123456789'; chararray:= 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'; -- check if the password is same as the username or username(1-100) if nls_lower(password) = nls_lower(username) then raise_application_error(-20002, 'password same as or similar to user'); end if; for i in 1..100 loop i_char := to_char(i); if nls_lower(username)|| i_char = nls_lower(password) then raise_application_error(-20005, 'password same as or similar to user name '); end if; end loop; -- everything is fine; return true ; return(true); end; / grant execute on verify_function_11g_wjzyy to public; -- this script alters the default parameters for password management -- this means that all the users on the system have password management -- enabled and set to the following values unless another profile is -- created with parameter values set to different value or unlimited -- is created and assigned to the user. alter profile default limit password_life_time 180 password_verify_function verify_function_11g_wjzyy;
我们将这个脚本,遵守之前oracle的命名方式,将其命名为utlpwdmg1.sql,放在同样的路径下。
这样,我们执行这个脚本就可以创建这个校验函数:
3.测试验证方案
将上面的删减版脚本进行测试并验证功能是否实现:
--执行脚本创建校验函数 @?/rdbms/admin/utlpwdmg1.sql --确认执行成功 select limit from dba_profiles where profile='default' and resource_name='password_verify_function'; --将password_life_time修改为30(选做) alter profile default limit password_life_time 30; --查询dba_profiles内容 select * from dba_profiles order by 1; --查询用户状态和过期时间 select username, password, account_status, lock_date, expiry_date from dba_users;
测试用户密码不能与用户名相同或者相似,否则会修改失败:
--密码与用户名一样,修改失败: sys@jyzhao1 >alter user jingyu identified by jingyu; alter user jingyu identified by jingyu * error at line 1: ora-28003: password verification for the specified password failed ora-20002: password same as or similar to user --密码与用户名相似,修改失败: sys@jyzhao1 >alter user jingyu identified by jingyu1; alter user jingyu identified by jingyu1 * error at line 1: ora-28003: password verification for the specified password failed ora-20005: password same as or similar to user name --密码与用户名不一致,修改成功: sys@jyzhao1 >alter user jingyu identified by alfred; user altered.
4.用户最近一次的登录时间
11g默认开启了审计,从aud$表中可以查到用户最近登录的时间:
--查询数据库时区 select property_value from database_properties where property_name='dbtimezone'; --查询aud$表 select max(to_char(a.ntimestamp#, 'yyyy-mm-dd hh24:mi:ss')) last_login, u.username from sys.aud$ a, dba_users u where a.userid(+) = u.username and u.user_id > 90 group by u.username order by 1;
结果示例:
sys@jyzhao1 >select max(to_char(a.ntimestamp#, 'yyyy-mm-dd hh24:mi:ss')) last_login, 2 u.username 3 from sys.aud$ a, dba_users u 4 where a.userid(+) = u.username 5 and u.user_id > 90 6 group by u.username 7 order by 1; last_login username ------------------- ------------------------------ 2018-04-17 07:16:46 jingyu testtesttest xs$null sys@jyzhao1 >
上述查询结果last_login为空的用户,就是在审计中没有记录到该用户的登录信息。
总结
以上所述是www.887551.com给大家介绍的提升oracle用户密码安全性的策略,希望对大家有所帮助