你好,我在 Centos 6.5 上使用 postfix 和 fail2ban,但我被机器人攻击了(我没有中继,但就是这样),出于某种原因,fail2ban 无法切断 ip 并阻止它,这种情况每秒发生 6/7 次。/var/log/maillog
Mar 3 13:05:47 postfix/smtpd[27715]: lost connection after UNKNOWN from Unknown[209.15.212.253]
Mar 3 13:05:47 postfix/smtpd[27715]: disconnect from unknown[209.15.212.253]
Mar 3 13:05:47 postfix/smtpd[27715]: warning: valid_hostname: misplaced delimiter: .
我对这个机器人的 IP 没有意见,publishing
因为它显然不是任何人的朋友,而且是一个专门构建的垃圾邮件引擎 IP(它将 RDNS 设置为“。”,以试图创建错位的分隔符漏洞)
无论如何,我已经正确配置了 fail2ban,它给我发邮件说它在 sasl 和 postfix 下启动并运行
这里是/etc/fail2ban/jail.local
findtime = 600
bantime = 600
maxretry = 6
[sasl-iptables]
enabled = true
filter = postfix-sasl
backend = polling
action = iptables[name=sasl, port=smtp, protocol=tcp]
sendmail-whois[name=sasl, [email protected]]
logpath = /var/log/maillog
maxretry = 5
bantime = 300
[postfix-tcpwrapper]
enabled = true
filter = postfix
action = hostsdeny[file=/not/a/standard/path/hosts.deny]
sendmail[name=Postfix, [email protected]]
logpath = /var/log/maillog
bantime = 300
maxretry = 6
##the following are done in sheer desperation - no idea if they are needed
[postfix]
enabled = true
port = smtp,ssmtp
filter = postfix
action = hostsdeny
logpath = /var/log/maillog
[perdition]
enabled = true
filter = perdition
action = iptables-multiport[name=perdition,port="110,143,993,995"]
logpath = /var/log/maillog
[dovecot-pop3imap]
enabled = true
port = pop3,pop3s,imap,imaps
filter = dovecot-pop3imap
action = hostsdeny
logpath = /var/log/maillog
谁能帮我解释一下为什么这些规则已经存在但/var/logs/maillog
仍然一直在制定,而且没有人被禁止?
[/EDIT] 作为一个 fail2ban 的菜鸟,我没有意识到它(有点)通过正则表达式手动操作每一行 - 这是我/etc/fail2ban/filter.d/postfix.conf
# Fail2Ban filter for selected Postfix SMTP rejections
#
#
[INCLUDES]
# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf
[Definition]
_daemon = postfix/smtpd
failregex = ^%(__prefix_line)sNOQUEUE: reject: RCPT from \S+\[<HOST>\]: 554 5\.7\.1 .*$
^%(__prefix_line)sNOQUEUE: reject: RCPT from \S+\[<HOST>\]: 450 4\.7\.1 : Helo command rejected: Host not found; from=<> to=<> proto=ESMTP helo= *$
^%(__prefix_line)sNOQUEUE: reject: VRFY from \S+\[<HOST>\]: 550 5\.1\.1 .*$
ignoreregex =
# Author: Cyril Jaquier
答案1
你还没有告诉我们你的postfix
过滤器里有什么,但如果你的安装和我的一样,它就像
failregex = reject: RCPT from (.*)\[<HOST>\]: 554
由于您向我们展示的日志行看起来与此完全不同,因此fail2ban
不会触发它们。如果您希望它们触发禁令,则需要编写自己的过滤器来匹配这些行。
但你可能会发现,为了阻止单个 IP 地址,自己制定规则更有效iptables
。例如
iptables -I INPUT 1 -s 209.15.212.253 -p tcp --dport 25 -j REJECT
可能会奏效。