Cryptography Attacks
Most cryptographic failures in real applications are not broken algorithms. They are a correct algorithm used in the wrong mode, a key stored where the attacker already is, a random number generator that is not random, or a library default nobody read. This section covers the attacks that follow from those choices, and how to recognise them from what you can actually observe.
What this section is and is not
Where to start
Work in the order below. The first three pages establish what you are looking at; the rest are the specific attacks, each of which needs a precondition you have usually already found on a previous page.
| If you observe this | Start here | Because |
|---|---|---|
| A distinct error, status code or response time when ciphertext is altered | Padding Oracle | That difference is the oracle the attack needs |
A token shaped like base64(iv).base64(ciphertext) |
ECB Block Attacks | Block boundaries and mode are inferable from the layout alone |
| Session IDs, reset codes or invite codes that look short and sequential | PRNG Attacks | Sampling the output is enough to clone a non-cryptographic generator |
| A cookie or API signature ending in hex, with data appended after it | Hash Length Extension | Secret-prefix MACs are forgeable without the secret |
| A repository, image or configuration tree | Key Management | A stored key is usually the fastest path to the data it protects |
What actually breaks
Four families account for almost every finding in this section. They are worth separating because the evidence, the impact and the fix are different for each one.
Weak primitives
- MD5 and SHA-1 for integrity or signatures
- DES, 3DES, RC4 and Blowfish still selecting traffic
- RSA-1024 and 2048-bit keys past their horizon
- Home-grown constructions instead of AEAD
Mode and protocol misuse
- ECB mode chosen by a library default
- CBC without a MAC, behind an error message
- Static or reused IVs and nonces
- TLS 1.0, TLS 1.1 and export cipher suites
Key and secret handling
- Credentials in source, images and CI variables
- Password hashes built from a fast primitive
- Encryption keys stored beside the ciphertext
- No rotation path after exposure
Predictable randomness
- random, Math.random and mt_rand in tokens
- Session identifiers derived from a timestamp
- Seeds taken from pid, time or a counter
- CSPRNG output truncated to too few bits
Cryptography testing sequence - map, classify, test the primitive, test the protocol, report
Scroll sideways to see the whole diagram
The testing sequence
The diagram above is the same sequence in text, so you can follow it without reading a picture. Each step has a page that covers the detail.
1. Map the cryptography
Every place a primitive appears: password storage, session tokens, cookies, signed URLs, file encryption, TLS termination, mobile storage, backups. A use you did not enumerate cannot be tested.
2. Classify each use
Primitive, mode, key source, IV or nonce discipline, and what the value protects. This is where most real findings appear - as a mode or a key-storage decision, not as an algorithm.
3. Test the primitive
Padding oracle, block alignment, length extension, RSA structure, generator state. Each needs a precondition; each page states its own.
4. Test the protocol
Versions, suites, certificate chain, HSTS, and the implementation bugs that are specific to a version.
5. Report the impact
What the key actually protects, for how long, and what an attacker gets if it is recovered today rather than in five years. A weak primitive with a rotating key is a different finding from the same primitive with a ten-year key.
Tooling
These cover the mechanical parts so the work is spent on the decisions. None of them produces a finding on its own, and the limit column is the part that matters in a report.
| Tool | Useful for | What it will not tell you |
|---|---|---|
| openssl | Inspect certificates, force protocol versions, dump a handshake, decrypt with a known key | SSLv3 is unavailable on a stock 3.x build; RC4 needs the legacy provider |
| testssl.sh | Full protocol and cipher sweep, known-vulnerability checks, header review | Talks to one endpoint at a time; says nothing about how the key is stored |
| sslyze | Scriptable scan with JSON output, good in CI against a fleet | Configuration only - an untestable code path is invisible to it |
| hashcat | Recover a password from a captured or leaked hash, with rules and masks | Depends on the hash being unsalted or the wordlist being adequate |
| CyberChef | Decode, identify and transform values interactively; useful for a first guess | No analysis - it shows you bytes, not whether they are safe |
| RsaCtfTool | Automate the standard RSA attacks against a public key or a ciphertext | Only the attacks it implements; a correct key and padding produce nothing |
| gitleaks | Scan a repository or working tree for credentials, with SARIF output | Pattern matching - an invented secret key passes and a documented sample key fails |
Algorithms are rarely the finding
Scope and where to go next
In scope here
- Applications in scope where source or an artefact is available
- Password storage, session tokens and API keys issued by the target
- TLS configuration, certificate chains and HSTS on the endpoints you were given
- Client-side crypto in mobile and thick-client builds (with the binary in hand)
- Key generation, storage and rotation process, as far as documentation allows
All pages
What each primitive guarantees, where the guarantees end, and what you can and cannot conclude by looking at a value.
MD5, SHA-1, DES, 3DES, RC4 and the hashcat workflow that turns a leaked hash into a credential.
The decryption oracle that answers a yes/no question about padding, and how 2,048 requests recover sixteen bytes.
Why a secret prefix breaks every Merkle-Damgard hash, and why HMAC does not have the problem.
Protocol versions, cipher suites, implementation bugs and the configuration defects auditors actually write up.
Small exponents, close primes, shared primes, Wiener and Bleichenbacher - the ways shipped keys fail.
Deterministic encryption as a detection signal, and the byte-at-a-time oracle that reads a secret out of a cookie.
Hardcoded secrets, secret scanning, password hashing parameters, and what happens to a key after it leaks.
Cloning MT19937 and a 48-bit LCG from their own output, and why a longer token does not save a weak generator.
Related Cryptography Guides
Remediation Guidance - Cryptography
The fix for each defect class covered in this section.
Source Code Review
How crypto misuse is found in source before it ships.
Web Penetration Testing
Where TLS and token weaknesses are exercised end to end.
CI/CD and Supply Chain
Secrets, signing keys and build-time supply chain exposure.