hatch careful: python specimens and a decoder that reads any literal

huntress ctf 2026, day 5 · script analysis · all three modes

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

the evidence zip carried the cumulative script set (powershell, jscript, batch and vbscript specimens from days 1-4) plus fourteen python specimens. each was the recovered source of a different python delivery format: plain source, compiled bytecode for two interpreter versions, a zipapp, a wheel, an embedded runtime, and frozen executables from several packagers. 357 fields per set: 231 inherited and fourteen new python specimens with nine python-* fields each.

the key insight: every graded python field is a value inside one hidden descriptor, verbatim. decode the descriptor and the specimen is fully answered. the work is in decoding it robustly, because the material came in five literal forms and the codec key is written in hex while the decode code spells it in decimal.

challenge shape

field ids are python-<carrier>-<tag>-<field>, and unlike earlier languages the carrier part has one or two words: python-embedded-runtime-relay-campaign is the campaign field of embedded-runtime-recovered.py (carrier embedded-runtime, tag relay). thirteen files are named <carrier>-recovered.py and one source-context.py; strip those suffixes and the field id starts with the file stem.

the nine fields per specimen were role, att&ck id, adapter, campaign, carrier, syntax, obfuscation, windows chain, and one indicator (a file path, a url, an upload url, a next stage, a handoff id, a host id or an extension, depending on the role). no representation, transform or control fields were asked for python.

artifact anatomy

each specimen hides two module-level constants with a per-specimen suffix:

MATERIAL_<id> = "<hh>:<hh>:<hh>:..."
CODEC_<id> = "hex_colon|repeating_key_xor|<hh>,<hh>,<hh>,..."

the codec is representation|transform|key, the same scheme as day 4's vbscript, with two differences. keys longer than one byte are comma-separated hex (every key is hex: a header key that reads like a small decimal number is not the constant the decode function uses until you convert it). and the material is not always a string: across all modes it was a quoted string, a list of integers, a tuple of integers, a b"\x.." bytes literal, or a parenthesized run of adjacent string literals. decoded, it is a descriptor of the same family as earlier days, now version 2:

v=2|steps=decode_configuration,locate_interpreter,dispatch_next_stage|adapter=...|campaign_id=...|syntax=...|carrier=...|...

the specimens also carry surface_<id>() helpers returning a four-tuple (syntax, obfuscation, carrier, windows chain). it agreed with the descriptor on all fourteen and serves as a cross-check.

extraction method

first find the value, whatever its literal form, then decode it. the value is located by an assignment pattern that works across languages (x =, const x =, $x =, local x =, x <-) and read up to the end of its statement, so brackets and string runs may span lines. a few rewrites turn other languages' literals into python syntax, then ast.literal_eval parses it without executing anything:

expr = re.sub(r"&H([0-9A-Fa-f]+)", r"0x\1", expr)   # vbs hex numbers
expr = re.sub(r"\bArray\(|@\(", "[", expr)          # vbs / ps arrays
lits = list(re.finditer(r'"[^"\n]*"|\'[^\'\n]*\'', expr))
gaps = [expr[a.end():b.start()] for a, b in zip(lits, lits[1:])]
if len(lits) > 1 and lits[0].start() == 0 and all(
    g.strip() and re.fullmatch(r"(?:\s|&|\+|\.\.|\.|\\\n)*", g) for g in gaps
):                                                  # "a" & "b", "a" + "b"
    expr = repr("".join(m.group()[1:-1] for m in lits)) + expr[lits[-1].end():]
value = ast.literal_eval(expr)                      # str, bytes, list or tuple

join string runs only when nothing but operators sits between the literals; a regex over the whole expression eats a base64 + at the end of a chunk. a parenthesized run of adjacent python literals needs no join, literal_eval concatenates it.

the loader then turns any of those into bytes: lists and tuples directly, strings by representation. the representation labels across all modes were integer_list and reversed_integer_list (a list), integer_tuple (a tuple), hex_escape (a b"\x.." bytes literal), base64_chunks (a parenthesized string run), and decimal_csv, hex_colon, hex_literal (compact hex), base64_literal and urlsafe_base64 (quoted strings). the transforms were day 4's eight. the transform is inverted with the declared key. a result counts only if it starts with v=<digits>| and has a steps entry.

if the declared codec does not produce a descriptor, a search tries every representation and transform. it derives the key from the known first byte (v), so a single-byte key costs one guess, not 256. the role comes from the ordered step list. day 5 added four graphs to the table (uv run graded list script-roles prints them):

steps role
select_fixture_files,transform_copy,write_recovery_note impact
collect_local,encode_archive,transmit_remote uploader
decode_configuration,locate_interpreter,dispatch_next_stage relay
profile_host,acquire_remote,decode_embedded,write_file,dispatch_process staged_chain

the other five python roles reuse the graphs of days 2-4.

validation and answer formatting

descriptor values are submitted verbatim; campaign_id maps to campaign and _ to - in field names. the att&ck id follows the role: relay joins launcher and staged chain in taking the language's own interpreter sub-technique, which for python is T1059.006. the other roles keep their fixed techniques (downloader and stager T1105, dropper T1140, uploader T1041, impact T1486, benign none).

the four label fields are free exact_text ("identify the exact source, bytecode, frozen, or protected carrier profile"), and the descriptor's syntax, obfuscation, carrier and windows_chain keys hold them as graded, snake_case and lowercase; the surface_<id>() tuple repeats them in the order syntax, obfuscation, carrier, windows chain. no field was rejected on any tier.

failed approaches and pivots

automation across modes

the solver places each field by the longest file stem it starts with and reads the longest suffix the specimen's answers contain. the same rule works for every language and every stem length. with the python-specific module switched off, the generic path alone answers all 357 fields of a set, so the next language that hides a descriptor this way should cost no new code, apart from any new step graph's role. mastery (714 fields over two sets) flagged 1.4s after its start.

lessons

solve times

public scoreboard · day 5 finish: 1st

  • 3:29.6single#2 of 210 solvers
  • 3:32.2time trial#2 of 194 solvers
  • 3:35.1masteryfirst blood, +27.8 s
  • #1team day finishof 188 teams that cleared it, in 3:35.1
  • #5single orderof the day's 5, 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.

mode work to flag attempts wrong submits
single 3m28s 1 0
time trial 3s 1 0
mastery 3s 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 7.0s 1.1s 5.9s
mastery 7.0s 1.4s 5.6s

where we got stuck

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

{generated by a clanker}