Secure Password Database
- Vulnerability
- Heartbleed-style buffer over-read
- Impact
- Leaks a hidden in-memory secret
- Tools
- objdump / Ghidra, Python, netcat
- Binary
- ELF64 PIE, x86-64, not stripped
Vulnerability Analysis
Root Cause: The readback loop trusts an attacker-supplied length instead of the password's real length, letting a read past the password into adjacent buffer memory that holds a hidden secret.
- CWE-125: Out-of-bounds Read — A user-controlled length drives how far past the intended data the readback loop goes
Same bug class as a real CVE: this is the same root cause as CVE-2014-0160 (Heartbleed) — OpenSSL's heartbeat extension trusted a client-supplied length field and read past the intended buffer into adjacent memory. No CVSS score applies to this lab binary itself; it is not a shipped, scored product.
References:
CWE-125
CVE-2014-0160
Summary
A C program lets you set a password and then prints it back from a 90-byte database buffer. A hidden 12-byte secret sits at offset 60 of that same buffer and is never meant to be shown. The readback loop trusts a user-supplied length for how many bytes to print — so lying about the length over-reads the buffer and leaks the secret. The secret feeds a hash check that unlocks the flag. The .rodata string heartbleed.c is the giveaway.
The program caps the readback at the real buffer size (90) but lets you choose the length — so you can ask it to print bytes past your password, straight out of memory that holds the secret.
Reversing the binary
It's PIE and not stripped, so symbols survive and main reads cleanly. The important flow:
calloc(0x5a, 1)→ a 90-byte DB buffer.- A 12-byte secret is deobfuscated (
obf_bytes XOR 0xaa) into the buffer at offset 60. - Your password is
strcpy'd to offset 0 (≤49 bytes, can't reach the secret). - It asks “How many bytes in length is your password?” →
atoi→ attacker-controlled length. - It prints
db[i]as decimals whilei < lenandi <= 0x59. - At the hash prompt, if your number equals
djb2(secret), it printsflag.txt.
Recovering the secret
Because the binary isn't stripped, the obfuscated bytes and the djb2 hash are right there. I rebuilt the secret and its hash offline:
obf = [ ... 12 obfuscated bytes from the binary, redacted ... ]
sec = bytes(b ^ 0xaa for b in obf)
print(sec.decode()) # <12-byte secret, redacted>
h = 5381 # djb2, 64-bit
for c in sec:
h = (h*33 + c) & (2**64 - 1)
print(h) # <djb2 hash, redacted>
Getting the flag
The live instance matched the binary I analysed, so the precomputed hash was enough — the password and length can be anything; only the hash is checked.
printf 'a\n5\n<djb2 hash, redacted>\n' | nc xebec.cylabacademy.net 22132
# ...
# Enter your hash to access your account!
# <flag redacted>
Fallback: leak the secret live (if the build differs)
Set length = 90 to dump the whole buffer, read the decimals at positions 60–71
as ASCII, recompute djb2 over those bytes, and submit that number.
Takeaways
- Never trust a user-supplied length when reading a buffer — that's the whole Heartbleed class.
- Unstripped binaries give you everything: symbols, the obfuscation, and the hash, all offline.
- The flag spells out the lesson: don't trust user input.
References & Standards
- Common Weakness Enumeration
- CWE-125: Out-of-bounds Read
- Related Real-World CVE
- CVE-2014-0160 (Heartbleed) — NVD entry, same bug class
- CISA Alert: OpenSSL Heartbleed Vulnerability