Pentesting Email
SMTP (TCP 25, 587, 465)
SMTP Commands
AUTH PLAIN
Client authentication
HELO
Start session
MAIL FROM
Sender address
RCPT TO
Recipient address
DATA
Begin email body
RSET
Abort transmission
VRFY
Verify mailbox exists
EXPN
Expand mailing list
NOOP
Keep-alive
QUIT
End session
Postfix Config
cat /etc/postfix/main.cf | grep -v "#" | sed -r "/^\s*$/d"Open Relay (Dangerous)
If
mynetworksis set to0.0.0.0/0, anyone can use the server as a relay
Telnet SMTP Interaction
Send Email via Telnet
Nmap SMTP
SMTP User Enum
-M— Sets the mode: EXPN, VRFY, RCPT (default VRFY)-u— Check if a single user exists-U— File of usernames to check-t— Target host running SMTP
Wordlists that worked well for SMTP VRFY enumeration:
IMAP (TCP 143, 993)
IMAP Commands
1 LOGIN username password
Login
1 LIST "" *
List all directories
1 CREATE "INBOX"
Create mailbox
1 DELETE "INBOX"
Delete mailbox
1 RENAME "ToRead" "Important"
Rename mailbox
1 LSUB "" *
List subscribed
1 SELECT INBOX
Select mailbox
1 UNSELECT INBOX
Exit mailbox
1 FETCH <ID> all
Retrieve message data
1 CLOSE
Remove deleted
1 LOGOUT
Close connection
cURL IMAP
OpenSSL Interaction
POP3 (TCP 110, 995)
POP3 Commands
USER username
Identify user
PASS password
Authenticate
STAT
Number of emails
LIST
List all emails with size
RETR id
Retrieve email by ID
DELE id
Delete email by ID
CAPA
Server capabilities
RSET
Reset
QUIT
Close connection
POP3 via Telnet
Dovecot Dangerous Settings
auth_debug
All auth debug logging
auth_debug_passwords
Log submitted passwords
auth_verbose
Log failed auth
auth_verbose_passwords
Log auth passwords
auth_anonymous_username
Username for ANONYMOUS SASL
Nmap All Email Protocols
Email Port Reference
TCP/25
SMTP Unencrypted
TCP/143
IMAP4 Unencrypted
TCP/110
POP3 Unencrypted
TCP/465
SMTP Encrypted
TCP/587
SMTP Encrypted/STARTTLS
TCP/993
IMAP4 Encrypted
TCP/995
POP3 Encrypted
MX Record Enumeration
Resolve the mail server:
Full Nmap email scan:
SMTP User Enumeration (Telnet)
VRFY
EXPN
RCPT TO
POP3 USER Enumeration
smtp-user-enum
Modes: -M VRFY, -M EXPN, -M RCPT
Keep names.txt handy for broader SMTP user discovery:
O365 Enumeration & Spraying
Validate O365 Domain
Enumerate Users
Password Spray
Hydra POP3 Password Spray
Open Relay Exploitation
Detect with Nmap:
Send phishing email via open relay with swaks:
Phishing Internal Password Reset Links
When SMTP accepts unauthenticated mail and IMAP/POP3 users are enumerable, use public site content and VRFY to build a user list:
Try usernames as passwords against IMAP:
After logging into the mailbox, look for internal themes to mimic. In one path, the sales inbox had an email from IT:
Because SMTP did not require authentication, spoof the trusted sender and send a matching link:
Listen with raw netcat if you want to capture the full request body:
Try the captured password over SSH:
OpenSMTPD RCE (CVE-2020-7247)
Affects OpenSMTPD up to version 6.6.2
Unauthenticated RCE via semicolon injection in the sender email address field
64-character command limit
Exploit: https://www.exploit-db.com/exploits/47984
Confirm execution with ICMP before trying for a shell:
A valid local recipient may be required for reverse-shell exploit tooling. If accepted by the server,
root@HOSTNAMEcan work:
See OpenSMTPD.
Evolution Email Client
GUI client supporting IMAP, SMTP, POP3 — useful for interacting with mailboxes after obtaining credentials.
Last updated