Welcome everyone. My name is Andrew Bellini and I am here today to both convince you and show you that anyone can hack IoT devices. So in the talk today, I'm hoping to both convince you that and I'm also going to walk you through a methodology that you can go take home, buy a cheap consumer IoT device and hopefully hack it. Before we get into the actual specifics of that, I actually just want to start with a really quick joke. And that joke is the S in IoT stands for security. Has anyone heard that joke before here? It's one that I hear. Yeah, I see some people are hearing it. It's one that I hear tossed around the cybersecurity community. And usually when I hear that joke, it's actually by folks that don't work specifically in IoT or embedded security. But as someone who actually has a background working in industrial IoT devices and embedded devices, I won't say I'm not salty about it. I'll actually put my hand up and be the first to say that it is a well-deserved joke. So the thing about that joke is, and we can all, you know, have a laugh at IoT devices and their lack of security, but the reality is if you, you know, check out and look at how many estimates for IoT devices there are connected in the world right now, you'll see greater than 15 billion, you know, estimates. That's almost two per person of IoT devices. And in addition to that, we're expecting there to be a big surge of IoT devices because of AI and machine learning, how they're going to be used for edge devices. And it's estimated looking at the projections, there could be 30 billion by the end of the decade. So that is a lot of things to secure. And these are everywhere. So it's not like they're just in our households from, you know, smart cameras to even smart toilets. These are also in critical infrastructure. They're in our cars. They're essentially everywhere nowadays. So one of the things that I kind of thought when I was starting to get interested in IoT security is there's so many devices. And in addition to that, there's this agreed upon kind of thing in the security community that IoT devices are not secure. So I figured there would be a lot of people doing IoT hacking. And the cyber criminals are definitely taking advantage of this. They love finding vulnerabilities in IoT devices and adding them to their botnets or using them for initial access. But my experience was in the ethical hacking community when I started meeting hackers and things like that and asking them if they hack IoT devices, a lot of times the answer was no. And that was kind of reaffirmed today too. I've had a booth here where we've been doing IoT hacking, and I had mostly beginners who had never done it. And it was awesome to teach them that. So one of the things that, you know, when I ask people, why aren't you doing IoT hacking, there's a few misconceptions that I hear about it. And I just want to try and dispel some of those. So the very first one is that it's too expensive. So you need to buy expensive gear, you need like, you know, an oscilloscope or like a microscope or expensive tools to get into it. When you're starting out, and this is a reality, you're probably going to need to buy the devices you want to hack on. And then addition, there was really a large lack of affordable training. When I was looking to learn even, you know, five years back, it was like $5,000 for a course, a lot of them were in person. And then the second misconception I hear is that it's very complicated, you need to like have an engineering degree, you need to know about electronics, you need about hardware, circuits, all of that stuff, you need to know about special protocols, in addition to just the normal things that you need to know about hacking. And in my opinion, you know, some of these are true, there is some truth to it. But I actually think there are ways that you can actually learn to hack IoT devices, commercial IoT devices off the shelf, without spending that much money. And there's a lot of great resources to learn how to do it for free or for very limited amounts of money. Okay, so I've been chatting for a little bit, I just wanted to give a quick intro to who I am and why I know a little bit about IoT and IoT security. So my name again is Andrew Bellini, I go by Digital Andrew on the socials. My background is actually in electrical engineering. So before I got into cybersecurity, I did a lot of work actually designing embedded devices and industrial IoT devices. So that's a little bit where I learned about it, not specifically in security, but just actually, you know, designing the devices that we use. I now work as a content creator at TCM Security. So there I am the creator of our IoT hacking course. It's a beginner's IoT hacking course, and I also created our Practical Junior IoT tester certification. And if you do want to link up with me, you want a copy of these slides, you want to see what I'm working on, I got lots of free blog resources or anything like that, check out my website. So a little bit of motivation for this talk. I have one specific goal, and that is to provide you with a methodology, specific tools, and knowledge to find vulnerabilities, aka hack, in commercial IoT devices. And I have a couple messages here from some of my previous students, just to give you some motivation and also proof that this methodology works. So I had one student, he actually just messaged me a couple weeks before DefCon, and I was super excited to see this. I didn't know him before, but he said, I took your course, and he had, you know, chatting with him. He had never done any IoT hacking. He took my suggestion, he went and got a cheap smart camera off Amazon, and he actually was able to find three vulnerabilities in it, got in touch with the vendor, and he's got three CVs coming. So super excited for him about that. And then there's another message, this person didn't want me to put their name up, but he took my course as well, and then he bought a cheap router, and he found a remote code execution vulnerability in it, and I just was chatting with him about how he could submit that to a CNA, because the vendor didn't want to talk to him about it, but how he found a vulnerability. So this chat is for everyone, of course, if you're here. I'm glad you're here. If you are, if you're new to IoT, or you're IoT curious, as I say, this talk is specifically catered to people who are new or just curious about IoT, and it's going to assume you have limited or no experience with IoT or embedded systems. So just a really quick agenda of what we're in for today. We'll start with some, really quickly, and legal considerations. We'll then talk about what device you should actually pick if you're getting started on. So if you want to go home and buy something off Amazon, what you should look for, if you're going to go dumpster diving, for example. We'll then talk about how you can build out an affordable toolkit, and what stuff you should buy, or what stuff you should avoid, and how to not, you know, break the bank doing this. Then I'm going to take a look at locating, using, and abusing hardware interfaces. We'll then talk about acquiring firmware, and then after that we get our hands on the firmware. We'll talk about analyzing and reversing engineering it. So just a really quick staying out of trouble. This is kind of like the golden rule of ethical hacking, in my opinion. Only test devices that you're authorized to. And then this is my personal suggestion, since I am giving a talk about potentially how to go out and find CVs and IoT devices, but I always recommend being ethical and following responsible disclosure if you do find things. Unfortunately for a lot of IoT devices, they don't have bug bounty programs, but they do have responsible disclosure, so you can at least report it, get some credit, and get a CV that way or something. So last one's up to you, but you know, I would implore you to go that route if you find something. Okay, so I did want to just give a little chat about staying safe, because sometimes I give workshops or things like that, and I teach people about IoT and hardware hacking, and they're a little bit nervous about opening up a device and working on the hardware of it. So the first thing I will say is IoT hacking is in itself very inherently safe. So hardware hacking on commercial IoT devices, and that's really if you just only follow one basic rule, you'll be fine. And that rule is that you should never work on anything high voltage. So when you open up the device, you're working on it, most of these devices are going to be like 12 volts, 9 volts, 3.3 volts, 5 volts operating voltage. All of those are, for the most part, safe to work on. You won't even feel it if you touch it. The voltage from our walls and our house and stuff, that stuff can really hurt you. So just stay away from that stuff. Just work inside your device, you'll be fine. Never use any damaged or modified power supplies, because that's how we can accidentally introduce those higher voltages into the device, damage our device ourselves. And then this last one is more about keeping your devices safe. But when I give workshops, I see people doing this all the time. And this is the most common way to brick or fry your device. But if you have it open and you're working on it, then that's not how the manufacturer intended you to be using it. And if you're plugging in clips or wires or things like that, if you have it powered on, it's easy to bridge something and do a short circuit. And that's the easiest way that I see people who are learning fry their device. So it's just really good practice. If you're not using it, turn it off, plug anything in you need, then turn it on when you're done. And if you need to unclip it, you power it off, then you work on it. And it's easy to forget. I'm always walking around in the workshops warning people of that. Last thing I just want to give a really quick shout out to because people have gotten seriously injured from this or hurt doing this. You aren't really going to counter these IoT devices. But if you take your hardware hacking skills that you learn from this to other things that have larger power supplies, is watch out for large capacitors because these can actually pack a punch as far as the amount of energy they store. And also some people don't realize but when you unplug these devices or capacitors from the wall, they can hold their charge for quite a while. So you may think you're safe, but they can zap you. This is not common in pretty much all IoT devices. But I just say this because a lot of people have this misconception if it's unplugged, it's safe. But if there's large capacitors, that's not the case. Okay, so now that we've got all of the preamble and everything out of the way, we can get on to, you know, kind of my methodology for how you can go home, get a cheap consumer IoT device and hack it. So the first thing to do is actually to pick the right target if you're learning. So I always suggest the cheaper the better when you're starting to learn. And there's a couple reasons for this. The first one is, and this isn't always the case, but usually you get what you pay for in terms of security and also hardware security. So on cheaper devices, you generally won't run into limitations on the hardware where the debug ports are locked down or the firmware is encrypted. And then the second one, which kind of goes with my second point here, is I never hack anything that I don't mind bricking or destroying. And if it's a cheap device, then you're not going to be as concerned or upset if you fry it. And, you know, I'll raise my hand and say I still, you know, fry or brick devices. It happens. I've been hardware hacking for a long time and it still happens. And if you're a follower of Joe Grand, for example, probably one of the most famous hardware hackers, he gave a talk a few DEF CONs ago. He literally just talked about all of the devices that he had bricked over the years. So it happens to all of us. If you're looking for a specific type of device, my suggestion is to go with cheap routers or cheap smart cameras. They're great to start on. They usually have vulnerabilities that you can find. And also, more importantly, they almost always run embedded Linux, which in my opinion is a much easier type of device to hack on when you're learning than something with a microcontroller like ESP32 or STM32 that's going to be running RTOS. Those are a little bit more advanced or harder when you're getting started. And I will give another shout out to dumpster diving. So on this picture here, this is one of many bins I have at my house that are just full of old devices. And I just kind of put it out into the universe, like my friends and family know that I'm this dude that likes hacking weird electronic stuff. So if they're throwing away their router or camera, then they ask me, or I find them in like disposal bins or whatever, I can't resist. So it's a great way to learn though, because usually these devices work fine. People are just, they're obsolete or whatever, but they don't have to worry about bricking them or anything. Okay, so once we've got a device, hopefully it's a smart camera or a router or something, we've got to acquire a little bit of gear to go along with this methodology. So I've got a couple of rules for that. The first one is we don't want to break the bank when we're starting out. You might not know if you want to do it or not. We don't want this to be a limitation. I also generally find that gear for IoT hacking follows the 80-20 rule. So if you're not familiar with this rule, it's kind of the idea that for any given input, that 20% of the inputs are responsible actually for 80% of the outputs. And I find that to be true with IoT hacking tools. You'll need to get a few of them and they'll do most of the heavy lifting. And then you'll need to acquire the more specialized expensive tools for specific tasks. Sure, at this point, everyone's seen a lot of the meme of this Turkish shooter guy. And I just wanted to demonstrate this. I was kind of poking fun last week in the IoT and hardware hacking community about how we all like to acquire gear. And I'll be the first one to say I'm addicted to buying gear. I've got all the stuff in the left-hand side of this picture. But really, when you're starting out with cheaper devices, you can probably get away with literally two things and spend $10. Okay, so the first piece of equipment that you should get if you don't have one already is a digital multimeter. This is like the Swiss RB knife of electronics. It can do things like measuring voltage, current, resistance, do continuity testing. Mostly, we will use this for verifying voltage levels. And also, we can actually use it to find a lot of common debug ports. Without special equipment, we can actually, you know, ID those and then do further investigation into those ports. You can literally spend $5 on this. This yellow one on here, that's $5. I got this off AliExpress. I've used it in my workshops before. I mean, I wouldn't use it for like commercial QA testing or anything. But as far as learning IoT hacking, getting started, it's not bad. I have $5 to $100 listed here. I wouldn't recommend spending more than $100, but you can. But your $5 one, honestly, it's not that bad. The second piece of equipment you'll need is a USB to X adapter. And by X, I mean the protocols that our IoT devices are going to be talking at the hardware level. So these are where those like debug and test ports come into play. The most common ones are UART, SPI, or sometimes you're referred to as SPI, I2C, JTAG, and SWD. The most common one you'll actually see and what we're going to be focusing on is UART. So you can just go and get this $2 one, and that will work for this methodology. You get these off AliExpress, Amazon, sometimes it's coming like a pack of four for $10, you get them $2.50. So if you just want to go the cheap route, you just buy this $2 one, you'll be fine. If you kind of want a future proof, and you actually want a tool to work into, I always recommend the Tigard board. I really like their board, and they have good training that's free that goes along with how to use it. And it's going to talk all of these common protocols, actually. So it'll do UART for you. And then when, you know, if you need to jump up to something JTAG, SWD, or I2C, then you can use this as well. Okay, so the last, this is the last thing that's going to be in our toolkit is some sort of flash programmer. You can get these in all varying different levels, but this is a cheap one for $10. And we will use these to mainly extract the firmware off the device if we can't get it from other methods. So most of the cheap IoT devices I see, and why I'm suggesting these routers and cameras, they all use the same like standard SPI flash chip eight pin. So you can use a flash programmer generic one like this to read it. If you did get the Tigard, you don't even need to get one of these, you can just use the SPI connection on that. And honestly, you might not even need this. So it might mean before you're seeing us, we get the firmware from the vendor, then you don't even need a flash programmer, you can just download it. Alright, so we got all our stuff, we picked the device, we've got our gear, we're ready to start hacking. The first thing we're going to take a look at is abusing debug ports and hardware interfaces. So for the most part, IoT and embedded devices, they don't have any keyboard or mouse input, they don't have a monitor, they just kind of do something. And if they're not doing that thing right, then when you're designing it, and as a designer, your debug and test interfaces, these are like your only link to that device to see what's going on, what's going wrong, what's happening, making sure things are going properly. So what happens in R&D of the cheap devices a lot of times is they will use these throughout the R&D design process, we'll get to the end, device will be ready to go and they don't want to do another revision of hardware and things like that, or maybe firmware. So they'll just leave these on the board open like they were when they were testing. In addition, a lot of times they're actually used in production devices for things like debugging, doing logging, QA testing, possibly even flashing memory or things like that. The most two common ones I see are UART and JTAG. We're just going to be focusing on UART because on the majority of cheap consumer IoT devices, that's the most present one and I almost always see UART that you can use and abuse. So this talk is like the no BS, no filler version of it, so I'm not even going to really teach you about what the UART protocol is, only the things that you need to know to hack it. It stands for Universal Asynchronous Receiver Transmitter. That just basically means there's no clock and there's two lines, one for receiving and one for transmitting on. It's a very old and common protocol for electrical communication. It's a little bit more complicated than this, but the basics of it is it literally just talks binary with voltage, so it sends plus 3.3 volts or 5 volts for a 1, 0 volts for a 0. And I got a little picture here of a capture if you're curious, but that's literally all you need to know about it as far as hacking on it. So getting a connection to a device is UART. If you're doing like a pen test or something, that would be a finding, but for the most part, manufacturers don't actually care specifically about that. However, actually getting access to the UART will make it a lot easier for us to be able to find vulnerabilities like something that could be exploited from the web. It's going to make us a lot easier to find those. And the reason for that is we can view the device as logging, so that's probably the most important thing. In embedded devices, there's usually not a lot of storage and there'll maybe almost no actual writable storage that we have, so there's no place to store logs. So instead, we're just going to dump that all out to UART. In addition, if we are encountering embedded Linux, then usually we can actually use the UART connection to get a shell into the device. We can do further enumeration that way. Sometimes we can access the bootloader, which is responsible for it actually brings up the device. And if we can get into the bootloader, we can do things like dump the firmware, see environment variables. And so yeah, getting UART is a great thing, especially for the logging. You can see in the picture here, I'm just looking at some of the boot logs, and there's actually quite a bit of detailed versioning information that we can see already. So once you start using UART, and this happens to me, like when I see a board, it's very, very easy to start picking them out. Like whenever I see a PCB now, just subconsciously, I'm like, oh, that's UART, I can see it. So I start looking for them. And once you start noticing a few characteristics, you'll be able to ID them. So generally for full duplex UART, so this means that you've got two devices, your IoT device, and then maybe your computer that has the UART adapter they're talking to, they're both talking to each other. That means there's going to be a transmit line, which you'll see abbreviated always as TX, a receive line abbreviated as RX, and a ground. Sometimes you'll see a VCC, and I'm just calling that out because if you see four pins, for our hacking purposes, you can just ignore the VCC. We don't even need to use it. So unfortunately, they won't always make it as easy like in this example here. They've gone so nice as to label them for us and all the hardware hackers, but they won't always make it this easy. Sometimes you'll have test pads like the ones here on this black circle PCB. This is a camera that I was hacking. And you'll notice there's only two pins together. But seeing those two pins together and close to the processor, I thought that they might be UART. And then I just picked up a ground elsewhere. And then we've got another router here where they've got a connector here for UART. And it's not labeled, but as soon as you see those pins together like that, it's a good indication that it's some sort of test interface. So this is where we're going to pull out our DMM, and we can use our $5 DMM to actually pick up UART. So what we're going to do is we're going to take advantage of the fact that UART is extremely chatty on boot up. So if you've ever booted up your Linux computer, even or some Windows ones, and you see all the stuff coming scrolling through the screen, telling you all those boot log information, well, embedded Linux is the same. And that's going to happen on the UART as well. And we can take advantage of that. So what we can do is use our multimeter, put it on the volts DC setting, and measure the pins of interest. So if we think there might be a UART pin, we'll just measure that from that connector, whatever it is, to ground. And then after we're doing that, we'll power on the device. So I always like to have a power bar in my workstation that has a button, it makes it a lot easier. And what you're looking for is a fluctuating voltage after that boot up. It'll usually be like a couple seconds after, take a second for like the initial boot loader to load things up, and then you'll start to see a bunch of voltage hopping up and down. You won't see it go like 0 to 3.3 volts or 0 to 5 volts, because it's going to be too fast for our multimeter to read that. So instead, what you'll see is more of an average voltage kind of moving around. A lot of times these devices operate at 3.3 volts, so you'll see like 1.5 to 2.7 volts, and you'll see that moving up and down. So if you see that, that's a really indication I should look further at this port, it's probably transmitting something. If you just power on the device and do this, you probably won't see anything, because it's not going to be as chatty, it'll maybe just send a couple messages, and it'll be really hard to even see those blips of voltage. You got to do it right at startup. Okay, so we've found this port, we've identified it, the next thing we're going to do is we can it's as easy as we can just plug it into our computer, basically. We use our UART to USB bridge adapter, plug that into our computer. The only thing you need to keep in mind for it is it's really easy to put like names together. So you want to put TX to TX, but the way that it works is one device's TX goes to the other one's RX, and vice versa. So you just need to cross those lines, grounds go to ground, ignore the VCC, you're all good. So just for reference, I got a little picture here if you're looking at the slides later, but that's the pinout that you would usually take. So unfortunately, sometimes they won't make it that easy. They won't put the header pin on, there won't be through-hole connectors. So what do we do in that scenario? Your best option is to solder. So hopefully you're hanging out at the soldering skill station. But if not, there's ways we can get around that. So if you are lucky enough to have through-hole connectors like we did, I showed in the one router, the best way to do that is to actually attach some header pins to it. And if you don't have those, there's lots of clips, adapters, and things like that where you can buy more specific to your device. Google is your friend here and they're really not that expensive. So just go out and take a look at your different options. And just to show you if you don't want to do soldering, here's two things I've done in a pinch and shown in classes where you can get away with. Generally with through-hole connectors, they'll actually be like connectivity that goes through the actual pin. So if you put a little pressure on what you're putting through it, so kind of lean to the left or right, that'll be to get good contact. And I did it here with a twist tie or that's some sticky tack. And obviously, soldering is your best option, but I don't want that to be a barrier to, you know, hacking IoT if you don't have a soldering iron or to solder. So this can be done in a pinch. If you're running on a Linux host, I mostly just included these commands here for people that are going to be taking these slides afterwards. But all we need to do to actually get a shell or connect to the device is we need to just check and see what the device ID is for our USB UART adapter. So we can do that with this command, and you'll get the device ID back. It'll most likely be TTY USB 0, but it could be 1, 2, 3. And then we can just launch a terminal emulator and use that to get a UART connection. When you're starting out, I suggest using screen because it's the easiest one. There's lots of other ones, picocom, minicom, putty if you're on Windows, they're all fine. But screen, in my opinion, is the easiest one. It requires very little setup. The only two arguments you need is that USB device ID that I showed before. And then you'll notice the last thing here, I've got a number 115,200. That is the baud rate or speed that the UART is communicating at. And since this is no BS, no filler talk, I'm not even gonna explain what baud rate is. On 99% of IoT devices I see, it is 115,200. So you can just use that. If it's not, it's probably 9600. And if it's not that, you're probably doing something wrong. There is also a very common list on Wikipedia you can look at of other ones, but it's pretty much going to be 115,200. Okay, so if everything worked with your connection, you got screen running, you power on device, you should start to actually now see those boot logs that we saw with our multimeter actually start streaming through. And do not discount the importance of actually reading through those boot logs and seeing what they are telling you. They're going to give you lots of versioning information that could be enough to even find a vulnerability on its own, seeing that it's using underlying libraries or things like that that are outdated and someone's already done the leg work and found a vulnerability in those. We'll also give you details in this one, for example, near the bottom, showing all of the partition details about the flash EEPROM that's on it. And that's going to make it a lot easier for us later to identify the different parts of the firmware. After the boot loader goes through and it's done streaming through the text, you can hit enter. And a lot of times on cheap IoT devices, that can be enough to just get a shell, they don't lock them down with a password or anything. So then we'll be in a root shell. Generally in embedded Linux, everything just runs as root, there's no like least privileges or anything, you'll just get a root shell. Again, like in the manufacturers, they're not as concerned about this as being a specific vulnerability. So I wouldn't recommend reporting this or anything, because they already know about it, they just don't necessarily care. But we're going to abuse that to find something that you care about. The majority of the routers and smart cameras, they're running embedded Linux. So that's where it's gonna make it easier to get that shell. Okay, so I always mentioned this, because you know, in cybersecurity, I feel like we all want to get a shell, everyone loves getting shells. And sometimes that's like, the end all of what we're doing, if we're doing like web app, or you know, other different types of network pen testing. But for us, actually, connecting to the UART, it's more important for us to see the logging, that's actually what we're more we're more interested in, or at least I am. So if you don't get a shell, that's okay, if you're not able to get in, that's fine. So sometimes there'll be a password, if there is, there's ways around that, we can maybe get the hash from the firmware, or Google it. But even if you can't get a shell, that's okay. The way that UART works is like, you don't need to authenticate or log in, it's a very like low level protocol, it's just going to stream those logging bits out to you, no matter what, you don't need to log in, or anything like that, you can still see the logging, unless the device like syncs or tanks the UART, which most don't. So I just got some pictures here showing some interesting things I see in logs, one of them here is just showing the location of RSA keys as it's setting up DropBear, it's common SSH protocol. And then the other two ones are interesting logging details about when I was actually interacting with the device and showing what could potentially be command injection, or one is just showing how it sets up and saves the pre-shared keys and SSIDs for a router. So if you are lucky enough to get a shell, I mean I was saying it's not as important, but it is always nice to get one. We'll be good hackers then and do our enumeration, so start poking around. Best places to actually start looking are the Etsy folders and the VAR folders, those are probably some of the places where you'll find like interesting configuration details and things like that. Some really quick wins are things I look for, their passwords, hard-coded keys, is there endpoints that maybe they don't want to expose or that we could see that's reaching out into the back end. And of course a lot of times you'll have like things like PS or Netstat, so you can see what processes are running and what network connections are going out, so that can give us a little bit of a lay of the land around the device. Okay, so at this point you know we've got our device, we've got our equipment, we use our equipment to find our debug interface. What's the next step? That's going to be to get our hands on the firmware and in my opinion this is where my favorite part starts and where we can start having some fun and find some vulnerabilities. If you're not familiar with what firmware is, this is essentially the software that is running on the device and we kind of call it firmware and differentiate it from software in that it's kind of designed specifically for that device so that that device can fulfill one function. It's not really changing, you're not going to like install any software or anything on your router or smart camera, you just get that one piece of firmware. In embedded Linux that we're talking about today, the firmware is generally comprised of four main parts. We've got the boot loader that's responsible for actually like bringing up the device on boot up, loading up the kernel. We've then got the Linux kernel itself, that's going to be one partition. We've then got the root file system, so that's actually where all of the interesting stuff is make the device do what it's going to do. All of the binary scripts, configuration documents, all that stuff is going to be in the root file system. We'll then possibly also have some sort of partition where we can store a little bit of writable data. So we'll generally want to hunt for this as well because that's where you're going to find things like passwords that users configured or like the maybe pre-shared key for their wireless or all that kind of stuff. So a lot of times you'll see that at the end of the flash memory. The root file system has the most goodies though by far, so that's all we're going to focus on today. You can find vulnerabilities in the other places in the boot loader and kernel, but when you're starting out we'll just look at the root file system and its contents and that's honestly where you'll find the majority of vulnerabilities anyway. So there's three main ways that I usually get my hands on the firmware. There are a few other ones that are more complicated, but the easiest one is a lot of cheap IoT manufacturers. They just put their firmware available on the internet from the vendor to download. The reason for this is that unfortunately they don't put any type of update mechanisms into their device, so they kind of pass that responsibility down on to the end users if there is security patching or things like that to go and, hey, make sure you go to our website, check it every day, download the firmware, and then put it on the device yourself, which I think unfortunately I'd say like 99% of users don't do. But to fulfill that obligation they put the firmware on their website on the support page and you can just google and find it and I love that because it's super easy to get our hands on the firmware. And if you do that then you can even do IoT hacking for free. You don't even need any gear, you just download the firmware. The second way is if you did get a UART shell, I would say 90% of the devices I see they have TFTP on them, so that's Trivial File Transfer Protocol. This is there because it's actually baked into the functionality of a lot of those update mechanisms. So if you have a web app or a browser or something and it allows you to do a firmware update through that, in the backend it uses TFTP, but we can abuse that or borrow it to set up our own TFTP server and then we can just bring back files of interest or if we're patient enough we can just bring the whole root file system back to our device over that and then we don't even really need to worry about dumping the firmware. And then the last one which sometimes you'll need to do is you'll just dump the firmware off of the device. So in these cheap commercial IoT devices I'm suggesting getting started on, they almost always use an 8-pin SPI flash chip and these always follow the same pinout and we can use our flash reader that I suggested getting or the TiGuard to really do a really quick read of these and we don't even need to usually take them off of the device, you can just read them in-device, in-circuit. And the way to do that is I generally recommend using FlashROM's free open source software that's great for interacting with flash chips. So again, command here for reference if you're just wanting to follow along later, but if you get a CH341A programmer which is that $10 one that I recommended from the start, you can just run this command after you put the clip on and it's as easy as that. There's also other test clips you can do to use it, but it's pretty straightforward. It lists the different pins that match the pins on the chip. You can just google standard SPI 8-pin flash and you'll see all of the pins. There's six of them that you need to use out of the eight pins. Just a heads up, so if you did get the TiGuard, you can do this with the TiGuard. Okay, so we've all this, basically everything we've been doing up until this point now has been to set us up for successful reverse engineering of the internals of the device to figure out what's going on and to hopefully find some vulnerabilities. So that's what we're going to be taking a look at now. And so one thing you can do too, if you don't want to spend any money, is you just can go and find the firmware for download and then you can do the majority of these steps as well and then you haven't even spent a dollar. Or you could also try and emulate the firmware as well. It's not something we're going into today, but I just want to give that a call out. Like if you can't get your hands on a device, you don't want to spend any money, you just kind of want to get started, you can do it for free. Just get your firmware, try and reverse engineer it, and emulation is your friend. Okay, so the first thing we do once we get our hands on the firmware is it's generally going to be in like a kind of like a blob format. So generally it's going to be in like a .bin file or binary file or maybe a hex file, possibly a .img, but it's not going to be probably readable for us at that point. So we need to go ahead and actually unpack that firmware into the different sections and files that are actually in there that we'll be able to interact with better. So the very first thing we're going to do is cross our fingers that it's not encrypted. So again, this is why I'm recommending when you're starting out, go for those cheaper devices, because most likely they're not going to use encryption for their firmware because it costs money both in software development and R&D, but also you're most likely going to need to spend a little bit more on hardware to actually rely on that to handle that decryption at the startup. If you do come across encrypted firmware and you're just getting started, my suggestion would be just save that device for later down the road. It's not like it can't be defeated. There's lots of attacks and things like that that we can do to try and defeat the encryption and find the keys obviously when it's booting up, it's going to need to actually do that decryption and we can possibly read the keys, but it's a little bit more of an advanced topic. So I'd save that for down the road after you've done a few and go and find another device and see if you can make sure that its device is not encrypted. So how do we check if it's encrypted and also how do we get the contents of that? We will use a utility called Binwalk. So there's a bunch of tools to do this and various ones and you can take a manual approach, but the easiest way is to just go ahead and use Binwalk. If we pass it two options, the capital M and the E, it will just recursively go through and anything it identifies that it can pick up as a file type that it knows, it will try and uncompress that or unzip it or whatever until it gets down to the actual it knows the file types, whether that's a binary file, a shared object, XML, whatever. And the E is telling us to extract it actually. So if you just run Binwalk without any commands, it'll actually just tell you what it sees. And then if you pass in the E, it'll go ahead and try and actually break those down. So awesome tool. It does a lot of the legwork for us. Alternatively, we saw that we had those different partitions already actually listed out for us in the boot log. So you can use DD as well if you want a manual approach just to carve it up. And sometimes you have to, but Binwalk is your friend. It works most of the time. Okay, so this is where the fun starts. So now that we've got the firmware, we're going to go and actually focus on the root file system and see what we can find. So some really low-hanging fruit is just to look for the configuration files and poke through those, see if we can find anything that shouldn't be in there. So a lot of times when I'm teaching IoT hacking, people are surprised to see, but the best tools I think are just some of the really easy basic Linux tools like Find, Strings, and Grep. They go a long way with IoT hacking. And we can use Find with the dash name argument and I like to just do like star dot extension. So I'll do star dot xml, star dot text, star dot json, and I'll just go through that and read through those documents. A lot of times see xml and sometimes they have interesting details in there. That's some low-hanging fruits. We can also use Strings. So this is a tip that I teach. If you use Strings with the dash f, the dash f tack on it, it'll bring back the file name that's attached to that string. And then we can run Strings over like a whole file system or a whole group of files. And then we can pipe that into Grep and look for things like password, API, key, all of those things. Sometimes I'll look for like .com, for example, or various TLDs just to see if we can find any endpoints. And that can just be an easy win as well using Strings and piping it into Grep. It's one of my favorite tricks when IoT hacking is to do that. The next thing we'll take a look at that is pretty easy because same with the readable files. All of the scripts, so a lot of times since it's embedded Linux, it's going to be Bash or SH scripts. You don't need to decompile them. You can just take a look at them, read through them. A lot of times the developers will put really nice comments in there telling you what they're doing because they're being good developers and putting comments and things like that. It's funny, I've seen even things like people's emails or like, you know, if you find a problem with this, email me at this email or things like that. But the one scripts that I always suggest that you should look at right when you're getting started with a device and looking at it are the RCS scripts. So most IoT devices use a tool called BusyBox, which is a way to actually combine all of the binaries into one binary to shrink them down. And then they use their init process. And the way that BusyBox works is it runs all of the RCS scripts in Etsy slash init.d. So after the bootloader is finished and Linux is done, it hands off to the BusyBox init system. And then it calls all of the scripts in there that start with RCS. And it does them in alphanumeric order. So it'll go like RCS one, two, or if you have like sometimes you see like one and it tells you what they're doing. And these scripts are great because they're responsible for actually setting up the device past Linux for what it actually does. So if it's a camera, or router, then it's probably going to, you know, bring up binaries or things like that, to actually do what the device does. Or sometimes they'll even reach out to like, back end infra or cloud infra to let it know what's up or pass back information. And again, these are human readable, like they're just bash scripts. So no decompiling, no real reverse engineering. And another tip too, is if you're not familiar with bash, like, honestly, chat GPT is really great at breaking down what bash scripts are. So you can just copy and paste these directly as firmware into our friend chat GPT, and it can help you out and tell you what's going on as well. Yeah, I frequently don't really find specific vulnerabilities in here. Sometimes you'll find things that shouldn't be in there. But most of the reason is just to get a lay of the land. And it'll tell you about like, what's going on, what binaries are being executed, things like that. Okay, so now we're at, in my opinion, the most fun part. And kind of like everything, even the other stuff before that has been leading up to setting ourselves up to be successful at reverse engineering the binaries and libraries that are on the device. So this is where you're honestly most likely to find some sort of vulnerability that you're going to report. And the one complicated or thing that I see people get stuck with on this is, where do we actually start? It's quite possible there's dozens to hundreds to maybe a thousand different libraries and binaries on the device. It takes a lot of time to reverse engineer and understand these. So which one do we pick? And how do we start? So the easiest way to actually do this is to avoid a needle in a haystack situation is to go with like a forward down approach. And this is what I teach or the methodology I teach when people are starting. And that is to start with the custom binaries and libraries that are actually unique to the device. So a lot of the libraries and binaries are going to be Linux stuff. So if you're familiar with using Linux, you might be able to just discount quite a few of these. But if you're not, or sometimes it could be hard to tell, especially with libraries, are these open source Linux things that do Linux or C stuff? Or are these ones that the designers of this device have actually created? So then we run into the problem is, how do we know they're custom? And after you start to do this for quite a while, you will start to pick out the names and stuff and go like, oh yeah, that's a custom one. But if we don't, then the thing that I suggest to do is to interact with the device and then follow that logging and trace that logging down to the underlying binaries and functions. And this is, in my opinion, the easiest way when you're starting to actually find vulnerabilities. So here in this picture, I've got an example. So this is a common router here that I like to hack on. And I went to the web browser of it. So just like most routers, it's got a web browser where you can go on, do lots of stuff, set the pre-shared key, set what type of... if it's WPA2 WAP or whatever, you know, set all that stuff. It's got a bunch of utilities. For some reason, it's got a ping test thing. You can make the router ping other stuff. So in this example, I'm just playing around with that because I kind of suspected that it might be, you know, doing bad things when we try and ping stuff. And so I wanted to find the underlying binary or function or library that's actually responsible for that. So what I do is I just go and play with all the functionality. If there's something that you can do on the device to make it do something, I do that. And I don't specifically do that, like trying injections or anything. I just, when I'm starting out, just use the device how it's supposed to be used. And I'll take a look at the logging. And a lot of times the logging will be very verbose in IoT devices when you're interacting with things. And then we can actually trace that logging back then to the underlying binaries or libraries. So in this device, and I actually see this in a decent amount of IoT devices, they were nice enough to even just put the function that's actually being called when you try and run this ping test. They put it in square brackets. That's their like logging nomenclature or whatever. So it was called util underscore exec system. So when I saw this immediately, and if you're familiar with like, you know, web pen testing or something like that, immediately looked like it was making a system call to me. And then they put a bunch of details in it, like they actually give us how the command is being formatted. So I didn't get to put the whole thing because I was running out of room. But if you can't see it, it literally says, OAL start ping, command is IP ping dash C, and it gives the whole details. And in that, you can actually see the IP address that we put in. So it definitely is kind of like giving us a hint that there's possible command injection or something we should look at deeper there. Okay. So now we have an idea that that function, that util underscore exec system is of interest to us. It could be a potential injection point. And what we should do is, you know, on the past page or like when we're doing that, like I will interact with everything I can and take a note of where all the logging is happening, what binaries and functions that logging is coming from. We'll just go back to our good friend strings piping into grep, one of my favorite tools for IoT hacking. And we can grep on that function name. So a lot of times in less expensive IoT devices, again, they're making it easier for us. They don't strip binaries and things like that. So the function names will just end up in the compiled binaries and libraries. So we can just pipe that into grep and put the function name in. So in this example here, I did that for util exec system. However, what if they do strip it? Well, if we just go back one page here, you can see the printout here. It kind of follows a format. It says OAL start ping command is and then gives the command. So that's a string that's actually in there too. And they're probably not going to obfuscate it because it's not malware. So we can also just pipe common strings that we see. So in this example, I kind of thought it was using like a print app or sprint app or something like that. So we look for a command is and we get the same hit. You can see here that actual string, how it is in that binary is %s command is %s. So it's using that formatting. So even if they do strip the function names, there's still ways to get around it and find those underlying binaries and libraries. Okay, so now that we've got our function name, we know that it's in that. So if I just go back in this one, for example, we see the hit because we use dash F. It's in this libcmm.so. So that is a custom library that the makers of this router in this example wrote that has the majority of the functionality of that router baked into it. We can pop that into Ghidra and start decompiling it. So one of the things that I find when I'm teaching IoT hacking or in my workshops is like this is the point where people usually get a little bit overwhelmed if they're not familiar with reverse engineering. And it starts to look quite complicated because the output of Ghidra can be very verbose. When it decompiles it, it is, in my opinion, a little bit more complex than just looking at regular C code. So it can be a little like discouraging. And I see some people are like, okay, I can't do this. I'm intimidated by it. But I have a few tips that I think can make it a lot easier for you to understand and read the output in here and still find vulnerabilities, even if you don't understand what the heck is going on and most of it doesn't make sense. So the very first thing I always say is because people who are in cybersecurity and have had a little bit of an intro to Ghidra or reverse engineering is it's usually looking at malware. And this is not malware. So with malware, usually good malware authors or majority of them are going to try and obfuscate what they're doing, make it confusing for reverse engineering. They're not going to use print statements. If they have strings, they're going to obfuscate those strings that are very hard to see. Instead, for IoT devices, we have developers who are trying to be good, helpful developers and write very clean, readable code so that it's easy for someone else to pick up after them. If someone's reading their code, it's going to be testable, debuggable, doing all those good things that developers do. And also in IoT devices, we do a lot of printing out to UART to tell what's going on so that we can actually do almost debugging through print statements in a production device, which is nice. It makes it really easy for us to then go and trace those back. So one of the first things that I always suggest with that in mind is to take a look at the print statements and let those guide you to what is going on. Of course, you can't always trust print statements. If you're a programmer, you know that it's not the best to always trust comments or print statements. But when you're getting started reverse engineering, I think it's okay. Just read the print statements. The very first one that I have here that's in red, it's just actually that print statement that we saw in the logging. So it helps us confirm that we're in the right spot. And then if you look down at line 32, it might be a little hard to read, but essentially what it's saying there is it's just saying system fork failed. And this, we don't care about that. It's not important to us. But if you look at the program flow and the if statements, well, now you know what that program flow does. It just checks if a system fork failed. Because before that, it says, you know, if local 234 equals FFFFFFF. Well, if I saw that, I have no idea what it was. Is it integral to the thing? Well, if you look at the print statement, it tells you exactly what it is. And you can just ignore that. The second thing you can do with print statements that makes your life a lot easier is a lot of times they'll be like printfs or sprintfs. And if you're not familiar with how those work, essentially we have a slot holder for a variable that we're going to pass into that print statement. And then the print statement basically tells you what that variable is. So in this top example here, we have the percent command is percent. And then we have two variables passed in that, you know, we wouldn't know what they were. One's param1 and one's underscore underscore S. Well, if we look and, you know, we just go back a couple to that print statement. Well, the first one, this is that identifier OAL underscore start pin command. So we know maybe that's like some sort of identifier. And then the second one, though, now we know of our interest. Well, that's the actual string that we manipulate, that we can pass the IP address in. And because of that sprintf or that printf function, well, now we know that underscore underscore S variable. We know what it is. And that's just through those print commands. The next thing I'll call out, or that's kind of like the final thing that we've been working towards, is to just start getting used to seeing unsafe things being done. So the easiest one to actually find is system command. So you can see that's in the second square there. We have a system command. And if you're not familiar with that when you're programming C, essentially, that's a way for you to just pass down to Linux to say like, hey, I want you to run this shell command. So it's essentially the same as if you're at the terminal and you type in, if you have a shell, whatever you pass into the system, it's the same way. So if you're not already thinking this, this is an extremely dangerous thing to do in your programming if you're using user variables, and especially if you're not going to be sanitizing those variables. So in this one, for example, this util underscore exec system function that they've written to make it easier to do system calls, it does no sanitization or checking. However, in this example, the caller of that, that actually initially takes in that IP address, well, it does do the sanitization. But if you look on this device, for example, there are about 500 calls to this util underscore exec system. And the person that wrote that function, this util underscore exec system that knows, okay, I need to sanitize my inputs further down the chain, they might not be the same ones writing the code. So you can actually see how it can happen to slip through where user-supplied input gets into a system call. So that's one of the easiest things when you're starting out is to just go interact with the device, chase down the inputs that you do because you know, and see where do they end up in the code. And if they end up in a system call, then I really need to look into this deeper and see if there's a way that I can do some sort of command injection. So of course, what's next after we know this? Well, we keep interacting with the device and tracing the logging back to binaries or libraries. So of course, there's other ways to approach this. You could just start with the library and look at all the system calls and go backwards. But when you're getting started, I think it's a lot easier to understand and conceptualize and not get lost in Kedra to try and start at the source, which is how we interact with it. And we know that there's like an injection point there, and then see if that actually filters down to something. So don't just use web browsers, like a lot of IoT apps, they have a mobile or IoT devices, a mobile app. So we can go use that mobile app, like do everything in the mobile app, do all the setup, check all of that, because it's going to be like a lot of times one of those lesser used places where there's some obscure setting or something you can set. Do all of that and see what logging you can get and trace that back and see where it goes. Like one example I found where I was able to crash a device is it was a camera. And if you wanted to pair it to your mobile app, you put the QR code up to the camera, and you compare it to the mobile app. And I was never able to like get any buffer overflow or anything, but I was able to crash the camera by doing like a malformed QR code. So just be creative. If there's cloud, like somewhere you can sign up in the cloud and then interact with your device, do that. Like usually there's a free 30 days or something. And you know, we're not actually pen testing the cloud thing, we don't want to be like trying to break that, but just interact with it how you're supposed to, and see how that filters down into the device. And then what we're looking for is when you're starting out, there's two main things I suggest to look for. So the first one is what we already looked at. Does it end up in an unvalidated or unsanitized system call? And like if you look at this router and go back and look at the CVs for this one I'm showing, or lots of IoT devices, you'll see lots of command injections being done. Because in cheap IoT devices, they want to save money, they don't want to write their own functionality. It's way easier to just use the built-in stuff in Linux and just hand it off to a system call. So it's not like these don't exist, you can definitely find them. The second one that's probably a little bit more common, but a little bit harder to find and abuse, is if your user input gets put into an unsafe C function. So there's a few examples of those are memcopy, stringcopy, stringcat, printf, that next one's supposed to be sprintf, getscanf. So essentially what these are doing though is they're going to be copying your data into some sort of buffer. And again, memory is limited on IoT devices, so we're always trying to be kind of stingy with our buffers. And a lot of times, if you're not sanitizing or validating those inputs, then it can end up in a buffer where we can overflow it and, you know, at the worst case, buffer overflow, or maybe just crash the device and have some sort of denial of service. So I could give a whole other talk then about where to go from here and how to actually then abuse these or actually exploit buffer overflows. But if you do get this far and you find this and like you'll be able to maybe crash the device or get some segfaults or something, then send me a message or just go out and do some further research. And there's a lot of great resources then for how to identify these buffer overflows. So that's where I'll end today. I just want to wrap up with a thank you. Thanks everyone for coming. I hope you learned something. I hope you go home and go buy a cheap IoT device when you get home. Hack it. If you do, let me know. I love to hear when people hack it. And if you want a copy of these slides, stay in touch with me. Link up, resources, anything. You can reach me at andrewbellini.com. Thanks everyone.