Documentation
¶
Overview ¶
Package dpapi implements DPAPI (Data Protection API) parsing and decryption for Windows secrets including master keys, credentials, and vaults.
Index ¶
- Constants
- Variables
- func DecryptWithBackupKey(domainKey *DomainKey, backupKey *BackupKey) ([]byte, error)
- type BackupKey
- type CredHist
- type CredHistEntry
- func (entry *CredHistEntry) Decrypt(key []byte) error
- func (entry *CredHistEntry) DecryptWithNTHash(ntHash []byte, sid string) error
- func (entry *CredHistEntry) DecryptWithPassword(password, sid string) error
- func (entry *CredHistEntry) Dump()
- func (entry *CredHistEntry) GetDecryptedNTHash() []byte
- func (entry *CredHistEntry) VerifyPassword(password string) bool
- type CredHistFile
- type Credential
- type CredentialFile
- type DPAPIBlob
- type DomainKey
- type MasterKey
- type MasterKeyFile
- type PVKFileHeader
- type PreferredBackupKey
- type PrivateKeyBlob
- type VaultAttribute
- type VaultAttributeItem
- type VaultCredential
- type VaultPolicy
Constants ¶
const ( CALG_SHA1 = 0x8004 CALG_SHA512 = 0x800e CALG_HMAC = 0x8009 CALG_3DES = 0x6603 CALG_AES_256 = 0x6610 )
Algorithm constants
Variables ¶
var ( // BACKUPKEY_BACKUP_GUID - 7F752B10-178E-11D1-AB8F-00805F14DB40 - backup a secret (ServerWrap) BACKUPKEY_BACKUP_GUID = [16]byte{ 0x10, 0x2B, 0x75, 0x7F, 0x8E, 0x17, 0xD1, 0x11, 0xAB, 0x8F, 0x00, 0x80, 0x5F, 0x14, 0xDB, 0x40, } // BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID - 018FF48A-EABA-40C6-8F6D-72370240E967 - retrieve backup key BACKUPKEY_RETRIEVE_BACKUP_KEY_GUID = [16]byte{ 0x8A, 0xF4, 0x8F, 0x01, 0xBA, 0xEA, 0xC6, 0x40, 0x8F, 0x6D, 0x72, 0x37, 0x02, 0x40, 0xE9, 0x67, } // BACKUPKEY_RESTORE_GUID_WIN2K - 7FE94D50-178E-11D1-AB8F-00805F14DB40 - legacy restore (ServerWrap) BACKUPKEY_RESTORE_GUID_WIN2K = [16]byte{ 0x50, 0x4D, 0xE9, 0x7F, 0x8E, 0x17, 0xD1, 0x11, 0xAB, 0x8F, 0x00, 0x80, 0x5F, 0x14, 0xDB, 0x40, } )
BKRP GUIDs for backup key retrieval
var ( // Windows Web Credentials VaultSchemaWebCredentials = [16]byte{ 0x3E, 0x0E, 0x35, 0xBE, 0x1B, 0x77, 0xD3, 0x01, 0xBD, 0xFC, 0x00, 0xC0, 0x4F, 0xC2, 0xF3, 0xB7, } // Windows Credential Picker Protector VaultSchemaCredPickerProtector = [16]byte{ 0xE6, 0x9D, 0x70, 0x74, 0x39, 0x7E, 0x5E, 0x40, 0xB1, 0x81, 0xC0, 0x26, 0x10, 0x81, 0x95, 0xF9, } // Windows Domain Password Credential VaultSchemaDomainPassword = [16]byte{ 0xE4, 0x6C, 0x2E, 0x92, 0xC2, 0x74, 0x0E, 0x49, 0x80, 0xBE, 0xA6, 0x2F, 0x5E, 0xE7, 0x85, 0xE3, } // Windows Domain Certificate Credential VaultSchemaDomainCertificate = [16]byte{ 0x27, 0x1E, 0xE6, 0x88, 0xBB, 0x5D, 0x9F, 0x47, 0xB5, 0x49, 0xE4, 0x73, 0x9B, 0xB0, 0xD0, 0x14, } // Windows Extended Credential VaultSchemaExtended = [16]byte{ 0x15, 0xE3, 0xA7, 0x3D, 0x30, 0xCA, 0xE3, 0x4E, 0x8A, 0x25, 0xCE, 0x83, 0x05, 0x03, 0x05, 0x3E, } // Windows Domain Password Credential (NGC) VaultSchemaNGCPassword = [16]byte{ 0x83, 0x3E, 0x0A, 0xF9, 0x8D, 0x47, 0x75, 0x42, 0x8A, 0xC7, 0xCD, 0xF9, 0xAD, 0x97, 0x4F, 0x42, } )
Vault schema GUIDs
Functions ¶
Types ¶
type BackupKey ¶
type BackupKey struct {
Version uint32
Magic uint32
KeyLength uint32
Certificate []byte
PrivateKey *rsa.PrivateKey
PVKData []byte
}
BackupKey represents a domain backup key
func LoadBackupKeyFile ¶
LoadBackupKeyFile loads a backup key from either PVK or PEM format
func LoadPEMFile ¶
LoadPEMFile loads a backup key from a PEM file
func LoadPVKFile ¶
LoadPVKFile loads a backup key from a PVK file
func ParseBackupKeyResponse ¶
ParseBackupKeyResponse parses the response from BKRP
func ParsePrivateKeyData ¶
ParsePrivateKeyData parses raw backup key data from LSA secrets The format depends on the version stored in LSA
type CredHist ¶
CredHist represents a credential history link
func ParseCredHist ¶
ParseCredHist parses a credential history structure
type CredHistEntry ¶
type CredHistEntry struct {
Version uint32
GUID string
UserSID string
HashAlgo uint32
CryptAlgo uint32
Salt []byte
Rounds uint32
HMACLen uint32
CipherTextLen uint32
CipherText []byte
DecryptedKey []byte
DecryptedHMAC []byte
SHA1 []byte // SHA1 of password used
NTHash []byte // NTLM hash of password
}
CredHistEntry represents a single entry in the credential history chain
func (*CredHistEntry) Decrypt ¶
func (entry *CredHistEntry) Decrypt(key []byte) error
Decrypt attempts to decrypt this CREDHIST entry using a key derived from password
func (*CredHistEntry) DecryptWithNTHash ¶
func (entry *CredHistEntry) DecryptWithNTHash(ntHash []byte, sid string) error
DecryptWithNTHash attempts to decrypt using an NTLM hash and SID
func (*CredHistEntry) DecryptWithPassword ¶
func (entry *CredHistEntry) DecryptWithPassword(password, sid string) error
DecryptWithPassword attempts to decrypt using a password and SID
func (*CredHistEntry) GetDecryptedNTHash ¶
func (entry *CredHistEntry) GetDecryptedNTHash() []byte
GetDecryptedNTHash returns the decrypted NTLM hash if available
func (*CredHistEntry) VerifyPassword ¶
func (entry *CredHistEntry) VerifyPassword(password string) bool
VerifyPassword verifies if a password matches this entry
type CredHistFile ¶
type CredHistFile struct {
Version uint32
GUID string
Entries []*CredHistEntry
}
CredHistFile represents a CREDHIST file containing a chain of credential history entries
func ParseCredHistFile ¶
func ParseCredHistFile(data []byte) (*CredHistFile, error)
ParseCredHistFile parses a CREDHIST file
func (*CredHistFile) WalkChain ¶
func (chf *CredHistFile) WalkChain(password, sid string) ([]*CredHistEntry, error)
WalkChain attempts to decrypt the entire credential history chain starting with the provided password and SID
type Credential ¶
type Credential struct {
Flags uint32
Type uint32
LastWritten uint64
Persist uint32
TargetName string
Comment string
TargetAlias string
UserName string
CredentialBlob []byte
}
Credential represents a decrypted Windows credential
func ParseCredential ¶
func ParseCredential(data []byte) (*Credential, error)
ParseCredential parses a decrypted credential blob
type CredentialFile ¶
CredentialFile represents a DPAPI credential file
func ParseCredentialFile ¶
func ParseCredentialFile(data []byte) (*CredentialFile, error)
ParseCredentialFile parses a credential file
type DPAPIBlob ¶
type DPAPIBlob struct {
Version uint32
GUIDProvider string
MasterKeyVersion uint32
GUIDMasterKey string
Flags uint32
Description string
AlgCrypt uint32
AlgCryptLen uint32
Salt []byte
HMACKeyLen uint32
HMACKey []byte
AlgHash uint32
AlgHashLen uint32
HMAC []byte
Data []byte
Sign []byte
}
DPAPIBlob represents an encrypted DPAPI blob
func ParseDPAPIBlob ¶
ParseDPAPIBlob parses a DPAPI blob structure
func (*DPAPIBlob) DecryptWithEntropy ¶
DecryptWithEntropy decrypts a DPAPI blob using the provided master key and optional entropy
type DomainKey ¶
type DomainKey struct {
Version uint32
SecretLen uint32
AccessCheck []byte
GUID string
Secret []byte
}
DomainKey represents a domain-encrypted master key
func ParseDomainKey ¶
ParseDomainKey parses a domain key structure
type MasterKey ¶
type MasterKey struct {
Version uint32
Salt []byte // 16 bytes
Iterations uint32
HashAlgo uint32
CryptAlgo uint32
Data []byte
DecryptedKey []byte // Set after successful decryption
}
MasterKey represents an encrypted master key
func ParseMasterKey ¶
ParseMasterKey parses a master key structure
func (*MasterKey) DecryptWithPassword ¶
DecryptWithPassword attempts to decrypt a master key using a password
type MasterKeyFile ¶
type MasterKeyFile struct {
Version uint32
Unk1 uint32
Unk2 uint32
GUID string // 36 chars UUID
Unk3 uint32
Policy uint32
Flags uint32
MasterKeyLen uint64
BackupKeyLen uint64
CredHistLen uint64
DomainKeyLen uint64
}
MasterKeyFile represents the header of a DPAPI master key file
func ParseMasterKeyFile ¶
func ParseMasterKeyFile(data []byte) (*MasterKeyFile, []byte, error)
ParseMasterKeyFile parses a master key file from raw bytes
type PVKFileHeader ¶
type PVKFileHeader struct {
Magic uint32 // 0xb0b5f11e
Reserved uint32
KeyType uint32
Encrypted uint32
SaltLength uint32
KeyLength uint32
}
PVKFileHeader represents the PVK file header
type PreferredBackupKey ¶
type PreferredBackupKey struct {
GUID [16]byte
}
PreferredBackupKey represents the GUID pointing to the preferred backup key
type PrivateKeyBlob ¶
type PrivateKeyBlob struct {
PublicKeyStruc struct {
Type byte
Version byte
Reserved uint16
AlgID uint32
}
RSAPubKey struct {
Magic uint32 // "RSA2" = 0x32415352
BitLen uint32
PubExp uint32
}
Modulus []byte
Prime1 []byte // p
Prime2 []byte // q
Exponent1 []byte // d mod (p-1)
Exponent2 []byte // d mod (q-1)
Coefficient []byte // q^-1 mod p
PrivateExponent []byte // d
}
PrivateKeyBlob represents a PRIVATEKEYBLOB structure
type VaultAttribute ¶
type VaultAttribute struct {
ID uint32
Unknown1 uint32
Unknown2 uint32
Unknown3 uint32
HasIV bool
IV []byte
Data []byte
}
VaultAttribute represents an attribute in a vault credential
type VaultAttributeItem ¶
type VaultAttributeItem struct {
ID uint32
Keyword string
Resource string
Identity string
Password string
}
VaultAttributeItem represents a decoded vault attribute
type VaultCredential ¶
type VaultCredential struct {
SchemaGUID string
Unknown1 uint32
LastWritten uint64
Unknown2 uint32
Unknown3 uint32
FriendlyName string
AttributeCount uint32
Attributes []*VaultAttribute
DecryptedClear []byte
}
VaultCredential represents a VCRD file structure
func ParseVaultCredential ¶
func ParseVaultCredential(data []byte) (*VaultCredential, error)
ParseVaultCredential parses a VCRD file
func (*VaultCredential) Decrypt ¶
func (vc *VaultCredential) Decrypt(keyAES256, keyAES128 []byte) error
Decrypt decrypts vault credential attributes using policy keys
func (*VaultCredential) Dump ¶
func (vc *VaultCredential) Dump()
Dump prints vault credential information
func (*VaultCredential) GetSchemaName ¶
func (vc *VaultCredential) GetSchemaName() string
GetSchemaName returns a human-readable name for the vault schema
type VaultPolicy ¶
type VaultPolicy struct {
Version uint32
GUID string
Description string
Unknown1 uint32
Unknown2 uint32
Unknown3 uint32
DPAPIBlob *DPAPIBlob
KeyAES256 []byte // Decrypted AES-256 key
KeyAES128 []byte // Decrypted AES-128 key
}
VaultPolicy represents a VPOL file structure
func ParseVaultPolicy ¶
func ParseVaultPolicy(data []byte) (*VaultPolicy, error)
ParseVaultPolicy parses a VPOL file
func (*VaultPolicy) Decrypt ¶
func (vp *VaultPolicy) Decrypt(masterKey []byte) error
Decrypt decrypts the vault policy using a master key