Get the FREE Ultimate OpenClaw Setup Guide →

ctf-crypto

Scanned
npx machina-cli add skill ljagiello/ctf-skills/ctf-crypto --openclaw
Files (1)
SKILL.md
7.8 KB

CTF Cryptography

Quick reference for crypto CTF challenges. Each technique has a one-liner here; see supporting files for full details with code.

Additional Resources

  • classic-ciphers.md - Classic ciphers: Vigenere, Atbash, substitution wheels, XOR variants, deterministic OTP, cascade XOR, book cipher
  • modern-ciphers.md - Modern cipher attacks: AES (CFB-8, ECB leakage), CBC-MAC/OFB-MAC, padding oracle, S-box collisions, GF(2) elimination, LCG partial output recovery
  • rsa-attacks.md - RSA attacks: consecutive primes, multi-prime, restricted-digit, Coppersmith structured primes, Manger oracle, polynomial hash
  • ecc-attacks.md - ECC attacks: small subgroup, invalid curve, Smart's attack (anomalous, with Sage code), fault injection, clock group DLP, Pohlig-Hellman
  • zkp-and-advanced.md - ZKP/graph 3-coloring, Z3 solver guide, garbled circuits, Shamir SSS, bigram constraint solving, race conditions
  • prng.md - PRNG attacks (MT19937, LCG, GF(2) matrix PRNG, middle-square, deterministic RNG hill climbing, random-mode oracle, time-based seeds, password cracking)
  • historical.md - Historical ciphers (Lorenz SZ40/42, book cipher implementation)
  • advanced-math.md - Advanced mathematical attacks (isogenies, Pohlig-Hellman, LLL, Coppersmith, quaternion RSA, monotone inversion, GF(2)[x] CRT, S-box collision code, LWE lattice CVP attack)

Classic Ciphers

  • Caesar: Frequency analysis or brute force 26 keys
  • Vigenere: Known plaintext attack with flag format prefix; derive key from (ct - pt) mod 26
  • Atbash: A<->Z substitution; look for "Abashed" hints in challenge name
  • Substitution wheel: Brute force all rotations of inner/outer alphabet mapping
  • Cascade XOR: Brute force first byte (256 attempts), rest follows deterministically
  • XOR rotation (power-of-2): Even/odd bits never mix; only 4 candidate states
  • Weak XOR verification: Single-byte XOR check has 1/256 pass rate; brute force with enough budget
  • Deterministic OTP: Known-plaintext XOR to recover keystream; match load-balanced backends

See classic-ciphers.md for full code examples.

Modern Cipher Attacks

  • AES-ECB: Block shuffling, byte-at-a-time oracle; image ECB preserves visual patterns
  • AES-CBC: Bit flipping to change plaintext; padding oracle for decryption without key
  • AES-CFB-8: Static IV with 8-bit feedback allows state reconstruction after 16 known bytes
  • CBC-MAC/OFB-MAC: XOR keystream for signature forgery: new_sig = old_sig XOR block_diff
  • S-box collisions: Non-permutation S-box (len(set(sbox)) < 256) enables 4,097-query key recovery
  • GF(2) elimination: Linear hash functions (XOR + rotations) solved via Gaussian elimination over GF(2)
  • Padding oracle: Byte-by-byte decryption by modifying previous block and testing padding validity

See modern-ciphers.md for full code examples.

RSA Attacks

  • Small e with small message: Take eth root
  • Common modulus: Extended GCD attack
  • Wiener's attack: Small d
  • Fermat factorization: p and q close together
  • Pollard's p-1: Smooth p-1
  • Hastad's broadcast: Same message, multiple e=3 encryptions
  • Consecutive primes: q = next_prime(p); find first prime below sqrt(N)
  • Multi-prime: Factor N with sympy; compute phi from all factors
  • Restricted-digit primes: Digit-by-digit factoring from LSB with modular pruning
  • Coppersmith structured primes: Partially known prime; f.small_roots() in SageMath
  • Manger oracle: Phase 1 doubling + phase 2 binary search; ~128 queries for 64-bit key
  • Polynomial hash (trivial root): g(0) = 0 for polynomial hash; craft suffix for msg = 0 (mod P), signature = 0
  • Polynomial CRT in GF(2)[x]: Collect ~20 remainders r = flag mod f, filter coprime, CRT combine
  • Affine over composite modulus: CRT in each prime factor field; Gauss-Jordan per prime

See rsa-attacks.md and advanced-math.md for full code examples.

Elliptic Curve Attacks

  • Small subgroup: Check curve order for small factors; Pohlig-Hellman + CRT
  • Invalid curve: Send points on weaker curves if validation missing
  • Singular curves: Discriminant = 0; DLP maps to additive/multiplicative group
  • Smart's attack: Anomalous curves (order = p); p-adic lift solves DLP in O(1)
  • Fault injection: Compare correct vs faulty output; recover key bit-by-bit
  • Clock group (x^2+y^2=1): Order = p+1 (not p-1!); Pohlig-Hellman when p+1 is smooth
  • Isogenies: Graph traversal via modular polynomials; pathfinding via LCA

See ecc-attacks.md and advanced-math.md for full code examples.

Lattice / LWE Attacks

  • LWE via CVP (Babai): Construct lattice from [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.
  • LLL for approximate GCD: Short vector in lattice reveals hidden factors
  • Multi-layer challenges: Geometry → subspace recovery → LWE → AES-GCM decryption chain

See advanced-math.md for full LWE solving code and multi-layer patterns.

ZKP & Constraint Solving

  • ZKP cheating: For impossible problems (3-coloring K4), find hash collisions or predict PRNG salts
  • Graph 3-coloring: nx.coloring.greedy_color(G, strategy='saturation_largest_first')
  • Z3 solver: BitVec for bit-level, Int for arbitrary precision; BPF/SECCOMP filter solving
  • Garbled circuits (free XOR): XOR three truth table entries to recover global delta
  • Bigram substitution: OR-Tools CP-SAT with automaton constraint for known plaintext structure
  • Trigram decomposition: Positions mod n form independent monoalphabetic ciphers
  • Shamir SSS (deterministic coefficients): One share + seeded RNG = univariate equation in secret
  • Race condition (TOCTOU): Synchronized concurrent requests bypass counter < N checks

See zkp-and-advanced.md for full code examples and solver patterns.

Modern Cipher Attacks (Additional)

  • Affine over composite modulus: 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.
  • Custom linear MAC forgery: XOR-based signature linear in secret blocks. Recover secrets from ~5 known pairs, forge for target. See modern-ciphers.md.
  • Manger oracle (RSA threshold): RSA multiplicative + binary search on m*s < 2^128. ~128 queries to recover AES key.

Common Patterns

  • RSA basics: phi = (p-1)*(q-1), d = inverse(e, phi), m = pow(c, d, n). See rsa-attacks.md for full examples.
  • XOR: from pwn import xor; xor(ct, key). See classic-ciphers.md for XOR variants.

Useful Tools

  • Python: pip install pycryptodome z3-solver sympy gmpy2
  • SageMath: sage -python script.py (required for ECC, Coppersmith, lattice attacks)

Source

git clone https://github.com/ljagiello/ctf-skills/blob/main/ctf-crypto/SKILL.mdView on GitHub

Overview

A quick-reference guide to crypto attack patterns used in CTFs. It covers classic and modern ciphers, RSA/ECC/LWE-type problems, padding and MAC flaws, and PRNG weaknesses. See the linked resources for deeper code examples.

How This Skill Works

Aggregates practical techniques into concise entries with the underlying weaknesses. Each entry explains how the attack leverages a specific flaw (padding, poor randomness, prime factors, lattice CVP, etc.) and points to runnable code in supporting files for quick experimentation.

When to Use It

  • When the challenge involves RSA with small d, a common modulus, or prime-factorization tricks (Wiener, Fermat, Pollard's p-1).
  • When facing AES modes weaknesses like padding oracle or ECB/CBC leakage.
  • When encountering ECC, isogeny, LWE, or lattice-based CVP problems.
  • When dealing with classic ciphers (Caesar, Vigenere, Atbash) and known-plaintext attacks.
  • When testing PRNGs (MT19937, LCG) or hash/MAC weaknesses in PRNG-based challenges.

Quick Start

  1. Step 1: Identify the challenge type (RSA, AES, ECC, PRNG, etc.) and choose the matching technique from the references.
  2. Step 2: Open the supporting files and run the example attacks; adapt parameters to the challenge.
  3. Step 3: Verify recovered plaintext or key against the flag format and iterate if needed.

Best Practices

  • Clearly identify the cipher type and the corresponding attack from the resource list before coding.
  • Start with low-hanging weaknesses (e.g., padding or known-plaintext) before attempting heavy math attacks.
  • Use the code examples and tools linked in the supporting docs; replicate with test vectors.
  • Validate results against the flag format; document findings and uncertainties.
  • Keep track of assumptions and limitations; avoid overfitting to a single challenge.

Example Use Cases

  • AES-CBC padding oracle: decrypt ciphertext without the key.
  • Wiener's attack on RSA with small private exponent d.
  • Common modulus attack using Extended GCD on the same message with different e.
  • Hastad's broadcast: same message encrypted under multiple e=3 ciphertexts.
  • Pollard's p-1 attack on RSA when p-1 is smooth.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers