Hello. First of all, say to everyone good afternoon and thank you for being here. I'm quite impressed for all the people that is here on the last day, the last talk before the last one. Keep touching the wall. And I hope you guys are still here after the second slide. Hopefully. So, my name is Rafa, and I work as a security consultant and security researcher for MWR Info Security in the UK. That is my email address, in case you want to send me an email after the talk. I doubt it. This is our lab's website, where the guys and me included, you know, put our research. But enough of me. Let's see what this talk is going to cover. I'm going to talk about security. We're going to be seeing different types of USB attacks, and we're going to understand the impact of these if they were to be exploited. We are going to be looking at different approaches for security assessing USB drivers and how to identify bugs. We also give details how we can actually implement these bugs in a USB hardware device itself. So, the details. The talk will break down in the following parts. First, we explain different types of USB attacks, and we'll see how USB has impacted our society. We'll look at different phasing approaches for phasing USB device drivers. We'll see how these crashes can actually be debugged and analyzed, and we'll see how can we actually get that bug and that exploit implemented in a USB hardware device. We have also a few demos here and there to actually supplement all this information. So, once upon a time, the serial port used to be our best friend for connecting hardware devices to our computer. It also was our worst enemy when it came to finding drivers for unsupported devices. devices. And we all have felt that pain. But the era of serial port is unfortunately far gone. And now we have the USB, the plug and play technology, and the mini USB device pen drives. And it's actually a bit of a pain in the ass to actually find a computer with inbuilt serial port. And for those that do hardware debugging, it's a bit frustrating. There's some danger with USB. And we have seen that companies has, well, lately has been some concerns about USB port itself. And we have seen this mainly at corporate level. We don't have to actually go very far to actually remember the famous configure, which actually exploited the auto run functionality and spread a swarm by using the USB devices passed from hand to hand to exploit this vulnerability. And we have also found there is, as in any software, a USB driver has also got vulnerabilities, which can be triggered by the power of the internet. and exploited from development mistakes. But we don't have to get too technical when it comes to exploiting USB attacks. An individual can come to your company or to your organization pretending to be the cleaner after working hours and actually plug a USB keyboard and after a period of time actually obtain a lot of information. And we all have seen in the news when a businessman or a politician has actually lost a pen drive containing a lot of sensitive information and actually compromising this data. But we have seen some concerns. Organizations have started to actually think about that USB is not actually that secure. Major operating systems have started to disable their organizations. They have run functionality. At corporate level, they are starting to use USB encrypted pen drives in case these get lost. And even we are seeing security policies that now a computer's standard build have a policy where they disable the USB port itself. And there is even software out there that actually allows you to set different USB devices that can be used in a computer depending on what they see or not. number. But there is still dangers there because at the end of the day it's up to the user to plug that USB device into the computer. And that involves security education and security awareness. That is something very difficult to combat with. But how did I get involved in this research? How did I start looking into USB devices? Well, it all came through one of our clients. They have this piece of hardware that does stuff. And they wanted this to be tested before the new release was actually out. So we tested it. The project took time in a period of two weeks. And we had to test the project involved a little bit of everything. From protocol fuzzing, reverse engineering, and further general functionality, hagging. It was a really great piece of work. Basically, hac the hardware in a period of two weeks as you could. And, of course, included the new feature that was implemented in this new release, which was the USB port. So we started looking at the USB port. We took different approaches. Black box white box testing which was a little bit boring as we all know. And black box testing, which was the fun part, because you don't actually see what you're sending. You see what you're sending, but you don't see exactly what's going on. And we faced the challenge of phasing USB device drivers. And, of course, the build base testing, which really helped when it came to doing this project. So, before we go any further, let's have a little bit of technical background about the USB communication between the host device and the host computer and the USB device. The numeration is the phase of communication between the host PC and the USB device. And it's where the PC actually learns information about the data. The actual device itself, about its identity. And the descriptors are data structures that the USB device sends to the host in the numeration phase and provide information about the configuration of the device, the manufacturer type and its properties. As I say, the numeration is the device identification and it happens as soon as you plug the USB device in your computer. It's automatic. In some operating systems, it's visible. And to us, such as Windows, where a pop-up Windows, well, where Windows appear telling you that a new USB device has been identified. And it's in this phase where descriptors are sent containing general information about the configuration of the device. We have different types of descriptors, and here we have some important ones. We have the device descriptor, which describes general information about the device and provides information such as the vendor ID, the product ID, and the serial number. It's in the product ID and the vendor ID that we are going to be particularly interested, because these are used to identify which device driver is going to be used. Then we have the configuration descriptor, which, as its name dictates, provides configuration information about the device, mainly relating to power management. Then we have the interface descriptor, which provides... information about an interface within a configuration. We have the endpoint descriptor, that provides information about the bandwidth that will be used in the USB port, USB bus, and we have the string descriptor, which is additional information that the device, the USB device provides to the host in the enumeration process. And this is human readable data, and provides information such as the manufacturer name, the product name, and the serial number. And here we can see how a device descriptor looks like. And we can see the vendor ID and the product ID, being those that are going to be used to identify the USB device, the driver that will be used in the communication. And here we have a string descriptor. We have the... as we can see, it's human readable data, and we have the manufacturer name and the product name. So... Everyone touching the wall? Yeah? So we start looking as... we were at the same time we were reviewing source, Linux USB drivers' source code, we were discussing how we were going to be performing USB driver fastening. We came with three different approaches, which were the approaches that fitted more to us in the timeframe that we had and in the project that we were performing. And I want to stop at this moment and say that I'm not selling here a fuzzing framework tool or a fuzzing technique. This is what worked for us and I hope it gives you some ideas. We took three different approaches, a virtualized approach using QEMU, a network approach using USB over IP, and a hardware approach, consisting actually in implementing hardware that will send my fork data to the target system. So QEMU. QEMU is an open source machine emulator, a virtualizer, and it's quite cool because it allows us to emulate. It emulates USB devices from the host computer to the guest operating system, as if this was actually physically plugged into the device, into the target system. The idea of this fuzzing approach was to actually have an environment with our host system and a virtual machine with the same... I forgot to say... Actually, we perform a source code review because the operating system that was being used in the hardware that we were testing was Linux. As we all know, secure operating system. So what we did in the virtual machine, we installed Linux, the exact version that was used in the hardware device that we were testing, with the idea of emulating multiple USB devices from the host computer. So what we did in the virtual machine, we installed Linux, the exact version that we to the guest virtual machine, sending my fork data to the guest virtual machine. For this, what we did was to recompile QEMU with multiple fuzzing cases, being each fuzzing case a USB device to be emulated into the virtual machine. The advantages of this approach is that it gave us a very quick start-up to start fuzzing USB device drivers. It required... It required... Very little resources when it came to software and hardware. First of all, because QEMU is open source, you have a virtual machine. And it just required a little bit of programming here and there to actually make this work. The main disadvantages is that we were... We lacked from a proper fuzzing engine. What I mean with a fuzzing engine is actually something that is going to be creating fuzzing cases for our fuzzing. And we were relying in text files containing malformed data. And every time that we wanted to create a bunch of fuzzing cases, we had to recompile QEMU with all our fuzzing cases. So we took a second approach. USB over IP. With the... With the... With the aim of overcoming some of the problems that we found in the previous approach. The idea of this is actually to get USB packets and sending over the network to the target system. For that, we look at... It's a Linux module called USB IP, which actually allows you to legitimate shared USB devices over the network. So we... We look at this... This module. And we got a couple of Wireshark captures. We see what was... What was being sent. As it is also open source. Open source. We look at the source code to actually create a little tool that will allow us to send... To replicate USB IP packets. So our environment looks something like this. We have the attacker system with this tool that we created to replicate the USB IP packets. We implement this. We implemented an already existing network fuzzing engine, which will be creating our fuzzing cases. The attacker would send the USB packets over IP. At the target system, we will have the USB over IP... USB IP module installed that will be in charge of taking the USB packet that we are sending with the malformed data, removing the IP header from the packet, and sending the USB packet directly to the... To the drivers. The advantages of the... The advantages of this is that we have a fuzzing engine. We use an already network system fuzzing engine, and it could create the different fuzzing cases. The disadvantages is that we were relying on a piece of software. And in this case, being USB IP, meaning that any problem in this software would actually affect the reliability of our software. Of our fuzzer. Sorry. The third approach, the hardware fuzzer. And the idea of this approach was actually create a hardware device that could actually be plugged directly into the target system and send malformed data. This... This... approach because it's quite a long-term project, I would say, and it requires more than two weeks that we had for the testing. But the ideas that we thought about were two approaches. The first approach would be to actually have this USB hardware that would create the fasting cases impersonating a USB, a specific USB device or multiple USB devices being plugged into the target system and actually send the malformed data. The second approach that we thought with the hardware fasting, it would be a man-in-the-middle approach where we would actually have the hardware device performing a man-in-the-middle. So we would be plugging a USB device to this hardware. This hardware would take the USB packet in the flight, modify, put the malformed data, and send that directly to the hardware. As I say, it's a longer-term project, and I know there is already people out there trying or performing this type of hardware faster. So we were reviewing the driver source code, and we were checking if the driver source code was working. We left the faster running. Every now and then, as you know, when you perform any fasting, every now and then you go and check the fast, if it has crashed, if it has identified something. At the same time, we were also performing some USB source code review. Just suddenly, while we were reviewing one of the drivers, USB driver source code, we found a development mistake, a vulnerability in one of the Linux USB device drivers that we were looking at. Oh, hold on. It's a pretty picture. You guys keep touching the wall, yeah? You guys keep touching the wall, yeah? It's a pretty picture. Hmm. Three seconds. Three seconds. And we found the bug. Okay. We found a bug in one of the Linux USB device drivers. The bad news. For some political issues, I can't actually disclose as much as I would like. In this slide, I would have had actually the vulnerability that I found, actually the device itself. And I cannot put the picture. So I say I'm going to put a pretty picture. All these political issues happened not very long ago. Actually a couple of days ago. So I have tried and I have, I would like to say here today that I'm hand over. But I'm not. Because I've been working on this to actually show you as much as I can. And so I had to modify a series of things to actually show you, you know, what is really going on without actually, you know what I mean. So the vulnerable device, as I did this in Vegas, is Vegas Girl. I don't know why. And it's a buffer overflow vulnerability that is happening in Tom, Dick and Harry function. I know why it's that name. I'm not going to say. Tom, Dick and Harry function, a function is in charge or is responsible for handling the USB string descriptor. And if we go back to the technical background slides, the string descriptor is that data structure that sends human readable data. The manufacturer name. We saw that before. The manufacturer name. The product name. And the serial name. And it's actually data that we control. Because it's sent from the USB device to the host computer. Which means that we can actually cause this, we can actually trigger this buffer overflow. So USB string function is actually, well it's not similar, but we can think of as a main copy. Or a string copy. Because we are actually copying from A to B and into a buffer. And the buffer that we are overflowing is used by an element of one of the USB device structure. So what is actually happening, we are just copying too much data in that buffer and allowing us to actually overwrite other elements of the data structure. And we'll see later what actually can happen with this. What we are going to do to demonstrate the vulnerability, we are going to do a kernel crash demo. So for the kernel crash demo, the QEMU that we had before, what we are going to have is QEMU running on a virtual machine. With Linux. And with the vulnerable USB device. Okay. With the driver. And what we are going to be doing is emulating our malicious Vegas, malicious Vegas kernel. That sounds a bit, malicious Vegas kernel device. So we start QEMU. It's started. And we can see here the vendor ID and the product ID being those where it's actually going to identify the device driver that's going to be used. Of course it's not 0000. And we are going to be looking at the data, in this case A, that is going to be overflowing the buffer for the element of the structure. So, we go to QEMU. And we go to QEMU. And we are going to emulate the USB device. And we get the kernel crash without actually showing the IP because it will be showing too much. So for crash analysis, there are many tools out there for kernel ‑‑ there are many tools out there. And we are analyzing kernel crash. A majority of them based in GDB. I'm quite a big fan of what did really work for me in this project was KGDB. Because it actually allows you to set breakpoints in the kernel in live execution. So the environment I have set up is KGDB in the debugger system, the target system running the Linux with the vulnerable USB device. The device driver connected with a serial connection. And the malicious USB device plugged into the target system. The target system running the Linux driver that would be debugged. So what I did, I implemented this exploit in a hardware device. And I used a PIC 18 family microcontroller. Which is relatively easy to program. And you got a lot of guides out there to actually do this. And I performed the malicious ‑‑ I implemented the malicious device. I flashed in the microcontroller with the share code in order to exploit the device driver. And the device driver, my little baby, looks something like this. Which I will show here. Which is a PIC 18, F14, K550. So let's do a little bit of crash ‑‑ demo of the crash analysis and the exploit demo that I implemented. With this device. With the idea of what we're going to be seeing is we're going to be seeing the environment where I flashed the ‑‑ where I programmed it. So we're going to be using a malicious device, we'll be flashing the microcontroller with our share code. And then we'll be plugging this in the target system and actually going through to actually see what is going on with this exploit. Oh. Ta-da. Ta-da. Ta-da. Ta-da. Ta-da. Ta-da. Ta-da. Ta-da. Very good. Very good. Very good. So this is my environment for ‑‑ for programming the USB device using MP Labs. It's just really quite cool software. And I'm not very good doing demos. But that is going to be a set of A's that will be the code that we're going to be executing in this demo. And these here are the different elements of the data structure that we are going to be overwriting. There is a static address and a pop return. I will explain. I'm not going to get into details now about this. But we'll explain this a little bit later. So, we compile our source code, hopefully. It would be good to have an error in a demo. And we're going to be flashing our microcontroller. The main reason for showing this in a demo is that this environment involves three laptops and the microcontroller itself. Plugging this around, it could be a little bit of trouble. I have problems with only one laptop. Imagine with three. So we flash the microcontroller. Okay. Okay. So we flash the microcontroller. And what we do, this is going to be our debugger system, which is actually plugged with a serial port to the target system with the device actually running. What we are doing is starting GDB to connect to the remote system via serial port. We connect to the target system. And we send a break point. And in Tom, Dick, and Harry function, that if we remember is the function where the numeration process takes place and the string descriptor is actually passed from the device to the host computer. So we continue. We hit a function. And we set a break point in USB string, which is going to be doing the copying into the buffer. We continue. And there is our buffer. And we are going to see the status of our buffer at that stage. And as we can see at the moment, the buffer is empty. So we continue. We hit the USB string function again. And we look at the status of our buffer. And now we see that our buffer is legitimately filled with our set of A's. Okay. We continue, and this is where we overflow actually the buffer, and we set, we actually overwrite the elements of the data structure, being the static address and the pop return. Now the idea of the static address and the pop return is to actually get the pop return just exactly after the execution of the stack, and we'll see that later. So. So. We have set a break point where we are going to be writing the pop return and we see that we have control of ECX and EVX. ECX being the pop return and EVX being a static address. And we see what this static address actually do. We set up a break point in 8.53 and we look at the status of the instruction at the address. So what we want to do is to actually with this move from ECX to EVX plus 3C, what we'll do is we'll get the pop return into EVX plus C which will be the next instruction to be executed. Which will be here. So we have it, it is what we want to write our pop return. So we step in and we look at the status. So we've done already the move of data and we have our pop Okay. Sorry. So we step in and we get into pop EAX. Pop EAX is going to be popping EAX and bringing execution to the next instruction, which is going to be a pointer with our shellcode close to where our shellcode is. And we return and we'll be executing the address. And we get a segmentation fault. If we do backtrace, we can see the execution path. And then we have the demo. So we have the demo. Getting closer to the end. The recommendations. Disable not required USB drivers when you can. Actually try to assess the USB device driver that you need and actually just use the ones that you need. In that way you actually will close down a little bit the attack vectors. And security test the USB drivers when possible. And if you have access to the source code, do a source code review. Or if not, you can also do black box testing. And also in organization or company, always assess the use of USB risk. Implement security policies when required. Yeah. Assess the risk. A little bit of reference here. More reference. More reference here. And questions. Any questions? Thank you.