7 min read

Cryptography
Advanced
A04

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

This is a testing section, not a mathematics section. Each page starts from something you can see in a request, a response, a configuration or a leak, and follows it to an attack that has been used in the field. Where the attack needs a specific oracle, the page says what that oracle is and what evidence you need before claiming the finding. The fix catalogue lives in Remediation Guidance.

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

Testing flow: map every place the application uses cryptography, classify each use by primitive and mode, test the primitive in isolation, test the protocol configuration, then report what the key actually protects.

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

AES-256 and RSA-3072 are not broken. A report that says a system uses a strong algorithm has said nothing about whether it uses it correctly. Look at the mode, the IV, the key's lifetime and where the key lives - those are the decisions an attacker can act on. The one exception is a shipped key that is structurally weak (a shared prime, a 1024-bit modulus, a fast hash used for passwords), which pages 2, 6 and 8 cover directly.

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