我想打印mod_securityexception分数到Apache错误日志。 我使用setenv
设置环境variables, %{name}e
语法将其打印在日志中。
Modsecurityconfiguration:
SecAction "id:90100,phase:5,pass, nolog, setenv:ModSecAnomalyScoreIn=%{tx.anomaly_score}, setenv:ModSecAnomalyScoreOut=%{TX.outbound_anomaly_score}"
Apacheconfiguration:
ErrorLogFormat "[...] [anomaly_score_in: %-{ModSecAnomalyScoreIn}e, anomaly_score_out: %-{ModSecAnomalyScoreOut}e ]"
但输出为空: [...] [anomaly_score_in: -, anomaly_score_out: - ]
如果我添加SecAction "id:9990101,phase:5,pass, log, msg:'in: %{env.anomaly_score}, out: %{env.ModSecAnomalyScoreOut}'
,打印成绩,但在新的日志行。
我哪里做错了?
ErrorLogFormat中的%{name}e
是否等于%{VARNAME}e
?
为什么你在%
和{
在第一个非工作例子中有一个破折号?
此外, Modsecurity参考手册还说,您应该使用%{modsecurity_variable_name}M
而不是%{modsecurity_variable_name}e
。
所以我相信你的最终configuration应该是:
ErrorLogFormat "[...] [anomaly_score_in: %{ModSecAnomalyScoreIn}M, anomaly_score_out: %{ModSecAnomalyScoreOut}M ]"
还要注意,自定义的ErrorLogFormats只适用于ModSecurity 2.9.1或更高版本: https : //github.com/SpiderLabs/ModSecurity/pull/840