Modsecurity 白名单 json ARG

Modsecurity whitelist json ARG

这是我得到的匹配:

against variable `ARGS:json' (Value: `{"j_username": "username", "j_password": "password_with_special_marks", "remember_me": false, "from":  (4 characters omitted)' ) [file "/usr/local/nginx/conf/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf"] [line "509"] [id "942130"]

密码有特殊标记,将其标记为SQL注入。

我尝试将规则列入白名单:

SecRuleUpdateTargetById 942130 !ARGS:'j_password'
SecRuleUpdateTargetById 942130 !ARGS:'json'

他们都没有工作。问题是我应该从 match ARGS 中获取什么参数?

你应该匹配 ARGS:json。这里有几件事需要考虑。

  1. SecRuleUpdateTargetById 必须在规则之后。看起来您正在使用 OWASP CRS 3.x,所以这意味着,理想情况下,将 RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example 重命名为 RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf 并把它放在里面。
  2. 为了安全起见,我会遵循参考手册 https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#secruleupdatetargetbyid 提出的指导。格式应为 SecRuleUpdateTargetById 12345 "!ARGS:foo"。在你的情况下 SecRuleUpdateTargetById 942130 "!ARGS:json"
  3. 尽管可能并非如此,但如果您的整个请求都是 JSON,您可以告诉 ModSecurity 照此处理。这是在推荐的 ModSecurity 配置中默认完成的 (https://github.com/SpiderLabs/ModSecurity/blob/v2/master/modsecurity.conf-recommended#L25)。如果只是参数是 JSON,不幸的是,ModSecurity 目前无法处理给定的参数。但是,保护仍然有效,只是不像上述情况那样理想。
  4. 如果这是一个完善的项目,例如 Drupal,请考虑使用现有的 Drupal Exclusions (https://github.com/SpiderLabs/owasp-modsecurity-crs/blob/e4e0497be4d598cce0e0a8fef20d1f1e5578c8d0/rules/REQUEST-903.9001-DRUPAL-EXCLUSION-RULES.conf). These can be enabled by commenting out SecAction 900130 in crs-setup.conf and enabling the Drupal exclusions. Please see the example https://github.com/SpiderLabs/owasp-modsecurity-crs/blob/v3.0/master/crs-setup.conf.example#L296

祝你好运!