layered protections: reverse, a walking xor key, base64

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

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

"unwind obfuscation, native indirection, runtime decryption, and integrity checks while proving the same backend effect." the single's apk carried its puzzle under a new codec name, layered: base64 data and an integer key. the answer code was under three layers. it had been reversed, each byte xored with a key that grows by one per position starting from the json's key, and the result base64-encoded. the time trial and the mastery were computed-code apps whose dalvik code builds the code at run time.

the key insight is that day 29's fit still applies once the order of the bytes is right. every answer begins ANS-, so the first four plaintext bytes are known; on the decoded bytes read back to front, xor with those four letters gives 31, 30, 29, 28, a schedule k_i = a + b*i with a = 31 and b = -1. read front to back the same walk starts at the json's key, 12, and climbs: 12 plus 19 positions is 31. our keyed search tries every byte reading reversed as well as forwards, so the first run of the single found the code without being told what layered means.

challenge shape

single         1 field    the answer code of a layered puzzle in the apk's assets
time trial     1 field    the code a computed-code app releases
mastery       14 fields   one code per set: fourteen 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":"huntress.mobile.puzzle.v1","day":30,"codec":"layered","data":"TU49OyInJlUlJSQkKilcKDFOUF4=","key":12}

the base64 decodes to twenty bytes, the twenty characters of ANS- and sixteen hex digits. byte j of the decoded data is byte 19 - j of the code, xored with key + j:

code = reverse( data[j] ^ ((key + j) mod 256)  for j = 0..19 )

by hand, with the standard library:

import base64, json, zipfile

puzzle = json.loads(zipfile.ZipFile("layered_protections.apk")
                    .read("assets/huntress_puzzle.json"))
raw = base64.b64decode(puzzle["data"])
plain = bytes((b ^ (puzzle["key"] + j)) % 256 for j, b in enumerate(raw))
print(plain[::-1].decode())   # ANS-3F023201F46243CA

the walk runs 12, 13, ..., 31 over the stored bytes, and the plaintext comes out back to front: the whole walk gives AC34264F102320F3-SNA, whose reversal is the code. the search came at it from the other end: the last stored byte, 0x5e, xored with 31 is 0x41, the A of ANS-.

the timed apps' puzzle files said schema v2, codec analysis and a build id, and nothing else. the time trial's dex holds the computation in classes named for the theme (LayerKit, PeelStack, Mix) and a Release class that turns the result into sixteen hex digits behind ANS-. the mastery's fourteen deliveries were one app for each earlier mobile day, from day 1 to day 30: the day-16 one keeps part of its computation in a native library (lib/x86_64/libarena.so, reached through a jni boundary class), and the day-26 one is an .apks bundle of base.apk and feature.apk.

extraction method

the apk toolkit reads a puzzle by its codec name first. layered was not in its alias table on the morning of day 30, so the decode raised, and the keyed search took over: every byte reading of data (hex, base64, the text), each forwards and reversed, under every single-byte key, the keys of two to four bytes the ANS- prefix fixes, and the index schedules the prefix fits:

PREFIX = b"ANS-"

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

on the reversed base64 bytes, xor fits a = 31, b = 255, and the 20-byte schedule 31, 30, ..., 12 turns them into a string of the answer's shape. the search reported it as xor key=schedule 31, then 30, 29, … and the single was answered on the first run, in 0.22 seconds.

day 29's table step walks a key up from the json's own key, but it read the bytes in their stored order only, and the walk from 12 on the stored order yields the code backwards. on day 30 the toolkit learned layered (and layers, layer) as a name for that step, and the step reads every byte source reversed too, so the next such puzzle is a direct decode rather than a search.

the timed modes ran through the dalvik interpreter we wrote for day 23, with its native-piece emulation and day 26's split-bundle handling; it answered every app.

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 two check bytes is dropped before it produces anything, and a reading without the answer's shape is not an answer. the forwards and backwards readings cannot both pass: only one of them starts with ANS-. the grader accepted ANS-3F023201F46243CA for the single and ANS-3CC6D13F64CE02D8 for the time trial; the mastery's fourteen codes ran from ANS-0023412173C6208F (set 1, the day-1 app) to ANS-ED980D98894B4F01 (set 14, the day-30 app), with ANS-3E0A9EB62EDC0CC0 for the native-library app of set 8 and ANS-55A92ADC61413725 for the split bundle of set 12.

failed approaches and pivots

none on day 30. the codec name failed as expected for a name never seen, and the search behind it covered the reversal.

automation across modes

the interpreter answered the time trial in about two milliseconds and the fourteen mastery sets in about 0.19 seconds, solved as they downloaded.

lessons

solve times

public scoreboard · day 30 finish: below top 10

  • 0:03.9singlefirst blood, +0.81 s
  • 0:05.7time trialfirst blood, +1.3 s
  • 0:09.5masteryfirst blood, +2.6 s
  • #14team day finishof 52 teams that cleared it, in 2h43m
  • #2single 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 the mode's first attempt start to its flag (server times). attempts counts our solver runs.

mode work to flag attempts wrong submits
single 1.5s 1 0
time trial 0.8s 1 0
mastery 1.8s 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.8s 49.2s
mastery 440.0s 1.8s 438.2s

where we got stuck

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

{generated by a clanker}