0x00 题目分析

一个Mach-O ARM64程序

使用自制的VMP进行加密

关于VMP介绍可以看这个:https://www.52pojie.cn/thread-1564978-1-1.html

虚拟化可以看这个:https://www.cnblogs.com/theseventhson/p/14240373.html:

变异可以看这个:https://www.52pojie.cn/thread-1565126-1-1.html

0x01 解

查壳,没有结果,直接拖IDA(不能用8.3,因为是ARM64)可以发现函数很少

先看看main

非常简单,这个byte_10003F47就是密文了

加密过程应该就是那个myopearate了

写入了很多数据,看不太懂

不过这里面有个函数interpretBytecode看起来挺重要的

函数里面很长,进行了很多操作

同时使用了一个不存在的地址,应该是程序写入内存的时候才会出现

非常符合VM的定义

由于没有mac系统,做不了模拟(应该有做模拟的方法的,挖个坑先)

所以只能copy计算流程然后进行点修改来爆破了

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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import struct


def exec(cin, a2):
start = False
v2 = buf[0]
if v2 < a2:
while True:
if (start):
buf[0] += 3
v2 = buf[0]
if (buf[0] >= a2):
break
if (not start):
start = True

for m in range(0, 3):
vm_body[m] &= 0xff
v6 = cin[v2]
v7 = cin[v2+1]
v8 = cin[v2+1]
v9 = cin[v2+2]
v10 = v9

if v6 == 0:
v11 = vm_body[v8]
vm_body[v8] = vm_body[v10]
vm_body[v10] = v11
elif v6 == 1:
vm_body[v8] ^= vm_body[v9]
elif v6 == 2:
vm_body[v8] += v9
elif v6 == 3:
vm_body[v8] += vm_body[v9]
elif v6 == 4:
vm_body[v8] -= v9
elif v6 == 5:
vm_body[v8] -= vm_body[v9]
elif v6 == 6:
vm_body[v8] *= v9
elif v6 == 7:
vm_body[v8] *= vm_body[v9]
elif v6 == 8:
vm_body[v8] = vm_body[v8] / v9
elif v6 == 9:
vm_body[v8] = vm_body[v8] / vm_body[v9]
elif v6 == 10:
vm_body[v8] = vm_body[v8] % v9
elif v6 == 11:
vm_body[v8] = vm_body[v8] % vm_body[v9]

elif v6 == 12:
v12 = vm_body[v8]
vm_body[v8] = v12 << v9

elif v6 == 13:
v12 = vm_body[0]
vm_body[v8] = v12 << v9

elif v6 == 14:
v15 = vm_body[v8]
vm_body[buf[1] + 16] = v15
buf[1] += 1

elif v6 == 15:
v13 = vm_body[v8]
elif v6 == 16:
v14 = buf[1] - 1
buf[1] -= 1
v13 = vm_body[v14 + 16]
# print(v13)

elif v6 == 17:
if not vm_body[v8]:
buf[0] = v9

elif v6 == 18:
if vm_body[v8]:
buf[0] = v9

elif v6 == 19:
buf[0] = v7

elif v6 == 20:
v8 = vm_body[v8]
v15 = vm_body[v8]
vm_body[buf[1] + 16] = v15
buf[1] += 1

elif v6 == 21:
v16 = buf[1] - 1
buf[1] -= 1
vm_body[0] = vm_body[v16 + 16]

elif v6 == 22:
v15 = v7
vm_body[buf[1] + 16] = v15
buf[1] += 1

elif v6 == 23:
buf[0] -= 3

elif v6 == 24:
vm_body[0] = vm_body[2] | vm_body[1]

elif v6 == 25:
# print(vm_body[0], v9)
vm_body[v8] = vm_body[0] >> v9

elif v6 == 26:
vm_body[v8] = v9

else:
continue

buf[0] = 0
return


enc = [0xDF, 0xD5, 0xF1, 0xD1, 0xFF, 0xDB, 0xA1, 0xA5, 0x89, 0xBD, 0xE9, 0x95, 0xB3, 0x9D,
0xE9, 0xB3, 0x85, 0x99, 0x87, 0xBF, 0xE9, 0xB1, 0x89, 0xE9, 0x91, 0x89, 0x89, 0x8F, 0xAD]
alpht = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_{|}~"
flag = [0]*30
index = 0
while ((index) < 29):
for i in alpht:
vm_body = [0]*0x10
buf = [0]*2
flag[index] = ord(i)
out = [0]*30
vm_body[3:3+4] = 0xBEEDBEEF.to_bytes(4, byteorder="little")
a1 = 0
v2 = index+1
code = [0]*64
while (v2):
v2 -= 1
code[48:48+8] = 0x20D01011903001A.to_bytes(8, byteorder="little")
code[55:55+8] = 0x300010201180702.to_bytes(8, byteorder="little")
code[50] = flag[a1]
exec(code[48:], 15)
code[32:32+8] = 0x20D02011903001A.to_bytes(8, byteorder="little")
code[39:39+8] = 0x400010201180602.to_bytes(8, byteorder="little")
code[34] = vm_body[0]
exec(code[32:], 15)
code[16:16+8] = 0x20D03011903001A.to_bytes(8, byteorder="little")
code[23:23+8] = 0x500010201180502.to_bytes(8, byteorder="little")
code[18] = vm_body[0]
exec(code[16:], 15)
code[0:0+8] = 0x20D04011903001A.to_bytes(8, byteorder="little")
code[7:7+8] = 0x600010201180402.to_bytes(8, byteorder="little")
code[2] = vm_body[0]
exec(code, 15)
out[a1] = ((vm_body[0] >> 5) | (vm_body[0] << 3)) & 0xff
a1 += 1

for u in range(index, index+1):
if index >= 29:
exit(0)
if out[index] != enc[index]:
break
else:
print(chr(flag[index]), end='')
index += 1
break
else:
break
#DASCTF{you_are_right_so_cool}