【发布时间】:2019-05-02 18:58:46
【问题描述】:
我有 Ubuntu 18.10 和 apache2、libapache2-mod-security2、modsecurity-crs 软件包,除了启用 ModSecurity 调试日志和复制 modsecurity.conf-recommended 并添加 SecRuleEngine On 之外,它们的默认配置。
我在/etc/modsecurity/ 的单独文件中添加了一个新的SecRule
/etc/modsecurity/sf4-modsec.conf的内容只有一行:
SecRule RESPONSE_BODY "@rx <script" id:1000137,phase:4,deny,log,status:403
我可以用phase:1 确认正在加载此规则,因为它出现在调试日志中:
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][4] Recipe: Invoking rule 7f8e0d40d138; [file "/etc/modsecurity/sf4-modsec.conf"] [line "1"] [id "1000137"].
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][5] Rule 7f8e0d40d138: SecRule "RESPONSE_BODY" "@rx <script>" "phase:1,auditlog,id:1000137,deny,log,status:403"
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][4] Rule returned 0.
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][9] No match, not chained -> mode NEXT_RULE.
[02/May/2019:20:48:33 +0200] [localhost/sid#7f8e0d51a5c8][rid#7f8e108d20a0][/_profiler/empty/search/results][4] Recipe: Invoking rule 7f8e0d40f5a0; [file "/etc/modsecurity/crs/crs-setup.conf"] [line "845"] [id "900990"].
但是,如果使用phase:4 指定,它不会出现在日志中(我找不到带有1000137 的行。)
我希望这条规则能够阻止其 HTML 中包含 <script> 的每个页面,但它不会,尽管 <script> 标记 100% 在响应中。
但是,OWASP CRS 设置的已安装规则似乎可以完美运行。
我的响应正文处理配置:
SecResponseBodyAccess On
SecResponseBodyMimeType text/plain text/html text/xml
SecResponseBodyLimit 524288
SecResponseBodyLimitAction Reject
我尝试通过sudo service apache2 restart 多次重启Apache。
我尝试禁用所有 OWASP CRS 规则,但仍然没有帮助。 这是我的第 4 阶段调试日志:https://pastebin.com/8aXk8hL0(很短)
【问题讨论】:
标签: apache ubuntu owasp mod-security mod-security2