\n\n\n\n\n\n\n\n\n\n\n
flawopen.com/Simulators/Heartbleed Buffer Overread
In-browser interactive memory model and packet simulator demonstrating how unvalidated TLS Heartbeat length fields trigger adjacent server heap memory overreads.
Imagine sending a single 4-letter word 'BIRD' to a trained parrot and saying: 'Repeat back my 4-letter word, but make your answer 64,000 letters long.' The parrot squawks 'BIRD' and then immediately starts babbling the next 63,996 letters stored in its recent memory—including secret passwords, private SSL keys, and personal messages spoken by other visitors. In Heartbleed, OpenSSL trusted the client's claimed message length without checking how long the packet actually was, copying raw server memory straight back to the attacker.
Attacker connects to TLS server and sends a Heartbeat Request containing a 1-byte payload ('A') with length field set to 0xFFFF (65,535 bytes).
OpenSSL reads 16-bit length via n2s(p, payload) without verifying that 1 + 2 + payload + 16 <= rrec.length.
Server allocates a full 64KB response buffer based on the client's claimed size and prepares the reply header.
Server executes memcpy(), overreading 64KB past the 1-byte packet into adjacent heap memory and returning private keys and session tokens.
/* Read 16-bit length directly from client packet without bounds check */
n2s(p, payload);
pl = p;
/* Allocate reply buffer based on client's claimed size */
buffer = OPENSSL_malloc(1 + 2 + payload + padding);
bp = buffer;
/* BUG: Copies up to 64KB of adjacent server heap memory! */
memcpy(bp, pl, payload);
r = ssl3_write_bytes(s, TLS1_RT_HEARTBEAT, buffer, 3 + payload + padding);
/* Read 16-bit length from packet */
n2s(p, payload);
pl = p;
/* FIX: Validate that claimed payload does not exceed actual received record length */
if (1 + 2 + payload + 16 > s->s3->rrec.length)
return 0; /* Silently discard malformed heartbeat */
buffer = OPENSSL_malloc(1 + 2 + payload + padding);
bp = buffer;
memcpy(bp, pl, payload);