2014-11-20 07:57:04 +00:00
|
|
|
/* Benjamin DELPY `gentilkiwi`
|
|
|
|
http://blog.gentilkiwi.com
|
|
|
|
benjamin@gentilkiwi.com
|
|
|
|
Licence : http://creativecommons.org/licenses/by/3.0/fr/
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "globals.h"
|
2015-06-03 00:13:43 +00:00
|
|
|
#include "kull_m_crypto.h"
|
2015-06-07 21:19:28 +00:00
|
|
|
#include "kull_m_crypto_system.h"
|
2014-11-20 07:57:04 +00:00
|
|
|
#include "kull_m_string.h"
|
|
|
|
|
2015-07-14 23:13:21 +00:00
|
|
|
#define CRYPTPROTECT_SYSTEM 0x20000000
|
|
|
|
|
2014-11-20 07:57:04 +00:00
|
|
|
typedef struct _KULL_M_DWORD_TO_DWORD{
|
|
|
|
PCWSTR name;
|
|
|
|
DWORD id;
|
|
|
|
} KULL_M_DWORD_TO_DWORD, *PKULL_M_DWORD_TO_DWORD;
|
|
|
|
|
|
|
|
#pragma pack(push, 4)
|
|
|
|
typedef struct _KULL_M_DPAPI_BLOB {
|
|
|
|
DWORD dwVersion;
|
|
|
|
GUID guidProvider;
|
|
|
|
DWORD dwMasterKeyVersion;
|
|
|
|
GUID guidMasterKey;
|
|
|
|
DWORD dwFlags;
|
|
|
|
|
|
|
|
DWORD dwDescriptionLen;
|
|
|
|
PWSTR szDescription;
|
|
|
|
|
|
|
|
ALG_ID algCrypt;
|
|
|
|
DWORD dwAlgCryptLen;
|
|
|
|
|
|
|
|
DWORD dwSaltLen;
|
|
|
|
PBYTE pbSalt;
|
|
|
|
|
|
|
|
DWORD dwHmacKeyLen;
|
|
|
|
PBYTE pbHmackKey;
|
|
|
|
|
|
|
|
ALG_ID algHash;
|
|
|
|
DWORD dwAlgHashLen;
|
|
|
|
|
|
|
|
DWORD dwHmac2KeyLen;
|
|
|
|
PBYTE pbHmack2Key;
|
|
|
|
|
|
|
|
DWORD dwDataLen;
|
|
|
|
PBYTE pbData;
|
|
|
|
|
|
|
|
DWORD dwSignLen;
|
|
|
|
PBYTE pbSign;
|
|
|
|
} KULL_M_DPAPI_BLOB, *PKULL_M_DPAPI_BLOB;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _KULL_M_DPAPI_MASTERKEY {
|
|
|
|
DWORD dwVersion;
|
|
|
|
BYTE salt[16];
|
|
|
|
DWORD rounds;
|
|
|
|
ALG_ID algHash;
|
|
|
|
ALG_ID algCrypt;
|
|
|
|
PBYTE pbKey;
|
2015-06-03 00:13:43 +00:00
|
|
|
DWORD __dwKeyLen;
|
2014-11-20 07:57:04 +00:00
|
|
|
} KULL_M_DPAPI_MASTERKEY, *PKULL_M_DPAPI_MASTERKEY;
|
|
|
|
|
2015-06-21 23:31:26 +00:00
|
|
|
typedef struct _KULL_M_DPAPI_MASTERKEY_CREDHIST {
|
2014-11-20 07:57:04 +00:00
|
|
|
DWORD dwVersion;
|
|
|
|
GUID guid;
|
2015-06-21 23:31:26 +00:00
|
|
|
} KULL_M_DPAPI_MASTERKEY_CREDHIST, *PKULL_M_DPAPI_MASTERKEY_CREDHIST;
|
2014-11-20 07:57:04 +00:00
|
|
|
|
2015-06-21 23:31:26 +00:00
|
|
|
typedef struct _KULL_M_DPAPI_MASTERKEY_DOMAINKEY {
|
2014-11-20 07:57:04 +00:00
|
|
|
DWORD dwVersion;
|
|
|
|
DWORD dwSecretLen;
|
|
|
|
DWORD dwAccesscheckLen;
|
|
|
|
GUID guidMasterKey;
|
|
|
|
PBYTE pbSecret;
|
|
|
|
PBYTE pbAccesscheck;
|
2015-06-21 23:31:26 +00:00
|
|
|
} KULL_M_DPAPI_MASTERKEY_DOMAINKEY, *PKULL_M_DPAPI_MASTERKEY_DOMAINKEY;
|
2014-11-20 07:57:04 +00:00
|
|
|
|
|
|
|
typedef struct _KULL_M_DPAPI_MASTERKEYS {
|
|
|
|
DWORD dwVersion;
|
|
|
|
DWORD unk0;
|
|
|
|
DWORD unk1;
|
|
|
|
WCHAR szGuid[36];
|
|
|
|
DWORD unk2;
|
|
|
|
DWORD unk3;
|
|
|
|
DWORD dwFlags;
|
|
|
|
DWORD64 dwMasterKeyLen;
|
|
|
|
DWORD64 dwBackupKeyLen;
|
|
|
|
DWORD64 dwCredHistLen;
|
|
|
|
DWORD64 dwDomainKeyLen;
|
|
|
|
PKULL_M_DPAPI_MASTERKEY MasterKey;
|
|
|
|
PKULL_M_DPAPI_MASTERKEY BackupKey;
|
2015-06-21 23:31:26 +00:00
|
|
|
PKULL_M_DPAPI_MASTERKEY_CREDHIST CredHist;
|
|
|
|
PKULL_M_DPAPI_MASTERKEY_DOMAINKEY DomainKey;
|
2014-11-20 07:57:04 +00:00
|
|
|
} KULL_M_DPAPI_MASTERKEYS, *PKULL_M_DPAPI_MASTERKEYS;
|
2015-06-14 00:46:21 +00:00
|
|
|
|
|
|
|
typedef struct _KULL_M_DPAPI_DOMAIN_RSA_MASTER_KEY {
|
2015-06-21 23:31:26 +00:00
|
|
|
DWORD cbMasterKey;
|
|
|
|
DWORD cbSuppKey;
|
|
|
|
BYTE buffer[ANYSIZE_ARRAY];
|
2015-06-14 00:46:21 +00:00
|
|
|
} KULL_M_DPAPI_DOMAIN_RSA_MASTER_KEY, *PKULL_M_DPAPI_DOMAIN_RSA_MASTER_KEY;
|
|
|
|
|
|
|
|
typedef struct _KULL_M_DPAPI_DOMAIN_ACCESS_CHECK {
|
2015-06-21 23:31:26 +00:00
|
|
|
DWORD dwVersion;
|
|
|
|
DWORD dataLen;
|
|
|
|
BYTE data[ANYSIZE_ARRAY];
|
|
|
|
// sid
|
|
|
|
// SHA1 (or SHA512)
|
2015-06-14 00:46:21 +00:00
|
|
|
} KULL_M_DPAPI_DOMAIN_ACCESS_CHECK, *PKULL_M_DPAPI_DOMAIN_ACCESS_CHECK;
|
2015-06-21 23:31:26 +00:00
|
|
|
|
|
|
|
typedef struct _KULL_M_DPAPI_CREDHIST_HEADER {
|
|
|
|
DWORD dwVersion;
|
|
|
|
GUID guid;
|
|
|
|
DWORD dwNextLen;
|
|
|
|
} KULL_M_DPAPI_CREDHIST_HEADER, *PKULL_M_DPAPI_CREDHIST_HEADER;
|
|
|
|
|
|
|
|
typedef struct _KULL_M_DPAPI_CREDHIST_ENTRY {
|
|
|
|
KULL_M_DPAPI_CREDHIST_HEADER header;
|
|
|
|
DWORD dwType; // flags ?
|
|
|
|
ALG_ID algHash;
|
|
|
|
DWORD rounds;
|
|
|
|
DWORD sidLen;
|
|
|
|
ALG_ID algCrypt;
|
|
|
|
DWORD sha1Len;
|
|
|
|
DWORD md4Len;
|
|
|
|
BYTE salt[16];
|
|
|
|
|
|
|
|
PSID pSid;
|
|
|
|
PBYTE pSecret;
|
|
|
|
|
|
|
|
DWORD __dwSecretLen;
|
|
|
|
} KULL_M_DPAPI_CREDHIST_ENTRY, *PKULL_M_DPAPI_CREDHIST_ENTRY;
|
|
|
|
|
|
|
|
typedef struct _KULL_M_DPAPI_CREDHIST {
|
|
|
|
KULL_M_DPAPI_CREDHIST_HEADER current;
|
|
|
|
PKULL_M_DPAPI_CREDHIST_ENTRY * entries;
|
|
|
|
DWORD __dwCount;
|
|
|
|
} KULL_M_DPAPI_CREDHIST, *PKULL_M_DPAPI_CREDHIST;
|
2014-11-20 07:57:04 +00:00
|
|
|
#pragma pack(pop)
|
|
|
|
|
2015-06-18 23:19:01 +00:00
|
|
|
PKULL_M_DPAPI_BLOB kull_m_dpapi_blob_create(LPCVOID data/*, DWORD size*/);
|
2014-11-20 07:57:04 +00:00
|
|
|
void kull_m_dpapi_blob_delete(PKULL_M_DPAPI_BLOB blob);
|
2015-06-18 00:18:17 +00:00
|
|
|
void kull_m_dpapi_blob_descr(DWORD level, PKULL_M_DPAPI_BLOB blob);
|
2015-06-18 23:19:01 +00:00
|
|
|
void kull_m_dpapi_blob_quick_descr(DWORD level, LPCVOID data/*, DWORD size*/);
|
2015-06-21 23:31:26 +00:00
|
|
|
|
2015-06-18 23:19:01 +00:00
|
|
|
PKULL_M_DPAPI_MASTERKEYS kull_m_dpapi_masterkeys_create(LPCVOID data/*, DWORD size*/);
|
2014-11-20 07:57:04 +00:00
|
|
|
void kull_m_dpapi_masterkeys_delete(PKULL_M_DPAPI_MASTERKEYS masterkeys);
|
2015-06-18 00:18:17 +00:00
|
|
|
void kull_m_dpapi_masterkeys_descr(DWORD level, PKULL_M_DPAPI_MASTERKEYS masterkeys);
|
2015-06-21 23:31:26 +00:00
|
|
|
|
2015-06-18 23:19:01 +00:00
|
|
|
PKULL_M_DPAPI_MASTERKEY kull_m_dpapi_masterkey_create(LPCVOID data, DWORD64 size);
|
2015-06-03 00:13:43 +00:00
|
|
|
void kull_m_dpapi_masterkey_delete(PKULL_M_DPAPI_MASTERKEY masterkey);
|
2015-06-18 00:18:17 +00:00
|
|
|
void kull_m_dpapi_masterkey_descr(DWORD level, PKULL_M_DPAPI_MASTERKEY masterkey);
|
2015-06-21 23:31:26 +00:00
|
|
|
|
|
|
|
PKULL_M_DPAPI_MASTERKEY_CREDHIST kull_m_dpapi_masterkeys_credhist_create(LPCVOID data, DWORD64 size);
|
|
|
|
void kull_m_dpapi_masterkeys_credhist_delete(PKULL_M_DPAPI_MASTERKEY_CREDHIST credhist);
|
|
|
|
void kull_m_dpapi_masterkeys_credhist_descr(DWORD level, PKULL_M_DPAPI_MASTERKEY_CREDHIST credhist);
|
|
|
|
|
|
|
|
PKULL_M_DPAPI_MASTERKEY_DOMAINKEY kull_m_dpapi_masterkeys_domainkey_create(PVOID LPCVOID, DWORD64 size);
|
|
|
|
void kull_m_dpapi_masterkeys_domainkey_delete(PKULL_M_DPAPI_MASTERKEY_DOMAINKEY domainkey);
|
|
|
|
void kull_m_dpapi_masterkeys_domainkey_descr(DWORD level, PKULL_M_DPAPI_MASTERKEY_DOMAINKEY domainkey);
|
|
|
|
|
|
|
|
PKULL_M_DPAPI_CREDHIST kull_m_dpapi_credhist_create(LPCVOID data, DWORD size);
|
2015-06-03 00:13:43 +00:00
|
|
|
void kull_m_dpapi_credhist_delete(PKULL_M_DPAPI_CREDHIST credhist);
|
2015-06-18 00:18:17 +00:00
|
|
|
void kull_m_dpapi_credhist_descr(DWORD level, PKULL_M_DPAPI_CREDHIST credhist);
|
2015-06-21 23:31:26 +00:00
|
|
|
|
|
|
|
PKULL_M_DPAPI_CREDHIST_ENTRY kull_m_dpapi_credhist_entry_create(LPCVOID data, DWORD size);
|
|
|
|
void kull_m_dpapi_credhist_entry_delete(PKULL_M_DPAPI_CREDHIST_ENTRY entry);
|
|
|
|
void kull_m_dpapi_credhist_entry_descr(DWORD level, PKULL_M_DPAPI_CREDHIST_ENTRY entry);
|
2015-06-07 21:19:28 +00:00
|
|
|
|
|
|
|
BOOL kull_m_dpapi_hmac_sha1_incorrect(LPCVOID key, DWORD keyLen, LPCVOID salt, DWORD saltLen, LPCVOID entropy, DWORD entropyLen, LPCVOID data, DWORD dataLen, LPVOID outKey);
|
|
|
|
BOOL kull_m_dpapi_sessionkey(LPCVOID masterkey, DWORD masterkeyLen, LPCVOID salt, DWORD saltLen, LPCVOID entropy, DWORD entropyLen, LPCVOID data, DWORD dataLen, ALG_ID hashAlg, LPVOID outKey, DWORD outKeyLen);
|
|
|
|
BOOL kull_m_dpapi_unprotect_blob(PKULL_M_DPAPI_BLOB blob, LPCVOID masterkey, DWORD masterkeyLen, LPCVOID entropy, DWORD entropyLen, LPCWSTR password, LPVOID *dataOut, DWORD *dataOutLen);
|
2015-06-18 23:19:01 +00:00
|
|
|
BOOL kull_m_dpapi_unprotect_raw_or_blob(LPCVOID pDataIn, DWORD dwDataInLen, LPWSTR *ppszDataDescr, LPCVOID pOptionalEntropy, DWORD dwOptionalEntropyLen, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags, LPVOID *pDataOut, DWORD *dwDataOutLen, LPCVOID pMasterKey, DWORD dwMasterKeyLen, LPCWSTR pPassword);
|
2015-06-07 21:19:28 +00:00
|
|
|
|
2015-06-14 00:46:21 +00:00
|
|
|
BOOL kull_m_dpapi_unprotect_masterkey_with_password(DWORD flags, PKULL_M_DPAPI_MASTERKEY masterkey, PCWSTR password, PCWSTR sid, BOOL isKeyOfProtectedUser, PVOID *output, DWORD *outputLen);
|
|
|
|
BOOL kull_m_dpapi_unprotect_masterkey_with_userHash(PKULL_M_DPAPI_MASTERKEY masterkey, LPCVOID userHash, DWORD userHashLen, PCWSTR sid, PVOID *output, DWORD *outputLen);
|
|
|
|
BOOL kull_m_dpapi_unprotect_masterkey_with_shaDerivedkey(PKULL_M_DPAPI_MASTERKEY masterkey, LPCVOID shaDerivedkey, DWORD shaDerivedkeyLen, PVOID *output, DWORD *outputLen);
|
|
|
|
BOOL kull_m_dpapi_unprotect_backupkey_with_secret(DWORD flags, PKULL_M_DPAPI_MASTERKEY masterkey, PCWSTR sid, LPCVOID secret, DWORD secretLen, PVOID *output, DWORD *outputLen);
|
2015-06-21 23:31:26 +00:00
|
|
|
BOOL kull_m_dpapi_unprotect_domainkey_with_key(PKULL_M_DPAPI_MASTERKEY_DOMAINKEY domainkey, LPCVOID key, DWORD keyLen, PVOID *output, DWORD *outputLen, PSID *sid);
|
|
|
|
|
|
|
|
BOOL kull_m_dpapi_unprotect_credhist_entry_with_shaDerivedkey(PKULL_M_DPAPI_CREDHIST_ENTRY entry, LPCVOID shaDerivedkey, DWORD shaDerivedkeyLen, PVOID md4hash, PVOID sha1hash);
|
2015-06-14 00:46:21 +00:00
|
|
|
|
2015-06-07 21:19:28 +00:00
|
|
|
void kull_m_dpapi_displayPromptFlags(DWORD flags);
|
|
|
|
void kull_m_dpapi_displayProtectionFlags(DWORD flags);
|