Oracle密码管理(Password Management使用utlpwdmg.sql)

摘自:http://blog.chinaunix.net/uid-20779720-id-2547722.html

 

使用脚本utlpwdmg.sql可以方便地启动数据库的密码管理。该脚本位于$ORACLE_HOME/rdbms/admin目录下。

启动密码管理以前:

SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

SQL> select * from dba_profiles where resource_type='PASSWORD';
PROFILE                        RESOURCE_NAME                    RESOURCE LIMIT
------------------------------ -------------------------------- -------- ----------------------------------------
DEFAULT                        FAILED_LOGIN_ATTEMPTS            PASSWORD 10
DEFAULT                        PASSWORD_LIFE_TIME               PASSWORD UNLIMITED
DEFAULT                        PASSWORD_REUSE_TIME              PASSWORD UNLIMITED
DEFAULT                        PASSWORD_REUSE_MAX               PASSWORD UNLIMITED
DEFAULT                        PASSWORD_VERIFY_FUNCTION         PASSWORD NULL
DEFAULT                        PASSWORD_LOCK_TIME               PASSWORD UNLIMITED
DEFAULT                        PASSWORD_GRACE_TIME              PASSWORD UNLIMITED

启用密码管理:

SQL> @?/rdbms/admin/utlpwdmg.sql

Function created

Profile altered

启动后:

SQL> select * from dba_profiles where resource_type='PASSWORD';

PROFILE                        RESOURCE_NAME                    RESOURCE LIMIT
------------------------------ -------------------------------- -------- ----------------------------------------
DEFAULT                        FAILED_LOGIN_ATTEMPTS            PASSWORD 3
DEFAULT                        PASSWORD_LIFE_TIME               PASSWORD 90
DEFAULT                        PASSWORD_REUSE_TIME              PASSWORD 1800
DEFAULT                        PASSWORD_REUSE_MAX               PASSWORD UNLIMITED
DEFAULT                        PASSWORD_VERIFY_FUNCTION         PASSWORD VERIFY_FUNCTION
DEFAULT                        PASSWORD_LOCK_TIME               PASSWORD .0006
DEFAULT                        PASSWORD_GRACE_TIME              PASSWORD 10

如果新设定的密码不符合复杂性检验规则,就会报错。例如:

SQL> alter user lh identified by lh;

alter user lh identified by lh

ORA-28003: password verification for the specified password failed
ORA-20001: Password same as or similar to user

取消密码管理:

SQL>alter profile DEFAULT limit unlimited;
如:
SQL>alter profile DEFAULT limit password_reuse_time unlimited;

停止密码检验函数:

SQL>alter profile DEFAULT limit password_verify_function null;

熟悉utlpwdmg.sql脚本有助我们更深入了解oracle密码检查机制。我们可以修改或自定义密码检验函数。

附utlpwdmg.sql脚本内容(红色自己是我修改的):

Rem
Rem $Header: utlpwdmg.sql 31-aug-2000.11:00:47 nireland Exp $
Rem
Rem utlpwdmg.sql
Rem
Rem Copyright (c) Oracle Corporation 1996, 2000. 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    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/ as sysdba before running the script

CREATE OR REPLACE FUNCTION verify_function
(username varchar2,
password varchar2,
old_password varchar2)
RETURN boolean IS
   n boolean;
   m integer;
   differ integer;
   isdigit boolean;
   ischar boolean;
   ispunct boolean;
   digitarray varchar2(20);
   punctarray varchar2(25);
   chararray varchar2(52);

BEGIN
   digitarray:= '0123456789';
   chararray:= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
   punctarray:='!"#$%&()``*+,-/:;<=>?_';

   -- Check if the password is same as the username
   IF NLS_LOWER(password) = NLS_LOWER(username) THEN
     raise_application_error(-20001, 'Password same as or similar to user');
   END IF;
    
   -- Check for the minimum length of the password
   -- wangnc modified,2008-9-25 15:11:30,change 4 to 16.
   IF length(password) < 16 THEN
      raise_application_error(-20002, 'Password length less than 16');
   END IF;

   -- Check if the password is too simple. A dictionary of words may be
   -- maintained and a check may be made so as not to allow the words
   -- that are too simple for the password.
   -- wangnc modified,2008-9-25 15:12:17,add 'dba', 'manager', 'tiger'
   IF NLS_LOWER(password) IN ('welcome', 'database', 'account', 'user', 'password', 'oracle', 'computer', 'abcd',
     'dba', 'manager', 'tiger') THEN
      raise_application_error(-20002, 'Password too simple');
   END IF;

   -- Check if the password contains at least one letter, one digit and one
   -- punctuation mark.
   -- 1. Check for the digit
   isdigit:=FALSE;
   m := length(password);
   FOR i IN 1..10 LOOP
      FOR j IN 1..m LOOP
         IF substr(password,j,1) = substr(digitarray,i,1) THEN
            isdigit:=TRUE;
             GOTO findchar;
         END IF;
      END LOOP;
   END LOOP;
   IF isdigit = FALSE THEN
      raise_application_error(-20003, 'Password should contain at least one digit, one character and one punctuation');
   END IF;
   -- 2. Check for the character
   <>
   ischar:=FALSE;
   FOR i IN 1..length(chararray) LOOP
      FOR j IN 1..m LOOP
         IF substr(password,j,1) = substr(chararray,i,1) THEN
            ischar:=TRUE;
             GOTO findpunct;
         END IF;
      END LOOP;
   END LOOP;
   IF ischar = FALSE THEN
      raise_application_error(-20003, 'Password should contain at least one \
              digit, one character and one punctuation');
   END IF;
   -- 3. Check for the punctuation
   <>
   ispunct:=FALSE;
   FOR i IN 1..length(punctarray) LOOP
      FOR j IN 1..m LOOP
         IF substr(password,j,1) = substr(punctarray,i,1) THEN
            ispunct:=TRUE;
             GOTO endsearch;
         END IF;
      END LOOP;
   END LOOP;
   IF ispunct = FALSE THEN
      raise_application_error(-20003, 'Password should contain at least one \
              digit, one character and one punctuation');
   END IF;

   <>
   -- Check if the password differs from the previous password by at least
   -- 3 letters
   IF old_password IS NOT NULL THEN
     differ := length(old_password) - length(password);

     IF abs(differ) < 3 THEN
       IF length(password) < length(old_password) THEN
         m := length(password);
       ELSE
         m := length(old_password);
       END IF;

       differ := abs(differ);
       FOR i IN 1..m LOOP
         IF substr(password,i,1) != substr(old_password,i,1) THEN
           differ := differ + 1;
         END IF;
       END LOOP;

       IF differ < 3 THEN
         raise_application_error(-20004, 'Password should differ by at \
         least 3 characters');
       END IF;
     END IF;
   END IF;
   -- Everything is fine; return TRUE ;
   RETURN(TRUE);
END;
/


-- 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.

/*
PASSWORD_LIFE_TIME 90 --用于指定口令有效期
PASSWORD_GRACE_TIME 10 --用于指定口令宽限期(为了强制用户定期改变口令,以上二者必须同时设置.)
PASSWORD_REUSE_TIME 1800 --用于指定口令可重用时间.
PASSWORD_REUSE_MAX UNLIMITED --用于指定在重用口令之前口令需要改变的次数.(需要主要,使用口令历史选项时,只能使用以上两种其中的一个选项.并将另一个选项设置为UNLIMITED.)
FAILED_LOGIN_ATTEMPTS 3 --用于指定连续登陆的最大失败次数.
PASSWORD_LOCK_TIME 1/1440 --用于指定帐户被锁定的天数.
PASSWORD_VERIFY_FUNCTION verify_function; --如果要禁用口令校验函数,可以将PASSWORD_VERIFY_FUNCTION选项设置为NULL.
*/

ALTER PROFILE DEFAULT LIMIT
PASSWORD_LIFE_TIME 90
PASSWORD_GRACE_TIME 10
PASSWORD_REUSE_TIME 1800
PASSWORD_REUSE_MAX UNLIMITED
FAILED_LOGIN_ATTEMPTS 3
PASSWORD_LOCK_TIME 1/1440
PASSWORD_VERIFY_FUNCTION verify_function;

 

--End--

 

------------

What is Profile

profile is a database object - a named set of resource limits to:

  • Restrict database usage by a system user – profiles restrict users from performing operations that exceed reasonable resource utilization. Examples of resources that need to be managed:
  • Disk storage space.
  • I/O bandwidth to run queries.
  • CPU power.
  • Connect time.
  • Enforce password practices – how user passwords are created, reused, and validated.
  • Profiles are assigned to users as part of the CREATE USER or ALTER USER commands.
  • User accounts can have only a single profile.
  • A default profile can be created – a default already exists within Oracle named DEFAULT – it is applied to any user not assigned another profile.
  • Assigning a new profile to a user account supersedes any earlier profile.
  • Profiles cannot be assigned to roles or other profiles.

Here are some system privileges for PROFILE.

  • alter profile
  • create profile
  • drop profile

Benefits of Profile

You can enforce a limit on resource utilization using resource limit parameters Also you can maintain database secutiry by using password management feature

Resource Parameters

• SESSIONS_PER_USER

Specify the number of concurrent sessions to which you want to limit the user.

• CPU_PER_SESSION

Specify the CPU time limit for a session, expressed in hundredth of seconds.

• CPU_PER_CALL

Specify the CPU time limit for a call (a parse, execute, or fetch), expressed in hundredths of seconds.

• CONNECT_TIME

Specify the total elapsed time limit for a session, expressed in minutes.

• IDLE_TIME

Specify the permitted periods of continuous inactive time during a session, expressed in minutes. Long-running queries and other operations are not subject to this limit.

• LOGICAL_READS_PER_SESSION

Specify the permitted number of data blocks read in a session, including blocks read from memory and disk.

• LOGICAL_READS_PER_CALL

Specify the permitted the number of data blocks read for a call to process a SQL statement (a parse, execute, or fetch).

• PRIVATE_SGA

Specify the amount of private space a session can allocate in the shared pool of the system global area (SGA), expressed in bytes.

• COMPOSITE_LIMIT

Specify the total resource cost for a session, expressed in service units. Oracle Database calculates the total service units as a weighted sum of CPU_PER_SESSION, CONNECT_TIME, LOGICAL_READS_PER_SESSION, and PRIVATE_SGA.

Creating Profile

Profiles only take effect when resource limits are "turned on" for the database as a whole.

• Specify the RESOURCE_LIMIT initialization parameter.

RESOURCE_LIMIT = TRUE

Let check the parameter value.

SQL> show parameter resource_limit
NAME TYPE VALUE
------------------------------------ ----------- ---------
resource_limit boolean FALSE

Its mean resource limit is off,we ist have to enable it.

• Use the ALTER SYSTEM statement to turn on resource limits.

SQL> ALTER SYSTEM SET RESOURCE_LIMIT = TRUE;
System altered.
SQL> show parameter resource_limit
NAME TYPE VALUE
------------------------------------ ----------- ---------
resource_limit boolean TRUE

• Resource limit specifications pertaining to passwords are always in effect.

Now I'm going to create a profile with the name my_profile.

SQL> CREATE PROFILE my_profile LIMIT
SESSIONS_PER_USER 2
IDLE_TIME 5
CONNECT_TIME 10;

Profile created.


In the above example i created simple profile which will handle

SESSIONS_PER_USER <<IDLE_TIME <<CONNECT_TIME <<


NOTE:

Both parameters take values in min.

Now I'm creating a test user to check the functionality of this profile.

SQL> create user Michel identified by michel
default tablespace users
temporary tablespace temp;
User created.

 

SQL> alter user Michel profile my_profile;
User altered.

With the above statement i assigned the profile my_profile to user Michel.

Let see how our profile will work.

I already opened 2 sessions with the user name Michel but when i tried for third session it thorwed this error.

sqlplus Michel
SQL*Plus: Release 11.1.0.6.0 - Production on Mon Nov 26 15:57:23 2007
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Enter password:
ERROR:
ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit

You noticed when i tried to open third session it gave me error.

Lets go to 2nd step IDLE_TIME.Here we go again

SQL> select * from tab;
select * from tab
*
ERROR at line 1:
ORA-02396: exceeded maximum idle time, please connect again

Because i was idle more than 5 min so thats why Oracle server kill mine session.

We can check the resource parameter of our profile by querying DBA_PROFILES.

SQL> select * from dba_profiles
where profile='MY_PROFILE';
PROFILE RESOURCE_NAME RESOURCE LIMIT
------------------------------ -------------------------------- -------- ------
---------------------------------
MY_PROFILE COMPOSITE_LIMIT KERNEL DEFAUL
MY_PROFILE SESSIONS_PER_USER KERNEL 2
MY_PROFILE IDLE_TIME KERNEL 5
MY_PROFILE CONNECT_TIME KERNEL 10
.
.
.

Assigning Profile

Profile can be assign in two ways either during USER creation or by using ALTER statement.

Case 1:

SQL> create user orafaq identified by pass profile my_profile;
User created.

We can check it by using this query.

SQL> select username,profile
from dba_users
where username='ORAFAQ';
USERNAME PROFILE
------------------------------ --------------
ORAFAQ MY_PROFILE

CASE 2:

SQL> drop user orafaq cascade;
User dropped.
SQL> create user orafaq identified by pass;
User created.
SQL> alter user orafaq profile my_profile;
User altered.

Altering Profile

Profiles can be altered with the ALTER PROFILE command. • A DBA must have the ALTER PROFILE system privilege to use this command. • When a profile limit is adjusted, the new setting overrides the previous setting for the limit, but these changes do not affect current sessions in process. See the example below


SQL> ALTER PROFILE accountant LIMIT CPU_PER_CALL default LOGICAL_READS_PER_SESSION 20000 SESSIONS_PER_USER 1;

Dropping Profile

Profiles no longer required can be dropped with the DROP PROFILE command. • The DEFAULT profile cannot be dropped. • The CASCADE clause revokes the profile from any user account to which it was assigned – the CASCADE clause MUST BE USED if the profile has been assigned to any user account. • When a profile is dropped, any user account with that profile is reassigned the DEFAULT profile. See examples below:

SQL> DROP PROFILE accountant;

ERROR at line 1:

ORA-02382: profile ACCOUNTANT has users assigned, cannot drop without CASCADE

SQL> DROP PROFILE accountant CASCADE;


SQL> SELECT username, profile FROM dba_users WHERE username = 'DBUSER1'; • Changes that result from dropping a profile only apply to sessions that are created after the change – current sessions are not modified.

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据库系统: 数据库系统(Database System),是由数据库及其管理软件组成的系统。 数据库系统是为适应数据处理的需要而发展起来的一种较为理想的数据处理系统,也是一个为实际可运行的存储、维护和应用系统提供数据的软件系统,是存储介质 、处理对象和管理系统的集合体。 安全策略: 第一,系统安全策略:包括了数据库用户管理、数据库操作规范、用户认证、操作系统安全4个部分。 1)数据库用户管理。数据库用户对信息访问的最直接途径就是通过用户访问。因此需要对用户进行严格的管理,只有真正可信的人员才拥有管理数据库用户的权限; 2)数据库需要有操作规范。数据库中数据才是核心,不能有任何的破坏,数据库管理员是唯一能直接访问数据库的人员,管理员的操作是非常重要的,因此需要对数据库维护人员培训,树立严谨的工作态度,同时需要规范操作流程; 3)用户身份的认证。Oracle数据库可以使用主机操作系统认证用户,也可以使用数据库的用户认证,从安全角度出发,initSID.ora文件中的remote_os_authent参数设成FALSE,以防止没有口令的连接。建议将remote_os_roles设成FALSE,防止欺骗性连接; 4)操作系统安全。对于运行任何一种数据库的操作系统来说,都需要考虑安全问题。数据库管理员以及系统账户的口令都必须符合规定,不能过于简单而且需要定期的更换口令,对于口令的安全同样重要。系统管理员在给操作系统做维护的时候,需要与数据库管理员合作,避免。 第二,数据安全策略。 数据安全策略决定了可以访问特定数据的用户组,以及这些用户的操作权限。数据的安全性取决数据的敏感程度,如果数据不是那么敏感,则数据的安全策略则可以稍微松一些;反之则需要制定特定的安全策略,严格的控制访问对象,确保数据的安全。 第三,用户安全策略。 用户安全策略是由一般用户安全、最终用户安全、管理员安全、应用程序及开发人员安全、应用程序管理员安全5个部分组成。 1)一般用户安全。如果对于用户的认证由数据库进行管理,则安全管理员就应该制定口令安全策略来维护数据库访问的安全性。可以配置oracle使用加密口令来进行客户机/服务器连接; 2)最终用户安全。安全管理员必须为最终用户安全制定策略。如果使用的是大型数据库同时还有许多用户,这是就需要安全管理员对用户组进行分类,为每个用户组创建用户角色,并且对每个角色授予相应的权限; 3)管理员安全。安全管理员应当拥有阐述管理员安全的策略。在数据库创建后,应对SYS和SYSTEM用户名更改口令,以防止对数据库的未认证访问,且只有数据库管理员才可用; 4)应用程序开发人员安全。安全管理员必须为使用数据库的应用程序开发人员制定一套特殊的安全策略。安全管理员可以把创建必要对象的权限授予应用程序开发人员。反之,创建对象的权限只能授予数据库管理员,他从开发人员那里接收对象创建请求; 5)应用程序管理员安全。在有许多数据库应用程序的大型数据库系统中,可以设立应用程序管理员 第四,口令管理策略。口令管理包括账户锁定、口令老化及到期、口令历史记录、口令复杂性校验。 1)帐户锁定。当某一特定用户超过了失败登录尝试的指定次数,服务器会自动锁定这个用户帐户; 2)口令老化及到期。DBA使用CREATE PROFILE语句指定口令的最大生存期,当到达了指定的时间长度则口令到期,用户或DBA必须变更口令; 3)口令历史记录。DBA使用CREATE PROFILE语句指定时间间隔,在这一间隔内用户不能重用口令; 4)口令复杂性校验。通过使用PL/SQL脚本utlpwdmg.sql(它设置缺省的概要文件参数),可以指定口令复杂性校验例行程序。 常见数据库系统: MySQL MySQL是一个快速的、多线程、多用户和健壮的SQL数据库服务器。MySQL服务器支持关键任务、重负载生产系统的使用,也可以将它嵌入到一个大配置(mass- deployed)的软件中去。 SQL Server SQL Server 提供了众多的Web和电子商务功能,如对XML和Internet标准的丰富支持,通过Web对数据进行轻松安全的访问,具有强大的、灵活的、基于Web的和安全的应用程序管理等。 Oracle Oracle产品系列齐全,几乎囊括所有应用领域,大型,完善,安全,可以支持多个实例同时运行,功能强。能在所有主流平台上运行。完全支持所有的工业标准。采用完全开放策略。可以使客户选择最适合的解决方案。对开发商全力支持。
数据库管理系统检查命令清单全文共2页,当前为第1页。数据库管理系统检查命令清单全文共2页,当前为第1页。数据库管理系统测评检查命令 数据库管理系统检查命令清单全文共2页,当前为第1页。 数据库管理系统检查命令清单全文共2页,当前为第1页。 Oracle 数据库 命令 说明 Oracle数据库管理系统测评检查命令 数据库检查时主要使用select只读查看命令,主要查看用户情况、安全策略配置文件、日志等。 cat /$ORACLE_HOME/rdbms/admin/utlpwdmg.sql cat /$ORACLE_HOME/network/admin/sqlnet.ora select * from v$version; select username,account_status from dba_users; select resource_name,limit from dba_profiles where profile='DEFAULT'; select granted_role from dba_role_privs where grantee='PUBLIC'; show parameter O7_DICTIONARY_ACCESSIBILITY; show parameter audit show parameter audit_sys_operations; show parameter audit_trail; select * from dba_stmt_audit_opts; select grantee from dba_tab_privs where table_name='AUD$' and grantee not in ('DELETE_CATALOG_ROLE') and grantee not in (select grantee from dba_role_privs where granted_role='DBA'); select resource_name,limit from dba_profiles where profile='DEFAULT' and resource_type='KERNEL'; select username,profile from dba_users; select * from dba_role_privs where granted_role= 'DBA'; select * from V_$PWFILE_USERS; archive log list; show parameter log_archive_dest; select * from role_sys_privs; select * from dba_sys_privs select policy_name,status from dba_sa_policies; select * from sys.aud$ where ROWNUM<5; SELECT name,password FROM user$ WHERE name='SYS'; select name from v$database; select instance_name from v$instance; Mysql 数据库管理系统检查命令清单全 共2页,当前为第2页。数据库管理系统检查命令清单全文共2页,当前为第2页。Mysql数据管理系统测评检查命令 数据库管理系统检查命令清单全 共2页,当前为第2页。 数据库管理系统检查命令清单全文共2页,当前为第2页。 数据库检查时主要使用select只读查看命令,主要查看用户情况、安全策略配置文件、日志等(连接数据库:mysql –uusername –ppassword show databases;use mysql;) cat my.ini select user(); select host,user,password from mysql.user; show global variables like "%timeout%"; show variables like '%skip_networking%'; show variables like 'log_%'; show variables; select * from mysql.user; select version(); netstat -lnpt " grep 3306 cat .mysql_history cat /etc/my.cnf SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值