Greetings, RF Village. Man, y'all sound super excited. There we go! Hell yeah. Hell yeah, it's toothbrush time, my friends. So... This wonderful person, who is definitely on several lists, is intimately and on first-name basis with the TSA, Amtrak, and organizations with three-letter affiliations, and not for good reasons, who loves doing interesting projects, up to and including... They brought an interesting RF case to my village that looked like a pair of RF boobs, or that you could put googly eyes on it and it would work the same. It was an amazing contraption that I was sure was making me sterile while I was standing next to it. They always produce good work and do good in our village competing, so that I know this talk is actually going to have some great information in it. So, without further ado, I'm going to turn over the microphone to this particular person of the toothbrush botnet fashion, so that you can learn all kinds of cool things. Everybody ready? Let's do this. Thank you for the introduction. Yeah, so this is how to make a toothbrush botnet. Tips, tricks, tools, and process for ESP32 hacking. So, we'll get a little brief outline real quick. So, we'll get into the background a bit, the impetus for how this even became a thing, get into dumping the existing firmware, getting into some extremely basic reverse engineering, some wireless sniffing, some buzzing, how OTA updates work, self-referencing firmware. Unfortunately, the demo video is not going to work because the internet is not fast enough in here right now. And then some future work that we've got going on. So, yeah, I'm Lo Zanning. I feel like Wasabi did a pretty good job of introducing a lot of the things that I make. But, yeah, I like ESP32s a lot, and that's kind of my bread and butter when it comes to things that I use to compete in the RFCTF. So, yeah, I've been launching balloons and gluing ESP32s to circuit boards and making all kinds of stuff like that. So a little bit of background. So, like, back in January, I think it was, Fortinet, some Fortinet employee was talking to some IT trade publication, and either through something being lost in translation or perhaps maybe a bit of intentional FUD, the story that ended up coming out was that there was, like, 7 million toothbrush botnet that was actively attacking a Swiss bank. And so then there was a lot of consternation on Twitter about whether or not that was a real thing that could happen or could not happen. A lot of people feeling very intensely about whether or not that was even a possible thing to do. And eventually, UK Daniel Card on Twitter actually ended up finding a toothbrush that had, they claimed to have wireless functionality built in, which I thought was super interesting, and he went and posted a picture to Twitter. And within that Twitter, within that... Within that photo, there was actually the FCC ID. And so I suppose if you take one thing from this talk, is that the FCCID.io website is, like, my number one hacking resource. And the reason why is because they upload photos of the internal circuit boards as part of the FCC certification process. And so if you've got something that's FCC ID, or if you know who the manufacturer of that device is, you can plop that in there and, boy, how do you get some beautiful photos of stuff? And you don't even have to buy it, so you can figure out what is in the thing before you even spend any money on it. So I went ahead and I looked it up, and if you can see where the arrow is over there, that certainly looked like it was going to be serial UR broken out. So that's an exciting thing if we're trying to create a botnet. So I went ahead and, you know, thinking that, you know, I should be able to play with this thing if I actually buy one. And I went ahead and did buy one. So real quick, so the ESP32 tools. These tips are... Well, the tips are in everything, and for good reason. They are dirt cheap. I've got, like, an ESP32 Borg cube that I made, and, like, I got a guy on Alibaba who will sell me those for, like, 62 cents apiece. And so these things are ubiquitous. They're getting put in more and more things. And, at least in my opinion, granted, I've never actually programmed anything other than an ESP32. Sorry, STM32 fans. At least in my opinion, the tooling is good, or at least adequate. And with ESP tool, you can actually just read the flash. So assuming we're able to figure out how that serial UR is broken out, figure out the baud rate, all of that good stuff, you can just get the firmware, assuming no EPs have been burned in, is generally not the case, and we'll touch on that a bit in the conclusion. So we went ahead and bought one, and it showed up. And so, as you can see over there, that is, in fact, a serial UR that we have broken out there. So we've got the ground 3.3 volts RXTX reset, as well as boot. So the thing showed up, I took it apart, and I was very excited to see what I had found. And that's essentially when the trouble starts. So I don't have any of those fancy PC bytes, like probe out things, and so when it comes to me hooking up stuff to a circuit board, I'm usually just trying to solder stuff on there in the grossest way, because I'm not the world's best solderer. So essentially, solder up to TX RX ground, we don't need to supply 3.3 volts through this, because we can plug it in through the USB-C adapter at the bottom of it, which is how the device is normally charged. And that's good enough to get it turned on, and trying to start talking to it. And so I tried a lot of things, I had to figure out whether or not, is the RX that's printed on the board, is that its RX, or is that where I'm supposed to hook up my RX, like what's the baud rate. And I essentially manually fuzzed the thing for a while, it could never get it to talk to me, ended up actually writing up some Python code to try and automate that fuzzing, that unfortunately I didn't get very far with. And so eventually, I went back to the documentation and read that, and it's really amazing the kind of secrets that they hide away from you inside the documentation that's on the manufacturer's website. And so, essentially there's strapping pins on an ESP32, for those of you that might not be familiar with microcontrollers, that's essentially a kind of spell or incantation you have to do on the device using the GPIO pins, depending on what order you bring those to 3.3 volts or ground, is going to dictate essentially the mode that the MCU boots up into. And so, eventually I figured out that I need to supply power to the thing while holding the boot pin to ground, and then bring the reset to ground, and then put them both to floating. And with that, I'm able to get the stub from the ESP32 tool to load into the boot loader of the MCU, and then from that we're actually able to dump the firmware, using the command that I showed a couple slides back. So , once you've got the firmware, then we can start doing reverse engineering. Spoiler alert, I'm terrible at reverse engineering. I don't really get how Ghidra works. It's the thing I'm trying to get better at, but for right now it's essentially kind of magic to me. But, not understanding how a thing works has never stopped me from trying to, you know, fuck with that thing. So , essentially once you get the firmware from ESP32 tool, you need to parse that out into the various partitions. You need to take the partition that actually contains the code that you're interested in investigating, and you turn that into an ELF, and then once you've got your ELF file, you can load that into Ghidra for analysis. I think I'm also probably skipping a step that I forgot here, where because you're not looking at x86 stuff, you actually need to be able to tell Ghidra what the architecture of the chip and the code that you're looking at is using. And that way it can try and make sense of things. So , yeah, so we pop this into Ghidra, and one of the very nice things about Ghidra is that it'll actually show you kind of a code flow, and you can see here that kind of at the very beginning, one of the very first things the thing does at all when it boots is that we see that there's a loop that passes in a string of evo-era. Evo-era is actually the manufacturer of this toothbrush. And so that's a curious thing that kind of roused my suspicions. So then as I kept going, it turns out that there's another while loop passing in the string 1, 2, 3, 4, 5, 6, 7, 8, which if you've done Wi-Fi stuff for long enough, you recognize that 8 characters is the minimum amount of characters that you need in order to have a valid Wi-Fi password. And so we've got a while loop where we're doing some stuff with evo-era, and we're doing some stuff with 1, 2, 3, 4, 5, 6, 7, 8. If you really are scared of Geter, like I was, you can also just run strings against the binary. I don't know that this is actually a valid way to do reverse engineering, quite frankly, or I don't want to say invalid, but perhaps not time efficient. Because trying to figure out which of these strings is potentially a Wi-Fi network or password seems like you are going to be fuzzing for a very long time. So based on having gotten that evo-era string and the 1, 2, 3, 4, 5, 6, 7, 8 string, we've got a hypothesis that perhaps if we stand up our own Wi-Fi network with that SSID and that password, then maybe some stuff will happen. And so the way that I went about doing this was essentially to stand up a Raspberry Pi with two wireless networking cards. One of those is going to actually host the actual network that we intend the device to connect to. So that's the one that's going to be broadcasting the evo-era network. And then we've got another card that we're going to go ahead and throw into monitor mode and then pipe that into Wireshark. And that way we can monitor everything that's going on. A lot of different tools that are kind of around and available to set that up. I happen to be partial to RASP-AP because I'm too lazy to edit host APD manually. So we set that all up and we get to sniffing around. We turn the toothbrush on and we get them in 4K60. So that's probably... oh yeah, that is much too small for any of you to be able to see. It's much too small for even me to be able to see. But essentially, if you look real close, we can see that... not only does our device is beaconing for an evo-era network, but we can see that it connects to our network and then it actually makes several requests. All of which, if these were bigger, you'd be able to see that they're entirely in plain text. This device is making a whole bunch of API requests to the backend and they are all HTTP. Every single one of them. So what does it do? Essentially, it makes several calls to na-api.evo-era.com on port 80. And like I said, those are entirely plain text. And so every time one of these packets gets sent, as long as the toothbrush gets back data from the server that validates, then it'll go ahead and make the subsequent request. And so there's a back-and-forth, back-and-forth, and there's like four or five API requests and subsequent responses that happen. And then the thing that we're most particularly interested in is the second-to-last request... or, I'm sorry, the... eventually what ends up happening is the toothbrush responds back to the backend with its current firmware version, at which point the server evaluates whether or not it has a firmware version that's a higher version number than the version number that it was just communicated the toothbrush was running. If the server decides that there is, in fact, a more up-to-date firmware, then it can reply back to the toothbrush with a URL, again, over HTTP, where the toothbrush should download a new bin file from. So, a quick little update on... or info on ESP32 updates. Kind of one of the main selling points of these chips is that they almost all have some kind of connectivity. Almost always Wi-Fi, and I think everything has Bluetooth at this point. And so one of the very useful features of that connectivity is that we can actually load new code into the device wirelessly, so we don't need to flash everything through the Sudo UART. Espressif provides a lot of examples in both Arduino and their native IDF for these. There's a lot of different ways that they demonstrate being able to do this. You can download code from an S3 bucket, you can have the device itself actually stand up its own AP, and then you can connect to that and upload new firmware, or essentially you can do the same thing kind of opposite, where the ESP32 will connect to a network, and then a device can push firmware to it. So then for our Toothbrush RGE chain, what we need is to stand up a wireless network that has SSID of eVoera, and a password of 12345678. We also need to be running a Poison DNS server on that very same network. That way, when the Toothbrush makes a DNS request for that na-api.evoera.com, we can reply back with the IP address of our own web server, whereby we can essentially forge the requests, and send all those valid communications back and forth, and eventually serve that bin file that we'll also need to have a way of serving. So , there are libraries that do all these things for the ESP32. In fact, they're mostly all built into the actual framework that Espressif puts out. So , we need to host a network, we need to run a DNS server, we need to run a web server, host a file, and so we spoiler alert, or I suppose we're boating, just need to write our own code that runs on an ESP32 that does all of that. And so, as it turns out, most of this is actually, thankfully, pretty easy. Standing up a network, super easy. That's like one of the core competencies of an ESP32. Running a web server, again, same thing. That's like right in the wheelhouse of ESP32 stuff. Running a DNS server, same. Hosting a binary on a web server, like that's just a file on a web server, and, you know, we can run a web server on an ESP32, so we're looking great there. Unfortunately, making a binary that we host that is able, excuse me, making a binary that contains itself and is able to serve that version of itself to other devices as it turns out is kind of stupid hard. So, quick primer on ESP32 storage partitions. Most of these devices have around four megabytes worth of storage and how you allocate those, presuming that you have the ability to flash the device over its serial UART is largely left up to you. There's a graph over on the right that kind of goes over the various partitions that are available for you to use or not use at your leisure. So, OTA0 and OTA1, those are going to be both where you can store your actual sketch. The reasons why we have an OTA0 and an OTA1 is because when we're running our active code from one of those partitions and we want to update it, we need to have a place to store our updated code. So, essentially the process is that you would write your new code to the OTA partition that you're not running and then once you've validated that, you've actually gotten that firmware written to the storage, the new firmware that is essentially the device reboots and it knows to start running from the other partition. So, the toothbrush that we're looking at has four megabytes of total storage. That graph on the right is for a different device. It's an important thing to know. Being able to change your partition table is a thing that is generally only available for you to do if you are flashing the device over the serial UART. If you are doing an OTA update, the OTA update process in and of itself doesn't provide a mechanism through which you can change your partition table. If you want to change the partition table over OTA updates, what you end up having to do is essentially trample in an update. You would need to load code into the other OTA partition that you're not running from and then that code itself needs to modify the code that actually stores the partition table and then you would need to do another update where you could actually load code into the storage of your newly defined partition table. So now we get into a little bit of the challenge of self-referencing firmware. At least on the existing partition table of the device itself as it comes from the factory, there's no SPFs partition. Essentially what the SPFs partition is, is that's just essentially kind of more regularly formatted storage such that if you have a device and it's going to display a picture on its screen or whatever, you'd usually end up putting that picture in the SPFs partition. Essentially, in order to compile... There's no SPFs partition, so that means that we can't compile our worm and reference a bin file and the SPFs partition within it and then after compiling the worm, load it into the SPFs partition. Essentially, this sets up a terrible self-referential problem whereby our code needs to be able to reference the raw bytecode of its own compiled form which gets you into this terrible kind of nesting doll situation where our uncompiled code needs to have the exact copy of the compiled code in it and it's a chicken and egg problem. The way that I went about trying to solve this was very terrible, quite frankly, and very silly. I won't read to you the entire steps of my very heinous and harebrained tool scheme. The important part there is down in red at the bottom where essentially after compiling and then decompiling and then re-referencing and then re-compiling like 8 times eventually I was able to make my firmware that was able to reference a complete version of itself. The issue with this is the size of the final binary that gets compiled at that point has a ton of dead code inside of it and the final size of the sketch ends up being significantly larger than what we can flash on a normally partitioned ESP32C3 with 4MB of flash which is our intended starting vector to the toothbrush. We can change the size of the partition on our evil ESP32 it's like our initial infection vector. So we can control the partition table of the device that we have the ability to flash over serial. Our initial patient zero of the botnet if you will. And that'll work except that then essentially you end up trying to shove a 2.5MB worth of data into the OTA partition on the actual brush and that partition is only 1.9MB based on the partition table we got from dumping the original firmware and so unfortunately the update always fails because we're trying to put 2.5MB worth of data into a 1.9MB bag. Luckily there are many people on the internet and a lot of them are way smarter than I am. So big shout out to ATC1441 who after I was posting all the terrible things that I was trying to do with compiling my firmware like 7 times so that it could finally reference itself asked me why I wasn't just doing it the smart way and the answer is that I didn't know that there was a smart way. If I did I would have started that way. And so essentially what we can do here is if we go back to this one you can see that there's actually memory addresses on that chart and so essentially really all we've got to do is when it comes to serving our bin file we just reference starting at that pointer and then we chunk through at I think it's like 1024 bytes at a time and my little Russian nesting doll firmware experiment I think I got absolutely nowhere with getting that to actually work Tim yesterday . We did a lot of stuff together. And then ATC came along and told me how to do it for real. And I think I had my proof of concept working within 45 minutes. Thanks to Tim. So one of the key things here is that we need to reference the firmware from the partition that we're running. So essentially, every time you do an OTA update onto an ESP32, you're going to change the partition that the active sketch is being run from, and so if the device has been updated before, there's no real way to know definitively what, or rather, there's no way to know pre-run time what partition we're running from. Thankfully, the Arduino tool set, or rather the ESP32 tools for the Arduino core library includes some handy methods by which we can just ask it which one we're running on and then reference the memory address from there. Like I said, I had a really cool video to show you, but the Wi-Fi doesn't work here, which is probably partially my fault, well enough to actually be able to download that. But I do have the toothbrush up here if you want to come take a look on the infected toothbrush there. So now we have full RCE, we can run our own code on the toothbrush. I don't know if you can see, that's my little ransomware funny ha-ha photo. Quite frankly, it's very silly to try to make a toothbrush botnet for a couple of reasons. Mainly that the way that we're able to spread and infect subsequent toothbrushes is that we need to be running our own Wi-Fi network such that other devices will connect to it, and then we need to serve firmware to those devices, which means that at any point we're trying to attack other stuff on the internet. By definition, that means that we're not also attacking the things physically in the room with us, because we're just broadcasting our own network there as opposed to connecting to a network that's being broadcast to us. So once you have full RCE on the thing, it's not entirely that novel to write ESP32 code that'll make a HTTP GET request that could potentially be something malicious. But nevertheless, we write a POC anyways. And so essentially the code will go ahead and scan for open networks. If there's an open Wi-Fi network, it'll go ahead and connect to it. It'll then make a request to GitHub where I've set up a really terrible C2 with some JSON where you can define an IP address as well as a payload, at which point the ESP32 will download that information, send the payload to the target IP address, and then resume broadcasting the EvoEra network for... I want to say it's like a minute and a half, which will then... So you've got a minute and a half to... It's dark in here. Have a minute and a half to infect other brushes, at which point, if it doesn't find any brushes to infect, it'll go back to scanning for open Wi-Fi networks, and it'll scan for open Wi-Fi networks for a minute and a half, and essentially it just goes back and forth between scanning for Wi-Fi networks that it can connect to, as well as continuing to try to connect... or not connect to, but continuing to try to infect other devices. So, yeah. Community control here for battery-powered Wi-Fi devices is pretty terrible, so if you're aspiring botnet creator, I don't know that I would recommend battery-powered Wi-Fi devices. Like, hard-wired into mains voltage is probably the way that you actually want to go there. So to the conclusion, so... If you look at the App Store information on Google Play, there are definitely not 3 million of these brushes, or if there are, 3 million people bought these smart toothbrushes and then didn't bother to download the app to actually enable any of that technology. But there certainly are at least 3 million ESP32s out there in production, if not significantly more. These chips are used in extremely low-cost devices, and I don't want to besmirch the good name of Espressif, but I think essentially what ends up happening is that companies are out there, they're trying to get stuff to market as quickly and as cheaply as possible. ESP32s are a way to do that, but... At this point, it kind of feels like that if you're putting ESP32s into a real actual product that you intend to sell to the public, that I'm just going to assume that you've probably cut every possible corner, and that you went ahead and used, like you've already did, the HTTP methods to do the OT update, and didn't use the HTTPS one, which Espressif does provide one single example of, whereby you've got to do a whole bunch of stuff where you hard-code your own cert within your own sketch. And so, my suspicion is that essentially any product that has an ESP32 in it is probably vulnerable to something along the lines of what you saw here. So depending on the form factor of the chips that are being put into these new products, odds are better than good that the device will have to go through FCC certification, and as a part of that process, like I said earlier, companies have to send their devices into a lab, and have those devices be photographed. Those photos are included in their FCC report, and almost nobody bothers to redact any of the photos, which is a thing that the FCC will allow you to do, and no one actually bothers with. And so that leads me to my next project, where I'm currently working on a computer vision system that'll subscribe to the RSS feed that the FCC puts out of all of the new products that are going through certification, checks and sees if there are internal photos associated with whatever new product is going through certification, download those photos, and then automatically send me notifications if the computer vision system is able to determine that it thinks that there's an ESP32 on that board. So these chips are everywhere, they're ripe for abuse, and I heavily encourage you to go out there and find them. Just recently, I believe it was Bishop Fox put out some research where they ended up getting O'Day on every Traeger Wi-Fi grill they'd ever made, because their flaws weren't as low-hanging fruit as this, but weren't that complicated either. So I would encourage you to go forth and to find these chips and devices around your home, or hopefully you don't have them in your home yet, but buy them and play with them, because it's a lot of fun, and they are, like I said, very ripe for abuse, and you can make household objects do strange things, and your own bidding. And yeah, that's the end of the presentation. If anybody has any questions, I'd be happy to answer. Well, so I'm of the opinion that if there's two of these toothbrushes, like that meets my, I don't know, legal definition of botnet, like, is it a good botnet? Is it equivalent in power as the Mirai botnet? Like, absolutely not. But one of the things that I was trying to do with this, is I had a version of the firmware that was essentially doing port scanning, and I was like, oh, it would be funny if I could get my IP address to show up in gray noise, as like a port, oh, this person's doing port scanning from this IP address, whatever, but the speed that these things work at, like the connectivity, is god-awful. Like, the scalability of it is pretty bad. I suppose if you had some kind of real simple attack that you could do that would grant you access to whatever it was you were trying to hack, it could work, but between kind of how unreliable the connectivity is and the fact that they're battery-powered... I'm going to go ahead and say... I'd never say never, but I'm going to say no, probably not. What was that? Oh, so that's one of the more hilarious things about this product, is that it's a smart toothbrush. It is not a powered toothbrush. So like, I have like a Sonicare toothbrush, right, and you like hit the button, and then it like zzzz, and you like brush your teeth with it. This thing doesn't go zzzz. So yeah, no, I don't get it either. So like the entire selling point is that there's a load cell that's connected between the head of the brush and the body of it, and then like a nine degree of freedom IMU inside. And so every time you finish brushing your teeth, it'll send information about like where you were brushing and how hard you were brushing to the Alibaba cloud, which is where all of their backend infrastructure is running out of. And then the app on your phone connects to the Alibaba cloud to retrieve that like brush health... I don't know, they give you a bunch of weird metrics that no dentist that I've ever been to has ever asked me about. So again, it's a product that I am apparently not in the target market for, for at least its intended use. So I think I saw one person has a toothbrush. If you also have a toothbrush, you can come up, and if you set it next to mine, we can see if we can really make a... we'll have two toothbrushes meeting my legal definition of a botnet. I will say though, I am massively skeptical of being able to see it actually work just based on how absolutely malicious the RF environment is in here right now. So yeah, so we got the Bluetooth logo right now, and then if it'll find it, the Bluetooth logo should switch to the Wi-Fi logo, and then you'll see that there's going to be progress bar loads for the bin file to be transferred. If you want to just like keep mine next to yours for as long as you want to hang out in the village, and like hopefully maybe it'll work, my hopes are unfortunately not all that high. Okay, cool. Yeah. I mean, yeah, absolutely, right? You're not going to convince me that these are going to make a great botnet, but as far as bringing a device into an area, I don't know, I've never worked in a SCIF, but I get that they exist and that they're supposed to be secure. How many SCIF managers know that they need to be checking for people? It seems weird to me to bring a toothbrush into the SCIF in the first place, so that's suspicious all on its own, I think. But I can certainly imagine environments like, I don't know, federal correctional facilities or something, I don't know, where you may not assume that, one, a toothbrush would even have Wi-Fi, let alone be out there purposely doing malicious things. I think being able to hide Wi-Fi stuff into objects that you wouldn't expect it to have, that you wouldn't expect it to have Wi-Fi, is certainly an interesting thing and it touches on some of the other projects I've been working on where, like, I don't know if you all saw where, whatever the, I think it was the Chinese version of the NSA, it was like hot gluing ESP32s into power strips and stuff. So yeah, anytime you can get a Wi-Fi radio in a place where people wouldn't expect it, I think that's certainly ripe for abuse. All right, well, if nobody has any questions, nobody else has any other questions, I think we'll call it. Thanks for coming to the talk.