Today we're going to talk about the ESP8266. Let me just see if this is working. First of all, has anybody heard of the ESP8266? Oh, wow, there's a lot more people than I thought would actually know about this. Ask how many of us heard in your talk yesterday. Oh, that too. All right, so first off, we're going to talk about who we are. We're going to talk about who we are. We're going to talk about what the ESP8266 is. We're kind of assuming that a lot of people haven't had exposure to it. There's probably a lot of people who haven't even heard of it until yesterday when they heard it in our talk. We're going to talk about some things that you can do with it for evil, and then we're going to give you some evil, annoying, Wi-Fi-throwy examples. All right, so first off, I'm going to rush through some of these slides. There's going to be a lot of information that are in the slides I'm not going to go over just because there's so much stuff because I'm kind of starting that scratch and kind of getting you going. I'm going to get you guys up to speed. We will be posting the slides for you. They're not up right now, but check back at ragingsecurity.ninja, and they should be posted probably by next week, depending on how hungover we are. Wait, is it? Is it? It might be a typo. It's actually spelled the right way. It is actually spelled the right way. All right, so I'm Matt Trimble. I go by Dem. I'm the information security manager for Barracuda Networks. I run their bug bounty. I run their cert. I run the red team. Pretty much anything that does security at Barracuda outside of their products, that's me. And generally, I get to play the pointy-haired manager and tell people no a lot, and I don't have budget for that or time. This is Eric Escobar. He goes by Justice Beaver. Eric's a special blend. He's 60% sunshine, 20% kitten videos, a little bit of tinfoil hat, and just a peck of Voldemort. All right, so what is an ESP8266? Do you want to go over this one? Yeah, sorry about some of these slides. I did it on Google Notes and then went, ah, I'm probably not going to have it. I didn't have network access, so I exported them to PowerPoint, and Google didn't like that. So it punished me by making the slides all jacked up. All right, so I discovered this chip a while ago. It was scouring through Hackaday, and I saw, hey, a Wi-Fi chip for like $3. This is awesome. I have a bunch of home stuff that I like to wire up. Originally, I got it to do stuff like my chicken coop, to do stuff like feeding the cat. And so I figured, hey, I can slide. I can slap $2 on an Arduino and make it Wi-Fi compatible and on my network. What could be better? And then from there, we kind of started playing with it and realizing we could do some pretty bad things with it. So, yeah, I mean, that's in a nutshell when we got started with it. I don't know where the clicker is. So just a quick history lesson. This guy hasn't been around for a long time. And for most of its life, most of the documentation was in Chinese. So, yes, and I love Pentoo. Anyways, so the first time we saw it was on Hackaday around August 2014. It was just starting to get some translated docs out there in English. There really wasn't a lot. Eric actually spent a lot of time translating docs from Chinese. And we found that just chucking technical jargon into a translator produces a pile of shit. So it takes a little massaging to actually get any real information. So in September 2014, we had GCC support land. It was really rudimentary. It required a very specific version of GCC that wasn't very well distributed. So when people were working on this, what they'd do is they'd build it. They'd build a VM that had all the exact right versions of everything. And they just distributed VMs because it was so hard to get everything just right. In October of 2014, an official SDK dropped. Still was in Chinese. March of 2015, we got Arduino IDU support and life started getting a lot better. In May of 2015, we saw the first throwy article. We had actually been working on throwys before that time. We just hadn't told anyone because we were afraid that the world would end if everyone figured out that you could build a $5 Wi-Fi throwy that could jam networks and just chuck them in places and wreak havoc. And we actually kind of thought about that for this talk. Pros and cons. We're pretty sure someone else is going to do it anyways. Why not do it first? So go way forward. In August. In August of 2015, we did the Wi-Fi CTF here. We actually used Wi-Fi throwys built off of the ESP8266. I was going to talk about what we did with the Fox. Or is that in there? No, go ahead. All right. So what we did is last year, the Fox, it would continually run around. And it wasn't reported that the Fox had been found. So what we had done is we created a bunch of these little throwys, same MAC address, same ESS ID. And we put. So this is like an example of one of the ones that we made. Oh, no, it's not. I 3D printed some ones and put some like a little case for it and had some magnets on it and turned it on, stuck it, because it had the magnets anywhere and everywhere. And all of a sudden, the Fox was everywhere but nowhere at the same time. So there's people going around like, oh, no, it's right. And they have no idea where it was. And so that's originally how we got, you know, how that happened. And that's what we created it for. And then at some point, you know, so they're disposable. It's $2, $3 plus, you know, some double A batteries and some wiring. So it's essentially, you know, disposable if you're using it for a competition. And we didn't recover all of them. And somebody turned them into the wireless village. And this is, I think, a quote directly from Rick from last time. He goes, who the made this? Yeah, we still have some of those, too. You're welcome. You should put it in a case and be a collector. So we donated it to him. No, they didn't. No, they didn't. No, they didn't. No, they didn't. No, they didn't. No, they didn't. No, they didn't. No, they didn't. Whatever. Same, same. All right. So this is what it looked like. It looks pretty ghetto. But it gets the job done. So that's going to be kind of a theme for the rest of this talk. It's going to look pretty ghetto. But it gets the job done. All right. So we're going to talk about some tools and some things you're going to need to set up in order to work with these guys. First, some cautionary words. Okay. We're not lawyers. We have no idea what's legal where. We're not making any legal recommendations. If you want to know what's legal where, go talk to your lawyer. I ask you, please, just use these to attack yourself. Don't turn Wi-Fi into a pile of shit for everyone. Just do it for yourself. Don't be the guy who proves that the greater Internet fuckwad theory applies to throwies. All right. So the first thing you're going to want to get is the Arduino IDE. I'm not going to go in-depth into how to do that. There's plenty of walk-throughs out there for how to get that set up and running. I am going to talk a little bit, though, about how to set it up specifically for the ESP8266. So there's a really nice library out there that's kind of a wrapper for the standard Arduino SDK that makes it function like the Arduino Wi-Fi adapter. And you can get that by adding the following URL up there to your list of additional board URLs. And then they actually have a standard package that you can install. It's going to set up everything for you. So it's really plug and play. You just grab my slide, grab the URL, follow directions. And what it's going to do is it's going to download the Arduino SDK. It's going to download all of the tools that you're going to need to actually program the ESP8266. And then it's going to download the wrapper library that makes it function like the standard Arduino Wi-Fi. And it's mostly compatible. There are some differences between the two. The next thing you're going to want to do is you're going to want to make a programmer. So unlike a standard Arduino, they don't come usually with a USB interface. So they're just going to come pinned out. And they have a mode switch that you have to do to actually program them. And while you can actually wire them up by hand, it's super annoying. Especially if you're going to do a bunch of them. So what you're going to want to do is you're going to want to build something like this. This is literally the programmer that I've been using all weekend. Super cheap. I think it cost me maybe, I don't know, 50 cents. But it saved me a ton of time. And what it has on it is it has a switch that switches it into programming mode. And, well, a button. And a button that does a reset on it. And then when you want to program it, you hold down the program button. You hit reset. You let go of reset. You let go of the program button. And now you're in program mode. If you're working on something and you want to reset the device, you just hit the reset. So it really speeds up working with these things. Otherwise, you're playing with pins and connectors or, you know, soldering things on. And it just becomes a nightmare. Also, note, you'll see a lot of diagrams out there on how to wire this thing up. Most of them are way too complicated. So this is my own little design that I put together. So the other thing about it, too, is if you look at the pins on it, this is not breadboard compatible. So this is not something you can just stick on a breadboard. Because one way, you're going to just completely short the thing out. And the other way, it's just not going to work. So it's not something that you can easily just attach to a breadboard and say, hey, you know, I'm going to get it to work. And that's why Matt built that programmer, just for that exact same reason. All right. So follow this. This will be super easy. You'll see some that have multiple resistors. You really only need one resistor. I'm sure there are better, more correct ways to do it. But I've used this for, I don't know, a year and a half. And I haven't had any problems. So I'm not going to go into the super low details. But it requires certain pins to be pulled low and high for operation versus programming mode. And then it wants a pull down for actual normal execution. All right. So I'm going to talk about your first sketch in Arduino. So this is going to work for most of your use cases. But not all of them. This is essentially setting up your sketch to use the standard ESP8266 Wi-Fi library. It makes it really easy to get up and going and getting your sketch running and getting either an AP in place or a client in place or a client AP in place. But it doesn't expose some of the more advanced feature sets. So if you're wanting to do anything crazy, you're going to have to bypass this. All right. So this is just an example of what a really super simple basic sketch is. I'm actually going to post this. There's a URL right there where you can grab it off of Google Docs. We were talking about throwing it up on a code repo. I just haven't gotten there. And I wanted to get this out to you guys. OK. So the next thing I'm going to talk about is how to use an ESP8266. This is an ESP8266 for AP scanning. So yesterday we were talking about setting up some nodes out there. We were actually talking about using Raspberry Pis. But the ESP8266 will work too. You can set these up essentially as a scanner. So it just sits there and scans and looks for APs. So you can throw these around if you think you have some jack wagon that's coming in with a rogue access point to help you find them. And because they're so cheap, you can throw 20 of these around your office. And get a really good feel for where they are. So the first thing you're going to want to do is you're going to want to set the Wi-Fi mode to Wi-Fi STA, which is essentially a client. So you're going to tell it, OK, you're going to client scan for access points. Then you want to make sure it's disconnected. You don't want to be associated with anything when you're doing your scan. For people who aren't familiar with the standard Arduino sketch, you've got two primary functions that you're going to use. The first is going to be setup. That's kind of the setup for the board. The next one is loop. Loop is just called over and over and over and over and over and over. So we're going to set it up. And then in our loop, we're actually going to do the scan. And to do the scan, you're going to call Wi-Fi scan networks. And what that's going to return is going to return the number of access points that it found. And then using that, you can call Wi-Fi dot whatever, R-S-S-I, B-S-S-I, is hidden, whatever it is you want to get the information back from, and pass it the index of the AP that you want to look at. So I actually have a demo set up. This is a big no-no. We're going to do a live demo. And it actually died on us this morning. We stepped on my programmer and totally crushed the USB portion of it. And so I hastily put it back together. It appears to be working, but we'll see. Drum roll. All right. So I'm going to put this guy in programming mode. Right now he's in run mode. So I'm just going to hold down the reset or the program button. Hit reset. Let go program. And we should be in program mode now. And now what I'm going to do is I'm going to compile and upload this sketch. This is essentially just a fleshed out version of what we were just looking at. It's just going to print information about some scans it sees. I am. I tested. It's going to take just a minute to do the upload. Use your fingers. It always goes way, way slower when you're presenting. Somehow it knows. . Yeah. Yeah, you absolutely could. The exact same thing. Especially tied in with like one of Adafruit's little GPS modules. Perfect. You just tie the two together. That's actually what in yesterday's talk I put on my cat. The cat walks around and maps everything. . . . . How's that causing such a 256-arı scan? Oh, I've actually had weird results when I tried doing a scan and I'm connected. Sometimes it will miss things, so I generally don't recommend that. What you could also do though, too, is you could scan down yourself, up yourself, connect, offload data, and then just switch modes to just kind of toggle back and forth between you being a client being in access point. . . Alright, so we compiled, we uploaded, it automatically switched over into run mode, and now we're actually doing some scans. If you want to, if you want to put this on here. That's fine. We'll just swap back and forth. Okay. It worked. Yay. All right, so now I'm going to talk about promiscuous mode. So the ESP8266 kind of supports promiscuous mode. If you read the API docs, they say they fully support it. In some places, which is a lie, and in other places, they'll say, we support it, but only some of the data. So it's not super useful. What you're actually going to get when you set up the device to listen in promiscuous mode is you're going to get the start of the Wi-Fi packet if it's a data packet, or the entire packet if it's a management packet. And if it's a data packet, it only gives you the first 32 bytes. And I think they have done this specifically so you can't make these sniffers. I'm like, super cheap and chuck them around everywhere and just monitor everyone's traffic. Because it appears to be a completely artificial limitation. The documentation is also not very good for this portion of the SDK. When you're hunting and pecking and looking for it, it actually is documented in their structures section, not in their API documentation. There's a whole section down there that describes the method for doing a promiscuous scan. So if you're looking for the documentation and you can't find it, I actually put up here the specific section that you need to go to to look at the documentation in the slide. So you can just grab this and take a look at it. But this is the basics of how you're going to do it. The first thing that we have to do is we can't use the standard Arduino interface. We have to bypass that and go straight to the SDK interface. So you can see up at the top, I've got this extern C. Include user interface H. That is including the SDK header instead of including the header for the Arduino API. When you do this, you have to use the programming methods that the SDK uses, which are a little different than the standard Arduino programming methods. It's really big on asynchronous things. So it handles this with a callback. And the definition for the callback is not defined well at all in the documentation. I actually had to dig around in a bunch of examples to get this guy. So this is good information right here, where you see the handle packet, PKT. That's the signature for the callback. When you get your data back, some of the information that you're going to need is actually encoded in the length of the packet. So if you get some data back and the length is equal to 128, you have a management packet. There's no flag that says, hey, this is a management packet. You're going to have 128 bytes. If you get something back that modulus of 10 is 0, so if it's a multiple of 10, I am absolutely dead serious. You have a data packet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . You have an undefined packet that is not reliable. I have found that sometimes it actually contains data, so I think what that is is if they do the CRC check on the packet and it fails, they just give you the whole thing because they think, this isn't valid anyways. But I pretty much ignore those because it says it's undefined and that you can't trust it. So the two things you want to look for is if it's equal to 128 or if it's a multiple I have never seen that. Theoretically, I guess that could be if it was over 30 because you're only going to get back 32 bytes maximum. So the other thing about that is they can pass you back multiple packets at once. So once you look at what they've passed you back and you look at the length, that's the length for the first packet they gave you. And then there's a flag that says, I actually have two packets. There's another packet right next to me. Here's a pointer to it. So it's kind of a funky layout. So in your setup, when you want to do this, you're going to do a couple of things. You're going to do a Wi-Fi set op mode station mode. You're going to set the channel, right? So whatever you're going to do, you're going to do a Wi-Fi set op mode station mode. That's what you're going to want to listen on. Then you're going to call Wi-Fi set promiscuous RxCB. So that actually sets up the promiscuous listen. And you have to register your callback. And then delay for a second. If you just call the next line right after the fact, I've had it fail. And it just won't capture anything. So do a delay of like 10. Just give it some time to get it set up. And then call Wi-Fi promiscuous enable. And that'll actually get you going so that you can do promiscuous captures. I don't know what the minimum delay is. Like there's no documentation on that. It's just something that I've observed. And I find that 10 usually does the trick. If you want to increase that or decrease that, have fun. All right. So the next thing we're going to talk about is the AT firmware. So the two previous things that we talked about use the standard firmware that comes with the Arduino SDK for the ESP8266. They have another firmware that they put out. It's closed source. We don't know how it works internally. We make some guesses about how it works. But we don't know for sure. And it actually exposes all the functionality of the device in the AT command set. So this is what I had a lot of fun playing with, the 3D printer. Because the AT is in Chinese documentation and some symbols do not translate so that makes things a lot harder and so so this is basically this is going off that same sketch so if anybody has like a phone that's Wi-Fi analyzer on it or anything I'm just gonna plug this in just to show you that you can get it from a pretty good distance away so it should be live now and just imagine if there's like you know maybe five of these and they all look exactly the same how difficult that would be able to find and so if you look through these AT commands you can see that okay the first the first set the CW sat you just set the SSID set the password the five is the channel so you can set that anywhere from you know one to eleven to fourteen if you're in Europe and then the three is the is the encryption type so the zero is open one is web two is WPA three is WPA two so that's that's how that instruction set works the the next line that won't the question mark that just gives you the details of what's currently on the device itself and then the next step so if you want to create an access point and you want to clone the MAC address you'll also want to set this AT I don't even know how to say that for the MAC address and then again the question mark is to check it if you're in our talk yesterday this is what we're talking about cloning the BSS ID and we actually so we were playing around with it and depending on what firmware you have there's a lot of different firmwares out there just go look at the command stack because you might there so instead of fixing some of the things that come with the MAC address they decide you know what we're gonna deprecate that feature and we're gonna add a new feature so it'll be the same thing you know underscore like new underscore you know current for C you are so it's just horrible horrible documentation from that standpoint and instead of fixing a feature they decide to deprecate it and then have a new one so just watch out for that if the the MAC address doesn't stick or if it doesn't stay another thing is to point out is the AT command set between the firmwares not only have they deprecated features but they've been adding them so if you're trying to do something and it's not working check your firmware because you may be too old some of the devices that we get still have the 0.9 firmware which is pretty darn old which has a very limited AT command set so you're probably gonna want to update to like a 1.3 we actually tried the 2.0 this morning trying to rebuild our throwy that died and we were having issues with it so I probably want to stick with a 1x if you want to do something with the AT command set and then my bread and butter the one that I always used for a long time was the 9.5.2 not if it makes any difference but that's the the 0.9 is the one that I've been using too I want to point out that it uses a superset of the AT command set so it has your standard AT commands and then a bunch of add-ons to do Wi-Fi and they're not very standard as you can see by some of the commands documentation has gotten a lot better they actually have some some supported English documentation it's not the greatest you can still tell that there's some translation difficulties but for the most part you can figure it out alright so if you've got something that can scan networks you should see that we actually have our throwy up we didn't want to actually DOS anyone's we set a MAC address of zero zero one one two two three three four four five five just to show you guys that we actually have control over the BSS ID alright so those are super annoying throwy example and it looked like it actually worked and and the other thing if you if we are DOSing you because you have that MAC address I'd really like to meet you because I use that MAC address a lot everywhere for testing alright so in closing I want you guys to just think about experimenting because this thing is so cheap you can go on you know Amazon and pick up 20 of them for next to nothing and and you know like I said the programmer cost me 50 cents to actually build and the software that you're gonna need is free so really all it's gonna take is your investment in time to play with them and you know maybe some documentation to kind of get you bootstrapped so you you can actually get some stuff working but I also want to ask you guys if you do something cool share it so this is the reason the ESP8266 has really become popular there's other devices that are similar to it similar price range is it has a really good community and so if you come up with something or you know you're in a forum and you see someone that's having trouble with something that you figured out you know talk to them you know throw out your ideas the community is better the more of us there are and the more of us there are communicating the more of us there are building documentation all right so in closing the moral of this story is the esp8266 is evil and hellbent on world domination you've been warned I just little shout out for imagenstribution let's think Spark Fun all of their images are actually licensed under Creative Commons which is super awesome and pexels pexels even even more awesome because they're under Creative Commons zero license which means you technically don't have to give them attribution at all but I did because they're cool all right so that's it we're gonna open it up to two questions yes in the back yes yes it has a deep sleep mode that you can put it in so one of the things we didn't go into that you can do that's super annoying is when you get a little more advanced and you're working on it and you get into the deep sleep mode you can actually throw like five or six of these suckers out there to do D off and then send them up on a timer so they pop up they D off for a minute then go offline for a few days and then just have them pop up and down all over the place and your IT guys will go bald it's just game over yes so I actually don't use them for that you can I use a different Adreno for that so I don't know if anyone's heard of the hope Rf chips but there are some some really nice low power Rf chips out there the one I've been using lately a supports Laura if you go to was it low power labs yeah low power labs l overview make some really awesome like integrated altogether modules can you pick them up for like 25 bucks that is like a long range Rf that you can easily turn into like a serial programmer and you can get in with the little flash chip so you could actually be OTAs but just you're whenever So I'll hook these up to one of those, and I'll set up OTA so I can actually program them in the field to do different things. Yeah, you could totally do that. There's actually some standard examples for that. Any other questions? Sorry. No. That would be super useful. So the one place that I found, oh, man, I can't think of it off the top of my head, but it has basically the whole, like, Flasher has the full firmware set, and we'll put it up in the slides, but that's where we've gotten started with it. And then there's another website. I think it's the ESP8266.com. I think that's the exact website. And those are basically the live forums for everything, and that answers a lot of questions. And there's a lot of people that, you know, can speak Chinese and English that are like, yeah, you want this link. Even though, you know, Google Translate just murders it. Okay. . I am playing with it, mainly to bypass the limitations of the promiscuous mode. I didn't get into it, but it also supports raw packet injection. But between firmwares, it's really flaky, and there are some undocumented behaviors where it changes parts of the packet prior to sending them, even in raw mode. And so I didn't want to talk about it because it's not really ready for prime time yet. And I think the community needs to get around bypassing some of Espressif's SDK to make those really work. . Far back. . So I do LoRa on Arduino. . Yeah. . So the ones that I like are from SparkFun. They sell on E1, which is what this is. There's actually some tiered. There's like E1, E2, E3. The super cheap one that looks like this is what they call an E1. And I get them from SparkFun. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a function that gets called very early on in initialization, and there are some things that you can't set outside of that. In particular, you can't set the MAC address outside of that function. You can add a hook inside of that to add your own code in the Arduino IDE to set the MAC address, but that's kind of an advanced thing. There is some patches up on GitHub that add some extensions so you can run some very early code through the Arduino IDE, but the one that you're going to download through the link doesn't have those in it. Any other questions? Going twice. Oh. How are you connecting the chips to your programmer? What were you using? So this is a USB serial adapter I got from Adafruit that's slightly modified. When you get... When you get it straight from them, it's going to be set up for 5 volts. These guys are a 3.3 volt. If you crack it open... That would be more on the ESP side, but it doesn't have a breadboard pin, where you just have a socket you plug into your programmer. Yeah. So it's just a cheap little socket I got off of eBay. I think I got, I don't know, 100 of them for like $5. Yeah, there's, I mean, the whole point of these things is they're super cheap. All right. Anything else? Then that's going to be it, guys. You were an awesome audience. Thank you. Thank you.