Mail servers are a critical part of any organizations infrastructure. Hardening those will considerably improve your security baseline. We have compiled the most important steps.
The most crucial protocol to harden with respect to mail infrastructure is SMTP. This protocol serves a double service:
- Submitting mail from a Mail User Agent (e.g., Thunderbird, Outlook, Evolution, …) to a Mail Submission Agent or combined Mail Transfer Agents and Mail Submission Agents (e.g., sendmail, qmail, Exchange);
- Relaying/Forwarding mail from one MTA to a different MTA (e.g., from alice@example.com to bob@example.org).
Historically, both of these used SMTP over port 25 (ingoing and outgoing!) between the MUA↔MSA/MTA and MTA↔MTA.
Nowadays, this connection mode is mostly reserved for the latter use (relaying server-to-server) and mail submission (client-to-server) is done using port 465 with dedicated TLS/SSL tunneling or using STARTTLS on port 587. Both methods (ideally) setup an encrypted channel between the MUA and the MSA/MTA because the login credentials for the user are exchanged over this channel.
In contrast, MTA↔MTA communication does not verify user credentials and remains on port 25. This channel is unencrypted and there does not exist an equivalent to the dedicated TLS/SSL tunnel as for submission. However, if both servers support it, they may upgrade to an encrypted channel using STARTTLS on port 25 too.
In order to secure mail infrastructure, Internet Service Providers (ISPs) typically disallow opening port 25 on regular contracts to prevent abuse.
Whilst ISPs are quite restrictive handing out port 25 nowadays, this is not a sufficient security measure. By default, this would still allow anyone with such access to send mail on the behalf of anyone else through your server; this will, if the recipient’s mail server is well-configured with SPF/DKIM, see below, be bounced and your mail server likely reported and put on a denylist/spamlist in consequence.
Finally, to replace the missing authentication & authorization of the user sending the mail when relaying it — and in doing so defend against other Open Relays and other badly configured mail servers —, the receiving MTA must have some way to verify that the sender is actually allowed to send mails on behalf of the sending domain. This is done through additional DNS records, which
- announce what MTAs are allowed to send a mail from a specified domain in the mails envelope
From:header (SPF), and - establish a signature scheme for mail content to be verifiably from a reputable server with a cryptographic public key associated with that domain (DKIM).
Thus, SPF works on the MTA level to drop mails if they’re received from a server that’s not authorized to send from the given domain. DKIM allows the MUA to verify a single mail’s sender domain.
Both mechanisms need again be configured and announced through DNS.
