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
| from z3 import *
checkstr=[0x7A, 0x08, 0x2E, 0xBA, 0xAD, 0xAF, 0x82, 0x8C, 0xEF, 0xD8, 0x0D, 0xF8, 0x99, 0xEB, 0x2A, 0x16, 0x05, 0x43, 0x9F, 0xC8, 0x6D, 0x0A, 0x7F, 0xBE, 0x76, 0x64, 0x2F, 0xA9, 0xAC, 0xF2, 0xC9, 0x47, 0x75, 0x75, 0xB5, 0x33] def func(src,key): des=[] v3=key[3] v4=src[3] v5=key[0] v6=src[0] v7=src[1] v8=key[1] v9=src[2] v10 = (v6+v4)*(key[0]+v3) v11=key[2] v12=v3*(v6+v7) v13=(v3+v11)*(v7-v4) v14=v4 *(v11-v5) v15=v5 * (v9+v4) des.append(v14+v10+v13-v12) des.append(v15+v14) des.append(v6*(v8-v3)+v12) des.append(v6*(v8-v3)+(v8+v5)*(v9-v6)+v10-v15) return des
key=[0x7E, 0x1F, 0x19, 0x75]
flag ="" for i in range(9): s=Solver() src=[BitVec("flag%i"%i,8) for i in range(4)] v3=key[3] v4=src[3] v5=key[0] v6=src[0] v7=src[1] v8=key[1] v9=src[2] v10 = (v6+v4)*(key[0]+v3) v11=key[2] v12=v3*(v6+v7) v13=(v3+v11)*(v7-v4) v14=v4 *(v11-v5) v15=v5 * (v9+v4) s.add(checkstr[i*4]==v14+v10+v13-v12) s.add(checkstr[i*4+1]==v6*(v8-v3)+v12) s.add(checkstr[i*4+2]==v15+v14) s.add(checkstr[i*4+3]==v6*(v8-v3)+(v8+v5)*(v9-v6)+v10-v15) if s.check() == sat: m=s.model() flag += "".join([chr(m.eval(j).as_long()) for j in src]) print(flag)
|