13. Enumeration - IMAP_POP

IMAP - Access to emails from a mail server is possible. Unlike POP3 - IMAP allows online mgmt of emails directly on server / supports folders. NFS-like management Net protocol for mgmt. Client-server based Synchronization support

POP3 - Does not have this same functionality

Protocols such as IMAP must be used for addtl functionality such as hierarchical mailboxes directly at the mailserver, access to multiple mailboxes, and pre-selection of emails.

**Without further measures, IMAP works unencrypted and transmits commands, emails, or usernames and passwords in plain text. **SSL/TLS is usually used for this purpose.

IMAP Commands

https://donsutherland.org/crib/imap

Command Description
1 LOGIN username password User's login.
1 LIST "" * Lists all directories.
1 CREATE "INBOX" Creates a mailbox with a specified name.
1 DELETE "INBOX" Deletes a mailbox.
1 RENAME "ToRead" "Important" Renames a mailbox.
1 LSUB "" * Returns a subset of names from the set of names that the User has declared as being active or subscribed.
1 SELECT INBOX Selects a mailbox so that messages in the mailbox can be accessed.
1 UNSELECT INBOX Exits the selected mailbox.
1 FETCH <ID> all Retrieves data associated with a message in the mailbox.
1 CLOSE Removes all messages with the Deleted flag set.
1 LOGOUT Closes the connection with the IMAP server.

POP3 Commands

Command Description
USER username Identifies the user.
PASS password Authentication of the user using its password.
STAT Requests the number of saved emails from the server.
LIST Requests from the server the number and size of all emails.
RETR id Requests the server to deliver the requested email by ID.
DELE id Requests the server to delete the requested email by ID.
CAPA Requests the server to display the server capabilities.
RSET Requests the server to reset the transmitted information.
QUIT Closes the connection with the POP3 server.

Dangerous Settings

Nevertheless, configuration options that were improperly configured could allow us to obtain more information, such as debugging the executed commands on the service or logging in as anonymous, similar to the FTP service. Most companies use third-party email providers such as Google, Microsoft, and many others. However, some companies still use their own mail servers for many different reasons. One of these reasons is to maintain the privacy that they want to keep in their own hands. Many configuration mistakes can be made by administrators, which in the worst cases will allow us to read all the emails sent and received, which may even contain confidential or sensitive information. Some of these configuration options include:

Setting Description
auth_debug Enables all authentication debug logging.
auth_debug_passwords This setting adjusts log verbosity, the submitted passwords, and the scheme gets logged.
auth_verbose Logs unsuccessful authentication attempts and their reasons.
auth_verbose_passwords Passwords used for authentication are logged and can also be truncated.
auth_anonymous_username This specifies the username to be used when logging in with the ANONYMOUS SASL mechanism.

Footprinting the Service

By default, ports 110, 143, 993, and 995 are used for IMAP and POP3. The two higher ports use TLS/SSL to encrypt the communication between client and server. Using Nmap, we can scan the server for these ports. The scan will return the corresponding information like what we see below if the server uses an embedded SSL certificate.

stejwes@htb[/htb]$ sudo nmap 10.129.14.128 -sV -p110,143,993,995 -sC
stejwes@htb[/htb]$ curl -k 'imaps://10.129.14.128' --user user:p4ssw0rd

* LIST (\HasNoChildren) "." Important
* LIST (\HasNoChildren) "." INBOX

SSL:

OpenSSL - TLS Encrypted Interaction POP3

  IMAP / POP3

stejwes@htb[/htb]$ openssl s_client -connect 10.129.14.128:pop3s

OpenSSL - TLS Encrypted Interaction IMAP

  IMAP / POP3

stejwes@htb[/htb]$ openssl s_client -connect 10.129.14.128:imaps

https://gist.github.com/akpoff/53ac391037ae2f2d376214eac4a23634

curl -n imaps://mail.server.tld -X 'imap command'