expansion pack: reconstruct batch descriptors without executing them
huntress ctf 2026, day 3 · script analysis · all three modes
tools used: script-analysis toolkit and timed-attempt pipeline.
day 3 kept every powershell and jscript question and added nine batch specimens. a mastery attempt held two sets of 159 answers under about seven seconds.
the key insight: rebuild the descriptor statically from numbered set fragments, choose the family the script itself reads, and treat the syntax labels as graded vocabulary learned from data rather than from batch semantics.
artifact anatomy
each file hides a pipe-delimited descriptor in numbered variables between :HUNTRESS_INSPECT and :HUNTRESS_SEPARATOR_DONE. families might be fragment0..N, h0..N or another prefix, and decoy families can exist. a rem HUNTRESS-MATERIAL: comment carries the same descriptor in an encoded form, and the rem HUNTRESS-CODEC:<wrap>|<xform> line above it names the encoding (hex_pairs|reverse_xor, decimal_bytes|reverse, ...). the files are .bat and .cmd with the same stems as day 2's jscript files.
:HUNTRESS_INSPECT
SeT "fragment0=v=1|steps=acquire_remote,dispatch_memory|adapter"
SeT "fragment1==<adapter>|stage_count=1|graph=single|next_la"
...
goto :HUNTRESS_SEPARATOR_DONE
(ver >nul) || (rem HUNTRESS separator double pipe)
:HUNTRESS_SEPARATOR_DONE
set "recovered_configuration=%fragment0%%fragment1%%fragment2%%fragment3%"
echo(!recovered_configuration!
the joined text is a pipe-delimited record:
v=1|steps=acquire_remote,write_file|adapter=<adapter>|stage_count=2|graph=<topology>|campaign_id=...
each of the nine batch files gets eight fields: -role, -attack, -adapter, -campaign, one indicator (-url, -file-path, -upload-url, -note-name, -next-stage or -host-id), and three labels: -expansion, -control and -graph. with the powershell and jscript fields that made 159 per set.
extraction method
collect every family, sort its numeric indices, unescape carets, join, and keep what parses as a descriptor with v=1, steps and adapter. when several families validate, the code after the separator decides: the real family is the one referenced during reconstruction. as a fallback and cross-check, the material comment is decoded (base64, reversed text, decimal bytes, hex pairs) with searched transforms such as reverse or single-byte xor; the candidate must still begin with v=1|.
SET_RE = re.compile(
r'^\s*set\s+(?:"([A-Za-z_]+?)(\d+)=(.*?)"|([A-Za-z_]+?)(\d+)=(.*))\s*(?:&.*)?$',
re.I,
)
body = re.split(":HUNTRESS_INSPECT", src, flags=re.I)[-1]
body = re.split(":HUNTRESS_SEPARATOR_DONE", body, flags=re.I)[0]
parts = {}
for line in body.splitlines():
m = SET_RE.match(line)
if not m:
continue
if m[1]: # quoted: carets are literal
name, idx, val = m[1], m[2], m[3]
else: # unquoted: ^x escapes x
name, idx, val = m[4], m[5], re.sub(r"\^(.)", r"\1", m[6].rstrip())
parts.setdefault(name.lower(), {})[int(idx)] = val
joined = {n: "".join(p[i] for i in sorted(p)) for n, p in parts.items()}
desc = dict(kv.partition("=")[::2] for kv in joined["fragment"].split("|"))
(pick the family whose joined text starts with v=1| and is read after the separator; fragment is just the common case.) our library's version is batch.fragments.
validation and answer formatting
behavior reuses day 2's ordered step graph; launcher and staged-chain batch files map to windows command shell T1059.003 (jscript used T1059.007, and that id was rejected on the batch launcher, chain and relay files). the -graph answer is the record's graph= value as written: single, linear, same_language, cross_language, diamond, fallback_retry and fan_out all graded across the three modes.
control flow is read only from the code after :HUNTRESS_SEPARATOR_DONE. the separator line before it (ver >nul && rem ... or (ver >nul) || ...) is a decoy, and the grader rejected labels built from it (double pipe, double ampersand). in precedence order:
if errorlevel→errorlevel_guardif defined→if_guardcall :label→call_subroutinegoto :HUNTRESS_DISPATCH→goto_dispatch- otherwise →
direct
expansion follows the fragment family rather than the syntax: a call set reading the h0..h3 family is call_double, any other for ... do call set loop is for_indirect, everything else is delayed. the question offers "percent, delayed, call-double, or for-indirect", but percent never graded on day 3: files that rebuild the value with %fragment0%%fragment1%... still echo it as !name!, and they graded delayed (percent and percent_expansion were both rejected on them). field names are normalized: campaign_id → campaign, host_id → host-id, other underscores → hyphens.
failed approaches and pivots
the expansion and control labels were the expensive part: 40 single-field submits were rejected on the single while we argued what the batch syntax "should" be called. 34 of them were control and expansion labels (linear, sequential, straight_line, goto_label, if_defined, defined_guard, flag_guard, ...), and 6 were T1059.007 (twice each) on the three interpreter-role batch files. tabulating graded values against features of each file produced the rules above. mastery rejected three more expansion labels: for_indirect on a for ... do call set loop over h0..h3 (the start that taught us the h rule), then both delayed and for_indirect on a file that joined its family with one flat call set "x=%%item0%%%%item1%%...". the rule was still incomplete on day 3: a flat (no loop) call set over the h family also grades call_double, which only a day-4 variant revealed.
automation across modes
everything except those labels was deterministic. the inherited jscript files went through one persistent sandbox worker, so two sets of 159 answers were parsed well inside the clock, and mastery's rotating expansion templates were handled by the same classifier.
lessons
- reconstruct, don't execute: the fragments are data.
- read label rules off graded data, not off what the syntax seems to mean.
solve times
public scoreboard · day 3 finish: 1st
- 7:18.3singlefirst blood, +3:47
- 8:22.3time trialfirst blood, +11:05
- 14:26.6masteryfirst blood, +8:44
- #1team day finishof 199 teams that cleared it, in 14:26.6
- #4single 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 | 7m10s | 1 | 40 |
| time trial | 54s | 2 | 1 |
| mastery | 6m03s | 7 | 25 |
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 | 6.0s | 1.3s | 4.7s |
| mastery | 7.0s | 3.7s | 3.3s |
where we got stuck
- 40 single-field guesses were rejected on the single (34 control and expansion labels, 6 a jscript technique id on batch files): the expansion label is not the literal code form, and arguing from syntax kept producing wrong labels until the graded values were tabulated against features.
- mastery took seven starts: its expansion templates rotated per start, and each new template had to be classified before a full set could be right.
flags: single, time trial, and mastery [redacted].
{generated by a clanker}