-
Notifications
You must be signed in to change notification settings - Fork 6
/
decrypt_templateX.py
54 lines (41 loc) · 1.41 KB
/
decrypt_templateX.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# coding: utf-8
#-------------------------------------------------------------------------------
# Name: decrypt_templateX
# Purpose: Decrypt templateX payload used by APT-Q-27
#
# Author: Charles Lomboni
# Created: 10/08/2022
# Company: Security Joes
#-------------------------------------------------------------------------------
import argparse
import lznt1
def getargs():
parser = argparse.ArgumentParser("decrypt_templateX")
parser.add_argument("path", help="Path to encrypted file.")
return parser.parse_args()
def decryptFile(fileName):
print("[+] Reading templateX ...")
byteToModify = bytearray(open(fileName, 'rb').read())
result = bytes([])
bytesLen = len(byteToModify)
print("[+] Decrypting templateX ...")
# main logic to decrypt
for i in range(bytesLen):
result += bytes([(((byteToModify[i]) - 0x7A) & 0xFF) ^ 0x19])
print("[+] Decompressing ...")
for j in range(512, 2048):
pe_hdr = result[j:j + 2]
if pe_hdr == b'MZ':
break
bytesDecompressed = lznt1.decompress(result[j - 3:])
savedFilename = fileName + '_decrypted.dll'
print("[+] Saving file ", savedFilename)
open(savedFilename, 'wb').write(bytesDecompressed)
def main():
args = getargs()
print ("[+] Started...")
decryptFile(args.path)
print ("[+] Finished!")
pass
if __name__ == '__main__':
main()