Bobcares

How to setup Fail2ban for Zimbra Mail Server

by | Nov 7, 2019

Mail servers like Zimbra has its own anti-spam addon to block malicious activity. Fail2ban provides additional protection to the mail server.

A good mail server always fight against spam!

Fail2ban can easily ban any IP that makes too many login attempts.

At Bobcares, we often receive requests to protect mail servers as part of our Server Management Services.

Today, let’s discuss how our Support Engineers set up fail2ban for Zimbra mail for our customers.

 

Zimbra Mail server with Fail2ban

Zimbra provides open source server and client software for messaging and collaboration.

To protect mails from continuous attacks we use fail2ban. Additionally, Fail2ban protects the server from brute-force attacks.

Fail2ban scans log files and ban IPs that show malicious signs.

Let us discuss how our Support Engineers setup Fail2ban for Zimbra Mail Server.

 

How to setup fail2ban for Zimbra mail server

Recently one of our customers contacted us to set up fail2ban for his Zimbra Mail Server. Let us discuss how we set up fail2ban for our customers.

First, we make sure that fail2ban and iptables are installed on the server. If not we install fail2ban and iptables.

We need to create a filter in fail2ban. The filter is used to identify authentication failures for that specific service.

By default, there are filters for the most commonly used service. The Zimbra is yet to feature in the list. So we manually add the filter at /etc/fail2ban/filter.d. Create a file and we add the below contents.

vi /etc/fail2ban/filter.d/zimbra.conf
[Definition]
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;$
\[oip=<HOST>;.* SoapEngine - handler exception: authentication failed for .*, account not found$
WARN .*;ip=<HOST>;ua=ZimbraWebClient .* security - cmd=AdminAuth; .* error=authentication failed for .*;$
NOQUEUE: reject: RCPT from .*\[<HOST>\]: 550 5.1.1 .*: Recipient address rejected:

Save the file.

Now we need to add the jail content for Zimbra. We add the details in the jail.conf or jail.local based on the configuration. We edit the file

vi /etc/fail2ban/jail.local
# This jail forces the backend to "polling".

[ssh-iptables]

enabled = false
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
sendmail-whois[name=SSH, dest=mail@domian.com, sender=mail@domain.com]
logpath = /var/log/messages
maxretry = 5

# jail for Zimbra

[zimbra-account]
enabled = true
filter = zimbra
action = iptables-allports[name=zimbra-account]
sendmail[name=zimbra-account, dest=mail@domain.com]
logpath = /opt/zimbra/log/mailbox.log
bantime = 600
maxretry = 5

[zimbra-audit]
enabled = true
filter = zimbra
action = iptables-allports[name=zimbra-audit]
sendmail[name=Zimbra-audit, dest=mail@domain.com]
logpath = /opt/zimbra/log/audit.log
bantime = 600
maxretry = 5

[zimbra-recipient]
enabled = true
filter = zimbra
action = iptables-allports[name=zimbra-recipient]
sendmail[name=Zimbra-recipient, dest=mail@domain.com]
logpath = /var/log/zimbra.log
bantime = 172800
maxretry = 5

# jail for postfix since postfix performs Zimbra mail transfer

[postfix]
enabled = true
filter = postfix
action = iptables-multiport[name=postfix, port=smtp, protocol=tcp]
sendmail-buffered[name=Postfix, dest=mail@domain.com]
logpath = /var/log/zimbra.log
bantime = 172800
maxretry = 5

Next, we change the configuration of Sendmail. We edit the file /etc/fail2ban/action.d/sendmail.conf and we change

Fail2Ban" | /usr/sbin/sendmail -f <sender> <dest>

to

Fail2Ban" | /opt/zimbra/postfix/sbin/sendmail -f <sender> <dest>

Finally, we restart the Fail2ban service.

service fail2ban restart 

We use the command to find the details regarding the ban.

fail2ban-client status zimbra-audit 

The output displays as

We also monitor it using the command.

[Need help on integrating Fail2ban on the Zimbra mail server? We can do it for you.]

 

Conclusion

In short, the Zimbra fail2ban combination works well in fighting again mail server attacks. We have also discussed how our Support Engineers set up fail2ban for the Zimbra Mail Server.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

1 Comment

  1. Mike

    In my zimbra version 8.8.15 the sendmail command is located here:
    ./opt/zimbra/common/sbin/sendmail

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF