Hello, my name is Dominic Spill. This is Mike Kershaw. This is going to be quite a quick talk. We submitted this as a 20-minute talk and they've given us an hour, so you've all got a coffee break in like 25 minutes' time. This is an idea we came up with a couple of... you've been talking about it for about 18 months? Yeah, I complained about it for a long time, and then Dominic finally went and did something about it. Where are the speakers? Over there. Alright, then everyone shut the hell up! Go outside if you want to talk, otherwise you can stand here and listen to me. I would recommend going outside. So, yeah, carry on. So, yeah, I came up with the idea probably about 18 months, 2 years ago, and then didn't bother doing anything with it until finally I asked Dominic enough to actually write the code. This is what we call the Kershaw method. Delegation. Yeah, so basically we want to solve driver issues with all sorts of devices, but in this case specifically 802.11. USB devices such as this one, or all the ones that you can see being used around CTF and things like that. And we want to try and solve some problems and open up some platforms to, you know, other platforms to Kismet and Aircrack and that sort of stuff. I'm Dominic Spill, I work for Great Scott Gadgets writing open source software and working on some hardware stuff. I'm really bad at hardware, so this project is based on me trying to avoid hardware by writing it in software. I'm Mike Kershaw, I do Kismet and I work for Blackphone. There we go. In case anyone missed that, Mike Kershaw wrote Kismet. Loads of times people don't recognize who he is, so this is what his face looks like. You owe him five bucks if you've ever been using Kismet and found it useful. You should give him five dollars. You don't have to give me five dollars. Make it rain. Okay, so 802.11 monitor mode. This is probably more your thing? Sure. So it requires drivers that support monitor mode obviously. Works really well in Linux. It doesn't work really well in anything else. OSX, there's some stuff that works with USB cards. There's some ways sometimes to put the internal card in monitor mode, but Apple keeps changing that and breaking it. There's nothing really good in Android. There's some solutions on Windows. They tend to be commercial and about 900 bucks. So, you know, how do we deal with these problems? So this led me to have a question a couple years ago about Android. Which is, can you write a device driver in Java? Or is that just stupid? This question is not an or. The answer is yes to both. So I did it the dumb way. You can see Android PCAP. It's in the Google market. There's links to the get code on the Kismet site. You can port kernel drivers to Java. The Android Java layer is basically libUSB. You just have to convert all the kernel USB functions and do them in Java. It's freaking terrible. I would not recommend doing this. It involves a lot of things like that. Some fun things that you discover doing this is Wi-Fi cards do really weird shit. The 8187, for example, if anyone does hardware and is aware of the SPI protocol, the 80211 or the 8187 drivers do SPI over USB per packet. Bit high, clock high, USB right. Clock low, USB right. Bit low, clock high, USB right. Repeat. It's insane. Timing can definitely be an issue trying to configure these things from an Android app with no extra permissions. That really doesn't expect to be doing this nonsense. The other thing about this is we've already got a working implementation. It seems like a really stupid thing to go and take an existing implementation and just try and copy the whole thing, bugs and all, into another language just to run a different system. You should be able to compile the code for both or something like that, but it's the limitations of Android and most of Android. In this case, I was targeting Android, but the same thing would apply to using random cards that work great in Linux on Windows or on OS X. So we figured we might as well leverage the fact that they all work in Linux and try and make them work for other platforms through that. Yeah, so the problem is, you know, doing it the dumb way doesn't scale. So that code supports the 8187 with a couple of the main tuner chips and a couple of the EEPROMs on it. It doesn't work with anything else. Anything else is going to be, you know, 5 to 20,000 lines of code. Plus you have to figure out how to do the firmware loading, which is another 20,000 lines of code for most of the modern cards. For every card out there and every new chipset that comes out. No thanks. I'm not doing that. Right. And, you know, our time is relatively expensive. So we were thinking if we could buy a little bit of hardware to fix this, then potentially that would be worth more than the time it would take to port the driver. So we found some hardware we liked, and we'll come on to that in a minute. But basically we're going to use a piece of hardware and build an abstraction layer. So there's already a library called LawCon. It's by Mike and Josh Wright. It's called... it's loss of radio connectivity. And what it does is abstract away the differences between those cards. So you don't have to worry about which driver you're talking to, how it works. You just say, open me an interface, give me monitor mode, something like that. And it abstracts all that away as long as you're running on Linux. So that doesn't solve our problem for Android or for Windows or anything like that. It only solves it if you want to simplify the code inside of Kismet or Aircrack or something like that to save those programs having to worry about the differences between drivers. So this seems like a pretty good abstraction layer, and if we're going to build a new one, we may as well build it on top of that. A lot of people are using USB devices for this, so we may as well carry on using USB. It's incredibly prolific. It's everywhere. These things are cheap. This was like 30 bucks. So we just decided to extend the USB interface and modify it slightly on the fly. So what we need is a USB man-in-the-middle device to do this, and luckily I wrote one. It's called USB proxy, and I gave a talk about it at B-Sides a couple of days ago, where I was doing things with USB mass storage like flash drives. In this case, we're doing very similar things, using exactly the same library to proxy USB traffic between the two sides of our piece of hardware. It's a C++ framework. It connects using libusb to a device. It uses GadgetFS, which is part of the Linux kernel, to present a USB device as a file system, and then we're using this Lorkon library to attach ourselves to the Athros chip in this case, but whatever, it's abstracted, and we're going to mirror those calls across USB. So this is kind of what USB proxy looks like. This is my opportunity to pimp my own project. We just have a device on one side, a host on the other, and we can relay traffic across the middle. We can inject packets, and we can remove them into the USB layer. For this project, all we're doing is that center line across the middle of the slide. We're not injecting anything. We're not filtering any packets. We're just relaying stuff back and forwards. And the hardware we're using is the BeagleBone Black, and I'm going to touch it and hope everything doesn't stop working. It looks like this. It is a single board computer from a company called CircuitCode, but they use a TI chip. It's kind of TI's answer to the Pi, I guess. It's kind of like a Raspberry Pi. It's got more capabilities in some regards. It's got less capabilities in others. But it's basically equivalent to a Pi. It's about the same price, about $40. It's a bit faster. It's got some really nice features. I prefer it to the Pi. I find the Pi relatively useless for what I want to do. But the one key thing it's got that the Pi doesn't have, and that's what makes this application work, is a USB device port. So from user space Linux code on the BeagleBone, I can write a device in software, plug it into another host, and it appears as a USB device. So they use this to appear as a file system, they use it to appear as a network device, and things like that. In our case, we're going to appear as our custom USB device to provide 802.11 monitor mode and things like that. Oh, and I like it because it's open source hardware. I'd forgotten about that. You can go and download the schematics and the getters and stuff like that. I hadn't seen you there. And we're using GadgetFS, as I said before. All this does is it just lets us write to a file system as if they're USB endpoints. Did anyone see the USB talk yesterday by Jesse Michael and Mickey something? They were basically talking about the structure of USB. You don't really need to worry about this at all because we've written the code for you. You've modified my slides. I have. We just kind of write to a file system as if it's an endpoint so we can receive data by reading and writing files, which means that I don't have to care about how USB works. I don't have to care about checksums and packet headers and any of that stuff. I can just go, here's some data. So on one hand, I'm talking to a radio library that gives me raw bytes. And on the other hand, I've got a file, and I can just write those raw bytes straight to that file, and they'll appear on the USB interface at the other end. So it's actually really nice and simple. And then look at the radio library we're using. And this abstracts away anything that we'd have to care about to do with different chipsets and different devices. As long as Linux supports it, and it has Montemo and raw frame injection and that sort of stuff, this will let us just talk to it with a common API. So we don't have to worry about, is it an Athros chip, is it an RTL something, something, something. Yeah, and it also lets us, you know, right now all the main drivers in Linux support RadioTap, but it's always possible that's going to change and whatnot. And Lortan abstracts out those headers so we can get the signal levels. And then we'll send the raw headers on to the other device, but they won't have to necessarily pay attention to it. And we even split it up so that if you're writing code to receive packets, you don't even have to care about the header format. It just tells you, skip this many bytes in and you get the raw header full of the packet. You don't have to care if it's PPI or RadioTap or Prism 2 or whatever the hell. So this is the point at which I was going to do a demo. It should be noted that it doesn't work. The word may in this sentence is incorrect. It doesn't work. But I'm going to at least show you kind of what happens. There's some very simple settings that we can do. It turns out, actually, we're capturing the radio data, capturing the packets on the BeagleBone. And as we pull them across the BeagleBone to write them out to the file system to send them over, the code segfaults because I'm terrible at pointer arithmetic. And this morning was not the time to rewrite that bit of code. So I'm really sorry, but I can't show packet snipping. But I will try to show it doing something. It's conceptually functional. It's just practically screwed up. All right. Well, this projector is not entirely on the right screen, is it? Let me increase my font size for you. And, yeah. Sorry. I may not be as prepared as other speakers. Ugh. So... Oh, you should also note that the code doesn't exit cleanly. So I can only do this once, and then I have to play around, like, killing things. Okay. So I just wrote a quick tool called USB, man in the middle. And it's going to use our specific device proxy here. It's called deviceproxy.11. And the config file literally just tells it which interface to use. There's only one on this system anyway, but it just tells it, use WLAN0. So... Huh. Let's hope this works. So what you can see, I'm going to wander and point... No, that's going to scratch the video, isn't it? I'm going to point with a mouse pointer. So what you can see is we opened up a USB device. It's using the Mac 802.11 driver. It's got WLAN0. And then it's just... The host tries to set the configuration on my USB device. Which doesn't do anything. And then we start sniffing packets. And here, we've sniffed a 197-byte header. Is that true? Okay, we've sniffed a 197-byte header with no data, which sounds like a beacon. And then we've written it to the other side. And... let's see if this does anything. No, it doesn't. So what we try and do is we then copy that over to the other side. To write over to the host system. And that's when the code just sort of dies. And nothing happens. And nothing to see here. But what we are able to do is do things like set the time out on the device. And read it back. And open the WLAN0 on capture interface. And we're that far away. If our talk had been an hour later, we probably still wouldn't have any working code. But we would have been a little bit closer. And that's pretty much the thing we've been working on for the past, well, four hours. And we think it's kind of a fun concept. And so we want to take the opportunity to just kind of talk to people about it. We're really sorry it doesn't work yet. But we did manage to hook it up to an Android tablet. And again, if I use the mouse pointer wherever it's gone. There it is. You can see it's connected to a .11 proxy. And in the logs, it's picking up stuff coming off the device. There's no way we can hook our Android tablet to the projector to show you this working. But, you know, it's got channel hopping enabled. And it can read the functionality from the wireless device. And we can report that to Android PCAP. And then we can start capturing packets. And then we can upload them to... Anything you can share to. You can upload it to CloudShark and get a live decode that way. Or we can copy it over to a host and rumble our shark. Or you can copy it to a host and throw it into aircraft or whatever you want to do. Another key part of this is that the same code that makes it work on Android means it'll work on Windows with a little USB the same way the UberTooth does. It'll work on Mac the same way that the UberTooth does. So we've taken it from porting 10,000 lines of code per random Wi-Fi card driver to... Well, here you go. Yeah, the amount of code needed to talk USB on Android, and that includes all the class-wrapper crap to plug into the Android PCAP GUI that I have, is 250 lines of code. Yeah, so we've dropped to a factor of... We'll try that sentence again. We've dropped the size of the code by a factor of 10. More than that. And more than that. And just for this one file. And that one interface will cover anything that supports... any Wi-Fi driver that's supported on Linux. So it's not just, oh, we've got a new device and it uses less code. We've got a new device and it covers all the existing devices. And once this code works, which is really soon... Once this code works, all of the supported Linux HL2.11 devices will work on Android. And someone can write some libUSB code for Windows and it'll work on Windows. And it just becomes a much, much easier way to do it. And the only thing that it costs is $40 for the BeagleByBlack. If you can get hold of one. We're also looking at porting it to... I mean, the code is generic. It's written for... targeted to Linux. So if you find another piece of embedded hardware with a USB device port on it, it'll work for that as well. So there's an Olmec's Lime. And I'm trying to remember some of the others. There are a whole bunch of different boards. And they're all in the, like, under $50 range. And so one of them, paired with a Wi-Fi device, will enable you to use Android or Windows or OS X. And I think that's mostly our project. So I want to thank Josh Wright and Mike Lussman. Because Josh Wright helped you write the Lorca library. And Mike Lussman continues to pay me, even though I work on things that have nothing to do with making any money. So thank you, Mike Lussman. Thank you. That's fine. I'm going to run down to you in a second.