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

245 lines
9 KiB
Markdown
Raw Normal View History

# 143,993 - Pentesting IMAP
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>从零开始学习AWS黑客技术成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTEHackTricks AWS Red Team Expert</strong></a><strong></strong></summary>
2022-04-28 16:01:33 +00:00
支持HackTricks的其他方式
2022-04-28 16:01:33 +00:00
* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
</details>
<figure><img src="/.gitbook/assets/image (675).png" alt=""><figcaption></figcaption></figure>
发现最重要的漏洞以便更快地修复它们。Intruder跟踪您的攻击面运行主动威胁扫描发现整个技术堆栈中的问题从API到Web应用程序和云系统。[**立即免费试用**](https://www.intruder.io/?utm\_source=referral\&utm\_campaign=hacktricks)。
{% embed url="https://www.intruder.io/?utm_campaign=hacktricks&utm_source=referral" %}
***
## 互联网消息访问协议
**互联网消息访问协议IMAP**旨在使用户能够通过互联网连接从任何位置**访问其电子邮件消息**。实质上,电子邮件**保留在服务器上**,而不是下载并存储在个人设备上。这意味着当电子邮件被访问或阅读时,是直接从服务器上进行的。这种能力允许方便地从**多个设备**检查电子邮件,确保无论使用哪种设备,都不会错过任何消息。
默认情况下IMAP协议在两个端口上运行
2023-08-03 19:12:22 +00:00
* **端口143** - 这是默认的IMAP非加密端口
* **端口993** - 这是您需要使用的端口如果要安全地使用IMAP进行连接
```
PORT STATE SERVICE REASON
143/tcp open imap syn-ack
```
2023-08-03 19:12:22 +00:00
## 横幅抓取
```bash
nc -nv <IP> 143
openssl s_client -connect <IP>:993 -quiet
```
### NTLM认证 - 信息泄露
如果服务器支持NTLM认证Windows您可以获取敏感信息版本
```
2023-08-03 19:12:22 +00:00
root@kali: telnet example.com 143
* OK The Microsoft Exchange IMAP4 service is ready.
>> a1 AUTHENTICATE NTLM
+
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
+ TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
```
或者使用 **nmap** 插件 `imap-ntlm-info.nse`**自动化** 这个过程。
### [IMAP暴力破解](../generic-methodologies-and-resources/brute-force.md#imap)
2023-08-03 19:12:22 +00:00
## 语法
IMAP命令示例来自[这里](https://donsutherland.org/crib/imap):
```
Login
2023-08-03 19:12:22 +00:00
A1 LOGIN username password
Values can be quoted to enclose spaces and special characters. A " must then be escape with a \
2023-08-03 19:12:22 +00:00
A1 LOGIN "username" "password"
List Folders/Mailboxes
2023-08-03 19:12:22 +00:00
A1 LIST "" *
A1 LIST INBOX *
A1 LIST "Archive" *
Create new Folder/Mailbox
2023-08-03 19:12:22 +00:00
A1 CREATE INBOX.Archive.2012
A1 CREATE "To Read"
Delete Folder/Mailbox
2023-08-03 19:12:22 +00:00
A1 DELETE INBOX.Archive.2012
A1 DELETE "To Read"
Rename Folder/Mailbox
2023-08-03 19:12:22 +00:00
A1 RENAME "INBOX.One" "INBOX.Two"
List Subscribed Mailboxes
2023-08-03 19:12:22 +00:00
A1 LSUB "" *
Status of Mailbox (There are more flags than the ones listed)
2023-08-03 19:12:22 +00:00
A1 STATUS INBOX (MESSAGES UNSEEN RECENT)
Select a mailbox
2023-08-03 19:12:22 +00:00
A1 SELECT INBOX
List messages
2023-08-03 19:12:22 +00:00
A1 FETCH 1:* (FLAGS)
A1 UID FETCH 1:* (FLAGS)
Retrieve Message Content
2023-08-03 19:12:22 +00:00
A1 FETCH 2 body[text]
A1 FETCH 2 all
A1 UID FETCH 102 (UID RFC822.SIZE BODY.PEEK[])
Close Mailbox
2023-08-03 19:12:22 +00:00
A1 CLOSE
Logout
2023-08-03 19:12:22 +00:00
A1 LOGOUT
```
### 演进
2023-08-03 19:12:22 +00:00
```
apt install evolution
```
![](<../.gitbook/assets/image (528).png>)
### CURL
使用[CURL](https://ec.haxx.se/usingcurl/usingcurl-reademail#imap)可以进行基本导航,但文档细节较少,建议查看[源代码](https://github.com/curl/curl/blob/master/lib/imap.c)以获取精确细节。
2023-08-03 19:12:22 +00:00
1. 列出邮箱imap 命令 `LIST "" "*"`
2023-08-03 19:12:22 +00:00
```bash
curl -k 'imaps://1.2.3.4/' --user user:pass
2023-08-03 19:12:22 +00:00
```
2. 在邮箱中列出消息imap命令`SELECT INBOX`然后`SEARCH ALL`
2023-08-03 19:12:22 +00:00
```bash
curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass```
2023-08-03 19:12:22 +00:00
```
The result of this search is a list of message indicies.
2023-08-03 19:12:22 +00:00
Its also possible to provide more complex search terms. e.g. searching for drafts with password in mail body:
2023-08-03 19:12:22 +00:00
```bash
```plaintext
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
```
---
```plaintext
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
```
2023-08-03 19:12:22 +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[]`)
2023-08-03 19:12:22 +00:00
```bash
```plaintext
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
```
```plaintext
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
2023-08-03 19:12:22 +00:00
```
```
The mail index will be the same index returned from the search operation.
2023-08-03 19:12:22 +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.
2023-08-03 19:12:22 +00:00
```bash
```plaintext
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
```
2023-08-03 19:12:22 +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):
2023-08-03 19:12:22 +00:00
```bash
```plaintext
2023-08-03 19:12:22 +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:
```bash
```bash
2020-12-21 13:41:29 +00:00
for m in {1..5}; do
2023-08-03 19:12:22 +00:00
echo $m
curl "imap://1.2.3.4/INBOX;MAILINDEX=$m;SECTION=HEADER.FIELDS%20(SUBJECT%20FROM)" --user user:pass
2020-12-21 13:41:29 +00:00
done
```
```
2022-05-01 13:25:53 +00:00
## Shodan
2020-10-05 13:04:03 +00:00
* `port:143 CAPABILITY`
* `port:993 CAPABILITY`
2021-08-12 13:02:06 +00:00
## HackTricks Automatic Commands
```
```markdown
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:
2023-08-03 19:12:22 +00:00
Name: Notes
Description: Notes for WHOIS
Note: |
互联网消息访问协议IMAP旨在使用户能够通过互联网连接从任何位置访问其电子邮件消息。实质上电子邮件保留在服务器上而不是下载并存储在个人设备上。这意味着当电子邮件被访问或阅读时是直接从服务器上进行的。这种功能允许从多个设备检查电子邮件确保无论使用哪种设备都不会错过任何消息。
2021-08-15 17:49:05 +00:00
https://book.hacktricks.xyz/pentesting/pentesting-imap
2021-08-15 17:49:05 +00:00
Entry_2:
2023-08-03 19:12:22 +00:00
Name: Banner Grab
Description: Banner Grab 143
Command: nc -nv {IP} 143
2021-08-15 17:49:05 +00:00
Entry_3:
2023-08-03 19:12:22 +00:00
Name: Secure Banner Grab
Description: Banner Grab 993
Command: openssl s_client -connect {IP}:993 -quiet
Entry_4:
2023-08-03 19:12:22 +00:00
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
```
```
<figure><img src="/.gitbook/assets/image (675).png" alt=""><figcaption></figcaption></figure>
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>
<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
Other ways to support HackTricks:
2022-04-28 16:01:33 +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)
* **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)**.**
* **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>