-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator_get_cfg.py
75 lines (62 loc) · 1.87 KB
/
validator_get_cfg.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
import sys
import pprint
import hashlib
from mlib.crypto import aes
from mlib.struct import Structure
cfg_struct_old = Structure.from_cstruct('''
typedef struct {
DWORD sample_id;
char c2_domain[260];
char param_name_cid[64];
char param_name_size[64];
char param_name_zero[128];
uint8_t comm_key_1[32];
uint8_t comm_key_2[32];
} cfg_struct;
''')
cfg_struct_new = Structure.from_cstruct('''
typedef struct {
DWORD sample_id;
char c2_domain[512];
char param_name_cid[64];
char param_name_size[64];
char param_name_zero[128];
uint8_t comm_key_1[32];
uint8_t comm_key_2[32];
} cfg_struct;
''')
blob_hdr = Structure.from_cstruct('''
typedef struct {
DWORD random;
DWORD is_compressed;
DWORD size;
DWORD size2;
DWORD padded_size;
BYTE decoded_hash[16];
DWORD unk_1[4];
BYTE data_hash[16];
DWORD unk_2[4];
} blob_hdr;;
''')
with open(sys.argv[1],'rb') as f:
d = f.read()
key = hashlib.md5(sys.argv[2]).digest()
off = d.find("\x44\x03\x00\x00\x50\x03\x00\x00")
cfg_struct = cfg_struct_new
if off == -1:
off = d.find("\x48\x02\x00\x00\x50\x02\x00\x00")
cfg_struct = cfg_struct_old
off -= 12
hdr = d[off:off+0x54]
hdr = blob_hdr.parse(hdr).as_dict()
data = d[off+0x54:off+0x54+hdr['padded_size']]
hdr['decoded_hash'] = bytearray(hdr['decoded_hash']).__str__().encode('hex')
hdr['data_hash'] = bytearray(hdr['data_hash']).__str__().encode('hex')
print('DATA HASH matches: {}'.format(hashlib.md5(data).hexdigest() == hdr['data_hash']))
cfg_data = aes.decrypt(data, key, 'cbc', None, "\x00"*16)[:hdr['size']]
cfg = cfg_struct.parse(cfg_data).as_dict()
cfg['comm_key_1'] = bytearray(cfg['comm_key_1']).__str__().encode('hex')
cfg['comm_key_2'] = bytearray(cfg['comm_key_2']).__str__().encode('hex')
print('DECODED HASH matches: {}'.format(hashlib.md5(cfg_data).hexdigest() == hdr['decoded_hash']))
pprint.pprint(hdr)
pprint.pprint(cfg)