custody.db
custody.db-wal

Forensics • 400 points (Static) • Medium

The custodian revoked a seal and deleted the record. The database disagrees about how gone it is. Challenge Artifacts: custody.db custody.db-wal Submit Flag*

Dr.Binary
todo_write
run_sandbox

A SQLite database with its WAL — classic WAL divergence forensics. The WAL already shows seal-B and "shift note" strings. Let me parse both files at the page level.

run_sandbox

Page size is 2 bytes at offset 16 — my mistake. Now let me dump every page version (DB and each WAL frame) and decode the b-tree cells.

run_sandbox

Now I see structure: interior pages with clerk records and blobs, leaf pages of "shift notes", and the WAL contains a seal-B cell. Let me write a proper SQLite page/cell parser and also try opening the DB with and without the WAL.

run_sandbox

Both tables revealed. The seals blobs are zlib streams (78 da). Note the nowal output was truncated — let me diff the two views compactly and decompress the blobs.

run_sandbox

Key facts so far:

  • WAL applied (withwal): notes row 7 = "seal-B revoked by custodian", and seal id 32 M.Bhatt part=B with blob seal-B:revoked exists.
  • DB only (nowal): note 7 = ordinary "shift note 6", and seal 32 is absent.

The WAL has two different versions of page 18 (frames 2 and 3). Let me verify the WAL checksum chain — which frames SQLite actually trusts — and dump both page-18 versions cell by cell.

run_sandbox

Interesting — my header-checksum computation fails, yet sqlite3 clearly recovered WAL content (the two views differ). Let me test byte-order variants and empirically check what Python's sqlite3 actually honors.

run_sandbox

The checksums are little-endian (what x86 SQLite uses — magic low bit 0 → native). So the WAL is valid to SQLite. Now let me walk the frame chain with the correct byte order and find where it breaks:

run_sandbox

All 4 frames are checksum-valid, so SQLite's view = DB + final frames. The interesting divergence must be in older page versions (frames 1-2 vs 3-4) and stale bytes in unallocated space. Time for a full record-level parser:

run_sandbox
run_sandbox

Page 1 has a 100-byte database header before the b-tree header. Let me handle that properly:

run_sandbox

The old broken block still runs first. Rewriting the script cleanly:

run_sandbox

Schema cell likely spills to an overflow page. Let me make the parser resilient (raw hex fallback + overflow following):

run_sandbox

Now the picture is emerging. Page 13 has a 75-byte freeblock containing a deleted seal record (holder M.Bhatt, part A, blob with a zlib stream), and page 14's freeblock holds deleted clerk3. Let me dump the WAL frame versions and all freeblocks, and decompress every zlib blob found:

run_sandbox

Found it. WAL frame 2 (the older, overwritten version of page 18) holds seal 32 M.Bhatt part B with the original blob — 24-byte prefix + a zlib stream — which frame 3 later replaced with the seal-B:revoked tombstone. Decompressing it:

run_sandbox

Both halves of the flag are recovered. Let me assemble the final proof:

run_sandbox
todo_write

Flag

CACTF{fr33bl0ck_4nd_w4l_r3m3mb3r_wh4t_y0u_d3l3t3d}

How it was solved

The database "disagrees about how gone it is" in two places — exactly the two techniques the flag text names:

1. Freeblock (main DB) — the deleted seal-A record

  • custody.db contains seals(id, holder, part, blob); ids 5 and 9 are missing from both views.
  • Page 13 (seals leaf) has a 75-byte freeblock @0x191. Its payload still holds the un-overwritten cell: [NULL, 'M.Bhatt', 'A', blob] — deleted seal id 5 (only the first 4 bytes, over-written by the freeblock header, are lost).
  • Its blob = 24 junk bytes + zlib stream → seal-A:CACTF{fr33bl0ck_4nd_ (page 14's freeblock similarly holds the old clerk3 row).

2. WAL — the overwritten seal-B record

  • The WAL has 4 checksum-valid frames (little-endian checksums, as x86 SQLite uses): page 4 twice, page 18 twice. SQLite recovery applies last version per page.
  • Frame 2 (page 18) has seal 32 M.Bhatt part B with the original blob → zlib-decompresses to seal-B:w4l_r3m3mb3r_wh4t_y0u_d3l3t3d}.
  • Frame 3 later rewrote the same page with a tombstone blob seal-B:revoked — and frame 1 of page 4 rewrote note 7 to "seal-B revoked by custodian". So a normal reader sees a "revoked" placeholder, while the real record survives only in the older WAL frame.

Concatenating the two halves: CACTF{fr33bl0ck_4nd_w4l_r3m3mb3r_wh4t_y0u_d3l3t3d} — literally "freeblock and WAL remember what you deleted".