Overview
The backupkey command retrieves the domain DPAPI backup key from a domain controller using the LsaRetrievePrivateData API. This private key can decrypt masterkeys for any domain user and never changes.Basic Usage
Command Arguments
| Argument | Description |
|---|---|
/server:SERVER.domain.com | Specify domain controller (auto-detected if not provided) |
/file:key.pvk | Save backup key to file instead of displaying |
/nowrap | Prevent wrapping base64 output (display in single line) |
Why The Backup Key Is Powerful
Never Changes
The domain backup key is generated once and never rotates
Domain-Wide
Works for ALL domain users across the entire domain
Decrypt Anything
Can decrypt any user’s DPAPI protected data
Persistent Access
Maintains access even after password changes
Example: Retrieve Backup Key
Example: Save to File
Using The Retrieved Backup Key
Once you have the backup key, use it with other SharpDPAPI commands:- Base64 Key
- Key File
- Remote Systems
Typical Workflow
1
Obtain Domain Admin
Compromise an account with Domain Admin or equivalent privileges
2
Retrieve Backup Key
3
Triage Local System
4
Triage Remote Systems
5
Maintain Access
Keep the backup key secure - it provides persistent domain-wide DPAPI decryption capability
Technical Details
Storage Location
The backup key is stored in Active Directory as an LSA secret:Retrieval Method
SharpDPAPI uses the LsaRetrievePrivateData API, the same method used by Mimikatz:- Connects to domain controller
- Authenticates with current credentials
- Retrieves the preferred backup key GUID
- Extracts the RSA private key
Key Properties
- Algorithm: RSA (typically 2048-bit)
- Format: Microsoft PRIVATEKEYBLOB structure
- Persistence: Never rotates unless manually regenerated
- Scope: All domain users
Converting Key Formats
The backup key can be used in different formats:- For SharpDPAPI
- For Mimikatz
Detection Considerations
Network Detection
- MS-BKRP Protocol: Backup Key Remote Protocol usage
- RPC Calls: LsaRetrievePrivateData calls to domain controller
- Event ID 4662: Access to sensitive AD objects
Host-Based Detection
- Process Execution: SharpDPAPI.exe or similar tools
- API Calls: LsaRetrievePrivateData invocations
- Privilege Usage: SeBackupPrivilege or equivalent
Event Log Indicators
Monitor domain controllers for:Defensive Measures
Detection Strategies
Detection Strategies
- Monitor for Event ID 4662 with object name containing “BCKUPKEY”
- Alert on MS-BKRP protocol usage
- Track LsaRetrievePrivateData API calls
- Monitor for privileged account access to sensitive LSA secrets
Prevention Strategies
Prevention Strategies
- Strictly control Domain Admin privileges
- Implement tiered administration model
- Use Protected Users group for high-value accounts
- Enable advanced audit policies for object access
- Consider rotating backup key periodically (requires planning)
Related Commands
masterkeys
Decrypt user masterkeys with backup key
triage
Comprehensive user DPAPI triage
credentials
Decrypt credentials with backup key
machinetriage
Triage machine DPAPI data
Tips
Operational Security
Operational Security
- Retrieve the backup key once and reuse it
- Store securely - it’s valid indefinitely
- Use
/fileto avoid base64 in command history - Consider exfiltrating key over encrypted channel
- Clean up temporary files after use
Troubleshooting
Troubleshooting
Access Denied:
- Verify you have Domain Admin privileges
- Check network connectivity to domain controller
- Ensure domain controller is reachable
- Domain must have DPAPI enabled (default in AD)
- Verify the domain controller is functioning properly
- Try specifying DC explicitly with
/server