【问题标题】:ModSecurity for URL Whitelisting用于 URL 白名单的 ModSecurity
【发布时间】:2017-04-25 16:18:23
【问题描述】:

我想写一个只允许特定 URL 的规则。我只有两个网址 1:abc.com/configuration/ 2:abc.com/update/

SecRule REQUEST_URI "!@beginsWith /configuration" \ "id:700003, phase:1,log,deny, msg:'不同的 URL 访问'"

SecRule REQUEST_URI "@beginsWith /update" \ "id:700004, phase:1,log,pass, msg:'更新访问的 URI'"

如何合并这两条规则,以便其中一条可以覆盖另一条?

谢谢

【问题讨论】:

  • 我不明白你的问题。
  • 我想允许以上 URL 的唯一休息我希望 modsecurity 将阻止。

标签: mod-security


【解决方案1】:

你可以在这里做很多事情。

By default a regex is used to match in ModSecurity 这样您就可以编写一条规则来覆盖两个 URI 并在不匹配时阻止:

SecRule REQUEST_URI "!\/(configuration|update)\/" "phase:1,id:700003,block

您也可以使用@pm:

SecRule REQUEST_URI "!@pm \/configuration\/ \/update\/" "phase:1,id:700003,block

或者,您可以使用skipAfter,它允许您在不同的规则中列出 URL,然后有一个阻止规则,如果前面的任何规则匹配,则会跳过该规则:

SecMarker BEGIN_VALID_URL_CHECK
SecRule REQUEST_URI "!@beginsWith /configuration" \ "id:700003, phase:1,log,skipAfter:END_VALID_URL_CHECK,msg:'Different URL Accessed'"
SecRule REQUEST_URI "@beginsWith /update" \ "id:700004, phase:1,log,skipAfter:END_VALID_URL_CHECK,msg:'Update URI accessed'"
SecRule REQUEST_URI "." \ "id:700005, phase:1,log,block,msg:'Another URI accessed - blocking'"
SecMarker END_VALID_URL_CHECK

或者,您可以allow 匹配那些在 ModSecurity 中停止处理此请求的模式的规则(这可能是一个不好的选择,因为它会跳过稍后在您的配置中定义的任何其他 ModSecurity 规则,但为了完整性我将其包括在内清酒):

SecRule REQUEST_URI "!@beginsWith /configuration" \ "id:700003, phase:1,log,allow,msg:'Different URL Accessed'"
SecRule REQUEST_URI "@beginsWith /update" \ "id:700004, phase:1,log,allow, msg:'Update URI accessed'"
SecRule REQUEST_URI "." \ "id:700005, phase:1,log,block, msg:'Another URI accessed - blocking'"

【讨论】:

    猜你喜欢
    • 2018-01-10
    • 1970-01-01
    • 2020-11-14
    • 2014-01-16
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    相关资源
    最近更新 更多