阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

提升Oracle用户密码的安全性的技巧

175次阅读
没有评论

共计 5322 个字符,预计需要花费 14 分钟才能阅读完成。

环境:Oracle 11.2.0.4

客户需求:主要背景是数据库中有很多业务用户名,且由于部分用户缺乏安全意识,甚至直接将自己的密码设置为和用户名一样,目前客户期望密码设置不要过于简单,最起码别和用户名一致或相似就好。

1. 官方解决方案
2. 删减版解决方案
3. 测试验证方案
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@linuxidc1 >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@linuxidc1 >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@linuxidc1 >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@linuxidc1 >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@linuxidc1 >

上述查询结果 LAST_LOGIN 为空的用户,就是在审计中没有记录到该用户的登录信息。

更多 Oracle 相关信息见 Oracle 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=12

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计5322字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中