Simple Mail Transfer Protocol (SMTP) is the backbone of email communication across the internet. It handles the transfer of emails between mail servers and from clients to servers. Understanding SMTP's structure and common misconfigurations is essential for comprehensive security assessments.
Protocol Basics
SMTP typically operates on:
Port 25: Standard unencrypted SMTP
Port 465: SMTP with SSL/TLS encryption (SMTPS)
Port 587: SMTP with STARTTLS (submission port)
Protocol Flow
The email delivery process involves multiple components:
MUA (Mail User Agent): Email client that composes messages
MSA (Mail Submission Agent): Validates email before sending
MTA (Mail Transfer Agent): Handles routing between mail servers
MDA (Mail Delivery Agent): Delivers email to recipient's mailbox
SMTP Flow
SMTP Commands
SMTP uses a set of commands for communication between clients and servers:
Command
Description
AUTH PLAIN
Authentication service extension
HELO
Client identifies itself with hostname
MAIL FROM
Specifies the email sender
RCPT TO
Specifies the email recipient
DATA
Initiates the transmission of the email
RSET
Aborts the current transaction but keeps connection
VRFY
Verifies if a mailbox is available
EXPN
Checks mailbox availability and expands mailing lists
NOOP
No operation; prevents disconnection due to timeout
QUIT
Terminates the session
Enumeration Techniques
Banner Grabbing
Example output:
Scanning with Nmap
MX Record Enumeration
Identify mail servers using DNS queries:
Example output:
User Enumeration
SMTP servers can often be abused to enumerate valid email accounts.
Using VRFY Command
Example response:
Using EXPN Command
Particularly useful for finding users in distribution lists:
Example response:
Using RCPT TO Command
This requires initiating an email transaction:
Example response:
Automated User Enumeration
Using the smtp-user-enum tool:
Example output:
Authentication Attacks
Once valid users are identified, authentication attacks can be attempted.
Password Spraying with Hydra
Example output:
Open Relay Abuse
An SMTP open relay allows anyone to send emails through the server, which can be abused for spam or phishing.
Testing for Open Relay
Example output:
Exploiting Open Relay
Using the swaks tool to send emails through an open relay:
Cloud Email Services Enumeration
Modern environments often use cloud email services like Microsoft 365 or Google Workspace.
O365 Enumeration Example
Using the o365spray tool:
Password Spraying against Cloud Services
Vulnerability Assessment
Common SMTP Vulnerabilities
Open Relay: Allows unauthorized email sending
User Enumeration: Leaks valid usernames
Cleartext Authentication: Transmits credentials in plaintext
Outdated Software: May have known vulnerabilities
Missing TLS: Allows eavesdropping on email communications
Weak Authentication: Susceptible to brute force attacks
Software-Specific Vulnerabilities
Mail Server
Notable Vulnerabilities
Sendmail < 8.14.9
Multiple buffer overflows
Exim < 4.92.3
Remote code execution vulnerabilities
Postfix < 3.3.1
Denial of service vulnerabilities
Microsoft Exchange
ProxyLogon, ProxyShell, etc.
Defense Evasion Techniques
Avoiding Detection during SMTP Testing
Rate limiting: Space out requests to avoid triggering alerts
Careful user selection: Target non-privileged accounts in password spraying
Vulnerability Assessment: Check for known CVEs based on version
Exploitation: Test identified vulnerabilities
Post-Exploitation: Leverage access for further objectives
Remediation Strategies
When reporting SMTP vulnerabilities, consider recommending:
Disable VRFY/EXPN commands unless required
Implement authentication for all SMTP transactions
Enable TLS for all communications
Update mail server software regularly
Implement rate limiting to prevent brute force attacks
Configure SPF, DKIM, and DMARC to prevent spoofing
Regular security testing of email infrastructure
Practical Testing Scripts
Simple SMTP User Enumeration Script
Testing All SMTP Commands
By understanding SMTP services and their security implications, penetration testers can effectively identify and exploit misconfigurations and vulnerabilities in email systems.
telnet 10.129.14.128 25
HELO test
MAIL FROM: test@example.com
RCPT TO: admin
RCPT TO: nonexistentuser
220 mail.inlanefreight.htb ESMTP Postfix (Ubuntu)
HELO test
250 mail.inlanefreight.htb
MAIL FROM: test@example.com
250 2.1.0 Ok
RCPT TO: admin
250 2.1.5 Ok
RCPT TO: nonexistentuser
550 5.1.1 <nonexistentuser>: Recipient address rejected: User unknown