WEBVTT

00:01.920 --> 00:05.740
First of all, allow me to introduce myself because you probably don't know me.

00:05.740 --> 00:08.740
I work as a security engineer for over eight years.

00:09.120 --> 00:14.100
Currently I'm working in Accenture Embedded System Security Team that's based in Prague, Czech Republic.

00:14.100 --> 00:15.820
That's also where I come from.

00:16.000 --> 00:23.920
And I'm a big open source enthusiast so the tools that I'll be showing you here today are already published on GitHub and could be used by anyone.

00:27.590 --> 00:30.050
Let's have a look at what's ahead of us.

00:30.050 --> 00:32.630
We will start with the description of the CAN bus.

00:32.630 --> 00:39.210
We're right next to the car hacking village so 90% people there actually know that better than I do, but I'll still try.

00:39.610 --> 00:49.930
We will use this knowledge to define the problem that I'd like to talk about and then I'll go into the demo section which will be quite long because I have two of the demos.

00:49.930 --> 01:02.130
First demo will be using a development board and access to the source code debugger and we will basically have a white box approach and we will see how this vulnerability works.

01:02.610 --> 01:11.830
Then we will continue in the second demonstration and I'd like to approach this one as a simulated security assessment here on stage of a real life ECU.

01:11.870 --> 01:16.070
So I brought an ECU from a vehicle and I'll be doing security assessment of that.

01:16.070 --> 01:17.690
This demo is quite packed.

01:17.690 --> 01:25.550
We will be using JTAG debugger, we will be analyzing firmware, we will be using oscilloscopes so there's a lot to see.

01:26.590 --> 01:33.890
And then we will just wrap up the talk with just a couple points about who could be affected by it and some general takeaways.

01:33.890 --> 01:37.870
At the end I hope there will be still some time left for questions and answers.

01:38.490 --> 01:44.230
So without further ado, let's jump into the first slide and that's the description of the CAN bus.

01:44.230 --> 01:58.270
So most of you probably know but CAN bus or controller area network bus is a standard that was originally aimed at the vehicles to allow multiple ECUs to communicate with each other reliably in the noisy environments such as the car.

01:58.470 --> 02:03.730
To achieve this there are two wires used for this which are carrying a differential signal.

02:03.730 --> 02:11.430
Differential signal means that the data being transmitted over these two lines is basically identical, it's just the polarity is inverted.

02:11.830 --> 02:15.570
And each of these buses is terminated by 120 ohm resistor.

02:16.310 --> 02:23.150
Typical vehicle probably contains multiple of these buses which are usually connected by something that's called security gateway.

02:23.650 --> 02:29.270
If I'm to use analogy to IP networks that would be like a router that decides which message can pass where.

02:30.210 --> 02:35.510
Thanks to these properties like robustness, it's found its way into other industries as well.

02:35.510 --> 02:39.410
That's why the talk is described as embedded devices.

02:39.590 --> 02:47.030
Because you can find CAN bus in heavy industry equipment, you can find CAN bus in medical devices and on a lot of other places too.

02:47.270 --> 02:52.830
It's also important to mention that there are multiple versions of the CAN bus as it evolved over the time.

02:52.890 --> 02:57.690
It started with an 11 bit identifier CAN bus that carried just 8 bytes of data.

02:57.890 --> 03:07.310
These have been deemed insufficient so an extended CAN ID came which just increased the ID portion to 29 bits.

03:07.470 --> 03:09.870
But it kept the 8 bytes of the data.

03:10.490 --> 03:16.230
Then further CAN bus versions have been introduced such as CAN FD with 64 bytes of data.

03:16.610 --> 03:23.850
But the talk that I'm having today is only applicable to the standard CAN ID frame and extended CAN ID frame.

03:23.850 --> 03:29.410
We'll discuss briefly CAN FD and CAN XL but only at the end of this talk.

03:30.850 --> 03:36.110
This slide shows the message, the frame and its individual fields.

03:36.390 --> 03:40.010
In the green part there is the most important field that's CAN ID.

03:40.010 --> 03:41.510
Obviously you need that.

03:41.510 --> 03:46.330
Then in the yellow you can see field called DLC or data length code.

03:46.470 --> 03:49.490
This tells us how many bytes of data actually follow.

03:49.490 --> 03:51.850
That could be between 0 to 8.

03:51.850 --> 03:56.830
So there is a perfect valid message in CAN bus that has 0 bytes of data.

03:56.830 --> 03:59.530
The meaning could be carried just inside the ID.

03:59.790 --> 04:02.830
But you can have anywhere up to 8 bytes of data.

04:03.730 --> 04:10.350
Then in the blue field you can see the CRC but that's not really relevant for this talk so I'm going to skip the remaining fields.

04:11.290 --> 04:16.170
For the picture at the bottom, that's a capture from an oscilloscope.

04:16.170 --> 04:19.190
It shows you how it works on the physical layer.

04:19.270 --> 04:24.990
You can see the differential signaling where the red line is CAN high, the blue line is CAN low.

04:25.070 --> 04:27.470
As you can see the data is basically identical.

04:27.470 --> 04:29.850
It's just a mirror image between those two.

04:30.070 --> 04:33.710
We'll be playing a bit with the oscilloscope later on in the demo.

04:33.950 --> 04:37.670
But for now this is just for me to show you how it works on the physical layer.

04:37.670 --> 04:40.950
It's not really relevant to what I'm going to talk about.

04:43.290 --> 04:55.890
If we dive a bit into the specification of the CAN bus and we look at the description of the data length code field, we will find that it has to have values between 0 and 8.

04:55.950 --> 05:01.630
To express 8 in binary, you need 4 bits because that's 1 followed by 3 zeros.

05:01.970 --> 05:10.850
And therefore, I got an idea like what would happen if I'm going to just send DLC field with all 4 ones.

05:11.450 --> 05:16.570
First disclaimer, you can never send more than 8 bytes of data in those CAN frames.

05:16.850 --> 05:25.070
Those packets would be just malformed, never really received, so you'll never send more than 8 bytes of data.

05:25.210 --> 05:32.950
However, what I found is that none of the hardware and most of the software actually cares about the DLC field value.

05:32.950 --> 05:39.590
So you can send whatever you want there and it's still valid and it will still be passed all the way to the developer.

05:39.870 --> 05:44.090
And then it's up to the firmware development team how they work with this value.

05:44.670 --> 05:49.210
On the slide, you can see a hypothetical memcpy situation.

05:49.470 --> 05:58.810
And because the developers that are working with CAN bus probably know that they can never receive more than 8 bytes, the destination buffer would be allocated to 8 bytes because why waste memory?

05:59.090 --> 06:04.550
Then the source of the operation as a second parameter would be CAN data, because that's what we want to copy.

06:04.850 --> 06:19.770
But since you're not always receiving 8 bytes, but sometimes you receive 4, 3 or any other value, you can use this convenient DLC field, which the frameworks you're using is giving you, to actually specify how many bytes should be copied.

06:20.070 --> 06:22.430
And that's exactly where the problem comes.

06:22.430 --> 06:25.750
Now I'm going to do the funny thing of readjusting the microphone.

06:26.230 --> 06:30.130
I'm sorry if I drop it, because I want to sit for the demo.

06:37.820 --> 06:39.160
Sorry for that delay.

06:40.320 --> 06:45.140
We'll basically jump into our first demonstration.

06:45.580 --> 06:49.000
But before that, I'd like to introduce you to the hardware that I brought with me.

06:49.800 --> 06:53.080
It's in this yellow suitcase that you can see on the stage.

06:53.240 --> 06:58.720
And as you can see, it contains a lot of PCBs, wires, some displays, LEDs.

06:59.360 --> 07:06.680
And I hope you like it at least as much as people at the airport security did, because I had to explain to like 3 people what it is.

07:06.680 --> 07:08.360
I had to take it apart.

07:08.960 --> 07:13.980
And they basically swiped the hell out of it with those anti-explosive detective papers.

07:14.380 --> 07:17.820
So it's kind of a miracle it still works, but it does.

07:18.500 --> 07:24.740
In this case, I have a red board here, the red one in the corner.

07:24.740 --> 07:27.020
That will be a victim for our first demo.

07:27.020 --> 07:30.540
It's an NXP board where I'll have source code running and everything.

07:31.100 --> 07:35.520
The guy in the corner here, the simple Arduino, that's the attacker.

07:35.520 --> 07:41.120
It has a little button here that you can't really see, but whenever I press it, a malicious message will be sent.

07:41.120 --> 07:43.960
I'm going to ignore the middle Arduino for now.

07:44.120 --> 07:47.520
And this is just a power source so that it actually works.

07:47.520 --> 07:49.120
So that's not really important.

07:49.540 --> 07:58.260
Now, if I'd like to show you actually how the source code looks like for these boards, I'll start with the attacker one, so the Arduino.

07:58.600 --> 08:02.360
In the setup function, I'll just set up CAN bus serial and the button.

08:02.360 --> 08:03.780
That's not really interesting.

08:04.480 --> 08:06.020
Then I set up the message.

08:06.100 --> 08:09.180
I'll start by setting a CAN ID 600A.

08:09.200 --> 08:11.760
You'll find out in the second demo why.

08:12.340 --> 08:16.520
But the most important thing, I'll set the DLC field value to F.

08:17.580 --> 08:20.220
Then I need to set some dummy payload.

08:20.220 --> 08:27.520
In this case, it would be A, B, C, D, E, F, G, H in capital ASCII so that we can actually see it and refer to it while we're debugging.

08:28.020 --> 08:36.080
And inside the loop, it just waits for the button press and whenever that happens, we're going to send the message with this function.

08:37.220 --> 08:42.940
When I switch to the victim, so the red board code, which we will be debugging, there's a main function.

08:42.940 --> 08:44.360
We just have two variables.

08:44.360 --> 08:48.540
One is obviously called overwrite buffer because we're going to overwrite it.

08:49.320 --> 08:57.100
And we start by setting it to value 1, 2, 3, 4, 5, 6, 7, again, so that we have something easy to refer to.

08:58.040 --> 09:01.820
Then there is not really interesting CAN bus setup, which I'll just skip.

09:02.060 --> 09:06.620
And in here, I'll be waiting for a message to arrive.

09:06.620 --> 09:17.920
And when it does, there is the main copy function, which is basically identical to the one from the previous slide, where we're copying into the buffer.

09:17.920 --> 09:23.540
Frame DSR is how MCU Expresso chose to call the data field.

09:23.880 --> 09:25.480
I'm not to blame for that.

09:25.480 --> 09:28.460
And frame DLR is the DLC field value.

09:28.540 --> 09:30.340
That's how it's called in MCU Expresso.

09:30.340 --> 09:33.100
Again, in every framework, it will be called differently.

09:33.860 --> 09:42.100
Since I have the board in the case, I can just hit debug, and this should run it, run the code, and we should stop on our first breakpoint.

09:42.280 --> 09:54.360
If I step over this, I can just investigate that the override buffer is now set to values 1, 2, 3, 4, 5, 6, 7, and ASCII terminated by a null byte, which is exactly as expected.

09:54.780 --> 10:01.180
And if I run the code, nothing really happens, because we're now in this endless loop and we're waiting for CAN messages to arrive.

10:01.460 --> 10:14.420
To do so, I need to press this almost invisible button, and hopefully you see a notification pop up here on my screen that tells me that the breakpoint was hit at this memcpy function.

10:15.340 --> 10:23.000
In the data that I'm using as a source for the memcpy, you can see the A, B, C, D, E, F, G, H, which we've set in the Arduino.

10:23.560 --> 10:28.920
And in the DLR, we can see value 15, which is the DLC field value which we've set.

10:29.220 --> 10:33.000
I'm just going to step over this so that the memcpy finishes what it did.

10:33.120 --> 10:38.980
Now, inside the buffer, I should have this A, B, C, D string.

10:39.480 --> 10:44.620
But more importantly, let's have a look at what is in the overwrite buffer.

10:44.620 --> 10:48.000
I'm just going to scroll over it.

10:48.240 --> 10:56.580
The very first value, I hope it's readable a bit, is value 15, which is suspicious, because 15 is the DLC field we've sent.

10:56.720 --> 11:04.660
But the remaining values I don't really recognize, because there is nullbyte, then 137, 172, then repeated, then another nullbyte.

11:04.900 --> 11:11.860
The final nullbyte hasn't been overwritten, because we're overwriting just with seven bytes, so the final nullbyte is from the original buffer.

11:12.680 --> 11:19.680
But now it would be good to see whether we have some control over the data that we're overwriting with.

11:19.760 --> 11:25.160
To do that, we have to investigate a structure called mscanframe.

11:25.320 --> 11:27.720
Again, this is specific to MCUXpresso framework.

11:27.720 --> 11:30.580
In other frameworks, you'll find something completely different.

11:31.080 --> 11:41.220
And we'll see that the value of DSR, which is the data where we started the copy operation, is actually a member of a union, so that you can access the data as data words or data bytes.

11:41.400 --> 11:46.040
But right after that, there is the DLR value, which is the DLC.

11:46.140 --> 11:51.080
This confirms our suspicion that we are overwriting with this structure.

11:51.120 --> 11:59.860
But the remaining values, such as buffer priority, type, format, and some timestamps, those aren't really in control of the attacker.

11:59.860 --> 12:03.100
So we have very limited control of what we overwrite with.

12:03.480 --> 12:10.120
But nevertheless, we can actually use this for some other impact than just denial of service that's in the title of this talk.

12:10.120 --> 12:19.520
I can imagine situations where you overwrite local and global variables in a way that you change their values from a zero to something else.

12:19.740 --> 12:21.180
Why this is important?

12:21.440 --> 12:27.000
And that's because when you program in C, there's quite a common practice of doing a null check.

12:27.000 --> 12:31.420
A null check is, for example, is authenticated if it is a variable.

12:31.460 --> 12:36.240
Then if it is zero, you're not authenticated, and anything else would mean you are.

12:36.340 --> 12:40.420
And this way you could theoretically bypass some of the controls.

12:40.800 --> 12:55.100
Although in the real life examples, this always resulted just in the denial of service, usually for various reasons, but mainly by overwriting pointers to something that makes absolutely no sense, and then crashing the firmware.

12:55.560 --> 13:04.500
With that, I'd like to transition into the second demonstration where I'll be using an ECU from a Tesla Model 3 vehicle.

13:04.620 --> 13:10.080
It's the security controller that sits between the seats where you tap your NFC card when you want to drive.

13:10.460 --> 13:16.460
It's responsible, for example, for unlocking the door and the decision whether you can drive or not.

13:16.460 --> 13:19.240
This is done together with the body control module.

13:19.760 --> 13:26.980
And if we do a typical assessment, we first unpack the ECU and see what the PCB has to offer.

13:27.240 --> 13:41.180
In this case, we found that on the bottom of the PCB, there is an SPC560B64 microcontroller from STMicro, and literally right next to it are pads which are labeled STJTAG.

13:41.420 --> 13:48.780
The jackpot in this case was that this was actually working JTAG interface, so we were able to dump the firmware image and proceed with the assessment.

13:48.780 --> 13:51.280
And this is exactly what I'd like to do here.

13:51.280 --> 13:59.840
And we will start by dumping the image, then we will analyze the firmware, find the vulnerability, exploit it, and then play with the oscilloscope and have some fun.

14:00.020 --> 14:04.580
So let me just show you the unobfuscated view on the suitcase.

14:05.140 --> 14:09.200
You can see the ECU, obviously the big green thing with the Tesla logo.

14:09.440 --> 14:14.960
The Arduino in the middle serves only one purpose, and that is to simulate the rest of the car.

14:14.960 --> 14:19.300
So in fact, this suitcase is the smallest Tesla car that you have probably seen.

14:20.200 --> 14:22.480
I'll have this again, a little black button.

14:22.480 --> 14:27.160
Whenever I press it, I simulate the rest of the car so that the ECU works as if it is in.

14:27.160 --> 14:31.520
If I don't do that, I can't really work with this ECU and show you it live.

14:32.780 --> 14:36.320
I talked about the debugger, so I have just the JLink.

14:36.880 --> 14:38.060
I hope it's readable.

14:39.120 --> 14:41.360
In this suitcase, there are actually multiple layers.

14:41.360 --> 14:48.340
One of the layers contains a JLink debugger, and I can connect with it and just type connect.

14:48.600 --> 14:53.380
I have pre-selected the correct MCU, so SPC560B64.

14:53.380 --> 14:57.700
So I'll just leave everything default, because I like defaults.

14:58.260 --> 15:01.500
And the CPU is now halted and I'm connected to it.

15:01.500 --> 15:03.700
This is a good time to dump the firmware image.

15:03.700 --> 15:06.620
I can use savebin command for that.

15:06.660 --> 15:11.480
And as a destination, I'll choose file tmpfw.bin, for example.

15:12.100 --> 15:15.040
And now I have to specify the memory range, which I want to dump.

15:15.040 --> 15:19.240
So it will be from address 0 to address 17FFFF.

15:20.060 --> 15:28.920
This memory range, I've read it from the data sheet, but I consider it kind of boring to open a data sheet here, so I'm just going to cheat and skip on that.

15:29.380 --> 15:31.820
But this will save the binary from that section.

15:32.000 --> 15:33.660
You can find it in the memory map.

15:33.660 --> 15:36.560
There's actually no science around this.

15:37.320 --> 15:43.420
Now we have a firmware dumped, and I'm going to open IDA and analyze the binary.

15:43.580 --> 15:47.680
I made all fonts ridiculously large, so I hope you can read it.

15:47.680 --> 15:53.960
For me, it's quite painful to work like this, but it's for the audience's sake.

15:55.240 --> 16:01.420
I'm going to choose PowerPC, because as I said, I was reading the data sheet, so I know that it's a PowerPC.

16:02.000 --> 16:06.380
And from now on, I'll use my beloved defaults everywhere.

16:08.520 --> 16:11.200
And this should load me a binary in an IDA.

16:11.200 --> 16:18.080
But as you can see, nothing really happened, because we're working with a binary blob, and IDA doesn't really know, is it the code?

16:18.080 --> 16:18.720
Is it data?

16:18.720 --> 16:19.600
Is it a mix of both?

16:19.600 --> 16:20.580
There are no entry points.

16:20.580 --> 16:21.500
What should I do?

16:22.260 --> 16:33.400
Since this is a situation that we faced quite often, working with extracted firmware image from a microcontroller, we made a little plug-in for IDA Pro, which is called Firm Loader.

16:33.540 --> 16:39.900
And here I just have to select the brand, the line of the MCU, and the correct MCU.

16:40.760 --> 16:42.880
And this will start the auto-analysis.

16:42.880 --> 16:51.400
It will also create memory sections such as RAM, peripherals, and will mark the code flash as executable and trigger the auto-analysis.

16:51.860 --> 16:56.960
If I'm to do a real assessment, this is a starting point, not a complete analysis.

16:56.960 --> 17:04.220
I have to do a bit more manual work to make it ideal, but we don't have time and we have to cheat a bit.

17:04.340 --> 17:11.720
So I'm going to be fine with the analysis that it did, mainly because it already found 1700 or so functions.

17:11.840 --> 17:16.000
So we have the binary loaded and we can start working with it.

17:16.120 --> 17:21.580
Now I'd like to show you two different ways on how to approach firmware analysis of an MCU.

17:22.000 --> 17:25.620
The first approach is identifying standard functions.

17:25.680 --> 17:34.540
Standard functions are things like memcpy, malloc, free, all of those libc functions that developers use everywhere.

17:34.680 --> 17:39.500
It's good to find them, because then it's a bit easier to uncover the custom logic in the firmware.

17:40.000 --> 17:42.940
You can use AIDA Lumina if you have AIDA for that.

17:42.940 --> 17:51.140
It's a great tool, but I'm going to do it manually, not because I just want to scare you with the assembly, but I just actually want to show you that it's not that hard.

17:51.760 --> 17:57.360
Let me just adjust the view of AIDA a little bit so that we have a more comfortable view.

17:58.340 --> 18:00.820
And I'm also going to need to set the compiler.

18:00.820 --> 18:02.180
Sorry for that delay.

18:03.280 --> 18:05.780
And this function is actually memcpy.

18:05.780 --> 18:10.120
I'm just going to walk you through very quickly on why it is a memcpy.

18:11.040 --> 18:18.820
Again, I had to read about PowerPC to figure out that the first three arguments to a function are passed in registers R3, R4, and R5.

18:18.820 --> 18:29.440
Therefore, if I look at the memcpy parameters, I know that the first one is the destination, the second one is source, and the third one is how many bytes should be copied.

18:29.760 --> 18:36.280
So the third parameter, R5, is here first incremented, and then it's set into something called counter register.

18:36.280 --> 18:38.920
Again, I had to read about PowerPC, unfortunately.

18:39.520 --> 18:45.120
Then this counter register is decremented every time we execute this instruction.

18:45.380 --> 18:49.020
And if it reaches zero, we go here to end the function.

18:49.020 --> 18:54.560
But as long as it's not zero, we will be executing this code block in a loop.

18:55.220 --> 19:03.800
So we already know that whatever this function does, it will do it for how many times we tell it in a third argument, which is already a good definition of a memcpy.

19:04.320 --> 19:14.640
But inside the body of the loop, we can see that it takes the second argument, so register R4, indexed by R0, and stores that value into R7.

19:15.160 --> 19:23.840
Then instruction after that takes that value from R7 and stores it in the first argument, which is R3, again indexed by R0.

19:23.940 --> 19:28.780
Then the index is just incremented and this repeats for however many times we specified.

19:28.960 --> 19:31.320
This is how you find a standard function.

19:31.320 --> 19:33.660
Sometimes it's a bit more complicated.

19:34.060 --> 19:36.780
I admit this was one of the very easiest examples.

19:37.340 --> 19:43.580
I'm also going to set the type of the function because I would like to show you some automation later and for that this is necessary.

19:44.180 --> 19:57.300
Now, if I'm doing a security analysis of a firmware, I can hit X on the keyboard and I should now theoretically go through all of these memcpy cross-references and see if they are vulnerable or not.

19:57.360 --> 20:00.240
I'm lazy and I don't have time, so I'm not going to do that.

20:00.980 --> 20:05.920
Second approach that I'd like to show you is a combination of static and dynamic analysis.

20:06.780 --> 20:11.040
During the dynamic analysis I know what the ECU sends on a CAN bus.

20:11.040 --> 20:13.200
I know what it receives on the CAN bus.

20:13.340 --> 20:21.660
So it's actually very simple to just use search for immediate values and find the CAN ID I'm interested in.

20:21.660 --> 20:26.860
This isn't exactly working every time, but in this case it does.

20:27.140 --> 20:39.320
So the second hit is especially interesting because it's in compare instruction and it's comparing register R3, so first argument to a function, to the value that I know I saw on the CAN bus.

20:39.320 --> 20:43.240
And if I look around I actually see a lot of the values that I've seen on the CAN bus.

20:43.240 --> 20:45.640
This one, this one, this one.

20:45.640 --> 20:55.540
So this is good enough assumption for me to just rename this to CAN handler because it appears to be handling incoming CAN messages.

20:56.040 --> 21:00.780
And now I'll end the torture and switch to the decompiler because we need to speed up a bit.

21:01.180 --> 21:05.700
And we said that the first one is CAN DLC, so I'm just, uh, CAN ID, sorry.

21:05.800 --> 21:07.760
I'm going to rename it to that.

21:08.420 --> 21:16.540
With a bit of analysis that I'm not going to show you here, uh, we would figure out this is CAN data and we would actually figure out this is CAN DLC.

21:18.120 --> 21:26.540
And now we basically went from a black box assessment where we took an ECU from a vehicle to a crappy source code review.

21:27.480 --> 21:33.220
Uh, and again, as you can see there are many CAN bus IDs being handled by this function.

21:33.500 --> 21:40.680
And in theory I should go through all of them and identify whether any of these are vulnerable to some issues.

21:40.880 --> 21:43.800
Again, I'm lazy, I don't have time so I'm not going to do that.

21:44.020 --> 21:50.660
Uh, instead I'm going to skip over and if you remember the attacking board sends CAN ID 600A.

21:50.660 --> 21:54.400
So I'm going to just look at the handler for CAN ID 600A.

21:54.400 --> 21:58.040
I'm going to rename it to that because I don't want to lose track.

21:58.400 --> 22:02.840
And this function gets CAN data and CAN DLC as parameters.

22:02.860 --> 22:04.460
So let's just open it.

22:05.200 --> 22:07.160
And do the renaming again.

22:10.220 --> 22:15.880
And now this mem copy here screams at us I'm vulnerable basically.

22:16.360 --> 22:20.140
Because as you can see this length specifier here is CAN DLC.

22:20.360 --> 22:22.080
The source is CAN data.

22:22.220 --> 22:25.240
And as a destination there is this weird memory address.

22:25.240 --> 22:29.260
Uh, weird memory addresses in MCU firmware are usually global variables.

22:29.260 --> 22:34.340
They're just static places in memory which are then used to access the variable values.

22:34.400 --> 22:42.540
If I look at it, I can find that there is between 1AF0 and 1AF7 I have preallocated 8 bytes for this variable.

22:42.840 --> 22:46.280
And right after it there is variable called 1AF8.

22:46.740 --> 22:50.460
And if I look at the cross references I can see that it is being used somewhere.

22:50.460 --> 22:58.060
So if I overflow this variable, I may adjust something in the firmware and cause some undesired behavior.

22:58.160 --> 23:04.760
I'm just going to synchronize the view because that's going to be useful if my right click would have worked.

23:04.980 --> 23:06.620
Sorry for that.

23:09.750 --> 23:17.550
And now when we saw the CAN handler, there were many, many, many functions that were handling CAN messages.

23:17.550 --> 23:20.010
I said I'm lazy so I'm not going to do that.

23:20.090 --> 23:29.550
But because I'm lazy all the time, but I don't have time just right now, we created a plugin that automates a bit a search for cross references.

23:30.090 --> 23:32.470
This plugin is called Wolfie.

23:32.730 --> 23:37.570
And to work with it, I wonder why my touch pad doesn't work.

23:37.570 --> 23:38.630
Thanks.

23:40.050 --> 23:42.890
You just have to add certain functions.

23:42.890 --> 23:46.890
I'm sorry I don't know how to enlarge this text so I'll just describe it.

23:46.990 --> 23:52.430
We first select some name for the rule that actually doesn't matter at all.

23:52.670 --> 24:01.310
And then we have to use a filter to somehow filter out all the memcpy functions we're not interested in or to just filter those that we are interested in.

24:01.310 --> 24:04.230
To find this vulnerability, there is one precondition.

24:04.230 --> 24:07.630
The memcpy function must not have static third parameter.

24:07.630 --> 24:13.570
If there is a static value like 2, 3, 8 in a third parameter, this vulnerability will not work.

24:13.570 --> 24:21.970
So I'll start by saying that the not param 2 dot is constant.

24:22.930 --> 24:26.090
I'm sorry for the syntax, it's just Python code that gets evaluated.

24:26.630 --> 24:34.310
And if this condition is fulfilled, I can also say that I'm actually only interested in the functions that are called from the can handler.

24:34.370 --> 24:46.810
So I can just say function, if I'm be able to type, function call dot reachable from can handler.

24:48.110 --> 24:59.230
And this query will now take a look at all 100 plus cross references to a memcpy function and it will only filter out those that match the criteria I've specified.

24:59.690 --> 25:06.710
As you can see, the very first one is the one we found manually in can handler 68, but there are five others.

25:06.710 --> 25:13.330
I'd like to specifically look at the one at 6F1BA, which is right here.

25:13.330 --> 25:22.470
The main reason I want to look at it is if I look at the cross references of this function, we can see it's being called at the can handler 68 here.

25:23.170 --> 25:24.410
And it's right here.

25:24.410 --> 25:28.350
As you can see again, it gets canData, canDLC as parameters.

25:29.030 --> 25:31.090
So rename again.

25:37.050 --> 25:41.830
And now we can see that right in the middle of the function, there is a memcpy function.

25:42.450 --> 25:46.070
It uses as a source canData as a count of bytes.

25:46.070 --> 25:53.290
This time it's V4, but V4 is here, it's just canDLC, so it's just canDLC through a proxy, let's say.

25:53.490 --> 25:57.990
The destination in this time is variable V7, which is a local variable.

25:57.990 --> 25:59.790
It is an 8 byte array.

26:00.050 --> 26:02.710
So we can share again, we will be overflowing.

26:03.410 --> 26:07.150
But we will be overflowing into something called variable V8.

26:07.250 --> 26:14.390
And if you look at what it is, it actually is set to some constant value here from a global variable at the beginning of the function.

26:14.390 --> 26:17.650
And then it's compared to it at the end of the function.

26:17.830 --> 26:21.290
This is a thing called stack canaries.

26:21.290 --> 26:27.370
And it is used to protect the values on the stack against buffer overflows such as this one.

26:27.490 --> 26:34.890
So in this case, we know that when we send this scan message, we would actually cause this stack canary to get triggered.

26:35.230 --> 26:37.370
But we should have a look at what's going to happen.

26:37.370 --> 26:41.250
And that's in this function, we will actually play a bit with peripherals.

26:41.250 --> 26:44.670
But more importantly, there is this endless while loop.

26:44.670 --> 26:49.990
Endless while loops are the best indicators for fault handlers in microcontrollers.

26:50.030 --> 26:57.310
Because while in endless while loop, the device cannot cause any harm by just doing weird things with its peripherals.

26:57.310 --> 27:00.510
It's just executing the same instruction over and over again.

27:01.650 --> 27:05.070
Therefore, we will cause a crash of this microcontroller.

27:05.070 --> 27:06.790
That's why denial of service.

27:07.170 --> 27:12.010
But unfortunately, it would be through an anti-climatic overwrite of a stack canary.

27:12.770 --> 27:22.010
We have access to the debugger, so it would be quite nice to actually see this in action and see if we actually overwrite with the same values as we have seen in the previous demo.

27:22.310 --> 27:27.630
So to do that, I decided to torture myself further and show you the access in the debugger.

27:28.850 --> 27:32.270
Where I can set breakpoints.

27:32.770 --> 27:36.310
First one would be at before mem copy function.

27:36.670 --> 27:39.450
The second one will be right after it.

27:42.780 --> 27:44.740
And I'll check if the CPU is halted.

27:44.740 --> 27:45.400
It is.

27:45.400 --> 27:46.500
I'll let it go.

27:47.320 --> 27:52.720
Now, the ECU wouldn't actually react to any kind of messages because it's sleeping state.

27:52.720 --> 27:54.640
So I have to press this button.

27:54.860 --> 27:58.860
This will turn on one of the LEDs that were so loved at the airport.

27:59.380 --> 28:06.440
And once it turns off, I know that the car is properly simulated and I can start working with the ECU.

28:07.080 --> 28:09.720
The CPU still shouldn't be halted.

28:10.360 --> 28:14.360
But this would change after I send the attacker message.

28:16.860 --> 28:17.980
And as you can see, it did.

28:17.980 --> 28:20.900
Now we're right before the mem copy function.

28:21.100 --> 28:23.240
And we can investigate the registers.

28:23.240 --> 28:31.460
And from the beginning of the demo, we can actually know that the register R3 is the one that holds the destination location.

28:31.600 --> 28:36.800
So I can use mem 32 function command to dump that part of the memory.

28:37.100 --> 28:42.360
I'm also terrible sorry to anyone who knows how to work with Jlink and these kind of commands.

28:42.360 --> 28:44.020
I'm not really good with that.

28:44.960 --> 28:50.080
But here, these eight bytes are the legitimate V7 buffer.

28:50.080 --> 28:53.340
This is what should be overwritten with the candata.

28:53.520 --> 28:57.580
This is stack canary, which is interestingly set to all zeros.

28:58.300 --> 29:02.240
And this is the value that should be protected by the stack canary.

29:03.540 --> 29:07.520
And now comes the part where I'm not really good with Jlink.

29:07.520 --> 29:10.300
Because this is how I step over break points.

29:11.540 --> 29:14.200
As I said, I'm sorry to anyone who knows how to do that.

29:14.620 --> 29:23.900
And if I repeat the command now, we can see that these 41, 42, this is basically the A, B, C, D, E, F, G, H string.

29:24.680 --> 29:28.900
This is the stack canary, which has been overwritten with the can ID.

29:29.380 --> 29:35.420
So we can cheer up a bit because we are controlling quite a lot of bytes that we're overflowing.

29:35.760 --> 29:40.960
But we can't really because if we change the can ID, this overflow would never happen.

29:41.440 --> 29:45.420
So again, we can't really change what we overflow with in this case.

29:45.420 --> 29:48.860
Then this is probably can DLC based on the value here.

29:48.860 --> 29:53.040
Then there are some null bytes for some flags inside the can structure.

29:53.140 --> 29:55.660
And this D8 is from the original pointer.

29:55.660 --> 29:57.480
We haven't really overwritten that.

29:58.880 --> 30:01.780
Now having access to the debugger is nice.

30:03.220 --> 30:04.340
And I'm not really good with that.

30:04.340 --> 30:06.220
But sometimes you don't have that.

30:07.200 --> 30:09.560
And let me just check that the CPU is not halted.

30:09.560 --> 30:10.580
It is not.

30:10.940 --> 30:16.700
And in this suitcase, there is a third layer underneath the J link layer and that contains an oscilloscope.

30:16.700 --> 30:20.140
One of the oscilloscope probes is connected here to the CAN bus.

30:20.180 --> 30:25.980
The other oscilloscope probe is hidden under this to sense the NFC field.

30:26.280 --> 30:33.940
So if I now press this simulation button, I can go into the oscilloscope view and start tracking.

30:33.940 --> 30:35.780
The red line is the NFC field.

30:35.780 --> 30:37.740
The blue line is the CAN bus.

30:37.960 --> 30:41.200
So when the ECU comes up, you can see NFC field is up.

30:41.200 --> 30:48.040
And if I press the attacker button, you'll first see that... let me stop that first.

30:48.040 --> 30:51.380
You'll see that the CAN messages have stopped being sent.

30:51.380 --> 30:53.840
That's the reset of the ECU.

30:54.240 --> 30:58.200
And about a half a second after that, the NFC field got killed as well.

30:58.200 --> 31:03.360
This is how we initially found the vulnerability through fuzzing and using this side channel detection.

31:03.720 --> 31:11.960
The delay between the crash of the MCU and the NFC field disappearing is caused by the fact that the NFC controller is actually a separate chip.

31:12.520 --> 31:16.520
And there is a communication line between the main MCU and the NFC chip.

31:16.620 --> 31:20.320
And that's why there is a bit of a half second delay before that shuts down.

31:20.900 --> 31:26.700
I'll try to zoom into this, but I have never found a way how to increase text here.

31:26.700 --> 31:29.160
So you'll probably not be able to read that.

31:29.640 --> 31:35.640
But the message before this drop happens, the last message is the one we've sent.

31:35.640 --> 31:37.200
So ID 600A.

31:37.500 --> 31:42.860
And the voltage drop is actually caused by the GPIO pins being reset into their default state.

31:43.220 --> 31:48.780
After that, if I zoom out a bit, there is a break in CAN messages being sent.

31:48.780 --> 31:50.880
This is because the ECU is restarting.

31:51.020 --> 31:55.420
And then it gets into the initial state where it again waits for it to be restarted.

31:55.700 --> 31:58.080
This is just one of the side channel ways.

31:58.360 --> 32:06.080
And when I was here, I've been actually given this invitation to a high roller cone.

32:06.740 --> 32:10.040
And quite interestingly, it actually works as an NFC field detector.

32:10.600 --> 32:20.140
So if you don't want to use oscilloscopes, for whatever reason, you can actually use this invitation that you can get here at DEF CON.

32:20.680 --> 32:29.060
If placed properly, this will light up the LED here whenever it sees the NFC field.

32:29.580 --> 32:34.700
And then by just pressing this button, you'll see that the NFC field will stop.

32:34.980 --> 32:38.360
I'm not going to the high roller cone, by the way.

32:38.360 --> 32:39.740
I have other plans.

32:40.280 --> 32:41.660
But anyway, thanks.

32:41.660 --> 32:42.680
I like this.

32:43.780 --> 32:48.480
The other side channel possibilities are detecting power consumption.

32:48.480 --> 32:52.520
That, however, requires soldering, which we have done here.

32:53.320 --> 32:56.940
But you can also do it on the CAN bus.

32:57.300 --> 33:00.100
There are usually messages that appear periodically.

33:00.100 --> 33:03.920
So you can detect the time difference in between the periodic messages.

33:04.420 --> 33:10.300
And the easiest way is when you find an ECU that actually sends a specific message on a reset.

33:10.300 --> 33:12.940
That's the easiest way how to detect a reset.

33:13.380 --> 33:16.340
There is a fuzzer published for that as well.

33:16.340 --> 33:19.700
It's actually not published yet because I haven't clicked the button to publish it.

33:19.700 --> 33:21.520
But it will be right after this call.

33:22.560 --> 33:25.600
Now I'd like to discuss who's affected by this issue.

33:25.620 --> 33:31.660
It could be basically anyone who just blindly accepts the value of this DLC field in some memory copy operations.

33:32.120 --> 33:45.720
We also looked at the popular SDKs and RTOSs and found that Armabed OS, STM32Cube SDK and NXP MCU Express OSDK, they don't really care and they will send you any value in the DLC field that you send to it.

33:46.020 --> 33:48.180
We reported this to all of them.

33:48.180 --> 33:51.020
So as of now, this should have been fixed.

33:51.200 --> 33:55.140
But there are other frameworks, some of them commercial, we haven't really looked at.

33:55.140 --> 33:56.980
So those might be still vulnerable.

33:57.660 --> 34:02.960
We looked also at the default Linux kernel drivers, which are not vulnerable.

34:02.960 --> 34:08.620
So those will never ever pass you anything higher than 8 in the DLC field if you're working with it.

34:09.520 --> 34:12.220
And now is a good time to look at other CAN bus versions.

34:12.220 --> 34:19.500
So CAN FD is not affected by the nature of it because the data payload was increased to 64 bytes.

34:19.620 --> 34:28.060
But the DLC field stayed at 4 bits and there is this weird translation table where you translate into those 4 bits how many bytes follow.

34:28.660 --> 34:31.400
CAN XL is likely not affected.

34:32.080 --> 34:37.800
I would like to wait with any judgments here because I haven't seen any real implementation of it anywhere.

34:37.940 --> 34:41.360
But based on the specification, it should not be.

34:42.280 --> 34:45.860
Finally, I would like to have some general takeaways from this.

34:45.860 --> 34:55.920
So first of all, if you're a developer, regardless of the protocol you work with, you should consider the metadata of it as entrusted, not just the data it arrives over it.

34:56.740 --> 35:03.920
It is also good to know how the libraries you're actually working with are handling values such as length of incoming data for that matter.

35:04.360 --> 35:16.320
And if you're on the assessment side such as me, I would like to suggest that it's always worth looking one layer below the obvious application data into the protocol world because there may be some interesting vulnerabilities in there as well.

35:16.800 --> 35:21.080
With that, I'd like to thank you for your attention and ask if you have any questions.

35:21.080 --> 35:24.020
I'll try to stand and adjust this microphone again.

35:33.390 --> 35:38.470
The high roller invitation, although I'm not sure if it's invitation, I can give it to someone if they want.

35:39.450 --> 35:42.790
I have enough things that the tech NFC feels at home.

35:49.260 --> 35:52.340
There's a microphone over there so that everyone can hear.

35:55.020 --> 36:00.820
Have you tried to increase the F value to read more memory and see what happens?

36:01.120 --> 36:02.980
I'm sorry, I haven't heard.

36:03.440 --> 36:04.540
Could you come just here?

36:04.540 --> 36:06.500
This microphone seems to work a bit better.

36:07.240 --> 36:08.840
You have a stage time.

36:13.120 --> 36:17.220
So the question was whether I tried to increase the F value in the DLC.

36:17.460 --> 36:20.160
I can't because there are just four bits.

36:20.260 --> 36:23.920
And if I set all four bits to one, it is up to F.

36:24.260 --> 36:27.200
I'd love to have more than F, but I can't.

36:27.200 --> 36:32.720
Actually, in CanXL, the DLC field is 11, which can fit up to 2047.

36:33.300 --> 36:38.700
But then the specification says you can have up to 2048 bytes of data.

36:39.500 --> 36:42.100
And I don't know how is that going to work.

36:42.260 --> 36:45.520
But I'll wait for the implementation and then I'll hack crap out of it.

36:53.140 --> 36:54.380
I guess that's all.

36:54.380 --> 36:56.740
So thank you and have a nice day.

