2024-07-19 11:24:45 +00:00
# 143,993 - Pentesting IMAP
2022-04-28 16:01:33 +00:00
2024-07-19 11:24:45 +00:00
{% hint style="success" %}
2024-09-04 13:29:40 +00:00
Learn & practice AWS Hacking:< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > [**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > \
Learn & practice GCP Hacking: < img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > [**HackTricks Training GCP Red Team Expert (GRTE)**< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > ](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-19 11:24:45 +00:00
< details >
2022-04-28 16:01:33 +00:00
2024-09-04 13:29:40 +00:00
< summary > Support HackTricks< / summary >
2022-04-28 16:01:33 +00:00
2024-09-04 13:29:40 +00:00
* Check the [**subscription plans** ](https://github.com/sponsors/carlospolop )!
* **Join the** 💬 [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
* **Share 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 >
2024-07-19 11:24:45 +00:00
{% endhint %}
2022-04-28 16:01:33 +00:00
2024-07-19 11:24:45 +00:00
## 互联网邮件访问协议
2023-09-03 01:34:43 +00:00
2024-09-04 13:29:40 +00:00
**互联网邮件访问协议 (IMAP)** 的设计目的是使用户能够**从任何位置访问他们的电子邮件消息**,主要通过互联网连接。实际上,电子邮件**保留在服务器上**,而不是下载并存储在个人设备上。这意味着当访问或阅读电子邮件时,是**直接从服务器**进行的。这种能力允许从**多个设备**方便地检查电子邮件,确保无论使用何种设备都不会错过任何消息。
2020-07-15 15:43:14 +00:00
2024-07-19 11:24:45 +00:00
默认情况下, IMAP 协议在两个端口上工作:
2020-07-15 15:43:14 +00:00
2024-05-05 22:03:00 +00:00
* **端口 143** - 这是默认的 IMAP 非加密端口
2024-07-19 11:24:45 +00:00
* **端口 993** - 如果您想安全地使用 IMAP 连接,则需要使用此端口
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
PORT STATE SERVICE REASON
143/tcp open imap syn-ack
```
2023-08-03 19:12:22 +00:00
## 横幅抓取
2020-07-15 15:43:14 +00:00
```bash
nc -nv < IP > 143
openssl s_client -connect < IP > :993 -quiet
```
2024-07-19 11:24:45 +00:00
### NTLM Auth - 信息泄露
2020-07-15 15:43:14 +00:00
2024-07-19 11:24:45 +00:00
如果服务器支持 NTLM 认证( Windows) , 您可以获取敏感信息( 版本) :
2021-10-18 11:21:18 +00:00
```
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=
2020-07-15 15:43:14 +00:00
+ TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
```
2024-09-04 13:29:40 +00:00
或**自动化**此操作,使用**nmap**插件`imap-ntlm-info.nse`
2020-07-15 15:43:14 +00:00
2024-09-04 13:29:40 +00:00
### [IMAP暴力破解](../generic-methodologies-and-resources/brute-force.md#imap)
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
## 语法
2024-02-06 04:10:34 +00:00
2024-09-04 13:29:40 +00:00
IMAP命令示例来自[这里](https://donsutherland.org/crib/imap):
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
Login
2023-08-03 19:12:22 +00:00
A1 LOGIN username password
2020-07-15 15:43:14 +00:00
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"
2020-07-15 15:43:14 +00:00
List Folders/Mailboxes
2023-08-03 19:12:22 +00:00
A1 LIST "" *
A1 LIST INBOX *
A1 LIST "Archive" *
2020-07-15 15:43:14 +00:00
Create new Folder/Mailbox
2023-08-03 19:12:22 +00:00
A1 CREATE INBOX.Archive.2012
A1 CREATE "To Read"
2020-07-15 15:43:14 +00:00
Delete Folder/Mailbox
2023-08-03 19:12:22 +00:00
A1 DELETE INBOX.Archive.2012
A1 DELETE "To Read"
2020-07-15 15:43:14 +00:00
Rename Folder/Mailbox
2023-08-03 19:12:22 +00:00
A1 RENAME "INBOX.One" "INBOX.Two"
2020-07-15 15:43:14 +00:00
List Subscribed Mailboxes
2023-08-03 19:12:22 +00:00
A1 LSUB "" *
2020-07-15 15:43:14 +00:00
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)
2020-07-15 15:43:14 +00:00
Select a mailbox
2023-08-03 19:12:22 +00:00
A1 SELECT INBOX
2020-07-15 15:43:14 +00:00
List messages
2023-08-03 19:12:22 +00:00
A1 FETCH 1:* (FLAGS)
A1 UID FETCH 1:* (FLAGS)
2020-07-15 15:43:14 +00:00
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[])
2020-07-15 15:43:14 +00:00
Close Mailbox
2023-08-03 19:12:22 +00:00
A1 CLOSE
2020-07-15 15:43:14 +00:00
Logout
2023-08-03 19:12:22 +00:00
A1 LOGOUT
2020-07-15 15:43:14 +00:00
```
2024-05-05 22:03:00 +00:00
### 演变
2023-08-03 19:12:22 +00:00
```
apt install evolution
```
2024-05-05 22:03:00 +00:00
![](< .. / . gitbook / assets / image ( 1033 ) . png > )
2023-08-03 19:12:22 +00:00
### CURL
2024-07-19 11:24:45 +00:00
基本导航可以使用 [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
2024-07-19 11:24:45 +00:00
1. 列出邮箱 (imap 命令 `LIST "" "*"` )
2023-08-03 19:12:22 +00:00
```bash
2024-02-08 22:20:49 +00:00
curl -k 'imaps://1.2.3.4/' --user user:pass
2023-08-03 19:12:22 +00:00
```
2024-07-19 11:24:45 +00:00
2. 列出邮箱中的消息( imap 命令 `SELECT INBOX` 然后 `SEARCH ALL` )
2023-08-03 19:12:22 +00:00
```bash
2024-03-09 13:16:16 +00:00
curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass
2023-08-03 19:12:22 +00:00
```
2024-07-19 11:24:45 +00:00
搜索的结果是消息索引的列表。
2023-08-03 19:12:22 +00:00
2024-07-19 11:24:45 +00:00
还可以提供更复杂的搜索条件。例如,搜索邮件正文中包含密码的草稿:
2023-08-03 19:12:22 +00:00
```bash
2024-02-09 12:48:25 +00:00
curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass
```
2024-07-19 11:24:45 +00:00
一个很好的搜索术语概述可以在 [这里 ](https://www.atmail.com/blog/imap-commands/ ) 找到。
2024-03-24 12:24:51 +00:00
2024-07-19 11:24:45 +00:00
3. 下载一条消息( imap 命令 `SELECT Drafts` 然后 `FETCH 1 BODY[]` )
2023-08-03 19:12:22 +00:00
```bash
2024-02-08 22:20:49 +00:00
curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass
```
2024-05-05 22:03:00 +00:00
邮件索引将与搜索操作返回的索引相同。
2024-02-08 22:20:49 +00:00
2024-07-19 11:24:45 +00:00
也可以使用 `UID` (唯一标识符)来访问消息,但这不太方便,因为搜索命令需要手动格式化。例如。
2023-08-03 19:12:22 +00:00
```bash
2024-02-08 22:20:49 +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
```
2024-07-19 11:24:45 +00:00
此外, 可以仅下载消息的部分内容, 例如前5条消息的主题和发件人( 需要使用`-v`才能查看主题和发件人):
2023-08-03 19:12:22 +00:00
```bash
$ curl -k 'imaps://1.2.3.4/INBOX' -X 'FETCH 1:5 BODY[HEADER.FIELDS (SUBJECT FROM)]' --user user:pass -v 2>& 1 | grep '^< '
```
2024-07-19 11:24:45 +00:00
虽然,写一个简单的 for 循环可能更简洁:
2024-02-08 22:20:49 +00:00
```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
2023-09-03 01:34:43 +00:00
* `port:143 CAPABILITY`
* `port:993 CAPABILITY`
2021-08-12 13:02:06 +00:00
2024-03-24 13:16:57 +00:00
## HackTricks 自动命令
2021-10-18 11:21:18 +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:
2023-08-03 19:12:22 +00:00
Name: Notes
Description: Notes for WHOIS
Note: |
2024-03-09 13:16:16 +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
2024-03-09 13:16:16 +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
2022-07-01 13:20:37 +00:00
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
```
2024-07-19 11:24:45 +00:00
{% hint style="success" %}
学习与实践 AWS 黑客技术:< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > [**HackTricks 培训 AWS 红队专家 (ARTE)**](https://training.hacktricks.xyz/courses/arte)< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > \
学习与实践 GCP 黑客技术:< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > [**HackTricks 培训 GCP 红队专家 (GRTE)**< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > ](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-19 11:24:45 +00:00
< details >
2022-04-28 16:01:33 +00:00
2024-07-19 11:24:45 +00:00
< summary > 支持 HackTricks< / summary >
2022-04-28 16:01:33 +00:00
2024-07-19 11:24:45 +00:00
* 查看 [**订阅计划** ](https://github.com/sponsors/carlospolop )!
* **加入** 💬 [**Discord 群组** ](https://discord.gg/hRep4RUj7f ) 或 [**Telegram 群组** ](https://t.me/peass ) 或 **关注** 我们的 **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
2024-08-18 11:02:47 +00:00
* **通过向** [**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 >
2024-07-19 11:24:45 +00:00
{% endhint %}