white box key recovery: a byte table keyed by its index

huntress ctf 2026, day 29 · mobile android · all three modes

tools used: android apk toolkit and timed-attempt pipeline.

"recover an equivalent key operation from challenge-owned table transformations, not a third-party protected binary." the single's apk carried its puzzle under a new codec name, table: twenty bytes of hex and an integer key, with the answer code recovered by subtracting from each byte a key that grows with the byte's position. the time trial and the mastery were computed-code apps whose dalvik code builds the code at run time.

the key insight is that a keyed transform with a known plaintext prefix is a fit, not a search. every answer begins ANS-, so the first four plaintext bytes are known; the first two fix the two parameters of a schedule k_i = a + b*i, the next two confirm it, and the rest of the code falls out. our keyed search tried constant keys only, so the first run of the single found nothing and the rule was read by hand from the puzzle; the toolkit now fits the schedule itself.

challenge shape

single         1 field    the answer code of a table puzzle in the apk's assets
time trial     1 field    the code a computed-code app releases
mastery       13 fields   one code per set: thirteen computed-code apps

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": 29, "codec": "table",
 "data": "<40 hex characters>", "key": <an integer>}

the twenty data bytes are the twenty characters of the answer code, each shifted by the key plus three times its index:

byte i of the code = (data[i] - (key + 3*i)) mod 256

by hand, with the standard library:

import json, zipfile

puzzle = json.loads(zipfile.ZipFile("white_box_key_recovery.apk")
                    .read("assets/huntress_puzzle.json"))
raw = bytes.fromhex(puzzle["data"])
print(bytes((b - puzzle["key"] - 3 * i) % 256 for i, b in enumerate(raw)).decode())

the timed apps' puzzle files said schema v2, codec analysis and a build id, and nothing else: their dex holds the computation in a class named for the challenge, and a release method turns the result into sixteen hex digits behind ANS-.

extraction method

the apk toolkit now reads table (and its synonyms sbox and schedule) as a codec step, and fits index schedules inside its keyed search even when the codec is unnamed. the fit uses the answer prefix as known plaintext:

PREFIX = b"ANS-"

def schedules(raw: bytes, op) -> list[bytes]:
    # k_i = a + b*i and k_i = a ^ (b*i), fitted on bytes 0-1, checked on 2-3
    need = [key_byte(op, raw[i], PREFIX[i]) for i in range(len(PREFIX))]
    out = []
    a, b = need[0], (need[1] - need[0]) % 256
    if all(need[i] == (a + b * i) % 256 for i in range(2, len(PREFIX))):
        out.append(bytes((a + b * i) % 256 for i in range(len(raw))))
    b = need[1] ^ need[0]
    if all(need[i] == a ^ ((b * i) % 256) for i in range(2, len(PREFIX))):
        out.append(bytes(a ^ ((b * i) % 256) for i in range(len(raw))))
    return out

key_byte solves one byte of the key from one cipher byte and one known plaintext byte for the operation at hand (subtraction, addition or xor). when the puzzle names a key, it is also tried as the schedule's first value under every step from 0 to 255, so a wrong or missing step costs nothing. a reading counts when it has the answer's shape.

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 was already in its table.

validation and answer formatting

the code must match the question's pattern, ANS- and exactly sixteen uppercase hex digits. a fitted schedule that fails its check bytes is dropped before it produces anything, and a reading without the answer's shape is not an answer. the computed codes are the ones the apps' own loops build. ANS-AB1D78DC8BA4D98C for the single, ANS-EEB9A44C90510842 for the time trial and ANS-AC9C54D9B638C3E5, ANS-9583EC90406C017D, ANS-2B1D847B7BDAC5D9 and ten more for the mastery's thirteen apps.

failed approaches and pivots

automation across modes

the time trial and the mastery's thirteen sets were computed-code apps: the interpreter answered the time trial in about a millisecond and the thirteen sets in about 0.15 seconds, solved as they downloaded. the time trial's clock went to the crash above, not to the reading.

lessons

solve times

public scoreboard · day 29 finish: below top 10

  • 0:18.1single#2 of 143 solvers
  • 1:12.7time trial#9 of 141 solvers
  • 1:16.9mastery#8 of 139 solvers
  • #61team day finishof 116 teams that cleared it, in 34:38.6
  • #5single 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; the time trial's two runs were one server attempt.

mode work to flag attempts wrong submits
single 15.4s 1 0
time trial 36.7s 1 0
mastery 2.5s 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 36.7s 13.3s
mastery 410.0s 2.5s 407.5s

where we got stuck

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

{generated by a clanker}