EMOS-fail2ban
用户担心,自己的邮件账号被外部通过字典攻击怎么办,fail2ban是一个非常优秀的工具。fail2ban可以监视系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是调用防火墙屏蔽,也可以发送e-mail通知系统管理员),如:当有人在试探你的SSH、SMTP、POP3、webmail密码,只要达到你预设的次数,fail2ban就会调用防火墙屏蔽这个IP。
在日志中,发现在许多sasl login的报错日志,有尝试盗用账号发邮件的情况,
Nov 17 04:10:35 mail postfix/smtpd[13618]: warning: unknown[199.36.76.15]: SASL LOGIN authentication failed: authentication failure
Nov 17 04:10:36 mail postfix/smtpd[13618]: warning: unknown[199.36.76.15]: SASL LOGIN authentication failed: authentication failure
Nov 17 04:10:37 mail postfix/smtpd[13618]: warning: unknown[199.36.76.15]: SASL LOGIN authentication failed: authentication failure
Nov 17 04:10:38 mail postfix/smtpd[13618]: warning: unknown[199.36.76.15]: SASL LOGIN authentication failed: authentication failure
默认情况下,fail2ban工具是能pop3,webmail,sshd做阻挡,对sasl阻拦无效,需要修改sasl.conf文件
编辑/etc/fail2ban/jail.conf,增加
[sasl]
enabled = true
filter = sasl
action = iptables[name=sasl, port=25, protocol=tcp]
logpath = /var/log/maillog
bantime = 1200 #阻挡20分钟
findtime = 120 #在2分钟内尝试15次就被阻挡
maxretry = 15
修改/etc/fail2ban/filter.d/sasl.conf,
注释下行:
#failregex = : warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5)authentication failed$
failregex = : warning: unknown\[<HOST>\]: SASL LOGIN authentication failed: authentication failure
重启fail2ban服务,查看日志已生效
运行 iptables -L,显示如下,说明对sasl已生效
Chain fail2ban-sasl (1 references)
target prot opt source destination
DROP all -- 121.239.157.15 anywhere
DROP all -- 180.107.119.250 anywhere
RETURN all -- anywhere anywhere