Modsecurity白名单json ARG

时间:2017-08-03 07:31:04

标签: json whitelist mod-security

这是我得到的匹配:

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'

他们都没有工作。问题是我应该从比赛ARGS中拿出什么参数?

1 个答案:

答案 0 :(得分:0)

你应该匹配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)。这些可以通过在crs-setup.conf中注释掉SecAction 900130并启用Drupal排除来启用。请参阅示例https://github.com/SpiderLabs/owasp-modsecurity-crs/blob/v3.0/master/crs-setup.conf.example#L296
  5. 祝你好运!