【问题标题】:what is this regex mod_security rule doing?这个正则表达式 mod_security 规则在做什么?
【发布时间】:2012-02-13 09:00:10
【问题描述】:

我一生都无法阅读正则表达式。
有人能帮我弄清楚为什么我的主机上次更新时突然触发了 mod_security 吗?

我收到了这个 mod_security 错误:

消息:访问被拒绝,代码为 406(第 2 阶段)。 REQUEST_HEADERS:Cookie 中的模式匹配“\b(\d+) ?= ?\1\b|[\'"](\w+)[\'"] ?= ?[\'"]\2\b”。 [file "/usr/local/apache/conf/modsec2.user.conf"] [line "94"] [id "959901"] [msg "SQL Injection Attack"] [data "1=1"] [severity" CRITICAL"] [标签 "WEB_ATTACK/SQL_INJECTION"]

这是产生此错误的记录的 cookie 之一:

Cookie:pmr=9d800ab159baf3962d1c777225b4b632; pmr_referrer=http%3A%2F%2Frateyourmusic.com%2Fadmin%2Fcoraq%2F%3F1%3D1%26status%3Dw%26show%3D10%26start%3D7020; __utma=229707933.920390620.1326769663.1326769663.1326769663.1; __utmb=229707933.1.10.1326769663; __utmc=229707933; __utmz=229707933.1326769663.1.1.utmcsr=rateyourmusic.com|utmccn=(referral)|utmcmd=referral|utmcct=/admin/corq/

这是因为“admin”在 cookie 中而触发吗???

这是另一个...

Cookie:ui-tabs-1=1; superBAGUS=af14474b9bcc7ec3ae436e58ba172520; superBAGUS_referrer=...; superBAGUS_admin=2%3A747167a9cd89703dbfafe3c7a5c523b4; acco=acco_1; superBAGUS_adviews=.2576.2580.; __utma=10910262.1479346800.1326871079.1326871079.1326873539.2; __utmb=10910262.10.8.1326873800604; __utmc=10910262; __utmz=10910262.1326871079.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)

这是因为“ui-tabs-1=1”看起来像 1=1 注入而触发的吗???

这个模式匹配到底是什么?

【问题讨论】:

  • 这是一个很好的例子,说明为什么一般的 Web 应用程序防火墙相当无用。

标签: regex apache cookies mod-security


【解决方案1】:

正则表达式与第一个模式不匹配,所以我不知道可能出了什么问题。

但它确实匹配第二个模式的1=1 部分,所以你的假设是正确的。

正则表达式的解释:

\b             # Assert position at the start of an alphanumeric "word"
(\d+)          # Match a number
 ?= ?          # Match =, optionally surrounded by spaces
\1             # Match the same number as before
\b             # Assert position at the end of an alphanumeric "word"
|              #  or
['"](\w+)['"]  # Match a quoted "word"
 ?= ?          # Match =, optionally surrounded by spaces
['"]\2\b       # Match a quote and the same word as before.

【讨论】:

  • 感谢详细解释!
猜你喜欢
  • 2011-10-24
  • 2014-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-16
  • 2013-04-19
相关资源
最近更新 更多