$ cat writeup.md…
$ cat writeup.md…
Hack.lu2026
Task: decrypt a `VLT1` password safe; the Go+cgo vault delegates key derivation to a stripped native libkdf.so. Solution: reverse the native KDF, find strlen() truncating the binary SHA-256 digest, brute force the 2-byte effective PBKDF2 password and AES-GCM-decrypt with the header as AAD.
Vaulty is a modern password manager built on best-in-class cryptography. Can you decrypt the password safe and reveal the credentials?
The challenge archive contains three files:
| File | Description |
|---|---|
vaulty | ~3.6 MB Go binary with cgo, not stripped |
libkdf.so | ~14 KB stripped native ELF shared library |
vault.psafe | 249 bytes — the encrypted password vault |
Goal: recover the vault master credential and read the plaintext entries.
The product advertises "best-in-class cryptography". In CTF terms that is a pointer away from the cipher: the AES-GCM layer is sound, so the flaw must live in how the key is produced. The interesting artifact is therefore the tiny native KDF library, not the encryption itself.
main.parseHeader @ 0x4f3fa0)All multi-byte integers are little-endian. Header length is 44 bytes and the whole header is later used as AES-GCM Additional Authenticated Data.
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | Magic VLT1 |
| 4 | 1 | Format version = 1 |
| 5 | 1 | Reserved / padding |
| 6 | 2 | Header length = 0x2c (44) |
| 8 | 4 | PBKDF2 iteration count = 12000 |
| 12 | 16 | Random salt |
| 28 | 12 | AES-GCM nonce |
| 40 | 4 | Plaintext length = 189 |
| 44 | n | AES-GCM ciphertext (189 bytes) |
| 44+n | 16 | AES-GCM authentication tag |
Total: 44 + 189 + 16 = 249 bytes, matching vault.psafe exactly.
main.deriveKey @ 0x4f4200)libkdf.so:derive_key (native code @ 0x1160) through cgo.libkdf.so:derive_key treats the incoming 32-byte digest as a C string: it
calls strlen() on it before using it as the PBKDF2 password. strlen stops at
the first 0x00 byte, so the effective PBKDF2 password is only the leading
non-NUL prefix of the digest — in practice 1–2 bytes instead of 32.
derive_key(const uint8_t *digest /* 32 bytes */, const uint8_t *salt, ...)
len = strlen((char*)digest); // <-- truncates at first zero byte
PKCS5_PBKDF2_HMAC(digest, len, salt, 16, 12000, EVP_sha256(), key, 32);
The search space therefore collapses from 2^256 to at most 2^16 (two nonzero bytes followed by the implicit zero byte), and with the tag as an oracle the whole vault falls in milliseconds. This is a C string-handling defect — a "faulty" handling of binary data — entirely independent of cipher strength.
main.seal @ 0x4f43e0, main.openSafe @ 0x4f48e0)seal: zlib-compress the JSON plaintext → AES-256-GCM encrypt with the derived
key, the header's 12-byte nonce, and the full 44-byte header as AAD.
openSafe reverses that order. Because the header is authenticated, any
candidate key must reproduce the original header byte-for-byte, which makes the
GCM tag a perfect offline verifier.
n in 0..65535, take digest_prefix = n.to_bytes(2, 'big') — this
models a SHA-256 digest whose first two bytes are nonzero and whose third
byte (implicitly) is 0x00.key = PBKDF2-HMAC-SHA256(digest_prefix, salt, 12000, 32).decrypt_and_verify; a ValueError means the candidate is wrong.Prefixes of length 0 (empty string) and length 1 do not authenticate; a
two-byte prefix does, which confirms the strlen truncation and yields the
key-equivalent truncated digest. No master password or wordlist is required —
only a two-byte key space.
#!/usr/bin/env python3 """Exploit the native KDF's strlen(SHA256(password)) truncation. Vaulty (Hack.lu2026): libkdf.so:derive_key() calls strlen() on the 32-byte binary SHA-256 digest, so PBKDF2 only ever sees the leading non-NUL prefix (1-2 bytes). Brute force that tiny key space and verify each candidate against the AES-GCM tag, using the 44-byte header as Additional Authenticated Data. """ import hashlib import json import struct import zlib from pathlib import Path from Crypto.Cipher import AES vault = Path(__file__).with_name('vault.psafe').read_bytes() # --- Parse the 44-byte VLT1 header ----------------------------------------- assert vault[:4] == b'VLT1' and vault[4] == 1 assert struct.unpack_from('<H', vault, 6)[0] == 44 # header length rounds = struct.unpack_from('<I', vault, 8)[0] # 12000 salt, nonce = vault[12:28], vault[28:40] plain_size = struct.unpack_from('<I', vault, 40)[0] # 189 ciphertext, tag = vault[44:-16], vault[-16:] header = vault[:44] # --- Brute force the strlen-truncated digest prefix ------------------------ # A SHA-256 digest whose first two bytes are nonzero and whose third byte is # 0x00 makes strlen() return exactly 2, so PBKDF2's password is those 2 bytes. FOUND = None for n in range(65536): digest_prefix = n.to_bytes(2, 'big') key = hashlib.pbkdf2_hmac('sha256', digest_prefix, salt, rounds, 32) gcm = AES.new(key, AES.MODE_GCM, nonce=nonce) gcm.update(header) # header is AAD try: compressed = gcm.decrypt_and_verify(ciphertext, tag) except ValueError: continue FOUND = (digest_prefix, key, zlib.decompress(compressed)) break if FOUND is None: raise SystemExit('no two-byte truncated digest prefix authenticated') digest_prefix, key, plaintext = FOUND print('effective PBKDF2 password (strlen prefix):', digest_prefix.hex()) print('derived key:', key.hex()) print('plaintext size:', plain_size, '==', len(plaintext)) entries = json.loads(plaintext)['entries'] print('vault entries recovered:', len(entries)) # The entry with username "flag" holds the challenge flag. credential = next(e['password'] for e in entries if e['username'] == 'flag') print('exfiltrated credential: REDACTED') # <-- flag, intentionally withheld
Running the script authenticates a single two-byte prefix out of the 65536
candidates, decompresses the vault JSON and reveals the credential entry whose
username is flag. Expected output shape:
effective PBKDF2 password (strlen prefix): <2 bytes>
derived key: <32 bytes>
plaintext size: 189 == 189
vault entries recovered: <n>
exfiltrated credential: REDACTED
Value: flag{REDACTED}.
Use this technique when:
libkdf.so)..so for KDF/crypto work —
language-boundary and type-boundary bugs live exactly there.strlen/strcpy/printf("%s") will silently truncate it
at the first 0x00.iterations/salt/nonce/size fields — parse it and reproduce it exactly.Lesson: cryptographic primitives can be flawless while the glue around them is not. When reviewing password managers, audit the KDF input encoding — raw bytes vs. hex vs. C string — before attacking the cipher.
$ cat /etc/motd
Liked this one?
Pro unlocks every complete writeup and expanded API access. $9/mo.
$ cat pricing.md$ grep --similar