绿盟 rhel6的oracle 基线修复脚本。

注意事项:
1、脚本中数据库用户oracle的密码为Oracle_123,可修改
2、Rac库中,grid用户不要放在dba组中。
3、revoke execute on 'UTL_FILE','UTL_TCP','UTL_HTTP','UTL_SMTP','DBMS_LOB','DBMS_SYS_SQL','DBMS_JOB' from public;这条sql可能会导致alert日志报错,若出现则重新授予即可。

如下是jixian.sql的内容:

点击(此处)折叠或打开

  1. /*创建密码复杂度函数VERIFY_FUNCTION2*/
  2. CREATE OR REPLACE FUNCTION sys."VERIFY_FUNCTION2" (
  3. username varchar2,
  4. password varchar2,
  5. old_password varchar2)
  6. RETURN boolean IS
  7. n boolean;
  8. m integer;
  9. differ integer;
  10. isdigit boolean;
  11. ischar boolean;
  12. ispunct boolean;
  13. digitarray varchar2(20);
  14. punctarray varchar2(25);
  15. chararray varchar2(52);

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

  20.    -- Check if the password is same as the username
  21.    IF NLS_LOWER(password) = NLS_LOWER(username) THEN
  22.      raise_application_error(-20001, 'Password same as or similar to user');
  23.    END IF;

  24.    -- Check for the minimum length of the password
  25.    IF length(password) < 8 THEN
  26.       raise_application_error(-20002, 'Password length less than 8');
  27.    END IF;

  28.    -- Check if the password is too simple. A dictionary of words may be
  29.    -- maintained and a check may be made so as not to allow the words
  30.    -- that are too simple for the password.
  31.    IF NLS_LOWER(password) IN ('welcome', 'database', 'account', 'user', 'password', 'oracle', 'computer', 'abcd') THEN
  32.       raise_application_error(-20002, 'Password too simple');
  33.    END IF;

  34.    -- Check if the password contains at least one letter, one digit and one
  35.    -- punctuation mark.
  36.    -- 1. Check for the digit
  37.    isdigit:=FALSE;
  38.    m := length(password);
  39.    FOR i IN 1..10 LOOP
  40.       FOR j IN 1..m LOOP
  41.          IF substr(password,j,1) = substr(digitarray,i,1) THEN
  42.             isdigit:=TRUE;
  43.              GOTO findchar;
  44.          END IF;
  45.       END LOOP;
  46.    END LOOP;
  47.    IF isdigit = FALSE THEN
  48.       raise_application_error(-20003, 'Password should contain at least one digit, one character and one punctuation');
  49.    END IF;
  50.    -- 2. Check for the character
  51.    <<findchar>>
  52.    ischar:=FALSE;
  53.    FOR i IN 1..length(chararray) LOOP
  54.       FOR j IN 1..m LOOP
  55.          IF substr(password,j,1) = substr(chararray,i,1) THEN
  56.             ischar:=TRUE;
  57.              GOTO findpunct;
  58.          END IF;
  59.       END LOOP;
  60.    END LOOP;
  61.    IF ischar = FALSE THEN
  62.       raise_application_error(-20003, 'Password should contain at least one \
  63.               digit, one character and one punctuation');
  64.    END IF;
  65.    -- 3. Check for the punctuation
  66.    <<findpunct>>
  67.    ispunct:=FALSE;
  68.    FOR i IN 1..length(punctarray) LOOP
  69.       FOR j IN 1..m LOOP
  70.          IF substr(password,j,1) = substr(punctarray,i,1) THEN
  71.             ispunct:=TRUE;
  72.              GOTO endsearch;
  73.          END IF;
  74.       END LOOP;
  75.    END LOOP;
  76.    IF ispunct = FALSE THEN
  77.       raise_application_error(-20003, 'Password should contain at least one \
  78.               digit, one character and one punctuation');
  79.    END IF;

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

  85.      IF abs(differ) < 3 THEN
  86.        IF length(password) < length(old_password) THEN
  87.          m := length(password);
  88.        ELSE
  89.          m := length(old_password);
  90.        END IF;

  91.        differ := abs(differ);
  92.        FOR i IN 1..m LOOP
  93.          IF substr(password,i,1) != substr(old_password,i,1) THEN
  94.            differ := differ + 1;
  95.          END IF;
  96.        END LOOP;

  97.        IF differ < 3 THEN
  98.          raise_application_error(-20004, 'Password should differ by at \
  99.          least 3 characters');
  100.        END IF;
  101.      END IF;
  102.    END IF;
  103.    -- Everything is fine; return TRUE ;
  104.    RETURN(TRUE);
  105. END;
  106. /

  107. /*创建应用用户profile APP_PROF*/
  108. create profile APP_PROF limit
  109. failed_login_attempts 6
  110. password_life_time 360
  111. password_reuse_time 60
  112. password_reuse_max 5
  113. password_lock_time .0004
  114. password_grace_time 5
  115. password_verify_function VERIFY_FUNCTION2;

  116. /*创建系统用户profile SYS_PROF*/
  117. create profile SYS_PROF limit
  118. failed_login_attempts 6
  119. password_life_time 180
  120. password_reuse_time 60
  121. password_reuse_max 5
  122. password_lock_time .001
  123. password_grace_time 30
  124. password_verify_function VERIFY_FUNCTION2;

  125. /*创建具名用户profile CMSZ_PROF*/
  126. create profile CMSZ_PROF limit
  127. failed_login_attempts 6
  128. password_life_time 180
  129. password_reuse_time 60
  130. password_reuse_max 5
  131. password_lock_time .01
  132. password_grace_time 60
  133. password_verify_function VERIFY_FUNCTION2;

  134. /*禁止具有数据库超级管理员(SYSDBA)权限的用户从远程登陆*/
  135. alter system set remote_login_passwordfile=NONE scope=spfile sid='*';

  136. /*限制只有SYSDBA用户才能访问数据字典基础表*/
  137. alter system set O7_DICTIONARY_ACCESSIBILITY=FALSE scope=spfile sid='*';

  138. /*禁止从其他OS登录认证*/
  139. alter system set REMOTE_OS_AUTHENT=FALSE scope=spfile sid='*';

  140. /*开启数据库审计功能*/
  141. alter system set audit_trail=DB scope=spfile sid='*';

  142. /*创建用户登录触发器*/
  143. create table LOGIN_LOG(
  144. SESSION_ID NUMBER(32,0) NOT NULL,
  145. LOGIN_ON_TIME DATE,
  146. USER_IN_DB VARCHAR(50),
  147. IP_ADDRESS VARCHAR(20)
  148. );

  149. create trigger LOGIN_INFO
  150. after logon on database
  151. begin
  152. insert into LOGIN_LOG(SESSION_ID,LOGIN_ON_TIME,USER_IN_DB,IP_ADDRESS) select AUDSID,sysdate,sys.login_user,SYS_CONTEXT('USERENV','IP_ADDRESS') from v$session where AUDSID=USERENV('SESSIONID');
  153. end;
  154. /

  155. /*回收public角色执行权限*/
  156. declare
  157.     cursor c1 is
  158.     select table_name from dba_tab_privs
  159.     where grantee='PUBLIC' and privilege='EXECUTE'
  160.     and table_name in ('UTL_FILE','UTL_TCP','UTL_HTTP','UTL_SMTP','DBMS_LOB','DBMS_SYS_SQL','DBMS_JOB');
  161.     
  162.     v_table_name varchar2(20);
  163.     v_sql varchar2(100);
  164.     
  165. begin
  166.     open c1;
  167.     loop
  168.         fetch c1 into v_table_name;
  169.         exit when c1%notfound;
  170.         v_sql := 'revoke execute on '||v_table_name||' from public';
  171.         execute immediate v_sql;
  172.     end loop;
  173.     close c1;
  174. end;
  175. /

  176. /*回收非系统DBA用户的DBA权限*/
  177. declare
  178.     cursor c1 is
  179.     select a.username from dba_users a left join dba_role_privs b on a.username = b.grantee where granted_role = 'DBA' and a.username not in ('SYS','SYSMAN','SYSTEM');

  180.     v_user_name varchar2(100);
  181.     v_sql varchar2(100);
  182. begin
  183.     open c1;
  184.     loop
  185.         fetch c1 into v_user_name;
  186.         exit when c1%notfound;
  187.         v_sql := 'revoke dba from '||v_user_name||' ';
  188.         execute immediate v_sql;
  189.     end loop;
  190.     close c1;
  191. end;
  192. /

  193. /*修改lock和expire系统用户默认密码*/
  194. declare
  195.     cursor c1 is
  196.     select username from dba_users where ACCOUNT_STATUS like 'EXPIRED%LOCKED' and profile='DEFAULT' and username <> 'XS$NULL';

  197.     v_user_name varchar2(100);
  198.     v_sql1 varchar2(100);
  199.     v_sql2 varchar2(100);

  200. begin
  201.     open c1;
  202.     loop
  203.         fetch c1 into v_user_name;
  204.         exit when c1%notfound;
  205.         v_sql1 := 'alter user '||v_user_name||' identified by Oracle_123';
  206.         v_sql2 := 'alter user '||v_user_name||' password expire';    
  207.         execute immediate v_sql1;
  208.         execute immediate v_sql2;
  209.     end loop;
  210.     close c1;
  211. end;
  212. /

  213. /*修改open系统用户默认密码和profile*/
  214. declare
  215.     cursor c1 is
  216.     select username from dba_users where ACCOUNT_STATUS = 'OPEN' and profile ='DEFAULT' and username in ('SYS','SYSTEM','OUTLN','FLOWS_FILES','MDSYS','ORDSYS','EXFSYS','DBSNMP','WMSYS','APPQOSSYS','APEX_030200','ORDDATA','CTXSYS','ANONYMOUS',
  217. 'XDB','ORDPLUGINS','SI_INFORMTN_SCHEMA','OLAPSYS','ORACLE_OCM','XS$NULL','MDDATA','DIP','APEX_PUBLIC_USER','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR');

  218.     v_user_name varchar2(100);
  219.     v_sql1 varchar2(100);
  220.     v_sql2 varchar2(100);

  221. begin
  222.     open c1;
  223.     loop
  224.         fetch c1 into v_user_name;
  225.         exit when c1%notfound;
  226.         v_sql1 := 'alter user '||v_user_name||' identified by Oracle_123';
  227.         v_sql2 := 'alter user '||v_user_name||' profile SYS_PROF';        
  228.         execute immediate v_sql1;
  229.         execute immediate v_sql2;
  230.     end loop;
  231.     close c1;
  232. end;
  233. /

  234. /*修改Locked系统用户过期*/
  235. declare
  236.     cursor c1 is
  237.     select username from dba_users where ACCOUNT_STATUS = 'LOCKED' and profile ='DEFAULT';

  238.     v_user_name varchar2(100);
  239.     v_sql varchar2(100);

  240. begin
  241.     open c1;
  242.     loop
  243.         fetch c1 into v_user_name;
  244.         exit when c1%notfound;
  245.         v_sql := 'alter user '||v_user_name||' password expire';    
  246.         execute immediate v_sql;
  247.     end loop;
  248.     close c1;
  249. end;
  250. /



  251. /*修改open应用用户profile*/
  252. declare
  253.     cursor c1 is
  254.     select username from dba_users where ACCOUNT_STATUS = 'OPEN' and profile ='DEFAULT' and username not in ('SYS','SYSTEM','OUTLN','FLOWS_FILES','MDSYS','ORDSYS','EXFSYS','DBSNMP','WMSYS','APPQOSSYS','APEX_030200','ORDDATA','CTXSYS','ANONYMOUS',
  255. 'XDB','ORDPLUGINS','SI_INFORMTN_SCHEMA','OLAPSYS','ORACLE_OCM','XS$NULL','MDDATA','DIP','APEX_PUBLIC_USER','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR');

  256.     v_user_name varchar2(100);
  257.     v_sql varchar2(100);

  258. begin
  259.     open c1;
  260.     loop
  261.         fetch c1 into v_user_name;
  262.         exit when c1%notfound;
  263.         v_sql := 'alter user '||v_user_name||' profile APP_PROF';
  264.         execute immediate v_sql;
  265.     end loop;
  266.     close c1;
  267. end;
  268. /


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31441616/viewspace-2152524/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31441616/viewspace-2152524/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值