Fail2ban 接受了定制的 jail,但未检测到事件

Fail2ban 接受了定制的 jail,但未检测到事件

这个问题让我抓狂。我配置了一个监狱来阻止过多的 http 帖子发送到我的网络服务器。

似乎 fail2ban 服务器接受了我的新 jail,但是 fail2ban 服务器上没有任何效果。

以下是我的 jail.local 配置的一部分(顺便说一下,fail2ban 中的 sshd 运行完美)。

#global setting
bantime  = 1h 
findtime  = 1h
maxretry = 5
backend = systemd
banaction = firewallcmd-rich-rules[actiontype=]
banaction_allports = firewallcmd-rich-rules[actiontype=]
[sshd]
# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode   = normal
enabled  = true
port    = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s

[webpost]
enabled  = true
filter   = webpost
logpath  = /var/log/message

以下是 filter.d/ 文件夹中的 webpost.conf:

[Definition]
failregex = ^.*myserver python3.6\[.*\]: <HOST> - - \[.*\] ".*POST \/enquiry HTTP.*".*-$
ignoreregex =
datepattern = ^%%b  %%d %%H:%%M:%%S

fail2ban 中的正则表达式测试正在运行,输出如下:

fail2ban-regex /var/log/messages /etc/fail2ban/filter.d/webpost.conf
Running tests
=============
Use   failregex filter file : webpost, basedir: /etc/fail2ban
Use      datepattern : ^%b  %d %H:%M:%S : ^MON  Day 24hour:Minute:Second
Use         log file : /var/log/messages
Use         encoding : UTF-8
Results
=======
Failregex: 115 total
|-  #) [# of hits] regular expression
|   1) [115] ^.*myserver python3.6\[.*\]: <HOST> - - \[.*\] ".*POST \/enquiry HTTP.*".*-$
`-
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
|  [115989] ^MON  Day 24hour:Minute:Second
`-
Lines: 115989 lines, 0 ignored, 115 matched, 115874 missed
[processed in 2.65 sec]

fail2ban 日志还显示一切都已加载并且运行正常。

2023-09-07 17:27:09,868 fail2ban.filtersystemd  [969]: NOTICE  [webpost] Jail started without 'journalmatch' set. Jail regexs will be checked against all journal entries, which is not advised for performance reasons.
2023-09-07 17:27:10,061 fail2ban.filtersystemd  [969]: INFO    [webpost] Jail is in operation now (process new journal entries)
2023-09-07 17:27:10,063 fail2ban.jail           [969]: INFO    Jail 'webpost' started

在我向我的网站发送大量 http post 请求后,fail2ban 似乎没有从 /var/log/message 检测到任何 http post。fail2ban 仅检测 sshd 尝试。根本没有检测到 webpost!

2023-09-07 17:36:46,206 fail2ban.filter         [969]: INFO    [sshd] Found 180.101.88.228 - 2023-09-07 17:36:45
2023-09-07 17:36:48,739 fail2ban.filter         [969]: INFO    [sshd] Found 180.101.88.228 - 2023-09-07 17:36:48
2023-09-07 17:36:52,034 fail2ban.filter         [969]: INFO    [sshd] Found 180.101.88.228 - 2023-09-07 17:36:51
2023-09-07 17:36:55,241 fail2ban.filter         [969]: INFO    [sshd] Found 180.101.88.228 - 2023-09-07 17:36:54
2023-09-07 17:37:57,290 fail2ban.filter         [969]: INFO    [sshd] Found 180.101.88.228 - 2023-09-07 17:37:56
2023-09-07 17:37:57,769 fail2ban.actions        [969]: NOTICE  [sshd] Ban 180.101.88.228
2023-09-07 17:37:57,795 fail2ban.filter         [969]: INFO    [pam-generic] Found 180.101.88.228 - 2023-09-07 17:37:57
2023-09-07 17:37:59,280 fail2ban.filter         [969]: INFO    [sshd] Found 180.101.88.228 - 2023-09-07 17:37:58

我不知道问题出在哪里。

答案1

fail2ban.filtersystemd [969]: NOTICE [webpost] Jail started without 'journalmatch' set...

您的默认设置backend似乎是systemd,这意味着它会监视 systemd 日志而不是日志路径。

只需添加backend = auto到监狱:

  [webpost]
  ...
  logpath  = /var/log/message
+ backend = auto

相关内容