我正在創建我自定義的mod-security規則,並且我有一個關於規則ID是否影響規則執行順序的問題。ModSecurity:是否按規則ID升序執行規則?
我目前的設置是:
- 我使用MOD-安全版本:2.6.3-1ubuntu0.2
- 我國防部的安全配置是基於http://mod-security.svn.sourceforge.net/viewvc/mod-security/m2/trunk/modsecurity.conf-recommended(它有5個SecRule指令 - IDS:200000 - 200005)
- 我的規則是一個分隔的文件/etc/apache2/conf.d/modsecurity-activated-rules.conf和他們的ModSecurity的配置的/ etc/apache2的/ conf目錄後加載。 d/modsecurity.conf
我的原則是:
<IfModule mod_security2.c>
# block all GET requests - learning purposes only
SecRule REQUEST_METHOD "^(GET)$" \
"phase:1,t:none,auditlog,block,id:1001,rev:2,tag:HARDENING"
</IfModule>
Disclamer:這是一個簡單的規則,可能不是最佳的,因爲我還在學習。建議,歡迎
所以,我的問題來找我,我分析了調試文件(9級激活)後:
[...]
[4] Recipe: Invoking rule 7f157a85da30; [file "/etc/apache2/conf.d/modsecurity-activated-rules.conf"] [line "11"] [id "1001"] [rev "2"].
[5] Rule 7f157a85da30: SecRule "REQUEST_METHOD" "@rx ^(GET)$" "phase:1,log,t:none,auditlog,block,id:1001,rev:2,tag:HARDENING"
[4] Transformation completed in 4 usec.
[4] Executing operator "rx" with param "^(GET)$" against REQUEST_METHOD.
[9] Target value: "GET"
[6] Ignoring regex captures since "capture" action is not enabled.
[4] Operator completed in 36 usec.
[2] Warning. Pattern match "^(GET)$" at REQUEST_METHOD. [file "/etc/apache2/conf.d/modsecurity-activated-rules.conf"] [line "11"] [id "1001"] [rev "2"] [tag "HARDENING"]
[4] Rule returned 1.[04/Sep/2012:09:30:27 +0000] [107.21.159.51/sid#7f157a854510][rid#7f1573fcf0a0][/poll/13456492248275482/vote/yes][9] Match -> mode NEXT_RULE.
[4] Recipe: Invoking rule 7f157a85e648; [file "/etc/apache2/conf.d/modsecurity.conf"] [line "24"] [id "200000"].
[5] Rule 7f157a85e648: SecRule "REQUEST_HEADERS:Content-Type" "@rx text/xml" "phase:1,auditlog,id:200000,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=XML"
[4] Rule returned 0.
[9] No match, not chained -> mode NEXT_RULE.
[...]
由於調試線顯示,我的規則(編號:1001)首次執行在規則(id:200000)之前,即使我的規則是在20000x之後讀取的。
雖然由於OWASP ModSecurity核心規則集https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project的規則ID在950000和990000之間,並且沒有關於特定攻擊的規則ID範圍的信息,因此規則執行順序中的ID並不重要:SQLi,XSS等
通過上述,我的問題是:
- 是通過ID號來確定規則執行(最小的數字得到執行第一)?
- 是否有任何文檔定義哪些規則ID範圍應該用於自定義規則?我在尋找類似:
- 國防部的安全性主要規則:200.000 - 200.xxx
- OWASP的ModSecurity核心規則集:950.000 - 999.xxx
- 自定義規則:1.000.000 - 9.xxx .XXX
感謝您的時間。