swift justice: a 67 mb swift elf, a base64 config literal, and answers that changed kind
huntress ctf 2026, day 8 · binary reverse engineering · all three modes
tools used: binary-analysis toolkit and timed-attempt pipeline.
the prompt: "swift binaries speak in protocols and hide their networking in plain sight. follow the symbols to the url configuration and see where this one phones home." the bundle was the cumulative one (the c and c++ elfs, the .net dll, the go and rust builds, day 6's java jar and day 7's kotlin jar) plus d08, a swift program for linux, 67 mb of elf.
the key insight: the configuration was the familiar hcfg blob, kept as one base64 string literal, while the four magic bytes HCFG also appeared in the code as an immediate operand. the decoder that validates bounds, checksum and json already rejected the immediate; what changed was where to look for the real blob in a binary this size, and how two fields that had been labels for seven days were now asked as integers.
challenge shape
d08_ fields: analysis_architecture, analysis_format, analysis_elf_class, analysis_machine, the hcfg configuration (config_campaign, config_crc32_hex, config_domain, config_mutex, config_url) and artifact_sha256_1. two older tags gained fields: d02_analysis_has_cpp_vtable and d02_analysis_has_cpp_typeinfo (true or false), and d06_/d07_analysis_compression_methods, a json array for each jar. the d08 class and machine questions use the answer kind integer ("base-10 integer with no units, separators, or explanatory text"), where the same field names on day 1 asked for labels.
artifact anatomy
the hcfg layout has not changed since day 2:
offset size field
0 4 ASCII "HCFG"
4 1 version
5 1 xor key
6 2 payload length, little-endian
8 4 crc32 of the plaintext payload, little-endian
12 n payload, single-byte xor with the key -> json
in the swift binary the whole blob is base64-encoded and stored as a string literal in read-only data. base64 encodes three bytes as four characters, so any base64 string of a blob that starts with HCFG starts with the same five characters, SENGR. the raw bytes HCFG also occur once in the code section, as an operand of an instruction; what follows them is machine code, so the length, checksum and json checks all fail there.
extraction method
the config search tries, in order: the bytes as delivered together with any decoded class-file or dex constants (jars, apks, bare dex), then base64 literals in the raw bytes. for the last step it no longer collects every base64-looking run in the file (in a 67 mb binary that was 1.2 million candidates and several seconds); it anchors on the encoded magic and decodes only the literals that start there. in plain python:
import base64, re
HCFG_B64 = b"SENGR" # base64 of b"HCFG" plus the next byte's top bits
B64_RUN = re.compile(rb"[A-Za-z0-9+/]+={0,2}")
blobs = []
at = b.find(HCFG_B64)
while at >= 0:
text = B64_RUN.match(b, at).group().rstrip(b"=")
blobs.append(base64.b64decode(text + b"=" * (-len(text) % 4)))
at = b.find(HCFG_B64, at + 1)
the decoded blob is validated exactly like a raw one (bounds, crc32, json); if two different valid configurations were found, the decoder raises instead of choosing.
the header fields come from the elf header itself:
bits = 64 if b[4] == 2 else 32 # EI_CLASS 2 -> 64, 1 -> 32
e_machine = struct.unpack_from("<H" if b[5] == 1 else ">H", b, 18)[0]
answers = {"elf_class": str(bits), "machine": str(e_machine)}
e_ident[EI_CLASS] is a class code (1 for 32-bit, 2 for 64-bit) and e_machine is a 16-bit number from the elf machine table. the integer questions want the class as the address width in bits, not the class code, and the machine as the e_machine number, not its name. has_cpp_vtable and has_cpp_typeinfo are read from the c++ abi symbols (_ZTV and _ZTI prefixes, standard-library ones excluded). compression methods are the jar's zip method ids (0 for stored, 8 for deflate in the zip spec), the distinct values over its entries in ascending order, as numbers rather than names: sorted({i.compress_type for i in zipfile.ZipFile(jar).infolist()}), dumped as compact json.
validation and answer formatting
the solver converts a value to the kind the question asks for: when the answer kind is integer, a producer that knows the field's numeric form answers in place of the label producer. the crc32 is zero-padded to eight hex digits with a 0x prefix, as the question's syntax says, and json answers are compact.
failed approaches and pivots
the single cost nine rejected values, mostly the representation of the new fields: the raw class code instead of the bit width, and method names (stored, deflated) instead of method numbers. one more was a crc32 read by hand at the raw HCFG bytes in the code section, the decoy the validating decoder skips.
the mastery failed twice. its question ids carry a set prefix (set3.d08_…), and the integer override matched the bare field name, so in the mastery it never fired and the class and machine went out as labels (x86-64, and i386 as the fallback, rejected on every set). the fix strips the set prefix before the field reaches a producer, and a test now runs every set of a mastery fixture through the integer path.
automation across modes
the mastery delivered five sets of nine members, each set with its own 67 mb elf, under a 27-second clock. the solver ran in 7.9s on the winning attempt; on day 8 we cut the fixture replay from 3.4s to 1.7s:
- header-only elf fields (class, endianness, machine, type, entry point) come from the header bytes, without starting binutils.
- the binutils runs that remain share one temporary copy of the binary instead of writing one each.
- the config decode is cached per binary: every
config_*field asked for it, 35 decodes of the same bytes in one mastery. - the sha-256 is computed alone, not with md5 and sha-1 beside it. analyzing the day tags of a set in parallel was tried and reverted: the thread pool defeated the solver's time cap.
lessons
- a magic number is a hint, not a structure: validate bounds, checksum and payload, and expect the magic to appear where the structure does not.
- in a large binary, search for the encoded form of a known prefix instead of decoding every candidate string.
- read the answer kind per question, never per field name: the same name can move from a label to a number.
- normalize id prefixes before routing a field to its producer.
solve times
public scoreboard · day 8 finish: top 10
- 1:54.0singlefirst blood, +8.0 s
- 2:33.2time trial#3 of 191 solvers
- 5:40.3mastery#4 of 186 solvers
- #7team day finishof 177 teams that cleared it, in 12:43.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 | 1m51s | 1 | 9 |
| time trial | 3s | 1 | 0 |
| mastery | 3m06s | 3 | 36 |
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 | 10.0s | 2.4s | 7.6s |
| mastery | 27.0s | 10.3s | 16.7s |
where we got stuck
- single: nine rejected values before the representation of the integer and list fields was clear.
- mastery: two failed attempts on the class and machine fields, because the set prefix hid the field name from the integer override. the attempt after the fix won.
flags: single, time trial, and mastery [redacted].
{generated by a clanker}