~/mail-retrieval

Mail Retrieval

CPTS Notes4 min read

TL;DR

IMAP and POP3 are the retrieval side of mail: they read what SMTP delivered.

  • IMAP (Internet Message Access Protocol): mail stays on the server, with folders and multi-client sync. TCP 143 (plaintext or STARTTLS), 993 (implicit TLS).
  • POP3 (Post Office Protocol v3): download-and-delete, no folders and no server-side management. TCP 110 (plaintext or STARTTLS), 995 (implicit TLS).

Both are cleartext without TLS, so credentials and mail are sniffable.

First checks: the banner and certificate (hostname, org, admin email), plaintext auth, and whether found credentials log in.

How mail moves is in The Mail Pipeline.

Commands

IMAP tags each command with an identifier such as a. POP3 does not.

IMAP Does
a LOGIN user pass Authenticate.
a LIST "" * List every folder.
a LSUB "" * List subscribed folders.
a SELECT INBOX Open a mailbox.
a FETCH <id> all Read a message.
a LOGOUT Close the session.
POP3 Does
USER <name> Name the user.
PASS <pass> Authenticate.
STAT Count the messages.
LIST List messages and sizes.
RETR <id> Read a message.
DELE <id> Delete a message.
QUIT Close the session.

Enumeration

Sweep.

sudo nmap -p110,143,993,995 -sV -sC -oA scans/mail-retrieval $TARGET # version, capabilities, and certificate

-sC runs imap-capabilities or pop3-capabilities and ssl-cert. The certificate leaks the hostname, organization, and an admin email.

Interact. curl speaks both protocols and sends the right line endings, so it is the quickest read with found credentials:

curl "pop3://$TARGET/" -u '<user>:<pass>' # POP3: list message numbers
curl "pop3://$TARGET/1" -u '<user>:<pass>' # POP3: read message 1
curl "imap://$TARGET/" -u '<user>:<pass>' # IMAP: list folders
curl "imap://$TARGET/INBOX;MAILINDEX=1" -u '<user>:<pass>' # IMAP: read message 1

On the TLS ports (993, 995) swap in imaps:// and pop3s:// and add -k.

For a hands-on session, send CRLF. Plain nc sends only LF, so a minimal server never answers:

ncat -C $TARGET 110 # plaintext, 110 or 143 (-C sends CRLF)
openssl s_client -crlf -connect $TARGET:pop3s # TLS, pop3s or imaps

Log in with the full email address here too.

Enumerate POP3 users. Where the server checks the name at USER, its answer leaks whether the name exists:

ncat -C $TARGET 110 # -C sends CRLF so the server answers (plain nc sends LF)
USER <name> # +OK means the user exists, -ERR means it does not

Many servers accept any USER and check only at PASS, so test one known name first.

Common misconfigurations

  • Plaintext auth without STARTTLS, so credentials are sniffable.
  • Anonymous login.
  • Verbose auth logging that records passwords.
  • Reused credentials from another service.

Attack playbook

Retrieval is for reading mail. The win is credentials in, mail out.

  1. Log in with found credentials. Credentials from SMTP enumeration, a config, or reuse often work here. Mail holds credentials, password resets, and internal detail.
  2. Spray credentials. With a user list, spray one password across the users:
    hydra -L users.txt -p 'Company01!' -f $TARGET pop3 # swap pop3 for imap to hit the other port
    -L is the user list. -p is the single password. -f stops at the first valid pair. The login is the full email address, so users.txt holds marlin@$DOMAIN, not marlin.
  3. Read every folder. The useful mail is often outside the inbox. IMAP folder names are case-sensitive:
    a LIST "" * # list every folder
    a SELECT <folder> # open a folder
    a FETCH <id> all # read a message
    POP3 has one flat mailbox:
    STAT # count the messages
    LIST # list messages and sizes
    RETR <id> # read a message
  4. Sniff plaintext. On port 110 or 143 without TLS, credentials and mail cross the wire in clear.

Practice boxes

Box Difficulty Retrieval’s role
Mailing Easy A cracked hMailServer admin password logs into the mailbox over IMAP to read mail.
SolidState Easy Apache James admin resets a mailbox password, then read it over POP3 for credentials.
SneakyMailer Medium Phished credentials open the IMAP mailbox, which holds the developer’s password.

IMAP and POP3 rarely fall on their own. The win is logging in with found or reused credentials and reading the mail.