CAN Bus Security Analysis A Fuzzing Approach
CAN Bus Security Analysis A Fuzzing Approach
Supervisor Candidate
Alessandro SAVINO Mattia DE ROSA
Co-Supervisors
Nicolò MAUNERO
Giacomo D’AMICO
Modern vehicles are equipped with numerous Electronic Control Units (ECUs),
each featuring intricate functionalities and being tightly interconnected via internal
networks. Among these, the Controller Area Network (CAN) is the most common.
Past research has revealed the CAN network to be vulnerable to a multitude
of cybersecurity attacks, enabling an attacker to take control of safety-critical
ECUs such as the ones managing the engine, steering, or brakes. Securing ECUs
connected via the CAN network against cyber threats is of paramount importance
since an infected ECU could be used to propagate the attack to the other units on
the network.
Fuzz testing is a widely adopted, automated software testing technique that
helps identify vulnerabilities and defects in programs. It involves sending a large
amount of generated data to the system under test to identify messages that cause
crashes, errors, or other incorrect behavior.
Existing fuzzers in the automotive security landscape often fall into two cat-
egories: proof-of-concept open-source tools lacking advanced functionalities or
closed-source solutions requiring proprietary hardware, hindering interoperability
with other tools.
This thesis aims to bridge this gap by developing a modular fuzzer tailored for
robustness and future extensibility. The primary focus is on enhancing the ease of
integration while providing a versatile tool for cybersecurity testing.
Organizing the fuzzer into multiple modules facilitates the concurrent devel-
opment of different features. Additionally, relying on a higher abstraction of the
CAN protocol ensures interoperability among the developed components. A di-
rect outcome of this abstraction is the elimination of dependence on proprietary
hardware.
The development of dedicated modules for various network interfaces transforms
them into plug-and-play components for the fuzzer. This thesis introduces two
interfaces: one for utilizing a virtual CAN bus and the other for interfacing with
Intrepid CS devices.
To validate the fuzzer’s effectiveness, testing has been conducted on both a sim-
ulated virtual ECU and a physical test bench. Finally, testing has been performed
to compare various developed fuzz generator modules, highlighting their efficacy
under different assumptions.
It is important to note that while the project primarily focuses on the CAN
network, the architecture has been designed to seamlessly extend to multiple pro-
tocols.
Contents
List of Tables 3
List of Figures 4
Acronyms 7
1 Introduction 9
1.1 Cybersecurity Concerns . . . . . . . . . . . . . . . . . . . . . . . . 10
1.1.1 Attack Goals . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.1.2 Attack Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2 Industry Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.1 AUTOSAR . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2.2 ISO 26262 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2.3 ISO/SAE 21434 . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 Solution Design 43
4.1 Key design principles . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2 Key components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.3 Additional components . . . . . . . . . . . . . . . . . . . . . . . . . 45
5 Implementation 47
5.1 Technologies and Libraries . . . . . . . . . . . . . . . . . . . . . . . 47
5.1.1 Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.1.2 python-can . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.1.3 python-ics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.1.4 PySide6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.2 CAN Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.3 Virtual ECU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
5.4 Fuzz Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.5 Fuzzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.6 Logger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.7 CAN Reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.8 User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
7 Conclusions 73
7.1 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
2
List of Tables
2.1 Comparison between different fuzzing techniques . . . . . . . . . . . 23
6.1 Fuzzer performance compared to different baudrates . . . . . . . . . 62
6.2 Components of the Fiat 500 BEV test bench and their respective
functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3
List of Figures
1.1 Means of transport in the EU, 2011-2021 . . . . . . . . . . . . . . . 10
1.2 AUTOSAR Classic Platform schema . . . . . . . . . . . . . . . . . 12
2.1 Data flow diagram example for a vehicle used for Threat Modeling . 17
2.2 Number of bugs reported by Domino over time . . . . . . . . . . . . 20
3.1 CAN adoption timeline . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2 CAN physical and data link layers in relation to the ISO OSI model 27
3.3 High-speed CAN signaling . . . . . . . . . . . . . . . . . . . . . . . 28
3.4 CAN bus Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.5 Arbitration example between three nodes in an 11-bit ID CAN net-
work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.6 CAN bit timing example with 10 time quanta per bit . . . . . . . . 33
3.7 Base CAN data frame . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.8 Extended CAN data frame . . . . . . . . . . . . . . . . . . . . . . . 35
3.9 CAN error frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.10 CAN overload frame . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.11 A gateway is used to decouple the CAN network in multple sub-
networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.1 Example of CAN network interfaces . . . . . . . . . . . . . . . . . . 45
4.2 Developed software modules and their relationship . . . . . . . . . . 46
5.1 ValueCAN 4-2 developed by IntrepidCS . . . . . . . . . . . . . . . . 49
5.2 CAN Interface overview . . . . . . . . . . . . . . . . . . . . . . . . 51
5.3 Virtual ECU state diagram . . . . . . . . . . . . . . . . . . . . . . . 52
5.4 Fuzzer UML diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.5 Identifing a CAN frame using CAN Reverse . . . . . . . . . . . . . 57
5.6 Fuzzer graphical user interface . . . . . . . . . . . . . . . . . . . . . 58
5.7 CAN Reverse graphical user interface . . . . . . . . . . . . . . . . . 59
6.1 CANalyzer testing setup . . . . . . . . . . . . . . . . . . . . . . . . 62
6.2 Example of a test bench using Volkswagen components . . . . . . . 63
6.3 Ratio between received CAN frames during and before a fuzzing
session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.4 Example Usage of the CAN reverse module . . . . . . . . . . . . . . 66
4
6.5 Virtual ECU testing setup . . . . . . . . . . . . . . . . . . . . . . . 67
6.6 Slow-rate vs batch fuzzing . . . . . . . . . . . . . . . . . . . . . . . 69
6.7 Batch fuzzer with varying batch size . . . . . . . . . . . . . . . . . 69
6.8 Bit Flip vs Random Fuzzing . . . . . . . . . . . . . . . . . . . . . . 71
6.9 Bit Flip vs Random Fuzzing, with CRC . . . . . . . . . . . . . . . . 71
6.10 Bit Flip fuzzing with CRC bruteforce . . . . . . . . . . . . . . . . . 72
5
6
Acronyms
ABC Abstract Base Class.
8
Chapter 1
Introduction
The most common method of transportation for people and goods are, by far, road
automobiles. According to a study performed by Eurostat [15], in 2011 transport
by car accounted for 73.1% of passenger-kilometers1 with small variations until
2019. After the pandemic we saw a decrease in the usage of public transport which
in turn caused the percentage of passenger-kilometers for cars to reach 79.7% in
2021 [Figure 1.1].
Cars have massively evolved over the years, the introduction of advanced tech-
nologies in auto vehicles began in the early ’70 thanks to the development of
integrated circuits and microprocessors which allowed the production of ECUs
(Electronic Control Unit) on a large scale. The number of ECUs has steadily in-
creased in road vehicles reaching as many as 150 on luxury models [5], all these
ECUs exchange thousand of messages every second and communicate which each
other through cabled or wireless communication networks, of which the most im-
portant is the CAN bus (Controller Area Network).
In recent years, the automotive industry has undergone a remarkable trans-
formation, propelled by technological advancements that have introduced a new
era of intelligent, connected, and autonomous vehicles. Vehicles have become
increasingly more sophisticated, incorporating cutting-edge technologies such as
advanced driver-assistance systems (ADAS), telematics, vehicle-to-vehicle (V2V)
and vehicle-to-everything (V2X) communication. As a result of these transforma-
tions, the necessity of addressing cybersecurity concerns in the automotive domain
has grown significantly.
1
The passenger-kilometer is a unit of measurement representing the transport of one passenger
by a defined mode of transport (road, rail, air, sea, inland waterways etc.) over one kilometer.
9
Introduction
Figure 1.1: Means of transport in the EU, 2011-2021. Image from Eurostat [15].
• Denial of service: Denying a service to the user, for example can be used to
prevent a car from unlocking the doors or starting.
2
DSRC is a technology for direct wireless exchange of V2X data between vehicles, other road
users (pedestrians, cyclists, etc.) and roadside infrastructure (traffic signals, electronic message
signs, etc.)
11
Introduction
1.2.1 AUTOSAR
AUTOSAR (AUTomotive Open System ARchitecture) is a global partnership of
leading companies in the automotive and software industry. It is focused on creat-
ing and establishing an open and standardized software architecture for automotive
ECUs.
AUTOSAR provides specifications basic software modules, focusing on creating
common API (Application Programming Interface) and development methodology
based on a standardized exchange format. AUTOSAR software architecture can be
used by vehicles of different manufacturers and components of different suppliers,
increasing interoperability and reducing research and development costs.
AUTOSAR Classic Platform [3] [Figure 1.2] is the standard for embedded
ECUs, it is composed by a three layer architecture:
Figure 1.2: AUTOSAR Classic Platform schema. Image from autosar.org [3].
12
Introduction
3
In the context of the automotive industry, functional safety assures that electronic and
electrical systems operate safely, without posing unreasonable risk, even when faced with faults
or failures.
13
Introduction
14
Chapter 2
It is ideal to establish a threat model early in the planning phase and subse-
quently evolve it alongside with the system it represents. This implies continuous
refinement throughout the entire lifecycle of the product: as more details are added
to the system, new attack vectors are created and exposed so updating the model
is needed to account for these changes.
The OWASP Foundation defines a "Four Question Framework" [42] to help
organize a threat model:
• What are we working on? The scope of the project, can be as small as a
sprint or as large as the whole system.
Figure 2.1: Data flow diagram example for a vehicle used for Threat Modeling.
Image from Copper Horse [12].
Fuzz testing (or Fuzzing) is an automated software testing technique, which con-
sists in finding implementation bugs using malformed data injection [17].
The biggest advantages of fuzzing are that the test design is extremely simple,
often being system-independent, and its complete automation. Additionally the
random approach allows this method to find bugs that would have been missed by
human eyes.
17
State of the Art for Vehicle Cybersecurity
1
The Common Vulnerability Scoring System is a standard for assessing the severity of com-
puter system security vulnerabilities. Scores range from 0 (NONE) to 10 (CRITICAL).
20
State of the Art for Vehicle Cybersecurity
• Black-box fuzzers do not require any additional input, they may be aware
of the structure of the input data, but knowledge about inner workings of the
target is not needed.
These kind of fuzzers are the most versatile since they can be applied with-
oud developing an ad-hoc solution, but they provide fewer insights on the
produced results. To counteract this, there are attempts at developing black-
box fuzzers that try to incrementally increase their knowledge about a target’s
internal structure, like LearnLib [39].
An additional strong point of black-box fuzzing is that it simulates the point
of view of an attacker more accurately.
• White-box fuzzers need internal knowledge about the target, usually source
code or data flow diagrams. This kind of fuzzer employs program analysis with
the main objective of increasing code coverage2 or reaching critical locations
in a program. Other possible techniques for white-box fuzzing include static,
taint or concolic analysis, each based on varying amount of knowledge of the
target.
These types of analysis are very effective on targeting specific platform, but
one of its main disadvanteges is the time needed to perform them. If a fuzzer
takes too long to generate a test case, a black-box fuzzer might be more
efficient, or produce results earlier.
2
Code coverage is a metric that measures the percentage of source code executed when a
particular test suite is run. An effective fuzzer tries to reach as close as full coverage as possible.
3
Instrumentation is a technique used to track application behaviour by detecting errors and
obtaining trace information. It employs debug tools to perform profiling of the application and
log major events such as crashes.
21
State of the Art for Vehicle Cybersecurity
• Researching the state of the art for vehicle security including leading industry
standards.
• Analyzing the inner workings and limitations of the CAN network.
• Developing a proof of concept virtual ECU to become acquainted with the
libraries interfacing with the CAN network.
• Developing the black-box fuzzer focusing on the modular structure, ease of
use and deployment of the tool.
• Testing the fuzzer against a test board including the key components of a
Fiat 500, simulating a real car in a lab environment.
23
Chapter 3
The Controller Area Network (CAN) bus is an asynchronous serial bus used for
realtime communication between multiple microcontrollers with eachother. It is a
message based protocol designed for communication in a multi-master architecture.
It was developed by Robert Bosch GmbH, released to the public in 1986 and
finally standardized in 1993 by the International Organization for Standardization
as ISO 11898 [27]. The CAN standard is still adapting and evolving to rising needs
in the industry, in 2015 CAN FD (Flexible Data) was standadrdized and in 2018
development for CAN XL has started.
In the modern automotive industry CAN is still the de-facto leading standard
for ECU communication in vehicles. The development of newer protocols, like
Figure 3.1: CAN adoption timeline. Image from CSS Electronics [14].
24
Controller Area Network (CAN) Bus
SAE J19391 and LIN2 , designed to operate either in conjunction with or on top
of the CAN bus, further solidifies the integral role of the CAN bus in automotive
ECU communication. These protocols exemplify the enduring significance and
adaptability of the CAN bus in the evolving landscape of automotive connectivity.
This chapter will provide the motivation for the focus of this thesis on the CAN
protcol and an in depth summary of the CAN protocol. Starting with an overlook
on the fundamental properties behind its design, followed by a description of its
phyiscal and data link layers, and concluding by highlighting the cybersecurity
concerns and measures taken to mitigate them.
1
Society of Automotive Engineers J1939 is the standard in-vehicle network for heavy-duty
vehicles like trucks and buses.
2
The LIN bus (Local Interconnect Network) has been introduced to complement CAN for
non-critical subsystems like air conditioning and infotainment.
25
Controller Area Network (CAN) Bus
• Multimaster: there is no central bus master, every ECU can act like one.
• Priority Handling: CAN messages are prioritized so that critical ECUs get
immediate bus access.
• Low Cost and Lightweight: allows to save on both cost and weight of
copper wiring in a vehicle.
The ISO 11898 standard covers both the physical and data link layers and is
composed of four parts [27].
Part 1 describes the data link layer composed of the logic link control (LLC),
media access control (MAC) and physical coding sub layers.
Part 2 describes the high-speed physical layer, it is by far the most popular
standard for the physical layer.
Part 3 describes the low-speed physical layer, it allows communication to con-
tinue even if there is a fault in one of the two wires. It is also referred to as "fault
tolerant CAN".
Part 4 describes time-triggered communication.
Part 5 and 6, pertaining to power modes and selective wake-up functionality,
previously existed independently but have since been withdrawn and merged into
part 2.
The role of CAN is often presented in the 7 layer ISO OSI model [Figure 3.2].
Figure 3.2: CAN physical and data link layers in relation to the ISO OSI model.
Image from CSS Electronics [14].
aimed to promote broader adoption thanks to the additional freedom given to the
manufacturers.
However, this approach resulted in potential interoperability challenges among
CAN bus implementations. To address this issue, two standards were subsequently
introduced: ISO 11898-2 (established in 2003) and ISO 11898-3 (established in
2006).
Figure 3.3: High-speed CAN signaling. ISO 11898-2. Image from Wikipedia, the
free encyclopedia [43].
28
Controller Area Network (CAN) Bus
Figure 3.4: CAN bus Node. Image from Wikipedia, the free encyclopedia [43].
3.4.1 Arbitration
Figure 3.5: Arbitration example between three nodes in an 11-bit ID CAN network.
Node 1 transmits a message with id 1631, node 2 uses id 1663 and node 3 uses id
1625. Node 2 is the first to lose arbitration since it has the highest id, while node
3 wins arbitration and procees with transmitting the rest of the frame.
To calculate the necessary adjustment, the controller divides the nominal bit
time into slices called quanta, the amount of which varies according to the con-
troller.
The quanta are then allocated among four different segments: synchronization,
propagation, phase 1 and phase 2. The sample point, crucial for calculating the
bit rate, is positioned between the phase 1 and phase 2 segments [Figure 3.6].
The synchronization segment is alway 1 quantum long and the propagation
segment is used to account for physical delay among nodes. The lengths of the
two phase segments can be extended or shortened by an amount calculated by the
CAN controller to compensate for desynchronizations.
Figure 3.6: CAN bit timing example with 10 time quanta per bit. Image from
Wikipedia, the free encyclopedia [43].
Every field in a CAN frame except CRC delimiter, ACK and end of frame field
are subject to bit stuffing. In fields where stuffing is used, six consecutive bits of
the same polarity are considered an error.
Receiver nodes are tasked with destuffing the signal, by discarding the next bit
each time five consecutive bits of the same polarity are received.
This stuffing and destuffing process guarantees that the original bit sequence
remains unaltered, while still providing consistent re-syncrhonization.
Data Frame
• Start of Frame (SOF): 1 bit, must be dominant. It denotes the start of the
frame and is used to synchronize sender and receivers.
Figure 3.8: ID, Control and Data portions of an extended CAN bus frame, to
highlight the differences with the base frame.
• Data: 0-64 bits. Data to be transmitted, the length of this field is dictated
in bytes by the DLC field.
• Cyclic Redundancy Check (CRC): 15 bits for the CRC sequence, followed
by 1 recessive bit for the CRC delimiter. Used for checking the integrity of
the received message. Uses the CRC-15-CAN polynomial.
• ACK: 1 bit for the ACK and 1 recessive bit for the ACK delimiter. The sender
writes a recessive bit, receivers can write a dominant bit to acknowledge the
correct reception of the message. The transmitter can read the ACK bit to
verify if any node received the sent frame, and possibly re-send it.
• End of Frame (EOF): 7 consecutive recessive bits. Used to signal the end
of the frame.
3
It is possible to put in 4 bits values higher than 8, although the maximum length of the data
field still remain 8 bytes. The behaviour for invalid lenghts depends on the implementation of
the controller.
35
Controller Area Network (CAN) Bus
Extended data frames share many of the fields with base data frame, with the
following distinctions:
• Substiture Remote Request (SRR): 1 bit. Replaces the RTR bit, must
be recessive.
Remote Frame
Typically, nodes autonomously transmit data; for instance, a sensor might con-
tinuously send data frames to be processed by another ECU. However, the CAN
standard, offers a method to request data from the source by sending a remote
frame.
A remote frame is similar to a data frame, with a few key differences:
• the DLC indicates the length of the requested data, not the transmitted one.
If a data frame and a remote frame with the same id begin arbitration at the
same time, the data frame will win arbitration since the dominant bit indicates a
data frame.
Interframe Spacing
Data frames and Remote frames are separated from preceding frames by a field
called interframe space. It consists of at least three recessive bits.
The next dominant bit received after the interframe spacing is considered a
start of frame.
36
Controller Area Network (CAN) Bus
Error Frame
Error frames are different from data and remote frames: instead of being transmit-
ted after the interframe spacing, they are allowed to be transmitted at the same
time of an ongoing data frame or remote frame, interrupting it.
Error frames rely on purposefully violating the bit stuffing rule and transmitting
six consecutive dominant or recessive bits to signal the error.
Error frames are composed of two fields:
• Error delimiter: 8 recessive bits, signaling the end of the error frame.
The error flag bits can be all dominant or all recessive depending on the state
of the node when the error flag is sent.
To determine the current state of the node, each one has two different counters:
the transmitted error count (TEC) and received error count (REC). These
two counters are increased respectively when a node transmits or receives an error
flag by varying amounts based on the type of error received. The counters can be
decreased if an error is not detected for some time.
The states the node can be in are the following:
• Active error state: the starting state of the node. In this state the node
transmits active error flags (six dominant bits) whenever it detects an error.
• Passive error state: the node enters this state when T EC ≥ 128 or REC ≥
128. In this state the node transmits passive error flags (six recessive bits)
whenever it detects an error.
37
Controller Area Network (CAN) Bus
• Bus off state: the node enters this state when T EC ≥ 256. In this state
the node is not allowed to transmit anything on the bus and can only read
from it.
• Bit error: detected when a node transmits a bit on the bus, and the value
of the read bit differs from the one that was sent. An exception is made for
when a recessive bit is sent, but a dominant one is read in the arbitration
field or ACK flag of the frame.
• Stuff error: detected when the sixth consecutive bit of the same value is
read on the bus, violating the stuffing rule.
• CRC error: detected when receiving a frame and the CRC calculated from
the message does not match the received one.
• Form error: detected when a fixed form-bit is the incorrect one. For example
if the CRC delimiter, which needs to always recessive, is read as dominant.
• ACK error: detected by the sender of a message when no other node trans-
mits a dominant bit for the ACK flag.
Overload Frame
An overload frame has the same format of an active error frame, but a very
different purpose:
An overload frame can only be sent during the interframe spacing and can be
sent for the following reasons:
• A node requires a delay of the next data frame or remote frame due to some
internal condition. In this case a node has to start sending the overload frame
on the first bit of the interframe spacing. Additionally a node is allowed to
send a maximum of two consecutive overload frames with the purpose of
delaying successive frames.
• A node detects a dominant bit in the second or third bit of the interframe
spacing. In this case the node will send an overload frame with a delay of 1
bit.
Among these methods network segmentation and IDS are the ones believed to
be the most cost-effective solutions. IDSs are especially useful when safeguarding
41
Controller Area Network (CAN) Bus
older vehicles due to the minimal modifications needed for integration with the
CAN bus.
Figure 3.11: A gateway is used to decouple the CAN network in multple sub-
networks. Image from Van Barel [24].
42
Chapter 4
Solution Design
The aim of this project is to develop a modular CAN fuzzer with dual functionality:
as a standalone tool for conducting fuzz testing on automotive networks and as
a foundational base for future future developments and integrations with other
tools.
A survey of existing solutions in this domain reveals a gap in the availabil-
ity of modular CAN fuzzers. Existing results from web searches yielded limited
outcomes, including open-source proof-of-concept projects lacking advanced fea-
tures [19, 1] or closed-source commercial products with limited modularity and
integration capabilities [26].
The objective is to recreate the many features available in commercial products,
while eliminating the necessity of using proprietary hardware that typically is
necessary to run the associated commercial solution.
• CAN Interfaces: this module is the foundation for the communication with
the hardware. It is often required by other modules. Multiple options are
available to allow the program to interface with different CAN devices or
virtual interfaces [Figure 4.1].
• Fuzzer Loop: the core of the fuzzer. It requires both a CAN interface and
a fuzz generator. The purpose of this module is to continously generate data
from a fuzz generator and send it via the CAN interface. Multiple instances
of the fuzzer loop can be run in parallel if fuzzing to multiple interfaces at
the same time is required.
• Logger: this module is responsible for logging both the sent and received
data on the CAN bus. It requires the user to specify the CAN interface to
log and supports multiple file types and log outputs.
• User Interfaces: the user interface module is optional and can be omitted
on headless devices for a more lightweighted application.
The CAN interface and fuzz generator modules have been developed with the
intent of being easily extensible. Adding support to different protocols and fuzzing
strategies is straightforward.
44
Solution Design
45
Solution Design
46
Chapter 5
Implementation
In this chapter we will introduce the technologies used during the development
of this project, followed by an in-depth expaination of the implementation of the
various modules, including the rationale behind the decisions and the challenges
faced during this process.
5.1.1 Python
A key requirement for this fuzzer is its capability to run on multiple platforms, for
this reason the Python programming language was selected.
Python [18] is a high-level, multi-paradigm, known for its simplicity, readabil-
ity, and versatility. It provides a dynamic, object-oriented approach to software
development and emphasizes code readability, making it easier for developers to
express concepts in fewer lines of code.
Python was conceived in the late 1980s by dutch programmer Guido van Rossum
and saw its first official release in 1991. Over the years, its substantial evolution
owes much to the open-source model and collaborative efforts within the commu-
nity. Presently, python has a myriad of community-created libraries encompassing
diverse domains, including web development, scientific and numeric computing,
desktop GUIs, cybersecurity tools and many more [25].
The rich community environment contributes greatly to the "ease of integration"
requirement, enhancing this fuzzer’s versatility and adaptability across a wide
47
Implementation
spectrum of applications.
The fuzzer has been developed using python 3.11, the latest stable release at
the time of writing this thesis.
5.1.2 python-can
The python-can library [7] provides Controller Area Network support for Python,
including common abstractions to different hardware devices and utilities for send-
ing and receiving messages.
The core of this library relies on the Bus and M essage classes which provide
an abstraction for communicating with different virtual or hardware CAN devices.
Other notable features of this library include:
5.1.3 python-ics
Python-ics [13] is a python library for interfacing with Intrepid Control System
[38] hardware.
Primarily functioning as a wrapper around libicsneo, a C++ API for interfacing
with various hardware devices from IntrepidCS, this library exhibits a more intri-
cate interface compared to python-can. Its usage demands a deeper comprehension
of the CAN bus, adopting a lower-level approach reminiscent of C programming.
The selection of this library was dictated by the project’s network interface
requirements, specifically the utilization of the ValueCAN 4-2 interface [Figure
5.1] developed by IntrepidCS.
5.1.4 PySide6
PySide6 [16] is the official python module for the Qt for Python project [11].
48
Implementation
49
Implementation
1 import can
2
8 msg2 = bus.recv()
1 class AbstractCANInterface(ABC):
2
3 @abstractmethod
4 def close(self):
5 pass
6
7 @abstractmethod
8 def send(self, message: MessageEnvelope):
9 pass
10
11 @abstractmethod
12 def receive(self, waitForever: bool = False) ->
tuple[List[MessageEnvelope], int]:
13 pass
50
Implementation
51
Implementation
52
Implementation
1 class AbstractFuzzGenerator(ABC):
2
3 @abstractmethod
4 def __next__(self) -> Optional[MessageEnvelope]:
5 pass
1
A BLF file (Binary Logging Format) is a message-based format for storing CAN messages,
developed by Vector Informatik GmbH.
53
Implementation
5.5 Fuzzer
The fuzzer component is fairly straightforward, its main purpose is to serve as an
orchestrator for lower level modules. These modules, in turn, manage the majority
of the logic.
To instantiate a F uzzer, two objects are required: an implementation of any
AbstractCAN Interf ace and an implementaiton of any AbstractF uzzGenerator.
The purpose of the fuzzer is to simply iterate over the fuzz generator, obtain a
CAN frame, and send it though the CAN interface.
Additionally, the F uzzer class provides methods to start and stop the fuzzing
loop. It requires a parameter to determine the delay between messages and op-
tionally accepts callback functions for handling events, such as sending a message
or reaching the end of the generator.
The fuzzer is a subclass of a python T hread so instantiating multiple fuzzers is
as simple as calling the F uzzer constructor multiple times.
5.6 Logger
The logger component operates similarly to the fuzzer. To instantiate a Logger, an
implementation of any AbstractCAN Interf ace is required, as it will be utilized to
continuously monitor the CAN bus and log all transmitted and received messages
on it.
The Logger class provides methods to start and stop it and is a subclass of
T hread, similar to the F uzzer class.
Initially, there was consideration to include the logging functionality directly
inside the fuzzer module since they share a common CAN interface and structure.
However, keeping them in separate modules allows for greater flexibility. For
instance, it is possible to run multiple fuzzers on the same interface and use only
a single logger instead of having to use multiple of them. Alternatively, one can
run the logger without a fuzzer if only monitoring of the CAN bus is required.
The logger currently supports three different logging methods:
• Python’s builtin logging module: by default the log is output on stdout, but
can be configured to write to files instead. A human readable format is used
for this output, its main utility is debugging if few messages were exchanged
over the network.
54
Implementation
56
Implementation
57
Implementation
Figure 5.6: Fuzzer graphical user interface. The interface selector allows the user
to specify which CAN interface to use and its configuration options. The CAN
fuzzer section, allows the user to specify the Fuzz Generator and its parameters.
58
Implementation
Figure 5.7: CAN Reverse graphical user interface. This module allows for loading
sections from the BLF file to replay, buttons are available to replay the two halves
of the section and then choose which of the two to keep. Refer to figure 5.5 for
the usage.
59
Chapter 6
60
Testing and Results
1 #!/bin/sh
2
Listing 6.1: Loads the vcan kernel module and creates a new virtual interface
named vcan0.
1 #!/bin/python
2
3 vcan0 = PythonCANInterface(can.Bus(channel="vcan0",
type="socketcan"))
4
5 randomGenerator = RandomFuzzGenerator()
6
9 fuzzer.start()
Listing 6.2: Instantiates a fuzzer with a random generator for the virtual interface
vcan0.
The command line utility candump can be used to visualize the output of the
fuzzer.
1 $ candump vcan0
2 vcan0 30B [6] 36 24 27 BE E3 AA
3 vcan0 7D7 [1] DF
4 vcan0 0A0 [4] 2A 63 E0 47
5 vcan0 523 [6] 04 FC E2 AD FA 28
6 vcan0 7FE [2] 6B C1
7 vcan0 1BA [5] F4 D6 FA 6E 82
8 vcan0 5E4 [8] CF 1C 78 61 50 45 25 F0
Listing 6.3: Example of the fuzzer output obtained with the utility candump. The
output includes the arbitration ID, DLC and data of the CAN frame.
61
Testing and Results
6.2 CANalyzer
During this test, the runtime has been set at 5 minutes, the messages have
been generated with a RandomF uzzGenerator with default parameters and the
estimated messages per second is based on an average frame size of 80 bits (stan-
dard arbitration ID and 4 data bytes). The virtual interface does not support a
baudrate because it does not abstract the transmission delay of a real network, for
this reason the thoughput is much higher. Lower baudrates achieve results slightly
closer to the estimated maximum due to the overhead of the communication having
less impact at lower baudrates.
62
Testing and Results
Figure 6.2: Example of a test bench using Volkswagen components. Image from
Ross-Tech Forum [32].
Table 6.2: Components of the Fiat 500 BEV test bench and their respective func-
tions.
resistance for the ValueCAN device. The issue was addressed by setting the flag
termination_enables to 1 in the library’s configuration, activating a software-
controlled termination.
Following this adjustment, the correct transmission of CAN frames was verified
by the ValueCAN LED, when transmitting frames with a baudrate of 500,000. All
further testing was performed with this rate.
Subsequent fuzzer runs elicited diverse reactions from the test bench, including
random fluctuation in the tachometer, activation of the rear view camera, various
alarms related to factors like seatbelt status, imminent collision, and others linked
to Bluetooth connectivity.
6.3.1 Results
A fuzzer efficacy is measured by the amount of errors or program crashes found
in a given amount of time. In the CAN protocol, program crashes translate to an
ECU resetting or violating the CAN protocol standard, thus causing error frames
to be sent. Program errors are instead communicated to other ECUs by using
error flags in the data block of a message.
During the multiple fuzzing runs executed, no error frames were reported, in-
dicating a correct implementation of the CAN standard by all ECUs considered.
Additionally, due to the black-box nature of this analysis, databases to interpret
the byte sequences received by the ECUs were non used, leaving the logged data
impossible to check for the presence of error flags.
Nonetheless, basic traffic analysis was performed on the frequency of received
arbitration IDs, to determine the influence of the fuzzer on the CAN network.
Figure 6.3 shows the increase or decrease in the number of receieved CAN
frames measured before and after the fuzzer session has started. The number of
the received CAN frames has been collected and averaged over multiple 5 minutes
64
Testing and Results
runs, and the ratio between the number of frames during and before the fuzzing
session has been plotted. As seen in the figure, only the CAN frames with ID
0x64D1 showed any noticeable increase in frequency, going from 1201 to 1985
received frames in a 5 minutes interval.
After empirical testing, frame 0x64D is confirmed to be the frame controlling
the ticking of the bench’s emergency lights. Additionally pressing the respective
button on the board does not turn off the emergency lights, so resulting to a board
reset is necessary.
Figure 6.3: Ratio between received CAN frames during and before a fuzzing ses-
sion. Fuzzing does not seem to affect the frequency of received CAN frames, with
the exception of frames with arbitration ID 0x64D, belonging to emergency lights.
1
Arbitration IDs have been replaced and frame data bits have been swapped in these results,
to avoid revealing the reverse engineered data.
65
Testing and Results
Figure 6.4: Example Usage of the CAN reverse module. The highlighted frame is
the one responsible for triggering the emergency lights.
67
Testing and Results
1 #!/bin/python
2
3 int0 = PythonICSInterface(0)
4 int1 = PythonICSInterface(1)
5
6 messageDataRule = {
7 5: 1,
8 6: 0,
9 7: 1,
10 8: 0,
11 }
12
6.4.1 Results
When fuzzing an ECU with a fixed response rate, there are two possible ap-
proaches: sending messages at a faster or slower rate than the ECU’s message
rate. Fuzzing at a slower rate requires sending a maximum of one message from
the fuzzer for every ECU cycle. This ensures that the logger can accurately pair a
"request" and a "response", allowing a straightforward approach to identify which
message caused an error. On the other hand, if the fuzzer exceeds the ECU’s rate,
sent messages must be grouped into "batches" for each cycle. The specific message
in the batch causing the error is subsequently identified using CAN reverse.
Figure 6.6 shows the difference in mean time needed to find the error between
the two strategies. As expected, the batch fuzzing technique yields better results,
even when factoring in the time required to execute CAN reverse. This is due to
the overall higher volume of messages sent.
Figure 6.7 compares the mean time needed to find the error among batch fuzzers
with different sizes. The results indicate that larger batch sizes result in improved
efficiency when dealing with larger error sizes. However, it is important to note
that excessively large batches can lead to a decrease in the number of messages
sent by the ECU, as the fuzzer may take precedence over the ECU response due
to the arbitration feature of CAN.
68
Testing and Results
The earlier findings are applicable only to an ECU that is able to maintain
the "ERROR" state. If an ECU that is not able to, and instead responds solely
to the last received message in each cycle, sending messages in batches becomes
impossible. This forces the fuzzer to operate using the slower-rate strategy.
Figure 6.6: Slow-rate vs batch fuzzing. The mean time needed to find an error is
plotted. The virtual ECU uses a 100 ms cycle time, the batch fuzzer uses a batch
of size 10 for every ECU cycle. In the batch fuzzer case, the time needed to run
CAN reverse is included.
Figure 6.7: Batch fuzzer with varying batch size. The mean time needed to find an
error is plotted. The virtual ECU uses a 100 ms cycle time. Note that a slow-rate
fuzzer would be equivalent to a batch fuzzer with size = 1. The time needed to
run CAN reverse is included.
69
Testing and Results
for the CRC byte. With this strategy, only 256 messages per bit flip are necessary,
resulting in a total of 8,448 messages sent.
Figure 6.8: Bit Flip vs Random Fuzzing. The sum of bit values for all error-causing
messages is plotted in this heatmap. Both strategies were able to successfully
identify the patterns in bits with indexes 5-8. The random strategy sent about
2,000 messages to achieve this result.
Figure 6.9: Bit Flip vs Random Fuzzing, on an ECU requiring a CRC in the
last byte (4). The bit flip strategy proved ineffective, while the random strategy
was able to identify the pattern. The random strategy sent about 57 thousand
messages to achieve this result.
71
Testing and Results
Figure 6.10: Bit Flip fuzzing, with CRC bruteforce. The resulting heatmap is
similar to the case without the CRC, except that the bits corresponding to the
CRC appear to be randomly distributed.
72
Chapter 7
Conclusions
This thesis has succeded in developing a CAN protocol fuzzer from scratch, focus-
ing on the modularity and extensibily aspects of the project. By organizing the
fuzzer into multiple modules and abstracting the CAN protocol, the project aimed
to enhance ease of integration while providing a versatile tool for cybersecurity
testing.
The project’s contributions include the development of specialized modules for
different network interfaces, effectively transforming them into plug-and-play com-
ponents for the fuzzer. Though the focus was on network interfaces produced by
Intrepid CS, the fuzzer can be easily extended to function with interfaces from
other manufacturers.
Testing conducted on simulated virtual ECUs and physical test benches val-
idated the fuzzer’s effectiveness and highlighted the efficacy of various fuzzing
techniques under different assumptions.
Moreover, post-processing techniques, such as analyzing heatmaps generated
from message data and implementing mutation strategies, provided insights into
error-inducing messages and enhanced the fuzzer’s capabilities.
Incorporating support for non CAN protocols, like WiFi or Bluetooth would
require additional effort, as it involves different message structures. However, by
maintaining the same basic structure and principles, the fuzzer can be adapted
to accomodate these protocols, extending its applicability to a wider spectrum of
automotive networks and technologies.
To further improve the developed solution, incorporating features of a smart
fuzzer could significantly improve its effectiveness. For instance, integrating gram-
mar or model based fuzz generation techniques would enable the fuzzer to gener-
ate test cases that adhere closely to the syntax and semantics of the underlying
communication protocols. This approach has the potential to uncover more vul-
nerabilities and edge cases while potentially reducing the runtime needed to find
them.
Furthermore, introducing a feedback mechanism within the fuzzer could en-
hance its adaptability and effectiveness. By collecting and analyzing feedback
from the target system, the fuzzer could dynamically adjust its testing strate-
gies and prioritize test cases that exhibit promising results or trigger interesting
behavior.
Implementing such features would necessitate integration with database CAN
files (DBC), which are widely used in automotive development. These files serve as
structured databases containing information about the message, signals, and the
encoding scheme used by an ECU. By integrating DBC files in the fuzzer, valuable
insights can be gathered from the fuzzed data.
74
Bibliography
[1] Accenture. can_dlc_fuzzer. URL https://github.com/Accenture/can_
dlc_fuzzer.
[4] Anirban Basu. Software Quality Assurance, Testing and Metrics. PHI Learn-
ing, June 2015.
78