hacktricks/network-services-pentesting/pentesting-imap.md

235 lines
9.2 KiB
Markdown
Raw Normal View History

2022-05-01 13:25:53 +00:00
# 143,993 - Pentesting IMAP
2022-04-28 16:01:33 +00:00
<details>
2024-01-05 22:37:11 +00:00
<summary><strong>Learn AWS hacking from zero to hero with</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-01-05 22:37:11 +00:00
Other ways to support HackTricks:
2022-04-28 16:01:33 +00:00
2024-01-05 22:37:11 +00:00
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
2024-02-09 12:24:06 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
2024-01-05 22:37:11 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2023-09-02 23:51:32 +00:00
<figure><img src="/.gitbook/assets/image (675).png" alt=""><figcaption></figcaption></figure>
2023-09-02 23:48:41 +00:00
Find vulnerabilities that matter most so you can fix them faster. Intruder tracks your attack surface, runs proactive threat scans, finds issues across your whole tech stack, from APIs to web apps and cloud systems. [**Try it for free**](https://www.intruder.io/?utm\_source=referral\&utm\_campaign=hacktricks) today.
{% embed url="https://www.intruder.io/?utm_campaign=hacktricks&utm_source=referral" %}
***
2022-05-01 13:25:53 +00:00
## Internet Message Access Protocol
2024-02-08 21:36:15 +00:00
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-ack
```
2022-05-01 13:25:53 +00:00
## Banner grabbing
```bash
nc -nv <IP> 143
openssl s_client -connect <IP>:993 -quiet
```
2022-05-01 13:25:53 +00:00
### NTLM Auth - Information disclosure
If the server supports NTLM auth (Windows) you can obtain sensitive info (versions):
```
root@kali: telnet example.com 143
* OK The Microsoft Exchange IMAP4 service is ready.
>> a1 AUTHENTICATE NTLM
+
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
+ TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
```
Or **automate** this with **nmap** plugin `imap-ntlm-info.nse`
2022-05-01 13:25:53 +00:00
### [IMAP Bruteforce](../generic-methodologies-and-resources/brute-force.md#imap)
2022-05-01 13:25:53 +00:00
## Syntax
2024-02-06 03:10:38 +00:00
IAMP Commands examples from [here](https://donsutherland.org/crib/imap):
```
Login
A1 LOGIN username password
Values can be quoted to enclose spaces and special characters. A " must then be escape with a \
A1 LOGIN "username" "password"
List Folders/Mailboxes
A1 LIST "" *
A1 LIST INBOX *
A1 LIST "Archive" *
Create new Folder/Mailbox
A1 CREATE INBOX.Archive.2012
A1 CREATE "To Read"
Delete Folder/Mailbox
A1 DELETE INBOX.Archive.2012
A1 DELETE "To Read"
Rename Folder/Mailbox
A1 RENAME "INBOX.One" "INBOX.Two"
List Subscribed Mailboxes
A1 LSUB "" *
Status of Mailbox (There are more flags than the ones listed)
A1 STATUS INBOX (MESSAGES UNSEEN RECENT)
Select a mailbox
A1 SELECT INBOX
List messages
A1 FETCH 1:* (FLAGS)
A1 UID FETCH 1:* (FLAGS)
Retrieve Message Content
A1 FETCH 2 body[text]
A1 FETCH 2 all
A1 UID FETCH 102 (UID RFC822.SIZE BODY.PEEK[])
Close Mailbox
A1 CLOSE
Logout
A1 LOGOUT
```
2022-05-01 13:25:53 +00:00
### Evolution
```
apt install evolution
```
![](<../.gitbook/assets/image (528).png>)
2022-05-01 13:25:53 +00:00
### CURL
2020-12-21 13:41:29 +00:00
Basic navigation is possible with [CURL](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap), but the documentation is light on details so checking the [source](https://github.com/curl/curl/blob/master/lib/imap.c) is recommended for precise details.
1. Listing mailboxes (imap command `LIST "" "*"`)
2024-02-08 21:36:15 +00:00
```bash
curl -k 'imaps://1.2.3.4/' --user user:pass
```
2. Listing messages in a mailbox (imap command `SELECT INBOX` and then `SEARCH ALL`)
2024-02-08 21:36:15 +00:00
```bash
curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass
```
2024-02-08 21:36:15 +00:00
The result of this search is a list of message indicies.
2024-02-08 21:36:15 +00:00
Its also possible to provide more complex search terms. e.g. searching for drafts with password in mail body:
```bash
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
```
2024-02-08 21:36:15 +00:00
A nice overview of the search terms possible is located [here](https://www.atmail.com/blog/imap-commands/).
3. Downloading a message (imap command `SELECT Drafts` and then `FETCH 1 BODY[]`)
2024-02-08 21:36:15 +00:00
```bash
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
```
2024-02-08 21:36:15 +00:00
The mail index will be the same index returned from the search operation.
2020-12-21 13:41:29 +00:00
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.
```bash
2024-02-08 21:36:15 +00:00
curl -k 'imaps://1.2.3.4/INBOX' -X 'UID SEARCH ALL' --user user:pass
curl -k 'imaps://1.2.3.4/INBOX;UID=1' --user user:pass
2020-12-21 13:41:29 +00:00
```
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):
```bash
2020-12-21 13:41:29 +00:00
$ curl -k 'imaps://1.2.3.4/INBOX' -X 'FETCH 1:5 BODY[HEADER.FIELDS (SUBJECT FROM)]' --user user:pass -v 2>&1 | grep '^<'
```
Although, its probably cleaner to just write a little for loop:
2024-02-08 21:36:15 +00:00
```bash
2020-12-21 13:41:29 +00:00
for m in {1..5}; do
echo $m
curl "imap://1.2.3.4/INBOX;MAILINDEX=$m;SECTION=HEADER.FIELDS%20(SUBJECT%20FROM)" --user user:pass
done
```
2022-05-01 13:25:53 +00:00
## Shodan
2020-10-05 13:04:03 +00:00
* `port:143 CAPABILITY`
* `port:993 CAPABILITY`
2022-05-01 13:25:53 +00:00
## HackTricks Automatic Commands
2021-08-12 13:02:06 +00:00
```
2021-08-12 13:02:06 +00:00
Protocol_Name: IMAP #Protocol Abbreviation if there is one.
Port_Number: 143,993 #Comma separated if there is more than one.
Protocol_Description: Internet Message Access Protocol #Protocol Abbreviation Spelled out
2021-08-15 17:49:05 +00:00
Entry_1:
Name: Notes
Description: Notes for WHOIS
Note: |
2024-02-08 21:36:15 +00:00
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.
2021-08-15 17:49:05 +00:00
https://book.hacktricks.xyz/pentesting/pentesting-imap
Entry_2:
Name: Banner Grab
Description: Banner Grab 143
Command: nc -nv {IP} 143
Entry_3:
Name: Secure Banner Grab
Description: Banner Grab 993
Command: openssl s_client -connect {IP}:993 -quiet
Entry_4:
Name: consolesless mfs enumeration
Description: IMAP enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/imap/imap_version; set RHOSTS {IP}; set RPORT 143; run; exit'
2021-08-12 13:02:06 +00:00
```
2022-04-28 16:01:33 +00:00
2023-09-02 23:51:32 +00:00
<figure><img src="/.gitbook/assets/image (675).png" alt=""><figcaption></figcaption></figure>
2023-09-02 23:48:41 +00:00
Find vulnerabilities that matter most so you can fix them faster. Intruder tracks your attack surface, runs proactive threat scans, finds issues across your whole tech stack, from APIs to web apps and cloud systems. [**Try it for free**](https://www.intruder.io/?utm\_source=referral\&utm\_campaign=hacktricks) today.
{% embed url="https://www.intruder.io/?utm_campaign=hacktricks&utm_source=referral" %}
2022-04-28 16:01:33 +00:00
<details>
2024-01-05 22:37:11 +00:00
<summary><strong>Learn AWS hacking from zero to hero with</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-01-05 22:37:11 +00:00
Other ways to support HackTricks:
2022-04-28 16:01:33 +00:00
2024-01-05 22:37:11 +00:00
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
2024-02-09 12:24:06 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
2024-01-05 22:37:11 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>