【问题标题】:SecRuleEngine On seem to block PUT and DELETE requests in mod_securitySecRuleEngine On 似乎阻止了 mod_security 中的 PUT 和 DELETE 请求
【发布时间】:2018-07-26 09:17:48
【问题描述】:

我已启用 SecRuleEngine,以便按照本教程在 apache 的 mod_security 中实现每个 IP 请求的突发限制。

https://johnleach.co.uk/words/2012/05/15/rate-limiting-with-apache-and-mod-security/

经过几次测试后,它似乎在 GET 和 POST 请求上按预期工作,但是单独启用 SecRuleEngine(未启用任何规则)似乎会阻止 PUT 和 DELETE 请求。这似乎不是预期的行为。

https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#SecRuleEngine

我使用带有 mod_security 版本 2 的 Apache 2.4,但如果它恰好是其中的一个错误,我愿意放弃 mod_security,并且我有一个替代方案来限制它。

如何在使用或不使用 mod_security 的情况下修复速率限制系统?

【问题讨论】:

    标签: apache mod-security2


    【解决方案1】:

    ModSecurity 仅阻止被告知要阻止的内容。

    我的猜测是,尽管你说你没有启用任何规则,但你包含了明确阻止这些方法的 OWASP CRS。

    版本 2 在其 modsecurity_crs_10_setup.conf.example 配置文件中具有以下规则,例如:

    #
    # Set the following policy settings here and they will be propagated to the 30 rules
    # file (modsecurity_crs_30_http_policy.conf) by using macro expansion.  
    # If you run into false positves, you can adjust the settings here.
    #
    SecAction \
      "id:'900012', \
      phase:1, \
      t:none, \
      setvar:'tx.allowed_methods=GET HEAD POST OPTIONS', \
      setvar:'tx.allowed_request_content_type=application/x-www-form-urlencoded|multipart/form-data|text/xml|application/xml|application/x-amf|application/json', \
      setvar:'tx.allowed_http_versions=HTTP/0.9 HTTP/1.0 HTTP/1.1', \
      setvar:'tx.restricted_extensions=.asa/ .asax/ .ascx/ .axd/ .backup/ .bak/ .bat/ .cdx/ .cer/ .cfg/ .cmd/ .com/ .config/ .conf/ .cs/ .csproj/ .csr/ .dat/ .db/ .dbf/ .dll/ .dos/ .htr/ .htw/ .ida/ .idc/ .idq/ .inc/ .ini/ .key/ .licx/ .lnk/ .log/ .mdb/ .old/ .pass/ .pdb/ .pol/ .printer/ .pwd/ .resources/ .resx/ .sql/ .sys/ .vb/ .vbs/ .vbproj/ .vsdisco/ .webinfo/ .xsd/ .xsx/', \
      setvar:'tx.restricted_headers=/Proxy-Connection/ /Lock-Token/ /Content-Range/ /Translate/ /via/ /if/', \
      nolog, \
      pass"
    

    如您所见,只有 GETHEADPOSTOPTIONS 被设置为允许的方法。

    较新的版本 3 在 crs-setup.conf.example 中有类似的配置:

    # HTTP methods that a client is allowed to use.
    # Default: GET HEAD POST OPTIONS
    # Example: for RESTful APIs, add the following methods: PUT PATCH DELETE
    # Example: for WebDAV, add the following methods: CHECKOUT COPY DELETE LOCK
    #          MERGE MKACTIVITY MKCOL MOVE PROPFIND PROPPATCH PUT UNLOCK
    # Uncomment this rule to change the default.
    #SecAction \
    # "id:900200,\
    #  phase:1,\
    #  nolog,\
    #  pass,\
    #  t:none,\
    #  setvar:'tx.allowed_methods=GET HEAD POST OPTIONS'"
    

    在这两种情况下,作为后续规则,使用此设置来阻止 PUTDELETE 等方法。

    无论您是使用这些规则还是其他规则集,ModSecurity 都应该在 Apache 错误日志中记录它阻止请求的原因。检查它以了解它被阻止的原因。

    【讨论】:

    • 该规则被默认 mod_security 模块文件中包含的 usr/share 文件阻止。我通过回到禁用误报风险的“偏执级别”0 来解决这个问题。谢谢你的回答。
    【解决方案2】:

    将偏执狂级别更改为 1 或 2 或 3 或 4 在新闻 OWASP CRS - Mod_Security 中无关紧要, 和偏执狂水平永远不应该是“0”

    cd /usr/share/modsecurity-crs

    SecAction \
    "id:900000,\
    phase:1,\
    nolog,\
    pass,\
    t:none,\
    setvar:tx.paranoia_level=1"
    enter code here
    

    添加 RESTful API 方法

    允许客户端使用的 HTTP 方法。 默认值:GET HEAD POST OPTIONS 示例:对于 RESTful API,添加以下方法:PUT PATCH DELETE 示例:对于 WebDAV,添加以下方法:CHECKOUT COPY DELETE LOCK MERGE MKACTIVITY MKCOL MOVE PROPFIND PROPPATCH PUT UNLOCK

    只需取消注释 HTTP 方法的 HTTP 策略:

    sudo nano /usr/share/modsecurity-crs/crs-setup.conf
    
    SecAction \
    "id:900200,\
    phase:1,\
    nolog,\
    pass,\
    t:none,\
    setvar:'tx.allowed_methods=GET HEAD POST OPTIONS PUT PATCH DELETE'"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 2019-11-29
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 2019-07-14
      相关资源
      最近更新 更多