Very good morning to you everyone, and I understand this is the first talk of the day, so thank you for coming. My name is Vivek, and today I'll be talking about an interesting tool which we've written called PCAP to XML and SQLite. A little bit about myself, I started as a programmer, 802.1 export security on the CAT 6K with Cisco. Moved on, did wireless security research, discovered the Café Latte attack, broke web cloaking, which was an encryption schema, currently owned by Motorola. I also run SecurityTube and Pentester Academy. My full-time job is researching, talking at conferences and writing courses, and a little bit of consulting as well. I'm an author of a couple of books on wireless security, and also our very first... self-published book. I'm going to give away a couple at the end for different questions, which I'm going to ask, you know, whoever answers it. Okay, so PCAP to XML and SQLite. Now, why did we create this tool? Now, I've been doing wireless security for the last, you know, 10 plus years, and every single time I want to get any meaningful data from the wireless traffic, it's actually quite difficult. How many of you have tried doing Wi-Fi forensics using Wireshark? How many of you actually succeeded? Okay. What did you search for? FTP traffic, right? At a pure wireless level, it's actually quite difficult to work with Wireshark. And, of course, that isn't Wireshark's limitation. Wireshark was never meant to be a framework to search, query, and mine data. You could, of course, write your own protocol disectors in Lua or in C, but the learning curve for all of that is quite a lot, and you'll spend a lot of time just looking at packet parsing code. So, what we did was, we decided to make a platform and a framework, which makes it extremely easy for anyone who's ever done SQL to go ahead and do wireless forensics. So, at the very... at a very high level, the concept of the tool is actually quite simple. We take PCAP files and packets in them, we map every single header field of a wireless packet that includes management data, control frames, most of the subtypes, and we actually map it to the database table. So, we take the packets, push them inside the database, and that actually allows you to do arbitrary queries. Now, as simple as the concept is, once the packets are in there, it's actually quite easy to get a lot of meaningful info. Now, PCAP to XML is actually quite portable. We have the Windows version, in case you prefer Windows. We also have the POSIX version. I've tested it on Ubuntu, but should work on any POSIX compatible system. The code will be open source as well. So, we're also seeing if we can port it on R, MIPS, and a couple of those CPUs as well, so that you can run it on embedded devices. The book which I've been doing is actually how to create your own Wi-Fi pineapple or something similar. So, you could actually run this on that, if you so desired. Now, getting started, let me actually show you a quick demo. I'm going to be using the Linux version. Now, there is a lot of stuff to be typed in, and I'm sure you wouldn't want me to do that. So, I'm just going to copy and paste a bunch of stuff. All of these commands are available, and you can go ahead and try them out after this talk. So, let's quickly copy this. Right? So, at the very bottom, you see a little error. It isn't. It's just trying to check if a newer version is available. If it fails, it just gives you a message. Now, what did pcap2xml actually do? It picked up the pcap file, processed every packet in it, and it goes ahead and converts that into a SQLite database, which is called xx.db at this point. We've converted pcap files, which are even around 2 gigs and above. So, you can actually give it a spin. Now, how does the SQLite file itself look like? So, we're going to actually open it up in SQLite. It's a client application. How many of you here have tried or love SQL injection? Okay. How many of you here know SQL? I've done some basic queries. So, with pcap2xml, you're basically as good as your SQL. Right? We have everything in the table. If you know how to do inner joins, kind of go ahead and take data from multiple tables and put them together, there's a lot of fun to be had. So, just to give you a very simple example, we could look at all the Mac headers for all the packet. There you go, right? Now, let me show you the schema. It's probably more interesting. So, we've mapped most management control data packets. We've also created summary tables. So, if you wanted to figure out if an access point has a specific encryption schema, then you may have to go find the right information element, figure out how to parse the IE. Now, we have the information elements and all of that in raw format as well, in case you prefer that. Right? We've base64 encoded it, so there's no need to worry about that. You can include it in your scripts if you'd like to write a fingerprint for Airbase NG, or Airreplay NG, or any of those tools as well. But this contains all of that plus the summary. So, to give you an example, the Mac header, the very first header in a wireless frame, we've actually mapped every single field including bit fields to the database. Now, this is the initial schema. If you think we can probably go ahead and optimize this further so that the queries can run faster, feel free to contribute. Now, PCAP to XML and SQLite can also dump in XML format. So, if you are more of an XPath and an XQuery person, you could actually run all of those queries on the XML itself. So, let me show you how that looks like. . So, the input which we've given right now is an additional hyphen X option where we specify the output XML file. Now, if I open that file up, for every single packet which we have, we actually have a nested XML packet structure. So, we start with the beacon frame. It's actually, the first frame is a beacon frame and we go through each of, you know, the fixed and packed parameters as an example. You have timestamp, beacon interval, capability, SSID, all the TLVs which may be in there. Now, the value of the TLVs are all base 64 encoded, right? I mean, you would have to do it or else it's kind of difficult to put everything in XML. You might break the XML depending on what could be there in one of the TLVs. And what we've done is in the XML, we've segregated the different headers. So, you can have the beacon header depending on if that is interesting to look at first and then we actually have the WLAN MAC header mentioned as well. Then you have all of the addresses, the four addresses and a bunch of other stuffs in there. Now, there are a lot of good features which PCAP to XML has. I'll just quickly run you through some of the features which you can try later. We've actually made it quite power packed. So, you can even give it a packet range or a list of packets to work on. So, if you're only interested in a subsection of the PCAP file, you could do that. So, this is basically the packet selection part. In case you have a data link layer, which is different from the regular PCAP offset, you could actually even mention the offset of where the .11 header starts. And this is something which I've faced a lot of times because a lot of cards may put in radio tap headers which may have more fields and things like that. So, this comes in handy there. We even have live mode. So, what live mode can do is if you're going ahead and dumping something inside a PCAP and you've shared that over an NFS based file system or even locally you're actually dumping using some other tool, then PCAP to XML can actually check for newer packets in the PCAP which it is monitoring. Just like if you've used AeroDump NG or any of those tools or Aircrack NG, it actually automatically pulls to see newer packets. Now, on POSIX based systems this is an experimental feature we just coded up last week. So, it's still experimental. But we will actually have live sniffing on POSIX based systems as well. On Windows you cannot do live sniffing without some kind of a device driver help. So, it doesn't apply there. Let's kind of go back. Now, one of the other interesting features is you could take multiple PCAP files and put them inside the same SQLite DB. So, this comes in handy if you'd like to do some kind of a spatial correlation. So, let's say you've probably deployed four pentesters who are collecting trace files approximately at the same time, you know, around the facility. You could merge those PCAPs or you can actually feed them directly to PCAP.xml and it's smart enough to be able to tag them based on the file name. We are also going to be adding additional options where you can even mention the location name so that you can query by location. Now, let me go back to the demos. Now, if you wanted to find all the beacon frames in Wireshark, how do you do that? Very simply put, you actually select a beacon frame. You'd go in here, right click and basically say apply as filter, right? And we get all the beacon frames which are there. 36 of them in this case. Now, you can actually do the same query here. And all you have to do is give the packet type and subtype. And there you go, right? Of course, you guys aren't here to just see me do the same thing which Wireshark can already do. Right? So, let's look at the second problem. When I do wireless pen testing, I'd like to know all the unique devices in the air, right? I'd like to know the list of all Mac addresses, APs and clients together. How do you do that in Wireshark? I'd like a unique list of Mac addresses for all the devices around. How do you do that with Wireshark? Actually, you can't. Right? You'd have to probably script or write something on your own. Now, because we have everything in the SQL database, this is unbelievably simple. So, we can actually go in here and just say select distinct across all the four different addresses of a Wi-Fi packet. Now, of course, right now we don't have a blacklist for let's say the broadcast address and the multicast addresses. You could do that as well and have a bigger query. But once we go here and we run this, you'll actually find that we get the list of all unique Mac addresses of all devices in the air. It seems to be around 390 of them. So, you can already see the power once everything is inside a SQL database. Now, let's actually make the queries a little bit more interesting. We have a lot of attack traffic in there as well. So, you may find some weird Mac addresses. We'll also talk about how to detect Mac address spoofing using this framework. Right? That's the last demo. So, don't worry if you see weird Macs in there. Now, if I'd like to find all access points, all I have to do is look at addresses which are transmitting beacon frames. Right? And I just take the distinct set. So, you can go in here. Paste this. And we have 36 rows in there. And these are unique Mac addresses of all the access points around. Now, we could do something similar to figure out which devices are actually sending data packets. Now, this is interesting if you'd like to run other tools on top of this analysis. Right? Let's say there is an open wireless network and you'd like to figure out certain Macs which are actually going ahead and sending data in plain text. So, the first thing is, hey, who's actually sending data? Figure out that. You can rip those packets out and then you can run other tools on them. So, this is again extremely easy to do with this tool. There you go. We can actually find the average packet length. So, many of these are like micro statistics as you can see here. So, the average length of all the packets, we have around 400,000 packets in 01.db. Okay, that's the total number of packets in there. So, the average packet length is 106 bytes. You could do things like find the inter-packet delta. Right? So, this is the packet delta between successive packets. Now, let's actually get some more interesting information. We saw how to get all the Mac addresses. What if we can just get a unique list of SSIDs and Mac addresses in a given PCAP. Right? That would be interesting. So, it's almost like writing your own arrow dump in G. And with live mode, you can actually run these queries live to actually find out what's in the air. So, I'm going to copy this. And there you go. Some of these are hidden SSID networks. So, the broadcast or SSID is actually null. There isn't anything in there. So, we can actually find a unique list of SSIDs and Mac addresses with just a simple query. Now, at this point, of course, we are joining multiple tables because we've tried to partition the tables in such a way that the queries can be optimized. So, we've looked at how we can run fast queries on, let's say, 2-3 million packets. And going ahead and creating an efficient schema is very important. Now, if we wanted to find all the hidden SSID networks around. Let's copy this out. And these are all the access points which are sending out hidden SSID networks. Right? It's a very simple where length SSID equals 0. That's it. You can actually run it on an entire column. And most of these macros are already available with SQLiteDB. I mean, I'm not using any of my own custom, you know, additional extensions or anything like that. This is the default SQLiteDB. Now, a lot of times when I do wireless pen tests, I'd like to know all SSIDs on a given channel. So, you can actually go in here. So, on channel 6, we basically have all of these access points and the SSIDs. The way we pick this up is in the beacon frame, you have something called a DS parameter, which actually specifies the channel on which the AP is. Now, attacking clients most of the times when you want to attack a client, you actually want to know the unique list of probed SSIDs, right? These are SSIDs for which the client is sending out probe requests. And then you can create a honeypot with the same SSID and the client connects to it. You know, you have tools like Karma or Karma you can use the Wi-Fi pineapple bunch of them out there. So, if we wanted to find all the probe SSIDs in the PCAP, all we have to do is run this query on the SQLite DB. Now, every single MAC also sends out null probe requests. Keep that in mind, right? So, there you go. Null probes along with whatever they are querying for. If you were interested in just one MAC address, you can optimize the query further and monitor a single MAC. And all of these things would actually take you tens of minutes, sometimes even hours to figure out with Wireshark. And there you go. This MAC address is actually querying for these set of SSIDs. Now, one of the reasons we have kept it SQLite is simply because as you can clearly see you can probably write your own scripts around this. So, if you like Python or Ruby or almost any language which can support SQLite, which almost all of them do, then you could make these queries and get meaningful information out. Now, let's actually make it even more interesting. Let's write our own arrow dump in G, kind of, right? Thomas' arrow dump of course is way more you know, interesting and sophisticated. So, what we have done is when we parse the packets, we also automatically pick up things like the encryption and all of that. Right? What are we using? Is this CCMP? Is the access point supporting both WPA, WPA2? And we push all of that into a macro statistics table. This is just so that you don't have to go through the pains of figuring out the right information element, what it looks like, how do you parse the TLV, right? To finally figure out the encryption and RSN information. Now, of course this requires a little bit more SQL magic. We are joining multiple tables. So, let me take this and there you go. Now, for some columns you may see CCMP, TK both. These are APs which are actually running in mixed mode. They advertise both possibilities. It's all picked up from the beacons. So, this basically can kind of go on. In the sense you can pick up any property of the access point. You can have the channels listed. You could have the data rates listed. Anything which is already there in the beacon can be comfortably done. You could extend the macro statistics part as well. Now, this entire tool is actually written in C++. The SQLiteDB, of course, once you want to go and do something in there, you can use any scripting framework. Now, when you want to do any form of attack tool fingerprinting, it's important to be able to look at all the IEs which are being sent. So, again, for a given network, this is actually quite easy. So, this is basically the list of all the different information elements. If you can have a go here. Now, most information elements are actually just simple data structures, right? Unfortunately, they aren't human readable. So, we've kind of encoded them in Base64 and put it inside the database. In the beginning, we were actually putting them in their raw binary form. But then that makes it quite difficult if you're writing a script which is doing some kind of fingerprinting because then you would have to do something similar. So, it's all Base64 encoded in there. Now, you can find client information elements as well. It's actually quite easy. It's very similar. Now, all of these IEs can be used to fingerprint clients and do interesting stuff if you so desire. Now, this one is just to look at what times exactly is a device actually sending something out, right? How active is a device over the air? So, these are different instances where the device was actually active using an absolute timestamp which is available in the packet header field which Wireshark creates for you. Or rather, whichever capturing program has actually put it in. Now, this is the first part where you can clearly see that once you go ahead and put everything inside a SQLite database, then you can actually run your own arbitrary queries. These are just a few I could think of. I mean, you're just limited by your creativity and how much SQL you know. So, I'm going to talk about one very interesting attack and how we could probably detect that writing a script to go ahead and use it. Let's use all of this data. Now, how do we detect AP max spoofing or max spoofing of any kind on a wireless interface? So, when we create a fake access point, fake AP 101 is actually you just creating the same SSID. It ends up having different BSSIDs, right? Which is what is the default option for airbase. But what if the attacker creates an access point with the exact same BSSID as your MAC address? How do you detect that fake AP is around? What if there are 10 of them around? Anyone? Actually, I did a DEF CON talk yesterday and I gave the answer there. So, this is kind of good because if everyone is new then this part is going to be a repetition. Okay, whoever can try you can actually win a book. How would that work? Okay. Okay, great. Were you for my talk yesterday? Okay. Here you go. Yep. I'm just leaving it here and you can collect it at the end of the talk. Thanks. Okay. So, what other parameters can we use to go ahead and detect things like max spoofing let's say in an enterprise environment? So, let's say we have a rogue device and we've connected that rogue access point to your enterprise, right? It's a very common case. What else can we use apart from sequence numbers to detect things like MAC address spoofing? Anyone? That's because you already knew I have another book as well, so . Actually, I have three of them. Anything else? I mean, yeah. . What exactly in the beacon frames? Okay. One good answer is the beacon frames would differ because most attack tools don't create the exact same beacon frame, right? So, yep. Here goes second book. What else can we use? Anything else? So, now let's assume the attacker is creating a fake AP which is identical. He even clones the beacon frame. No attack tool does that right now. You could probably hack that up with Skp, but none of the attack tools do that. They don't have like a beacon frame replication mode. So, the MAC address is the same. The beacon frame looks identical apart from the sequence number. Is there anything else we could use in an enterprise environment? I've kind of limited the scope. The MAC address is the same. Yeah. If the MAC address is identical, most of your analytics tool will just pick up the first three octets and decide that. I mean, we can't see any of the APs that we can kind of, you know, turn them and actually look at the manufacturer name. Little bit more. Yeah, go ahead. I mean, you're close, but... The beacon interval timing can be cloned, right? I mean, you can just monitor an AP and most of them actually have it fixed values. Manufacturers set that to fixed values. Nobody ever changes it. So, this is an attacker who's actually monitoring the air and is creating his fake AP. And I've kind of limited the scope. This is an enterprise environment. I mean, maybe the fake AP is somewhere in this entire floor and this is an enterprise office, right? How do wireless intrusion detection systems do it today? Okay. Okay, very good. Very good. So, signal strength is something we can use as well, provided you have sensors around, right? So, here is a book as well. Great. So, a bunch of metrics which actually can be used. The sequence number itself is actually quite powerful. Now, let me show you how this looks like. . . . So, this is a PCAP file in which I have a TP-link based access point which is sending out beacon frames. And after some time, though you could have started the fake AP right now itself, we've also started a fake access point with the same MAC address. In this case, the beacons are differing, but let's not worry about the beacons, right? Let's use beacons to fingerprint two different devices. Let's use sequence numbers. So, if you can now scroll down, always keep looking at this value here, SN. Okay? SN stands for sequence numbers. In wireless, all devices are supposed to increment their sequence number by one for every frame they send. Once they hit the maximum, they just go ahead and, you know, start from one again. So, here is one device which is sending out sequence frames. Kind of increasing. Okay. Do you notice something interesting now? So, now what you actually see is, there seem to be two different sequences. Now, you might argue, what happens if an attacker copies that, right? It's extremely difficult to do it, but if he does it, there are going to be collisions in a very small space, right? So, let's say the real AP sent out a sequence number 100. The attacker sniffs that, sends the next frame 100. But by then, 100 is already in the air. We have it. So, there's probably going to be 100 after that. If the real AP is transmitting at a fast rate, you'd actually find 100 to 110 being sent out, and then the attacker is trailing behind. Right? Regardless, till the time there are multiple frames in the air with the same sequence number, that's something which is extremely fishy. Intrusion detection systems combine that with the RSSI value to actually say, hey, this isn't a coincidence. These are actually two separate devices because three of my sensors are picking up completely different RSSI values. Now, who gives you the RSSI values? Well, depending on the sensor box, it's basically going to be the hardware driver. So, if we actually look at these values, and go down here, that is the signal strength. Now, keep in mind, just one node monitoring signal strength is not a good metric at all. Right? Wi-Fi has what we call multi-path fading. So, this environment is continuously changing. At the same location, you can have local maximas and minimas, depending on how the waves are interfering and go out of phase based on the environment. So, network IDSs, just like a GPS system, require at least three sensors to be able to triangulate a device on a given floor plan. And if you can think about a newer way of doing it, most of those are multi-million dollar patents because of which companies in this space actually get acquired. That's probably the only metric used. So, now, how can we use PCAP to XML with a little bit of visualization to actually pick this up for any given MAC address? So, here is what I did. This is an illustration of using PCAP to XML. So, let me run the tool and I'll show you how it looks like. Now, I've given it a MAC address. You can automate that to pick up all MACs in a given PCAP and actually run it for each of them, right? So, this is just an illustration. Let me go back and open up spoof.png. . . . . Let me actually copy this out somewhere. Does anyone remember any GUI program that I used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . All of this code is available. It's going to be on GitHub, so feel free to use it. . . . . Anyone here use Python? Couple of guys? Okay. So, internally, we actually just use Python for a couple of things and other visualization. We actually even use Pandas in case you've used it. It's quite good to be using that. So, what we basically do is we initialize the database and we've written all of that wrapper code for you. So, you don't have to worry with like how do we initialize it, what is the SQLite driver, even though most of that stuff is actually quite boilerplate and simple. We go through a list of sequence numbers, pick them up, and after that, we just do a quick check about whether sequence numbers are going ahead and going back in time or going forward in time at any given point. Right? And after that, you can just plot all of them. The script goes ahead and figures that out and just gives you a very simple attack or deny. . Just when we ran it here. . Let's go. . . So, it'll just tell you MAC address detected, spoofing detected or not. The visualization makes it clear what was the actual logic of doing it. . . . So, all of this stuff we've already looked at. I'm going to go down below. . . . You could do a ton of other things with it. I have some sample scripts which you can take a look later. Detection based on signatures. So, you can actually detect Airbase NG. I don't know if any of you got time to catch my talk on Chellam, which I gave two days back. Right? So, Chellam actually goes ahead and fingerprints Airbase NG and a couple of other tools. The technique is very, very similar. . Replay attacks, again very easy to detect. . So, you could actually go ahead look at a frame and create some kind of a hash for it and then check if any frame which matches the exact same hash. Unauthorized devices and associations is actually quite easy as well. Have a list of APs and authorized clients and check if any other data packet or any other packet is going between any client AP pair not on the list. The more difficult part of course is MAC spoofing, which is what we can have showed right now. So, any questions? Yeah. . Okay. Good question. So, SQLite right now is the only one, but the schema itself is so flexible you could port it to MySQL and anything else as well. The only reason we chose SQLite is I actually want this to run on embedded platforms. I'm already testing a couple on Android and some home based routers as well to see if your phone can intelligently go ahead and detect many of these things. So, imagine that you have your Android device and it can scan the air with a list of authorized MAC addresses and check for things like this. It's an experimental feature right now. Probably in the next one month it's going to be stable. So, PCAP XML when you run it, you'll actually see we have sniffing options in there. Now, the most difficult part to get right to create something very stable when you do things like live capture is the packet parsing code. Now, the packet parsing code sometimes can be a little buggy because when we started off looking at some of the more uncommon frames, we had to go and actually see the 802.11 spec to understand how to parse it. So, I expect some parsing bugs to be there which you would like to iron out and that is something in live mode is difficult to figure out at times but the feature is already there. You could try it. I think in a month's time it might be more stable. It's actually all of our own parsers. We have a POSIX one as well and that has a different build available to it. So, this is the main directory. This is all the packet parsing which is happening. So, pretty much we are like looking at every single frame and doing it. So, this does not use any other actually there isn't a very elaborate library apart from the Wireshark platform itself. The problem with that is we actually felt it's easy to make this stand alone so that we can port it easier on much other platforms rather than just becoming a Wireshark dissector. You can write a dissector which can do a lot of this stuff. When we started doing a lot of aggregate statistics, either I probably got it wrong or definitely it was slowing down Wireshark quite a lot. So, I wanted this to be out outside of it. It's all actually complete C++ code which is looking at parsing stuff. We've kind of documented the whole thing. We had a team of three people. It's me, Julian and Ashish who was responsible for testing it. Both of those guys started coding it. In the beginning when I started, I probably thought this was quite easy to get done but almost took us four months of part time along with building Chellam and a couple of other things which I demoed this year. For sniffing we actually use PCAP for live sniffing. Yeah. We wanted to use the raw socket stuff to begin with but that wasn't very portable for at least some platforms. So, we defaulted to using PCAP and of course to parse a PCAP or to basically get PCAP files out using the PCAP library is the best option. Right? So, it's complete C++ code. Yeah. . . . . the only place we can actually use the beacon time stamps and a couple of things inside is if you want to detect something like clock skews. The problem really is that sometimes not know at what time which devices may be around. I mean based on what you are saying right now it's actually quite difficult to get that amount of prior information. However, kind of building upon what you said, there is one technique where you can actually detect clock skews. So, when there are multiple devices and you start looking at the time stamps which are there inside the beacon frame. There are a bunch of them as well. You may be able to detect a clock skew when multiple devices have the same max. There are actually a lot of papers on that as well. I haven't implemented it in this right now but I am planning. Clock skews I wasn't very happy with the initial results. It wasn't good enough to demo. Or maybe it was just my bad code so I still have to work on it because there seem to be a lot of papers on it so I am assuming it probably works for sure at least theoretically. The papers were all academic so they had they could actually run it through MATLAB and do simulations. But when you work with real traffic you know some of those academic stuff is kind of difficult to get right. So yeah, clock skews is something I do plan to use eventually. Questions? You could also actually write this in Python. What I found is when you actually go about file sizes of over 2 gigs it takes a very long time if you want to parse every single field. So given I used to actually program in CC++ for a very long time I thought this is something which comes naturally to me so that's why I chose this. But yes you could have used Python if you wanted to or any language. Around 3 gigs. 3 to 4 gigs actually. That's simply because the SQLite database will have a lot of meta information associated with it. We also have multiple indexes which we build. Right? So you are only limited by the RAM on the machine where you analyze it. Not right now but we actually might eventually. I think there were a couple of projects which I found for the wired side. Though not everyone was trying to map every single bit field so that your queries can be as flexible as you like. But I think if many people use it, we'll build it. Yeah we first want to be sure that we can build something very stable for WiFi. I mean this is still early alpha software at least in my view. Probably we'll go through at least a year of iteration before it is extremely stable you know that you can actually be very sure about it. Questions? Okay. Thank you very much. Hope you enjoyed the talk.