前言:这里简单记录下,z3的利用技巧,所以这里采用强网杯的一道题,z3很强大,。摸
int show()
{
unsigned __int64 v1; // [rsp+8h] [rbp-8h]
puts("index:");
v1 = sub_BEF();
if ( v1 > 0x10 || !*((_QWORD *)&chunk + 2 * v1) || !qword_202068[2 * v1] )
{
puts("error");
exit(0);
}
show_encrypto(**((_DWORD **)&chunk + 2 * v1));
show_encrypto(*(_DWORD *)(*((_QWORD *)&chunk + 2 * v1) + 4LL));
return puts("done");
}
show_encrypto:
int __fastcall sub_FCC(unsigned int a1)
{
int i; // [rsp+1Ch] [rbp-4h]
for ( i = 2; i > 0; --i ) // 2
a1 ^= (32 * a1) ^ ((a1 ^ (32 * a1)) >> 17) ^ (((32 * a1) ^ a1 ^ ((a1 ^ (32 * a1)) >> 17)) << 13);
return printf("%lx\n", a1);
}
我们这里利用z3解出这个方程
z3.py:
def decode(data):
solver = Solver()
a1 = BitVec('a1', 32)
t = a1
for i in range(2):
a1 ^= (32 * a1) ^ (LShR((a1 ^ (32 * a1)), 17)) ^ (((32 * a1) ^ a1 ^ (LShR((a1 ^ (32 * a1)), 17))) << 13)
solver.add(a1 == data) //进行比对
solver.check()
ans = solver.model()
return p32(solver.model()[t].as_long())
def show(idx):
choice(4)
sh.sendlineafter("index:\n", str(idx))
t1 = sh.recvuntil('\n', drop=True)
t2 = sh.recvuntil('\n', drop=True)
a1 = decode(int(t1, 16))
a2 = decode(int(t2, 16))
return a1 + a2
总结:很多题目用z3去解决问题都能够快速的解决,这里简单的记录下。