攻防世界Normal_RSA

2023-12-18 11:42:29 浏览数 (1)

题目可以使用openssl读取和生成密钥方法,或脚本求解,rsatool脚本或

flag.enc 看后缀enc,分析是一个通过openssl加密后生成的文件

pubkey.pem 应该是一个公钥信息文件

1、openssl求解

这里我使用kali系统,因为kali系统自带了openssl

先进入openssl 输入 rsa -pubin -text -modulus -in warmup -in pubkey.pem 查看信息

代码语言:shell复制
OpenSSL> rsa -pubin -text -modulus -in warmup -in pubkey.pem
rsa: Unrecognized flag inkey.pem
rsa: Use -help for summary.
error in rsa
OpenSSL> rsa -pubin -text -modulus -in warmup -in pubkey.pem
RSA Public-Key: (256 bit)
Modulus:
    00:c2:63:6a:e5:c3:d8:e4:3f:fb:97:ab:09:02:8f:
    1a:ac:6c:0b:f6:cd:3d:70:eb:ca:28:1b:ff:e9:7f:
    be:30:dd
Exponent: 65537 (0x10001)
Modulus=C2636AE5C3D8E43FFB97AB09028F1AAC6C0BF6CD3D70EBCA281BFFE97FBE30DD
writing RSA key
-----BEGIN PUBLIC KEY-----
MDwwDQYJKoZIhvcNAQEBBQADKwAwKAIhAMJjauXD2OQ/ 5erCQKPGqxsC/bNPXDr
yigb/ l/vjDdAgMBAAE=
-----END PUBLIC KEY-----

Exponent:指的是RSA中的e

Modulus:指的是N,即pq相乘,使用yafu分解N,得到pq

代码语言:python代码运行次数:0复制
from Crypto.Util.number import inverse,long_to_bytes,bytes_to_long

n='C2636AE5C3D8E43FFB97AB09028F1AAC6C0BF6CD3D70EBCA281BFFE97FBE30DD'
n = int(n,16)
e = 65537
p = 319576316814478949870590164193048041239
q = 275127860351348928173285174381581152299
phi_n = (q - 1) * (p -1)
d = inverse(e , phi_n)

with open('flag.enc','rb') as f:
    c = bytes_to_long(f.read())
flag = pow(c,d,n)
print(long_to_bytes(flag))
代码语言:python代码运行次数:0复制
b'x02xc0xfex04xe3&x0e[x87x00PCTF{256b_i5_m3dium}n'

2、rsatool脚本解

需要安装gmpy2库

代码语言:shell复制
python3 rsatool.py -f PEM -o private.pem -p 275127860351348928173285174381581152299 -q 319576316814478949870590164193048041239 -e 65537

生成private.pem文件

代码语言:shell复制
openssl rsautl -decrypt -in flag.enc -inkey private.pem

解密

代码语言:shell复制
OpenSSL> rsautl -decrypt -in flag.enc -inkey private.pem
PCTF{256b_i5_m3dium}

3、CTF-RSA-tool求解

代码语言:shell复制
python2 solve.py --verbose -k ./pubkey.pem --decrypt ./flag.enc
rsa

0 人点赞