-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsolve.py
64 lines (43 loc) · 1.38 KB
/
solve.py
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
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
from gmpy2 import iroot
from pwn import context, log, remote, sys
from random import getrandbits, seed
from sage.all import CRT
def main():
if len(sys.argv) != 3:
log.warning(f'Usage: python3 {sys.argv[0]} <host> <port>')
exit(1)
host, port = sys.argv[1], sys.argv[2]
seeds = log.progress('Seed')
for i in range(10000000):
seeds.status(str(i))
seed(i)
if getrandbits(32) < 50:
nice_seed = i
break
if nice_seed is None:
log.warning('Could not find nice seed')
exit(1)
seeds.success(str(nice_seed))
name = bytes.fromhex(hex(nice_seed)[2:])
seed(nice_seed)
e = 2 * getrandbits(32) + 1
log.info(f'{e = }')
ns, cs = [], []
connections = log.progress('Connections')
for i in range(1000):
connections.status(str(i))
with context.local(log_level='CRITICAL'):
r = remote(host, int(port))
r.sendlineafter(b'>>> ', name)
r.recvuntil(b'n = ')
ns.append(int(r.recvline().strip().decode()))
r.recvuntil(b'c = ')
cs.append(int(r.recvline().strip().decode()))
r.close()
connections.success(str(i))
m_e = CRT(cs, ns)
m = iroot(m_e, e)
log.success(f'Flag: {bytes.fromhex(hex(m[0])[2:]).decode()}')
if __name__ == '__main__':
main()