我可以提高摄取管道 GROK 模式的性能吗?

问题描述

背景:我想摄取apache错误日志,通过modsecurity进行了丰富。为此,我更改了 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 模式不再执行。

有什么方法可以优化我的模式或更改超时值?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)