gpt4 book ai didi

python - Fail2ban Regex - 不匹配日志文件中的行

转载 作者:行者123 更新时间:2023-12-05 06:57:51 27 4
gpt4 key购买 nike

我正在尝试针对此字符串创建一个 fail2ban 正则表达式:

[2020-Nov-10 16:13:35] [freepbx_security.NOTICE]: Authentication failure for S from 109.38.128.48 [] []

到目前为止我创建的是这个正则表达式:

\[.*\] \[freepbx_security\.NOTICE\]: Authentication failure for .* from <HOST> \[\] \[\]

我已经更改了风格以明确使用 Python。 Regex101 显示匹配项,但我的 fail2ban-regex 仍然无法观察到它。

我创建了一个测试用例,其中包含最基本形式的日志行,并针对它进行了最简单的测试,但即使那样也失败了:

fail2ban-regex 'Authentication failure for S from 109.38.128.48' 'Authentication failure for S from <HOST>'

Running tests
=============

Use failregex line: Authentication failure for S from <HOST>
Use single line: Authentication failure for S from 109.38.128.48


Results
=======

Failregex: 0 total

Ignoreregex: 0 total

Date template hits:

Lines: 1 lines, 0 ignored, 0 matched, 1 missed
[processed in 0.02 sec]

|- Missed line(s):
| Authentication failure for S from 109.38.128.48

如果我应用

如果我将 -D 开关添加到 fail2ban-regex,我会得到一个显示完全匹配的 debuggex URL。然而,Fail2ban 声称它仍然是一个错误:Link

无论我如何摆弄通配符,fail2ban-regex 都不匹配,而如果我在 https://regex101.com/ 上测试正则表达式则匹配.我可能忽略了一些小而愚蠢的东西。有没有人可以指导我走上启蒙之路:)

最佳答案

很快,fail2ban 在日志中搜索日期(以及匹配该日期的默认日期模式之一)。你可以试试加-l HEAVYDEBUG参数 fail2ban-regex看看那里发生了什么。并且您的日期模式与 fail2ban 的默认值不匹配。

所以只需指定您自己的 datepattern在 jail 中(仅限 fail2ban 版本 > 0.10)或在过滤器中:

datepattern = ^\[%%Y-%%b-%%d %%H:%%M:%%S\]\s
failregex = ^\[freepbx_security.NOTICE\]: Authentication failure for \S+ from <ADDR>

如果你的fail2ban版本还是0.9,把datepattern放到filter的Init部分,替换<ADDR><HOST> .
请注意,在应用 failregex 之前,匹配 datepattern 的字符串会从 line out 中删除(因此 failregex 不能包含它)。

这里是它在 fail2ban-regex 中的工作原理:

fail2ban-regex --datepattern '^\[%Y-%b-%d %H:%M:%S\]\s' '[2020-Nov-10 16:13:35] [freepbx_security.NOTICE]: Authentication failure for S from 109.38.128.48 [] []' '\[freepbx_security.NOTICE\]: Authentication failure for \S+ from <ADDR>'

关于python - Fail2ban Regex - 不匹配日志文件中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64782530/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com