Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
tutoriaux:install-email-server:install-email-server-part-6 [2023/01/06 16:41] – supprimée - modification externe (Unknown date) 127.0.0.1 | tutoriaux:install-email-server:install-email-server-part-6 [2024/09/27 18:31] (Version actuelle) – frater | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Part 6 - OpenDMARC with Postfix to Block Spam/Email Spoofing ====== | ||
+ | This tutorial will be showing you how to set up OpenDMARC with Postfix SMTP server on debian to block email spoofing and spam. OpenDMARC is an open-source DMARC email policy filter for MTAs (Message Transport Agent, aka SMTP server). | ||
+ | |||
+ | ===== What is DMARC ===== | ||
+ | |||
+ | DMARC (Domain-based Message Authentication, | ||
+ | |||
+ | If a domain owner created [[https:// | ||
+ | |||
+ | [[..: | ||
+ | |||
+ | ===== Email Spoofing Example ===== | ||
+ | |||
+ | A spammer sent me a Random email using '' | ||
+ | |||
+ | {{ tutoriaux: | ||
+ | |||
+ | '' | ||
+ | |||
+ | {{ tutoriaux: | ||
+ | |||
+ | Then I checked the email headers, which shows SPF failed. There’s no DKIM signature. So DMARC check fails. This is a spoofed email. | ||
+ | |||
+ | [[..: | ||
+ | |||
+ | This goes to show that not only big brands are being used by email spoofers, any domain names on the Internet could be impersonated by bad actors. Unfortunately the DMARC policy for this domain name is p=none, which tells receiving email server to do nothing special if DMARC check fails. If the policy is to p=reject, then my Postfix SMTP server would reject this email with OpenDMARC. | ||
+ | |||
+ | Paypal and Facebook have created a reject DMARC policy for their domain name. | ||
+ | |||
+ | opendmarc configuration | ||
+ | |||
+ | So if a bad actor tries to spoof Paypal or Facebook, my email server can reject the spoofed email with OpenDMARC. There are many other well-known domain names that deployed a reject DMARC policy, as can be seen in the table below. | ||
+ | |||
+ | bankofamerica.com | ||
+ | yahoo.com | ||
+ | chase.com | ||
+ | wellsfargo.com | ||
+ | facebook.com | ||
+ | google.com | ||
+ | youtube.com | ||
+ | twitter.com | ||
+ | reddit.com | ||
+ | instagram.com | ||
+ | linkedin.com | ||
+ | medium.com | ||
+ | pinterest.com | ||
+ | dropbox.com | ||
+ | microsoft.com | ||
+ | whatsapp.com | ||
+ | The secure mailbox provider Protonmail is using Postfix and OpenDMARC to perform DMARC checks on inbound emails and I will show you how to do the same on your own Postfix SMTP server. | ||
+ | |||
+ | ===== Prerequisites ===== | ||
+ | |||
+ | This tutorial is for mailbox providers and anyone who run their own mail server, to protect their users from being scammed by email spoofing. If you are a domain name owner and want to prevent your domain name from being used by email spoofers, please read this [[tutoriaux: | ||
+ | |||
+ | To follow this tutorial, you need to get [[tutoriaux: | ||
+ | |||
+ | ===== Setting up OpenDMARC ===== | ||
+ | |||
+ | OpenDMARC is an open-source software that can perform DMARC verification and reporting. It’s already in the Ubuntu repository, so you can run the following command to install it. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | If you are asked to configure a database for OpenDMARC with dbconfig-common, | ||
+ | |||
+ | {{ tutoriaux: | ||
+ | |||
+ | Once installed, it will be automatically started. Check its status with: | ||
+ | |||
+ | systemctl status opendmarc | ||
+ | Output: | ||
+ | |||
+ | < | ||
+ | ● opendmarc.service - OpenDMARC Milter | ||
+ | | ||
+ | | ||
+ | Docs: man: | ||
+ | | ||
+ | Main PID: 14858 (opendmarc) | ||
+ | Tasks: 6 (limit: 1110) | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | <WRAP round important> | ||
+ | Hint: If the above command doesn’t quit immediately, | ||
+ | </ | ||
+ | |||
+ | Note that auto-start at system boot time is disabled. We can enable it by: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Then edit the main configuration file with your text editor. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Find the following line: | ||
+ | |||
+ | < | ||
+ | |||
+ | By default, OpenDMARC uses the MTA hostname as the '' | ||
+ | |||
+ | < | ||
+ | |||
+ | Next, add the following line. Replace the hostname with your real Postfix hostname. This tells OpenDMARC to trust authentication result with '' | ||
+ | |||
+ | < | ||
+ | |||
+ | If the Postfix hostname isn’t included in the '' | ||
+ | |||
+ | < | ||
+ | |||
+ | Then find this line: | ||
+ | |||
+ | < | ||
+ | |||
+ | By default, OpenDMARC won’t reject emails that fail DMARC check, even if the domain’s policy is set to '' | ||
+ | |||
+ | < | ||
+ | |||
+ | You may want OpenDMARC to ignore SMTP clients that are successfully authenticated via SMTP AUTH. For example, I have a Postfix SMTP server running on my blog web server that uses my main mail server as a relay to send notification emails, so I want openDMARC to ignore emails that are submitted from my blog web server. This also applies to desktop/ | ||
+ | |||
+ | < | ||
+ | |||
+ | Add the following line at the end of this file. | ||
+ | |||
+ | < | ||
+ | |||
+ | This will reject emails that don’t conform to email header standards as described in RFC5322. For example, if an incoming email doesn’t have From: header or date: header, it will be rejected. A From: field from which no domain name could be extracted will also be rejected. | ||
+ | |||
+ | It’s recommended to also add the following line at the end of this file. This will make OpenDMARC perform a fallback SPF check itself when it can find no SPF results in the message header. | ||
+ | |||
+ | < | ||
+ | |||
+ | OpenDMARC is implemented as a milter (mail filter). Postfix can talk to milter applications via Unix socket. The default socket file used by OpenDMARC is / | ||
+ | |||
+ | Find the following line. | ||
+ | |||
+ | < | ||
+ | Change it to: | ||
+ | |||
+ | < | ||
+ | |||
+ | Save and close the file. | ||
+ | |||
+ | <WRAP round info> | ||
+ | Note: The / | ||
+ | Create a directory to hold the OpenDMARC socket file and change the ownership so that opendmarc user and opendmarc group can access it. | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Change permission to 750 to restrict access, so users not in group opendmarc can’t access this directory. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Add user postfix to group opendmarc. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Then restart OpenDMARC. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | ===== Configure Postfix SMTP Server ===== | ||
+ | |||
+ | Edit the main configuration file. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | If you have already configured OpenDKIM, then you should have lines in this file like below. | ||
+ | |||
+ | < | ||
+ | # Milter configuration | ||
+ | milter_default_action = accept | ||
+ | milter_protocol = 6 | ||
+ | smtpd_milters = local: | ||
+ | non_smtpd_milters = $smtpd_milters | ||
+ | </ | ||
+ | |||
+ | Now you just need to add the OpenDMARC socket file so that Postfix can talk to OpenDMARC. (Make sure it’s after the OpenDKIM socket.) | ||
+ | |||
+ | < | ||
+ | # Milter configuration | ||
+ | milter_default_action = accept | ||
+ | milter_protocol = 6 | ||
+ | smtpd_milters = local: | ||
+ | non_smtpd_milters = $smtpd_milters | ||
+ | </ | ||
+ | |||
+ | Save and close the file. Then restart Postfix for the change to take effect. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | |||
+ | ===== Testing OpenDMARC Verification ===== | ||
+ | |||
+ | Now send an email from your other email address like Gmail to your domain address. After that, check the email headers. If OpenDMARC is working correctly, you can see the DMARC verification results like below. | ||
+ | |||
+ | < | ||
+ | |||
+ | I sent an email from my Gmail account to my domain email address and it passed DMARC verification. If you don’t see this email header, then check your mail logs. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | You will see something like below, which means OpenDMARC is working. | ||
+ | |||
+ | < | ||
+ | opendmarc[26495]: | ||
+ | opendmarc[26495]: | ||
+ | </ | ||
+ | |||
+ | ==== Ignoring Authentication-Results ==== | ||
+ | |||
+ | If you see the following message. | ||
+ | |||
+ | < | ||
+ | |||
+ | it means OpenDMARC is ignoring the SPF and DKIM verification results, so OpenDMARC isn’t working. You need to add the following line in ''/ | ||
+ | |||
+ | < | ||
+ | |||
+ | If you change the Postfix '' | ||
+ | |||
+ | < | ||
+ | |||
+ | ==== Postfix Can’t Connect to OpenDMARC ==== | ||
+ | |||
+ | If you find the following error in the Postfix mail log (''/ | ||
+ | |||
+ | < | ||
+ | |||
+ | you should check if the opendmarc service is running. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | If '' | ||
+ | |||
+ | < | ||
+ | |||
+ | Find the following line: | ||
+ | |||
+ | < | ||
+ | |||
+ | Replace it with | ||
+ | |||
+ | < | ||
+ | |||
+ | So OpenDMARC will be listening on the '' | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Find the following line: | ||
+ | |||
+ | < | ||
+ | Replace it with: | ||
+ | |||
+ | < | ||
+ | |||
+ | So Postfix will connect to OpenDMARC via the TCP/IP socket. Restart OpenDMARC and Postfix. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | ===== Testing OpenDMARC with Telnet ===== | ||
+ | |||
+ | You can use telnet to spoof another domain name, such as paypal.com. First, run the following command on your local computer to connect to port 25 of your mail server. | ||
+ | |||
+ | < | ||
+ | |||
+ | Then use the following steps to send a spoof email. (server response are starting with ''>>'' | ||
+ | |||
+ | < | ||
+ | HELO mail.paypal.com | ||
+ | >>250 mail.yourdomain.com | ||
+ | MAIL FROM:< | ||
+ | >>250 2.1.0 Ok | ||
+ | RCPT TO:< | ||
+ | >>250 2.1.5 Ok | ||
+ | DATA | ||
+ | >>354 End data with < | ||
+ | From: | ||
+ | To: | ||
+ | Subject: | ||
+ | |||
+ | Click this link to update your password. | ||
+ | . | ||
+ | >>550 5.7.1 rejected by DMARC policy for paypal.com | ||
+ | quit | ||
+ | </ | ||
+ | |||
+ | As you can see, my mail server rejected this email because it didn’t pass DMARC check and Paypal deployed a p=reject policy. | ||
+ | |||
+ | <WRAP round important> | ||
+ | If a domain’s DMARC policy is set to p=quarantine, | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== How to Whitelist an IP Address in OpenDMARC ===== | ||
+ | |||
+ | If you want to allow your other server to relay emails via port 25 of your main mail server which runs OpenDMARC, then you should whitelist the IP address of the other server in OpenDMARC, because OpenDMARC will check the From: domain in relay emails as well. | ||
+ | |||
+ | Edit OpenDMARC config file. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Add the following line at the end of this file. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Save and close the file. Then create the / | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Create the ignore.hosts file. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Add the IP addresses you want to whitelist in this file like so: | ||
+ | |||
+ | < | ||
+ | 127.0.0.1 | ||
+ | 12.34.56.78 | ||
+ | </ | ||
+ | |||
+ | Save and close the file. Then restart OpenDMARC. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | ===== Conclusion ===== | ||
+ | |||
+ | I hope this tutorial helped you set up OpenDMARC with Postfix SMTP server on Ubuntu to block email spoofing and spam. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂 | ||
+ | |||
+ | {{page> |