Most of the time, taking over an account means getting its password or its hash. Shadow Credentials is different. If you can write one attribute on a target object, you can authenticate as that object without ever knowing or changing its password. The legitimate owner keeps logging in, nothing looks reset, and you have a clean path to a Kerberos TGT and from there to the NT hash.
I like this technique because it is quiet, it is reversible, and it leans on a feature that is working exactly as designed. The feature is key-based authentication for Kerberos, and the attribute is msDS-KeyCredentialLink.
What msDS-KeyCredentialLink is
msDS-KeyCredentialLink is a multi-valued attribute on user and computer objects. It holds raw public keys that the object can use to authenticate via PKINIT, the public-key extension to Kerberos pre-authentication. This is the plumbing behind Windows Hello for Business: instead of a password, a device presents a key pair, and the private key proves who it is.
The attack is simply this. You generate your own key pair, write the public key into the target's msDS-KeyCredentialLink, and then you authenticate as the target using your private key through PKINIT. The DC trusts the key because it is listed on the object, and it issues you a TGT for that account.
Conditions that have to hold
This does not work everywhere. The requirements are specific:
- At least one domain controller running Windows Server 2016 or later. Key Trust and this attribute's enforcement came in with 2016.
- The DC must be able to do PKINIT. In practice that means Active Directory Certificate Services is present, or at minimum the DC has a certificate suitable for server authentication so it can validate the PKINIT exchange. Without a DC certificate, the key trust path does not complete.
- You need write access to the target's
msDS-KeyCredentialLinkattribute.
That last point is the whole prerequisite, so it is worth being precise about it.
Who can write the attribute
You can set msDS-KeyCredentialLink on a target if you hold any of these over that object:
- GenericAll — full control, which obviously includes writing the attribute.
- GenericWrite — write access to object properties, which covers this attribute.
- WriteProperty on the attribute specifically.
- AddKeyCredentialLink — an extended right that grants exactly this, nothing more.
This is why Shadow Credentials shows up so often as the payoff at the end of a BloodHound path. Any edge that lands you GenericWrite or GenericAll over a user or computer is a shadow credentials opportunity. It is frequently the cleanest way to cash in control of a computer object, since computers cannot simply have their password "known" the way a user password can be guessed.
Attack flow on Windows with Whisker
Whisker is the C# tool for this on Windows. It handles generating the key pair and writing the attribute, and it hands you a ready-to-run Rubeus command for the authentication step.
Add the shadow credential to a target computer:
Whisker.exe add /target:WS01$ /domain:corp.local /dc:dc01.corp.local
Whisker generates a certificate, writes the public key into msDS-KeyCredentialLink, and prints a Rubeus asktgt command containing the certificate as a base64 blob. You then request a TGT and pull credentials in one step:
Rubeus.exe asktgt /user:WS01$ /certificate:MIIJ... /password:<generated> \
/domain:corp.local /dc:dc01.corp.local /getcredentials /show
The /getcredentials flag is the part that turns this from "I have a ticket" into "I have the hash," which I will come back to.
Attack flow on Linux with pyWhisker or Certipy
From Linux, pyWhisker writes the attribute and produces a certificate file. Add the credential:
pywhisker.py -d "corp.local" -u "jdoe" -p "Passw0rd!" \
--target "WS01$" --action "add" --filename shadow_ws01
By default it exports a PFX. That certificate then feeds a PKINIT tool to get the TGT. Dirk-jan's PKINITtools are the usual choice:
python gettgtpkinit.py corp.local/WS01$ \
-cert-pfx shadow_ws01.pfx -pfx-pass <password> ws01.ccache
That emits a TGT into a ccache and, usefully, prints the AS-REP encryption key with a line telling you that you might need it later. You do.
Certipy collapses the whole sequence into one command. The shadow auto action adds the key credential, authenticates with PKINIT, recovers the NT hash, and then restores the attribute to its original state:
certipy shadow auto -u jdoe@corp.local -p 'Passw0rd!' \
-dc-ip 10.0.0.10 -account WS01$
The -account flag names the target whose msDS-KeyCredentialLink you are writing. When it finishes, you have the target's NT hash and the attribute is back the way you found it. For day-to-day lab work this is the fastest path, but it is worth understanding the individual steps so you know what each tool is doing on your behalf.
From TGT to NT hash: UnPAC-the-hash
Getting a TGT is often enough, but the NT hash is more portable. The trick that extracts it is called UnPAC-the-hash.
When a DC issues a TGT in response to a PKINIT request, it embeds a PAC_CREDENTIAL_INFO structure in the ticket. That structure contains the account's NTLM key, encrypted. The point is to let the client fall back to NTLM later without a password. If you hold the TGT and the AS-REP session key, you can decrypt that structure and read the NT hash straight out of it.
On Linux, that AS-REP key from gettgtpkinit.py is exactly what getnthash.py needs. Point it at the ticket and pass the key:
export KRB5CCNAME=ws01.ccache
python getnthash.py corp.local/WS01$ -key <AS-REP-encryption-key>
On Windows, Rubeus does it in the single asktgt call above: /getcredentials decrypts the credential info and prints the NT hash alongside the ticket. Same mechanism, one step.
Now you hold a reusable NT hash for the account, independent of the shadow credential you planted, which means you can clean up and still keep your access.
Cleanup
Leaving your key in msDS-KeyCredentialLink is sloppy and it is a standing backdoor on the client's object. Remove it. If you used Certipy's shadow auto, it already restored the attribute. Otherwise, list the entries to find the Device ID of the one you added, then remove it by that ID.
With Whisker on Windows:
Whisker.exe list /target:WS01$ /domain:corp.local /dc:dc01.corp.local
Whisker.exe remove /target:WS01$ /domain:corp.local /dc:dc01.corp.local \
/deviceid:2de4643a-2e0b-438f-a99d-5cb058b3254b
With pyWhisker on Linux:
pywhisker.py -d "corp.local" -u "jdoe" -p "Passw0rd!" \
--target "WS01$" --action "remove" \
--device-id a8ce856e-9b58-61f9-8fd3-b079689eb46e
Always list first and remove by the specific Device ID. A clear action exists, but it wipes every value on the attribute, including any legitimate Windows Hello keys that were there before you arrived. Do not clear when you only need to remove your own entry.
Detection
For defenders, the attribute change itself is the strongest signal:
-
Event 5136 — "A directory service object was modified." With directory service change auditing enabled, writes to
msDS-KeyCredentialLinkappear here. An unexpected modification to this attribute, especially on a privileged account or a computer, made by an account that is not a provisioning service, is worth an alert. - Event 4768 — a TGT request. PKINIT-based requests carry certificate information in the logged event, so a 4768 showing certificate-based pre-authentication for an account that has no business using Windows Hello stands out.
Correlating the two is powerful: a 5136 writing a key credential onto an object, followed shortly by a 4768 with certificate info for that same object, is the attack's full shape in the logs.
Mitigations
- Audit and tighten who has GenericWrite, GenericAll, WriteProperty and AddKeyCredentialLink over user and computer objects. BloodHound makes these edges easy to find, for you and for an attacker. Remove the ones that are not needed.
- Enable directory service change auditing so 5136 on
msDS-KeyCredentialLinkis actually recorded. - If you do not use Windows Hello for Business or key trust at all, treat any population of
msDS-KeyCredentialLinkas anomalous by default. - Protect the ADCS infrastructure and DC certificates generally. The PKINIT trust chain is what makes the key credential meaningful in the first place.
Shadow Credentials is a reminder that in Active Directory, write access to the right attribute can be as good as a password. The owner of the account never notices, which is exactly why it is worth knowing both how to use it and how to catch it.
Everything here was done in a lab. Only test systems you own or have written permission to test.