攻防世界 cr4-poor-rsa
题目
给了一个压缩包,内有文件:flag.b64(打开发现是base64编码的)和key.pub
解题过程
p = 863653476616376575308866344984576466644942572246900013156919
q = 965445304326998194798282228842484732438457170595999523426901
- 由p,q,e得到d(RSA相关知识点中已有介绍)
- rsa库的PrivateKey生成私钥
- 打开flag.b64并用base64解码,再利用key解密即可得到flag
from Crypto.PublicKey import RSA
from gmpy2 import invert
import rsa
from base64 import b64decode
f = open("F:\\ChromeCommon\\key.pub","rb").read()
pub = RSA.importKey(f)
n = pub.n
e = pub.e
p = 863653476616376575308866344984576466644942572246900013156919
q = 965445304326998194798282228842484732438457170595999523426901
d = int(invert(e, (p-1)*(q-1)))
key = rsa.PrivateKey(n,e,d,p,q)
f = open("F:\\ChromeCommon\\flag.b64",'r').read()
c = b64decode(f)
flag = rsa.decrypt(c,key)
print(flag)
ALEXCTF{SMALL_PRIMES_ARE_BAD}