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: