-
Notifications
You must be signed in to change notification settings - Fork 0
/
MalwareTech-vm1.py
121 lines (112 loc) · 6.33 KB
/
MalwareTech-vm1.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#MalwareTech Challenge: vm1 (solver)
#link: https://www.malwaretech.com/vm1
#-- sad0p
#Thanks to Duchy (@DuchyRE) for catching xor instruction bug
def vm():
OP_1 = 0x01
OP_2 = 0x02
OP_3 = 0x03
ram = bytearray(
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0xDE, 0x7E, 0x7D, 0x55, 0x1E, 0x05, 0xE6, 0x9F, \
0xE4, 0xA6, 0x47, 0x50, 0x02, 0x01, 0xC7, 0xFC, 0xCB, 0x60, \
0x09, 0xC6, 0x0E, 0x2E, 0x41, 0x65, 0xA4, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00])
bytecode = bytearray(
[0x01, 0x1D, 0xBD, 0x01, 0x05, 0x53, 0x01, 0x12, 0x48, 0x01,\
0x10, 0xE6, 0x01, 0x13, 0x8A, 0x01, 0x0D, 0x47, 0x01, 0x16, \
0x13, 0x01, 0x0A, 0x15, 0x01, 0x00, 0x98, 0x01, 0x02, 0x3C, \
0x01, 0x18, 0xD9, 0x01, 0x1A, 0x57, 0x01, 0x06, 0xAB, 0x01, \
0x1B, 0xC6, 0x01, 0x01, 0x32, 0x01, 0x17, 0x20, 0x01, 0x15, \
0x6F, 0x01, 0x11, 0x2D, 0x01, 0x08, 0xC9, 0x01, 0x09, 0xE7, \
0x01, 0x03, 0x12, 0x01, 0x0C, 0x2F, 0x01, 0x0E, 0x88, 0x01, \
0x19, 0x6C, 0x01, 0x04, 0x65, 0x01, 0x1E, 0xAE, 0x01, 0x14, \
0x59, 0x01, 0x1F, 0x91, 0x01, 0x1C, 0x5D, 0x01, 0x0F, 0xAE, \
0x01, 0x0B, 0x15, 0x01, 0x07, 0xCC, 0x02, 0x20, 0x00, 0x03, \
0x00, 0x00, 0x02, 0x21, 0x00, 0x03, 0x01, 0x00, 0x02, 0x22, \
0x00, 0x03, 0x02, 0x00, 0x02, 0x23, 0x00, 0x03, 0x03, 0x00, \
0x02, 0x24, 0x00, 0x03, 0x04, 0x00, 0x02, 0x25, 0x00, 0x03, \
0x05, 0x00, 0x02, 0x26, 0x00, 0x03, 0x06, 0x00, 0x02, 0x27, \
0x00, 0x03, 0x07, 0x00, 0x02, 0x28, 0x00, 0x03, 0x08, 0x00, \
0x02, 0x29, 0x00, 0x03, 0x09, 0x00, 0x02, 0x2A, 0x00, 0x03, \
0x0A, 0x00, 0x02, 0x2B, 0x00, 0x03, 0x0B, 0x00, 0x02, 0x2C, \
0x00, 0x03, 0x0C, 0x00, 0x02, 0x2D, 0x00, 0x03, 0x0D, 0x00, \
0x02, 0x2E, 0x00, 0x03, 0x0E, 0x00, 0x02, 0x2F, 0x00, 0x03, \
0x0F, 0x00, 0x02, 0x30, 0x00, 0x03, 0x10, 0x00, 0x02, 0x31, \
0x00, 0x03, 0x11, 0x00, 0x02, 0x32, 0x00, 0x03, 0x12, 0x00, \
0x02, 0x33, 0x00, 0x03, 0x13, 0x00, 0x02, 0x34, 0x00, 0x03, \
0x14, 0x00, 0x02, 0x35, 0x00, 0x03, 0x15, 0x00, 0x02, 0x36, \
0x00, 0x03, 0x16, 0x00, 0x02, 0x37, 0x00, 0x03, 0x17, 0x00, \
0x02, 0x38, 0x00, 0x03, 0x18, 0x00, 0x01, 0x19, 0x00, 0x04, \
0x00, 0x00, 0x00])
current_instruction = 0
operand_1 = b'\x00'
operand_2 = b'\x00'
global_byte = 0
while(True):
inst = bytecode[current_instruction]
operand_1 = bytecode[current_instruction + 1]
operand_2 = bytecode[current_instruction + 2]
print(f'Instruction: {hex(inst)}')
print(f'operand_1: {hex(operand_1)}')
print(f'operand_2: {hex(operand_2)}')
# f'global_byte: {hex(global_byte)}')
#mov operand_1, operand_2
if inst == OP_1:
print(
f'(before) mov ram[{hex(operand_1)}], {hex(operand_2)} ; ram[{hex(operand_1)}] = {hex(ram[operand_1])}')
ram[operand_1] = operand_2
print(
f'(after) mov ram[{hex(operand_1)}], {hex(operand_2)} ; ram[{hex(operand_1)}] = {hex(ram[operand_1])}')
#mov global_byte, ram[operand_1]
elif inst == OP_2:
vglobal_byte = hex(int(global_byte))
print(
f'(before) mov global_byte, ram[operand_1] ; global_byte = {vglobal_byte} ram[operand1]= {hex(ram[operand_1])};')
global_byte = ram[operand_1]
vglobal_byte = hex(int(global_byte))
print(
f'(after) mov global_byte, ram[operand_1] ; global_byte = {vglobal_byte} ram[operand1]= {hex(ram[operand_1])};')
#xor operand_1, global_byte
elif inst == OP_3:
vglobal_byte = hex(int(global_byte))
print(
f'(before) xor ram[operand_1], global_byte; ram[operand_1] = {hex(ram[operand_1])} global_byte = {vglobal_byte}')
ram[operand_1] = ram[operand_1] ^ global_byte #mistake: operand_1 ^ global_byte
vglobal_byte = hex(int(global_byte))
print(
f'(after) xor ram[operand_1], global_byte; ram[operand_1] = {hex(ram[operand_1])} global_byte = {vglobal_byte}')
else:
break
current_instruction = current_instruction + 3
print('-' * 20)
return ram
def main():
flag = vm()
for c in flag:
if c == 0x00:
break
print(chr(c), end='')
if __name__ == '__main__':
main()