1 00:00:00,000 --> 00:00:04,960 Hello. First of all, say to everyone good afternoon and thank you for being here. 2 00:00:05,340 --> 00:00:13,360 I'm quite impressed for all the people that is here on the last day, the last talk before the last one. 3 00:00:15,520 --> 00:00:16,600 Keep touching the wall. 4 00:00:19,260 --> 00:00:23,940 And I hope you guys are still here after the second slide. Hopefully. 5 00:00:27,100 --> 00:00:33,840 So, my name is Rafa, and I work as a security consultant and security researcher for MWR Info Security in the UK. 6 00:00:35,620 --> 00:00:40,220 That is my email address, in case you want to send me an email after the talk. I doubt it. 7 00:00:41,880 --> 00:00:47,960 This is our lab's website, where the guys and me included, you know, put our research. 8 00:00:49,180 --> 00:00:52,720 But enough of me. Let's see what this talk is going to cover. 9 00:00:53,420 --> 00:00:53,920 I'm going to talk about security. 10 00:00:53,940 --> 00:01:00,600 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. 11 00:01:02,040 --> 00:01:13,120 We are going to be looking at different approaches for security assessing USB drivers and how to identify bugs. 12 00:01:13,620 --> 00:01:20,160 We also give details how we can actually implement these bugs in a USB hardware device itself. 13 00:01:22,680 --> 00:01:23,920 So, the details. 14 00:01:23,940 --> 00:01:25,720 The talk will break down in the following parts. 15 00:01:26,740 --> 00:01:33,420 First, we explain different types of USB attacks, and we'll see how USB has impacted our society. 16 00:01:34,940 --> 00:01:40,380 We'll look at different phasing approaches for phasing USB device drivers. 17 00:01:41,780 --> 00:01:53,920 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. 18 00:01:53,940 --> 00:02:01,560 We have also a few demos here and there to actually supplement all this information. 19 00:02:04,740 --> 00:02:14,140 So, once upon a time, the serial port used to be our best friend for connecting hardware devices to our computer. 20 00:02:14,840 --> 00:02:22,460 It also was our worst enemy when it came to finding drivers for unsupported devices. 21 00:02:22,460 --> 00:02:29,520 devices. And we all have felt that pain. But the era of serial port is unfortunately far 22 00:02:29,520 --> 00:02:36,520 gone. And now we have the USB, the plug and play technology, and the mini USB device pen 23 00:02:36,520 --> 00:02:43,000 drives. And it's actually a bit of a pain in the ass to actually find a computer with 24 00:02:43,000 --> 00:02:47,560 inbuilt serial port. And for those that do hardware debugging, it's a bit frustrating. 25 00:02:56,080 --> 00:03:05,700 There's some danger with USB. And we have seen that companies has, well, lately has 26 00:03:05,700 --> 00:03:12,320 been some concerns about USB port itself. And we have seen this mainly at corporate 27 00:03:12,320 --> 00:03:12,780 level. 28 00:03:15,440 --> 00:03:17,300 We don't have to actually 29 00:03:17,300 --> 00:03:25,320 go very far to actually remember the famous configure, which actually exploited the auto 30 00:03:25,320 --> 00:03:34,760 run functionality and spread a swarm by using the USB devices passed from hand to hand to 31 00:03:34,760 --> 00:03:36,040 exploit this vulnerability. 32 00:03:36,660 --> 00:03:44,740 And we have also found there is, as in any software, a USB driver has also got vulnerabilities, 33 00:03:45,160 --> 00:03:47,100 which can be triggered by 34 00:03:47,100 --> 00:03:47,280 the power of the internet. 35 00:03:47,280 --> 00:03:53,000 and exploited from development mistakes. But we don't have to get too technical when it 36 00:03:53,000 --> 00:04:01,060 comes to exploiting USB attacks. An individual can come to your company or to your organization 37 00:04:01,980 --> 00:04:07,800 pretending to be the cleaner after working hours and actually plug a USB keyboard and 38 00:04:07,800 --> 00:04:16,160 after a period of time actually obtain a lot of information. And we all have seen in the 39 00:04:16,160 --> 00:04:24,980 news when a businessman or a politician has actually lost a pen drive containing a lot 40 00:04:24,980 --> 00:04:30,240 of sensitive information and actually compromising this data. 41 00:04:32,580 --> 00:04:39,780 But we have seen some concerns. Organizations have started to actually think about that 42 00:04:39,780 --> 00:04:45,920 USB is not actually that secure. Major operating systems have started to disable their 43 00:04:45,920 --> 00:04:46,140 organizations. 44 00:04:46,160 --> 00:04:53,000 They have run functionality. At corporate level, they are starting to use USB encrypted 45 00:04:53,000 --> 00:04:59,320 pen drives in case these get lost. And even we are seeing security policies that now a 46 00:05:00,040 --> 00:05:08,220 computer's standard build have a policy where they disable the USB port itself. And there 47 00:05:08,220 --> 00:05:13,780 is even software out there that actually allows you to set different USB devices that can 48 00:05:13,780 --> 00:05:16,140 be used in a computer depending on what they see or not. 49 00:05:16,140 --> 00:05:21,480 number. But there is still dangers there because at the end of the day it's up to the user 50 00:05:21,480 --> 00:05:29,120 to plug that USB device into the computer. And that involves security education and security 51 00:05:29,120 --> 00:05:32,260 awareness. That is something very difficult to combat with. 52 00:05:34,470 --> 00:05:40,920 But how did I get involved in this research? How did I start looking into USB devices? 53 00:05:40,920 --> 00:05:50,760 Well, it all came through one of our clients. They have this piece of hardware that does 54 00:05:50,760 --> 00:06:00,180 stuff. And they wanted this to be tested before the new release was actually out. So we tested 55 00:06:00,180 --> 00:06:05,900 it. The project took time in a period of two weeks. And we had to test the project involved 56 00:06:05,900 --> 00:06:10,900 a little bit of everything. From protocol fuzzing, reverse engineering, and further 57 00:06:10,900 --> 00:06:15,180 general functionality, hagging. It was a really great piece of work. Basically, hac 58 00:06:15,180 --> 00:06:22,100 the hardware in a period of two weeks as you could. And, of course, included the new feature 59 00:06:22,100 --> 00:06:25,460 that was implemented in this new release, which was the USB port. 60 00:06:27,700 --> 00:06:36,260 So we started looking at the USB port. We took different approaches. Black box white 61 00:06:36,260 --> 00:06:38,060 box testing which was a little bit boring 62 00:06:40,900 --> 00:06:46,380 as we all know. And black box testing, which was the fun part, because you don't actually 63 00:06:46,880 --> 00:06:51,980 see what you're sending. You see what you're sending, but you don't see exactly what's 64 00:06:51,980 --> 00:07:00,180 going on. And we faced the challenge of phasing USB device drivers. And, of course, the build 65 00:07:00,180 --> 00:07:04,220 base testing, which really helped when it came to doing this project. 66 00:07:06,980 --> 00:07:12,460 So, before we go any further, let's have a little bit of technical background about 67 00:07:12,460 --> 00:07:19,820 the USB communication between the host device and the host computer and the USB device. 68 00:07:21,140 --> 00:07:28,360 The numeration is the phase of communication between the host PC and the USB device. And 69 00:07:28,360 --> 00:07:34,200 it's where the PC actually learns information about the data. 70 00:07:34,220 --> 00:07:40,260 The actual device itself, about its identity. And the descriptors are data structures that 71 00:07:40,260 --> 00:07:46,040 the USB device sends to the host in the numeration phase and provide information about the configuration 72 00:07:46,040 --> 00:07:50,300 of the device, the manufacturer type and its properties. 73 00:07:53,560 --> 00:07:58,960 As I say, the numeration is the device identification and it happens as soon as you plug the USB 74 00:07:58,960 --> 00:08:04,200 device in your computer. It's automatic. In some operating systems, it's visible. And 75 00:08:04,200 --> 00:08:11,260 to us, such as Windows, where a pop-up Windows, well, where Windows appear telling you that 76 00:08:11,260 --> 00:08:16,380 a new USB device has been identified. And it's in this phase where descriptors are sent 77 00:08:16,380 --> 00:08:19,920 containing general information about the configuration of the device. 78 00:08:21,480 --> 00:08:25,460 We have different types of descriptors, and here we have some important ones. We have 79 00:08:25,460 --> 00:08:31,120 the device descriptor, which describes general information about the device and provides 80 00:08:31,120 --> 00:08:38,460 information such as the vendor ID, the product ID, and the serial number. It's in the product 81 00:08:38,460 --> 00:08:42,060 ID and the vendor ID that we are going to be particularly interested, because these 82 00:08:42,060 --> 00:08:45,740 are used to identify which device driver is going to be used. 83 00:08:47,060 --> 00:08:52,640 Then we have the configuration descriptor, which, as its name dictates, provides configuration 84 00:08:52,640 --> 00:08:57,920 information about the device, mainly relating to power management. 85 00:08:58,640 --> 00:09:01,100 Then we have the interface descriptor, which provides... 86 00:09:02,300 --> 00:09:07,980 information about an interface within a configuration. We have the endpoint descriptor, that provides 87 00:09:07,980 --> 00:09:14,140 information about the bandwidth that will be used in the USB port, USB bus, and we have 88 00:09:14,140 --> 00:09:19,740 the string descriptor, which is additional information that the device, the USB device 89 00:09:19,740 --> 00:09:26,740 provides to the host in the enumeration process. And this is human readable data, and provides 90 00:09:26,740 --> 00:09:30,980 information such as the manufacturer name, the product name, and the serial number. 91 00:09:33,640 --> 00:09:39,120 And here we can see how a device descriptor looks like. And we can see the vendor ID 92 00:09:39,120 --> 00:09:44,620 and the product ID, being those that are going to be used to identify the USB device, 93 00:09:45,180 --> 00:09:54,180 the driver that will be used in the communication. And here we have a string descriptor. We have 94 00:09:54,180 --> 00:09:58,780 the... as we can see, it's human readable data, and we have the manufacturer name and 95 00:09:58,780 --> 00:09:59,320 the product name. 96 00:10:03,760 --> 00:10:04,280 So... 97 00:10:09,960 --> 00:10:11,900 Everyone touching the wall? Yeah? 98 00:10:14,160 --> 00:10:18,460 So we start looking as... we were at the 99 00:10:18,460 --> 00:10:24,400 same time we were reviewing source, Linux USB drivers' source code, we were discussing 100 00:10:24,400 --> 00:10:28,660 how we were going to be performing USB driver fastening. 101 00:10:29,840 --> 00:10:36,160 We came with three different approaches, which were the approaches that fitted more to us 102 00:10:36,160 --> 00:10:40,680 in the timeframe that we had and in the project that we were performing. 103 00:10:41,160 --> 00:10:47,980 And I want to stop at this moment and say that I'm not selling here a fuzzing framework 104 00:10:47,980 --> 00:10:49,940 tool or a fuzzing technique. 105 00:10:50,200 --> 00:10:54,080 This is what worked for us and I hope it gives you some ideas. 106 00:10:54,080 --> 00:11:02,220 We took three different approaches, a virtualized approach using QEMU, a network approach using 107 00:11:02,220 --> 00:11:09,300 USB over IP, and a hardware approach, consisting actually in implementing hardware that will 108 00:11:09,300 --> 00:11:11,800 send my fork data to the target system. 109 00:11:13,120 --> 00:11:14,260 So QEMU. 110 00:11:14,700 --> 00:11:22,520 QEMU is an open source machine emulator, a virtualizer, and it's quite cool because it 111 00:11:22,520 --> 00:11:24,060 allows us to emulate. 112 00:11:24,060 --> 00:11:29,680 It emulates USB devices from the host computer to the guest operating system, as if this 113 00:11:29,680 --> 00:11:35,020 was actually physically plugged into the device, into the target system. 114 00:11:36,740 --> 00:11:44,740 The idea of this fuzzing approach was to actually have an environment with our host 115 00:11:44,740 --> 00:11:49,800 system and a virtual machine with the same... 116 00:11:52,260 --> 00:11:54,040 I forgot to say... 117 00:11:55,540 --> 00:11:59,460 Actually, we perform a source code review because the operating system that was being 118 00:11:59,460 --> 00:12:03,600 used in the hardware that we were testing was Linux. 119 00:12:04,500 --> 00:12:07,060 As we all know, secure operating system. 120 00:12:09,620 --> 00:12:15,000 So what we did in the virtual machine, we installed Linux, the exact version that was 121 00:12:15,000 --> 00:12:22,540 used in the hardware device that we were testing, with the idea of emulating multiple USB devices 122 00:12:22,540 --> 00:12:23,500 from the host computer. 123 00:12:23,500 --> 00:12:23,780 So what we did in the virtual machine, we installed Linux, the exact version that we 124 00:12:23,780 --> 00:12:28,680 to the guest virtual machine, sending my fork data to the guest virtual machine. 125 00:12:30,500 --> 00:12:36,460 For this, what we did was to recompile QEMU with multiple fuzzing cases, being each fuzzing 126 00:12:36,460 --> 00:12:40,360 case a USB device to be emulated into the virtual machine. 127 00:12:43,880 --> 00:12:49,160 The advantages of this approach is that it gave us a very quick start-up to start fuzzing 128 00:12:49,160 --> 00:12:50,780 USB device drivers. 129 00:12:51,560 --> 00:12:52,800 It required... 130 00:12:52,800 --> 00:12:53,480 It required... 131 00:12:53,500 --> 00:12:57,540 Very little resources when it came to software and hardware. 132 00:12:57,940 --> 00:13:03,320 First of all, because QEMU is open source, you have a virtual machine. 133 00:13:05,400 --> 00:13:09,520 And it just required a little bit of programming here and there to actually make this work. 134 00:13:10,040 --> 00:13:12,720 The main disadvantages is that we were... 135 00:13:12,720 --> 00:13:15,380 We lacked from a proper fuzzing engine. 136 00:13:15,940 --> 00:13:21,380 What I mean with a fuzzing engine is actually something that is going to be creating fuzzing 137 00:13:21,380 --> 00:13:22,900 cases for our fuzzing. 138 00:13:23,500 --> 00:13:27,620 And we were relying in text files containing malformed data. 139 00:13:28,240 --> 00:13:33,900 And every time that we wanted to create a bunch of fuzzing cases, we had to recompile 140 00:13:33,900 --> 00:13:37,220 QEMU with all our fuzzing cases. 141 00:13:44,680 --> 00:13:46,880 So we took a second approach. 142 00:13:49,480 --> 00:13:50,760 USB over IP. 143 00:13:50,960 --> 00:13:51,500 With the... 144 00:13:51,500 --> 00:13:52,040 With the... 145 00:13:52,040 --> 00:13:55,860 With the aim of overcoming some of the problems that we found in the previous approach. 146 00:13:58,260 --> 00:14:02,960 The idea of this is actually to get USB packets and sending over the network to the target 147 00:14:02,960 --> 00:14:03,260 system. 148 00:14:03,660 --> 00:14:05,560 For that, we look at... 149 00:14:09,500 --> 00:14:16,660 It's a Linux module called USB IP, which actually allows you to legitimate shared USB devices 150 00:14:16,660 --> 00:14:17,640 over the network. 151 00:14:18,040 --> 00:14:18,740 So we... 152 00:14:18,740 --> 00:14:19,860 We look at this... 153 00:14:20,160 --> 00:14:20,740 This module. 154 00:14:20,740 --> 00:14:23,640 And we got a couple of Wireshark captures. 155 00:14:24,440 --> 00:14:25,620 We see what was... 156 00:14:25,620 --> 00:14:26,480 What was being sent. 157 00:14:26,600 --> 00:14:27,860 As it is also open source. 158 00:14:28,000 --> 00:14:28,780 Open source. 159 00:14:28,860 --> 00:14:34,780 We look at the source code to actually create a little tool that will allow us to send... 160 00:14:36,560 --> 00:14:39,080 To replicate USB IP packets. 161 00:14:41,560 --> 00:14:43,800 So our environment looks something like this. 162 00:14:43,940 --> 00:14:49,580 We have the attacker system with this tool that we created to replicate the USB IP packets. 163 00:14:49,800 --> 00:14:50,720 We implement this. 164 00:14:50,740 --> 00:14:54,920 We implemented an already existing network fuzzing engine, which will be creating our 165 00:14:54,920 --> 00:14:55,540 fuzzing cases. 166 00:14:56,440 --> 00:14:59,980 The attacker would send the USB packets over IP. 167 00:15:00,240 --> 00:15:05,220 At the target system, we will have the USB over IP... 168 00:15:05,220 --> 00:15:11,100 USB IP module installed that will be in charge of taking the USB packet that we are sending 169 00:15:11,100 --> 00:15:15,600 with the malformed data, removing the IP header from the packet, and sending the USB packet 170 00:15:15,600 --> 00:15:16,820 directly to the... 171 00:15:16,820 --> 00:15:17,540 To the drivers. 172 00:15:19,580 --> 00:15:20,720 The advantages of the... 173 00:15:20,740 --> 00:15:22,940 The advantages of this is that we have a fuzzing engine. 174 00:15:23,220 --> 00:15:27,920 We use an already network system fuzzing engine, and it could create the different fuzzing 175 00:15:27,920 --> 00:15:28,160 cases. 176 00:15:28,900 --> 00:15:32,700 The disadvantages is that we were relying on a piece of software. 177 00:15:32,880 --> 00:15:39,960 And in this case, being USB IP, meaning that any problem in this software would actually 178 00:15:39,960 --> 00:15:42,280 affect the reliability of our software. 179 00:15:42,560 --> 00:15:43,620 Of our fuzzer. 180 00:15:43,700 --> 00:15:43,980 Sorry. 181 00:15:51,980 --> 00:15:58,720 The third approach, the hardware fuzzer. 182 00:15:58,980 --> 00:16:04,880 And the idea of this approach was actually create a hardware device that could actually 183 00:16:05,240 --> 00:16:08,960 be plugged directly into the target system and send malformed data. 184 00:16:11,060 --> 00:16:11,700 This... 185 00:16:13,140 --> 00:16:13,460 This... 186 00:16:13,460 --> 00:16:19,860 approach because it's quite a long-term project, I would say, and it requires more than two 187 00:16:19,860 --> 00:16:24,760 weeks that we had for the testing. But the ideas that we thought about were two approaches. 188 00:16:25,480 --> 00:16:30,760 The first approach would be to actually have this USB hardware that would create the fasting 189 00:16:30,760 --> 00:16:38,400 cases impersonating a USB, a specific USB device or multiple USB devices being plugged 190 00:16:38,400 --> 00:16:46,400 into the target system and actually send the malformed data. The second approach that we 191 00:16:46,400 --> 00:16:50,080 thought with the hardware fasting, it would be a man-in-the-middle approach where we would 192 00:16:50,080 --> 00:16:56,420 actually have the hardware device performing a man-in-the-middle. So we would be plugging 193 00:16:56,420 --> 00:17:03,620 a USB device to this hardware. This hardware would take the USB packet in the flight, modify, 194 00:17:04,000 --> 00:17:08,380 put the malformed data, and send that directly to the hardware. 195 00:17:08,400 --> 00:17:17,320 As I say, it's a longer-term project, and I know there is already people out there trying 196 00:17:17,320 --> 00:17:19,960 or performing this type of hardware faster. 197 00:17:25,480 --> 00:17:38,380 So we were reviewing the driver source code, and we were checking if the driver source code was 198 00:17:38,400 --> 00:17:42,940 working. We left the faster running. Every now and then, as you know, when you perform 199 00:17:42,940 --> 00:17:46,560 any fasting, every now and then you go and check the fast, if it has crashed, if it 200 00:17:46,560 --> 00:17:55,080 has identified something. At the same time, we were also performing some USB source code 201 00:17:55,080 --> 00:18:07,760 review. Just suddenly, while we were reviewing one of the drivers, USB driver source code, 202 00:18:08,400 --> 00:18:14,100 we found a development mistake, a vulnerability in one of the Linux USB device drivers that 203 00:18:14,100 --> 00:18:14,860 we were looking at. 204 00:18:19,000 --> 00:18:35,620 Oh, hold on. It's a pretty picture. You guys keep touching the wall, yeah? 205 00:18:36,320 --> 00:18:36,880 You guys keep touching the wall, yeah? 206 00:18:38,400 --> 00:18:45,040 It's a pretty picture. 207 00:18:52,240 --> 00:18:53,000 Hmm. 208 00:19:05,720 --> 00:19:07,880 Three seconds. Three seconds. 209 00:19:35,220 --> 00:19:36,260 And we found the bug. 210 00:19:44,060 --> 00:19:44,780 Okay. 211 00:19:47,920 --> 00:19:52,820 We found a bug in one of the Linux USB device drivers. 212 00:19:54,500 --> 00:19:55,200 The bad news. 213 00:19:57,100 --> 00:20:03,260 For some political issues, I can't actually disclose as much as I would like. 214 00:20:04,380 --> 00:20:07,940 In this slide, I would have had actually the 215 00:20:08,700 --> 00:20:11,140 vulnerability that I found, actually the device itself. 216 00:20:11,560 --> 00:20:12,900 And I cannot put the picture. 217 00:20:13,060 --> 00:20:15,600 So I say I'm going to put a pretty picture. 218 00:20:23,560 --> 00:20:27,900 All these political issues happened not very long ago. 219 00:20:28,840 --> 00:20:30,020 Actually a couple of days ago. 220 00:20:30,420 --> 00:20:36,780 So I have tried and I have, I would like to say here today that I'm hand over. 221 00:20:36,780 --> 00:20:38,300 But I'm not. 222 00:20:38,400 --> 00:20:42,120 Because I've been working on this to actually show you as much as I can. 223 00:20:43,800 --> 00:20:49,020 And so I had to modify a series of things to actually show you, you know, what is really 224 00:20:49,020 --> 00:20:51,520 going on without actually, you know what I mean. 225 00:20:53,220 --> 00:20:57,860 So the vulnerable device, as I did this in Vegas, is Vegas Girl. 226 00:20:58,360 --> 00:20:59,120 I don't know why. 227 00:21:00,380 --> 00:21:06,600 And it's a buffer overflow vulnerability that is happening in Tom, Dick and Harry 228 00:21:06,600 --> 00:21:06,820 function. 229 00:21:07,440 --> 00:21:08,940 I know why it's that name. 230 00:21:09,140 --> 00:21:09,940 I'm not going to say. 231 00:21:12,960 --> 00:21:19,440 Tom, Dick and Harry function, a function is in charge or is responsible for handling 232 00:21:19,440 --> 00:21:24,940 the USB string descriptor. 233 00:21:25,160 --> 00:21:33,460 And if we go back to the technical background slides, the string descriptor is that data 234 00:21:34,260 --> 00:21:36,580 structure that sends human readable data. 235 00:21:36,580 --> 00:21:38,160 The manufacturer name. 236 00:21:38,260 --> 00:21:38,780 We saw that before. 237 00:21:38,940 --> 00:21:39,540 The manufacturer name. 238 00:21:39,640 --> 00:21:40,360 The product name. 239 00:21:40,460 --> 00:21:41,120 And the serial name. 240 00:21:41,400 --> 00:21:44,660 And it's actually data that we control. 241 00:21:44,960 --> 00:21:47,660 Because it's sent from the USB device to the host computer. 242 00:21:48,000 --> 00:21:54,600 Which means that we can actually cause this, we can actually trigger this buffer overflow. 243 00:21:58,160 --> 00:22:04,180 So USB string function is actually, well it's not similar, but we can think of as a main 244 00:22:04,180 --> 00:22:04,480 copy. 245 00:22:04,480 --> 00:22:05,480 Or a string copy. 246 00:22:05,700 --> 00:22:08,700 Because we are actually copying from A to B and into a buffer. 247 00:22:09,200 --> 00:22:17,920 And the buffer that we are overflowing is used by an element of one of the USB device 248 00:22:17,920 --> 00:22:18,200 structure. 249 00:22:20,400 --> 00:22:25,560 So what is actually happening, we are just copying too much data in that buffer and allowing 250 00:22:25,560 --> 00:22:29,000 us to actually overwrite other elements of the data structure. 251 00:22:29,500 --> 00:22:34,380 And we'll see later what actually can happen with this. 252 00:22:35,260 --> 00:22:42,380 What we are going to do to demonstrate the vulnerability, we are going to do a kernel 253 00:22:42,380 --> 00:22:42,920 crash demo. 254 00:22:49,040 --> 00:22:54,780 So for the kernel crash demo, the QEMU that we had before, what we are going to have is 255 00:22:57,900 --> 00:22:59,680 QEMU running on a virtual machine. 256 00:23:00,440 --> 00:23:01,260 With Linux. 257 00:23:01,400 --> 00:23:03,800 And with the vulnerable USB device. 258 00:23:03,960 --> 00:23:04,440 Okay. 259 00:23:04,440 --> 00:23:04,900 With the driver. 260 00:23:05,120 --> 00:23:12,020 And what we are going to be doing is emulating our malicious Vegas, malicious Vegas kernel. 261 00:23:12,280 --> 00:23:17,400 That sounds a bit, malicious Vegas kernel device. 262 00:23:17,960 --> 00:23:28,480 So we start QEMU. 263 00:23:33,320 --> 00:23:34,220 It's started. 264 00:23:34,440 --> 00:23:40,080 And we can see here the vendor ID and the product ID being those where it's actually 265 00:23:40,080 --> 00:23:43,520 going to identify the device driver that's going to be used. 266 00:23:44,260 --> 00:23:45,840 Of course it's not 0000. 267 00:23:51,460 --> 00:23:55,360 And we are going to be looking at the data, in this case A, that is going to be overflowing 268 00:23:56,100 --> 00:23:58,240 the buffer for the element of the structure. 269 00:24:01,260 --> 00:24:02,580 So, we go to QEMU. 270 00:24:03,100 --> 00:24:04,420 And we go to QEMU. 271 00:24:05,480 --> 00:24:07,920 And we are going to emulate the USB device. 272 00:24:09,280 --> 00:24:15,020 And we get the kernel crash without actually showing the IP because it will be showing 273 00:24:15,020 --> 00:24:15,360 too much. 274 00:24:21,540 --> 00:24:32,880 So for crash analysis, there are many tools out there for kernel ‑‑ there are many 275 00:24:32,880 --> 00:24:33,480 tools out there. 276 00:24:34,440 --> 00:24:36,440 And we are analyzing kernel crash. 277 00:24:36,740 --> 00:24:38,720 A majority of them based in GDB. 278 00:24:39,200 --> 00:24:44,220 I'm quite a big fan of what did really work for me in this project was KGDB. 279 00:24:44,420 --> 00:24:50,260 Because it actually allows you to set breakpoints in the kernel in live execution. 280 00:24:51,620 --> 00:25:00,420 So the environment I have set up is KGDB in the debugger system, the target system running 281 00:25:00,420 --> 00:25:04,420 the Linux with the vulnerable USB device. 282 00:25:04,420 --> 00:25:06,800 The device driver connected with a serial connection. 283 00:25:07,340 --> 00:25:12,320 And the malicious USB device plugged into the target system. 284 00:25:12,700 --> 00:25:19,200 The target system running the Linux driver that would be debugged. 285 00:25:23,140 --> 00:25:30,480 So what I did, I implemented this exploit in a hardware device. 286 00:25:30,860 --> 00:25:34,060 And I used a PIC 18 family microcontroller. 287 00:25:34,420 --> 00:25:36,860 Which is relatively easy to program. 288 00:25:37,080 --> 00:25:39,720 And you got a lot of guides out there to actually do this. 289 00:25:40,540 --> 00:25:46,360 And I performed the malicious ‑‑ I implemented the malicious device. 290 00:25:48,300 --> 00:25:53,140 I flashed in the microcontroller with the share code in order to exploit the device 291 00:25:53,140 --> 00:25:53,340 driver. 292 00:25:53,920 --> 00:26:00,180 And the device driver, my little baby, looks something like this. 293 00:26:01,320 --> 00:26:02,360 Which I will show here. 294 00:26:02,360 --> 00:26:05,260 Which is a PIC 18, F14, K550. 295 00:26:15,160 --> 00:26:19,860 So let's do a little bit of crash ‑‑ demo of the crash analysis and the exploit demo 296 00:26:19,860 --> 00:26:20,960 that I implemented. 297 00:26:22,420 --> 00:26:23,200 With this device. 298 00:26:23,620 --> 00:26:28,740 With the idea of what we're going to be seeing is we're going to be seeing the environment 299 00:26:29,560 --> 00:26:32,040 where I flashed the ‑‑ where I programmed it. 300 00:26:32,360 --> 00:26:41,200 So we're going to be using a malicious device, we'll be flashing the microcontroller with 301 00:26:41,200 --> 00:26:41,760 our share code. 302 00:26:42,100 --> 00:26:48,940 And then we'll be plugging this in the target system and actually going through to actually 303 00:26:48,940 --> 00:26:50,980 see what is going on with this exploit. 304 00:26:55,240 --> 00:26:55,880 Oh. 305 00:26:56,700 --> 00:26:57,440 Ta-da. 306 00:26:57,800 --> 00:26:58,260 Ta-da. 307 00:26:58,260 --> 00:26:58,460 Ta-da. 308 00:26:58,460 --> 00:26:58,520 Ta-da. 309 00:27:01,540 --> 00:27:02,340 Ta-da. 310 00:27:02,360 --> 00:27:03,000 Ta-da. 311 00:27:03,000 --> 00:27:03,500 Ta-da. 312 00:27:03,540 --> 00:27:03,980 Ta-da. 313 00:27:03,980 --> 00:27:04,420 Very good. 314 00:27:05,480 --> 00:27:06,260 Very good. 315 00:27:12,740 --> 00:27:14,300 Very good. 316 00:27:14,300 --> 00:27:23,300 So this is my environment for ‑‑ for programming the USB device using MP Labs. 317 00:27:24,960 --> 00:27:26,980 It's just really quite cool software. 318 00:27:30,900 --> 00:27:33,300 And I'm not very good doing demos. 319 00:27:34,000 --> 00:27:42,560 But that is going to be a set of A's that will be the code that we're going to be executing 320 00:27:42,560 --> 00:27:43,160 in this demo. 321 00:27:49,100 --> 00:27:57,040 And these here are the different elements of the data structure that we are going to 322 00:27:57,040 --> 00:27:57,520 be overwriting. 323 00:27:59,280 --> 00:28:01,440 There is a static address and a pop return. 324 00:28:01,800 --> 00:28:02,580 I will explain. 325 00:28:02,740 --> 00:28:05,020 I'm not going to get into details now about this. 326 00:28:05,120 --> 00:28:06,420 But we'll explain this a little bit later. 327 00:28:12,920 --> 00:28:18,920 So, we compile our source code, hopefully. 328 00:28:33,860 --> 00:28:35,600 It would be good to have an error in a demo. 329 00:28:39,440 --> 00:28:43,700 And we're going to be flashing our microcontroller. 330 00:28:50,700 --> 00:28:55,640 The main reason for showing this in a demo is that this environment involves three laptops 331 00:28:56,540 --> 00:28:58,380 and the microcontroller itself. 332 00:29:01,060 --> 00:29:04,400 Plugging this around, it could be a little bit of trouble. 333 00:29:05,600 --> 00:29:07,220 I have problems with only one laptop. 334 00:29:07,820 --> 00:29:08,700 Imagine with three. 335 00:29:11,340 --> 00:29:13,720 So we flash the microcontroller. 336 00:29:17,000 --> 00:29:17,500 Okay. 337 00:29:18,900 --> 00:29:19,020 Okay. 338 00:29:37,880 --> 00:29:38,840 So we flash the microcontroller. 339 00:29:38,840 --> 00:29:44,140 And what we do, this is going to be our debugger system, which is actually plugged 340 00:29:44,140 --> 00:29:50,560 with a serial port to the target system with the device actually running. 341 00:29:51,580 --> 00:29:58,940 What we are doing is starting GDB to connect to the remote system via serial port. 342 00:29:59,140 --> 00:30:00,700 We connect to the target system. 343 00:30:02,420 --> 00:30:04,280 And we send a break point. 344 00:30:04,280 --> 00:30:11,940 And in Tom, Dick, and Harry function, that if we remember is the function where the numeration 345 00:30:11,940 --> 00:30:20,040 process takes place and the string descriptor is actually passed from the device to the 346 00:30:20,040 --> 00:30:20,400 host computer. 347 00:30:21,460 --> 00:30:22,420 So we continue. 348 00:30:22,640 --> 00:30:23,360 We hit a function. 349 00:30:26,760 --> 00:30:33,260 And we set a break point in USB string, which is going to be doing the copying into the 350 00:30:33,260 --> 00:30:33,980 buffer. 351 00:30:35,100 --> 00:30:35,960 We continue. 352 00:30:37,060 --> 00:30:38,800 And there is our buffer. 353 00:30:41,120 --> 00:30:44,240 And we are going to see the status of our buffer at that stage. 354 00:30:44,500 --> 00:30:47,420 And as we can see at the moment, the buffer is empty. 355 00:30:49,940 --> 00:30:51,260 So we continue. 356 00:30:51,420 --> 00:30:54,480 We hit the USB string function again. 357 00:30:54,820 --> 00:30:56,640 And we look at the status of our buffer. 358 00:30:57,000 --> 00:31:02,920 And now we see that our buffer is legitimately filled with our set of A's. 359 00:31:03,200 --> 00:31:03,660 Okay. 360 00:31:06,760 --> 00:31:18,980 We continue, and this is where we overflow actually the buffer, and we set, we actually 361 00:31:18,980 --> 00:31:24,920 overwrite the elements of the data structure, being the static address and the pop return. 362 00:31:28,460 --> 00:31:43,120 Now the idea of the static address and the pop return is to actually get the pop return 363 00:31:43,120 --> 00:31:47,720 just exactly after the execution of the stack, and we'll see that later. 364 00:31:50,200 --> 00:31:50,880 So. 365 00:31:51,960 --> 00:31:52,640 So. 366 00:31:56,600 --> 00:32:06,160 We have set a break point where we are going to be writing the pop return and we see that 367 00:32:06,160 --> 00:32:13,580 we have control of ECX and EVX. ECX being the pop return and EVX being a static address. 368 00:32:13,860 --> 00:32:24,900 And we see what this static address actually do. We set up a break point in 8.53 and we 369 00:32:24,920 --> 00:32:31,240 look at the status of the instruction at the address. So what we want to do is to actually 370 00:32:32,120 --> 00:32:45,980 with this move from ECX to EVX plus 3C, what we'll do is we'll get the pop return into EVX 371 00:32:45,980 --> 00:32:54,900 plus C which will be the next instruction to be executed. Which will be here. So we have 372 00:32:54,920 --> 00:32:58,600 it, it is what we want to write our pop return. 373 00:33:03,380 --> 00:33:11,920 So we step in and we look at the status. So we've done already the move of data and we 374 00:33:11,920 --> 00:33:12,640 have our pop 375 00:33:38,140 --> 00:33:46,840 Okay. Sorry. So we step in and we get into pop EAX. Pop EAX is 376 00:33:46,840 --> 00:33:50,100 going to be popping EAX and bringing execution to the next 377 00:33:50,100 --> 00:33:55,260 instruction, which is going to be a pointer with our shellcode 378 00:33:56,220 --> 00:34:00,440 close to where our shellcode is. And we return and we'll be 379 00:34:00,440 --> 00:34:08,160 executing the address. And we get a segmentation fault. If we 380 00:34:08,160 --> 00:34:16,840 do backtrace, we can see the execution path. And then we 381 00:34:20,600 --> 00:34:25,540 have the demo. So we have the demo. Getting closer to the end. 382 00:34:26,000 --> 00:34:31,860 The recommendations. Disable not required USB drivers when you 383 00:34:31,860 --> 00:34:38,520 can. Actually try to assess the USB device driver that you need 384 00:34:38,520 --> 00:34:42,320 and actually just use the ones that you need. In that way you 385 00:34:42,320 --> 00:34:49,840 actually will close down a little bit the attack vectors. And security 386 00:34:50,100 --> 00:34:54,500 test the USB drivers when possible. And if you have access to the 387 00:34:54,500 --> 00:34:59,460 source code, do a source code review. Or if not, you can also do 388 00:34:59,460 --> 00:35:04,160 black box testing. And also in organization or company, always 389 00:35:04,160 --> 00:35:09,820 assess the use of USB risk. Implement security policies when 390 00:35:09,820 --> 00:35:19,040 required. Yeah. Assess the risk. A little bit of reference here. 391 00:35:19,260 --> 00:35:20,080 More reference. 392 00:35:20,100 --> 00:35:29,820 More reference here. And questions. Any questions? Thank you.