Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

RsaCtfTool

> 编程语言
Open source

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

7.0K stars0 likes1 views
WebsiteGitHub

About

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

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 <arguments>

Attacks

Non-Factorization Attacks

  • Wiener's attack
  • Hastad's attack (small public exponent)
  • Boneh-Durfee (small private exponent d < n^0.292)
  • Same n, huge e
  • Small CRT exponent
  • Partial q / Partial d
  • Lattice reduction

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 --publickey key.pub --attack factordb --private

Send Results to Factordb

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

Check for ROCA Vulnerability

bash
RsaCtfTool --isroca --publickey "examples/*.pub"

Convert SSH Key to PEM

bash
RsaCtfTool --convert_idrsa_pub --publickey ~/.ssh/id_rsa.pub

For more examples, run pytest tests/ --collect-only to see available tests.

Testing

Tests use pytest and are located in tests/.

Running Tests

bash
pytest tests/                 # Run all tests
pytest tests/ -m "not slow"   # Skip slow tests
pytest tests/ -v              # Verbose mode
pytest tests/ -k "fermat"     # Run tests matching "fermat"

Test Markers

  • @pytest.mark.slow - Slow factorization tests
  • @pytest.mark.network - Tests requiring network (Factordb)
  • @pytest.mark.attack - Attack integration tests

Test Files

File Description
test_number_theory.py Number theory functions (gcd, is_prime, phi, etc.)
test_algos.py Factorization algorithms (fermat, brent, pollard_rho, etc.)
test_keys_wrapper.py PublicKey/PrivateKey classes
test_utils.py Utility functions
test_pubkey_decode.py RSA public key decoding
test_attacks.py Attack integration tests
test_regression.py Bug fix regression tests
test_exceptions.py Custom exceptions
conftest.py pytest configuration and fixtures

Contributing

Please read CONTRIBUTING.md for guidelines and CODE_OF_CONDUCT.md before contributing.

License

The original project was released under GPLv3. This code has been relicensed under the MIT License.

Thanks

Issues· 4 open

View all issuesOpen on GitHub
  • #553

    [Bug] attack wolframalpha.py doesn't work at test

    Updated Jun 8, 2026
  • #486

    Test Method for Each Attack

    Updated Apr 25, 2025
  • #398

    Maybe a typo at "retreive":

    bugwontfixUpdated Nov 27, 2023

> Tags

Pythoncryptographyrsarsa-attack

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 22, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言