protocol reconstruction: an answer code inside a framed packet
huntress ctf 2026, day 28 · mobile android · all three modes
tools used: android apk toolkit and timed-attempt pipeline.
"reconstruct the app-to-backend protocol and preserve nonce and ordering semantics." the single's apk carried its puzzle under a new codec name, packet: hex of one framed message whose payload is the answer code. the time trial and the mastery were computed-code apps whose dalvik code builds frames, seals them and mixes nonces before it releases the code.
the key insight is that the codec name was new and the content was not. one hex decode of the puzzle's data shows a two-byte magic, a one-byte length, the answer code in plain ascii and a checksum byte. our decoder searched thousands of codec chains for one whose whole output is an answer, and none was, because the answer sat inside the very first reading it made. the fix has two halves: a frame parser for the codec, and a scan for the answer's shape inside every one-step reading.
challenge shape
single 1 field the answer code of a packet puzzle in the apk's assets
time trial 1 field the code a computed-code app releases
mastery 12 fields one code per set: twelve computed-code apps
labelled with days of the event from 1 to 28
artifact anatomy
the single's apk has a manifest, a small dex that only describes the challenge, a signature and the puzzle file:
{"schema": "<puzzle schema v1>", "day": 28, "codec": "packet", "data": "<hex>"}
decoded, data is one frame:
offset size meaning
0 2 magic, the ascii letters HA
2 1 payload length n
3 n payload: the answer code in ascii
3 + n 1 trailer: the xor of every byte before it
by hand, with the standard library:
import functools, json, operator, zipfile
puzzle = json.loads(zipfile.ZipFile("protocol_reconstruction.apk")
.read("assets/huntress_puzzle.json"))
raw = bytes.fromhex(puzzle["data"])
assert raw[:2] == b"HA"
n = raw[2]
payload, trailer = raw[3:3 + n], raw[3 + n]
assert functools.reduce(operator.xor, raw[:3 + n]) == trailer
print(payload.decode()) # ANS- and sixteen uppercase hex digits
the timed apps' puzzle files said schema v2, codec analysis and a build id, and nothing else. their dex holds the computation in classes named for the protocol (a frame kit and a wire state) whose methods seal a frame, seal the ordering, mix a nonce and build a session frame, and a release method that turns the result into sixteen hex nibbles behind ANS-.
extraction method
the apk toolkit reads packet by searching the frame layout instead of assuming one: the magic's width, the header bytes after it and where a one- or two-byte length sits among them, the length's byte order, and the trailer's width. a layout must tile the bytes exactly, one repeated magic per frame, and each trailer is checked against the checksum rules for its width (xor, sum or negated sum for one byte, a 16-bit sum for two, crc32 for four). the layout whose trailers verify most wins:
def unframe(raw: bytes) -> list[Frame] | None:
best = None
for layout in layouts(): # the single's layout first
tiled = tile(raw, layout) # None unless it covers raw exactly
if tiled is None:
continue
frames, verified = [Frame(p, meta) for _, p, _, meta in tiled], 0
for rule in CHECKSUMS.get(layout.trailer, ()):
ok = [rule(body) == trail for body, _, trail, _ in tiled]
if sum(ok) > verified:
verified = sum(ok)
frames = [Frame(p, meta, good) for (_, p, _, meta), good in zip(tiled, ok)]
if best is None or verified > best[0]:
best = (verified, frames)
return best[1] if best else None
several frames, back to back in data or as a json list, are put in sequence order (a json sequence field, or a header field whose values number the frames), a replayed nonce is dropped, and frames whose checksum fails are dropped before the rest; the payloads joined in that order are the reading. that is what "preserve nonce and ordering semantics" asks of a multi-frame message, though the single had one frame.
the second half does not depend on knowing the codec at all. the answer has a known shape, so every one-step reading of data (the text itself, its frames, every decoding transform, the decoded bytes as latin-1 and utf-16, inflated, xored with keys from the puzzle) is scanned for it, forwards and reversed; with nothing found, the same readings keyed by the app's own strings, then two steps deep:
ANSWER = re.compile(r"ANS-[0-9A-F]{16}")
def answer_scan(puzzle: dict, data: str) -> list[str]:
counts: dict[str, int] = {}
for reading in one_step(puzzle, data):
for code in {*ANSWER.findall(reading), *ANSWER.findall(reading[::-1])}:
counts[code] = counts.get(code, 0) + 1
return sorted(counts, key=counts.get, reverse=True) # most readings first
the timed modes ran through the dalvik interpreter we wrote for day 23: it executes the release method with an emulated framework, and every call these apps make (string building, Long.toHexString, uri helpers) was already in its table.
validation and answer formatting
the code must match the question's pattern, ANS- and exactly sixteen uppercase hex digits. from the frame reader, a layout that tiles the bytes and verifies its trailer beats one that only tiles them; from the scan, one code answers and several come back as ranked candidates. the computed codes are the ones the apps' own loops build. ANS-601D3906BB5885AC for the single's packet puzzle, ANS-C69FF9537568EA1D for the time trial and ANS-92AAC61153D2BA6B, ANS-1946A38E5D805DAE, ANS-F0DF6AA81ECE6D4C and nine more for the mastery's twelve apps.
failed approaches and pivots
the first run treated packet as an unknown codec name, searched twenty thousand readings for a chain whose output is an answer, and failed. the code was in the first reading it made, the hex decode, between three bytes of header and one of trailer. when an answer has a known shape, every intermediate reading is a place to look for it, not only the last one.
automation across modes
the timed modes never needed the frame reader: the time trial and the mastery's twelve sets were computed-code apps, and the interpreter answered them in a few milliseconds each.
lessons
- a framed payload is a magic, a length, a body and a checksum: search the layout and let the checksum choose it.
- a known answer shape is a search goal for every intermediate reading of a decoder, not just for its final output.
- "preserve nonce and ordering semantics" describes several frames: order them, drop replays, then join the payloads.
solve times
public scoreboard · day 28 finish: below top 10
- 14:12.7single#77 of 148 solvers
- 16:15.1time trial#72 of 145 solvers
- 16:18.8mastery#68 of 144 solvers
- #49team day finishof 122 teams that cleared it, in 31:21.7
- #7single orderof the day's 7, 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 when we started working on the mode to its flag. the single was submitted by hand, so its row uses the flag time the event recorded.
| mode | work to flag | attempts | wrong submits |
|---|---|---|---|
| single | 14m10.4s | 1 | 0 |
| time trial | 0.5s | 1 | 0 |
| mastery | 1.2s | 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 | 50.0s | 0.5s | 49.5s |
| mastery | 380.0s | 1.2s | 378.8s |
where we got stuck
- single, about fourteen minutes: the first run failed at release on the new codec name. the failure waited about eight minutes for us to pick it up (the same slow start as the day's other new families), and then about six more minutes passed with the puzzle's hex in view before the code inside it was recognised as the answer and submitted by hand. the answer scan finds it at release now.
- time trial, about two minutes between the single's flag and its start: it started once the framing reading was saved in the solver; the run itself flagged in 0.5s, the computed app taking milliseconds.
flags: single, time trial, and mastery [redacted].
{generated by a clanker}