0

背景:我想摄取由 modsecurity 丰富的 apache 错误日志。为此,我更改了 apache 模块的摄取管道。

modsecurity 日志不完全共享一个共同的模式。因此,我想为它们提供两种 grok 模式。我使用 grok 调试器来创建它们并且两者都可以工作。

问题是,它们似乎很慢:当我使用摄取管道模拟 API 测试它们时,我得到:"grok pattern matching was interrupted after [1000] ms". 取决于我是否将匹配的 grok 模式作为patterns数组中的第一个或第二个元素。

为了解决这个问题,下面的 grok 模式:

^\[%{APACHE_TIME:apache.error.timestamp}\] \[\:%{LOGLEVEL:log.level}\] \[pid %{NUMBER:process.pid:long}\] \[client %{IPORHOST:source.address}:%{POSINT:source.port}.*\[file "%{PATH:modsec.rule.path}.* \[id "%{NUMBER:modsec.rule.number}"\] \[msg "%{MODSECMSG:message}.*? \[hostname "%{IPORHOST:host.hostname}"\] \[uri "%{URIPATH:url.path}"\] \[unique_id "%{MODSECMSG:modsec.unique_id}"\], referer\: %{URI:http.request.referrer}$

需要很长时间才能注意到它与此日志条目不匹配:

[Tue May 11 12:30:02.209790 2021] [:error] [pid 29329] [client 127.0.0.1:59586] [client 127.0.0.1] ModSecurity: Warning. Matched phrase "etc/passwd" at ARGS:page. [file "/usr/share/modsecurity-crs/rules/REQUEST-930-APPLICATION-ATTACK-LFI.conf"] [line "99"] [id "930120"] [msg "OS File Access Attempt"] [data "Matched Data: etc/passwd found within ARGS:page: /etc/passwd"] [severity "CRITICAL"] [ver "OWASP_CRS/3.1.0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-lfi"] [tag "OWASP_CRS/WEB_ATTACK/FILE_INJECTION"] [tag "WASCTC/WASC-33"] [tag "OWASP_TOP_10/A4"] [tag "PCI/6.5.4"] [hostname "localhost"] [uri "/dvwa/vulnerabilities/fi/"] [unique_id "YJp4yhyfYYeU0eSqwUU4GwAAAAA"]

因此解析失败并出现上述错误,因为下一个确实匹配日志条目的 grok 模式不再执行。

有没有办法可以优化我的模式或更改超时值?

4

0 回答 0