from Crypto.Util.number import * from pwn import * from tqdm import * from hashlib import sha256
defproof_of_work(): table = string.digits + string.ascii_letters temp = r.recvuntil(b"sha256(XXXX+") temp = r.recvline() suffix = temp[:16].decode() hex1 = temp[20:].strip().decode() for i in tqdm(table): for j in table: for k in table: for m in table: temp1 = i+j+k+m if(sha256((temp1+suffix).encode()).hexdigest() == hex1): r.sendline(temp1.encode()) return
defnext(x): x = int((x ** 2) // (10 ** (s // 2))) % n high = (int(hashlib.sha256(str(x).encode()).hexdigest(),16) >> 16) & (2 ** 16 - 1) low = x & (2 ** 16 - 1) result = high << 16 | low return (x,result)
while(1): r = remote("node5.anna.nssctf.cn", 28469) proof_of_work()
#guess #part1 get_first_result r.recvuntil(b"guess : ") r.sendline(b"1") r.recvuntil(b"number is ") result = int(r.recvline().strip().decode()) x = result n = 10000000000 s = 4 hash = x >> 16 for i inrange(n // (2**16)): temp = i*(2**16) + (x & (2**16-1)) high = (int(sha256(str(temp).encode()).hexdigest(),16) >> 16) & (2 ** 16 - 1) if(high == hash): x = temp
#part2 get_subsequent_result right = 1 for i inrange(20): x,result = next(x) r.sendline(str(result).encode()) temp = r.recvline() if(b"Success!"notin temp): right = 0 if(right == 1): print(r.recvline()) exit() else: r.close()