NSSCTF_Crypto_[NSSCTF 2022 Spring Recruit]automatic
我引用之前博客园里的共模攻击脚本:
import imp from pwn import * import gmpy2 import binascii import rsa import math from Crypto.Util import number p=remote('112.124.34.157',12000)//远程连接 for i in range(778): def exgcd(m, n, x, y): if n == 0: x = 1 y = 0 return (m, x, y) a1 = b = 1 a = b1 = 0 c = m d = n q = int(c / d) r = c % d while r: c = d d = r t = a1 a1 = a a = t - q * a t = b1 b1 = b b = t - q * b q = int(c / d) r = c % d x = a y = b return (d, x, y)#扩展欧几里得算法 p.recvuntil("n=")//读行直到n= n=int(p.recvline().strip().decode())//然后读取那一行,一下雷同 p.recvuntil("e1=") e1=int(p.recvline().strip().decode()) p.recvuntil("e2=") e2=int(p.recvline().strip().decode()) p.recvuntil("c1=") c1=int(p.recvline().strip().decode()) p.recvuntil("c2=") c2=int(p.recvline().strip().decode()) ans=exgcd(e1,e2,0,0) s1=ans[1] s2=ans[2] m=(gmpy2.powmod(c1,s1,n)*gmpy2.powmod(c2,s2,n))%n p.sendlineafter("[+] Plz Tell Me proof :",number.long_to_bytes(m))//在指定字符串之后上传数据 print(i) p.recvuntil("You get flag!") print(p.recvlines(2))
跑出来flag:
NSSCTF{nice_try}