decrypting dpapi data - black hat briefings

109
Decrypting DPAPI data Jean-Michel Picod, Elie Bursztein EADS, Stanford University Tuesday, February 2, 2010

Upload: others

Post on 03-Feb-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Decrypting DPAPI data - Black Hat Briefings

Decrypting DPAPI dataJean-Michel Picod, Elie Bursztein

EADS, Stanford University

Tuesday, February 2, 2010

Page 2: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Data Protection API

• Introduced in Windows 2000

• Aim to be an easy way for application to store safely data on disk

• Tie encryption key to user password

Tuesday, February 2, 2010

Page 3: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Developer point of view

Application

DPAPI

Tuesday, February 2, 2010

Page 4: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Developer point of view

Application

DPAPI

Tuesday, February 2, 2010

Page 5: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Developer point of view

Application

DPAPIDPAPI

Tuesday, February 2, 2010

Page 6: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Developer point of view

Application

DPAPIDPAPI

Tuesday, February 2, 2010

Page 7: Decrypting DPAPI data - Black Hat Briefings

GTalkWIFI keys

Tuesday, February 2, 2010

Page 8: Decrypting DPAPI data - Black Hat Briefings

DPAPI is a simple API*

*http://msdn.microsoft.com/en-us/library/ms995355.aspx

Tuesday, February 2, 2010

Page 9: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Why digging deeper ?

• Offline forensic

• EFS on Linux

• Security ?

Tuesday, February 2, 2010

Page 10: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Previous work

• Multiples attempts to analyze DPAPI

• Some incomplete (Wine)

• Some close source (Nir Sofer - NirSoft)

Tuesday, February 2, 2010

Page 11: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Take away

• Decrypt offline sensitive data

• Recovers user previous password

• Do a key escrow attack

Tuesday, February 2, 2010

Page 12: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Outline

• DPAPI overview

• Decryption process

• Security design implications

• DPAPIck demo

Tuesday, February 2, 2010

Page 13: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

How the system interacts with DPAPI

Tuesday, February 2, 2010

Page 14: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

How the system interacts with DPAPI

DPAPIcryptoAPIcrypt32.dll

Tuesday, February 2, 2010

Page 15: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

How the system interacts with DPAPI

DPAPIcryptoAPIcrypt32.dll

Local Security AuthoritycryptoAPIcrypt32.dll

Tuesday, February 2, 2010

Page 16: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

How the system interacts with DPAPI

EFS Encrypted file

DPAPIcryptoAPIcrypt32.dll

Local Security AuthoritycryptoAPIcrypt32.dll

Tuesday, February 2, 2010

Page 17: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

How the system interacts with DPAPI

EFS Encrypted file

DPAPIcryptoAPIcrypt32.dll

EFS

Local Security AuthoritycryptoAPIcrypt32.dll

Tuesday, February 2, 2010

Page 18: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

How the system interacts with DPAPI

EFS Encrypted file

EFSuser private

key

DPAPIcryptoAPIcrypt32.dll

EFS

Local Security AuthoritycryptoAPIcrypt32.dll

Tuesday, February 2, 2010

Page 19: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

How the system interacts with DPAPI

EFS Encrypted file

EFSuser private

key

DPAPIcryptoAPIcrypt32.dll

EFS

Local Security AuthoritycryptoAPIcrypt32.dll

Tuesday, February 2, 2010

Page 20: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

DPAPI CryptUnprotecData Function

BOOL WINAPI CryptUnprotectData (

*pDataIn,

*ppszDataDescr,

*pOptionalEntropy,

pvReserved,

*pPromptStruct,

dwFlags,

*pDataOut

Tuesday, February 2, 2010

Page 21: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

DPAPI CryptUnprotecData Function

BOOL WINAPI CryptUnprotectData (

*pDataIn,

*ppszDataDescr,

*pOptionalEntropy,

pvReserved,

*pPromptStruct,

dwFlags,

*pDataOut

Encrypted data aka data blob

Tuesday, February 2, 2010

Page 22: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

DPAPI CryptUnprotecData Function

BOOL WINAPI CryptUnprotectData (

*pDataIn,

*ppszDataDescr,

*pOptionalEntropy,

pvReserved,

*pPromptStruct,

dwFlags,

*pDataOut

Optional description

Tuesday, February 2, 2010

Page 23: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

DPAPI CryptUnprotecData Function

BOOL WINAPI CryptUnprotectData (

*pDataIn,

*ppszDataDescr,

*pOptionalEntropy,

pvReserved,

*pPromptStruct,

dwFlags,

*pDataOut

Optional entropy (salt)

Tuesday, February 2, 2010

Page 24: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

DPAPI CryptUnprotecData Function

BOOL WINAPI CryptUnprotectData (

*pDataIn,

*ppszDataDescr,

*pOptionalEntropy,

pvReserved,

*pPromptStruct,

dwFlags,

*pDataOut

Optional password

Tuesday, February 2, 2010

Page 25: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

DPAPI CryptUnprotecData Function

BOOL WINAPI CryptUnprotectData (

*pDataIn,

*ppszDataDescr,

*pOptionalEntropy,

pvReserved,

*pPromptStruct,

dwFlags,

*pDataOut Decrypted data

Tuesday, February 2, 2010

Page 26: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Derivation scheme

User

Tuesday, February 2, 2010

Page 27: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Derivation scheme

User

Pre keySHA1(password)

Tuesday, February 2, 2010

Page 28: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Derivation scheme

User

Pre keySHA1(password)

Master Key

Tuesday, February 2, 2010

Page 29: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Derivation scheme

User

Pre keySHA1(password)

Master Key

Blob key Blob key Blob key

Tuesday, February 2, 2010

Page 30: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Derivation scheme

User

Pre keySHA1(password)

Master Key

Blob key Blob key Blob key

Tuesday, February 2, 2010

Page 31: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Blob structure

• Returned to the application (opaque structure)

• Store user encrypted data

• Contains decryption parameters

Tuesday, February 2, 2010

Page 32: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

key subtleties

• SHA1 password are in UTF-16LE

• SID for HMAC are also in UTF-16LE (don’t forget the \0 !)

• Windows 2000 do not use SHA1/3DES. We think it uses SHA1/RC4 (Anyone want to try ?).

Tuesday, February 2, 2010

Page 33: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Tuesday, February 2, 2010

Page 34: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Nb of crypto providers

Tuesday, February 2, 2010

Page 35: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Crypto providers GUID

Tuesday, February 2, 2010

Page 36: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Nb of masters keys

Tuesday, February 2, 2010

Page 37: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Masters keys GUID

Tuesday, February 2, 2010

Page 38: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Optional description

Tuesday, February 2, 2010

Page 39: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Encryption algorithm ID

Tuesday, February 2, 2010

Page 40: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Initialization vector

Tuesday, February 2, 2010

Page 41: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Hash algorithm ID

Tuesday, February 2, 2010

Page 42: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Salt generated by DPAPI

Tuesday, February 2, 2010

Page 43: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC;

Encrypted data

Tuesday, February 2, 2010

Page 44: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

data blob structure key fields

DWORD cbProviders;

GUID *arrProviders;

DWORD cbKeys;

GUID *arrKeys;

WCHAR *ppszDataDescr;

DWORD idCipherAlgo;

BYTE *pbIV;

DWORD idHashAlgo;

BYTE *pbSalt;

BYTE *pbCipher;

BYTE *pbHMAC; Blob HMAC

Tuesday, February 2, 2010

Page 45: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Master key structure

• Store the key used to decrypt blob

• Encrypted with the user password

• Renewed every 3 months

Tuesday, February 2, 2010

Page 46: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

The master key file

Header

Tuesday, February 2, 2010

Page 47: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

The master key file

Header

Keys infos

Tuesday, February 2, 2010

Page 48: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

The master key file

Header

Keys infos

Master key

Tuesday, February 2, 2010

Page 49: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

The master key file

Header

Keys infos

Master key

Key ?

Tuesday, February 2, 2010

Page 50: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

The master key file

Header

Keys infos

Master key

Key ?

Footer

Tuesday, February 2, 2010

Page 51: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Header structure

dwVersion;

nullPad1;

szKeyGUID[36];

nullPad2;

Header

Keys infos

Master key

Key ?

Footer

Tuesday, February 2, 2010

Page 52: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Header structure

dwVersion;

nullPad1;

szKeyGUID[36];

nullPad2;

Header

Keys infos

Master key

Key ?

Footer

File version

Tuesday, February 2, 2010

Page 53: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Header structure

dwVersion;

nullPad1;

szKeyGUID[36];

nullPad2;

Header

Keys infos

Master key

Key ?

Footer

Master key GUID

Tuesday, February 2, 2010

Page 54: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Key infos structure

dwUnknown;

cbMasterKey;

cbMysteryKey;

dwHMACLen;

nullPad3;

Header

Keys infos

Master key

Key ?

Footer

Tuesday, February 2, 2010

Page 55: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Key infos structure

dwUnknown;

cbMasterKey;

cbMysteryKey;

dwHMACLen;

nullPad3;

Header

Keys infos

Master key

Key ?

Footer

Master Key struct length

Tuesday, February 2, 2010

Page 56: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Key infos structure

dwUnknown;

cbMasterKey;

cbMysteryKey;

dwHMACLen;

nullPad3;

Header

Keys infos

Master key

Key ?

Footer

Key ? struct length

Tuesday, February 2, 2010

Page 57: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Key infos structure

dwUnknown;

cbMasterKey;

cbMysteryKey;

dwHMACLen;

nullPad3;

Header

Keys infos

Master key

Key ?

Footer

HMAC length

Tuesday, February 2, 2010

Page 58: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Master key structure

dwMagic;

pbSalt[16];

cbIteration;

idMACAlgo;

idCipherAlgo;

pbCipheredKey[];

Header

Keys infos

Master key

Key ?

Footer

Tuesday, February 2, 2010

Page 59: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Master key structure

dwMagic;

pbSalt[16];

cbIteration;

idMACAlgo;

idCipherAlgo;

pbCipheredKey[];

Header

Keys infos

Master key

Key ?

Footer

Key salt

Tuesday, February 2, 2010

Page 60: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Master key structure

dwMagic;

pbSalt[16];

cbIteration;

idMACAlgo;

idCipherAlgo;

pbCipheredKey[];

Header

Keys infos

Master key

Key ?

Footer

PBKDF2 nb rounds

Tuesday, February 2, 2010

Page 61: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Master key structure

dwMagic;

pbSalt[16];

cbIteration;

idMACAlgo;

idCipherAlgo;

pbCipheredKey[];

Header

Keys infos

Master key

Key ?

Footer

HMAC algorithm ID

Tuesday, February 2, 2010

Page 62: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Master key structure

dwMagic;

pbSalt[16];

cbIteration;

idMACAlgo;

idCipherAlgo;

pbCipheredKey[];

Header

Keys infos

Master key

Key ?

Footer Encryption Algo id

Tuesday, February 2, 2010

Page 63: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Master key structure

dwMagic;

pbSalt[16];

cbIteration;

idMACAlgo;

idCipherAlgo;

pbCipheredKey[];

Header

Keys infos

Master key

Key ?

Footer

Encrypted key

Tuesday, February 2, 2010

Page 64: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting the Master key

DPAPIDecryptKey(sha1, encKey) {

tmp-key = HMAC(sha1, SID)

pre-key = PBKDF2(decryptKey, Salt, ID_ALGO, nbIteration)

3desKey = pre-key[0 - 23]

3desIV = [24 - 31]

(hmac[0-35], DWORD[36-39], master-key[40-104]) = 3des-cbc(3desKey, iv, encKey)

}

Tuesday, February 2, 2010

Page 65: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

key structure

• Seems to have the same structure than the master key

• One round of derivation (XP not Seven)

• 256 bits (half size of the real master-key)

Header

Keys infos

Master key

Key ?

Footer

Tuesday, February 2, 2010

Page 66: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Possible explanation

• The documentation state a compatibility mode for windows 2000 exist.

• The registry key to trigger it is unknown

• If we are correct and W2k uses RC4 then the mystery key is possibly a RC4 key (256bits is the correct size).

• PBKDF2 used to compute the IV ??

Header

Keys infos

Master key

Key ?

Footer

Tuesday, February 2, 2010

Page 67: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Possible explanation continued

• We know that RC4 have a weak key scheduling algorithm (remember WEP ?)

• Might be a potential weakness (or not)

Header

Keys infos

Master key

Key ?

Footer

Tuesday, February 2, 2010

Page 68: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Header structure

dwMagic;

credHist[16];

Header

Keys infos

Master key

Key ?

Footer

Tuesday, February 2, 2010

Page 69: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Header structure

dwMagic;

credHist[16];

Header

Keys infos

Master key

Key ?

Footer

Password GUID

Tuesday, February 2, 2010

Page 70: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Differences between windows version

XP Vista Seven

PBKDF2rounds 4000 24000

Variable (factor ?)

Symmetricalgorithm 3DES 3DES AES

Hash algorithm SHA1 SHA1 SHA512

Tuesday, February 2, 2010

Page 71: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob

Tuesday, February 2, 2010

Page 72: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Tuesday, February 2, 2010

Page 73: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

Tuesday, February 2, 2010

Page 74: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

User SID

Tuesday, February 2, 2010

Page 75: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

User SID

Master key

Tuesday, February 2, 2010

Page 76: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

User SID

Master key

Cipher + Key

Tuesday, February 2, 2010

Page 77: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

User SID

Master key

Blob key

Cipher + Key

Tuesday, February 2, 2010

Page 78: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

User SID

Master key

Blob key

Salt + IV

Cipher + Key

Tuesday, February 2, 2010

Page 79: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

User SID

Master key

Additio

nal p

asswor

d

Blob key

Salt + IV

Cipher + Key

Tuesday, February 2, 2010

Page 80: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

User SID

Master key

Additio

nal p

asswor

d

Blob key

Salt + IV

Additional entropy

Cipher + Key

Tuesday, February 2, 2010

Page 81: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Did I miss something ?

• How the OS knows the current master key ?

• How the OS decides to renew the master key ?

• What happen when the user changes his password ?

Tuesday, February 2, 2010

Page 82: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Key renewal process

• Renewed every 3 months automatically

• Passive process: executed when CryptProtect called

• Hardcoded limit (location unknown)

• Possibly in psbase.dll (MS crypto provider)

• Can be reduced by using registry override

Tuesday, February 2, 2010

Page 83: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Master key selection

• All master keys are kept because Windows can’t tell if a key is still used

• Keys are stored in %APPDATA%/Microsoft/Protect/[SID]

• Current master key is specified in the Preferred file

Tuesday, February 2, 2010

Page 84: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

The Preferred file

• Simply contains :

“GUID master key” . “timestamp”

• The key is renewed when

current time > timestamp

Tuesday, February 2, 2010

Page 85: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

The Preferred file

• Simply contains :

“GUID master key” . “timestamp”

• The key is renewed when

current time > timestamp

➡Key escrow attack : Plant a key and update the Preferred file every 3 months (e.g using the task scheduler)

Tuesday, February 2, 2010

Page 86: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

User password renewal

• Master keys are re-encrypted when the password change

• Experimentally not all of them, just the last few ones

Tuesday, February 2, 2010

Page 87: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

Master key

Additio

nal p

asswor

d

Blob key

Salt + IV

Additional entropy

Cipher + Key

Tuesday, February 2, 2010

Page 88: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decrypting a blob

Data blob Master key file CREDHIST

Master key GUID

Pre key

Salt, Nb iterations

SHA1(password)

Master key

Additio

nal p

asswor

d

Blob key

Salt + IV

Additional entropy

Cipher + Key

CREDHIST GUID

Tuesday, February 2, 2010

Page 89: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST overview

SHA1(password)

Tuesday, February 2, 2010

Page 90: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST overview

Structurepass n-1 SHA1(password)

Decrypt

Tuesday, February 2, 2010

Page 91: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST overview

Structurepass n-1

Structurepass n-2

Decrypt

SHA1(password)Decrypt

Tuesday, February 2, 2010

Page 92: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST overview

Structurepass n-1

Structurepass n-2

Structurepass n- 3

Decrypt

Decrypt

SHA1(password)Decrypt

Tuesday, February 2, 2010

Page 93: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST overview

Structurepass n-1

Structurepass n-2

Structurepass n- 3

Structurepass 1

Structurepass 2

...

Decrypt

Decrypt

Decrypt

SHA1(password)Decrypt

Tuesday, February 2, 2010

Page 94: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16]

Tuesday, February 2, 2010

Page 95: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16]

Hash algo ID

Tuesday, February 2, 2010

Page 96: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16]

Nb rounds

Tuesday, February 2, 2010

Page 97: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16]

Encryption Algorithm ID

Tuesday, February 2, 2010

Page 98: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16]

User USID

Tuesday, February 2, 2010

Page 99: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16]

Computer SID

Tuesday, February 2, 2010

Page 100: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16]

Account ID

Tuesday, February 2, 2010

Page 101: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16]

Encrypted password SHA1

Tuesday, February 2, 2010

Page 102: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

CREDHIST entry structure main fields

idHashAlgo;

dwRounds;

dwCipherAlgo;

bSID[12];

dwComputerSID[3];

dwAccountID;

bData[28];

bPasswordID[16] Password GUID

Tuesday, February 2, 2010

Page 103: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Decryption algorithm overview

DecryptCredhist{

SID = (USID-ComputerID-AccountID)

tmp-key = HMAC(sha1, SID)

pre-key = PBKDF2(decryptKey, Salt, ID_ALGO, nbIteration)

3desKey = pre-key[0 - 23]

3desIV = [24 - 31]

(SHA1[0-19], HMAC[20-39]) = 3des-cbc(3desKey, iv, encKey)

Tuesday, February 2, 2010

Page 104: Decrypting DPAPI data - Black Hat Briefings

DPAPIck demo

grab a copy from http://dpapick.com

Tuesday, February 2, 2010

Page 105: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

LSA

• LSASS secret contains a DPAPI_SYSTEM value

• Length == 2 * SHA1

• Usage are unknown

• We think that 1 of them is used as a SYSTEM account “password”

• Need to be confirmed

Tuesday, February 2, 2010

Page 106: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

EFS

• Certificate private key is encrypted with DPAPI

• Key are stored in

• To read EFS file offline, we just need to import the user certificate and its private keys in our key store.

• Work in progress in DPAPIck

Tuesday, February 2, 2010

Page 107: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

What is next

• Can we build a rogue crypto provider ?

• What are the two SHA1 stored in the LSA ?

• Where is stored the renewal hard lime ?

• CryptDeriveKey needed to be reversed to have a fully portable implementation (Everything else is already portable)

Tuesday, February 2, 2010

Page 108: Decrypting DPAPI data - Black Hat Briefings

Jean-Michel Picod, Elie Bursztein http://www.dpapick.com

Conclusion

• Open the door to offline forensic

• First step toward EFS on alternative systems

• CREDHIST allows to recover previous passwords

• DPAPIck : http://dpapick.com

• Some things remain unknown

Tuesday, February 2, 2010

Page 109: Decrypting DPAPI data - Black Hat Briefings

Questions ?Thanks to the nightingale team

Tuesday, February 2, 2010