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
| from pwn import * from time import * from Crypto.Util.number import * import gmpy2
def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y
def function1(e1, e2, n, c1, c2): s = egcd(e1, e2) s1 = s[1] s2 = s[2] if s1 < 0: s1 = - s1 c1 = gmpy2.invert(c1, n) elif s2 < 0: s2 = - s2 c2 = gmpy2.invert(c2, n)
m = pow(c1, s1, n) * pow(c2, s2, n) % n flagg = long_to_bytes(int(m)) return flagg
p = remote("node4.anna.nssctf.cn", 28831)
def attack(): p.recvuntil('py?\n')
n = int(p.recvline().decode().split('=')[-1][:-1]) e1 = int(p.recvline().decode().split('=')[-1][:-1]) e2 = int(p.recvline().decode().split('=')[-1][:-1]) c1 = int(p.recvline().decode().split('=')[-1][:-1]) c2 = int(p.recvline().decode().split('=')[-1][:-1])
print('[n]: ', n) print('[e1]: ', e1) print('[e2]: ', e2) print('[c1]: ', c1) print('[c2]: ', c2)
data = function1(e1, e2, n, c1, c2) p.sendlineafter('Pl Give Me flaag :', data)
for i in range(666): sleep(0.1) attack() print('[time]: ', i)
p.interactive()
|