UDS

UDS, the diagnostic that opens the doors

The standardised protocol we use to talk to ECUs: read, write, reset, reflash. Designed for the workshop, it becomes an attack surface the moment you learn to divert it.

A protocol on top of the bus

UDS (Unified Diagnostic Services, ISO 14229) is a request/response protocol between a tester (the diagnostic tool) and an ECU. It does not replace CAN: it rides on top of it, carried by ISO-TP (ISO 15765-2) when a request exceeds eight bytes, or by DoIP on Ethernet-equipped vehicles.

Each request begins with a one-byte service identifier (SID). A positive response returns that SID increased by 0x40; a negative response returns 0x7F, the original SID, then an error code.

A UDS request and its positive response (SID + 0x40)
Tester -> ECU : 10 03                 open the extended session
ECU -> Tester : 50 03 00 32 01 F4       positive (0x10 + 0x40 = 0x50)

The services that matter

A handful of services is enough to cover the essentials of offensive diagnostics.

Reference UDS services
SIDServiceWhat it allows
0x10DiagnosticSessionControlOpen a session (default, extended, programming) and unlock sensitive services.
0x27SecurityAccessUnlock a protected function through a challenge/response (seed/key).
0x22ReadDataByIdentifierRead a value by identifier: VIN, software versions, sensors.
0x2EWriteDataByIdentifierWrite a value by identifier, and thus change an ECU parameter.
0x31RoutineControlRun an internal routine: erasing, tests, calibrations.
0x34 / 36 / 37Request/Transfer/ExitThe reflashing sequence: announce, transfer, close.
0x11ECUResetRestart the ECU.
0x3ETesterPresentKeep the session open (keep-alive).
0x28CommunicationControlStop or restore the sending and receiving of messages.
0x85ControlDTCSettingEnable or disable the recording of fault codes.

Reading a value, in practice

Before writing or reflashing, you read. Service 0x22 (ReadDataByIdentifier) is the simplest in all of UDS: you ask for a value by its identifier, the ECU returns it. It is the starting point of any reconnaissance.

Reading the VIN with ReadDataByIdentifier (service 0x22)
Tester -> ECU : 22 F1 90                      read the VIN (DID 0xF190)
ECU -> Tester : 62 F1 90 57 56 57 5A 5A 5A ... positive, VIN as ASCII
  1. Service 0x22 asks for a value; F1 90 is the identifier (DID) of the VIN.
  2. The response begins with 0x62, that is 0x22 increased by 0x40, then repeats the DID F1 90.
  3. The following bytes are the VIN encoded as ASCII: 0x57 gives W, 0x56 gives V, 0x57 gives W.
  4. You simply read the string. Other identifiers return software versions, part numbers or sensor states.

Sweeping the identifiers from 0x0000 to 0xFFFF draws the full map of the ECU, often without any authentication at all. It is the first thing an audit does.

SecurityAccess: the seed/key challenge

Service 0x27 protects sensitive functions (writing, reflashing) with a challenge-response. The principle is simple; all of its strength rests on the secrecy of the algorithm.

  1. The tester asks for a seed: a 0x27 request with an odd sub-function (0x01, requestSeed).
  2. The ECU returns a random seed, a few bytes long.
  3. The tester computes the key by applying to the seed an algorithm the manufacturer keeps secret.
  4. The tester sends the key: a 0x27 request with the matching even sub-function (0x02, sendKey).
  5. If the key matches, the ECU unlocks; otherwise it refuses, and after several attempts it imposes an anti-bruteforce delay.
Seed/key exchange (service 0x27)
Tester -> ECU : 27 01                 requestSeed
ECU -> Tester : 67 01 A3 7F 2C 90       seed (4 bytes)
Tester -> ECU : 27 02 11 22 33 44       sendKey (computed key)
ECU -> Tester : 67 02                 positive, access granted

The seed-to-key algorithm lives in the ECU firmware. If it is weak (linear operations, a fixed key) or extracted through a memory dump, it can be replayed offline. That is why 0x27 is the first target of a UDS audit, and why a strong algorithm and SecOC change everything.

Reflashing: 0x34 / 0x36 / 0x37

Reprogramming an ECU follows a precise sequence, in a programming session and after a successful SecurityAccess.

  1. 0x34 RequestDownload: announces the address, the size and the format of the data to be written.
  2. 0x36 TransferData: sends the firmware in numbered blocks.
  3. 0x37 RequestTransferExit: closes the transfer; the ECU verifies and then validates.

Without an authenticity and integrity check, this sequence makes it possible to write modified firmware. That is why secure boot and signed updates (the R156 framework) are decisive.

Tying it back to the attacks

The attacks in the explorer's Diagnostic layer all rely on these services: forcing a session, bruteforcing a weak seed, writing a data identifier, running a routine, reflashing an ECU.

Frequently asked questions

What is the difference between UDS and OBD-II?
OBD-II (SAE J1979) is a standardised, mandatory subset focused on emissions, with public identifiers. UDS (ISO 14229) goes much further: sessions, writing, routines, reflashing, and manufacturer-specific identifiers. The workshop works mostly in UDS.
How do you read the VIN of an ECU?
With service 0x22 (ReadDataByIdentifier) and identifier 0xF190. The ECU returns the VIN encoded as ASCII. Most of the time neither a special session nor an unlock is required: it is a basic read.
Is the SecurityAccess service safe?
It depends entirely on the manufacturer's seed-to-key algorithm. A linear algorithm or a fixed key break once the firmware is extracted; a strong algorithm holds. It is historically the weak link, and the reason SecOC exists.
Can an ECU be reflashed without authorisation?
The 0x34/0x36/0x37 sequence makes it technically possible, but it first requires a programming session and a successful SecurityAccess. Without secure boot and signed updates, modified firmware gets through; with them, it is rejected.
Does UDS work over Ethernet?
Yes, through DoIP (Diagnostics over IP, ISO 13400) on recent vehicles with automotive Ethernet. The same UDS services then travel in IP packets instead of CAN frames, which opens the classic network attack surface.