8.2 KiB
143,993 - Pentesting IMAP
{% hint style="success" %}
学习与实践 AWS 黑客技术:HackTricks 培训 AWS 红队专家 (ARTE)
学习与实践 GCP 黑客技术:HackTricks 培训 GCP 红队专家 (GRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 分享黑客技巧。
Try Hard Security Group
{% embed url="https://discord.gg/tryhardsecurity" %}
互联网邮件访问协议
互联网邮件访问协议 (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 Auth - 信息泄露
如果服务器支持 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暴力破解
语法
IAMP命令示例来自这里:
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
演变
apt install evolution
CURL
基本导航可以使用 CURL 实现,但文档内容较少,因此建议查看 源代码 以获取准确的细节。
- 列出邮箱 (imap 命令
LIST "" "*"
)
curl -k 'imaps://1.2.3.4/' --user user:pass
- 列出邮箱中的消息(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
一个很好的搜索术语概述可以在 这里 找到。
- 下载一条消息(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
Try Hard Security Group
{% embed url="https://discord.gg/tryhardsecurity" %}
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: |
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.
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'
{% hint style="success" %}
学习与实践 AWS 黑客技术:HackTricks 培训 AWS 红队专家 (ARTE)
学习与实践 GCP 黑客技术:HackTricks 培训 GCP 红队专家 (GRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 分享黑客技巧。