from pwn import * import requests import gmpy2 from bs4 import BeautifulSoup
# LCG solver deflcg(m, a, c, x=0): return (a * x + c) % m
defrlcg(m, a, c, x=0): ainv = gmpy2.invert(a, m) return ainv * (x - c) % m
defsolve_a(lcg0, lcg1, lcg2, m): a = (lcg2 - lcg1) * gmpy2.invert(lcg1 - lcg0, m) % m return a
defsolve_c(lcg0, lcg1, m, a): c = (lcg1 - a * lcg0) % m return c
session = requests.session()
defmain(): # Get lcg values original io=remote('129.226.4.186',7000) e=io.recvuntil("please enter num:") io.sendline("1") lcg_0 = int(io.recvline("\n")) e=io.recvuntil("please enter num:") io.sendline("1") lcg_1 = int(io.recvline("\n"))
e=io.recvuntil("please enter num:") io.sendline("1") lcg_2 = int(io.recvline("\n"))
e=io.recvuntil("please enter num:") io.sendline("1") lcg_3 = int(io.recvline("\n"))
# Find the mod value modulus = -1 for mod_value inreversed(range(9999, 2**17)): try: a = solve_a(lcg_0, lcg_1, lcg_2, mod_value) c = solve_c(lcg_0, lcg_1, mod_value, a) next = lcg(mod_value, a, c, lcg_2)
# Now we have all the parameters print('>> mod:') print(mod_value) print('>> a:') print(a) print('>> c:') print(c) for i inrange(32): m=str((a*lcg_3+c)%mod_value) print(m) lcg_3=int(m) io.sendline(m) s=io.recv(2048) print(s) if i==31: print(s) break