Skip to main content
Be Bitwise

TLS/SSL Vulnerabilities

Web Application Exploitation (Low-Level Perspective) · Advanced Exploitation track

9 min read

In this module

The Lock Icon Is Not Enough

TLS and its predecessor SSL are the cryptographic protocols securing virtually all web traffic. The padlock icon means TLS is encrypting your connection. But the protocol implementations have had serious vulnerabilities — not in the cryptographic algorithms themselves, but in the software around them.

Looking at TLS vulnerabilities at a low level shows how memory corruption, protocol design flaws, and implementation errors can each independently hollow out an otherwise sound cryptographic system.

TLS at a High Level

Before examining vulnerabilities, a quick review of what TLS actually does:

  1. Handshake: The client and server negotiate a protocol version, cipher suite, and exchange keys. The server provides a certificate to prove its identity.
  2. Key exchange: Using asymmetric cryptography (RSA or Diffie-Hellman), both sides derive a shared secret without transmitting it.
  3. Encrypted communication: All subsequent data is encrypted with symmetric cryptography using keys derived from the shared secret.

Every step involves complex parsing of binary protocol messages, cryptographic operations, and state machine transitions. Each is a potential source of vulnerabilities.

Heartbleed: A Memory Safety Catastrophe

Heartbleed (CVE-2014-0160) is perhaps the most impactful memory safety vulnerability in the history of the internet. It affected OpenSSL, the library used by roughly two-thirds of all HTTPS servers at the time.

The bug was in the TLS heartbeat extension - a keep-alive mechanism. A heartbeat request contains a payload and a length field. The server is supposed to echo back the payload. The vulnerable code looked like this (simplified):

c
/* Read the heartbeat request */
unsigned short payload_length = ntohs(request->length);
unsigned char *payload = request->data;
/* Allocate response buffer */
unsigned char *response = OPENSSL_malloc(1 + 2 + payload_length + padding);
/* Copy the payload into the response */
memcpy(response_ptr, payload, payload_length);

The critical bug: the code trusted the payload_length field from the request without checking whether the actual request data was that long. An attacker could send a heartbeat request with a small actual payload (say, 1 byte) but set the length field to 65535 (the maximum for a 16-bit unsigned integer). The server would then copy 65535 bytes starting from the payload address - reading 65534 bytes of adjacent server memory.

text
Heartbeat Request:
payload_length: 65535 (attacker-controlled)
actual payload: 1 byte
Server's memcpy reads 65,535 bytes starting at payload address:
[1 byte of actual payload] [65,534 bytes of server memory]

Those 65,534 bytes could contain anything that happened to be adjacent in memory: private keys, session cookies, user passwords, other users' request data. The attacker could repeat this request thousands of times, each time potentially receiving different chunks of server memory.

Heartbleed

Heartbleed (CVE-2014-0160) was a missing bounds check in OpenSSL's TLS heartbeat extension. The server copied more data than was actually present in the request, leaking up to 64KB of server memory per request. This could expose private keys, session tokens, and user data. The fix was a two-line bounds check.

The fix was astonishingly simple - two lines of code to verify that the actual payload length matched the declared length:

c
if (payload_length > actual_record_length) {
return 0; /* Silently discard */
}

Netcraft estimated that about 17% of the internet's TLS-enabled web servers, roughly half a million sites, were vulnerable when the bug went public in April 2014. Heartbleed demonstrated how a single missing bounds check in a C program could compromise the security of millions of servers worldwide.

Padding Oracle Attacks

CBC mode (Cipher Block Chaining) is a block cipher mode that was widely used in TLS. After decryption, the plaintext must be unpadded - the last N bytes must all have the value N (PKCS#7 padding). The server must verify that the padding is correct.

A padding oracle attack exploits the difference between two error conditions:

  1. Invalid padding (detected during decryption)
  2. Invalid message content (detected after successful decryption)

If the server responds differently to these two cases - different error messages, different response times, or even different TCP behaviour - the attacker has an oracle that tells them whether a modified ciphertext decrypted to correctly padded plaintext.

The trick lies in how CBC decrypts. Each plaintext block is P[i] = Decrypt(C[i]) XOR C[i-1], so flipping a byte in the previous ciphertext block flips the same byte of the plaintext, without touching the block cipher at all. The attacker sends a forged previous block followed by the target block C[i], and watches the response:

text
For each byte position in the target block (working right to left):
For each possible byte value (0x00 to 0xFF):
Set that byte of the forged previous block C'[i-1]
Send C'[i-1] || C[i] to the server
If server says "bad MAC" (not "bad padding"):
The modification produced valid padding
→ Decrypt(C[i]) at that position = guess XOR padding value,
and XOR with the real C[i-1] gives the plaintext byte

By systematically trying all 256 values for each byte and observing which ones produce valid padding, the attacker can decrypt the entire ciphertext without knowing the key. Each byte requires at most 256 attempts, so decrypting N bytes requires at most 256 * N requests.

The POODLE attack (Padding Oracle On Downgraded Legacy Encryption) exploited this against SSL 3.0, which had a padding format that made the oracle particularly easy to exploit. The defence is to use authenticated encryption modes (like AES-GCM) that do not have separate padding and integrity checks.

Downgrade Attacks

TLS supports version negotiation: the client proposes the highest version it supports, and the server responds with the highest version both support. A downgrade attack is a man-in-the-middle attack that pushes the two sides onto a weaker protocol version or cipher suite than they'd otherwise pick.

The naive version, editing the client's offer in flight, doesn't work on its own. Both sides hash every handshake message into their Finished messages, which are keyed with the session secret, so a tampered ClientHello shows up as a Finished mismatch. Real downgrades got round that in two ways.

The first was the insecure fallback. When a handshake failed, browsers used to retry with a lower version, to cope with buggy servers. An attacker who simply dropped the first few attempts got a fresh, untampered SSL 3.0 handshake, and its Finished messages checked out because nothing had been modified. POODLE used exactly this to reach SSL 3.0's padding oracle.

The second targeted export-grade cipher suites, which servers still supported years after the export rules went away. With FREAK, buggy clients accepted a 512-bit export RSA key they'd never asked for, and 512-bit RSA could be factored in hours. Logjam rewrote the client's offer to request DHE_EXPORT; the server's signature over its 512-bit Diffie-Hellman parameters didn't cover the cipher choice, and with precomputation the attacker could solve the discrete log fast enough to forge both Finished messages before either side timed out. Breaking the weak key exchange in real time is what defeats the Finished check.

TLS 1.3 includes a downgrade protection mechanism: when the server supports TLS 1.3 but negotiates a lower version, it embeds a specific sentinel value in its ServerHello random field. A TLS 1.3-capable client checks for this sentinel and aborts the handshake if it detects a downgrade. This is a protocol-level defence that does not rely on the security of the lower-version handshake.

Implementation Bugs in State Machines

TLS is a complex protocol with a multi-step handshake. The implementation must maintain a state machine that tracks where it is in the handshake and what messages are valid next. Bugs in state machine implementation can have catastrophic consequences.

A notable example is the Apple goto fail bug (CVE-2014-1266). In Apple's TLS implementation, a duplicated goto fail; statement caused the signature verification step to be skipped entirely:

c
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail; /* DUPLICATE LINE - always executes! */
/* Signature verification code - never reached */
if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
goto fail;

The second goto fail was not inside an if statement - it always executed, jumping past the actual signature verification. This meant the server's certificate was never verified, allowing any man-in-the-middle attacker to impersonate any HTTPS server.

This bug demonstrates how a single line of C code - with no memory corruption involved - can completely break TLS security.

Renegotiation Attacks

TLS allows renegotiation - starting a new handshake within an existing connection. A vulnerability in the original renegotiation mechanism (CVE-2009-3555) allowed a man-in-the-middle attacker to inject data at the beginning of a TLS connection:

  1. The attacker establishes a TLS connection to the server
  2. The attacker sends a partial HTTP request to the server
  3. The attacker hands the connection to the real client (by forwarding the TLS handshake)
  4. The client and server renegotiate, and the client sends its own request
  5. The server sees the attacker's partial request followed by the client's request, interpreting them as one request

This allowed the attacker to prepend arbitrary data to the client's request. The fix was RFC 5746, which added a renegotiation indication extension that cryptographically binds the renegotiation to the original connection.

TLS Renegotiation

TLS renegotiation allows a new handshake within an existing connection. The original design did not bind the new handshake to the original connection, allowing injection attacks. RFC 5746 fixed this by adding a cryptographic binding that ensures renegotiation only succeeds between the same parties.

Lessons from TLS Vulnerabilities

TLS vulnerabilities cluster into a few categories, each with a different lesson:

  • Memory safety bugs (Heartbleed): Cryptographic code is still C code. Bounds checking is non-negotiable.
  • Cryptographic protocol flaws (Padding oracle, downgrade): Protocol design must account for what error handling and negotiation inadvertently reveal.
  • Implementation logic errors (goto fail, renegotiation): State machines need rigorous testing. Compilers won't catch the logic error that breaks TLS entirely.
  • Legacy compatibility (POODLE, FREAK): Every old protocol version you keep supporting is a liability. Removing weak versions and cipher suites isn't optional hygiene.

The evolution from SSL 2.0 to TLS 1.3 is essentially a long catalogue of these mistakes, each one fixed in turn. TLS 1.3 dropped CBC mode, removed RSA key transport, simplified the handshake, and added downgrade protection. The implementation still has to be correct, though — and TLS libraries remain attractive targets for security researchers precisely because the stakes are so high.