SMTP Forwarders / Relays
SMTP Redirector + Stripping Email Headers
Setting up Relay Mail Server
I am going to set up a mail server that will be later used as an SMTP relay server. First off, a new Ubuntu droplet was created in Digital Ocean:

Postfix MTA was installed on the droplet with:
During postfix installation, I set nodspot.com as the mail name. After the installation, this can be checked/changed here:
DNS Records
DNS records for nodspot.com has to be updated like so:


Testing Mail Server
Once postfix is installed and the DNS records are configured, we can test if the mail server is running by:
If successful, you should see something like this:

We can further test if the mail server works by trying to send an actual email like so:
Soon enough, the email comes to my gmail:

...with the following headers - all as expected. Note that at this point the originating IP seen in headers is my droplet IP 206.189.221.162:
Setting up Originating Mail Server
We need to set up the originating mail server that will use the server we set up earlier as a relay server. To achieve this, on my attacking machine, I installed postfix mail server.
The next thing to do is to amend the /etc/postfix/main.cf and set the relayhost=nodspot.comwhich will make the outgoing emails from the attacking system travel to the nodspot.com mail server (the server we set up above) first:

Once the change is made and the postfix server is rebooted, we can try sending a test email from the attacking server:

If you do not receive the email, make sure that the relay server is not denying access for the attacking machine. If you see your emails getting deferred (on your attacking machine) with the below message, it is exactly what is happening:

Once the relay issue is solved, we can repeat the test and see a successful relay:

This time the headers look like so:

Note how this time we are observing the originating host's details such as a host name and an IP address - this is unwanted and we want to redact that information out.
Removing Sensitive Headers in Postfix
We need to make some configuration changes in the relay server in order to redact the headers for outgoing emails.
First off, let's create a file on the server that contains regular expressions that will hunt for the headers that we want removed:
Next we need to amend the /etc/postfix/master.cf to include the following line: -o header_checks=regexp:/etc/postfix/header_checks:

This will tell the postfix server to remove headers from outgoing emails that match regular expressions found in the file we created above.
Save the changes and reload the postfix server:
Now send a test email from the attacking machine again and inspect the headers of that email:


Note how the Received headers exposing the originating (the attacking) machine were removed, which is exactly what we wanted to achieve:
This lab is not going to deal with the emails being marked as phishing by gmail. This, however, is related to setting up DKIM, PTR records and the likes, see below for more references.
References
Last updated
Was this helpful?
