re -24 buuctf [GXYCTF2019]simple CPP

[GXYCTF2019]simple CPP
前话:遇到复杂的代码别慌,开着动态调试,编写注释便往下步过,总会结束
hint:flag中间有一段乱码,因为构建的Z3表达式有多组解,乱码应为e!P0or_a

ida打开,代码很长
re -24 buuctf [GXYCTF2019]simple CPP
re -24 buuctf [GXYCTF2019]simple CPP
re -24 buuctf [GXYCTF2019]simple CPP
re -24 buuctf [GXYCTF2019]simple CPP
在此之上的代码,就是输入的字符串与一组字符串异或后,每8个字节一赋值给4个变量v16,v15,v14,v13。
re -24 buuctf [GXYCTF2019]simple CPP
将这一步每个式子都用变量v16,v15,v14,v13构建等式。最终会得到5个等式。

s.add((v14 & ~v16) == 0x11204161012)
s.add((v14 & (~v15)) & v16 | v14 & ((v15 & v16) | v15 & ~v16 | ~(v15 | v16)) == 0x8020717153E3013)
s.add((((v14 & ~v16) |(v15 & v16) | (v14 & (~v15)) | (v16 & (~v15))) ^ v13) == 0x3E3A4717050F791F)
s.add(((v14 & ~v16) | (v15 & v16) | v15 & v14) == (~v16 & v14 | 0xC00020130082C0C) )
s.add((((v14 & ~v16) |(v15 & v16) | (v14 & (~v15)) | (v16 & (~v15)) == 0x3E3A4717373E7F1F)))

写脚本跑出四个变量的值

from z3 import *

v14,v15,v16,v13=BitVecs('v14 v15 v16 v17',64)

s=Solver()

s.add((v14 & ~v16) == 0x11204161012)
s.add((v14 & (~v15)) & v16 | v14 & ((v15 & v16) | v15 & ~v16 | ~(v15 | v16)) == 0x8020717153E3013)
s.add((((v14 & ~v16) |(v15 & v16) | (v14 & (~v15)) | (v16 & (~v15))) ^ v13) == 0x3E3A4717050F791F)
s.add(((v14 & ~v16) | (v15 & v16) | v15 & v14) == (~v16 & v14 | 0xC00020130082C0C) )
s.add((((v14 & ~v16) |(v15 & v16) | (v14 & (~v15)) | (v16 & (~v15)) == 0x3E3A4717373E7F1F)))

s.check()
m = s.model()
for i in m:
    print("%s = 0x%x"%(i,m[i].as_long()))

re -24 buuctf [GXYCTF2019]simple CPP

如此就已经拿出该步异或后得到的字符串
下一步寻找qword_140006048内容
通过交叉引用发现
re -24 buuctf [GXYCTF2019]simple CPP
得到i_will_check_is_debug_or_not
编写解密脚本

b = 'i_will_check_is_debug_or_not'

a = [0x3E,0x3A,0x46,0x05,0x33,0x28,0x6F,0x0D,0x8C,0x00,0x8A,0x09,0x78,0x49,0x2C,0xAC,0x08,0x02,0x07,0x17,0x15,0x3E,0x30,0x13,0x32,0x31,0x06]

flag = ''

for i in range(len(a)):
    flag += chr(a[i] ^ ord(b[i]))
print(flag)

得到
re -24 buuctf [GXYCTF2019]simple CPP
将中间一节乱码替换为e!P0or_a即得到flag

上一篇:[HCTF 2018]WarmUp_BUUCTF


下一篇:BUUCTF—misc—面具下的flag