@@ -281,7 +281,7 @@ def mscrypt_derive_key_sha1(secret:bytes):
281
281
digest2 .update (buf2 )
282
282
hash2 = digest2 .finalize ()
283
283
284
- derived_key = hash1 + hash2 [: 4 ]
284
+ derived_key = hash1 + hash2
285
285
return derived_key
286
286
287
287
def deobfuscate_secret_policy_blob (output ):
@@ -292,12 +292,20 @@ def deobfuscate_secret_policy_blob(output):
292
292
buffer = output [64 :64 + data_length ]
293
293
294
294
key = mscrypt_derive_key_sha1 (output [4 :4 + 0x28 ])
295
- iv = bytes ([0 ] * 8 )
296
- cipher = Cipher (algorithms .TripleDES (key ), modes .CBC (iv ), backend = default_backend ())
295
+ blob_prefix = output [:2 ]
296
+
297
+ if blob_prefix == b'\x89 \x13 ' :
298
+ block_cipher_algorithm = algorithms .TripleDES (key [:24 ])
299
+ elif blob_prefix == b'\x8a \x13 ' :
300
+ block_cipher_algorithm = algorithms .AES256 (key [:32 ])
301
+
302
+ iv = bytes ([0 ] * (block_cipher_algorithm .block_size // 8 ))
303
+ cipher = Cipher (block_cipher_algorithm , modes .CBC (iv ), backend = default_backend ())
304
+
297
305
decryptor = cipher .decryptor ()
298
306
decrypted_data = decryptor .update (buffer ) + decryptor .finalize ()
299
307
300
- padder = padding .PKCS7 (64 ).unpadder () # 64 is the block size in bits for DES3
308
+ padder = padding .PKCS7 (block_cipher_algorithm . block_size ).unpadder ()
301
309
decrypted_data = padder .update (decrypted_data ) + padder .finalize ()
302
310
303
311
try :
@@ -545,7 +553,22 @@ def secret_policy_process(self, policyID, policy, private_key, client_guid, loot
545
553
546
554
LOG .debug (f"Found { len (blobs_set .keys ())} obfuscated blob(s) in secret policy." )
547
555
for i , blob_name in enumerate (blobs_set .keys ()):
548
- data = deobfuscate_secret_policy_blob (blobs_set [blob_name ])
556
+ blob_prefix = bytes .fromhex (blobs_set [blob_name ])[:2 ]
557
+ if blob_prefix in (b'\x89 \x13 ' , b'\x8a \x13 ' ):
558
+ data = deobfuscate_secret_policy_blob (blobs_set [blob_name ])
559
+ else :
560
+ LOG .debug (f"Unable to decrypt obfuscated blob due to unknown blob type with prefix '{ blob_prefix .hex ()} '." )
561
+ continue
562
+
563
+ # Attempt to pretty-print decrypted XML task sequence blobs prior to file write.
564
+ if blob_name == "TS_Sequence" :
565
+ try :
566
+ blobroot = ET .fromstring (clean_junk_in_XML (data ))
567
+ ET .indent (blobroot )
568
+ data = ET .tostring (blobroot , encoding = "unicode" )
569
+ except :
570
+ pass
571
+
549
572
filename = f'{ loot_dir } /{ policyID } /secretBlob_{ str (i + 1 )} -{ blob_name } .txt'
550
573
with open (filename , 'w' ) as f :
551
574
f .write (f"Secret property name: { blob_name } \n \n " )
0 commit comments