> ## Documentation Index
> Fetch the complete documentation index at: https://www.0101isnothacking.nl/llms.txt
> Use this file to discover all available pages before exploring further.

# IMAP/POP3 enumeration

> Active enumeration techniques for IMAP (143/993) and POP3 (110/995) mail services.

IMAP (Internet Message Access Protocol) runs on ports 143 and 993. POP3 (Post Office Protocol) runs on ports 110 and 995.

## Check open ports

```bash theme={null}
nmap -p143,993,110,995 <ip>
```

## Nmap default NSE scripts

With this scan we are able to grab information about the domain, organization name, state, and version.

```bash theme={null}
sudo nmap -p143,993,110,995 -sCV <ip>
```

## List all inboxes

```bash theme={null}
curl -k 'imaps://$ip' --user test:test
```

## Connect to mail

```bash theme={null}
openssl s_client -connect <ip>:pop3s
openssl s_client -connect <ip>:imaps
```

> [!NOTE]
>
> In IMAPS you have to give it a numeric index before typing any command, for example: `1 login test test` `2 list "" *`

## Commands

### IMAP

Example command sequence:

```text theme={null}
1 login test test
2 list "" *
3 select inbox
4 fetch 1 BODY[]
```

| 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

| 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

The following settings are potentially dangerous because they may expose sensitive authentication information. When `auth_verbose` is enabled, an attacker who gains access to the logs may be able to view previous authentication attempts and, depending on the system's logging behavior, potentially obtain passwords or other credentials. Enabling `auth_debug` may also reveal details about previous logins, helping an attacker identify users and gather information about the system.

| 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. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.