Hello DEF CON! Hi! I hope you enjoy your time here, we definitely do. It's actually our first time here at DEF CON and thus we are very proud and excited to present to you our talk Redefining V2G, how to use your vehicle as a game controller. So, why do we need to redefine the acronym V2G? Well, let me tell you a story. Once upon a time, our professor told us we should do some research about V2G. And what he means by that is that we look at vehicle-to-grid communication, the communication between the car and the charge point, and also the back-end and even the power grid for bi-directional charging, for example. Well, that's actually a pretty cool research topic, but do you know what's even cooler? Using your car as a game controller. So, that's why we developed this little project called Vehicle-to-Game. But before we get started with that, a short introduction of ourselves. My name is Tim, I'm a PhD student at Darmstadt University of Applied Sciences in Germany, and I mainly do automotive security, so also a lot of theoretical stuff. I look at protocols and standards and do a formal analysis of these standards to see if they meet certain security goals. Yeah, hello from my side too. I'm Janis, I'm also a PhD student at our small automotive research group called ACSD, Automotive Cyber Security Darmstadt. It's located in Germany. I finished my master's at the end of the last year, and now I'm a PhD student about resilience in the automotive topic, but also for IoT systems. It means what happens if an ECU in a car breaks or is going to be compromised, how you can migrate functionality to another ECU and strengthen the safety inside the car by such a resilient concept. Our research group is also very focused on teaching. We have a lecture called Automotive Security, and therefore we have to motivate students, of course, and that's why we have created this motivating and beginner-friendly talk and our project V2G to get students excited and motivated about the topic of automotive research. Maybe the most important member of our research group is our research car. It's a Volkswagen ID.3. It's an electric vehicle. And since, of course, we are Germans, we have to do research on the Volkswagen. Usually, the initial step of the automotive research, but also other security research, is considering attack vectors. And that's what we have to do also for the automotive context. You can see there are various attack... it's a huge attack surface. First of all, you have long-range attacks, you have short-range attacks, but you have also physical attack possibilities. For the long-range attacks, for example, the cellular communication between the car and the back-end of the OEM, for example, for over-the-air updates. In newly upcoming cars, you have also the V2X communication, cars communicating to each other about their location, about their speed. You have cars communicating with road signs to get a status about allowed speed, for example, of this street section. You have short-range attacks, that's more or less classical cyber security, considering Bluetooth, Wi-Fi connection for your infotainment system between the smartphone, for example, for playing via Apple CarPlay, for example, the music on your car. And the maybe most interesting and car-specific attack vectors are these physical attacks, that's the bus systems inside the car, there are several of them, but we want to focus on two, and we go into them a little bit later in detail, because we need them for our V2G project, for getting all information required for our game controller out of this car. So, here you can see our two main research cars. We are focused on electric vehicles, so on the left side you can see our Volkswagen ID.3, on the right side you can see the Tesla Model 3. We use them for practical research, Tim also introduced them as theoretical research, I'm also more theoretical part, but you cannot do the whole time theoretical research, so you have to do tinkering around with the car, it's also good for the motivation. There's a lot of information you just get when you look at the actual car, because the manufacturers won't tell you, and also for students it's quite cool to do research on the actual cars and projects. So, we have equipped our cars with lots of techniques to get information about them, and we show you in the following how we have done this. That's the back of the Volkswagen ID.3, we've equipped this with lots of measurement techniques, on the right you can see so-called vector boxes, they're from a German company called Vector, that's why we call them vector boxes, they're for capturing different buses inside the car, and we have equipped the car in a way that we can get a holistic view of all relevant buses in this car. On the left side you can also see some interesting parts, more for the electrical engineers, we have equipped the car with so-called LEM sensors, they are current measuring sensors via induction, you can clip them on the high voltage system wires to measure the current. The idea behind this holistic view between physical and messages inside the car is that we can compare those data and get correlations between the actual physical measurements and the recorded, for example, canvas data. As I've already introduced, from a theoretical way, there's also a practical attack surface, of course. On the left side you can see classical key fob attacks using an SDR, maybe all of you have heard about the roll jam attack, you jam the signal of the key fob because it's using a rolling code, and the owner of the car will press a second time, and you have recorded both signals, and you re-send the older one because the car hasn't heard this already, and so you have a newer one for the car, unlocking this in the future without the owner getting any notice about this. In the middle you can see, for automotive and classical attack surfaces also, unsoldering the chips where the firmware is located on, because you have physical access to your car. If you own the car, you can do anything you like with it, more or less. So that's why we have unsoldered the EMMC chip, to get in contact with the firmware. That's the same we've done with the key fob, you can see here there was the memory chip. And maybe another interesting part is that you can directly connect, here you can see such a vector box, to the internal buses of the car. Here you can see one such an ECU, and we have connected this box with the CAN bus of the ECU, controlling messages. But before we go there for a little bit in detail, how these messages look like, first we have to understand what this CAN bus actually is, how can we talk to those cars. For a game controller, we require, as I've already mentioned, information about specific actuators of the car, for example the steering wheel. We later want to transfer the angle of the steering wheel, to our virtual game controller. So we have to get this information out of the car. And this information is transferred via the CAN bus. The topology of such a car looks like follows, it's a very condensed view, it's a very simplified view of our Volkswagen ID.3, where you can see there's a main gateway ECU, and several domains. Each domain consists of several other ECUs, and each of those domains is separated in a way, based on criticality of those functionality and the ECUs. For example, in the middle domain you can see, in the drive domain you can see, there's located the engine ECU, but also the brake ECU, they're all safety relevant, so they're very critical for the safety behavior of the car. On the left side you can see a separated domain, with less criticality for, for example, the light controlling inside the car. The special thing in this topology is, that those domains are separated, based on this gateway ECU. The gateway ECU is responsible for, for shielding the inside of the car against the outside, because, you know, maybe you know this from combustion engine, the outside of the car is connected with so-called OBD2 port. It's for diagnosis, if you bring your car to a garage, they will plug there in. And you want to prevent that via the OBD2 port, everyone can read everything of the car. So that's why such a gateway ECU is introduced into this topology. But this strongly depends on the actual car you want to consider. That's just for the Volkswagen ID.3 and the group of vehicles from Volkswagen. Now we get a little bit into detail about this CAN bus. The CAN bus was developed by Bosch in 1986. It's a dual wire twisted pair cable, and as I said before, it's a bus topology. What does it mean? A bus topology means that the ECUs are connected to the same wire, or wire pair, and all ECUs get the same state of information in the respective time frame. We have a frequency in this CAN bus, and all this information is distributed in this time frame to all ECUs connected to this CAN bus. It's also a multi-master protocol. It means that all ECUs can send and receive on demand, and there's no master required to control them. Now we have the foundations how this CAN bus works. Now we get to gain access to this physical CAN bus inside the car. Maybe the most convenient way is to find just a repair manual or a wiring diagram of the car. They're usually available for garages. For Volkswagen, you can get them online. If you claim you have a garage, then you can buy it. Otherwise, you have to find it out by yourself, but this can become very, very hard. So we recommend having such a wiring diagram. Based on this wiring diagram, you can find a good exposed position of an interesting CAN bus where you can connect to. For example, here you can see the Tesla Model 3, which is in the mid console of the car. There's one of three CAN buses, which you can easily open and connect to ready-to-buy adapter. You can buy those adapters easily on eBay, for example. And then you can gain access to this CAN bus. If you don't want to destroy your car or altering this, there are also less intrusive techniques. These are called contactless CAN readers. They read CAN messages based on induction of the signal. And that's more or less... it looks like a crocodile. That's why some products are called CAN crocodile. You clamp the CAN wires high and low, those dual wires, between the clamp of the contactless CAN reader, and you can read those messages. So, you have gained access to the physical layer, you have read those physical signals of the CAN bus. Now you have to transfer them into software, and therefore you need such... for the Raspberry Pi, for example, a CAN head, where those physical CAN signals are interpreted and transferred to the kernel of the Raspberry Pi. There are also other options available, which can conveniently be used, where you can connect your CAN bus directly via USB to your PC. This also works for Windows, so maybe it's for part of you interesting. So, now we have transferred the message to the software part of our project, and that's where Tim continues. Alright, so very conveniently in the Linux kernel, there's already a CAN driver built in. And if you want to work with that, there's CANutils, which has all the basic tools to use that. Also, if you want to do more advanced stuff for scripting, you can use, for example, PythonCAN as a really good library. That's what we use for our project. There's also CANtools for more advanced command-line tools. If you're into GUIs, there's SavvyCAN, which is a really good open-source GUI tool. And, of course, there are a lot of commercial tools. We talked about all this vector stuff before. But let's stick with the very basics. So you install CANutils, and then there's this CANdump command, which will just print out all of the CAN messages on the bus. It looks somehow like this, but probably a lot faster if you're on a real car. For Tesla, for example, it might be on one bus, I think, like 3,000 messages a second, so it can be quite a lot. One step back, even, if you connect to this, for Linux, the CAN interface is like any other network interface if your adapter is compatible with SocketCAN. The only difference is that you don't have a network manager to directly get your interface up and running, and you also need a bitrate. So you have to tell the computer how fast the bus operates. You can measure that by using an oscilloscope, of course. Luckily for automotive, it's usually 500 kilobits per second, so you can also try that. And just as a disclaimer, there are also more modern standards, like improvements on the CAN standards, for example, CAN FD, and there you will also need to have the data rate, for example. But let's assume standard CAN for now. And then we've already seen the candab command. I just want to walk very quickly through what you can see here. That's one single message picked out. You see the interface in the front, if you have multiple CAN interfaces connected, that's important. Then the CAN ID, and the data length, and the data. The thing is, this CAN ID, if you're used to IP, you're usually used to having a source and a destination address. The CAN ID is actually neither. Think of it more like a publish-subscribe topic. So it will tell you how to define or how to interpret the bits in the data part. Also, it's the priority of the message. So the lower the ID, the higher the priority. And this data, it can be really arbitrarily defined. The information in there is called signals, and it can be like 1-bit, it can be 5-bit, it can be all 8-bytes. So that's up to the manufacturer to define that, and that's why we usually need some reverse engineering to make sense of this information. Okay, so you might want to get started, but maybe you do not want to remove all the plating of your car. It sounds like a lot of work to figure out all the wiring and stuff. So that's actually how we started, but if you don't want to do that, there's also the way the garages do that. So Janice already spoilered it, that you have this OBD2 connector, and for vehicle diagnostics. And this connector is usually very conveniently located somewhere in the driver area of your vehicle in front, and you can just plug in a diagnostic connector there. It's usually an OBD2 dongle, which connects via Bluetooth to a diagnostic device, and will read out data like that. And the protocol to do this is called UDS, Unified Diagnostic Services, and it's basically a request-response protocol. The diagnostic tester will, for example, in our case, we want the steering wheel angle, so it will ask, is you responsible for that? Can you give me the steering wheel angle? And it will respond with the correct value. So that's on top of the CAN protocol. It can also be IP, but usually CAN, or both. And in between, there's actually another protocol, which is called ISOTP, and which allows to basically combine multiple CAN measures. They are limited to 8-byte, to one message in UDS, so you can send longer data. But that comes with the difference that now we also... I told you before that this is not like source and destination address to CAN ID, but for UDS, it's actually the destination address now. So there's also, if you want to read data, there's also a data identifier, which identifies which data it is. So you can have now multiple different interpretations for data with the same CAN ID, and data can be split over multiple CAN frames. Just watch out for that. All right, and with that, I think we should have everything ready to go. Yeah, I think so. We have considered the physical layer, we have considered the transfer to the software, we have considered how we can interpret those CAN messages, so we have all together to create our game. And as a small in-between motivation, that's the actual result. Here you can see Tim sitting in our Volkswagen ID.3. In front, we have placed a big monitor, playing Need for Speed Most Wanted from 2008, with the actual car. Thank you. Here you can see a little bit more of our V2G experience. On the left side, you can see our setup, a laptop where the game is actually running. In front of the car, we have placed a huge monitor for a very immersive experience for the driver, but also for all other people inside the car. On the right side, you can see me playing, again, Need for Speed Most Wanted. And you can see I'm very focused on this game. So, as I said, it's very immersive, and it's a very cool experience sitting in such an equipped car. But how can we now connect the laptop, the game, with the car? You can see on the right, the topology again. Therefore, we have several possibilities to connect the car. First, we can use wires. We can use the USB-based P-CAN Pro, for example, connecting, as one possibility, to the internal CAN bus. Therefore, we have to figure out which CAN bus relevant messages are located on. We have to find the relevant messages, figuring out the relevant signals of the CAN messages, and there's an overwhelming number of CAN messages on this internal bus. As Tim said, several thousands per second. So it's quite difficult to figure this stuff out. Also, the whole breakout box stuff we've shown to you is required to get access to those internal buses, so the more convenient solution is connecting directly to the OBD2 port and use the diagnostic services for pulling those informations and getting conveniently just the requested information. But since we live in 2024, wires are a little bit outdated. We have created a Raspberry Pi head, which allows us to emulate an Xbox 360 controller with a Raspberry Pi Zero, connecting directly to the OBD2 port of the car. And this Raspberry Pi connects via Bluetooth to the laptop, emulates this controller, and the laptop can stand outside the car and runs the game. For this setup, we use UDS. Now, a little bit into detail of the actual hardware we use for it. The lower layer of this, you can see it's a classical Raspberry Pi Zero with no modifications. Above that, we have located the Raspberry Pi CAN head, which is responsible for converting those physical CAN signals to a software-readable CAN message. And the top layer, we have created a self-designed PCB for connecting to this OBD2 port of the car. From this OBD2 port, we only use four connections. The 12V, the ground, the CAN high and CAN low connection. The CAN high and CAN low connection is directly transferred via this PCB to the lower CAN head, which converts this message. But the more interesting part of this PCB is the 12V, 5V DC-DC conversion. So we can very conveniently connect this dongle to our car without the requirement for a power bank and power supply of the Raspberry Pi. As a short disclaimer, we are no electrical engineers, so if you have any recommendation about this, feel free to contact us. We are quite happy about recommendations. This circuit for 12V, 5V DC-DC conversion is just taken out of the datasheet of the used IC. Feel free to come offstage to us and discuss it with me. We have also added the possibility to add status LEDs, but that's to be done. They are connected to the GPIO pins of the Raspberry Pi, so if you want to extend the project, you can use them for your own purpose. So, we have the hardware. Now, the software. I'm just going very briefly over the software architecture of our tool. So, if you want to use it in the Bluetooth mode, as a Bluetooth controller, there's an install script for that. You just run it on your pre-imaged Raspberry Pi and it will set up everything which is required. If you don't want to do it, then just run it on your own laptop. There's a run script for Linux. For Windows, you just directly run the Python protocol. The run script actually will also set up some interfaces and stuff, but you can do this beforehand if you do not want to execute it with pseudo-privileges, because that's required for interface management. Then, for emulating the game controller, for the Bluetooth version, we used the HitPi project to emulate a Bluetooth device, and if you run it on your own laptop, we used the VGamePad library, which is also cross-platform, so it also runs on Windows. You can also use that. For the Bluetooth one, it doesn't really work on Windows so far, so if you have any recommendations on that, and are an expert on Hit devices, also pull requests are welcome. So, now to our actual domain components. We have a car detector. If you have multiple vehicles, as we have the ID3 and the Tesla, you can give it basically a list of CAN IDs, and it will figure out which car it is, and then use the according configuration. The heart of our project is the car connector, which will convert all the CAN signals in the messages to triggers for the Xbox emulation. And then there is the vehicle configuration, which has all the vehicle-specific stuff in there. And I'll just have a more detailed look on that. You can configure a name for your vehicle to reference it. Then you have to specify which operation mode, if you want to use the internal mode or the UDS mode. Sometimes, if you have an older car, where there is no gateway in between the internal buses and the OBD2 connector, you can also use the internal mode for that. Or if you install the OBD2 adapter for the Tesla. Otherwise, for the UDS mode, you will also have what you can see on the right side, and you will have to send those polling messages I talked about earlier. Basically, you can just paste them in here, and it will periodically send them to get the data. There is also an update interval. Usually, we have a higher interval for the steering angle and brakes. And for the buttons, we use a lower update interval, because there is a limit how fast the ECUs will respond. Also, we have some... You can see the auto-detect IDs I mentioned before. And also, we have some high-level configuration stuff. For example, we limit the steering, because if you play a racing game, and you have to two times turn the wheel for the maximum steering, it's just too slow, right? And also, there is the steering dead zone, which basically, you have a bit more space to set your steering wheel to zero. Because otherwise, if it's like 0.01 degrees, and it will always go left in the menus, or you just cannot drive straight, it's actually pretty hard to get your steering wheel to exactly zero degrees. So, that's pretty handy. I'll go a bit into detail on the signal configuration later. But for now, let's look at how it works out. Yeah, we are ready to play. Unfortunately, we are not allowed to bring our car with us, so we have brought some videos of the gaming experience. You can see me here driving with first-person view, playing SuperTux Kart. You can see I control the racing car with the steering wheel, left and right. And now I've paused, because you can see I put my foot on the brake. Let's see what happens next. As expected, the racing car slows down, and I was overtaken. Now, you can see I've started the indicator. We've mapped the indicator function for left to throwing items in this game. You can do this for your own purpose, for your own game, but we've mapped it like this. So you can see here, I'm throwing this exploding muffin to the racing car in front of me, so it will explode. Unfortunately, because PowerPoint is a little bit annoying, sometimes, usually you should see that I've turned on the full beam flash, full beam 2, so we've mapped the full beam trigger to the nitro activation in the game. So it's very cool, driving in the night, igniting, and the car speeds up. See what happens? You can see the nitrogen. Now, you can see it's a little bit difficult to drive, especially with just one hand, but it is possible to race, it is possible to overtake enemies in this game, and it is also possible for you to get the right items, in this example, an acceleration one, to win racing games. And it's actually a lot of fun. You see, we're very excited about this. So, maybe, over to Tim. So, the question all of you probably have in your mind, how do you support your own car to use this? Well, before you get started on that, just make sure you keep in mind the safety. So, make sure you cannot accidentally drive into a wall. Why? Because if you're in your garage, and you're really into your game, and by accident you switch to drive mode, you don't want to do that. You're probably out on the gas, right? So, make sure you cannot do that. Of course, there's less of a problem on combustion engine vehicles, where you do not have to turn on the engine, but then make sure not to drain your 12-volt battery, like playing all night. It's probably not good if you do not have a charger connected. So, what do you need? I think we talked about everything of that. You can also use just an OBD2 open-ended cable, if you do not want to solder your own OBD2 head. So, that all should be less than 50 bucks, I think, to get started. If you use the diagnostic mode, and you have to get a diagnostic tester to reverse-engineer that, that really depends on the car, probably. There are sometimes some very cheap ones, and if you have to get a garage-level one, it's pretty expensive. So, yeah, probably too much. Okay, and then you can start reverse-engineering. So, here you can see the UDS tester setup, basically. The actuator, we are looking at a steering wheel angle, as before. Here we have a tablet with the diagnostic tool, which reads out the steering angle. And here we have my laptop, which runs CanSniffer, which is a very convenient tool to show you the differences in car messages. And what we'll do next is turn the steering wheel to see where the information is. And actually, I turn it one time completely to the left, and one time to the right to get the min and maximum value, which is possible for the signal, but you have seen where it is located. And, yeah, sometimes you're lucky, and you will find already complete CAN database files, those called DBC files, online for your car. Then you can also try to get this information out of there and use that. But otherwise, reverse-engineering of this data is quite good because it's like you can easily turn the steering wheel to see where the data is, right? It's just if there are 3,000 messages, it might take you some time to find the right one. Then for configuring it, you basically add all this information, the CAN ID, the position in the signal, and the length of the data. And then that's why we use Python for the configuration. You can just use a function to specify the signal mapping. In this case, we have the first byte turning to the left, the second to the right, and then we specify the min and maximum value and map this to a range of minus 1.0 to 1.0. All right, that's what you need to configure for your own car. In conclusion of this talk, if anybody asks you, especially our professor, now you definitely know that V2G stands for Vehicle-to-Game. Car hacking can be really fun. And I think our project is a great entry point if you want to get into that or just want to be able to say that you have a very expensive game controller at home. Always be careful if you do that stuff. Do not drive into walls. We actually use it, as Janis said before, as a demonstrator to motivate students to show it to visitors. It's always a good icebreaker to get started about talking about automotive security. And so the only question that remains is, what are you going to use it for? Feel free to contact us. Do any contributions to our project. Write us an email. Here you can see the QR code. The Git repository is public, so you can make an issue or do a pull request. Feel free. We're happy if we can keep in contact with you. And I think we have eight minutes left for questions, if there are any. Otherwise, we can also take further questions offstage. Have you thought about playing with heads-up display? You know, you can get these things now. You just put it on the dash and it'll actually just reflect your iPad or anything up onto the windscreen. And it looks like a heads-up display kind of a thing. Have you thought about that? Just for a way to project onto the screen. Where's the question? Oh yeah, so the question was if we have thought about projecting the game, basically, onto the screen of the car. So we've thought about that. We haven't done it. We also thought about it because the ID3 actually has a heads-up display. Yeah, so I think there are adapters to the protocol they use there. And then you can use it as an HDMI interface, basically, if you plug in there. So we have some plans, maybe, for the future. But we actually haven't done that or tested it. Just putting a projector in the back of the car is probably quite good. It's not a security-related problem. It's just throwing money on it via such a converter. And then you can easily connect your laptop with those internal screens of the car. That's expensive but easily doable. Yeah, but come up with your own setup. I think there's a lot of possibility, right? Yeah. The question was how if we build up a flight simulator out of this. If you have a real airplane, maybe you can transfer this. I don't know. Maybe you can use also your car for this. It should be possible. It's just an Xbox controller. You can map it to anything you want. Okay, any further questions? No? No. Alright. Okay, thank you. Thanks for listening and have a nice day. Enjoy the last day of DEF CON.