On this page 20 sections
- What SMTP is
- Common SMTP ports
- Initial enumeration
- SMTP banner
- HELO and EHLO
- Why EHLO matters
- VRFY
- EXPN
- SMTP user enumeration
- STARTTLS
- SMTP AUTH
- Basic SMTP mail flow
- Send a test message manually
- Open relay
- SMTP commands with Nmap
- Metasploit SMTP version scanner
- Metasploit SMTP user enumeration
- SMTP vs POP3 vs IMAP
- Enumeration workflow
- Quick reference
What SMTP is
SMTP, or Simple Mail Transfer Protocol, is used to send and relay email between mail clients and mail servers or between mail servers. SMTP is primarily a message-delivery protocol rather than a protocol for retrieving messages.
Common SMTP ports
TCP port 25 is traditionally used for mail transfer between servers. Port 587 is commonly used for authenticated message submission by clients. Port 465 is commonly associated with implicit TLS SMTP submission.
Initial enumeration
Start by identifying the SMTP service, implementation and available capabilities. The banner may reveal the mail server software, hostname or version information.
nmap -sV -p 25,465,587 <TARGET>nmap -sC -sV -p 25,465,587 <TARGET>nc -nv <TARGET> 25telnet <TARGET> 25SMTP banner
An SMTP server normally responds with a 220 banner when a connection is established. The response may reveal the server hostname and mail software.
nc -nv <TARGET> 25HELO and EHLO
HELO identifies the SMTP client to the server. EHLO is the Extended SMTP version and usually causes the server to return a list of supported extensions and capabilities.
HELO example.comEHLO example.comWhy EHLO matters
EHLO can reveal useful SMTP capabilities such as STARTTLS, AUTH methods, message-size limits and other supported extensions.
EHLO example.comVRFY
VRFY asks the SMTP server to verify whether a mailbox or user exists. Some servers disable or restrict this command because it can expose valid usernames.
VRFY <USERNAME>EXPN
EXPN requests expansion of a mailing list or alias. If enabled, it may reveal users or addresses associated with a distribution list.
EXPN <LIST>SMTP user enumeration
SMTP user enumeration may be possible through VRFY, EXPN or differences in server responses during SMTP transactions. Modern servers often restrict these techniques, so results should be validated carefully.
nmap -p 25 --script smtp-enum-users <TARGET>STARTTLS
STARTTLS upgrades an existing plaintext SMTP connection to TLS. If the server advertises STARTTLS after EHLO, the client can request encryption before continuing the SMTP session.
nmap -p 25 --script smtp-commands <TARGET>openssl s_client -starttls smtp -connect <TARGET>:25SMTP AUTH
SMTP AUTH allows clients to authenticate before sending email. EHLO may reveal supported authentication mechanisms such as PLAIN or LOGIN.
EHLO example.comBasic SMTP mail flow
A manual SMTP transaction generally follows HELO or EHLO, MAIL FROM, RCPT TO, DATA and finally a single dot on its own line to finish the message body.
MAIL FROM:<sender@example.com>RCPT TO:<recipient@example.com>DATASend a test message manually
When authorised, SMTP can be tested manually to understand how the server handles sender and recipient addresses.
EHLO example.com
MAIL FROM:<test@example.com>
RCPT TO:<user@example.com>
DATA
Subject: Test
Test message
.
QUITOpen relay
An open relay is an SMTP server that accepts mail from an unauthorised external sender and relays it to an external recipient. This is a mail-server misconfiguration and can be abused for spam or phishing.
nmap -p 25 --script smtp-open-relay <TARGET>SMTP commands with Nmap
Nmap can enumerate commands advertised by the SMTP server and provide a quick overview of available capabilities.
nmap -p 25 --script smtp-commands <TARGET>Metasploit SMTP version scanner
Metasploit provides auxiliary modules for SMTP service detection and user enumeration.
msfconsoleuse auxiliary/scanner/smtp/smtp_versionset RHOSTS <TARGET>runMetasploit SMTP user enumeration
The smtp_enum module can test potential usernames against supported SMTP enumeration behaviour.
use auxiliary/scanner/smtp/smtp_enumset RHOSTS <TARGET>show optionsrunSMTP vs POP3 vs IMAP
SMTP is primarily used to send and relay messages. POP3 and IMAP are used to retrieve or access stored email. POP3 commonly uses ports 110 and 995, while IMAP commonly uses 143 and 993.
Enumeration workflow
Identify the SMTP ports and service version, inspect the banner, issue EHLO to enumerate capabilities, check STARTTLS and authentication support, test user-enumeration behaviour where authorised and determine whether the server improperly relays external mail.
nmap -sC -sV -p 25,465,587 <TARGET>nmap -p 25 --script smtp-commands <TARGET>nmap -p 25 --script smtp-enum-users <TARGET>Quick reference
These are the SMTP commands and tools worth remembering.
nmap -sV -p 25,465,587 <TARGET>nc -nv <TARGET> 25EHLO example.comVRFY <USERNAME>EXPN <LIST>openssl s_client -starttls smtp -connect <TARGET>:25use auxiliary/scanner/smtp/smtp_versionuse auxiliary/scanner/smtp/smtp_enum