# key爆破 cip = '89b8aca257ee2748f030e7f6599cbe0cbb5db25db6d3990d3b752eda9689e30fa2b03ee748e0da3c989da2bba657b912' cp = [cip[i:i+16] for i inrange(0,len(cip),16)]
flag = b'ByteCTF{' last = bytes_to_long(flag) ^ int(cp[0],16)
for i inrange(-32, 33): for j inrange(-32, 33): for k inrange(-32, 33): for l inrange(-32, 33): last = bytes_to_long(flag) ^ int(cp[0],16) keys = [i,j,k,l] try: m1,last = decry_ofb(int(cp[1],16),keys,last) M = m1.decode('ASCII') m2,last = decry_ofb(int(cp[2],16),keys,last) M = M + m2.decode('ASCII') if check(M): print(M,keys) except: pass # [-12, 26, -3, -31] key = [-12, 26, -3, -31] IV = 16476971533267772345
S = z3.Solver() x = z3.BitVec('x',65) S.add(convert(x,key) == int(cp[5],16)) if S.check(): print(S.model())
# 连接用脚本 import pwn from gmpy2 import invert from random import randint p = 62606792596600834911820789765744078048692259104005438531455193685836606544743 g = 5
con = pwn.remote('39.105.38.192',30000) resp = con.recvuntil("$ ").decode() con.sendline('1'.encode()) resp = con.recvuntil("$ ").decode() Alice = int(resp.split('\n')[0])
con.sendline('2'.encode()) resp = con.recvuntil("$ ").decode() Bob = int(resp.split('\n')[0])
import pwn from hashlib import sha256 import codecs from time import sleep
defproof(END, HASH): table = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' for i in table: for j in table: for k in table: for l in table: STR = i + j + k + l + END if sha256(STR.encode()).hexdigest() == HASH: print(i + j + k + l) return i + j + k + l
pt = b"Hello, I'm a Bytedancer. Please give me the flag!" con = pwn.remote('39.105.181.182', 30001) resp = con.recvuntil('> ').decode().split('\n')[-2] END = resp[12:40] HASH = resp[45:] con.sendline(proof(END,HASH).encode()) resp = con.recvuntil('> ').decode() con.sendline(('0' * 1024).encode()) resp = con.recvuntil('> ').decode() tmp = int(resp.split('\n')[1][32:34], 16) END = hex(tmp ^ 1)[2:].ljust(2, '0') DATA = ['0'] * 1022 + [END[0] , END[1]] roundnum = '' TABLE = [50,250,450] for i inrange(49): sleep(1) idx = TABLE[i % 3] roundnum += hex(tmp ^ pt[i])[2:].rjust(2,'0') for j inrange(len(roundnum)): DATA[idx + j] = roundnum[j] con.sendline((''.join(DATA)).encode()) resp = con.recvuntil('> ').decode() print(i,roundnum.zfill(98)) tmp = int(resp.split('\n')[1][TABLE[i%3]+2*i + 2:TABLE[i%3]+2+2*i + 2],16)