RSA challenges hand you numbers: a modulus n, a public exponent e, and a ciphertext c. Properly generated RSA can't be broken, so the challenge always hides a flaw in how the key was made. RsaCtfTool runs through a long list of known flaws automatically.
Installing
git clone https://github.com/RsaCtfTool/RsaCtfTool.git
cd RsaCtfTool
pip install -r requirements.txt
Some attacks use SageMath or other optional dependencies; the tool simply skips attacks it can't run.
Decrypting from n, e and c
python3 RsaCtfTool.py -n 8775...201 -e 65537 --decrypt 3361...988
It tries attacks one after another until one recovers the private key, then decrypts the ciphertext. Add --attack all to make sure every attack is attempted, or name one, like --attack wiener, to save time once you suspect the weakness.
Working with key files
python3 RsaCtfTool.py --publickey key.pub --private
python3 RsaCtfTool.py --publickey key.pub --decryptfile flag.enc
python3 RsaCtfTool.py --dumpkey --key key.pub
--private prints the recovered private key in PEM format; --dumpkey shows n and e from a PEM file, which is useful just for inspecting a key.
What it can catch
- Small or factorable n — factored directly or found in the factordb.com database
- Primes too close together — Fermat factorization
- Small e with a short message — the ciphertext is just
m^e, so an integer cube root recoversm - Large e / small d — Wiener's and Boneh–Durfee attacks
- Several keys sharing a prime — a GCD between moduli factors both (pass several
--publickeyfiles)
When to do it by hand
RsaCtfTool is a fast first try, not a replacement for understanding. If it fails, read the challenge again: are you given extra values (dp, phi, a hint about how p was chosen)? Those point to a specific attack you can script in a few lines of Python with pow(e, -1, phi). Our Mind your Ps and Qs writeup walks through factoring a small modulus and rebuilding the private key by hand.