
Originally Posted by
jimbo
Maybe a good fail2ban rule for /opt/zimbra/log/audit.log would be of benefit. Anybody have one to share?
I have fail2ban rules set up for pop3/imap, web, web admin, and postfix. They seem to work, though I haven't tested extensively.
/etc/fail2ban/jail.conf
Code:
[zimbra-account]
enabled = true
filter = zimbra
action = iptables-multiport[name=Zimbra-account, port="pop3,pop3s,imap,imaps", protocol=tcp]
sendmail[name=Zimbra-account, dest=it@here.com]
logpath = /opt/zimbra/log/mailbox.log
bantime = 600
ignoreip = 127.0.0.1
maxretry = 5
[zimbra-audit]
enabled = true
filter = zimbra
action = iptables-multiport[name=Zimbra-audit, port="pop3,pop3s,imap,imaps", protocol=tcp]
sendmail[name=Zimbra-audit, dest=it@here.com]
logpath = /opt/zimbra/log/audit.log
bantime = 600
ignoreip = 127.0.0.1
maxretry = 5
[postfix]
enabled = true
filter = postfix
action = iptables[name=Postfix, port=smtp, protocol=tcp]
sendmail[name=Postfix, dest=it@here.com]
logpath = /var/log/maillog
bantime = 600
ignoreip = 127.0.0.1
maxretry = 5 I copied cyrus-imap.conf to zimbra.conf, then edited.
/etc/fail2ban/filter.d/zimbra.conf, in the [Definition] section:
Code:
failregex = \[ip=<HOST>;\] account - authentication failed for .* \(no such account\)$
\[ip=<HOST>;\] security - cmd=Auth; .* error=authentication failed for .*, invalid password;$
;oip=<HOST>;.* security - cmd=Auth; .* protocol=soap; error=authentication failed for .* invalid password;$
WARN .*;ip=<HOST>;ua=ZimbraWebClient .* security - cmd=AdminAuth; .* error=authentication failed for .*;$ At first, I used audit.log, but it doesn't log invalid accounts. So, I made two jail rules. Most of the probes I get are to determine valid usernames, with failures being logged to mailbox.log. Only after that do they try passwords with those users. This filter will parse both POP3 and IMAP. The last 2 regex deal with the web and web admin logins. I adapted them from someone else's post, for v6.x. The regex will likely be different for 5.x.
Obviously, you may want to change the rule names, bantime, maxretry. I have not permanently settled on those myself. The maxretry should be less than the "consecutive failed logins allowed" in the COS, if the "failed login lockout" is enabled. The multiport Zimbra action will ban all ports to the offending IP. I put in several protocols, though plain pop3 is of most interest. You also may not want the sendmail option, to get ban emails. There is also a iptables-multiport-log action, if you want logs.