143,993 - Pentesting IMAP
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Internet Message Access Protocol
The Internet Message Access Protocol (IMAP) is designed for the purpose of enabling users to access their email messages from any location, primarily through an Internet connection. In essence, emails are retained on a server rather than being downloaded and stored on an individual's personal device. This means that when an email is accessed or read, it is done directly from the server. This capability allows for the convenience of checking emails from multiple devices, ensuring that no messages are missed regardless of the device used.
By default, the IMAP protocol works on two ports:
Port 143 - this is the default IMAP non-encrypted port
Port 993 - this is the port you need to use if you want to connect using IMAP securely
PORT STATE SERVICE REASON
143/tcp open imap syn-ackBanner grabbing
nc -nv <IP> 143
openssl s_client -connect <IP>:993 -quietNTLM Auth - Information disclosure
If the server supports NTLM auth (Windows) you can obtain sensitive info (versions):
Or automate this with nmap plugin imap-ntlm-info.nse
Syntax
IMAP Commands examples from here:
Evolution

CURL
Basic navigation is possible with CURL, but the documentation is light on details so checking the source is recommended for precise details.
Listing mailboxes (imap command
LIST "" "*")
Listing messages in a mailbox (imap command
SELECT INBOXand thenSEARCH ALL)
The result of this search is a list of message indicies.
Its also possible to provide more complex search terms. e.g. searching for drafts with password in mail body:
A nice overview of the search terms possible is located here.
Downloading a message (imap command
SELECT Draftsand thenFETCH 1 BODY[])
The mail index will be the same index returned from the search operation.
It is also possible to use UID (unique id) to access messages, however it is less conveniant as the search command needs to be manually formatted. E.g.
Also, possible to download just parts of a message, e.g. subject and sender of first 5 messages (the -v is required to see the subject and sender):
Although, its probably cleaner to just write a little for loop:
Shodan
port:143 CAPABILITYport:993 CAPABILITY
HackTricks Automatic Commands
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Last updated