Overview
The certificates command searches for and decrypts DPAPI-protected certificate private keys for users or machines. Recovered certificates can be used for authentication, code signing, or encrypting/decrypting data.Windows stores certificate private keys encrypted with DPAPI. Decrypting these keys allows certificate export and usage without the original user context.
Basic Usage
Command Arguments
Decryption Methods
- CryptUnprotectData
- Domain Backup Key
- Masterkey Mappings
- User Credentials
Targeting Options
| Argument | Description |
|---|---|
/target:FILE | Target specific certificate private key file |
/target:FOLDER | Target specific folder of certificate files |
/machine | Use machine certificate store (requires elevation) |
/showall | Show all decrypted private keys, not just those linked to installed certificates |
/cng | Target CNG private keys instead of CAPI (default is CAPI) |
/server:SERVER | Triage remote server (not applicable for machine mode) |
Certificate File Locations
User Certificate Private Keys (CAPI):Execution Context
- User Certificates
- Machine Certificates (/machine)
- Run elevated to access all users
- Run unelevated for current user only
- Use
/unprotectfor unprivileged decryption
Example: User Certificates with Masterkeys
Example: Using /unprotect
Example: Machine Certificates
Certificate Usage Scenarios
Client Authentication
Client Authentication
EKU:
1.3.6.1.5.5.7.3.2- Used for user/computer authentication
- Can authenticate to Active Directory
- Access web services and APIs
- Remote desktop services
- High value for lateral movement
Code Signing
Code Signing
EKU:
1.3.6.1.5.5.7.3.3- Sign executables and scripts
- Sign driver packages
- Create trusted applications
- Bypass application whitelisting
Secure Email
Secure Email
EKU:
1.3.6.1.5.5.7.3.4- S/MIME email encryption
- Email signing
- Access encrypted email archives
Server Authentication
Server Authentication
EKU:
1.3.6.1.5.5.7.3.1- SSL/TLS server certificates
- Web server authentication
- Service authentication
Encrypting File System (EFS)
Encrypting File System (EFS)
EKU:
1.3.6.1.4.1.311.10.3.4- Decrypt EFS-encrypted files
- Access encrypted user data
- Recover encrypted documents
Common Scenarios
Post-Domain Compromise
Post-Domain Compromise
After obtaining domain backup key:
Unprivileged Certificate Extraction
Unprivileged Certificate Extraction
Extract certificates from current user context:
Finding Authentication Certificates
Finding Authentication Certificates
Look for certificates usable for authentication:These can be used for:
- Kerberos authentication (PKINIT)
- Web service authentication
- Network service access
Machine Certificate Extraction
Machine Certificate Extraction
Extract system certificates for service impersonation:
Using Recovered Certificates
The output provides both the private key and certificate in PEM format:1
Save Output
Save the private key and certificate sections to separate files:
cert.key- Private key portioncert.crt- Certificate portion
2
Convert to PFX
3
Import Certificate
Import the PFX to use for authentication or signing
Detection Considerations
Host-Based Indicators:- Reading files from
%APPDATA%\Microsoft\Crypto\RSA\ - Access to
C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\ - Non-standard processes accessing certificate private key files
- Bulk enumeration of certificate stores
- LSASS access for machine certificate operations
- Monitor access to user crypto directories
- Alert on MachineKeys folder access
- Track certificate private key file reads
- Detect bulk certificate enumeration
- Monitor for certificate export operations
Related Commands
triage
Includes user certificate triage
machinetriage
Includes machine certificate triage
masterkeys
Decrypt user masterkeys
backupkey
Retrieve domain backup key
Tips
Certificate Hunting
Certificate Hunting
- Look for “Client Authentication” EKU for authentication
- Check machine certificates on domain controllers and servers
- Code signing certificates are valuable for persistence
- EFS certificates can decrypt user files
- Smart card certificates are high-value targets
OPSEC Considerations
OPSEC Considerations
- Use
/unprotectfor unprivileged, stealthy extraction - Target specific certificate files if locations are known
- Machine certificate operations require elevation (more visible)
- Redirect output to file to avoid console display
- Consider exfiltration method for recovered certificates
Troubleshooting
Troubleshooting
No certificates found:
- User may not have certificate private keys
- Try
/showallto see all decrypted keys - Check both CAPI and CNG locations
- Verify masterkeys are correct
- Masterkey may not be available
- Try using domain backup key
- Certificate may use different DPAPI protection
- Check if
/cngflag is needed
- Must run as Administrator or SYSTEM
- Uses DPAPI_SYSTEM LSA secret
- Cannot use /unprotect for machine certs