Install
openclaw skills install ctf-cryptoProvides cryptography attack techniques for CTF challenges. Use when attacking encryption, hashing, signatures, ZKP, PRNG, or mathematical crypto problems involving RSA, AES, ECC, lattices, LWE, CVP, number theory, Coppersmith, Pollard, Wiener, padding oracle, GCM, key derivation, or stream/block cipher weaknesses.
openclaw skills install ctf-cryptoQuick reference for crypto CTF challenges. Each technique has a one-liner here; see supporting files for full details with code.
Python packages (all platforms):
pip install pycryptodome z3-solver sympy gmpy2 hashpumpy fpylll py_ecc
Linux (apt):
apt install hashcat sagemath
macOS (Homebrew):
brew install hashcat
Manual install:
apt install sagemath, macOS: brew install --cask sagegit clone https://github.com/RsaCtfTool/RsaCtfTool (automated RSA attacks)Note:
gmpy2requires libgmp — Linux:apt install libgmp-dev, macOS:brew install gmp.
/ctf-reverse./ctf-forensics./ctf-pwn or /ctf-web./ctf-ai-ml./ctf-misc.# Identify cipher type
python3 -c "from Crypto.Util.number import *; n=<N>; print(f'bits={n.bit_length()}')"
# RSA quick check
python3 -c "from sympy import factorint; print(factorint(<n>))" # Small factors?
openssl rsa -pubin -in key.pub -text -noout # Extract n, e from PEM
# Quick factorization tools
python3 RsaCtfTool.py -n <n> -e <e> --uncipher <c>
# XOR analysis
python3 -c "from pwn import xor; print(xor(bytes.fromhex('<hex>'), b'flag{'))"
# Hash identification
hashid '<hash>'
hashcat --identify '<hash>'
# SageMath (for lattice/ECC)
sage -c "print(factor(<n>))"
(ct - pt) mod 26. Kasiski examination for unknown key length (GCD of repeated sequence distances)C1 XOR C2 XOR known_P = unknown_P; crib dragging when no plaintext knownfile reports "data". XOR first bytes against expected magic bytes to derive repeating key; extend using trailer structures (%%EOF, IEND marker). See classic-ciphers.md.See classic-ciphers.md for full code examples.
ecb_cpa_decrypt); image ECB preserves visual patterns. ECB cut-and-paste: splice ciphertext blocks to forge JSON fields (e.g., is_admin: true). See modern-ciphers-2.md.new_sig = old_sig XOR block_difflen(set(sbox)) < 256) enables 4,097-query key recovery(state >> 1) XOR next_state for LSB=1 transitions to directly recover tap mask. Autocorrelation sliding finds correct length. See stream-ciphers.md.SHA256(public_key) XOR seed is fully recoverable without private key; "hybrid" RSA+AES provides no security. See modern-ciphers-2.md.nonce-disrespect. See modern-ciphers.md.A = 0 or A = n to force shared secret to 0, bypassing password verification entirely. See modern-ciphers-2.md.c = m^2 mod n with LSB oracle enables binary search plaintext recovery in log2(n) queries via multiplicative homomorphism (c * 4 mod n doubles plaintext). See modern-ciphers-2.md.SHA1(password) instead of password when original exceeds 64 bytes. See modern-ciphers-2.md.fastcol runs to produce 2^k files with identical MD5. Merkle-Damgard composition: collisions propagate through appended suffixes. See modern-ciphers-2.md.See modern-ciphers.md and modern-ciphers-2.md for full code examples.
f.small_roots() in SageMathor short-circuit skips expensive PBKDF2 when Y != 0, creating fast/slow timing oracle. Full 3-step attack (~1024 iterations for 1024-bit RSA). Calibrate timing bounds with known-fast/known-slow samples.g(0) = 0 for polynomial hash; craft suffix for msg = 0 (mod P), signature = 0r = flag mod f, filter coprime, CRT combinep=q so server computes wrong phi=(p-1)^2 instead of p*(p-1); test decryption fails, leaking ciphertextnthroot_mod, enumerate CRT combinations (3^k feasible for small k)phi(n) (e.g., e*d-1) enables factoring via Miller-Rabin square root technique; succeeds with prob ≥ 1/2 per attemptp = kp*B + tp with small kp create mixed-radix structure in n; brute-force kp*kq (2^24) to factore' = e/g, compute d' = e'^(-1) mod phi, partial decrypt to m^g, then take g-th root over integers(dp*e-1)/k+1 is prime. See rsa-attacks-2.md.gcd(s^e - m, n) (Bellcore attack). See rsa-attacks-2.md.c by querying oracle with c * r^e mod n, then dividing result by r. See rsa-attacks-2.md.n has many small prime factors, factor with trial division, solve m mod p_i per prime, CRT combine. See rsa-attacks-2.md.e recipients applies a known affine transform a_i*m+b_i before encryption, CRT + Coppersmith small_roots recovers m. See rsa-attacks.md.See rsa-attacks.md and advanced-math.md for full code examples.
p-1 or curve order are small). Sage: discrete_log(Mod(h,p), Mod(g,p)). See advanced-math.md.r in two signatures leaks nonce k and private key d via modular arithmetic. Check for repeated r valueskey = master * uid mod l; query powers of 2, check y-coordinate consistencyb* = max(Mb[i] - M[i][j]) recovers shared secret directly from public matricesk is small (e.g., 20-bit), brute-force all k values and check which yields the known r. See ecc-attacks.md.gcd(n1, n2) reveals the shared prime. See ecc-attacks.md.k derives from MD5(prefix+counter), use fastcoll to produce MD5 prefix collision forcing nonce reuse, then standard private key recovery. See ecc-attacks.md.See ecc-attacks.md, advanced-math.md, and exotic-crypto.md for full code examples.
observed * 2^t + hidden and solve for the small hidden corrections. See lattice-and-lwe.md.[q*I | 0; A^T | I], use fpylll CVP.babai to find closest vector, project to ternary {-1,0,1}. Watch for endianness mismatches between server description and actual encoding.See advanced-math.md for worked LWE solving code and lattice-and-lwe.md for attack selection, embeddings, and failure-mode triage.
nx.coloring.greedy_color(G, strategy='saturation_largest_first')counter < N checksSee zkp-and-advanced.md for full code examples and solver patterns.
c = A*x+b (mod M), M composite (e.g., 65=5*13). Chosen-plaintext recovery via one-hot vectors, CRT inversion per prime factor. See modern-ciphers.md.m*s < 2^128. ~128 queries to recover AES key.Self-referential CRC: find ASCII string whose CRC equals itself. CRC is linear over GF(2), so the constraint becomes a solvable linear system. Free variables chosen for printable ASCII range. See advanced-math.md.
Server reveals valid/invalid padding → decrypt any CBC ciphertext without key. ~4096 queries per 16-byte block. Use PadBuster or padding-oracle Python library. See modern-ciphers.md.
RSA PKCS#1 v1.5 padding validation oracle → adaptive chosen-ciphertext plaintext recovery. ~10K queries for RSA-2048. Affects TLS implementations via timing. See modern-ciphers.md.
n-bit hash collision in ~2^(n/2) attempts. Meet-in-the-middle breaks double encryption in O(2^k) instead of O(2^(2k)). See modern-ciphers.md.
CRC32 is linear — append 4 chosen bytes to force any target CRC32, forging CRC32(msg || secret) signatures without the secret. See modern-ciphers.md.
Extend ciphertext by one bit per oracle query to leak plaintext via parity. Manipulate BBS squaring sequence to produce valid extended ciphertexts. See modern-ciphers-2.md.
Exploits Merkle-Damgard hashes (hash(SECRET || user_data)) — append arbitrary data and compute valid hash without knowing the secret. Use hashpump or hashpumpy. See modern-ciphers-2.md.
Compression before encryption leaks plaintext via ciphertext length changes. Send chosen plaintexts; matching n-grams compress shorter. Same class as CRIME/BREACH. See modern-ciphers-2.md.
RC4's second output byte is biased toward 0x00 (probability 1/128 vs 1/256). Distinguishes RC4 from random with ~2048 samples. See stream-ciphers.md.
Unpadded RSA: S(a) * S(b) mod n = S(a*b) mod n. If oracle blacklists target message, sign its factors and multiply. See rsa-attacks-2.md.
phi = (p-1)*(q-1), d = inverse(e, phi), m = pow(c, d, n). See rsa-attacks.md for full examples.from pwn import xor; xor(ct, key). See classic-ciphers.md for XOR variants.Pattern: Binary uses srand(time(NULL)) + rand() for keys/XOR masks. Python's random module uses a different PRNG. Use ctypes.CDLL('./libc.so.6') to call C's srand(int(time())) and rand() directly, reproducing the exact sequence. See prng.md for XOR decryption examples and timing tips.
Pattern: V8 JavaScript engine uses xs128p PRNG for Math.random(). Given 5-10 consecutive outputs of Math.floor(CONST * Math.random()), recover internal state (state0, state1) with Z3 QF_BV solver and predict future values. Values must be reversed (LIFO cache). Tool: d0nutptr/v8_rand_buster. See prng.md.
Pattern: Server exposes random.random() floats. Standard untemper needs 624 × 32-bit integers, but floats yield only ~8 usable bits each. A precomputed GF(2) magic matrix (not_random library) recovers the full MT state from 3360+ float observations. Use to predict password reset tokens, session IDs, or CSRF tokens derived from random.random(). See prng.md.
x = r * x * (1 - x), r ≈ 3.99-4.0; seed recovery by brute-forcing high-precision decimalsstruct.pack("<f", x) per iteration; XOR with ciphertextSee prng.md for full code.
Divide-and-conquer SPN key recovery: attack each S-box position independently, intersect valid key candidates across multiple plaintext-ciphertext pairs. Reduces exponential key space to independent sub-key searches. See modern-ciphers-2.md.
pip install pycryptodome z3-solver sympy gmpy2sage -python script.py (required for ECC, Coppersmith, lattice attacks)python RsaCtfTool.py -n <n> -e <e> --uncipher <c> — automated RSA attack suite (tries Wiener, Hastad, Fermat, Pollard, and many more)