@app.route('/public/<path:name>') defreadbook(name): name = str(name) for i in DISALLOWED1: if i in name: return"banned!" for j in DISALLOWED_FILES: if j in name: return"banned!" for k in BLACKLIST: if k in name: return"banned!" print(name) try: res = os.popen('cat {}'.format(name)).read() return res except: return"error"
@app.route('/list/<path:name>') deflistbook(name): name = str(name) for i in DISALLOWED1: if i in name: return"banned!" for j in DISALLOWED_FILES: if j in name: return"banned!" for k in BLACKLIST: if k in name: return"banned!" print(name) cmd = 'ls {}'.format(name) try: res = os.popen(cmd).read() return res except: return"error"
if __name__ == '__main__': app.run(host='0.0.0.0',port=8878)
from Crypto.Util.number import * from secret import flag
deffakeN_list(): puzzle_list = []
for i inrange(15): r = getPrime(32) puzzle_list.append(r)
p = getPrime(32) q = getPrime(32) com = p*q
puzzle_list.append(com)
return puzzle_list
defencrypt(m,e,fake_n_list):
fake_n = 1 for i inrange(len(fake_n_list)): fake_n *= fake_n_list[i]
really_n = 1 for i inrange(len(fake_n_list)-1): really_n *= fake_n_list[i]
c = pow(m,e,really_n)
print("c =",c) print("fake_n =",fake_n)
if __name__ == '__main__': m = bytes_to_long(flag) e = 65537 fake_n_list = fakeN_list() encrypt(m,e,fake_n_list)
''' c = 6451324417011540096371899193595274967584961629958072589442231753539333785715373417620914700292158431998640787575661170945478654203892533418902 fake_n = 178981104694777551556050210788105224912858808489844293395656882292972328450647023459180992923023126555636398409062602947287270007964052060975137318172446309766581 '''
先用yafu分解fake_n,然后一个一个试即可。
脚本:
import gmpy2 from Crypto.Util.number import long_to_bytes
defdecode(c,e,phi,n): d = gmpy2.invert(e, phi) m = pow(c, d, n) flag = long_to_bytes(m) return flag
e = 65537 c=6451324417011540096371899193595274967584961629958072589442231753539333785715373417620914700292158431998640787575661170945478654203892533418902
N = [3429664037,2290486867,2333428577,3417707929,4098704749,3278987191,3965529989,3716624207,4267348123,2507934301,2215221821,3389689241,2446301969,2590663067,3107210929,2361589081,3859354699]
phi = 1 n = 1
for i in N: n *= i phi = (i-1)*phi flag = decode(c,e,phi,n) ifb"flag"in flag orb"begin"in flag: print(flag) break # b'begin{y0u_f1nd_th3_re4l_n}'
PAD
源码:
import random, math
from Crypto.Util.number import * from flag import flag flag=flag[:64] assertlen(flag) == 64
classRSA(): def__init__(self, m: int): self.p, self.q, self.e, self.m = getPrime(512), getPrime(512), getRandomRange(1,8), m self.n = self.p * self.q defPublickey(self): return (self.n, self.e,self.c) defEncrypt(self): pad = PAD(m=self.m, e=0) pad.PAD() self.c = (pad.e,pow(pad.M, self.e, self.n)) classPAD(): def__init__(self, m: int, e): self.e, self.m, self.mbits = e, m, m.bit_length() if e == 0: self.e = getRandomRange(2, 7) defPAD(self): self.M = pow(self.e, self.mbits) + pow(self.m, self.e) GIFT = bytes_to_long(flag) withopen("GIFT.txt", "w") as f: for i inrange(40): rsa = RSA(m=GIFT) rsa.Encrypt() f.write(str(rsa.Publickey()) + "\n")
m = 26557762379124264922132214420209728936796452559751033517820166259647971200493029434772959145551662395540203237914969022639479368547265045300822940244603592956901947131088363115332681941180989239355596363143445708865429254462912210194997411474244175252940834791770566886483490068164580622099300335891131365129
n = 7709388356791362098686964537734555579863438117190798798028727762878684782880904322549856912344789781854618283939002621383390230228555920884200579836394161 c = 5573755468949553624452023926839820294500672937008992680281196534187840615851844091682946567434189657243627735469507175898662317628420037437385814152733456
e = 2
k = 0 while1: res = gmpy2.iroot(k*n+c,e) if(res[1] == True): print(bytes.fromhex(hex(res[0])[2:])) break k += 1 # b'begin{quadr4ticresidue_i5_s0_3asy}'