08TCP
POP3 & IMAP
💡POP3 and IMAP are both protocols used to retrieve email from a mail server, but they differ in how they handle emails. POP3 downloads emails from the server to the local device, typically removing them from the server once downloaded, making it suitable for single-device access. In contrast, IMAP synchronizes emails across multiple devices, leaving the emails on the server and allowing users to manage their mail consistently from any device. IMAP is better suited for users who need to access their email from multiple locations or devices. Additionally, IMAP supports folder organization and flags (e.g., read/unread), while POP3 lacks these features.
01. POP3 - Post Office Protocol Version 3
| Command | Description |
|---|---|
| USER [username] | First login command (identifies user). |
| PASS [password] | Second login command (authenticates user). |
| STAT | Returns total number of messages and their size. |
| LIST | Lists all messages with IDs and sizes. |
| RETR [messageID] | Retrieves the entire message by ID. |
| DELE [messageID] | Marks a message for deletion by ID. |
| CAPA | Displays server capabilities. |
| RSET | Undeletes messages marked for deletion. |
| QUIT | Logs out, saves changes, and closes connection. |
| NOOP | Does nothing; server responds positively. |
| TOP [message] [number] | Returns headers and specified lines of a message. |
## ------------------| Login via telnettelnet <IP> 110 ### Login via telnetUSER h4rithd ### Enter user name with USER command | Receive +OK, if successPASS harith123 ### Enter password with PASS command | Receive +OK Welcome h4rithd, if successSTAT ### Returns total number of messages and total size | Receive +OK 1 743LIST ### Lists all messages | +OK 1 743, if successRETR 1 ### Retrieves the whole message RETR <number>
## ------------------| Login via OpenSSL [Encrypted]openssl s_client -connect <IP>:pop3sopenssl s_client -connect <IP>:pop3s -quiet -crlf
## ------------------| Enumerate using Nmapsudo nmap -sV -Pn -p110,143,993,995 -sC <IP>sudo nmap -sV -Pn --script pop3-ntlm-info.nse -p 110 <IP>sudo nmap -sV -Pn --script pop3-brute.nse -p 110 <IP>
## ------------------| Brute forcehydra -l <USERS> -P <PASSWORDS> -f <IP> pop3 -Vhydra -S -v -s 995 -l <USERS> -P <PASSWORDS_LISTS> -f <IP> pop3 -Vuse auxiliary/scanner/pop3/pop3_login02 IMAP - Internet Message Access Protocol
## ------------------| Scan using Nmapsudo nmap -sV -Pn -p143,993,995 -sC <IP>sudo nmap -sV -Pn --script imap-capabilities.nse -p 143 <IP>sudo nmap -sV -Pn --script imap-brute.nse -p 143 <IP>curl -k 'imaps://<IP>' --user h4rithd:password123 -v
## ------------------| Connect to the servertelnet <IP> 143 ### use 'c1 STARTTLS' If you need to switch to SSLncat --crlf --verbose <IP> 143 ### use 'c1 STARTTLS' If you need to switch to SSLopenssl s_client -connect <IP>:143 -crlf -quiet -starttls imap
## ------------------| Connect to the server [Encrypted]ncat --ssl <IP> 993openssl s_client -connect <IP>:imapsopenssl s_client -connect <IP>:993 -quiet
## ------------------| Authenticating to IMAPANYTHING001 login <USER> <PASS>A1 LOGIN <USER> <PASS>
## ------------------| List Folders/MailboxesA1 LIST "" *A1 LIST INBOX *A1 LIST "Archive" *
## ------------------| Status of MailboxA1 STATUS INBOX (MESSAGES UNSEEN RECENT)
## ------------------| List Subscribed MailboxesA1 LSUB "" *
## ------------------| Select/Examine MailboxA1 SELECT INBOXA1 EXAMINE INBOX
## ------------------| Fetch EmailsA1 FETCH 1 BODY[]A1 FETCH 1 ALLA1 FETCH 1:5 (FLAGS BODY[HEADER.FIELDS (SUBJECT FROM)])
## ------------------| Search EmailsA1 SEARCH ALLA1 SEARCH SUBJECT "Report"A1 SEARCH SINCE 1-Feb-2025
## ------------------| Delete EmailsA1 STORE 1 +FLAGS (\Deleted)A1 EXPUNGE
## ------------------| Copy EmailsA1 COPY 1:3 "Archive"
## ------------------| Store FlagsA1 STORE 1 +FLAGS (\Seen)A1 STORE 1 -FLAGS (\Deleted)A1 STORE 1 +FLAGS (\Flagged)
## ------------------| Create/Rename/Delete MailboxesA1 CREATE "NewFolder"A1 RENAME "OldFolder" "RenamedFolder"A1 DELETE "UnwantedFolder"
## ------------------| List messagesA1 FETCH 1:* (FLAGS)A1 UID FETCH 1:* (FLAGS)
## ------------------| Retrieve Message ContentA1 FETCH 2 body[text]A1 FETCH 2 allA1 UID FETCH 102 (UID RFC822.SIZE BODY.PEEK[])
## ------------------| Close MailboxA1 CLOSE
## ------------------| LogoutA1 LOGOUT