能力值:
( LV12,RANK:407 )
|
-
-
2 楼
Part 0xC: res = func(s) 这个func是如何关联到程序的?
|
能力值:
( LV12,RANK:207 )
|
-
-
3 楼
htg
Part 0xC:
res = func(s)
这个func是如何关联到程序的?
import os
import itertools
def func(s):
# Part 0x0
v70 = 0
v4 = len(s)
v5 = 0
v71 = v4
v6 = v4
v72 = 0
if v4 != 0:
v7 = s
for i in range(v6):
v5 = ord(v7[i]) ^ v5
v5 = v5 & 0xFF
v8 = 8
for j in range(8):
v9 = 2 * v5
v9 = v9 & 0xFF
v10 = v9 ^ 7
if v9 < 0x80:
v10 = v9
v5 = v10
v4 = v71
v72 = v10
print('Part 0x0 Calculate v72 For Part 0x4: ', hex(v72))
# Part 0x1
list_5B20 = sub_40106C()
for x in list_5B20:
#print(hex(x))
pass
# Part 0x2
v11 = 0xFFFFFFFF
for i in range(v4):
tmp = list_5B20[0xFF & (v11 ^ ord(s[i]))]
if v11 >= 0x80000000:
v11 = ((v11 >> 8) | 0xFF000000) ^ tmp
else:
v11 = (v11 >> 8) ^ tmp
v67 = v11 ^ 0xFFFFFFFF
print('Part 0x2, This Value Should Be 0xF52E0765: ', hex(v67))
if v67 == 0xf52e0765:
return 1
# Part 0x3
s = sub_4010B7(s, v4)
print('Part 0x3 Manipulat Original String, Used For Xor: ', s)
# Part 0x4
v13 = v72
v69 = 1
v14 = v72 + 1
v66 = []
while(v13 < v14):
if v13 > 0x80:
v15 = 0xFFFFFF00 | v13
for j in range(200):
if (v15 & 1) != 0:
v15_abs = 0xFFFFFFFF - v15 + 1
v15_abs = 3 * v15_abs - 1
v15 = 0xFFFFFFFF - (v15_abs - 1)
else:
if v15 > 0x80000000:
v15 = (v15 >> 1) | 0x80000000
else:
v15 = v15 >> 1
v66.append(hex(v15))
#print(j, ' ', hex(v15))
else:
v15 = v13 & 0xFF
for j in range(200):
if (v15 & 1) != 0:
v15 = 3 * v15 + 1
else:
if v15 > 0x80000000:
v15 = (v15 >> 1) | 0x80000000
else:
v15 = v15 >> 1
v66.append((v15))
#print(j, ' ', hex(v15))
v13 = v13 + 1
# Part 0x5
if v72 < 0x80:
print('Part 0x5, Calculate With Or: ', (v66[195]), (v66[196]), (v66[197]))
v17 = (v66[195]) | (v66[196]) | (v66[197])
v18 = v71
cmp_a = (s[0])^(s[1])^(s[2])
print('Part 0x5, Or Result: ', hex(v17))
print('Part 0x5, Xor Result: ', hex(cmp_a))
else:
print('Part 0x5, Calculate With Or: ', hex(int(v66[195], 16)), hex(int(v66[196], 16)), hex(int(v66[197], 16)))
v17 = int(v66[195], 16) | int(v66[196], 16) | int(v66[197], 16)
v18 = v71
cmp_a = (s[0])^(s[1])^(s[2])
print('Part 0x5, Or Result: ', hex(v17))
print('Part 0x5, Xor Result: ', hex(cmp_a))
# Part 0x6
v19 = v17 + 2
v20 = v18 - v19 - 7
print('Part 0x6, This Value Should Be Less Than Or Equal 0: ' , v20)
# Part 0x7 ['007KCTF' can pass here]
print('Part 0x7, s[3] should be 0x14/20: ', s[3])
print('Part 0x7, s[4] should be 0xC/12: ', s[4])
print('Part 0x7, s[5] should be 0x1D/29: ', s[5])
print('Part 0x7, s[5] should be 0xF/15: ', s[6])
# Part 0x8
# v69 = 1, define in Part 0x4
# v74[0] == s[6]
# v74[1] ~ v74[
# v19, Rest Length Of String
# v70 = 0, define in Part 0x0
v74 = s[6:]
print('Part 0x8, Rest Length Of String: ', v19)
v21 = 0
v71 = 0
if v19 > 0:
v22 = 1
for i in range(v19):
v23 = v74[v22] + 10 * v70
print('Part 0x8, (' ,v23, '=', v74[v22], '+', '10 *', v70, ')%', v69, '==', v23%v69)
v24 = v23 - 0x37373737
if v23 <= 0x4B435445:
v24 = v23
v70 = v24
if (v24 % v69):
print('Failed! ')
return 0
#break
v69 = v69 + 1
v22 = v69
# Part 0x9 Just A Sort
v25 = v19 - 1
if (v19 - 1) > 0:
v26 = v19 - 1
for i in range(v26):
v27 = 0
if v25 > 0:
for i in range(v25):
v28 = v74[v27 + 1]
v29 = v74[v27 + 2]
if v28 > v29:
v74[v27 + 1] = v29
v74[v27 + 2] = v28
v27 = v27 + 1
v25 = v25 - 1
print('Part 0x9, Last 9 Elements After Sort: ', v74[1:])
# Part 0xA
a_str = '1234567890_ABCDEFGHIJKLMNOPQRSTUVWXYZ'
a_str = sub_4010B7(a_str, v19)
print('Part 0xA, a_str: ', a_str)
v30 = 0
if v19 > 0:
for i in range(v19):
print('Part 0xA, Compare 2: ', a_str[v30], v74[v30+1])
if a_str[v30] != v74[v30+1]:
print('Failed!')
return 0
v30 = v30 + 1
return 0
def sub_4010B7(s, length):
res = []
for i in range(length):
v4 = ord(s[i])
v5 = 48
if v4 >= 58:
v5 = 55
res.append((v4 - v5) & 0xFF)
#res.append(chr((v4 - v5) & 0xFF))
#print(''.join(res))
return res
def sub_40106C():
v1 = []
for i in range(1024):
v2 = i
v3 = 8
for j in range(8):
if (v2 & 1) != 0:
tmp = 0xEDB88320
else:
tmp = 0
if v2 >= 0x80000000:
v2 = ((v2 >> 1) | 0x80000000) ^ tmp
else:
v2 = (v2 >> 1) ^ tmp
#print(hex(v2))
v1.append(v2)
v1.append(1)
return v1
if __name__ == '__main__':
#s = 'A7AKCTF381654729'
#res = func(s)
'''
# Fuzz One For Last 9 Bytes
prefix = 'A7AKCTF'
maybe_result = []
example = '123456789'
result = itertools.permutations(example)
for x in result:
suffix = ''.join(x)
s = prefix + suffix
#print(s)
res = func(s)
if res == 1:
print(res, s)
break
print(maybe_result)
'''
'''
# Fuzz Two For First 3 Bytes
suffix = 'KCTF381654729'
text = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVMXYZ'
result = itertools.permutations(text, 3)
for x in result:
prefix = ''.join(x)
s = prefix + suffix
#print(s)
res = func(s)
if res == 1:
print(res, s)
break
'''
|
能力值:
( LV12,RANK:207 )
|
-
-
4 楼
htg
Part 0xC:
res = func(s)
这个func是如何关联到程序的?
定义了一个func,然后在main中去调用,代码写的比较呆,但恰好可以解出答案,两次fuzz都是单独去执行的。我在fuzz后9位的时候将func的返回值设置为1;fuzz前3位的时候,把Part 0x3~0xA都注释掉,然后将返回值设置为0
|
能力值:
( LV12,RANK:407 )
|
-
-
5 楼
|