簡體   English   中英

Apache2 ModSecurity2不起作用(Ubuntu 14.04)

[英]Apache2 ModSecurity2 does not work (Ubuntu 14.04)

我遵循wiki.ubuntuusers.de上的官方文檔,但是我的test.php文件仍然允許惡意訪問,例如test.php?secret_file = my / secret / file.txt。 想法為什么?

test.php的:

<?php
    $secret_file = $_GET['secret_file'];
    include ( $secret_file);
?>

test.php?secret_file = my / secret / file.txt的預期結果是HTTP 403-訪問被拒絕,但是我的Web服務器仍顯示包含文件的內容。

我的安裝步驟:

sudo apt-get install libapache2-mod-security2
sudo a2enmod security2
sudo a2enmod headers

Configuration

sudo cp /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf

# Enable ModSecurity, attaching it to every transaction. Use detection
# only to start with, because that minimises the chances of post-installation
# disruption.
#
#SecRuleEngine DetectionOnly
#
SecRuleEngine On                                   

Include /usr/share/modsecurity-crs/*.conf
Include /usr/share/modsecurity-crs/base_rules/*.conf
Include /usr/share/modsecurity-crs/optional_rules/*.conf

SecDebugLog /var/log/apache2/modsec_debug.log
SecDebugLogLevel 5

sudo service apache2 restart
sudo service apache2 force-reload 

這是我的modsec_debug.log文件: modsec_debug.log

當我致電惡意test.php?secret_file = my / secret / file.txt時,它說:

[Sun Jan 25 13:21:51.773188 2015] [:error] [pid 14993] [client x.x.x.x] ModSecurity: Warning. Match of "eq 1" against "&ARGS:CSRF_TOKEN" required. [file "/usr/share/modsecurity-crs/optional_rules/modsecurity_crs_43_csrf_protection.conf"] [line "31"] [id "981143"] [msg "CSRF Attack Detected - Missing CSRF Token."] [hostname "example.com"] [uri "/test.php"] [unique_id "VMTf31XWGY4AADqRE00AAAAB"]

[Sun Jan 25 13:21:51.777069 2015] [:error] [pid 14993] [client x.x.x.x] ModSecurity: Warning. Operator LT matched 5 at TX:inbound_anomaly_score. [file "/usr/share/modsecurity-crs/base_rules/modsecurity_crs_60_correlation.conf"] [line "33"] [id "981203"] [msg "Inbound Anomaly Score (Total Inbound Score: 3, SQLi=0, XSS=0): Request from Known SPAM Source (Previous RBL Match)"] [hostname "example.com"] [uri "/test.php"] [unique_id "VMTf31XWGY4AADqRE00AAAAB"]

[Sun Jan 25 13:21:51.777133 2015] [:error] [pid 14993] [client x.x.x.x] ModSecurity: Warning. Match of "rx (?i:(<meta.*?(content|value)=\\"text/html;\\\\s?charset=|<\\\\?xml.*?encoding=))" against "RESPONSE_BODY" required. [file "/usr/share/modsecurity-crs/optional_rules/modsecurity_crs_55_application_defects.conf"] [line "23"] [id "981220"] [msg "[Watcher Check] No charset was specified in the HTTP Content-Type header nor the HTML content's meta tag."] [data "Content-Type Response Header: text/html"] [tag "WASCTC/WASC-15"] [tag "APP_DEFECT/MISCONFIGURATION"] [tag "http://code.google.com/p/browsersec/wiki/Part2#Content_handling_mechanisms"] [hostname "example.com"] [uri "/test.php"] [unique_id "VMTf31XWGY4AADqRE00AAAAB"]

[Sun Jan 25 13:21:51.777193 2015] [:error] [pid 14993] [client x.x.x.x] ModSecurity: Warning. Match of "rx (<meta.*?(content|value)=\\"text/html;\\\\s?charset=utf-8|<\\\\?xml.*?encoding=\\"utf-8\\")" against "RESPONSE_BODY" required. [file "/usr/share/modsecurity-crs/optional_rules/modsecurity_crs_55_application_defects.conf"] [line "36"] [id "981222"] [msg "[Watcher Check]  The charset specified was not utf-8 in the HTTP Content-Type header nor the HTML content's meta tag."] [data "Content-Type Response Header: text/html"] [tag "WASCTC/WASC-15"] [tag "MISCONFIGURATION"] [tag "http://websecuritytool.codeplex.com/wikipage?title=Checks#charset-not-utf8"] [hostname "example.com"] [uri "/test.php"] [unique_id "VMTf31XWGY4AADqRE00AAAAB"]

modsecurity_crs_43_csrf_protection.conf上的規則正在查找CSRF攻擊,但是,您嘗試執行的規則不是CSRF。

你可以試試看

  1. /etc/apache2/mods-enabled/security2.conf刪除Include /usr/share/modsecurity-crs/base_rules/*.confInclude /usr/share/modsecurity-crs/optional_rules/*.conf /etc/apache2/mods-enabled/security2.conf (我猜您正在使用Ubuntu)。
  2. /etc/modsecurity/modsecurity_crs_15_customrules.conf創建規則集
  3. 將此規則包含在該文件中SecRule REQUEST_URI "secret" "phase:1,t:none,log,deny,id:'9000070001',msg:'Malicious content blocked'"
  4. 運行sudo service apache2 restart

嘗試從瀏覽器中訪問相同的URL,觀看/var/log/apache2/modsec_audit.log,讓我知道它的運行方式。

謝謝,

丹尼爾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM