Set Up ParseDMARC on Ubuntu 18.04, 16.04 to Analyze DMARC Reports

ParseDMARC is an open-source, self-hosted DMARC report analyzer. For those who don’t know, DMARC is an email security standard that can protect your domain name from email spoofing and also identify incoming spoofed emails to protect end users. In a previous article, we discussed how to create DMARC DNS record for your domain name and in this tutorial, we are going to set up ParseDMARC on Ubuntu 18.04/16.04 server so we can analyze DMARC reports.

Prerequisites

It is assumed that you have created a DMARC DNS record for your domain name.

To generate visualized data, ParseDMARC relies on Elasticsearch and Kibana, both of which are RAM hungry. They will use about 2G RAM after installation and require more RAM to process data. So you need a server with at least 3G RAM. You can click this special link to get $100 free credit on DigitalOcean. (For new users only). If you are already a DigitalOcean user, then you can click this special link to get $50 free credit on Vultr (for new users only). Once you have an account at DigitalOcean or Vultr, install Ubuntu 18.04 or 16.04 on your server and follow the instructions below.

Installing ParseDMARC on Ubuntu 18.04 or Ubuntu 16.04

ParseDMARC is a Python program and can be installed from the PyPI (Python Package Index) software repository. First, we need to install the Python package installer on Ubuntu 18.04/16.04. In the following command, we install the python3-pip package because ParseDMARC can only work Python 3. The geoipupdate package is used to update the MaxMind GeoIP database.

sudo apt install python3-pip geoipupdate

Then install the latest stable version of ParseDMARC with the following command.

sudo -H pip3 install -U parsedmarc

To check information about the parsedmarc package, you can run

pip3 show -f parsedmarc

To see command line options, run

parsedmarc --help

Installing Elasticsearch and Kibana on Ubuntu 18.04/16.04

ParseDMARC is a command-line program, which produces hard-to-read output. If you want to see visualized DMARC reports in a web-based interface, you need to install two other open-source programs: Elasticsearch and Kibana. Elasticsearch is a search and analytics engine and Kibana allows users to visualize data with charts and graphs in Elasicsearch.

We can install Elasticsearch and Kibana from the official repository with the following commands. Elasticsearch is written in Java programming language, so we also install the default-jre-headless (Java runtime environment) package in the last command.

sudo apt-get install -y apt-transport-https

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

sudo apt-get update

sudo apt-get install -y default-jre-headless elasticsearch kibana

By default, the Elasticsearch systemd service is disabled. You can start and enable it with the following commands.

sudo systemctl start elasticsearch

sudo systemctl enable elasticsearch

Then check the status.

systemctl status elasticsearch

We can see that it’s now enabled and running. (Hint: if this command doesn’t quit immediately, press Q to quit.)

parsedmarc elasticsearch

We also need to do the same for Kibaba.

sudo systemctl start kibana

sudo systemctl enable kibana

Check the status.

systemctl status kibana

parsedmarc kibana

Setting Up Nginx Reverse Proxy for Kibana

Kibana web server listens on 127.0.0.1:5601. We can use Nginx to set up reverse proxy to allow for remote access and also protect Kibana web interface. Run the following command to install Nginx from Ubuntu 18.04, 16.04 repository.

sudo apt install nginx

Create a Nginx virtual host file for Kibana.

sudo nano /etc/nginx/conf.d/kibana.conf

Put the following lines into the file. Replace the placeholder as necessary and you should create a DNS A record for the sub-domain.

server {
      listen 80;
      server_name dmarc.yourdomain.com;

      access_log /var/log/nginx/dmarc.access;
      error_log /var/log/nginx/dmarc.error;

      add_header X-Frame-Options SAMEORIGIN; 
      add_header X-Content-Type-Options nosniff;

      location / {
         proxy_pass http://127.0.0.1:5601;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
}

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx for the change to take effect.

sudo systemctl reload nginx

Now you can access Kibana dashboard at dmarc.yourdomain.com.  Click the Explore on my own button.

dmarc report analyzer open source

 

Enable HTTPS

To encrypt the HTTP traffic when you visit Kibana dashboard via a domain name, we can enable HTTPS by installing a free TLS certificate issued from Let’s Encrypt. Run the following command to install Let’s Encrypt client (certbot) on Ubuntu 18.04, 16.04 server.

sudo apt install certbot

If you use Nginx, then you also need to install the Certbot Nginx plugin.

sudo apt install python3-certbot-nginx

Next, run the following command to obtain and install TLS certificate.

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d dmarc.yourdomain.com

The certificate should now be obtained and automatically installed.

self-hosted dmarc analyzer

Restricting Access to the Kibana Dashboard

By default, Kibana doesn’t provide user authentication. To allow only trusted users to access Kibana dashboard, we can enable HTTP basic authentication in Nginx. First, we need to install the apache2-utils package which provides the htpasswd password file create tool.

sudo apt install apache2-utils

Then run the following command to create the admin user. You will need to set a password.

sudo htpasswd -c /etc/nginx/htpasswd admin

Next, edit the Kibana virtual host file.

sudo nano /etc/nginx/conf.d/kibana.conf

Add the following two lines in the listen 443 ssl server block.

auth_basic "Login required";
auth_basic_user_file /etc/nginx/htpasswd;

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx for the change to take effect.

sudo systemctl reload nginx

Now you reload the Kibana dashboard in your web browser, you will be asked to enter an username and password.

kibana HTTP basic authentication

Configuring ParseDMARC

In order to use ParseDMARC and send data to Elastisearch, we need to create a configuration file.

sudo nano /etc/parsedmarc.ini

Put the following lines in the file. Replace the palceholders as necessary.

[general]
# Save aggregate and forensic reports to Elasticsearch
save_aggregate = True
save_forensic = True

[imap]
# Log into the DMARC report email address and download data.
host = mail.yourdomain.com
port = 993
ssl = True
user = [email protected]
password = your_password_here
watch = True

[elasticsearch]
# Send data to Elastichsearch, which listens on port 9200.
hosts = 127.0.0.1:9200
ssl = False

[smtp]
# For sending email
host = mail.yourdomain.com
port = 587
ssl = True
user = [email protected]
password = your_password_here
from = [email protected]

# send results to this address
to = [email protected]

Save and close the file.

Running ParseDMARC as a Systemd Service

We can manually run ParseDMARC with parsedmarc -c /etc/parsedmarc.ini, but it’s more convenient to run ParseDMARC as a systemd service in the background. Create a systemd service unit file for ParseDMARC with the following command.

sudo nano /etc/systemd/system/parsedmarc.service

Put the following lines into the file.

[Unit]
Description=parsedmarc mailbox watcher
Documentation=https://domainaware.github.io/parsedmarc/
Wants=network-online.target
After=network.target network-online.target elasticsearch.service

[Service]
ExecStart=/usr/local/bin/parsedmarc -c /etc/parsedmarc.ini
User=parsedmarc
Group=parsedmarc
Restart=always
RestartSec=5m

[Install]
WantedBy=multi-user.target

Save and close the file. This systemd service will run as the parsedmarc user, so we need to create the user with the following command.

sudo adduser --system --no-create-home --group parsedmarc

We also need to protect the /etc/parsedmarc.ini file so only root and parsedmarc group users can read it.

sudo chown parsedmarc /etc/parsedmarc.ini

sudo chmod 600 /etc/parsedmarc.ini

ParseDMARC will need to download MaxMind GeoIP database to /usr/share/elasticsearch/modules/ingest-geoip directory, so the parsedmarc user needs to have write permission.

sudo setfacl -R -m "u:parsedmarc:rwx" /usr/share/elasticsearch/modules/ingest-geoip/

Now we can start and enable the parsedmarc systemd service.

sudo systemctl start parsedmarc

sudo systemctl enable parsedmarc

Check status.

systemctl status parsedmarc

parsedmarc systemd service

ParseDMARC will start fetching DMARC reports from the report email address and send them to Elasticsearch for analysis. If you have lots of DMARC report emails, please be patient to let ParseDMARC finish its work.

Importing ParseDMARC Objects In Kibana

To use the Kibana dashboard with ParseDMARC, first you need to import the ParseDMARC objects. You can use the following command to download it on your local Linux or Mac computer.

wget https://raw.githubusercontent.com/domainaware/parsedmarc/master/kibana/kibana_saved_objects.json

If you use Windows, then just copy the https link and paste it in browser address bar. Then in Kibana dashboard, click the last icon (management) in the left panel. Next, select Saved Objects and click the Import button to import the ParseDMARC objects you downloaded. parsedmarc kibana objects

Analyzing DMARC Reports in Kibana

Once the ParseDMARC systemd service finishes reading emails, the DMARC report data will show up in Kibana. The most useful report I think is the DMARC Summary. You can check it by going to Saved Objects -> DMARC Summary and then click the view Dashboard button. The most useful thing you can do with DMARC summary is to identify legitimate sources that failed DMARC check.

  1. Filter the results to only show messages that didn’t pass DMARC.
  2. Then you can see the message dispositions (How the receiving email servers handle them: do nothing, put into spam folder, or reject them).
  3. Scroll down to see the SPF alignment and DKIM alignment details to identify the reason why some legitimate sources failed DMARC check.

If the sender doesn’t include DKIM signature or doesn’t have a reverse DNS record, then it’s clearly spam.

DKIM alignment details

What surprises me is that some mailbox providers uses their own domain name in the DKIM signature when forwarding my legitimate emails. Other mailbox providers uses my domain name in the DKIM signature but still failed DKIM alignment. To further investigate the cause, you can check the individual forensic report.

Conclusion

I hope this tutorial helped you set up ParseDMARC on Ubuntu 18.04 and Ubuntu 16.04 to analyze DMARC reports. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 0 Average: 0]

3 Responses to “Set Up ParseDMARC on Ubuntu 18.04, 16.04 to Analyze DMARC Reports

  • Matthias Tisat
    1 month ago

    Hi,

    thanx for your very good How tos.

    Is there a chance to use ParseDMARC on a multi-domain-mailserver?

    Thanx

    Matthias

    • You can create multiple ParseDMARC configuration files like:

      /etc/parsedmarc-01.ini
      /etc/parsedmarc-02.ini
      /etc/parsedmarc-03.ini
      

      Each file using a different IMAP account to download DMARC report from different domains. Then create systemd service unit for each configuration file.

  • Sean Whalen
    2 weeks ago

    Thanks for helping people deploy ParseDMARC. Let me know if you have any feature requests 🙂

    Sean Whalen
    Author of ParseDMARC

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • If my answer helped you, please consider supporting this site. Thanks :)