Challenge Description
Everything seems secure; strong numbers, familiar parameters but something small might ruin it all. Can you recover the secret?
We are given RSA parameters (n, e, c) where something “small” introduces a critical vulnerability. The challenge hints at either a small public exponent (e), a small prime factor, or a small private exponent (d).
Approach
Identifying the Vulnerability
The title “Small Trouble” and the description “something small might ruin it all” point to one of several classic RSA weaknesses related to small values:
-
Small public exponent (e=3) with small message — If
m^e < n, the ciphertextc = m^eand we can recovermby simply computing the integer e-th root ofc. Even ifm^eis slightly larger thann, we can iterate:m = iroot(c + k*n, e)for small values ofk. -
Small prime factor — If one of the prime factors of
nis small enough to be found by trial division or a factoring database (like factordb.com), we can factorntrivially. -
Small private exponent (Wiener’s Attack) — If
dis too small relative ton, the continued fraction expansion ofe/nrevealsd.
Most Likely Scenario: Small Exponent (e=3) Cube Root Attack
Given the challenge’s 200-point value, high solve count (1270), and the phrasing “familiar parameters,” this is most likely an RSA challenge with e=3 where the plaintext is small enough that m^3 barely exceeds n. This is the classic “Mini RSA” / cube root attack.
The math:
- RSA encryption:
c = m^e mod n - If
e = 3andmis small, thenm^3 = c + k*nfor some small integerk - We iterate over
k = 0, 1, 2, ...and check ifc + k*nis a perfect cube - When we find a perfect cube,
m = iroot(c + k*n, 3)
Alternative: Small Prime Factor
If the challenge provides a large n but one prime is suspiciously small:
- Try factoring with small primes or use factordb.com
- Once we have
pandq, computephi(n) = (p-1)(q-1), thend = inverse(e, phi(n)), thenm = pow(c, d, n)
Solution
Step-by-step:
- Extract the parameters from the challenge files (n, e, c).
- Check the value of e — if
e = 3(or another small value), try the cube root attack. - Iterate over
k = 0, 1, 2, ..., computingiroot(c + k*n, e)until we find a perfect e-th root. - Convert the resulting integer
mto bytes to get the flag.
Cube Root Attack (e=3):
import gmpy2
from Crypto.Util.number import long_to_bytes
# Given values from the challenge
n = ... # RSA modulus
e = 3 # Small public exponent
c = ... # Ciphertext
# Iterate: try c + k*n for k = 0, 1, 2, ...
for k in range(100000):
candidate = c + k * n
root, is_perfect = gmpy2.iroot(candidate, e)
if is_perfect:
m = int(root)
plaintext = long_to_bytes(m)
print(f"Found at k={k}: {plaintext}")
break
Small Prime Factorization (alternative):
from Crypto.Util.number import long_to_bytes
from sympy import factorint
# If n has a small factor
factors = factorint(n) # or use factordb
p, q = list(factors.keys())
phi = (p - 1) * (q - 1)
d = pow(e, -1, phi)
m = pow(c, d, n)
print(long_to_bytes(m))
Solution Script
python3 solve.py
Flag
picoCTF{...} (placeholder - actual flag varies per instance)