Thanks for coming to my talk. I'm going to talk to you today about NFC and why, besides my body odor, you shouldn't stand too close to me. Okay, so who am I? So first one to hack iPhone and G1 phone. I won this snazzy jacket. I wrote some books. Got some letters I can put after my name sometimes if I feel like it. And I'm still, even after yesterday's talk by Apple, not a member of the iOS developer program. So today what's on the agenda? So first I'll tell you why I did this project. Then I'll go through some basic stuff about NFC so that we all know what I'm talking about and can see what NFC is all about. And then the main part of the talk is basically how to fuzz NFC, NFC stacks on phones. And then I'll look beyond that at sort of applications that deal with NFC. And finally I'll have some, like, you know, some tips and tricks on how to fuzz NFC. Demos and if there are anything like my projector that will fail horribly. But I have backup videos because I've had too many talks totally bombed. So hopefully the videos at least will work. Okay. So why NFC? So I started looking at this, like, nine months ago. And I was actually having lunch with Moxie Marlin Spike and he told me that the code in the Linux kernel looked really weak. And I was like, oh, okay, weak code. I like that. And NFC is, like, you know, sort of mobile phone related and I like phones. And I was like, oh, okay, weak code. I like that. And NFC is, like, you know, you don't have to, like, make the person touch anything. I like that. So there's a lot of things that were kind of appealing. And while there's not that many phones right now that have NFC, like, you know, supposedly if you believe Johnny Evans, in the future there's going to be more. So, you know, maybe the next iPhone would have NFC. Who knows? I hope the last one would have it and it didn't. So all Nokia phones supposedly from now on are going to have NFC in them. The new Samsung phones have it. I don't know if they're going to have NFC. I don't know. And then the Windows Phone 8s are supposed to have it when they come out. So anyway, so in theory NFC is going to be something that everyone is going to have in a couple years. So it's, like, you know, pertinent to look at it now, I think. And the thing I found out is it's actually really hard to test NFC. So all these things are sort of the reasons I did it. So I wanted to, you know, finding bugs is cool and really, like, that's what the end of the talk is about. It's, like, wow, cool. Check it out. I pop all these things in there. So I wanted to, you know, figure out how to make sure I was getting all of these boxes and stuff. But, really, what this is about was giving away that, you know, people could test NFC implementation. So I have a bunch of code. You can download it and, you know, test the NFC on your phone or on the next phone that comes out and stuff. And what I'm really concerned about is, like, getting owned through NFC. So I don't really care about, you know, Google Wallet and credit card information or I shouldn't say I don't care, but I didn't look at that. So what I was concerned about is, like, can someone, you know, use this new chip and you can actually use it if they don't want to use it. shipping my phone to get a shell on my phone and steal all my contacts and all my naked photos and stuff. So here's some, if you're interested, some other guys have done some really cool research on NFC related things like getting free gym memberships or snacks from vending machines and other really cool stuff. But that's not what my talk is about. So check out those references if you're interested. As far as other people who have looked at this idea of can you use NFC as a way to attack a phone. Colin Molnar a few years ago looked into fuzzing NFC a little bit but he didn't have a way to automate it so it was more like write a tag, put the tag by the phone, it didn't crash. Write a tag, put the tag by the phone, it didn't crash. So he gave up after a couple of hours. So a couple of these academic guys looked at the Nokia 6212 to see if they could find attacks against it and they did. And the attacks they found are kind of similar to what I'll talk about and the Nokia phone I looked at. And for the finally, Dan Rosenberg found some bugs in the Linux kernel stack. I think that this is what Moxie was looking at. But it turns out that this code is for hardware that doesn't really exist yet. So these are bugs in the NFC stack but no one's using it yet. But it still just shows that bugs can exist in the NFC stack. And at least one of those bugs is like really easy to exploit stack overflow with no canaries and stuff. It's really sweet. So he shouldn't have told anyone until the chip came out. All right. So what's NFC all about? Well, it's a basically based on RFID and it runs at 13.56 megahertz at least initially. And then the range for it is like four centimeters. So this is like, you know, the actual papers and stuff will say ten centimeters but I've never actually seen that. So in real life it's more like four centimeters, something like that. And, you know, there's people who talk about building like big old antennas and going across the room and stuff. But for me, it's just, you know, you just need to know that you have to be like really close but you don't have to touch. That's basically what it means. All right. All right. All right. All right. I have a very naughty thing to say just there but I'm not going to say it. Okay. So sorry. I'm really trying to be good. So the data rates for NFC is like quite slow. So you don't want to transfer like a bunch of data with it. And it's not really designed to do that. Okay. So how close do you really have to be? So here's like a couple little experiments just to give you an idea. So let me pause this one. So on the right there's a hotel key, NFC card, and a wallet and a pocket and you can read it. By like getting it in your pocket and getting close to the pocket. On this one, it's just like a NFC tag and a phone. And so you can see it's basically, you know, more than a thumb's width to read the tag. So that's how close you have to be. But then if you want to actually do something in real life, I thought I'd do a little experiment. So this is my coworker, Todd Manning, who I understand. He didn't know this was coming until Black Hat, he was sitting in the audience and all of a sudden he saw his ass on the screen. But so here's a little video of me trying to read his hotel card key without him knowing. So I'm in the green shirt. He's in the checkered shirt. You can hear our idle chatter. There it is. I'm so subtle. But I must admit that I was trained by the NSA. So a normal person might not be able to pull this off. So anyway, you can't see this, but I looked and it didn't show up. I was like, what the hell? So I was like, well, I'll do it while he's moving. So this is a moving circuit. It's a little harder. I'm looking, like, damn it's not working. So I'm like, I'm just going to sit on his ass at this point. So that's the video. Thanks. So I was like, I can't believe this didn't work. This totally should have worked. What was the deal? I followed him back to his room, and he goes to get into his hotel room, and he pulls the key out of his front pocket. So I was like, oh, okay. So anyway, that's one version of the, you know, what my opponent likes to do. So I'm like, tell me, bugs I'm going to talk about you can do is follow around uncomfortably next to somebody. Sort of a more realistic attack is equivalent to ATM card skimmers or something where there would be an MC pay terminal or movie poster or something and you would stick a tag on the side or you would replace the terminal with a fake one or whatever. Tags are pretty little. They're just stickers sometimes. Sometimes they're like plastic cards or whatever. So you can imagine putting it in a situation where, you know, someone wants to use NFC. So that would be a way easier attack than what I tried to do. Speaking of that, when is NFC on? It doesn't do any good if it's not on. It is on when your phone is awake. Like this phone went to sleep and NFC is off. And for newer versions of mobile operating systems, if you have a pass code it also is to be unlocked. The SDK has an MFüğür дис씨 Put biases or even the ice cream sandwich it's only on when it's unlocked and gingerbread it's on no matter what if the device is on. And for the Nokia phone I look at the low level stack is accessible if it's not, if it's locked. But the high level apps don't behave right unless it's unlocked. So basically the easy scenario is if the person is like talking on the phone or using the phone or has just finished using the phone and it's unlocked then you can do the things I'm going to talk about. And then the other thing is as long as they don't have a passcode on their phone you can actually wake up the phone and then turn NFC on and then use NFC. So here's a little movie of this. So here's a Nokia N9 and the tag NFC reader isn't working because it's asleep. The phone is asleep. But this is my friend. The phone is in his pocket or something. So I sent him a text message and that wakes up the phone and then I just run up and give him a swat and then the NFC is working. So it would have been a two-step process against my friend Todd Manning. I would have had to send him a text message while I was like in the elevator with him. Okay. So that's basically how NFC, when NFC is available, how you, you know, a couple ways you can imagine trying to attack someone with an NFC phone. So now let's talk about NFC. So it's basically two modes to NFC. One is passive. So this is, you know, this scenario where you've got, you know, a phone, an active reading device and you've got an attack device. And then you've got an active reading tag. And tags are just like, I said, little stickers or something. So, you know, you just put it up there and then something happens. Right? So that's, that's passive. In that case, the tags don't have a battery or power or anything. They just use the power provided by the initiator. So and the other mode is peer-to-peer. So if you have two phones and you want to, like, share data between them, you just kind of get them close and NFC will let you share files that way. And the way that that works is, you know, if you have two phones and the way that that works is, both of them are powered devices. So it's a little different. And they have different protocols and stuff. So when I sat down to fuzz this, you know, this stack, I was like, okay, there's like 200 bytes on this card and I want to fuzz this. So it's probably not that complicated. And then I was like, I got this diagram and I was like, oh, shit, it's, like, super complicated. So there's lots and lots of specs and, you know, you have to sit down and read them all. And I'll just run through them real quick. So at the very lowest level, you've got, like, you know, radio waves and stuff. So here, this is the spec you would want. And this is, if you can kind of see it, so this is just a FFT plot I got from using a software-defined radio. And then if you want to, you can actually see the radio waves and decode them into bits. And it's a real pain in the ass, but it's possible. So here's an example of one. Every time it crosses the line, you get a zero. Otherwise, you get ones. I did it bigger here so you can see. And then there's some sort of decoding scheme where, like, you get a zero. And then you get a one. And then you get a two. You get a one if there's two ones unless it's followed by one, in which case it's zero one. Anyway, so all these basic rules that allow you to convert this line crossing into actual bits. And then you can see that this waveform actually is sending hex 26. And hex 26, if you read the spec, is the sends rec command, which is basically, like, the wake up. Like, NFC, here I am, wake up. Okay. So that was the, like, super low level, where the radio transmissions look like. I didn't fuzz at that level because, you know, I was super hard. And I'm lazy. Okay. So the next thing is initialization, anti-collision, stuff like that. So whenever a device enters or, like, say a tag enters the phone's, you know, RF range, then they start to have to, you know, work out some initial stuff. And that's what this layer is. There's almost no data exchanged. So I didn't fuzz this, although I could have. And then I'll show you an example of this and you'll see what these bytes look like. Okay. And then sort of a more interesting layer is when you get a little higher. So then you get into, there's lots and lots of different kinds of tags. And each one speaks a slightly different protocol. And then at the bottom there's this LCP and that's the communications for peer to peer communication. So I'll just show you some details on a couple of those because these are the ones I actually fuzzed. So one is called type 2 tags, also known as my fair ultralight. The actual commands that the device can send, you know, it can send a message into the tag or things like read, write, stuff like that. And the stuff that the tag can send back is things like this. So first there's some metadata. It has things like serial numbers. And then there's this capability container and that contains information like version number, how much data to expect, stuff like that. And then there's the actual data itself. And then another type of tag is a type 4 tag called . So this one's a little different. Here it's like a little virtual file system. And you can, they're kind of commands that the device can send are like select, read and update. And so the important thing is just to know that there's this capability container file and then there's a file or files that contain the actual data that you want to send. So the way that it typically works is the phone will be like, okay, I want to read you. So then it selects the capability container file. Then it reads the capability container file. And that tells it where to find the data. So then it selects the data file and then it reads the data. So that's the back and forth communication between the device and the phone and the tag. And then finally, if you have two peer devices want to talk to each other, they send each other these things called PDUs. There's lots of different kinds of PDUs and, you know, this is more or less what they look like. So if you want to see an example exchange of, you know, say I want to share like the greatest, coolest, you know, video of, with you, I would send this connect PDU with some parameters and like what service I want to connect to. Then I would, you would respond with a connection complete, a CC PDU. Then I'd send you an I PDU. I stands for information. You'd either send me back another information or an RR, which is just like an acknowledgement. And we just go back and forth sending data back until one of us is done and sends a disconnect. All right. And then unlike the tags, the LCP is more like a connection and then you have to say where you want to connect to. So there's different kinds of service end death that you can connect to. And all the like stuff I looked at, I only saw two. One was called MPP. And that was, I saw on the Android phones. And then another is Snap, which you see on like other phones, like Okias and stuff. All right. So all that's left is, you know, so far it's just how to communicate data back and forth, but I haven't talked about the actual data. So the actual data is called, is stored, it can be anything, but it's normally stored in a format called end death. So this is just some binary data and it describes different things that it can contain. It can contain lots of different kinds of data. And I talked about it, I gave this talk in Black Hat, except that talk was like a lot more expensive than this talk. So you guys are really getting your money's worth. So the Black Hat badges had MSC and you could read the end death data and stuff off them. But anyway, so end death is just the format of the data that is typically exchanged. So we're going to talk a little bit about the data. So, you know, I sit down and I read specs for, you know, three months and I'm about to blow my brains out. So I finally get an antenna and I actually look at the data and I, you know, because I want to use something like Wireshark, but they don't have it. So instead I look at this. So I get a Proxmark, you can sniff the traffic and see what it looks like. So this is what the traffic looks like between an MSC reader and a type 2 My Fair Ultralight card. So I don't know if you can read it, but I'll just explain it anyway. So the first reader is like, hey, wake up. And then the card says, okay, I have a seven byte serial number. And then the reader says, cool, give it to me. And the reader says, okay, here's the first three bytes. And then the reader is like, okay, I got those three bytes. Are they these? And he's like, yep. And then he says, okay, send me more. And he says, okay, here's the rest. And he says, were they these? And he says, yep. So, you know, anyway, and the other thing that happens is at some point the tag said, by the way, I'm a type 2 tag. So once they get to this point, they've done the initialization and they're ready to actually do the data and they know to use the type 2 protocol. So he knows he can do reads. So he reads column 8 from that chart I showed you. The tag responds with a bunch of data. And then he reads the third one, which is that capability container stuff. So he reads the card sends, the tag sends this data. And then he reads the actual data. So anyway, you can start thinking about what you want to fuzz. So you could fuzz like the serial number and stuff. But I didn't because it seemed like a waste. You can start to fuzz, you know, like the serial numbers and the memory stuff. And then down here you can fuzz the data. So there's stuff to fuzz, but not a ton. And then I, if you look at that last slide, I pulled out the actual data. And you can break that data out, too, and see what it looks like. So in this example, it starts with the three that just says, hey, it's actually, you know, I'm going to end up. And then it says a link. So end up is basically type link value. So it's linked and then it says, like, okay, I'm a D1, which says I'm a message begin, message end, which means I'm just a complete message. Short record, which means my links are one byte as opposed to four. And then, like, I'm a well-known type. And then it's, like, type link, payload link, type, blah, blah, blah, blah. And then, you know, type, and then, so once you know that the type is T for text, then you look at that spec and see how text data looks like. And eventually you break it out to some text and then you're done. So you can extract this data and you can imagine, like, fuzzing these things and there's some link values. And so there's some potential for some coolness. But then you got to, you know, so at this point, you know, I read the specs. I understood NFC. Like, you know, everyone in this room now, so, you know, we're all NFC experts. And how, you know, where are the bugs going to be? So if you look at, say, the software stack on an Android phone, it looks something like this for NFC. So you've got the kernel. There's some drivers. You've got, you know, you've got, you know, the driver and the kernel that is, you know, talking to the hardware, you know, the actual NFC chip. And then there's an Android service that deals with all the NFC data. And then there's applications that consume the data afterwards. So in this picture, the driver's native code. Inside the service there's some native code libraries. But mostly the service is written in Java. And likewise, this tags application that handles the end up data is written in Java. So you can use that. So if you're looking for memory corruption bugs, like you're kind of limited, right, to just these native code dudes. The Mego, which is the other phone I looked at, Nokia 9 running Mego, which was the reason I chose these two phones, by the way, is, like, last fall they were more or less the only phones I could get my hand on that had NFC. And then the Mego had the advantage of being kind of Linux-y, which is something that I like. Turns out, at least in the U.S., there's not many people with Nokia N9s. But there's a few people. Like, I saw a trend in the U.S. where they were like, oh, Travis Goodspeed has one the other night. So I'm going to totally own his ass. And then I heard H.C. Moore might have one, too. So I want to see those guys on the phone. I'm going to be, like, all over them. Okay. So the Mego stack basically looks like the Android stack. The biggest difference, so, you know, there's kernel, driver, service, and then applications that consume the data. The difference is here everything is native code. So it seems there's at least a potential for some more bugs. All right. All right. So I already kind of mentioned this, but, you know, so when you sit back and say, okay, where are the bugs? Well, there could be bugs in the actual MFC-specific code, like the thing that's parsing NDEFs or parsing capability containers or something. Or there could be bugs in the applications, like tags, that are actually processing the data afterwards. We want to look for bugs in both those spots. So the first thing I want to do is fuzz the low-level stuff. Because that's like, you know, it's the whole, you know, when you're hammer, everything looks like a nail. So I want to look for bugs and I do fuzzing and so everything I want to do starts with fuzzing. So fuzzing on MFC is a little hard. It took me like six months to get this fuzzer running. So the first thing you do is you create data and then you want to present it to the phone and then you want to monitor the phone for, you know, crashes and stuff. So the test case generation is really pretty simple. I use two approaches. The first one was, you know, what they call dumb fuzzing, mutation-based fuzzing. So I just got some valid data and did some bit flipping, added some bits, stuff like that. So, you know, valid data for, like, these are, like, PDUs, these are capability containers, these are NDEFs. So, you know, just got a bunch of data and then started flipping it. And then I also, at least for the NDEFs, used Soli to create some fuzzed NDEFs, you know, so that you could have, like, very long strings but everything else is right. Like, you know, the links are right and stuff like that. So I tried both approaches. And, you know, I generated, like, something like 50,000 test cases for each of the phones. So then the question, that part was easy. The hard part is, like, getting the test cases to the phone. So, like, NFC is basically designed to be, like, some dude has a phone, he puts it near some other phone and then he takes the phone away, right? But I want to just, like, leave it running overnight. And I only have, you know, there's only so many interns who will just do this all day. So, like I mentioned before, Colin Molnar originally did this by hand and then realized that that was kind of silly. So I had to figure out a way to automate this. So the first thing I thought is I'll just get some off-the-shelf NFC readers and have them. There's a mode called card emulation, which means, like, pretend to be a card, a tag. And then if you go to read it, you know, the phone doesn't make any difference. But the problem is there's, like, tons of different kinds of NFC hardware. They all kind of claim, you know, in some vague way that they're not going to be able to do card emulation. But then when you buy it, they don't. And, you know, the help support dudes are, like, oh, yeah, we didn't actually do that. We can sort of do that. And then there's lots of different software that you can try for each of the pieces of hardware. So for a long time I couldn't get any of them to actually do card emulation. So then the next approach I looked at was using a USRP. So here you can do everything, you know, from the very beginning to the very end. And then you can do everything from the very bottom up. You can pretend to do the radio signals and be a card or be a peer and do everything. And the advantage is you can fuzz everything, too. And then I started writing code. And, you know, there's getting these waveforms and decoding waveforms and having to send out more waves. And, yeah, it wasn't working very well. So I'm not a signal analyst apparently. And the best I could get was I could decode this way, but it took, like, six seconds. And it turns out that you have to respond in like .0001 seconds so I was too slow. So I gave up on that. And then Kyle Molnar at summer con this year released an Android injection framework that would theoretically allow you to inject data into the NFC demon so it would think that you had just presented a tag. But I don't think anyone has ever used that to fuzz yet and also it turns out the bugs I'm going to tell you about, a lot of them are related to timing issues and so you won't get those either. So there's some reasons you wouldn't want to do this. But it's at least a possibility. So finally I found after I did all that stuff and gave up, I eventually went back and actually found some hardware that worked. So you get this reader and use that software or this reader and that software, you're in business. So you can plug those in and they'll pretend to be cards and you can read them. So now with those combinations of hardware and software I can fuzz the parts of the spec that are this like ugly green. So it's like roughly half or something. So there's still lots of work that you guys can do if you want. This is what I did. So let's start talking about how I did it. So the top level fuzzing NDEFs was pretty easy. So I already had a bunch of fuzzed NDEFs. I just had to get them to the phone. And lib NFC comes with a little program that basically does exactly that. It takes in a binary file and presents that as an NDEF to the phone. So that part was easy. Then if I wanted to fuzz this part, the purple part, then I want to fuzz the sort of low level type 2 transactions. So what I did there is I just made some modifications to lib NFC to allow me to modify these bytes that weren't the metadata bytes of things like capability container. So it just changed up that program and then it was working pretty good. Pretty much the same thing for type 4 fuzzing. So if I wanted to do the low level stuff, all I did was instead of fuzzing the NDEF data, which is what lib NFC wants me to do, I just changed lib NFC to instead allow me to supply a capability container file. And then finally fuzzing LLCP, so the peer-to-peer communication. I just again modified this time NFC-py to allow me to change the connecting information previews. So that was cool. So what I could do at that point was I could emulate a tag, I could put the phone down and it would read the tag. And those tags could have like crazy mess up fields. But then I need to like do that a lot, right? And again, my interns started quitting after a couple hours. So I had to figure out a way to automate that. And so basically what I would do is I would just turn off NFC, I would change the tag to be something new, and then I would turn on NFC and that would be sort of the equivalent of presenting the tag. And then I would, once that was done, then I would turn off NFC, change the tag, turn on NFC, so forth. And then I would do that again. There's a couple ways here that you can turn off or turn on NFC. Hey, you're leaving my talk? The demos are still coming. The cool part is at the end, this is the painful part where you learn to appreciate the hard work I did before the whiz bang demos. All right. Thanks. All right, so he's going to leave and be like, man, that talk was so boring. It was just all about specs and shit. So all right, anyway, so then I needed a way that it turns out NFC readers aren't designed to emulate 10,000 tags in a day. So after a little bit, they just freeze up. And the support people say the way you fix it is you just unplug it and plug it back in and everything's great, hard reset. I was like, well, I don't know if that's actually better than doing this with the phone if I'm doing this with the USB. So I got this, I found this USB hub that I could control the power on and software I could turn the power off and then back on. And so it was kind of like plugging it and unplugging it. And you also notice, like, a lot of people come up to me and be like, Charlie, like, how do you find time to do all this research? And I say, well, I totally, I don't do any household chores at all. And so you can see, like, total water damage in my wall. It's like, eh, I'll just set up my fuzzer right next to it. All right, so the final part of the puzzle is looking for crashes. And Android, it's super easy. They have logcat, which basically tells you any time anything crashes. And on Amigo, no one's really ever looked at that operating system. So it turns out they have GDB, though, so I was kind of attached to the server or the service. And then in case other things crashed, I just did basically a PS before and after sending the NDEF and looked to see if anything significant had changed. And then finally, like, I wanted to make sure NFC was still working. So between every fuzz test case, I would send a valid test case, a valid, you know, NDEF file or something. And then I would just make sure that that worked. And if not, I would kind of restart everything. So in Android, tags puts things in a SQLite database. You can just check to make sure the thing you just sent shows up there. And in Amigo, if you start the NFC daemon with this extra, you know, verbosity setting, it actually shows you the NDEFs that it's reading and syslogs. You can look to make sure everything's working great. All right, so here is, like, super boring videos, but it took me six months to make, so you're going to watch it. So here's the Nokia N9. So this is, like, the valid test case. This is the invalid test case. It can't read it. And this is the valid test case. I would send it, like, a RAM number. And this is the invalid test case. And here is a Nexus S. Go. Go Nexus S. There we go. So I don't even turn it up. Oh, there it is. Beauty. So this one is a valid test case, and then there's an invalid test case that doesn't even show up. And then there is another valid test case. So if you lived in my house, you would just hear, like, in the background all day, all night, wink, wink, wink. So it's pretty annoying, but, you know, that's what I do for Sunday. So I'm going to show you how to do it. And then the other thing that happened in my house is that one stupid reader, the big one, in some weird situations, it would just start, like, making this huge loud noise. Like that loud. And I was like, well, this isn't ideal. So at first I tried to put a pillow on it, and you can still hear it. So that's why I moved eventually to my basement that's all flooded up. So finally I did the actual fuzzing. So like I said, it was, like, 50,000 test cases. I fuzzed against the latest OS that was available at the time. Last fall, which was 233 for gingerbread and 1.2 for the Nokia's. And as you saw in the video, each test case would take around, you know, five or ten seconds. So it was a very, very slow process. So as soon as you start fuzzing, you'll basically start to see things crashing and stuff. So the first thing that you'll see crash is tags. Tags, like, crash is super easy. But the problem is it's written in Java, so, like, it's not very exciting. So it's just Java exceptions. You can't really do anything with that. Keep fuzzing and then eventually the NMC demon will start dying. In this case, again, it's a Java exception, so not super cool. But at least it's good to know your fuzzer is working. And then finally you get some native code crashes. So that's cool. Here's one. It's a no pointer reference, so it's still not so exciting. But at least, again, it's like, wow, at least it crashed in native code. I'm getting there. So this is an example of if you send connection complete PDU before you establish a connection, it references a no pointer. All right. And then finally some actual bugs. And this is in the two, what did I say, 223 gingerbread NMC stack. So the key is to look at this thing. LCP check LCP. So this showed up in the logs and then it crashed in abort from free. So this is the source code for that. So the cool thing about Android is you can look at the source code. So if you look here, it's doing, you know, it's checking LCP, blah, blah, blah, blah. It allocates a buffer. And then if things don't work out right, there's dot, dot, dot here. So something happens. And then if things don't work out, it prints that thing which you saw in the log. And then it frees the buffer. Cool. And then it goes to down here and it calls DNIT which frees the buffer, which is not cool. So this is a double free. You know, with some work you could maybe write an exploit for it. And so the cool thing about this exploit, if you wrote it, which I didn't, would be, you know, basically you present a tag to a person and then you get a phone and you get a shell. So that would be like pretty exciting, I think. Anyway, this would give you code access as the NFC daemon, which does not have Internet access but does have Bluetooth admin access, which as you'll see later is like pretty awesome. So what about this? Well, being the responsible researcher I am, Google actually found it without me because I didn't report it. So it's fixed, though, at Ice Cream Sandwich, which is cool. The bad thing is that even though it's fixed on Ice Cream Sandwich, it's fixed on the NFC daemon. Most people still run gingerbread devices. So there's still like some guys out there you can get close to in the elevator and maybe get a shell. So now this is the part of the talk where I wasted so much time it's not even funny. So it turns out I found a bunch of these other like really awesome memory corruption bugs in the gingerbread stack. But I could never replicate them in any reasonable fashion. So I suspect they have to do with timing issues because if I ran the same thousand test cases I would always get, you know, the same number of them, more or less. But they weren't ever in the same spot. So I couldn't really replicate it. But anyway, here is some, like, super cool memory corruption crashes that may or may not be fixed. There's just a mystery. So here's one that crashes in DL malak, calls abort. And that usually happens when there's memory corruption. Here's one that happens in DL free, calls abort. That happens a lot in memory corruption. Here's one that crashes in free when it's trying to unlink a chunk where the back pointer is screwed up. That's my favorite one. Not a bad thing. But it's a really good memory corruption for sure. Here's one more. A bunch of crashes I found. Never hunted down. Reran the test cases and each time it took like four days. So many times that it's insane. But anyway, so the moral of the story is if Google had a decent tool chain for me to use, there would be like maybe four more bugs I would have not reported to them. Okay. So I'm just kidding. I'm a very responsible person. If any reporters are here, I never do anything bad. Thank you. Okay. So that's the NFC stack. So found some bugs in gingerbread. Some are fixed. Some may not be fixed. And then there's I didn't find any bugs in the N9 stack. So that means either their code, which is all native code, is perfect or there was something wrong with my fuzzer. So please fix my fuzzer for me. So now the question is fine. I've looked at the low level NFC code and that was like pretty good. I've looked at the low level and there weren't too many bugs. But what about the higher level stuff, right? So it turns out that Nokia and Google can do a pretty good job at parsing 200 bytes on an NFC tag. That's what NFC basically is. But what about these other apps? Can they do that? So at first glance, you look at what happens when you present a tag to NFC and it's super boring. So gingerbread, it just, you know, if they can screw up printing a string to a screen, like that's pretty bad. But they didn't. So here's a string. Here's a string. Here's a string. So if they can screw up printing a string, it's super boring, nothing exciting going on. But then they added all these like extra features. Starting at ice cream sandwich, Android has this thing called beam. Nokia has this equivalent thing called content sharing and also this Bluetooth pairing thing. So if you start to look at these things, get a little more interesting. So what's Android beam? Basically it's a way for you and your friend who both have Android phones to like share files and pictures and stuff like that. So or I guess in this case, really web pages. So how does it work now that you guys understand all the specs? This sentence will make sense to you when it wouldn't have an hour ago. They use LLCP with snap and they fall back to LLCP and MPP. See like what you learned. And the interesting thing is you can see here I'm beaming this game called Crime City, which is a fun game. You should get it. But to beam it, I have to press a button. But the guy on the receiving side, it just gets beamed and they can't do anything. It just shows up. It's sort of the opposite of what, you know, what you're thinking you might want to design if you were thinking about security. So how is this implemented? Like it's designed for two phones to be close to each other. But the way it's implemented is because like most things in Android with intents. And so that means as long as it gets an intent, it doesn't matter if it came via another phone or a tag. So you can still get it to do things like open up a web page just by getting a tag close to it. So, you know, if I get close to Todd Manning on the elevator, I can make his phone open up a web page to a URL I specify, which is not probably what would be good. So here's an example of just to show you how web pages get opened up. You get to a tag and, look, it goes to a website. So before, you know, I trusted, as much as I distrust vendors, I can trust them to parse 200 bytes, right? But now I have to trust them to parse what browser parses, right? And I don't trust that. So, you know, HTML, movies, videos, images, sounds, fonts. So now you can get to all this stuff through NFC. Okay. So now time for a demo. I got to thank Josh, Jayduck, Drake, and I don't know how to spell his name. Georg. So they wrote this exploit with me, I should say, but they did most of the work. It's just an Android exploit, right? It's an Android browser exploit. But, you know, you can get to it. So let me show you this and see if it works. And I have a backup movie if it doesn't work. So, hey, look, I have a project meeting today. Okay. So here is the exploit. So here in this window I have a Netcat listener. Here I have a phone. So this is an Android phone running 401. So this particular web, it's a WebKit bug, is fixed in 404. But it's still kind of cool. So anyway, here's a phone, right? I'm talking on the phone in a busy subway and some pervert comes up to me and is like, hey, Charlie, look at this. Oh, what, what, what, what? Oh, look, there's something. Oh, wait. Oh, it's gone. What happened? Right? And then over here is a shell. Anyway, it's pretty awesome. So touch a tag, get a shell. Oh, here's the movie if you didn't believe it was going to work. But it, of course, worked. That movie. Why did I do that? Okay. So the point of that is it's not that, wow, there's another WebKit bug, right? The point is that while you thought the NFC attack service was, you know, the 200 bytes of end data, really the NFC attack service is the browser, right? And the browser, you know, I mean, the good news is that Google fixed that WebKit bug that was in 401. So now the browser is secure. Okay. So that was Android. Now let's move on to Travis Goodspeed's phone, the Nokia N9. So it has something just like Android Beam which allows you to share, you know, images and files and stuff like that. Again, without user interaction. And the thing that's interesting is they have, so in Android, NFC is either on or off. And on the N9 it's on or off and you get this extra security option called confirm sharing and connecting. So you think if you turn that on, then if I tried to push you a video, it would like make you confirm. But it doesn't. So it actually does something else which I'll talk about in a minute. So here is an example of on a Nokia N9. So you can check Bluetooth is off. So I'm not doing anything with Bluetooth. But if I, so I touch, I touch it near to another N9 and then I just sit back and wait. And it's like, well, probably nothing bad is going to happen. Oh, it turned on my Bluetooth. Oh, it's downloading something. Well, it's just downloading. What's the harm, right? So cool, that was it. Oh, shit, it's rendering it. So anyway, so the point is without user interaction, you can push like things like PDFs and Word documents and Excel spreadsheets and stuff to a phone without the person doing anything. So again, it's just like this much larger attack service than you would have imagined. So instead of the attack service being this little guy that prints a string, it's actually, you can't do a web page on Nokia, but you can do basically everything else. So what kind of bugs could there possibly be? Well, if you're like lazy and you just want to use public bugs, you could do that. But, you know, that's pretty lame. So there's LibPNG, for example, ships on the latest Nokia N9, which is running version 1.3. It has LibPNG 1242 and there's at least two critical vulnerabilities reported on that. But, like, you know, you guys are too good to use public bugs. So I turned on my fuzzer for a little bit to see what I could find. And, you know, I found this, like, invalid free in PowerPoints and this invalid write in PDFs. So here, look, dear Google, look, I'm using Valgrind on my phone. See how cool that is? Maybe you should do that for Android. Or if you don't want to use those bugs, here's another bug I found, which is pretty awesome. So this bug is in the way they parse Word documents. And it's also, turns out to be a zero day in K office, too. So for your friends who think they're secure because they use Linux, you can just ship them this Word document and own them, basically. So basically the way this bug works is it allocates a buffer called group grupex or something based on some number you gave it. And then it reads in this other value, short from the data stream you're providing. And then it loops that number of times it just read and writes into your allocated buffer, grupex, whatever it reads. So you can, you have the choice of how big the allocation is, how much data you want to copy, and what data you copy. So you can, you can do that. So it's like a classic heap overflow bug. So I didn't write an exploit for this one either, but I'll show you that it's pretty easy to exploit. So here's an example of a data stream. I made the link big and then I put some data. So it crashes. Here's the back trace. It crashes at some address that isn't mapped. But if you look at what happened right before, it crashed. It loaded a value from R3. And then it, you know, from where R3 is pointing. And then it brings it back. And then it branches that value. And it turned out I controlled R3. So if I would have just pointed it to, you know, some other data I controlled, I would have gotten control. So basically this is a pretty easy to exploit bug. And again, you would get it just by getting one N9 close to another N9. You could make it open up the Word document and own them. All right. So the final thing I want to show you is this. So it turns out that if you Google Nokia N9 NFC, you come across like 10,000 versions of this video. So the guy's listening to his music. He's jamming out. And then he gets his phone close to the speakers. And then all of a sudden, like, the whole room is jamming out to his music. And I was like, how did that, what just happened, right? Like, he's on his phone. And now all of a sudden the speaker's, like, on his phone. It is magic. And where there's magic, there's security problems. So I bought one of these speakers, right? And I'll show you how it works, I think, except it's kind of, whoa, someone totally hacked my N9 because I went to my talk yesterday, I think. Oh, here we go. So now, so I got one of these speakers. I got out my N9 and I downloaded some free music. And then I was like, okay, let's see what's going to happen. So I put it here. Is it going to work? Give me one more second. See, I get the shell to work in the demo, but I can't get, like, the actual music player to work. One check real quick and then I will move on. All right. All right. All right. So I'm going to try this one. It should work. Okay, let's try it again. Is the thing on? The speaker has to be on. It's a piece of crap. Oh, wait, it's working, I think. Yeah. Is it working? This is crap. Anyway, it was just like the dude with the, like, little music symbol. I don't know. I don't know. I'm going to try this one. It was going to look just like that, but it's not working. Anyway, the point is, I got this thing and I was like, how the hell are these talking to each other? And I didn't do anything. So I looked into it some. Oh, look. I had this sharing option on. That's what happened. So now I don't know if it will work. But who cares? Oh, it's working. Oh, it worked. So, like, I didn't do anything. Well, that time I did do something, but you'll see in a second. So there's this, so, like I said before, oh, and then it turned off. You press it again. Oh, it worked. So, like, I didn't do anything. Well, I'm going to unplug it in about one second. So there's this, oh, no, it's got a battery. I unplugged it, but it didn't stop. So now we're back to this thing about confirmed sharing. So if you have the confirmed sharing set, which isn't on by default, then it actually would prompt you before you do the magical speaker thing. But if you just, if you don't touch your NFC settings, then it just magically happens like in the video. So the way that it magically, like, it just behind the curtain, behind the magic is this NDEF. So if you send it this NDEF data, what you send it is a Bluetooth address, a pin that you made up that it's going to then know, and then a name. So it turns out, like, you know, I grew up in the old days, and my whole life I've been looking for a root shell. But it turns out what I really wanted was this thing, Bluetooth. So here's the video. So here's a Bluetooth tag. It's an NDEF tag. So you can see it's a Bluetooth tag. So you can see it Bluetooth is off. Cool. And then I'm going to present the tag to the phone. So you imagine, like, you know, I'm running up, hey, how's it going, swat on the butt. And then, you know, nothing happened on the phone. If you look, like, the phone made that little blue thing, but that was it. And then even then it's kind of screwed. So anyway, it pairs. You look over, oops, you can't see where I'm pointing. So this thing showed that it just paired with me. And I didn't need to know the pin or anything like that, because I told it the pin to use. And then I can mount the file set up. And then I can go back to the file system on the phone and, you know, read all of its files. And on the phone, there's nothing going on. So thanks. So I can see all their files. And then so you can see things like, you know, pictures they've taken with their camera, JPEGs that they just happened to have downloaded, music, that song I was just playing for you, you know, like, documents. So basically anything you want, you can just download. And then you can write to it too, although I never bothered. But, you know, files are one thing. I want to actually, like, use the phone, right? This is what makes this cooler than the root shell. So now I'm going to send a text message with the phone. So send the text message. Wait for it, wait for it, wait for it. Let's go over here. So there's my phone. It showed up. If I turned this on, you would have actually heard it show up. But too late. Anyway, so trust me, that text message really sent. And then you can do things like read their contacts. So, and then you can actually use the phone. And these are the contacts that are stored on the file system as well as the SIM card. So you can see, you know, in a second here. Let's fast forward. So anyway, here's their contacts. And then finally, like, the super end all money shot is then you can actually just, like, dial their phone for them. . And I put the camera on so you don't see my phone number. So you can't call me. I'm very clever that way. And then I wait, wait, wait. Come here, okay, it's dialing and then it shows up over here. Compliments of AT&T. Thank you. So anyway, the thing is if you don't change that setting, if I just present a tag to you, then I own your phone. So if you do have that setting set, though, you get this nice thing and I have to then push you a Word document that owns your phone. So just to wrap things up quickly, so NFC is like a whole new way to own people's phones, server side. It's hard to test them, but I'm releasing tools that will let you test them. Vendors should let you say okay before people can push Word documents and Web pages to you. Here's the code, tiny URL, NFC dash files, and here's all the people that helped me while I was doing this, including cyber fast track which funded part of this work. Thank you. Thank you.