自定义fail2ban禁止规则不起作用(failregex使用不正确?)

自定义fail2ban禁止规则不起作用(failregex使用不正确?),regex,fail2ban,Regex,Fail2ban,我目前正在尝试保护我们的备份服务器及其接口,因为除了强密码之外,它目前没有任何(额外)安全性。备份服务器基于CentOS 7.x 日志文件位置: /var/log/backup 日志文件名: backuplog-2019310.log backuplog-2019309.log backuplog-2019308.log backuplog-2019307.log 错误登录记录如下: [2019-11-06T13:13:33+01:00] [Audit] Web login failure

我目前正在尝试保护我们的备份服务器及其接口,因为除了强密码之外,它目前没有任何(额外)安全性。备份服务器基于CentOS 7.x

日志文件位置:

/var/log/backup
日志文件名:

backuplog-2019310.log
backuplog-2019309.log
backuplog-2019308.log
backuplog-2019307.log
错误登录记录如下:

[2019-11-06T13:13:33+01:00] [Audit] Web login failure for account 'admin': Invalid authentication (Address=200.100.150.50:28534)
[2019-11-06T13:13:34+01:00] [Audit] Web login failure for account 'test': Invalid authentication (Address=120.30.40.20:28534)
[2019-11-06T13:13:35+01:00] [Audit] Web login failure for account 'info': Invalid authentication (Address=85.80.75.70:28534)
[2019-11-06T13:13:35+01:00] [Audit] Web login failure for account 'user': Invalid authentication (Address=25.125.155.190:28534)
在/etc/fail2ban/jail.local中:

[backup]
enabled  = true
filter   = backup
logpath  = /var/log/backup/backuplog-*.log
port     = 80,443
这里可以用星号,对吗

我希望到目前为止我理解正确

但是,我在为此自定义故障创建正确的筛选器时遇到问题2禁用规则(=筛选器)

/etc/fail2ban/filter.d/backup.conf示例:

[Definition]
failregex = [[]Web login failure for account []] .* Invalid authentication
ignoreregex =
但它不起作用。所以我猜我的failregex是不正确的?也许有人可以建议我正确的failregex来申请使它工作

启动fail2ban时,我收到以下错误消息:

ERROR  NOK: ("No 'host' group in '[[]Web login failure for account []] .* Invalid authentication'",)
所以我猜failregex是不正确的

//更新1-仍然存在问题+附加问题 再鬼混一点。这是更新的failregex:

failregex = [][] Web login failure for account .* <HOST>
failregex = Invalid authentication \(Address=<HOST>
那么我做错了什么

另外,仔细想想,我认为使用“/var/log/backup/backuplog-*.log”并没有那么好。尤其是当创建越来越多的日志文件时。对吧?

是否有针对当前或最新日志文件的方法,例如backuplog-2019310.log

提前谢谢

在此期间,我会再胡闹一点

//更新2-主要问题已解决!! 我想我通过使用以下failregex解决了这个问题:

failregex = [][] Web login failure for account .* <HOST>
failregex = Invalid authentication \(Address=<HOST>
failregex=身份验证无效\(地址=
我会看看我是否能让它变得更好。但这对我来说是一个很好的开始

因此,也许有人可以帮助我解决与上述日志文件有关的问题。为了便于阅读,我将在此处再次询问:

还有,想想看,我觉得 “/var/log/backup/backuplog-*.log”不是很好,尤其是当 越来越多的日志文件被创建,对吗

是否有针对当前或最新日志文件的方法,例如。 backuplog-2019310.log

也许有人能解决这个问题


提前谢谢。

对于regex,最好使用锚定的RE,因此在结尾:

failregex = Invalid authentication \(Address=<HOST>\)\s*$
failregex=无效身份验证\(地址=\)\s*$
或在开始时:

failregex = ^\[\] \[Audit\] Web login failure for account '[^']+': Invalid authentication \(Address=<HOST>
failregex=^\[\]\[Audit\]帐户'[^']+'的Web登录失败:身份验证无效\(地址=
如果日志中不需要主机名(或使用
),则禁用此监狱的
usedns