Summary
A black-box pwn against a virtual ECU (vECU, an x86-64 Linux process) that speaks the automotive diagnostic/flash stack — DoIP (ISO-13400) → ISO-TP (ISO-15765-2) → UDS (ISO-14229) — over a TCP socket. The goal is the burned-in production master key. No binary is given; everything below is recovered over the wire.
Each TCP connection is an isolated “virtual power cycle”: session / unlock / transfer state
reset on disconnect, so a wrong SecurityAccess key never locks you out — retry freely on a
fresh connection.
Protocol stack
Three layers, big-endian throughout.
DoIP header (8 bytes): version (0x03 normally), ~version (validated), payload type
(u16), payload length (u32). Relevant payload types: 0x0001 vehicle identification,
0x0004 announcement, 0x0005/0x0006 routing activation, 0x8001 diagnostic message,
0x8002/0x8003 ACK/NACK.
ISO-TP inside a 0x8001: SF [0x0L][L bytes], FF [0x10|len_hi][len_lo][6],
CF [0x20|SN][7], FC [0x30][BS][STmin]. The server replies to a FF with BS=4,
STmin=5 ms and aborts with NRC 0x24 if a consecutive frame arrives earlier than
STmin — so sleep STmin before sending each CF, including the first after the FC.
Sleeping after each CF instead produces intermittent 7F .. 24 desyncs.
UDS: standard SIDs — 0x10 session, 0x11 reset, 0x22 RDBI, 0x23 RMBA, 0x27
SecurityAccess, 0x31 RoutineControl, 0x34/35/36/37 download/upload/transfer/exit,
0x3E TesterPresent. Negative responses are [0x7F][SID][NRC].
1. Recon — read the build string
A Vehicle Identification request returns an Announcement containing
SEC-GATE v2.3.1 (legacy-compat build). The challenge states the version string encodes the
build configuration — the (legacy-compat build) tag is the central hint that a legacy code
path exists.
After a default routing activation: 0x10 0x02 (programming session) returns
NRC 0x22 (conditionsNotCorrect), 0x27 0x11 returns an 8-byte seed, and 0x23 (RMBA) is
reachable.
2. Privilege escalation — empty OEM credential
Production flashing needs routing activation type 0x01 (“requires OEM credentials”).
Enumerating the credential: an empty credential (oem_len = 0) returns result 0x10
(success), while 00000000 and "LEGACY" are rejected. After this activation, 0x10 0x02
changes from NRC 0x22 to NRC 0x33 (securityAccessDenied) — the only remaining gate is
SecurityAccess.
3. Arbitrary read — ReadMemoryByAddress
0x23 format: [0x23][addrLenFmt][addr][size], where addrLenFmt’s high nibble is the
size-field byte count and low nibble the addr-field byte count. The 8-byte “absolute” form
(addrLenFmt = 0x18) performs, under a sigsetjmp/SIGSEGV guard, a
memcpy(out, (void*)addr, size) — an arbitrary read of any mapped page (NRC 0x31 when the
read faults). This works after activation + extended session, no SecurityAccess needed:
def rmba_abs(addr, size): # absolute 8-byte read
req = bytes([0x23, 0x18]) + addr.to_bytes(8, "big") + size.to_bytes(1, "big")
resp = uds(req) # 0x8001 diagnostic message, DoIP v0x03
if resp[0] == 0x7f: raise IOError(f"NRC {resp[2]:#x}") # 0x31 == faulted/unmapped
return resp[1:]
The leaked stack holds PIE pointers (ASLR fixed for the process lifetime). Page-align one and
scan downward with absolute RMBA until \x7fELF appears; read the program headers and dump
every PT_LOAD. From here it is effectively white-box.
4. The legacy channel — DoIP version 0x02
The normal 0x27 key check is HMAC-SHA256(secret, seed) against a 32-byte master key kept
in an mmap‘d PROT_NONE page — unforgeable offline. But the DoIP parser accepts
version - 2 <= 1, i.e. 0x02 and 0x03. Under version 0x02 the payload after
[src][dst] is treated as raw UDS (no ISO-TP) and routed to a legacy dispatcher whose
0x27 is a toy xorshift16:
def legacy_sa_response(seed16, A=0x9e37, B=0x5a5a, X=0x4b37):
x = seed16 & 0xFFFF
x ^= (x << 7) & 0xFFFF
x ^= (x >> 9)
x ^= (x << 8) & 0xFFFF
x &= 0xFFFF
return (((A * x) & 0xFFFF) ^ B ^ X) & 0xFFFF
Request seed with 27 01, send 27 02 <resp_be> — this sets the same unlock bit as the HMAC
path. Over the wire (DoIP version 0x02, payload after [src][dst] is raw UDS):
>> 8001 [src][dst] 27 01 # request seed
<< 8001 [dst][src] 67 01 <seed16> # 16-bit seed
>> 8001 [src][dst] 27 02 <resp_be> # legacy_sa_response(seed16), big-endian
<< 8001 [dst][src] 67 02 # unlocked
5. Recovering the master key
On every legacy unlock the server stages the flag into the per-connection download buffer at
offset 0x1000 (a readable RW page). The staging XORs cancel to leave flag XOR keystream,
where k_i = xorshift64(k_{i-1}):
M64 = (1 << 64) - 1
def xorshift64(s):
s ^= (s << 13) & M64; s ^= (s >> 7); s ^= (s << 17) & M64
return s & M64
The per-connection seed is wiped, but the flag starts with flag{, so brute the 3 unknown
bytes of the first keyword and chain forward. End to end:
- Routing activation type
0x01, empty credential. - Locate the PIE base (RMBA scan for
\x7fELF); read the download-buffer pointer and flag length from.bss. - Legacy SecurityAccess unlock (DoIP version
0x02) — stages the encrypted flag atdownload_buf + 0x1000. - Absolute RMBA that buffer; decrypt offline with the known-plaintext routine.
No flashing, CRC, or watchdog needed. Re-running on a fresh connection yields a different ciphertext that decrypts to the same plaintext, confirming correctness.
Flag
flag{...} (redacted)
Why each control failed
- Production activation → empty credential accepted.
- Memory protection → RMBA (
0x23) is an arbitrary read; a SIGSEGV-guardedmemcpyis still an arbitrary read. - SecurityAccess → a legacy DoIP version byte reaches a second, weak algorithm.
- Flag at rest → a
PROT_NONEpage is pointless once the secret is copied, barely obfuscated, into a readable buffer. - Flag encryption → a hand-rolled xorshift stream collapses to a few bytes of known plaintext.