vm_wo

Posted by Humb1e on 2023-09-04
Estimated Reading Time 4 Minutes
Words 846 In Total
Viewed Times

羊城杯——vm_wo

应该是比较简单的vm题型,由于本人太菜了,没做

image-20230904224001433

分析他的逻辑,其实是单字节加密,对于这样的题目其实爆破是一种很好的方法。

赛后看了星盟的wp发现他们也是用单字节爆破的方式来解的,其实对于这样的爆破题可以结合一下z3来使用。

本题是单字节加密其实用不用z3没多大差别,但是如果以后有前一个字节会对之后的字节产生影响,每个位置上独立是可能存在多解的情况下z3可能是一个不错的选择,本来那种题可能会用到dfs之类的算法,这里仅仅提供一种思路,vm逆向也许可以和z3结合使用。

附上结合z3的exp,加密和初始化都是照搬星盟wp的

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
import struct
from z3 import *
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]
num=[BitVec("num[%d]"%i,32) for i in range(29)]
solver=Solver()
for i in range(29):
vm_body = [0]*0x10
buf=[0]*2
out = [0]*30
vm_body[3:3+4] = 0xBEEDBEEF.to_bytes(4, byteorder="little")
a1 = 0
v2 = i+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] = num[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 i in range(29):
solver.add(out[i]==enc[i])
print(solver.check())
#for i in num:
# print(solver.model()[i],end=",")
flag=[68,65,83,67,84,70,123,121,111,117,95,97,114,101,95,114,105,103,104,116,95,115,111,95,99,111,111,108,125]
for i in flag:
print(chr(i%128),end='')#DASCTF{you_are_right_so_cool}

如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !