Skip to content

Commit cb7793b

Browse files
mikeryanMike Ryan
authored andcommitted
support multiple PEKs in Windows 2016
__decryptHash was throwing IndexError on Windows 2016 if a hash was encrypted with a PEK with a higher index than 0. This patch attempts to extract all keys from the PEK list. The PEK list format was reverse engineering by eyeball. YMMV.
1 parent 434c868 commit cb7793b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

impacket/examples/secretsdump.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,8 +1888,21 @@ def __getPek(self):
18881888
decryptedPekList = self.PEKLIST_PLAIN(
18891889
self.__cryptoCommon.decryptAES(self.__bootKey, encryptedPekList['EncryptedPek'],
18901890
encryptedPekList['KeyMaterial']))
1891-
self.__PEK.append(decryptedPekList['DecryptedPek'][4:][:16])
1892-
LOG.info("PEK # 0 found and decrypted: %s", hexlify(decryptedPekList['DecryptedPek'][4:][:16]).decode('utf-8'))
1891+
1892+
# PEK list entries take the form:
1893+
# index (4 byte LE int), PEK (16 byte key)
1894+
# the entries are in ascending order, and the list is terminated
1895+
# by an entry with a non-sequential index (08080808 observed)
1896+
pos, cur_index = 0, 0
1897+
while True:
1898+
pek_entry = decryptedPekList['DecryptedPek'][pos:pos+20]
1899+
if len(pek_entry) < 20: break # if list truncated, should not happen
1900+
index, pek = unpack('<L16s', pek_entry)
1901+
if index != cur_index: break # break on non-sequential index
1902+
self.__PEK.append(pek)
1903+
LOG.info("PEK # %d found and decrypted: %s", index, hexlify(pek).decode('utf-8'))
1904+
cur_index += 1
1905+
pos += 20
18931906

18941907
def __removeRC4Layer(self, cryptedHash):
18951908
md5 = hashlib.new('md5')

0 commit comments

Comments
 (0)