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

8.8 KiB
Raw Blame History

143,993 - IMAP渗透测试

通过 htARTE (HackTricks AWS红队专家)从零开始学习AWS黑客攻击

支持HackTricks的其他方式

找到对您最重要的漏洞以便更快修复它们。Intruder追踪您的攻击面运行主动威胁扫描在您的整个技术栈中找到问题从API到Web应用程序和云系统。今天就免费试用

{% embed url="https://www.intruder.io/?utm_campaign=hacktricks&utm_source=referral" %}


互联网邮件访问协议

顾名思义IMAP允许您在任何地方访问您的电子邮件消息;大多数时候,它是通过互联网访问的。基本上,电子邮件消息存储在服务器上。每当您检查收件箱时您的电子邮件客户端都会联系服务器将您与您的消息连接起来。使用IMAP阅读电子邮件消息时您实际上并没有下载或存储它在您的计算机上;相反,您是在从服务器上阅读它。因此,您可以从几个不同的设备检查电子邮件,而不会错过任何东西。

默认情况下IMAP协议在两个端口上工作

  • 端口143 - 这是默认的IMAP非加密端口
  • 端口993 - 如果您想要使用IMAP安全地连接您需要使用的端口
PORT    STATE SERVICE REASON
143/tcp open  imap    syn-ack

横幅抓取

nc -nv <IP> 143
openssl s_client -connect <IP>:993 -quiet

NTLM 认证 - 信息泄露

如果服务器支持 NTLM 认证Windows您可以获取敏感信息版本

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 暴力破解

语法

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

这里

Evolution

apt install evolution

CURL

可以使用 CURL 进行基本导航,但文档对细节描述不多,因此建议查看源代码以获取精确细节。

  1. 列出邮箱IMAP 命令 LIST "" "*"
$ curl -k 'imaps://1.2.3.4/' --user user:pass
  1. 列出邮箱中的消息IMAP 命令 SELECT INBOX 然后 SEARCH ALL
$ curl -k 'imaps://1.2.3.4/INBOX?ALL' --user user:pass

此搜索结果是消息索引列表。

也可以提供更复杂的搜索条件。例如,搜索邮件正文中含有密码的草稿:

$ curl -k 'imaps://1.2.3.4/Drafts?TEXT password' --user user:pass

一个关于可能的搜索条件的好概述位于这里。 3. 下载消息IMAP 命令 SELECT Drafts 然后 FETCH 1 BODY[]

$ curl -k 'imaps://1.2.3.4/Drafts;MAILINDEX=1' --user user:pass

邮件索引将与搜索操作返回的索引相同。

也可以使用 UID(唯一标识符)来访问消息,但这不太方便,因为需要手动格式化搜索命令。例如:

$ 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
同样可以只下载消息的一部分例如前5条消息的主题和发送者需要`-v`才能看到主题和发送者):
$ curl -k 'imaps://1.2.3.4/INBOX' -X 'FETCH 1:5 BODY[HEADER.FIELDS (SUBJECT FROM)]' --user user:pass -v 2>&1 | grep '^<'

尽管如此编写一个小型的for循环可能会更简洁

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

Shodan

  • port:143 CAPABILITY
  • port:993 CAPABILITY

HackTricks 自动命令

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

Entry_1:
Name: Notes
Description: Notes for WHOIS
Note: |
As its name implies, IMAP allows you to access your email messages wherever you are; much of the time, it is accessed via the Internet. Basically, email messages are stored on servers. Whenever you check your inbox, your email client contacts the server to connect you with your messages. When you read an email message using IMAP, you aren't actually downloading or storing it on your computer; instead, you are reading it off of the server. As a result, it's possible to check your email from several different devices without missing a thing.

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'
<figure><img src="/.gitbook/assets/image (675).png" alt=""><figcaption></figcaption></figure>

找到对您最重要的漏洞以便您能更快修复它们。Intruder 跟踪您的攻击面运行主动威胁扫描在您的整个技术栈中找到问题从API到网络应用程序和云系统。[**免费试用**](https://www.intruder.io/?utm\_source=referral\&utm\_campaign=hacktricks) 今天。

{% embed url="https://www.intruder.io/?utm_campaign=hacktricks&utm_source=referral" %}


<details>

<summary><strong>从零开始学习AWS黑客技术成为英雄通过</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>

支持HackTricks的其他方式

* 如果您想在HackTricks中看到您的**公司广告**或**下载HackTricks的PDF**,请查看[**订阅计划**](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) 或 [**telegram群组**](https://t.me/peass) 或在 **Twitter** 🐦 上**关注**我 [**@carlospolopm**](https://twitter.com/carlospolopm)**。**
* **通过向** [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>