我在我的Debian-8主机上使用fail2ban。我有几个单独的监狱来检测对我的SMTP服务器的攻击,我想把它们合并成一个监狱。每个监狱都使用一个带有单个failregex行的过滤器,这对我来说是用来检测这些攻击的。但是,当我尝试将这些合并到一个监狱和一个带有多个failregex行的过滤器中时,就不会再检测到攻击了。
以下是当前正在工作的多个监狱-多个过滤器设置的总结:
## from the 'postfixauth.conf' filter for the 'postfixauth' jail ...
failregex = ^.*lost connection after AUTH from unknown\[\].*$
## from the 'postfixconcur.conf' filter for the 'postfixconcur' jail ...
failregex = ^.*concurrency limit exceeded:.*from unknown\[\].*$
## from the 'postfixconnect.conf' filter for the 'postfixconnect' jail ...
failregex = ^.*(timeout|lost connection) after (RSET|AUTH|CONNECT|EHLO|STARTTLS) from unknown\[\].*$
## from the 'postfixresolve.conf' filter for the 'postfixresolve' jail ...
failregex = ^.*hostname \S+ does not resolve to address +.*$
## from the 'postfixsasl.conf' filter for the 'postfixsasl' jail ...
failregex = ^.*unknown\[\]: SASL (PLAIN|LOGIN) authentication failed.*$
## from the 'postfixssl.conf' filter for the 'postfixssl' jail ...
failregex = ^.*SSL_accept error from unknown\[\].*$但是,如果我将这六个单独的监狱替换为一个单独的监狱,其过滤器文件中的failregex如下所示,它似乎没有阻止这些攻击:
## from the 'postfix.conf' filter for the 'postfix' jail ...
failregex = ^.*lost connection after AUTH from unknown\[\].*$
^.*concurrency limit exceeded:.*from unknown\[\].*$
^.*(timeout|lost connection) after (RSET|AUTH|CONNECT|EHLO|STARTTLS) from unknown\[\].*$
^.*hostname \S+ does not resolve to address +.*$
^.*unknown\[\]: SASL (PLAIN|LOGIN) authentication failed.*$
^.*SSL_accept error from unknown\[\].*$我的理解(这可能是错误的)是,多个failregex行是合法的,它们是或合并在一起的;也就是说,如果日志文件中的任何给定行匹配这些正则表达式中的一个或多个,则该行被认为匹配并表示“失败”。
假设我的理解是正确的,有人能看到我做这件事的方式有什么问题吗?
提前谢谢你。
发布于 2020-10-12 13:33:11
事实证明,我遇到的问题与将多个过滤器转换为多个failregex行的单个过滤器无关。我的机器上有一个不相关的问题,它发生在我最初忽略的同一时间,我错误地认为fail2ban过滤器是错误的。
在修复了不相关的问题并重新启动所有东西之后,我在上面展示的多行正则表达式确实起作用了。
更新:为了提供更多细节,这个问题与fail2ban无关。大约在我对多行正则表达式进行更改的同时,我意外地运行了/etc/init.d/iptables off而不是/etc/init.d/iptables stop。这导致iptables在重新启动后没有启动,而且我的所有fail2ban规则都没有效果。一旦我意识到这个错误并正确地启动了iptables,多行正则表达式就可以正常工作了。
https://serverfault.com/questions/1037273
复制相似问题