1. File Analysis
The first time this topic, see the topic but know that this is a problem rsa decryption.
Public key n = p * q, where p and q are two large prime numbers
e is a randomly selected number, as the public key
d is a number associated with the e, satisfy the conditional formula: ed = 1 (mod phi (n))
phi (n) is the Euler function, phi (n) = (p-1) (q-1)
Transfer: https://blog.csdn.net/kevin66654/article/details/54087647
pub.key is the public key, flag.enc the rsa encrypted file, so long as we parsed n, e, p, q, d public key file, and then using a script file to decrypt the encrypted rsa.
2. The public process
2.1 extract the public key
IDA open pub.key, which converts a string of hexadecimal extracted public key.
-----BEGIN PUBLIC KEY----- MDwwDQYJKoZIhvcNAQEBBQADKwAwKAIhAMAzLFxkrkcYL2wch21CM2kQVFpY9+7+ /AvKr1rzQczdAgMBAAE= -----END PUBLIC KEY-----
2.2 Analytical public key (extract e, n)
In http://tool.chacuo.net/cryptrsakeyparse the public key is resolved
Public exponent and module information:
key length: | 256 |
Model number: | C0332C5C64AE47182F6C1C876D42336910545A58F7EEFEFC0BCAAF5AF341CCDD |
index: | 65537 (0x10001) |
Get to
e = 65537
n = 86934482296048119190666062003494800588905656017203025617216654058378322103517 (ADC decimal)
2.3 Analytical public key (extraction p, q)
Use yahu or http://www.factordb.com/index.php?query=86934482296048119190666062003494800588905656017203025617216654058378322103517 by parsing n p, q
p = 285960468890451637935629440372639283459
q = 304008741604601924494328155975272418463
3. decryption script
import gmpy2 import rsa e = 65537 n = 86934482296048119190666062003494800588905656017203025617216654058378322103517 p = 285960468890451637935629440372639283459 q = 304008741604601924494328155975272418463 phin = (q-1)*(p-1) d = gmpy2.invert(e, phin) key = rsa.PrivateKey(n, e, int(d), p, q) with open("C:\\Users\\10245\\Desktop\\output\\flag.enc", "rb+") as f: f = f.read() print(rsa.decrypt(f, key))
4.get flag!
flag{decrypt_256}
Want to learn more about the CTF's rsa, you can take a look at https://err0rzz.github.io/2017/11/14/CTF%E4%B8%ADRSA%E5%A5%97%E8%B7%AF/