Fail2ban 濾鏡正規表示式

Fail2ban 濾鏡正規表示式

我使用centos8 +fail2ban + haproxy

我有一個特殊的監獄“my-haproxy404”,具有以下設置:

[my-haproxy404]
enabled  = true
port     = http,https
filter   = my-haproxy404
logpath  = /var/log/my-haproxy.log
backend  = poller
journalmatch =
maxretry = 3
bantime  = 86400
findtime  = 3600

和過濾器:

[Definition]
failregex = .*:<HOST>(?::\d+)?\s+.*\d* 404

我的範例日誌行是:

Sep 19 14:38:21 localhost haproxy[53925]: 77.77.77.77:55763 [19/Sep/2021:14:38:21.483] backend1 line1/test1 0/0/12/88/100 404 687 - - ---- 1/1/0/0/0 0/0 "GET /test/string HTTP/1.1"

所以,...也許這有效,但在fail2ban.log中我看到IP如下:

INFO    [my-haproxy404] Found 0.0.217.211 - 2021-09-19 14:38:21

這不是真的IP(真實的IP是:77.77.77.77),fail2ban阻止了這個IP(0.0.217.211)...但是(77.77.77.77)仍然有效

我知道正規表示式有問題

你能幫我找到這個 404 字串的正確正規表示式規則嗎

Sep 19 14:38:21 localhost haproxy[53925]: 77.77.77.77:55763 [19/Sep/2021:14:38:21.483] backend1 line1/test1 0/0/12/88/100 404

問候

答案1

failregex = ^\s*\S+ haproxy\[\d+\]: <ADDR>:\d+(?: \[[^\]]+\])? \S+ \S+ \d+(?:/\d+)+ 404\b

您也可以替換404\b(?!401)[45]\d\d\b以匹配任何“壞”程式碼4xx5xx例外401(需要一些先決條件才能正確考慮授權握手,並且有一個haproxy-http-auth可用於此目的的過濾器)

相關內容