out of bounds: two clojure builds, one index past the end

huntress ctf 2026, day 25 · binary · all three modes

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

"somewhere in here, the code reaches where it shouldn't. prove the bounds error is real, trace its reachability, and compare against the corrected twin that learned its limits." the day's new tag was a pair of java archives compiled from clojure: a vulnerable build and its corrected twin.

the key insight: as on days 23 and 24, the story is dynamic and the questions are static. the new tag's twelve fields ask for the two members' hashes, each member's format and the configuration record both builds carry; none asks about the bounds error. the error is real, one instruction long and worth reading, and the answers come from the same readers as every earlier jar.

challenge shape

single        300 fields   25 tags (d01..d25), twelve fields each; d25:
                           two member hashes, two formats, the shared
                           config and the corrected build's config
time trial    300 fields   the same over a fresh bundle
mastery      2700 fields   the same over nine bundles

artifact anatomy

the d25 members are d25--sample-vulnerable.jar and d25--sample-corrected.jar, a few kib each. each is a zip with a manifest (a Main-Class and a Created-By naming a clojure build factory) and six class files under day25/. ahead-of-time compiled clojure has a recognisable shape:

<ns>.class                 the namespace class
<ns>__init.class           its loader: load() binds every var's root value
<ns>$parse_frame.class     one class per defn, the body in invokeStatic
<ns>$_main.class           -main, a variadic function (clojure.lang.RestFn)
<ns>$fn__NNN.class         compiler helpers: registering the namespace
<ns>$loading__NNNN__auto____NNN.class

the namespace defines three vars: encoded-config, parse-frame and -main. the configuration is the event's hcfg record, base64-encoded as one string constant in the loader class's constant pool, the value load() binds to encoded-config. the question spells the layout out:

offset  size  field
0       4     "HCFG"
4       1     version
5       1     xor key
6       2     payload length, little-endian
8       4     crc-32 of the decoded payload, little-endian
12      n     payload: json, each byte xored with the key

the two builds carry byte-for-byte the same record.

the bug is in parse-frame. reconstructed from the bytecode, the vulnerable build is

(defn parse-frame [frame]
  (nth frame 4))

which compiles to a single call of RT.nth(Object, int) with the index 4. the corrected build is

(defn parse-frame [frame]
  (if (< 4 (count frame))
    (nth frame 4)
    -1))

whose bytecode pushes the long 4, calls RT.count on the frame, compares the two with lcmp and returns a boxed -1 when 4 is not below the count. two-argument nth on a vector throws IndexOutOfBoundsException when the index is past the end; the three-argument form would return a default, and the vulnerable build does not use it.

reachability is in -main. it reads a host-model environment variable (with a default) and a second environment variable that turns the fault on. with the fault off, the frame is a five-element vector and index 4 is its last element; with it on, the frame is a two-element vector and index 4 is past the end. neither build's -main has an exception handler (javap shows no exception table in either), so in the vulnerable build the exception escapes -main; the corrected build returns -1, and the json trace line -main prints reports the fault as contained. with the fault off, both builds print the same line, whose branch and event count come from the host model. that is the proof the prompt asks for: the old function reads past the end of a frame the program itself can build, and the new one checks the length first.

extraction method

nothing new: the binary toolkit answers each field by its producer.

for cls in class_files(jar):
    for text in utf8_constants(cls):
        if len(text) >= 80 and BASE64.fullmatch(text):
            raw = base64.b64decode(text)
            record = hcfg(raw)          # None unless magic, bounds and crc agree
            if record is not None:
                return json.loads(record.payload)

by hand, unzip -p d25--sample-corrected.jar 'day25/*__init.class' | strings -n 80 prints the loader's long constants; the one starting SENGR is the base64 of the record.

validation and answer formatting

the hcfg record is accepted only when its magic, its length and the crc-32 of the xor-decoded payload agree. the shared fields require the two builds' records to be byte-for-byte equal before using the common value; as on day 24 our producer takes the first valid record and does not compare the two. we checked separately: in all eleven bundles of the winning runs (the single, the time trial and the mastery's nine) the two records were identical and crc-valid. the configuration values are submitted as the decoded json stores them, without quotes ("exact case-sensitive artifact-derived text only"): campaign BR25-000, domain node-000.day25.example.invalid, mutex Global\HuntressBR25_000 and url https://node-000.day25.example.invalid/api/BR25-000 for the single's bundle, and the same four for the corrected build's fields. the time trial's record and the mastery's nine followed another naming pattern, e.g. campaign BR25-8A7F66B2, domain cache-4988a6a5.day25.example.invalid, mutex Global\HuntressD4478F9EEDE8 and url https://edge-c87b8563.day25.example.invalid/relay/aa0d2e6c29 for the time trial.

failed approaches and pivots

none on day 25.

automation across modes

the compound producers answered all 25 tags in every bundle, about half a second for a 300-field bundle once it was on disk. about half of each mode's time was the bundle download (tens of megabytes each), nine of them for the mastery.

lessons

solve times

public scoreboard · day 25 finish: below top 10

  • 0:07.3single#2 of 155 solvers
  • 0:12.4time trial#2 of 152 solvers
  • 0:21.6mastery#2 of 151 solvers
  • #11team day finishof 138 teams that cleared it, in 6:15.3
  • #4single orderof the day's 8, 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 start on the game master to its correct submit.

mode work to flag attempts wrong submits
single 5.1s 1 0
time trial 2.9s 1 0
mastery 7.1s 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 80.0s 2.9s 77.1s
mastery 595.0s 7.1s 587.9s

where we got stuck

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

{generated by a clanker}