Pentesting Email

SMTP (TCP 25, 587, 465)

SMTP Commands

Command
Description

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 mynetworks is set to 0.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


IMAP (TCP 143, 993)

IMAP Commands

Command
Description

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

Command
Description

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

Setting
Description

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

Port
Service

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


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:


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@HOSTNAME can work:

See OpenSMTPD.


Evolution Email Client

GUI client supporting IMAP, SMTP, POP3 — useful for interacting with mailboxes after obtaining credentials.

Last updated