Motor City Hotwire

WolvCTF 2026RevMediumBy ufosaysoofWriteup by @xabito

We pulled this firmware off a control module during a teardown in the Motor City. Help us find its secret.

The download is a stripped ARM Thumb ELF for offline analysis. There is no live CAN interface or network service; its request and response behavior can be studied by disassembly or emulation.

Attachments

Recon

The handout is a tiny stripped bare-metal ARM Thumb ELF (6,952 bytes, entry 0x8001, sections .text @ 0x8000, .rodata @ 0x87cc, .bss @ 0x9920). It implements an offline CAN-style diagnostic exchange, so its request and response behavior can be recovered by disassembly or emulation.

The .rodata strings 67 02, 7F 27 35, and the hex table 0123456789ABCDEF give away the protocol: UDS/ISO-14229 SecurityAccess (service 0x27), a seed/key authentication scheme that we have to “hotwire”.

Disassembling the whole .text with objdump -d (Apple’s LLVM objdump handles Thumb-2 fine) gives a readable 725-line listing with these main pieces:

  • 0x8000: entry stub, calls main at 0x8234, then returns a “success” byte from .bss.
  • 0x8010: a round function F(x, i) built from lookup tables in .bss.
  • 0x8070: a SHA-256-style compression routine (IV 6a09e667 bb67ae85 ... and the full 64-word SHA-256 K table live in .rodata).
  • 0x8234: main, which generates the lookup tables from a PRNG seeded with 0xC0DE1234/0xA5A5F00D (an xoroshiro-family generator), Fisher–Yates-shuffles a 256-byte S-box with an RC4-style KSA, then loops reading hex request lines.
  • Request dispatch: byte 0 must be 0x27; byte 1 selects the sub-function.
  • 0x8518 onward: the 16-round ARX loop followed by flag construction.

The request dispatch implements two sub-functions:

Ghidra decompilation of main with the 0x27 request dispatch

  • Sub 0x01 responds with a fixed seed: ten bytes 67 01 1a 2b 3c 4d 5e 6f 77 88 hex-encoded over the wire (67 01 is the UDS “requestSeed” positive response; the actual seed is 1a2b3c4d5e6f7788).
  • Sub 0x02, which requires the seed to have been requested first and at least 10 parsed bytes, loads the 8 key bytes that follow 27 02 and runs the ARX check.

Exploitation

The ARX round function

F(x, i), verified instruction-by-instruction and later differentially against an emulator:

p = (S_low[i] * x) & 0xffffffff        # S_low: 16 odd words @ 0x9920
m = S2[p & 0xff] | S2[p >> 8 & 0xff] << 8 | S2[p >> 16 & 0xff] << 16 | S2[p >> 24 & 0xff] << 24
m = ror32(m, (32 - T_A[i]) % 32)       # S2: shuffled permutation @ 0x9960, T_A @ 0x9A60
return ((m + T_B[i]) & 0xffffffff) ^ T_C[i]   # T_B @ 0x9AA0, T_C @ 0x9AE0

The main loop keeps two 32-bit words initialized from the 8 key bytes: state = BE32(k4..k7), aux = BE32(k0..k3). For each of 16 rounds i, with w = T_D[i] (all odd, generated via | 1) and t = T_E[i]:

objdump listing of the 16-round ARX loop and the flag construction

  • t != 0: tmp = aux*w; aux' = state ^ F(tmp, i); state' = tmp
  • t == 0: tmp = aux*w; aux' = state; state' = tmp ^ F(state, i)

The final values are masked with embedded constants: A = 0x5e6f7788 ^ state_final, B = 0x1a2b3c4d ^ aux_final. There is no comparison against an expected value anywhere. The firmware computes an output for any key, but that output is readable ASCII (the flag) only for the one key the author designated.

The eight flag-mask bytes are hashed together with the key itself: a 20-byte message LE32(A) || LE32(B) || LE32(state0) || LE32(aux0) || LE32(counter) goes through the firmware’s SHA-256-like hashing for counter 0 and counter 1, producing two digests. A 38-byte blob in .rodata at 0x88f8 is XORed with digest_0[1..32] || digest_1[1..8] and printed after the 67 02 positive response.

Inverting the handshake

A 2⁶⁴ search is out of the question, but every round is invertible: the T_D words are odd, so multiplication has an inverse modulo 2³², S_low[i] is odd, S2 is a permutation, and the rotate, add, and XOR steps all invert. Choosing (state_final, aux_final) = (0x5e6f7788, 0x1a2b3c4d) makes both A and B zero.

The complete forward and inverse model below uses the tables dumped by the emulator. arx_bwd undoes the two branch shapes differently, and the first four key bytes come from aux0, not state0:

import random
import struct

M = 0xffffffff
C1, C2 = 0x5e6f7788, 0x1a2b3c4d

# fw is an initialized Firmware instance from the Unicorn harness below.
T = fw.tables()
S_low = struct.unpack("<16I", T["S_low"])
S2 = T["S2"]
TA = struct.unpack("<16I", T["T_A"])
TB = struct.unpack("<16I", T["T_B"])
TC = struct.unpack("<16I", T["T_C"])
TD = struct.unpack("<16I", T["T_D"])
TE = T["T_E"]

S2inv = [0] * 256
for i, v in enumerate(S2):
    S2inv[v] = i

def ror32(x, n):
    n %= 32
    return ((x >> n) | (x << (32 - n))) & M if n else x & M

def rol32(x, n):
    n %= 32
    return ((x << n) | (x >> (32 - n))) & M if n else x & M

def rot_amount(i):
    return ((32 - TA[i]) & 0xff) % 32

def F(x, i):
    p = (S_low[i] * x) & M
    m = (S2[p & 0xff] | (S2[(p >> 8) & 0xff] << 8)
         | (S2[(p >> 16) & 0xff] << 16) | (S2[(p >> 24) & 0xff] << 24))
    m = ror32(m, rot_amount(i))
    return ((m + TB[i]) & M) ^ TC[i]

def Finv(y, i):
    y ^= TC[i]
    y = (y - TB[i]) & M
    m = rol32(y, rot_amount(i))  # inverse of the forward ROR
    p = (S2inv[m & 0xff] | (S2inv[(m >> 8) & 0xff] << 8)
         | (S2inv[(m >> 16) & 0xff] << 16)
         | (S2inv[(m >> 24) & 0xff] << 24))
    return (p * pow(S_low[i], -1, 1 << 32)) & M

def arx_fwd(state, aux):
    for i in range(16):
        w, t = TD[i], TE[i]
        tmp = (aux * w) & M
        if t == 0:
            state, aux = tmp ^ F(state, i), state
        else:
            state, aux = tmp, state ^ F(tmp, i)
    return state, aux

def arx_bwd(state, aux):
    for i in range(15, -1, -1):
        w, t = TD[i], TE[i]
        winv = pow(w, -1, 1 << 32)
        if t == 0:
            # Forward: state' = aux*w ^ F(state), aux' = state.
            s_old = aux
            a_old = ((state ^ F(s_old, i)) * winv) & M
        else:
            # Forward: state' = aux*w, aux' = state ^ F(state').
            a_old = (state * winv) & M
            s_old = aux ^ F(state, i)
        state, aux = s_old, a_old
    return state, aux

# Validate both directions on 2000 random state pairs before trusting the key.
rng = random.Random(0xc0de1234)
for _ in range(2000):
    state, aux = rng.getrandbits(32), rng.getrandbits(32)
    assert arx_bwd(*arx_fwd(state, aux)) == (state, aux)

s0, a0 = arx_bwd(C1, C2)
assert arx_fwd(s0, a0) == (C1, C2)
key = struct.pack(">2I", a0, s0)
print(f"state0={s0:08x}, aux0={a0:08x}, key={key.hex()}")

This recovers state0 = 0x8e96b90b, aux0 = 0x1b869bc5, and key 1b869bc58e96b90b. With the target final state, the message prefix A || B becomes eight zero bytes. Emulation with the recovered key confirms msg = 0000000000000000 0bb9968e c59b861b 00000000.

Emulation-verified extraction

The firmware’s compression function carries the SHA-256 IV and K table but is subtly modified, and standard hashlib.sha256 of the identical padded block disagrees with the emulated digest. Rather than trusting our reimplementation of the hash chain, we let the firmware compute its own flag with Unicorn.

Memory mapping. The file is mapped at 0x7000, RAM covers 0x9000 through 0x200000, and SP starts at 0x180000. Running from 0x8000|1 to the hook at 0x800A initializes and dumps the tables.

Input hooks. Re-entering main at 0x8234|1 reaches two read() call sites, 0x8418 and 0x8482. Their hooks copy "2701" and then "2702" + key.hex() into the stack input buffer, stop emulation, and resume at the corresponding return address. Hooks are registered before the first emu_start, since translated blocks cache their hook set.

Thumb return handling. A PC write inside UC_HOOK_CODE is unreliable, so each hook stops and the outer loop restarts emulation instead. LR = 0x8007 keeps the Thumb bit set when main returns; without it, the popped PC enters ARM mode.

import struct
from unicorn import *
from unicorn.arm_const import *

class Firmware:
    def __init__(self):
        data = open("firmware.bin", "rb").read()
        uc = Uc(UC_ARCH_ARM, UC_MODE_THUMB)
        uc.mem_map(0x7000, 0x2000)
        uc.mem_map(0x9000, 0x200000 - 0x9000)
        uc.mem_write(0x7000, data)
        self.uc = uc
        self.st = {"phase": "init", "inputs": [], "idx": 0, "resume": None}
        uc.hook_add(UC_HOOK_CODE, self._hook)

    def _hook(self, uc, address, size, ud):
        st = self.st
        if address == 0x800a and st["phase"] in ("init", "done"):
            uc.emu_stop()
        elif st["phase"] == "req" and address in (0x8418, 0x8482):
            sp = uc.reg_read(UC_ARM_REG_SP)
            i = st["idx"]
            line = st["inputs"][i] if i < len(st["inputs"]) else b""
            st["idx"] = i + 1
            uc.mem_write(sp + 0x130, line + b"\x00")
            uc.reg_write(UC_ARM_REG_R0, len(line))
            st["resume"] = 0x841c if address == 0x8418 else 0x8486
            uc.emu_stop()

    def init(self):
        self.uc.reg_write(UC_ARM_REG_SP, 0x180000)
        self.uc.emu_start(0x8000 | 1, 0, timeout=0)

    def tables(self):
        uc = self.uc
        return {
            "S_low": bytes(uc.mem_read(0x9920, 64)),
            "S2": bytes(uc.mem_read(0x9960, 256)),
            "T_A": bytes(uc.mem_read(0x9a60, 64)),
            "T_B": bytes(uc.mem_read(0x9aa0, 64)),
            "T_C": bytes(uc.mem_read(0x9ae0, 64)),
            "T_D": bytes(uc.mem_read(0x9b20, 64)),
            "T_E": bytes(uc.mem_read(0x9b60, 16)),
        }

    def exchange(self, inputs):
        self.st.update(phase="req", inputs=list(inputs), idx=0)
        uc = self.uc
        uc.reg_write(UC_ARM_REG_SP, 0x180000)
        uc.reg_write(UC_ARM_REG_LR, 0x8007)
        pc = 0x8234 | 1
        for _ in range(50):
            self.st["resume"] = None
            uc.emu_start(pc, 0, timeout=0)
            if self.st["resume"] is None:
                break
            pc = self.st["resume"] | 1
        self.st["phase"] = "done"
        length = struct.unpack("<I", uc.mem_read(0x9b78, 4))[0]
        return bytes(uc.mem_read(0x9b7c, length))

fw = Firmware()
fw.init()
key = bytes.fromhex("1b869bc58e96b90b")
log = fw.exchange([b"2701", b"2702" + key.hex().encode()])
print(log.decode())

Flag capture

The emulated module authenticates and hands over its secret:

67 01 1A 2B 3C 4D 5E 6F 77 88
67 02
wctf{5M0OTH_0P3R4TORRRRR_6ef709d1ac21}