flag.enc内容是通过rsa加密了的密文
pubkey.pem是rsa公钥,加密者利用这个文件对flag原文进行了加密
如果对rsa加密算法不了解的可以补一下教学视频
数学不好也能听懂的算法 - RSA加密和解密原理和过程_哔哩哔哩_bilibili
openssl rsa -pubin -text -modulus -in pubkey.pem
E=65537
N=C2636AE5C3D8E43FFB97AB09028F1AAC6C0BF6CD3D70EBCA281BFFE97FBE30DD
这里的N是十六进制所以对该值转换成十进制便于后续计算:
手动补齐十六进制头:0x
就获得了十进制的N:
N=87924348264132406875276140514499937145050893665602592992418171647042491658461
通过对N值进行分解,获得rsa加密中的关键值:p、q
网站:factordb.com
p=275127860351348928173285174381581152299
q=319576316814478949870590164193048041239
再次利用python帮我们把T的值算出来
T=87924348264132406875276140514499937144456189488436765114374296308467862464924
import gmpy2
from Crypto.PublicKey import RSA
n = 87924348264132406875276140514499937145050893665602592992418171647042491658461
e = 65537
T = 87924348264132406875276140514499937144456189488436765114374296308467862464924
d = int(gmpy2.invert(e, T))
prikey = RSA.construct((n, e, d), False)
with open('prikey.pem', 'w') as f:
key = prikey.export_key().decode('utf-8')
print(key)
f.write(key)
openssl pkeyutl -decrypt -in flag.enc -inkey prikey.pem