RsaCtfTool /RsaCtfTool

RSA attack tool (mainly for ctf) - retrieve private key from weak public key and/or uncipher data

★ 7,208⑂ 1,018👁 69⑃ 281● 231▤ 0
PythonCreated 2015-03-08
7,208
stars
+0+3+36
1,018
forks
69
watchers
281
prs
231
issues
0
releases
–
discussions

README

RsaCtfTool















RSA multi-attack tool that decrypts data from weak public keys and recovers private keys.

 Overview

This tool is a utility designed to decrypt data from weak public keys and attempt to recover the corresponding private key. It offers a comprehensive range of attack options for cracking RSA encryption.

RSA security relies on the complexity of integer factorization. This project combines multiple factorization algorithms to enhance decryption capabilities.

 Note: This tool is primarily intended for educational purposes. Not every key can be broken in a reasonable timeframe. The tool only supports RSA textbook semiprime composite modulus (not multiprimes).

For advanced factorization, consider msieve, yafu, or cado-nfs.

 Usage

bash
RsaCtfTool --publickey key.pub --private                    Recover private key
RsaCtfTool --publickey key.pub --decryptfile ciphertext     Decrypt file
RsaCtfTool --publickey key.pub --attack wiener              Use specific attack


For complete usage, run: RsaCtfTool --help

 Installation

 Prerequisites

- Python 3.9+
- SageMath (optional but recommended)

 Virtual Environment (Recommended)

bash
python3 -m venv venv
source venv/bin/activate
pip install -e .


 Docker

bash
docker build -t rsactftool/rsactftool .
docker run -it --rm -v $PWD:/data rsactftool/rsactftool 


 Attacks

 Non-Factorization Attacks

- Wiener's attack
- Hastad's attack (small public exponent)
- Boneh-Durfee (small private exponent d  Note for text parameters (--sm-prefix, --sm-suffix): Values starting with 0x or 0X are parsed as hex byte strings, while all other string inputs are parsed as UTF-8 / ASCII text bytes.

 Integer Factorization Methods

| Method | Description |
|--------|-------------|
| Fermat | Close p and q |
| Pollard Rho | General factorization |
| Elliptic Curve (ECM) | Smooth numbers |
| Pollard p-1 | Smooth numbers |
| Williams p+1 | Smooth numbers |
| ROCA | Vulnerable key generation |
| SQUFOF | Square forms |
| Quadratic Sieve | General factorization |
| Dixon | Random squares |
| Factordb | Online factorization database |
| Common factor attacks | Keys sharing factors |
| GCD attacks | Mersenne, Primorial, Fibonacci, etc. |

 CTF-Specific Methods

- Noveltyprimes
- Past CTF Primes
- Gimmicky Primes
- Non-RSA (b^x form)
- Z3 Theorem Prover
- Wolfram Alpha

 Examples

 Recover Private Key

bash
RsaCtfTool --publickey key.pub --private


 Decrypt a File

bash
RsaCtfTool --publickey key.pub --decryptfile ciphertext


 Attack Multiple Keys

bash
RsaCtfTool --publickey ".pub" --private


 Create Public Key from n and e

bash
RsaCtfTool --createpub -n 7828374823761928712873... -e 65537


 Dump Key Parameters

bash
RsaCtfTool --dumpkey --key key.pub
RsaCtfTool --dumpkey --ext --key key.pub   Include CRT parameters


 Factor with ECM

bash
RsaCtfTool --publickey key.pub --ecmdigits 25 --private


 Use Specific Attack

bash
RsaCtfTool --publickey key.pub --attack wiener --private
RsaCtfTool --public

Snapshot: 2026-11-04T14:00:00Z · Data license Apache-2.0 · JSON