【问题标题】:ModSecurity OWASP 3.3.2 breaking Nextcloud - cannot solve this oneModSecurity OWASP 3.3.2 破坏 Nextcloud - 无法解决这个问题
【发布时间】:2023-01-18 15:00:17
【问题描述】:
  • 运行 ModSecurity 2.93 和 OWASP ModSecurity 核心规则集 (CRS) 3.3.2.
  • 启用了REQUEST-903.9003-NEXTCLOUD-EXCLUSION-RULES.conf 中包含的 Nextcloud 异常,它们正在正常加载。
  • Nextcloud 已更新至最新的稳定版本,并通过了所有检查。

然而,ModSecurity 在许多重要方面破坏了它的功能。

关于桌面同步应用程序、移动同步应用程序和一般 WebDav 的活动,我得到了一些误报。

这完全是 ModSecurity 做的。 Nextcloud 报告没有错误,禁用 ModSecurity 解决了问题。

我试图解决这个问题失败了。特别是,将以下规则添加到 REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf 会完全破坏 Nextcloud 的功能,并且不会解决任何误报。不知道为什么:

 SecRule REQUEST_URI "@beginsWith /remote.php/dav/files/admin/" \
 "id:10000003,\
 phase:2,\
 pass,\
 nolog,\
 ctl:ruleRemoveTargetById=921110,\
 ctl:ruleRemoveTargetById=980130,\
 ctl:ruleRemoveTargetById=949110"

来自 ModSecurity 审计日志的示例:

Message: Warning. Match of "within %{tx.allowed_request_content_type}" against "TX:content_type" required. [file "/etc/modsecurity/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf"] [line "956"] [id "920420"] [msg "Request content type is not allowed by policy"] [data "|image/png|"] [severity "CRITICAL"] [ver "OWASP_CRS/3.3.2"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "capec/1000/255/153"] [tag "PCI/12.1"]
Message: Access denied with code 403 (phase 2). Operator GE matched 5 at TX:anomaly_score. [file "/etc/modsecurity/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "93"] [id "949110"] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [severity "CRITICAL"] [ver "OWASP_CRS/3.3.2"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"]
Message: Warning. Operator GE matched 5 at TX:inbound_anomaly_score. [file "/etc/modsecurity/rules/RESPONSE-980-CORRELATION.conf"] [line "91"] [id "980130"] [msg "Inbound Anomaly Score Exceeded (Total Inbound Score: 5 - SQLI=0,XSS=0,RFI=0,LFI=0,RCE=0,PHPI=0,HTTP=0,SESS=0): individual paranoia level scores: 5, 0, 0, 0"] [ver "OWASP_CRS/3.3.2"] [tag "event-correlation"]
Apache-Error: [file "apache2_util.c"] [line 273] [level 3] [client <ip>] ModSecurity: Warning. Match of "within %{tx.allowed_request_content_type}" against "TX:content_type" required. [file "/etc/modsecurity/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf"] [line "956"] [id "920420"] [msg "Request content type is not allowed by policy"] [data "|image/png|"] [severity "CRITICAL"] [ver "OWASP_CRS/3.3.2"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "capec/1000/255/153"] [tag "PCI/12.1"] [hostname "<hostname>"] [uri "/index.php/apps/files/"] [unique_id "Y8Yq5sm-7UrRygrbZZNbsgAAABc"]
Apache-Error: [file "apache2_util.c"] [line 273] [level 3] [client <ip>] ModSecurity: Access denied with code 403 (phase 2). Operator GE matched 5 at TX:anomaly_score. [file "/etc/modsecurity/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "93"] [id "949110"] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [severity "CRITICAL"] [ver "OWASP_CRS/3.3.2"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"] [hostname "<hostname>"] [uri "/index.php/apps/files/"] [unique_id "Y8Yq5sm-7UrRygrbZZNbsgAAABc"]

Android 同步应用程序中的消息通常是“不允许您上传到此文件夹”。通常,所有同步应用程序都会被 ModSecurity 提供的 403 错误所困扰。我不确定这不会只发生在某些文件类型或某些文件夹中,或者我认为,所有文件都会发生。

【问题讨论】:

    标签: owasp nextcloud mod-security


    【解决方案1】:

    CRS Dev-On-Duty 在这里。您的调整规则似乎有两个问题。

    第一个问题是您在使用控制语句ctl:ruleRemoveTargetById=921110 时没有在规则后指定目标。使用 ctl:ruleRemoveTargetById=9xxxxx;ARGS:myArg 指定目标,或者仅使用 ruleRemoveById 而不是 ruleRemoveTargetById 来删除规则。

    第二个问题:永远不要删除阻止规则949110 或关联规则980130。您关闭 WAF。

    为了解决您的问题(除了阻止和关联规则之外,我只看到一个匹配的规则),我认为最好将 Content-Type: image/png 添加到允许的请求内容类型列表中。这可以通过取消注释 crs-setup.conf 中的规则 900220 并添加所需的请求内容类型来完成: https://github.com/coreruleset/coreruleset/blob/v3.3/dev/crs-setup.conf.example#L422

    如果您需要更多调优帮助,我强烈推荐我们的 CRS 联合负责人 Christian Folini 的调优指南,尤其是“使用 OWASP CRS 处理误报”:https://www.netnea.com/cms/apache-tutorial-8_handling-false-positives-modsecurity-core-rule-set/

    【讨论】:

    • 谢谢您的回答。我试过按照你的建议无济于事。我为该规则更改为 ruleRemoveById,但我仍然收到相同的 403 错误。添加内容类型也无济于事。除了误报之外,响应时间也非常缓慢。唯一能让事情恢复正常的是完全关闭 Nextcloud 的引擎。
    • 你的建议很好,我的 conf 中还有另一个错误 - 请参阅本页上我自己的答案。
    【解决方案2】:

    我想我可能已经弄清楚了我的问题。

    我在我的crs-setup.conf 中启用了此功能:

    SecRule SERVER_NAME "<hostname>" 
    "id:10000001,
    phase:1,
    pass,
    nolog,
    setvar:tx.error_anomaly_score=4"
    

    这是我在阅读 MS 手册后降低 MS 灵敏度的旧尝试。显然我在那里做出了一些严重的误判。现在一切似乎都在起作用。

    顺便问一下:如何正确更改主机名的异常分数,使 MS 不那么敏感?正常值是多少?我以为是5...

    【讨论】: