My name is Aaron or Acorn. Uh and I'm a security researcher with Grimm. And I play with cars and I'm gonna tell you about what UDS is and why it can help you hack cars. And let's get moving. So what is UDS? Um I'm not gonna go through all this detail because it's really boring and a bunch of standards. But basically UDS is a higher level protocol that lives on top of CAN. CAN itself uh for the for the purposes of this particular talk you can think of CAN as about uh kind of old school 10 100 ethernet. You can have a bunch of things on the bus and they can talk to each other to use the MAC address to figure out what messages are meant for them. Right? So keep that in mind that's basically CAN. UDS itself is then a higher level protocol living on top of that. As you may know CAN has a limit of 8 bytes per message. And so if you want to send anything bigger than 8 bytes, like you want to send firmware to an ECU on a car, you're going to need to use a higher level protocol to segment that up into multiple messages. So ISOTP is a segmentation layer, kind of like IP. And then you have UDS itself which you can think of like, I mean the analogies break down at this point but you can go with maybe UDP, TCP, whatever you feel like. Like I said the analogy does break down at that point. But there's the ISO standards if you feel like looking at it. One quick mention OBD2. OBD2 is a little bit different standard. Uh it's not really living on top of these things as well. Uh it but it's meant it's very specifically uh single purpose meant to talk to the uh emissions related equipment for scanning codes. So it's not really the same thing but sometimes the ECUs which do talk OBD2 also talk UDS. Sometimes not. So CAN. Um you have a message ID, arbitration ID. It's what identifies what message is meant to go on the bus. Uh the if you have standard CAN is 11 bits only for the message ID, arbitration ID. In standard for UDS is 7xx is going to be the request and then 7xx plus 8 is going to be the response ID. This will make sense eventually. I promise. Uh the 29 bit which or the extended CAN is a little bit different where it uses two different uh you know two different bytes as kind of the sender and receiver. It makes a little bit more sense. Uh OBD2 there's a specialized set of uh IDs that are meant for OBD2 only. So you don't know and so going back to the Ethernet and IP example, we don't have uh routers here. We don't have a switch. We don't have DNS to tell us what's on the bus. So the thing is we need to figure it out. But right here we've got a very it's a pretty limited subset of IDs that we can scan to figure out what's on that bus. It's like a maximum of that's actually a little bit less than 255, 256. So real quick, ISOTP, there's a couple different frame types. It's not really important at this point but basically the first nibble of the CAN data frame indicates what type of message it is. Since it's a limited subset of values, it can make it really easy to see uh large data transfers. And which is one of the things that is nice about UDS. It makes it easy to just visually take a look at it and see that something is happening. Uh couple different UDS services. If you take a look at this and you say what do I want to do to a car? You can say that well downloading and uploading things to the ECUs does sound interesting. Transferring data, security access. This is there's a lot more than this. If you want to know you can go look at the standard. Actually the Wikipedia page for UDS is pretty good. Uh and so you can go take a look at that. There's a lot of things in here that are custom per automaker which means to figure out what uh is actually supported for an ECU. You need to either have the design documents or you need to figure it out. So that's kind of the goal here. So let's take a look here's a couple different ECU uh UDS responses. The whole idea is you've got a request. So in the very first message here we've got a request ID of 74A. And the response here is 7B4. And you'll notice that that's not actually what I said earlier. Earlier I said it should be 8 more than that. Well that's the standard. Just because it's the standard doesn't mean it's actually what is ever done because nothing's ever actually done standardly on passenger automa- passenger vehicles. So here we see the message uh the very first you see the first nibble of the data is uh 0 which means it's a single frame message. Again it's very obvious what's going on. Second nibble is the length. And then after that we see 10, 0, 3. 10 is the uh diagnostic session request. 3 is just a session ID. What does that session mean? Well again it means whatever the automaker wants it to mean. So the only way to figure out what it means is if you can start actually taking uh you know querying what functionality is available in that diagnostic session. You might have some simple diagnostics in session 2. You might be able to um reprogram the ECUs in session 2. Maybe session 3 lets you do things like um disable the brakes or something like that. You know so maybe it's some uh debugging or implementation. Something the engineers were doing that's not really meant for general consumption. Well if you can figure out what that is if you can get in there and scan what's going on then it allows you to get access to what that type of functionality is. So other another one the second UDS request here again we've got 7 oh oh yeah so the response itself so we have 0, 6. Uh so again single frame message 6 bytes. 50. So the first byte here is isotp. That's kind of the encapsulation layer. UDS itself is then the actual uh the remaining bytes right the remaining 7 bytes of this message. The request is the service ID which was 10. The response if it's a successful response is then hex 40 more than the request. These all seem incredibly arbitrary. I know. And basically it's because I don't know the people who wrote the standard did it that way. It's actually it's similar it's based on of older standards so what you're seeing here is kind of the evolution of a lot of things based on a lot of things based on a lot of things. Which is basically how all technology in computers has ever worked. Because it's all based on well we did it this way so let's do it this way now. That's why it's this way. So you just gotta take a look at it and look at the standard and you eventually figure it out. So 50. That means successful because it was 40 more than the request. And then the next thing is going to be 3 which is the diagnostic session that was requested. The length is 6 which means there's 3 more bytes of data here. I have no idea what they mean but usually it doesn't actually matter much what they mean but they're here in case you wanna refer to it later. Uh if you're actually implemented this or doing something with the dealer tools it might be meaningful. I don't know. So if it's 40 more that's successful response. Uh what happens if it's an unsuccessful response? That's the next example I got here. Got 0, 2, 10, 4. So it's slightly different session uh session ID I'm looking for. The response itself then is 7F. That means it's a negative response. And then you have the error code here which so it says after the negative response the next byte is the service ID that caused the error. 10. And then it's the error code. Well the error code itself is 12. Uh that is thankfully a standard thing in this. And 12 means subfunction not supported. So that basically is somebody telling us that we don't know what this means. So this is again this is the way that the UDS protocol is allowing us to enumerate what functionality exists on an ECU. The last one here is a read did message. So a did in UDS speak is uh a block of data. If you wanna find out what VIN is in a car you read a particular data identifier and in this case data identifier F190. Uh that's part of the standard. There's a range of these different dids which are standard for the ISO standard. There's uh then there's a bunch of other stuff which automakers or suppliers do because they feel like it. Or probably really to put in information that they feel is necessary. What version of software do we have in here? Uh what version of the hardware is this? Who compiled it? Navy. So here the response was uh there's a couple two things I wanna point out about this last one. You can see that the error is we have a 7F which means error. But the error code is 78. Error code 78 means that it's a it's a hold on let me look let me read this properly. Request correctly received. Response pending. So basically it means hold on a second. And this is one that always annoyed me a little bit. Because if you take a look at the timestamps it didn't actually take that much longer for the actual message to come back. First nibble is 1 which means it's the first frame of a multi-frame message. And then again like I said 3 is the flow control. So it's saying here's uh it's the person who's receiving the data telling the other end if it has any restrictions in the block sizes right? So if you can think of this again in terms of Ethernet this is kind of like uh uh uh handshake working out like MTU sizes or something like that right? Again these these these analogies are a little bit strained but you know it's it's a way to think about it. But then the first frame is 2. 2 means it's a multi-frame message. And this is really good if you're like looking at the dealer tools for taking a look at if you use the dealer tools and look at the canned messages that are happening while the dealer tools are like programming the ECU. It makes it extremely obvious when there's a block of data going to a particular location. Because it all starts with 2 and the message ID is all 7 something or other. Uh in this case the actual response doesn't matter too much. It was just because of those two things I wanted to point out there. Alright. So that's the basics of UDS. Um I could go in for quite a long time going into detail of UDS which would probably bore everyone more than you're already bored. Um unless you're a standards nerd, you don't necessarily like looking at standards. But it's useful to see that raw level of things. Tools can usually can easily uh abstract what's the important stuff that's going on behind the scenes that helps you have a deeper understanding of what the how the computer is behaving. So a couple useful tools I want to point out here. First one is CanCat. Um I work with Grimm. We've uh we like CanCat. We use it. It's not. There's a uh it has a lot of libraries for allowing you to do the low level can stuff which is what we demonstrate over at our booth. But we also have uh class in there for UDS. It allows you to interact with uh ACU uh doing UDS functionality. Um and what I'm gonna show here in the second half is taking a look at a tool I wrote on top of the CanCat stuff that allows you to essentially do Nmap style scanning uh on a car. There's uh two other ones I'd like to point out here that are capable of doing uh UDS things. First one is carrying car- carrying caribou which I have a hard time saying. Um it works pretty well. It works with standard Python can stuff. Uh if you have a socket can capabilities like a cantact, uh this will work well with it. Um it also does UDS scanning. Scapey can also do this as well. As much as I love Scapey, it's not uh the interface is a little bit harder to use unless you're familiar with how it's working. In this particular case. So can utils um the raw low-level socket can that if you run in Linux, you've got socket can. You've got can utils. They're installed by default, pretty sure, on most distributions. Uh but the thing is they interact with the raw can messages. They don't necessarily give you the UDS capabilities. Um what we demo over at our booth for just recording and replaying messages, you can do that with can dump and can player. Uh can sniff is also a really useful tool. Unfortunately can sniffer isn't actually support 29 bit messages. There's a pull request that's been open for like a year for it. Uh you can go and look at the pull request if you want to go and see it. You can go find a particular patch and download it and compile it. So it's useful for low-level things but uh once you start getting to higher-level protocols, uh you need to usually need to step outside of something like socket can. And here, like I said, you can use the can message uh can utils for doing can injection. And here's just a simple example. You don't really see it interacting with the vehicle at this point but what I did was I hit can dump. I started logging. I hit the unlock button. And then I can't, I control C to kill the can dump. Then I take the can dump that was generated and I run it through can player and I watch the car unlock itself, right? So this is again a simple example of message injection with can utils. Can sniffer is another useful one um and this allows you to do like an interactive viewing of the messages that are going on the bus. You hit the pound sign and then it will slowly shrink the window like notches the messages it's receiving. And then it highlights, if you give it the dash C flag, it'll highlight the new messages it receives. So in this particular case, what I did was I started can sniffer and then I was periodically hitting the lock, unlock button. And if you got a sharp eye, you might notice what message ID is actually doing the door unlocking in this case. Or if you already did, figured it out when you were taking a look at it on our booth. But anyway, so again, hit the lock, hit the unlock message, unlock button on the key fob and the message popped up, you're highlighted with the changed bytes in red. Can escapee again, so there's the uh, there's the incantation for doing it. You can go on the escapees, read the docs page and it will, there's a good lot of, there's a lot of information there about using escapee for automotive testing. And you know, this is just a simple example. Again, you can do can sniff, this again records all the messages and you can, it's a python interactive shell and you can interact with them using all the different python tools escapee presents. Caring caribou, again this is uh, doing an ECU scan. So this is starting to get into more of what I was talking about. How you can use UDS capabilities to identify what's on the bus. So this again was looking, I was scanning 3PO and I did UDS discovery. This is just using uh, the can, cannibal, I was uh, little $10 piece of hardware. And it's fi- going through all the different ECUs to find out what's present on the bus. And you can see here it's finding different things. It's finding some things that are standard, it's finding some things that are not standard. The particular results in this case don't matter too much. It's nicer to have something animated on the screen. So UDS, uh, one of the nicest, well okay, the functionality of, not the nicest, but one of the nicer things about UDS is the error codes. They're extremely verbose. This is one of those things where you take a look at a protocol and you can tell it was written by an engineer. Because they say, well I want to know why this didn't work. I want to know why this didn't work. So there's, well, there's a byte for the messages. So you've got a couple hundred possibilities of what the error code is. They're not all valid but a lot of them are valid. And here's some of the common ones. Service not supported. Conditions not correct, which is an interesting one. Security access denied. Invalid key. Exceeded number of attempts. Uh, so exceeded number of attempts for example is one where if you're trying to do a security access, what should happen if you do it wrong is you're supposed to then get an error message back saying that you ran out of attempts. Well, sometimes it happens, sometimes it doesn't. Uh, conditions not correct is a good one because what it's saying is I can't do the thing that you're asking for but I am capable of doing it if the conditions were correct. So then you've got to figure out what those conditions might be. Again, it lets you start narrowing down the type of functionality you're looking for. There's also a really verbose section of errors like RPM too high, RPM too low. Engine is running. Engine is not running. Uh, throttle pedal too high, too low. Transmission not in neutral. Transmission in gear. And not all of these different error codes are things that all automakers implement. But when you see them, it allows you to know that, well, great, this thing I've almost gotten to the ability to activate this function. All I have to do is change the conditions that the car is in. So again, this is allowing you to scan the functionality. You don't have any knowledge of what's going on. And it's allowing you to figure out what is going on. So, UDS. So, because I can't help myself, I named it CanMap. Because it's based on CanCat and it helps you do end mapping of a car, right? That's the theory anyway. So there's, there's my, there's my car. My own test subject that I tested this on. Uh, to try and figure out what's going on. So, again, uh, when you're taking, doing a pen test, right? If you're doing a pen test, you want to figure out what's on this network. What services are available on this network? You run Nmap with a different range of IP addresses and you come back with, there's a service there that gives you a successful or an error, some error responses. It allows you to know that that IP address is valid and allows you to know what services may or may not be present on there. It can allow you to detect if there's a firewall present. Um, so Nmap is again a blind tool that lets you go through it and figure out what's going on. CanMap is pretty much the same thing. And of course Karen Caribou does similar things as well. But I had the, I, I, I felt like doing it on my own. I don't really like using tools that I've not wrote because I don't actually ever understand how the tools work until I play with them myself with my own hands. I might be the only one who ever uses the tool, but the whole point is it's helped me learn about how, how UDS works. It's written on top of CanCat. So it's an example of how you can use CanCat's existing API to interact with the bus. So use it as a way to learn how CanCat stuff works. Uh, use it as a tool, standalone tool by itself. Um, whatever you, use this as an example or a chance to explore other new tools. As long as people are going out and learning new things, that's my goal. So, first thing the tool has right now, uh, because it's brand new, is it allows you to scan for ECUs. Right here, and it'll start over in a second. So it allows you to, first thing I'm doing is scanning for ECUs. There's a couple different ways you can do this. Any functionality you can send to an EC, any function you can request. So the things I pointed out earlier, redid, diagnostic session control, uh, data transfer, ECU reset, there's all these things that you could send that would allow you to check if an address is valid. Um, in this particular case, the one of the default modes is just reading a DITS. So it tries to read the VIN out of a vehicle. And you can see a bunch of things coming back here. So it's detecting that, that if there's a nonstandard response, um, and it logs it in different ways. There's different, this is just the way that I had figured out how I wanted to do it. I want to, uh, talk a little bit too about how the scanning works. UDS works, uh, UDS is the basis of all the different functionality that like the dealer tools use. When the dealer goes and interacts with an ECU, if they need to reprogram it, they're going to use the UDS protocol to get this to happen. Well, one of the things that's being hap- that's happening on newer vehicles is there's a CAN gateway sitting on the OBD2 port. That's supposed to only let the certain things through that are allowed to go through to the rest of the vehicle. One of the things that by design it has to allow through is the UDS messages that allow the dealer tool to interact with the ECUs. Which means that you, using the UDS will help you find things, even getting through a gateway. It's essentially using a firewall's capabilities to allow you to go through it on its own. You don't have to break through it as long as it lets you through in a nice and friendly manner. So here's the results, the results of my scan are output into a YAML file. I'm not a fan of YAML but it does work well. And the YAML file has the list of like what are the transmit IDs, what are the response IDs and eventually what are the actual values of different DIDS. Now what is the bus speed that I use for this? And then this YAML file can be used in future scans that will allow you to not worry about scanning for the ECUs because you've got them already saved in the file and then you can use those and go on and scan for other things. It's also got the notes there indicating what the actual command you ran was. The idea being that it should help you find out how long did the scan take and uh what actually, how did you actually invoke the command that generated the results you see there. So here again scanning for DIDS, I'm not gonna show you an animated one for that because it's just a ton of output. But I wanna point out a couple things here. Again looking at the ISO TP frame IDs. If you take a look at the bottom one, you'll see you've got the 0, 1, 3 and a bunch of 2s. Again that's very in, that's very classic, it's an easy way to see looking at the raw CAN messages that you're looking at an ISO TP uh block transfer. And then you can actually see the read DID result there. In this case it was uh one of the application identifiers. F182, whatever it is, I don't know. One of the things I also wanna point out about how UDS is useful in this case is by taking a look at the contents that you can get out of the different data identifiers on the different ECUs. Once you have extracted the firmware for the ECU, they can act as good sign posts. Because it allows you to have this particular string, search for that string in the firmware somewhere. And then once you find it, you can start finding the references. And you can uh, you know that the references are going to be related to this particular CAN function out. So it can allow you to go from a known info set of information in the software that will allow you then figure out how you get back there to the CAN stuff. And once you take a look at the CAN functions, you can see what other functionality might be available through that CAN interface. Uh one of the other things that is nice about uh that I like about the tool CANCAT, so it allows you to do a save session file. You've recorded all this information, all these CAN messages have been saved, you've been doing hours of testing. Well, there's a function called save session to file. Uh you can just type it interactively on the IPython shell, it's a normal way. Or what, and what we can do here is if you pass the dash C flag to CAN map, it'll save the session file for you also. It's just a pickle, a Python pickle if you know how those work. Yes they're insecure so don't unpickle other people's pickles that they provide. If that phrase makes, if that sentence makes sense. But it's really useful because it allows you to take your logged output that you see, here's the results I see, here's what's going on, and you can take a look at the raw CAN messages themselves. So if something has gone weird, then it can allow you to core, find out exactly what's going on here. In my limited testing leading up to this, I didn't have time to go through every scenario to figure out what works, but being able to go through and look at the raw messages helps you figure out what's going weird. The last set of functionality I've gotten it is scan for diagnostic sessions. Um, I've got the warning here because when I started doing this, things do start acting weird because it does involve, uh, putting the ECUs into different modes. I set the immobilizer off on my car. It did clear as soon as I turned the car on and off again. Off and on again. Uh, but again, this is one of those things where once you start messing around with different diagnostic sessions and ECU resets, things can get weird. Uh, on the other hand, it can also help you identify which ECU does what on a car. When I was doing this scanning for sessions and I saw, okay, well here's the session ID and then I see my radio start rebooting, I know that that session ID is my radio. Because just looking at the raw message IDs, you don't know which ECU those belong to necessarily. But when you start seeing the actual physical effects on the car, then you can start correlating that to what ECU does what function. Again, here's some results. You can see some of the weird errors I started getting. One of them was like, when I go to a particular session, after I start scanning long enough, then it just, it just kind of stopped responding in a friendly manner. Um, again, I'm not entirely sure why, but looking at the raw messages can help you diagnose what's going on. And again, this is the first version of it. It'll get better. It's still sitting in a pull request up to the main CANCAT. So, uh, it'll get there eventually. Uh, the, oh, that must be a later slide. So, real quick wrap up. UDS helps you to enumerate the vehicles and taxis. Let's you figure out what ECUs are present. It lets you figure out what data is in there. The data can then be used to more easily reverse engineer what's going on in the thing. I do want to point out that UDS itself is not necessarily a vulnerability in and of itself. It's simply a way to discover the functionality that's present on the vehicle. The functionality itself might be the vulnerability, right? If I'm alive, if I can do things to a car that are bad, if I can, uh, put my, if I can unlock a vehicle from an external location, that itself is the vulnerability. Not the fact that I found out I could do it with UDS. Uh, if I can put an ECU into diagnostics mode while the car is running and then, uh, impact the vehicle dynamics, that is the vulnerability. Not the fact that I use a session control to do it. This is again similar to the way different protocols work. Uh, in, in, if you're talking, thinking about regular computers. I could go on forever with these if I had time, which I don't. Um, again, the more tools, the better. So I like Canmap, Kirin, Caribou, Scapey, other options out there. Uh, and lastly, go out there, scan, be curious, play with your own car, uh, and have fun. That's it. I know it was really quick. And if you have any questions, uh, we don't have time right now, unfortunately, but please, uh, I'll stand around afterwards. If you have questions, let me know and I'll answer them or go into more detail if you wish. A couple links here. If you haven't yet read Chris and Charlie's paper, it goes a lot into UDS and security access key, uh, uh, the seed key pairs. That's very valuable to go and look at. It talks about reverse engineering those algorithms out of the dealer tools. The dealer tools are always a valuable resource when you're trying to figure out what the capabilities of a vehicle are. Uh, and again, some links to the other different CAN tools here. That's it. Yes? Uh, yeah, question was if I've messed with the Tesla 3. I've not personally messed with the Tesla 3. Anyway, I'm pretty sure I'm out of time. It is in a poll request up on the CANCAT repo. So if you go up to CANCAT and you look for pull requests, you'll find one of them that's branch labeled CANMAP. So it's working on it. It was a lot of code changes, so it is, uh, it was a lot of code changes, so it's gonna take a little while to review and make, and fix all the stylistic things that I've messed up. Alright, question was about emulators, so for messing around with this. If you play with the SocketCAN tools, you can create a virtual CAN device which will allow you to play back pre-recorded data. Uh, I did, did create a testing CAN interface for CANMAP. Uh, it's kind of limited at the moment though, but it allows you to kind of fake out the high level stuff, but not the low level ones. So, short answer is, kind of. Right, yeah, and there's also tool, we also have a tool in CANCAT now that allows you to go between SocketCAN dumps and, uh, P, or PCAPs and CANCAT sessions files. So you can convert from one to the other to play with them if you wanted to. But, uh, that is functionality I would like to do eventually. But, I'm now a couple minutes past time. Whoever's next is gonna need to get up here, so I do need to shut down. Thank you everybody for being here. And I'll be hanging around afterwards.