This section focuses on practical cryptography for offensive security and CTFs: how to quickly recognise common patterns, pick the right tools, and apply known attack templates. The goal is not to prove security proofs but to break things.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/HackTricks-wiki/hacktricks/llms.txt
Use this file to discover all available pages before exploring further.
Quick classification workflow
When you encounter an unknown crypto challenge or sample:- What is the primitive? Block cipher, stream cipher, hash, MAC, or public-key?
- What do you control? Plaintext oracle, ciphertext, key material, IV/nonce?
- What is leaked? Padding errors, timing differences, error messages, nonce reuse?
- Which mode/construction is used? ECB, CBC, CTR, GCM, RSA-PKCS1v1.5, etc.?
Toolchain setup
Symmetric crypto
Cipher Block Chaining (CBC)
Malleability, padding oracle attacks, bit-flip exploits.
Padding Oracle Attacks
Decrypt arbitrary ciphertext and forge messages without the key.
AES modes at a glance
| Mode | Deterministic? | Malleable? | Primary weakness |
|---|---|---|---|
| ECB | Yes | Yes | Equal blocks → equal ciphertext; pattern leakage |
| CBC | No (IV) | Yes | Bit-flip in C[i-1] flips known bits in P[i]; padding oracle |
| CTR | No (nonce) | Yes | Nonce reuse → XOR of two plaintexts; no integrity |
| GCM | No (nonce) | Yes* | Nonce reuse breaks both confidentiality and integrity |
ECB detection and exploitation
ECB encrypts each 16-byte block independently: equal plaintext blocks produce equal ciphertext blocks.admin aligns to a block boundary, encrypt it, then swap that ciphertext block into the position of the user field in a legitimate token.
CTR and GCM nonce reuse
If two messages are encrypted under the same key and nonce:Hash attacks
Length extension
Many hash constructions (MD5, SHA-1, SHA-256) are vulnerable to length extension: givenH(secret || message) and the length of secret, an attacker can compute H(secret || message || padding || extension) without knowing secret.
Hash cracking quick reference
Public-key crypto
RSA common mistakes
| Scenario | Attack | |---|---|---| | Small public exponente=3, small message | Cube-root attack (no padding) |
| Same message, different moduli, same small e | Coppersmith / Håstad broadcast |
| Shared prime factor between two moduli | gcd(n1, n2) recovers p immediately |
| Weak random — close primes | Fermat factorisation |
| PKCS#1 v1.5 padding oracle | Bleichenbacher attack |
MAC forgery
CBC-MAC variable-length forgery
CBC-MAC is secure only for fixed-length messages. If an attacker obtains tags for two messages and can concatenate them, they can forge a tag for the concatenation without knowing the key.Stream ciphers and XOR
Almost every stream cipher or custom encryption scheme reduces to:Recommended reading
- Trail of Bits — Carelessness versus craftsmanship in cryptography (2026)
- Cryptopals challenges (cryptopals.com) — practical exercises covering all the above attacks
- SageMath documentation — for lattice and ECC attacks