Tactical LogHuntress CTF 2026 // team archive

Days / Day 30 / Binary RE / SHA1-Hulud

DAY 30//LANE: BINARY RE//STATUS: CORRECT x1

SHA1-Hulud

Binary RE SSTTMM Modes reported CORRECT in this write-up

SHA1-Hulud (Day 30 special, binary-reverse-engineering-day-30-sha1-hulud)

Flag: Decodedflag{2ff66ea0d4ca257322ea315657ee784f} GM result: CORRECT (solved_by Blandman3, 2026-10-30T16:09:25.943Z, Single Solve only - no TT/MM for this special). Verified locally: sha1-hulud.exe (challenge artifact, not published) prints correct, the flag is flag{2ff66ea0d4ca257322ea315657ee784f}.

A full read-the-game writeup, not a transcript. The goal is: next time a protected standalone RE binary lands in the lane, we skip the mistakes and go straight to the right pipeline. Everything general has been moved out of this file into challenges/_lib/binary_kit/ and challenges/_lib/kb/binary_veh_rust_playbook.md.


1. What the artifact actually was

sha1_hulud.zip (challenge artifact, not published) (sha256 a4e97ad6...3df4843709e5, password infected) -> sha1-hulud.exe (challenge artifact, not published), 632,320 bytes, PE32+ x86_64 Rust console app. It prompts What is the flag?, reads one line of stdin, computes for ~3.5 s on every input, and prints nothing on wrong answers. Exit code is always 0.

That silence-on-wrong is deliberate: the success message is XOR-decrypted with input-derived state, so a wrong input produces unprintable bytes that never get flushed.

2. The layers inside it (lid off)

  1. Anti-debug. NtSetInformationThread(ThreadHideFromDebugger), NtQueryInformationProcess DebugPort / DebugObjectHandle / DebugFlags, PEB BeingDebugged and NtGlobalFlag, heap flags, NtGetContextThread reading DR0-DR7, NtQuerySystemInformation kernel-debugger class, plus a TF single-step trap that must reach its own VEH. Every result feeds the key schedule, so attaching a debugger silently corrupts the computation instead of being caught.
  2. VEH-driven control flow. RtlAddVectoredExceptionHandler(1, 0x140065baa) installs a handler that branches on a global token ([0x140098ae0]): INT3 writes R15 = fault_addr; single-step tracing updates R11; access violation redirects RIP = RDI; #UD also redirects RIP = RDI. Those redirects are the control flow for whole stretches of the program.
  3. Anti-tamper. Two 45,000,000-iteration mixing loops over constant data XOR-feed the SHA1 IV constants used downstream. This is the fixed ~3.5 s on every input. Patching either loop changes the keys.
  4. Four self-modifying SHA1-variant compressors at 0x140001080, 0x140010840, 0x14001dfc0, 0x14002b840. Each is a 77-byte stub whose body decrypts one instruction slot at a time, executes it, re-encrypts. 80 standard-K rounds, non-standard rotations and schedule, and each of the four is a DIFFERENT function. These are called ~16,000 times during a run and derive every per-block key.
  5. Block cipher check. message = u64(len) || input, zero-padded to 16-byte blocks. Two passes:
    • Stage A (forward CBC). 16 rounds of a 128-bit ARX cipher: splitmix round keys, rotation table at 0x140087e40, xorshift (10,21) / (14,33), Klimov-Shamir T-function x -> x + (x^2 | 5) as the nonlinear step. Block i's key is derived from the preceding block's output - the "worm chaining" that makes block-by-block recovery necessary.
    • Stage B (reverse CBC). Same cipher structure with a constant key, round-constant seed 0xb19e19b36281f0b9 + i*0x33c3366c503e1720, rotation table 0x140087ee8, xorshift (30,26) / (24,29).

    Stage-B bytes are then XOR'd with a fixed keystream and compared against eight stored records in a 16 KB .rdata table. The compare loop is xor bl,sil; xor bl,dl; or [acc],bl - a constant-time compare where acc == 0 iff every byte matched.

  6. Success output. Decrypted embre XOR string .rdata[0x14008838e] XOR .rdata[0x1400883a3] -> correct, the flag is - printed verbatim followed by input\n.

Two of the eight compare records decode to decoys when inverted: "flag{thi..." and "your fla...". Record 5 is the real flag; record 4 is a 16-byte sentinel len=5 body="\x0f\x08=db" that gates the check.

3. How we actually solved it (the method)

Debugging was off the table from the second check (ThreadHideFromDebugger + VEH + DRx reads), so the whole arc was snapshot the real process after the anti-tamper loops, then continue in a Unicorn emulator with the right stand-ins, then model and invert. Concretely:

  1. Static recon with radare2, capstone, and Ghidra headless. Confirmed: Rust, embre (crypt path in strings), .xsobf orphan section, VEH handler, TLS AHash seeding at 0x1400637df, 7 inlined SHA1 IV sites, hashed-API resolver fcn.140064480(dll_hash, api_hash) with kernel32 hash 0x12d69cb1.
  2. Snapshot (solver/snapshot.py). CreateProcess the exe with a pipe, wait for the main thread's RIP to leave the loop window 0x481d0..0x48280, SuspendThread, dump every committed region (~37 MB) + full CONTEXT + TEB + loaded modules + input-string addresses to snap/regions.bin (challenge artifact, not published) and snap/meta.json.
  3. Emulate (solver/emu.py). Unicorn resumes from the snapshot. Three things that had to be reimplemented because Unicorn / a bare x86 model does not provide them:
    • VEH semantics. Reimplemented the handler's branches in veh(code, exc_addr, info) so INT3/#UD/single-step/AV match the real Windows kernel's delivery of the right fields to the handler.
    • Syscall table. Parsed ntdll exports out of the snapshot, mapped SSNs to names, answered the anti-debug ones ("no debugger"), returned 0 for the rest.
    • AVX ntdll helpers. Unicorn has no AVX. Hooked memset, memcpy, memmove, memcmp, wcslen, wcsnlen, strlen, strnlen at their ntdll export addresses with Python stand-ins. Fixed the AV-at-ntdll crash that otherwise happened in wcslen.
  4. Trace-and-replay the self-decrypting SHA1 copies (solver/hulud_compress.py, solver/trace_sha1.txt (too large to publish; 3450 KB) plus the three siblings). Unicorn mis-handles in-place self-modifying code even with per-write cache invalidation. The fix: single-step the first call to each of the four copies in the emulator, record every executed instruction's bytes AS THE CPU SAW THEM, lift the ~2000-op data path into a plain Python register/memory loop (make_runner). Validated 6/6 against subsequent real calls per copy. From that point every SHA1 call runs in Python; the emulator finishes in ~45 s instead of hanging.
  5. Model stage A and stage B in Python (solver/hulud_cipher.py, solver/hulud_model.py). The T-function x -> x + (x^2 | 5) is a permutation on u64 and invertible bit by bit (ks_inv). The two xorshift primitives invert as a short fixed-point iteration. The forward model was verified against emulator logs for every observed call (stage-A 4/4 blocks, stage-B 3/3 blocks).
  6. Pull the compare target. Probes (solver/diff_probe.py, solver/iter_probe.py, solver/cipher_probe.py) logged the per-byte compare operands and the iterated raw-output bytes for each of the 8 groups. The target for group g is ks1 ^ sil ^ dl where ks1 is a constant keystream (fixed in all runs); every byte known.
  7. Invert block by block (solver/solve_hulud.py, solver/step_solve2.py). Block 0's stage-A key is fixed, so block 0 inverts straight to "flag{2ff". Block 1's key depends on block 0, so we re-run the emulator with Decodedflag{2ff00000000000000000000000000000}, read block 1's new key, invert -> "66ea0d4ca257322e". Repeat for block 2: "a315657ee784f}". Three emulator passes.
  8. Verify on the real binary, then GM.submit.

4. What we recognized (the signals that would have cut hours)

In order of how much time they would have saved if we had looked at them first:

  • AddVectoredExceptionHandler in the imports plus the TLS callback at 0x1400637df. These two together say "control flow lives in the handler; do not attach a debugger."
  • .xsobf custom PE section with ZERO RIP-relative LEAs from .text into it. An orphan section is almost always an obfuscator stash; the references happen through computed addresses or through code the loader patches.
  • Seven inlined SHA1 IV sequences (01 23 45 67 ... 89 ab cd ef within 32 bytes). More than one copy of a SHA1 schedule in .text is a tell for "worm" style per-call KDFs, not for a legitimate hashing routine.
  • The 45M-iteration counter immediate (cmp r9, 0x2aea540) in .text. Any cmp reg, imm32 with imm in the tens of millions is an anti-tamper burn-loop; snapshot AFTER it, not before.
  • 23 hashed-API resolver call sites (mov ecx,imm32; mov edx,imm32; call <same> repeated). This is fcn.140064480(dll_hash, api_hash) style. If you see this pattern, the exe is doing its own imports; let it, snapshot after.
  • The embre/crypt/src/xor.rs cargo path in strings. That names the string obfuscator; the layout is a pair of const BYTES[N] and const KEY[N] arrays near each other in .rdata. Grepping and XORing neighbours is a one-liner.

The triage tool (challenges/_lib/binary_kit/triage.py) now reads all of these in 5 ms and prints a plan. On SHA1-Hulud it says, verbatim: "FULL-RE: this is NOT a fields challenge; do not hand to autosolve_binary - open under binary_kit workflow".

5. What slowed us down, and how it's now fixed

  • Lots of guessed inputs (Oasis lyrics, "trickortreat", "happyhalloween", hex-of-SHA1-Hulud, iterated SHA1 of common seeds, etc). The exe compares stageB(stageA(len||input)) against a fixed 16-byte-stride table; the input is a 32-char hex suffix, so no English guess was ever going to hit. Triage would have said that from byte 1. Fixed: triage.
  • A long detour trying to brute-force a 20-byte H1 that turned out to be arbitrary emulator-adjacent heap bytes, not the compare target. Fixed: the playbook says "pull the compare target from the trace, don't guess what's in heap."
  • Multiple failed hardware-breakpoint attempts inside the real process. The ThreadHideFromDebugger + DRx checks defeat every attached-debugger method. Fixed: snapshot-and-emulate is now the first thing in the playbook, not the last.
  • Unicorn hangs on self-decrypting SHA1. Even with ctl_remove_cache(addr,size) per write, the four 77-byte copies produce stale blocks. Fixed: trace once, replay the data path.
  • AVX wcslen crash inside ntdll. Fixed: entry-point stand-ins for memset/memcpy/memmove/memcmp/wcslen/wcsnlen/strlen/strnlen.
  • Four separate SHA1-variants - we assumed one function at first and the replay misfired for calls through the other three. Fixed: the replay now carries one trace per routine VA and dispatches by entry address.

6. Faster next time (budget targets)

With the kit and playbook now in place:

stepfirst time (this challenge)next time budget
triage + decide shape~1 hour of guessing5 ms (automatic)
grep for crate paths + XOR obvious30 min1 min
snapshot after anti-tamper45 min (figuring windows)10 s
build/validate emulator90 min20 min
trace-and-replay inner routines60 min10 min
model and invert60 min15 min
verify + submit5 min1 min
total end-to-end~4 hoursunder 30 min

If the next binary uses litcrypt / obfstr / rust-code-obfuscator instead of embre, add a lookup in binary_kit/README.md with the pair-storage layout of that crate; everything else carries over.

What we learned

  • Solved - Single Solve: GM CORRECT Decodedflag{2ff66ea0d4ca257322ea315657ee784f}. No TT/MM for this special.
  • Learned - (1) VEH + ThreadHideFromDebugger + DRx reads means snapshot-and-emulate, not attach-and-step. (2) Unicorn mis-handles in-place self-modifying code even with cache invalidation - trace once, replay the data path. (3) Unicorn has no AVX; ntdll string/mem routines need Python stand-ins at the export entries. (4) Worm-chained keys require iterative block-by-block inversion. (5) The 2025 Rust Tickler walkthroughs (Day 23, 28, 30) were the right starting reference for embedded encrypted tables and per-entry keystreams. (6) Guessing against a len||input -> CBC-ARX -> compare check is hopeless; always confirm the compare target comes from the trace, not from heap entropy.

8. Files