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:
1
apt-get install postfix
Copied!
During postfix installation, I set nodspot.com as the mail name. After the installation, this can be checked/changed here:
1
[email protected]-s-1vcpu-1gb-sfo2-01:~# cat /etc/mailname
2
nodspot.com
Copied!

DNS Records

DNS records for nodspot.com has to be updated like so:
A record pointing to the droplet IP

Testing Mail Server

Once postfix is installed and the DNS records are configured, we can test if the mail server is running by:
1
telnet mail.nodspot.com 25
Copied!
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:
1
[email protected]-s-1vcpu-1gb-sfo2-01:~# sendmail mantvydo@gmail.com
2
yolo
3
,
4
.
Copied!
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:
1
Delivered-To: mantvydo@gmail.com
2
Received: by 2002:a81:1157:0:0:0:0:0 with SMTP id 84-v6csp5026946ywr;
3
Tue, 2 Oct 2018 12:22:38 -0700 (PDT)
4
X-Google-Smtp-Source: ACcGV62oH69fwYnfV1zg+o+jbTpjQIzIzASmjoIsXbbfvdevE0LlkY32jflNS/acOtNBXiwzxYxP
5
X-Received: by 2002:a62:6547:: with SMTP id z68-v6mr17716388pfb.20.1538508158395;
6
Tue, 02 Oct 2018 12:22:38 -0700 (PDT)
7
ARC-Seal: i=1; a=rsa-sha256; t=1538508158; cv=none;
8
d=google.com; s=arc-20160816;
9
b=FpEgLAICLn66cI+DDvpIsStUrReQ8fArcreT7FyS8SYcFQXFiK44HDcxwVHXCA8Xxb
10
fUl+3HcerQEznHZMttZ4pZIMbN18pJS08wzuZdOlhGKAA2JSTkxGd+1PhJwDe1SFTYZc
11
NoARSHL9opemJKg5YqZNjSTDSTfk/QqaCbq7mQL9LAwCKzanGSNR/R/28WymYrdRACOR
12
GSmDCVvPaUaoemIP8+GwXkfU5Gkk49+F7t9Jbg23HKKq/YOhwF3ryeOEVfn74bhtZIkM
13
QcUzWn5WSL0lIm0nbd2t7677/wcabOg0TCoZj1IHg+I7yLXE7+QZOYX1TguKu16oZeqt
14
mTIA==
15
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
16
h=from:date:message-id;
17
bh=VSFU9fKoMQMmtQzPFdmefDuA+phTpwZXd9k5xGRzwRs=;
18
b=VZ2vHjhPUSs17PXAUDyjYzm0w5sdQYqFx7h9iirh/BF1krrl3MQg4QAgfeo0py9qZH
19
Xf8/9HmNe1pIgxnZiiZJeVijXeSHCIB4XkG4HYFJY2m/gQ9oZ4JSMfX/Kiw/CXEmbt71
20
YP5S7yQKQNkHw24XnP3WUeDDQ7XvENEfPIS+LlCVtQOPT8fM9TAWQReKz06idynolfhR
21
7P73wH8igwPea7586wdhSOtDYCURSMKTNVb8yP2eEPNBlP2u2jUrFImG2D2/lke4O6Iu
22
7zu96tCYEY9FVG11dPFheKlMjvMoL4rqPSAQ3zty4Cbi4Vy2Is6f/VF8AYZ34i0FJooj
23
eEkw==
24
ARC-Authentication-Results: i=1; mx.google.com;
25
spf=pass (google.com: domain of [email protected].com designates 206.189.221.162 as permitted sender) smtp.mailfrom=[email protected].com
26
Return-Path: <[email protected].com>
27
Received: from ubuntu-s-1vcpu-1gb-sfo2-01 ([206.189.221.162])
28
by mx.google.com with ESMTP id 38-v6si3160283pgr.237.2018.10.02.12.22.38
29
for <[email protected].com>;
30
Tue, 02 Oct 2018 12:22:38 -0700 (PDT)
31
Received-SPF: pass (google.com: domain of [email protected].com designates 206.189.221.162 as permitted sender) client-ip=206.189.221.162;
32
Authentication-Results: mx.google.com;
33
spf=pass (google.com: domain of [email protected].com designates 206.189.221.162 as permitted sender) smtp.mailfrom=root@nodspot.com
34
Received: by ubuntu-s-1vcpu-1gb-sfo2-01 (Postfix, from userid 0) id DC6DD3F156; Tue,
35
2 Oct 2018 19:22:37 +0000 (UTC)
36
Message-Id: <20181002192237.[email protected]-s-1vcpu-1gb-sfo2-01>
37
Date: Tue,
38
2 Oct 2018 19:22:31 +0000 (UTC)
39
From: root <[email protected].com>
40
41
yolo
42
,
Copied!

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.
original_msg.txt
3KB
Text
Email Headers

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:
/etc/postfix/header_checks
1
/^Received:.*/ IGNORE
2
/^X-Originating-IP:/ IGNORE
3
/^X-Mailer:/ IGNORE
4
/^Mime-Version:/ IGNORE
Copied!
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:
1
postmap /etc/postfix/header_checks
2
postfix reload
Copied!
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:
1
Delivered-To: [email protected]
2
Received: by 2002:a81:1157:0:0:0:0:0 with SMTP id 84-v6csp5668508ywr;
3
Wed, 3 Oct 2018 03:47:35 -0700 (PDT)
4
X-Google-Smtp-Source: ACcGV614wuffoVOsvFkTPPxCiRj0hgFwTIH7y3B4ziIaXfogLFjsoiFyYOdNVChhr+oRcL1axO+a
5
X-Received: by 2002:a17:902:a9cc:: with SMTP id b12-v6mr988630plr.198.1538563655360;
6
Wed, 03 Oct 2018 03:47:35 -0700 (PDT)
7
ARC-Seal: i=1; a=rsa-sha256; t=1538563655; cv=none;
8
d=google.com; s=arc-20160816;
9
b=qhbzI+R3vHbkqwp2ALOEQ0ItUXU/fA1kEmYln1dBe0CmLELuIfourst4gZVYiU0tAf
10
sRx20Z5Vcqvv9w6s6f2gVp6crlOuoX2cSKJCn/HyRYKiDB5aVKpEYTDjQtGEBRLoL9xm
11
/T8+3PgV6CHy/KowoPeLugKg3t5mIh9pq+Ig8gG+VVKZcFyvUBJa9YEgBgVKcMwew8H6
12
x8WzIB2zyavpZLnbIi6SrtheYZAeSTMTwXRutqxZl0n4O/iZS4Y+ZVdRlYeXFXFNdtMK
13
JFaS1XVLR4hYXOzlQT1IC2yeQlqf+Q3FJukmkDlDTgw91ImfZa0HtQYQoo3LwKotp92Q
14
1HiQ==
15
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
16
h=from:date:message-id;
17
bh=hZH42YPrA1C1YyKkQ/LM0S6pyh9p5LGmoqE/s4CGGts=;
18
b=Squ71HtAuuwYHfX+4z63WcgBMoiKbcX5KAQLKwfvlnXuF5QEJNHjfX0GwekViXJIZ5
19
D2v03648ni6W3/b6uXVoecrtX0MZ9Z/Ck+LxcJRi16toE4QfjR6fhX5l9OSKFjgqkst3
20
Exk9yB1iiX8IAoIvnSaT0pQ5UzOov5Yneti3HO8QbzeCnT1/HieLwIhB/d+znryw1mTQ
21
jj/VBlNEGFEJhpXjS7cbQFHQEz3yGl1YTSNB3Kxp9T5a7+ncsW3pOAlfKqNYpVywSlBe
22
s6OUSTZ/bEwVYP3dv9aHmbpOIV6rC8uPgUlm+SKYtlj9xiR9uXTtj21IbA0F1esFx+Up
23
jAQw==
24
ARC-Authentication-Results: i=1; mx.google.com;
25
spf=pass (google.com: domain of [email protected] designates 206.189.221.162 as permitted sender) [email protected]
26
Return-Path: <[email protected]>
27
Received: from ubuntu-s-1vcpu-1gb-sfo2-01 ([206.189.221.162])
28
by mx.google.com with ESMTP id y11-v6si1190446plg.237.2018.10.03.03.47.35
30
Wed, 03 Oct 2018 03:47:35 -0700 (PDT)
31
Received-SPF: pass (google.com: domain of [email protected] designates 206.189.221.162 as permitted sender) client-ip=206.189.221.162;
32
Authentication-Results: mx.google.com;
33
spf=pass (google.com: domain of [email protected] designates 206.189.221.162 as permitted sender) [email protected]
34
Message-Id: <[email protected]>
35
Date: Wed, 3 Oct 2018 11:47:28 +0100 (BST)
36
From: root <[email protected]>
37
38
removing traces like a sir
Copied!
headers-removed.txt
2KB
Text
Headers Removed
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

How To Install and Configure DKIM with Postfix on Debian Wheezy | DigitalOcean
DigitalOcean
How do I remove Received-headers from emails?
Server Fault
Remove sensitive information from email headers with postfix
ExampleSite
Last modified 2yr ago