knowledge

Overview

IMAP (Internet Message Access Protocol) and POP3 (Post Office Protocol 3) are the two primary protocols for retrieving email from a mail server. IMAP supports server-side folder management and multi-client synchronization, making it the modern standard. POP3 is a simpler, older protocol that downloads and optionally deletes messages. Both are commonly found in corporate environments and can be fingerprinted for version information and used for credential testing.


Terminology

TermDefinition
IMAPInternet Message Access Protocol — server-side email management with folder sync; TCP/143 (unencrypted), TCP/993 (TLS)
POP3Post Office Protocol 3 — download-and-optionally-delete email retrieval; TCP/110 (unencrypted), TCP/995 (TLS)
IMAPSIMAP over SSL/TLS — encrypted IMAP on port 993
POP3SPOP3 over SSL/TLS — encrypted POP3 on port 995
DovecotCommon open-source IMAP and POP3 server for Linux
MailboxServer-side storage location for a user’s email
UIDUnique Identifier — persistent message ID used by IMAP
INBOXDefault IMAP folder for incoming mail
SASLSimple Authentication and Security Layer — framework used for IMAP/POP3 authentication

Core Concepts

IMAP vs POP3

FeatureIMAPPOP3
Email storageStays on serverDownloaded to client (optionally deleted)
Multi-client syncYes — changes sync across all clientsNo — each client has independent state
Folder managementFull server-side foldersNone
Offline accessSupported via local copyDefault behavior
Protocol styleStateful, persistent sessionsSimple request/response
Default port143 (plain), 993 (TLS)110 (plain), 995 (TLS)

SMTP is used to send emails outbound; IMAP/POP3 retrieve emails inbound. IMAP also copies sent emails to a server-side folder so all clients can access them.


IMAP Commands

IMAP commands are prefixed with a tag (e.g., 1) so the client can match responses to requests. Multiple commands can be sent without waiting for each response.

CommandDescription
1 LOGIN <username> <password>Authenticate to the mail server
1 LIST "" *List all mailbox folders
1 CREATE "INBOX"Create a mailbox with a specified name
1 DELETE "INBOX"Delete a mailbox
1 RENAME "ToRead" "Important"Rename a mailbox
1 LSUB "" *List subscribed/active mailbox folders
1 SELECT INBOXSelect a mailbox for message access
1 UNSELECT INBOXDeselect the current mailbox
1 FETCH <UID> allRetrieve all data for a message
1 FETCH <UID> rfc822.textRetrieve the email body text
1 FETCH <UID> rfc822.headerRetrieve only the email headers
1 FETCH <UID> BODY[]Retrieve full message (headers + body)
1 CLOSERemove all messages flagged for deletion
1 LOGOUTEnd the session

POP3 Commands

CommandParametersDescription
USER<username>Provide username
PASS<password>Provide password
STATReturns count and total size of messages in mailbox
LISTLists all messages with their IDs and sizes
RETR<id>Download message by ID
DELE<id>Mark message for deletion
CAPAList server capabilities
RSETReset — cancel pending deletions
QUITCommit deletions and end session

Default Configuration

Managed by Dovecot (dovecot-imapd, dovecot-pop3d).

Key config locations:

  • /etc/dovecot/dovecot.conf — main configuration
  • /etc/dovecot/conf.d/ — modular config directory

Dangerous Settings

SettingRisk
auth_debug = yesFull authentication debug logging — exposes credentials in logs
auth_debug_passwords = yesSubmitted passwords and schemes logged in plaintext
auth_verbose = yesFailed authentication attempts logged with reasons
auth_verbose_passwords = yesPasswords used for failed attempts logged (possibly truncated)
auth_anonymous_usernameEnables ANONYMOUS SASL mechanism — allows unauthenticated login
Plaintext auth without TLSCredentials sent in cleartext

Most companies use third-party email providers, but some run internal mail servers — which are often poorly maintained and misconfigured.


Footprinting IMAP/POP3

Scan ports 110, 143, 993, and 995 with Nmap (-sV -sC) — Nmap retrieves TLS/SSL certificate details including CN, organization, and server location.

Connect with curl using the IMAPS URL scheme (curl -k 'imaps://<target>' --user user:pass -v) to enumerate the server banner and TLS certificate details. See curl for full flag reference.

Test TLS-enabled connections directly with openssl s_client -connect <target>:imaps (IMAP) or openssl s_client -connect <target>:pop3s (POP3), then send IMAP/POP3 commands interactively in the session.


  • Service Enumeration

References / Images