如何對特定頁面使用Modsec規則?

如何對特定頁面使用Modsec規則?

我想使用 Apache Mod_security 阻止代理(x-forwarded)ip 某些頁面(wp-comments-post.php)。

我目前的 mod_security 規則:

SecRule REQUEST_HEADERS_NAMES "^x-forwarded-for" "log,deny,id:48,status:403,t:lowercase,msg:'Don't use Proxy'"

答案1

你應該能夠使用類似的東西

<LocationMatch "wp-comments-post.php" >
    SecRule &REQUEST_HEADERS:X-Forwarded-For "@gt 0" "log,deny,id:48,status:403,msg:'Don't use Proxy'"
</LocationMatch>

我沒有方便的機器來測試這個,但如果有 >0 X-Forward-For 請求標頭,它應該會拒絕訪問相關位置。許多公司使用代理,因此您可能會發現需要設定“@gt 1”以減少誤報。阿帕契人地點位置匹配文件.

答案2

我相信如果您將 modsec 規則包含在位置指令中,例如,您可以做到這一點。

<Location /koko/lala/wp-comments-post.php >
SecRule .... 
</Location>

相關內容