攻防世界 cr4-poor-rsa

题目

给了一个压缩包,内有文件:flag.b64(打开发现是base64编码的)和key.pub

解题过程

  1. 首先利用Crypto.PublicKey的RSA模块从key.pub中获取公钥信息,这个RSA相关知识点中已有介绍
  2. 得到n后可以拿到大数分解,得到

p = 863653476616376575308866344984576466644942572246900013156919
q = 965445304326998194798282228842484732438457170595999523426901

  1. 由p,q,e得到d(RSA相关知识点中已有介绍)
  2. rsa库的PrivateKey生成私钥
  3. 打开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}

posted @ 2020-08-09 17:59  vict0r  阅读(1232)  评论(0编辑  收藏  举报