[英]Fail2ban Regex - not matching lines in log file
我正在嘗試針對此字符串創建一個 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 聲稱它仍然是一個錯誤: 鏈接
無論我如何擺弄通配符,fail2ban-regex 都不匹配,而如果我在https://regex101.com/上測試它,regex 確實匹配。 我可能忽略了一些小而愚蠢的東西。 有沒有人可以指導我走上啟蒙之路:)
很快,fail2ban 在日志中搜索日期(以及匹配該日期的默認日期模式之一)。 您可以嘗試添加-l HEAVYDEBUG
參數fail2ban-regex
以查看那里發生了什么。 並且您的日期模式與 fail2ban 的默認值不匹配。
因此,只需在監獄中指定您自己的日期模式(僅限datepattern
版本 > 0.10)或在過濾器中:
datepattern = ^\[%%Y-%%b-%%d %%H:%%M:%%S\]\s
failregex = ^\[freepbx_security.NOTICE\]: Authentication failure for \S+ from <ADDR>
如果您的 fail2ban 版本仍然是 0.9,請將 datepattern 放在過濾器的 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>'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.