在 fail2ban 中配置备用 jail 以供手动使用

在 fail2ban 中配置备用 jail 以供手动使用

我有一个运行良好的 fail2ban 实例。

但我也喜欢偶尔手动检查日志并尝试识别围绕我的标准 f2b 定义的系统探测。

我正在寻找的是如何定义一个可以持续较长时间的监狱,我可以在这样的命令中手动使用它:

fail2ban-client set $JAIL banip $IP

有人能给我提供在配置文件中指定自定义 jail 的语法吗?该 jail 并非真正由日志文件触发(或者可能是标准 jail,但存在一些可能不会真正触发的条件),我可以在手动语句中使用吗?我想要做的是,在查看日志时,将手动禁止的禁止时间延长很多。

答案1

这是我的方法。

我将其添加到jail.local:

[manban]
enabled  = true
filter   = manban
action   = iptables[name=HTTP, port="80,443,110,995,25,465,143,585,993,587,21,22", protocol=tcp]
logpath  = /var/log/manban.log
maxretry = 1
# 1 month
bantime  = 2592000
findtime = 3600

然后我添加了文件 /etc/fail2ban/filter.d/manban.conf:

[Definition]
failregex = ^\[\w{1,3}.\w{1,3}.\d{1,2}.\d{1,2}:\d{1,2}:\d{1,2} \d{1,4}. \[error] \[client.<HOST>].File does not exist:.{1,40}roundcube.{1,200}
ignoreregex =

我复制了另一个过滤器的过滤协议,但将其指向不存在的文件,然后我创建了一个虚拟文件:

touch /var/log/manban.log

然后运行命令:

fail2ban-client reload

现在要手动禁止某个 IP 地址一个月,请输入:

fail2ban-client set manban banip <IP>

这招很管用。

现在有些客户端会“学习”您的 fail2ban 封禁时间,并会自动调整其系统探测以避免被封禁。但是当您查看日志时,很明显这些都是系统探测。您可以通过设置超长的封禁时间来扰乱他们的系统。您还可以编写一个脚本,将符合特定条件的 IP 转储到您的特殊封禁日志中,并让 fail2ban 长时间封禁它们。

答案2

为什么不使用空过滤器?这是我的 /etc/fail2ban/filter.d/manual.conf

[Definition]
failregex=
ignoreregex=

然后 /etc/fail2ban/jail.d/manual.conf

[manual]
enabled = true
port = http,https
action = iptables-multiport[name=manual, port="http,https", protocol=tcp]
bantime = 9999999999999999

然后fail2ban-client reload我可以快速

fail2ban-client set manual banip <IP>

相关内容