Open relay attacks pose a serious threat to email servers, allowing unauthorized users to send spam and malicious emails through your system. This guide provides a detailed, step-by-step process to secure your email server against open relay vulnerabilities and ensure safe email handling.
Table of Contents
- Introduction to Open Relay Attacks
- Understanding Open Relay Risks
- Identifying Open Relay Vulnerabilities
- Securing Postfix Against Open Relay
- Securing Exim Against Open Relay
- Securing Sendmail Against Open Relay
- Testing for Open Relay Vulnerabilities
- Implementing Additional Security Measures
- Monitoring and Maintaining Email Security
- Best Practices to Prevent Open Relay Attacks
1. Introduction to Open Relay Attacks
An open relay is a misconfigured email server that allows anyone on the internet to send email through it. Spammers exploit open relays to distribute bulk spam and phishing emails. This can lead to blacklisting of your mail server and reputational damage.
Common consequences of open relay attacks:
- Increased spam sent from your server
- Server blacklisting by major email providers
- Legal and compliance issues
2. Understanding Open Relay Risks
Open relays can:
- Facilitate email spoofing and phishing attacks
- Cause mail server overload
- Damage your IP reputation, leading to email delivery failures
3. Identifying Open Relay Vulnerabilities
Check if your email server is an open relay using online tools like MXToolbox or manual tests with telnet
or swaks
.
Manual Open Relay Test Using Telnet
telnet mail.example.com 25 HELO test MAIL FROM:<attacker@example.com> RCPT TO:<victim@example.com> DATA Subject: Open Relay Test This is a test email. . QUIT
If the server accepts and forwards the message, it is an open relay.
4. Securing Postfix Against Open Relay
Step 1: Verify Configuration Files
Postfix uses /etc/postfix/main.cf
for primary settings. Ensure these directives are present:
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination mynetworks = 127.0.0.0/8
Step 2: Restrict Relay Access
Ensure only trusted networks are allowed to relay by setting mynetworks
.
mynetworks = 127.0.0.1/8, [Your Trusted IP Range]
Step 3: Reload Postfix
sudo systemctl restart postfix
5. Securing Exim Against Open Relay
Step 1: Verify Configuration Files
Edit /etc/exim/exim.conf
and ensure the following settings:
hostlist relay_from_hosts = 127.0.0.1 : [Your Trusted IP Range]
Step 2: Disable Unauthorized Relaying
Ensure Exim does not accept unauthorized relay requests:
deny message = Relaying denied !hosts = : +relay_from_hosts domains = !+local_domains
Step 3: Reload Exim
sudo systemctl restart exim
6. Securing Sendmail Against Open Relay
Step 1: Verify Configuration Files
Check /etc/mail/sendmail.mc
for the following settings:
FEATURE(`access_db')
Step 2: Define Access Rules
Edit /etc/mail/access
to allow only specific hosts:
localhost.localdomain RELAY 127.0.0.1 RELAY 192.168.1 RELAY ALL REJECT
Rebuild and reload Sendmail:
makemap hash /etc/mail/access < /etc/mail/access sudo systemctl restart sendmail
7. Testing for Open Relay Vulnerabilities
Using SWAKS (Swiss Army Knife for SMTP)
Install and test with SWAKS:
sudo apt install swaks swaks --to user@example.com --from attacker@example.com --server yourmailserver.com
If the message is delivered, the server may be an open relay.
Online Relay Testing Tools
Use external services like:
8. Implementing Additional Security Measures
Enable SMTP Authentication
Require users to authenticate before sending mail.
Example for Postfix:
smtpd_sasl_auth_enable = yes
Use TLS Encryption
Ensure secure transmission with TLS.
smtpd_tls_security_level = may
Implement DKIM, SPF, and DMARC
Set up these protocols to validate email integrity.
9. Monitoring and Maintaining Email Security
Enable Logging
Ensure logging is active:
tail -f /var/log/mail.log
Automate Security Audits
Use scripts and cron jobs to regularly test for open relays.
10. Best Practices to Prevent Open Relay Attacks
- Limit Trusted Networks: Only allow relaying from verified IP ranges.
- Require Authentication: Ensure all users authenticate before sending mail.
- Update Regularly: Keep your MTA and packages up-to-date.
- Monitor Logs: Regularly review mail logs for suspicious activity.
- Use External Tools: Periodically test using online relay checkers.
By following these guidelines, you will effectively secure your mail server against open relay attacks and maintain a safe, spam-free email environment.