SuperAPI AI Directory

imap-pentesting

Testing & quality

View repository

Updated 10-16 08:08

About this skill

IMAP email penetration testing methodology (143/993)

In-depth reference


Overall decision tree

发现 143/993 端口开放
├─ Phase 1: 服务发现
│   ├─ Banner 抓取 -> 识别邮件服务与版本
│   ├─ 143 (明文) vs 993 (SSL/TLS)
│   └─ Nmap 脚本 -> 能力枚举 / NTLM 信息
├─ Phase 2: Banner 信息分析
│   ├─ 邮件服务器类型 (Dovecot / Exchange / Cyrus / Zimbra)
│   ├─ NTLM 信息泄露 (Exchange) -> Windows 版本、域名
│   └─ CAPABILITY 命令 -> 支持的功能
├─ Phase 3: 凭据爆破
│   ├─ hydra / medusa / ncrack
│   ├─ Metasploit imap_version
│   └─ 默认凭据 / 弱密码
├─ Phase 4: 邮箱枚举与邮件下载
│   ├─ LIST "" * -> 列出所有邮箱文件夹
│   ├─ SELECT INBOX -> 选中收件箱
│   ├─ SEARCH ALL -> 列出所有邮件
│   ├─ FETCH -> 下载邮件内容
│   └─ SEARCH TEXT "password" -> 关键词搜索
└─ Phase 5: 已知漏洞
    ├─ 服务器特定 CVE
    ├─ IMAP 命令注入
    └─ searchsploit <imap_server> <version>

Phase 1: Service discovery

1.1 Banner grabbing

# 明文 IMAP (143)
nc -nv <IP> 143

# SSL/TLS IMAP (993)
openssl s_client -connect <IP>:993 -quiet

1.2 Nmap enumeration

# IMAP NTLM 信息泄露
nmap --script imap-ntlm-info -p 143 <IP>

# IMAP 能力枚举
nmap --script imap-capabilities -p 143 <IP>

1.3 Metasploit

msfconsole -q -x 'use auxiliary/scanner/imap/imap_version; set RHOSTS <IP>; set RPORT 143; run; exit'

Phase 2: Banner information analysis

2.1 NTLM information extraction (Exchange)

If the server supports NTLM authentication, information such as the Windows version can be extracted:

# Telnet 交互
telnet <IP> 143
* OK The Microsoft Exchange IMAP4 service is ready.
>> a1 AUTHENTICATE NTLM
+
>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=
# 服务器返回 NTLMSSP_CHALLENGE (含 OS 版本、域信息)

2.2 Information analysis decision tree

Banner 分析
├─ Microsoft Exchange
│   ├─ NTLM 信息泄露 -> 版本、域名、主机名
│   └─ 可能存在 ProxyLogon / ProxyShell 等漏洞 (通过 HTTP)
├─ Dovecot
│   └─ 检查版本特定 CVE
├─ Cyrus IMAP
│   └─ 检查版本特定 CVE
├─ Zimbra
│   └─ 检查 Web 接口相关 CVE
└─ CAPABILITY 结果
    ├─ STARTTLS -> 可升级加密
    ├─ AUTH=PLAIN -> 明文认证
    └─ AUTH=NTLM -> Windows 域环境

Phase 3: Credential brute-forcing

3.1 Brute-forcing tools

# hydra — IMAP 明文
hydra -l <username> -P <password_list> -f <IP> imap -V

# hydra — IMAPS (SSL)
hydra -l <username> -P <password_list> -f <IP> -s 993 imaps -V

# medusa
medusa -h <IP> -u <username> -P <password_list> -M imap

# ncrack
ncrack -p 143 --user <username> -P <password_list> <IP>

Phase 4: Mailbox enumeration and email download

4.1 IMAP command operations

# 登录
a1 LOGIN username password

# 列出所有邮箱/文件夹
a1 LIST "" *
a1 LIST INBOX *

# 选中邮箱
a1 SELECT INBOX

# 查看邮箱状态
a1 STATUS INBOX (MESSAGES UNSEEN RECENT)

# 搜索所有邮件
a1 SEARCH ALL

# 关键词搜索
a1 SEARCH TEXT "password"
a1 SEARCH SUBJECT "vpn"
a1 SEARCH FROM "admin"

# 获取邮件标志
a1 FETCH 1:* (FLAGS)

# 下载邮件全文
a1 FETCH <msg_id> body[text]
a1 FETCH <msg_id> all
a1 UID FETCH <uid> (UID RFC822.SIZE BODY.PEEK[])

# 关闭邮箱
a1 CLOSE

# 退出
a1 LOGOUT

4.2 CURL operations (more convenient)

# 列出所有邮箱
curl -k 'imaps://<IP>/' --user user:pass

# 列出 INBOX 中的邮件
curl -k 'imaps://<IP>/INBOX?ALL' --user user:pass

# 关键词搜索
curl -k 'imaps://<IP>/Drafts?TEXT password' --user user:pass

# 下载指定邮件
curl -k 'imaps://<IP>/INBOX;MAILINDEX=1' --user user:pass

# UID 操作
curl -k 'imaps://<IP>/INBOX' -X 'UID SEARCH ALL' --user user:pass
curl -k 'imaps://<IP>/INBOX;UID=1' --user user:pass

# 批量获取邮件头
curl -k 'imaps://<IP>/INBOX' -X 'FETCH 1:5 BODY[HEADER.FIELDS (SUBJECT FROM)]' --user user:pass -v 2>&1 | grep '^<'

4.3 Email content analysis

邮件提取后关注内容
├─ 凭据信息
│   ├─ 密码重置邮件
│   ├─ 系统通知 (新账户创建)
│   └─ VPN / SSH / RDP 配置
├─ 内部网络信息
│   ├─ 内网 IP / URL
│   ├─ 系统架构文档
│   └─ 运维通知
├─ 附件
│   ├─ 配置文件
│   ├─ 文档 (Word/Excel/PDF)
│   └─ 压缩包
├─ 草稿箱
│   └─ 可能包含未发送的敏感信息
└─ 社会工程素材
    └─ 邮件模板 / 签名 -> 钓鱼攻击参考

4.4 Batch download script

# 循环下载前 N 封邮件
for m in {1..20}; do
  echo "--- Message $m ---"
  curl -k "imap://<IP>/INBOX;MAILINDEX=$m;SECTION=HEADER.FIELDS%20(SUBJECT%20FROM)" --user user:pass
done

Phase 5: Known vulnerabilities

5.1 Vulnerability detection decision tree

IMAP 服务版本已知
├─ Dovecot
│   ├─ CVE-2019-11500 (堆溢出)
│   └─ searchsploit dovecot
├─ Cyrus IMAP
│   ├─ CVE-2019-18928 (认证绕过)
│   └─ searchsploit cyrus imap
├─ Microsoft Exchange
│   ├─ ProxyLogon (CVE-2021-26855)
│   ├─ ProxyShell (CVE-2021-34473)
│   └─ 通过 HTTP/HTTPS 接口利用
├─ Zimbra
│   ├─ CVE-2022-27925 (RCE)
│   └─ CVE-2022-37042 (认证绕过 + RCE)
└─ 通用
    └─ searchsploit imap

Graphical client

If a more intuitive way to operate on email content is needed:

# Evolution 邮件客户端 (Linux)
apt install evolution
# 添加 IMAP 账户配置后可浏览完整邮箱

Shodan search

port:143 CAPABILITY
port:993 CAPABILITY