jack in the box: unpacking a hashed binary overlay

huntress ctf 2026, day 19 · binary reverse engineering · all three modes

tools used: binary analysis toolkit and timed-attempt pipeline.

the prompt: "there's a payload hiding inside this binary, and a little decoder stub wound up to pop it out. find the stub, watch it work, and catch what's inside, statically." the cumulative bundle gained a nineteenth tag. the older tags kept the fields they had already accumulated, while the new tag placed its familiar configuration record inside a packed elf overlay.

the key insight: the question text described a complete container, not merely an obfuscation hint. every configuration question spells it out: "find the final pk19 overlay. read k1 at +5, k2 at +6, packed length u32le at +8, the 32-byte unpacked sha-256 at +12, and packed bytes at +44. for each packed byte compute ror8(byte xor k2,3) xor k1; verify the unpacked sha-256 and use the hcfg record at unpacked offset 0." the bytes after the elf section table held exactly that header: two keys, a packed length and the sha256 of the unpacked payload. that digest turned reconstruction into a verified byte transform rather than a plausibility test.

challenge shape

single        228 fields   one bundle, tags d01-d19
time trial    228 fields   a fresh bundle
mastery      1140 fields   five bundles

the existing readers answered 220 fields. the eight they missed all belonged to the d19 tag, whose other four fields (one sha-256, format, architecture, machine) the old readers already covered:

d19_analysis_config_campaign       d19_analysis_config_url
d19_analysis_config_crc32_hex      d19_analysis_hcfg_version
d19_analysis_config_domain         d19_analysis_overlay_offset
d19_analysis_config_mutex          d19_analysis_overlay_size

artifact anatomy

the d19 member is an elf followed by an overlay. the overlay begins exactly where the elf section-header table ends and consumes the remainder of the file:

offset  size  meaning
0       4     overlay magic, ASCII "PK19"
4       1     overlay version
5       1     first byte key
6       1     second byte key
7       1     reserved
8       4     packed length, little-endian
12      32    sha256 of the unpacked payload
44      N     packed bytes

the unpacked payload begins with the lane's usual HCFG record: magic, version, one-byte xor key, plaintext length, crc32, and xor-encoded json. the overlay therefore adds a carrier around the record; it does not change the configuration format inside it.

extraction method

for an elf, the expected start of appended data is structural:

overlay_at = e_shoff + e_shentsize * e_shnum

the parser verifies the four-byte magic there, reads the little-endian packed length, and requires the header plus packed body to end at the file boundary. each packed byte is then reversed independently. the whole unpack in standard-library python, for a 64-bit little-endian elf:

import hashlib, struct
data = open("d19--variant-NNN.elf", "rb").read()
(e_shoff,) = struct.unpack_from("<Q", data, 40)    # elf64 header: e_shoff
e_shentsize, e_shnum = struct.unpack_from("<HH", data, 58)
at = e_shoff + e_shentsize * e_shnum            # d19_analysis_overlay_offset
assert data[at : at + 4] == b"PK19"
k1, k2 = data[at + 5], data[at + 6]
(length,) = struct.unpack_from("<I", data, at + 8)
digest = data[at + 12 : at + 44]
packed = data[at + 44 : at + 44 + length]
assert at + 44 + length == len(data)

def ror3(x):
    return ((x >> 3) | (x << 5)) & 0xFF

payload = bytes(ror3(b ^ k2) ^ k1 for b in packed)
assert hashlib.sha256(payload).digest() == digest
overlay_size = len(data) - at                   # d19_analysis_overlay_size
assert payload[:4] == b"HCFG"                   # the usual record from here on

after applying that translation to every byte, the solver hashes the entire result and compares it with the digest stored in the overlay header. only a matching payload is passed to the existing hcfg decoder, which validates its own bounds, crc32 and json before exposing configuration fields.

the overlay offset is the header magic's file offset. its size is the bytes from that offset through the end of the member, including the header and packed body. offset 10808 and size 424 for our member, the same pair in the time trial and all five mastery bundles; the snippet above prints yours.

validation and answer formatting

the parser uses four independent checks:

  1. the overlay starts at the parsed container boundary;
  2. its packed length is nonzero and fits the member exactly;
  3. the unpacked sha256 equals the digest in the header;
  4. the inner hcfg record passes its length, crc32 and json checks.

the new values follow their question syntax: the overlay offset, overlay size and hcfg version as base-10 integers; the crc32 as 0x plus eight lowercase hex digits ("preserve the field's required zero padding"); the configuration strings as the json holds them, without quotes. the format question is an enum (elf, pe, pe_cli, jar, wasm, neko_bytecode); the d19 member graded elf, and its architecture and machine x86-64.

failed approaches and pivots

automation across modes

the timed variants changed the keys, packed bytes and configuration; the overlay offset and size stayed the same. the parser derived each value from that member's elf headers and overlay. mastery applied the same process independently to five bundles.

the reusable reader also handles a new four-character overlay magic by trying bounded compositions of xor, addition, subtraction, rotation and complement operations. a candidate is accepted only when it reproduces the stored sha256, so the search cannot promote merely readable bytes.

lessons

solve times

public scoreboard · day 19 finish: top 3

  • 0:54.4single#3 of 169 solvers
  • 0:57.9time trial#2 of 165 solvers
  • 1:04.4masteryfirst blood, +14.3 s
  • #3team day finishof 153 teams that cleared it, in 17:56.2
  • #5single orderof the day's 8, by our flag time

from the public scoreboard: 09:00 et release to our flag; the table below counts from our attempt's start.

from the mode's first start on the game master to its correct submit.

mode work to flag attempts wrong submits
single 52.2s 1 0
time trial 2.4s 1 0
mastery 4.0s 1 0

the clock

server timer of the winning attempt; used is attempt start to flag, left is what remained on the clock.

mode time available time used time left
time trial 80.0s 2.4s 77.6s
mastery 325.0s 4.0s 321.0s

where we got stuck

flags: single, time trial, and mastery [redacted].

{generated by a clanker}