ModSecurity 中是否有任何函数可以设置相关参数正则表达式,如 SecAuditLogRelevantStatus 选项?

Is thre an any function in ModSecurity to set relevant parameters regular expression like SecAuditLogRelevantStatus option?

我在我的 Apache 服务器上使用 ModSecuity,我想将它设置为不记录在查询字符串中具有确定参数的请求。

在 mod_secuirty.conf 中,我有以下配置:

SecAuditEngine RelevantOnly
SecAuditLogRelevantStatus "^(?:5|4(?!04))"

我想设置 SecAuditLogRelevantParameter“?!(test)”之类的东西(记录任何没有 test 参数的请求)。

mod_security2 for Apache supports ctl:auditLogPartsctl:auditLogEngine(注意:libmodsecurity3 不支持 auditLogEngine ctl 的子操作)。因此,您可以制定一个规则,关闭审计引擎,或修改日志部分。我想你想把它关掉,所以根据你的要求,你需要这样的东西:

SecAction
  "id:111001,\
  phase:1,\
  nolog,\
  pass,\
  t:none,\
  setvar:tx.args_contains_test=0"

SecRule ARGS_NAMES "@rx test" \
    "id:111002,\
    phase:2,\
    pass,\
    nolog,\
    t:lowercase,
    setvar:'tx.args_contains_test=1'"

SecRule TX:args_contains_tests "@lt 1" 
    "id:111003,\
    phase:2,\
    pass,\
    nolog,\
    ctl:auditLogEngine=Off"

将这些规则放在规则集的最开头 - 如果您使用 CRS,那么 REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf 是一个不错的选择。

这个排除是如何工作的?

正如您在上面所写,条件是“任何具有测试参数的请求”。这不是那么简单,因为你必须检查某物不存在,因此你必须检查所有参数。

在 ModSecurity 中,你只能通过上面的方式来做到这一点:首先,你必须设置一个交易变量,它存储信息,请求包含任何名称为 test 或不包含的参数。这是第一个(也是唯一一个)SecAction.

@rx test 是一个 ModSecurity 运算符及其参数,用于检查 ARGS_NAMES 集合。该集合包含请求的所有参数。规则 111002 检查所有参数名称,如果有任何名称类似于 test 的变量(正则表达式匹配),则它会更改 TX 变量。

规则 111003 检查 TX 变量,如果它是 1,则禁用 当前 事务的 auditLog 引擎。就是这样。

请注意,@rx 运算符是 case-sensitive,这就是 t:lowercase 在那里的原因。

另请注意,两个 SecRulephase:2 中执行。如果要检查 GET 参数,则必须将此规则移动到 phase:1。如果要检查所有可能的变量,则必须复制此规则:一个用于 phase:1,另一个用于 phase:2 - 具有唯一 ID!

如果您想使用 QUERY_STRING 参数关闭 auditLogEngine,例如。 http://example.com/form.cgi?test=1,那么解决方法就更简单了——不过任何人都可以这样关机:

SecRule REQUEST_URI "@endsWith test=1" \
    "id:111001,\
    phase:1,\
    pass,\
    nolog,\
    t:lowercase,\
    ctl:auditLogEngine=Off"