-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcyax-extra.py
81 lines (43 loc) · 1.63 KB
/
cyax-extra.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import argparse
def unscramble(data):
"""Decrypt data with an embedded key."""
key = data[:16]
data = data[16:]
decrypted = []
for i in range(len(data)):
decrypted.append(data[i] ^ key[i % 16])
return decrypted
def xor_dec(data, key):
"""Decrypt data with an external key."""
klen = len(key)
num2 = data[-1] ^ 112
decrypted = []
for i in range(len(data)):
decrypted.append(data[i] ^ num2 ^ key[i % int(klen / 2)])
return decrypted
def to_big_endian_unicode(data):
"""Emulate a call Encoding.BigEndianUnicode.GetBytes()."""
big = []
for d in data:
big.append(0)
big.append(ord(d))
return big
if __name__ == '__main__':
"""Point d'entrée du programme."""
parser = argparse.ArgumentParser(description='Python translation of the Extra class features', add_help=False)
parser.add_argument('-h', '--help', action='store_true', help='Display the command line options')
parser.add_argument('resource', help='Resource file to process', type=str)
parser.add_argument('--key', type=str, help='Key to use for XOR decryption', required=False)
args = parser.parse_args()
with open(args.resource, 'rb') as fd:
data = fd.read()
if args.key:
print('[*] Decrypting %s' % args.resource)
master_key = to_big_endian_unicode(args.key)
data = xor_dec(data, master_key)
print('[*] Unscrambling %s' % args.resource)
data = unscramble(data)
output = args.resource + '.plain'
print('[*] Writing %s...' % output)
with open(output, 'wb') as fd:
fd.write(bytes(data))