ORACLE 限制某些IP、使用者的對重要表的惡意操作

來源:互聯網
上載者:User

標籤:can   參數   ddr   sql   als   exe   add   替代   ica   

1,問題描述
         Oracle預設帳號是沒有限制ip的,這樣的隱患就在於,如果我知道了oracle帳號使用者名稱密碼,我只要能串連到db,就可以對db進行操作,這樣對於線上的db來說是很危險的,因為有些非dba人員,比如開發人員、測試人員一不小心誤刪除了線上的資料,就慘了。所以要找一種辦法,在一些重要的表上加觸發器來限制使用者對線上db的表的操作。
 
2,觸發器編寫
如果開全域的sql審計,消耗效能太大,不太合適,想來只有在某些重要的表上做限制,初步解決問題了。
1)驗證ip:(sys_context(‘userenv‘,‘ip_address‘)not in(‘192.168.120.211‘)
2)驗證使用者名稱:selects.USERNAME into v_username from v$session s where s.audsid=(selectuserenv(‘SESSIONID‘) from dual) and rownum<2
3)範例預存程序如下:

create or replace trigger  pri_stu_test_limit before update or delete or insert on stu.zzz_testDECLARE  PRAGMA AUTONOMOUS_TRANSACTION;    //自治事務。對於定義成自治事務的Procedure,實際上相當於一段獨立啟動並執行程式段,這段程式不依賴於主程式,也不干涉主程式      v_username varchar2(200) default ‘‘;BEGIN  select s.USERNAME into v_username from v$session s wheres.audsid=(select userenv(‘SESSIONID‘) from dual) and rownum<2;   IF deleting   AND (sys_context(‘userenv‘,‘ip_address‘) not in(‘192.168.120.211‘) OR ‘stuuser‘ like v_username)      THEN       RAISE_APPLICATION_ERROR(-20001, ‘can not delete the table ‘);     //用於在plsql使用程式中自訂不正確訊息
                                             文法為:raise_application_error(error_number,message[,[true|false]]);
                                                error_number用於定義不正確號,該不正確號必須在-20000到-20999之間的負整數;
                                                message用於指定不正確訊息,並且該訊息的長度無法超過2048位元組;
                                                第三個參數假如為true,則該不正確會被放在先前不正確堆棧中,假如為false(預設值)則會替代先前所有不正確。
ELSIF inserting AND (sys_context(‘userenv‘,‘ip_address‘) not in(‘192.168.120.211‘) OR ‘stuuser‘ like v_username)   THEN     RAISE_APPLICATION_ERROR(-20001, ‘can not insert the table ‘); ELSIF updating AND (sys_context(‘userenv‘,‘ip_address‘) not in(‘192.168.120.211‘) OR ‘stuuser‘ like v_username)   THEN      RAISE_APPLICATION_ERROR(-20001, ‘can not update the table ‘); END IF;END;

 


4)驗證:
SQL>
SQL> insert into stu.zzz_testvalues(3,‘zhuren33‘);
insert into stu.zzz_testvalues(3,‘zhuren33‘)
ORA-20001: can not insert the table
ORA-06512: at"stuuser.PRI_STU_ACCT_LIMIT", line 18
ORA-04088: error during execution oftrigger ‘stuuser.PRI_STU_ACCT_LIMIT‘
SQL> commit;
Commit complete
 
SQL>
SQL> update stu.zzz_test setremark=‘zhuren33_up‘ where id=3;
update stu.zzz_test setremark=‘zhuren33_up‘ where id=3
ORA-20001: can not update the table
ORA-06512: at"stuuser.PRI_STU_ACCT_LIMIT", line 22
ORA-04088: error during execution oftrigger ‘stuuser.PRI_STU_ACCT_LIMIT‘
SQL> commit;
Commit complete
 
SQL>
SQL> delete from  stu.zzz_test where id=3;
delete from stu.zzz_test where id=3
ORA-20001: can not delete the table
ORA-06512: at"stuuser.PRI_STU_ACCT_LIMIT", line 14
ORA-04088: error during execution oftrigger ‘stuuser.PRI_STU_ACCT_LIMIT‘
SQL> commit;
Commit complete
 
SQL>
// OK增刪改都可以被限制住了,應該暫時解決了問題。

ORACLE 限制某些IP、使用者的對重要表的惡意操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.