提问人:DixFlatline 提问时间:9/11/2023 更新时间:9/13/2023 访问量:65
为 Fail2ban 和 Bookstack 配置过滤器
Configuring a filter for Fail2ban and Bookstack
问:
我无法成功配置 fail2ban 过滤器以使用 Bookstack。 我尝试了 3 种不同的正则表达式检查器,它们都捕获了日志行,但是当我尝试使用 failban-regex 工具时,它没有命中任何东西。
Apache 错误日志文件:
[Mon Sep 11 10:41:55.375879 2023] [php:notice] [pid 30757] [client 82.32.100.175:52892] Failed login for [email protected], referer: https://bookstack.exemple.com/login
[Mon Sep 11 10:44:55.883100 2023] [php:notice] [pid 30743] [client 100.154.118.1:59728] Failed login for [email protected], referer: https://bookstack.exemple.com/login
fail2ban/filter.d/bookstack.conf:
[Definition]
failregex = (\[client <HOST>\]) (Failed login for .*?[^,]+)
jail.local网站:
[bookstack]
enabled = true
port = http,https
logpath = %(apache_error_log)s
filter = bookstack
$ sudo fail2ban-regex /var/log/apache2/error.log /etc/fail2ban/filter.d/bookstack.conf --print-all-matched >
Running tests
=============
Use failregex filter file : bookstack, basedir: /etc/fail2ban
Use log file : /var/log/apache2/error.log
Use encoding : UTF-8
Results
=======
Failregex: 0 total
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
| [51] {^LN-BEG}(?:DAY )?MON Day %k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
`-
Lines: 51 lines, 0 ignored, 0 matched, 51 missed
[processed in 0.01 sec]
Missed line(s): too many to print. Use --print-all-missed to print all 51 lines
任何帮助将不胜感激。非常感谢您抽出时间接受采访。
答:
1赞
DixFlatline
9/12/2023
#1
我终于解决了这个问题。但是,我不确定如何。 可能是因为 UFW 或 netfilter-persistent。我将很快尝试重新安装服务器以测试这两种可能性。
这是 bookstack.conf:
datepattern = {^LN-BEG}(?:DAY )?MON Day %%k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
failregex = .*client <HOST>.*Failed login for .*?
此正则表达式也正常工作(没有日期模式):
failregex = ^.*\[client <HOST>:\d+\] Failed login for.*?[^,]+
最后,我在我的jail.local中添加了更多设置(以前缺少):
maxretry = 3
bantime = 300
编辑:以防万一它对其他人有用。我重新安装了服务器,它在没有 netfilers 的情况下工作——持久性也不是 UFW。
评论
netfilter-persistent
service --status-all