[00:00.000 --> 00:07.360] Welcome everyone. My name is Andrew Bellini and I am here today to both convince you and show you [00:07.360 --> 00:13.200] that anyone can hack IoT devices. So in the talk today, I'm hoping to both convince you that and [00:13.200 --> 00:18.580] I'm also going to walk you through a methodology that you can go take home, buy a cheap consumer [00:18.580 --> 00:24.000] IoT device and hopefully hack it. Before we get into the actual specifics of that, I actually [00:24.000 --> 00:31.540] just want to start with a really quick joke. And that joke is the S in IoT stands for security. [00:31.540 --> 00:36.160] Has anyone heard that joke before here? It's one that I hear. Yeah, I see some people are hearing [00:36.160 --> 00:41.960] it. It's one that I hear tossed around the cybersecurity community. And usually when I [00:41.960 --> 00:47.780] hear that joke, it's actually by folks that don't work specifically in IoT or embedded security. [00:47.780 --> 00:53.780] But as someone who actually has a background working in industrial IoT devices and embedded [00:53.780 --> 00:58.760] devices, I won't say I'm not salty about it. I'll actually put my hand up and be the first to say [00:58.760 --> 01:05.000] that it is a well-deserved joke. So the thing about that joke is, and we can all, you know, [01:05.000 --> 01:10.640] have a laugh at IoT devices and their lack of security, but the reality is if you, you know, [01:10.640 --> 01:16.480] check out and look at how many estimates for IoT devices there are connected in the world right now, [01:16.480 --> 01:20.600] you'll see greater than 15 billion, you know, estimates. That's almost two per person [01:20.600 --> 01:27.360] of IoT devices. And in addition to that, we're expecting there to be a big surge of IoT devices [01:27.360 --> 01:32.940] because of AI and machine learning, how they're going to be used for edge devices. And it's [01:32.940 --> 01:40.640] estimated looking at the projections, there could be 30 billion by the end of the decade. So that is [01:40.840 --> 01:45.460] a lot of things to secure. And these are everywhere. So it's not like they're just in our [01:45.460 --> 01:50.940] households from, you know, smart cameras to even smart toilets. These are also in critical [01:50.940 --> 01:58.620] infrastructure. They're in our cars. They're essentially everywhere nowadays. So one of the [01:58.620 --> 02:03.060] things that I kind of thought when I was starting to get interested in IoT security is there's so [02:03.060 --> 02:08.620] many devices. And in addition to that, there's this agreed upon kind of thing in the security [02:08.620 --> 02:14.860] community that IoT devices are not secure. So I figured there would be a lot of people doing IoT [02:14.860 --> 02:20.880] hacking. And the cyber criminals are definitely taking advantage of this. They love finding [02:20.880 --> 02:26.500] vulnerabilities in IoT devices and adding them to their botnets or using them for initial access. [02:26.500 --> 02:30.800] But my experience was in the ethical hacking community when I started meeting hackers and [02:30.800 --> 02:36.160] things like that and asking them if they hack IoT devices, a lot of times the answer was no. [02:36.160 --> 02:41.240] And that was kind of reaffirmed today too. I've had a booth here where we've been doing IoT hacking, [02:41.240 --> 02:44.820] and I had mostly beginners who had never done it. And it was awesome to teach them that. [02:46.220 --> 02:50.920] So one of the things that, you know, when I ask people, why aren't you doing IoT hacking, [02:50.920 --> 02:56.960] there's a few misconceptions that I hear about it. And I just want to try and dispel some of those. [02:56.960 --> 03:02.360] So the very first one is that it's too expensive. So you need to buy expensive gear, you need like, [03:02.360 --> 03:08.420] you know, an oscilloscope or like a microscope or expensive tools to get into it. When you're [03:08.420 --> 03:12.340] starting out, and this is a reality, you're probably going to need to buy the devices you [03:12.340 --> 03:18.060] want to hack on. And then addition, there was really a large lack of affordable training. [03:18.220 --> 03:23.460] When I was looking to learn even, you know, five years back, it was like $5,000 for a course, [03:23.560 --> 03:29.680] a lot of them were in person. And then the second misconception I hear is that it's very complicated, [03:29.680 --> 03:33.600] you need to like have an engineering degree, you need to know about electronics, you need about [03:33.600 --> 03:39.540] hardware, circuits, all of that stuff, you need to know about special protocols, in addition to just [03:39.540 --> 03:45.860] the normal things that you need to know about hacking. And in my opinion, you know, some of [03:45.860 --> 03:49.800] these are true, there is some truth to it. But I actually think there are ways that you can actually [03:49.800 --> 03:56.500] learn to hack IoT devices, commercial IoT devices off the shelf, without spending that much money. [03:56.500 --> 04:01.160] And there's a lot of great resources to learn how to do it for free or for very limited amounts of [04:01.160 --> 04:06.700] money. Okay, so I've been chatting for a little bit, I just wanted to give a quick intro to who [04:06.700 --> 04:12.880] I am and why I know a little bit about IoT and IoT security. So my name again is Andrew Bellini, [04:12.880 --> 04:18.680] I go by Digital Andrew on the socials. My background is actually in electrical engineering. [04:18.680 --> 04:23.800] So before I got into cybersecurity, I did a lot of work actually designing embedded devices and [04:23.800 --> 04:28.920] industrial IoT devices. So that's a little bit where I learned about it, not specifically in [04:28.920 --> 04:35.020] security, but just actually, you know, designing the devices that we use. I now work as a content [04:35.020 --> 04:41.400] creator at TCM Security. So there I am the creator of our IoT hacking course. It's a beginner's IoT [04:41.400 --> 04:47.220] hacking course, and I also created our Practical Junior IoT tester certification. And if you do [04:47.220 --> 04:50.760] want to link up with me, you want a copy of these slides, you want to see what I'm working on, [04:50.760 --> 04:54.520] I got lots of free blog resources or anything like that, check out my website. [04:56.460 --> 05:02.120] So a little bit of motivation for this talk. I have one specific goal, and that is to provide you [05:02.120 --> 05:08.640] with a methodology, specific tools, and knowledge to find vulnerabilities, aka hack, [05:08.640 --> 05:14.360] in commercial IoT devices. And I have a couple messages here from some of my previous students, [05:14.360 --> 05:18.320] just to give you some motivation and also proof that this methodology works. So I had [05:18.320 --> 05:22.460] one student, he actually just messaged me a couple weeks before DefCon, and I was super excited to [05:22.460 --> 05:27.920] see this. I didn't know him before, but he said, I took your course, and he had, you know, chatting [05:27.920 --> 05:32.500] with him. He had never done any IoT hacking. He took my suggestion, he went and got a cheap [05:32.960 --> 05:38.280] smart camera off Amazon, and he actually was able to find three vulnerabilities in it, got in touch [05:38.280 --> 05:42.340] with the vendor, and he's got three CVs coming. So super excited for him about that. And then [05:42.340 --> 05:46.180] there's another message, this person didn't want me to put their name up, but he took my course as [05:46.180 --> 05:51.200] well, and then he bought a cheap router, and he found a remote code execution vulnerability in it, [05:51.200 --> 05:55.580] and I just was chatting with him about how he could submit that to a CNA, because the vendor [05:55.580 --> 06:01.540] didn't want to talk to him about it, but how he found a vulnerability. So this chat is for everyone, [06:01.540 --> 06:06.920] 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 [06:06.920 --> 06:12.400] curious, as I say, this talk is specifically catered to people who are new or just curious [06:12.400 --> 06:18.980] about IoT, and it's going to assume you have limited or no experience with IoT or embedded systems. [06:20.020 --> 06:24.340] So just a really quick agenda of what we're in for today. We'll start with some, really quickly, [06:24.340 --> 06:29.400] and legal considerations. We'll then talk about what device you should actually pick [06:29.400 --> 06:33.680] if you're getting started on. So if you want to go home and buy something off Amazon, what you [06:33.680 --> 06:37.840] should look for, if you're going to go dumpster diving, for example. We'll then talk about how [06:37.840 --> 06:41.660] you can build out an affordable toolkit, and what stuff you should buy, or what stuff you should [06:41.660 --> 06:46.340] avoid, and how to not, you know, break the bank doing this. Then I'm going to take a look at [06:46.340 --> 06:52.060] locating, using, and abusing hardware interfaces. We'll then talk about acquiring firmware, and then [06:52.060 --> 06:56.400] after that we get our hands on the firmware. We'll talk about analyzing and reversing engineering it. [06:56.720 --> 07:00.600] So just a really quick staying out of trouble. This is kind of like the golden rule of ethical [07:00.600 --> 07:05.520] hacking, in my opinion. Only test devices that you're authorized to. And then this is my personal [07:05.520 --> 07:10.420] suggestion, since I am giving a talk about potentially how to go out and find CVs and [07:10.420 --> 07:15.640] IoT devices, but I always recommend being ethical and following responsible disclosure if you do [07:15.640 --> 07:21.060] find things. Unfortunately for a lot of IoT devices, they don't have bug bounty programs, [07:21.060 --> 07:25.680] but they do have responsible disclosure, so you can at least report it, get some credit, and get a [07:25.680 --> 07:30.240] CV that way or something. So last one's up to you, but you know, I would implore you to go that route [07:30.240 --> 07:36.080] if you find something. Okay, so I did want to just give a little chat about staying safe, because [07:36.080 --> 07:40.740] sometimes I give workshops or things like that, and I teach people about IoT and hardware hacking, [07:40.740 --> 07:44.780] and they're a little bit nervous about opening up a device and working on the hardware of it. [07:44.780 --> 07:51.400] So the first thing I will say is IoT hacking is in itself very inherently safe. So hardware [07:51.400 --> 07:56.980] hacking on commercial IoT devices, and that's really if you just only follow one basic rule, [07:56.980 --> 08:01.100] you'll be fine. And that rule is that you should never work on anything high voltage. So when you [08:01.100 --> 08:05.540] open up the device, you're working on it, most of these devices are going to be like 12 volts, 9 [08:05.540 --> 08:11.180] volts, 3.3 volts, 5 volts operating voltage. All of those are, for the most part, safe to work on. You [08:11.180 --> 08:15.820] won't even feel it if you touch it. The voltage from our walls and our house and stuff, that stuff [08:15.820 --> 08:20.120] can really hurt you. So just stay away from that stuff. Just work inside your device, you'll be [08:20.120 --> 08:25.160] fine. Never use any damaged or modified power supplies, because that's how we can accidentally [08:25.600 --> 08:30.400] introduce those higher voltages into the device, damage our device ourselves. And then this last [08:30.400 --> 08:35.200] one is more about keeping your devices safe. But when I give workshops, I see people doing this [08:35.200 --> 08:40.000] all the time. And this is the most common way to brick or fry your device. But if you have it open [08:40.000 --> 08:44.980] and you're working on it, then that's not how the manufacturer intended you to be using it. And if [08:44.980 --> 08:49.620] you're plugging in clips or wires or things like that, if you have it powered on, it's easy to [08:49.620 --> 08:53.780] bridge something and do a short circuit. And that's the easiest way that I see people who are learning [08:53.780 --> 08:58.740] fry their device. So it's just really good practice. If you're not using it, turn it off, [08:58.740 --> 09:02.500] plug anything in you need, then turn it on when you're done. And if you need to unclip it, [09:02.500 --> 09:05.860] you power it off, then you work on it. And it's easy to forget. I'm always walking around [09:05.860 --> 09:10.380] in the workshops warning people of that. Last thing I just want to give a really quick shout [09:10.380 --> 09:15.120] out to because people have gotten seriously injured from this or hurt doing this. You [09:15.120 --> 09:18.680] aren't really going to counter these IoT devices. But if you take your hardware hacking skills that [09:18.680 --> 09:22.560] you learn from this to other things that have larger power supplies, is watch out for large [09:22.560 --> 09:28.020] capacitors because these can actually pack a punch as far as the amount of energy they store. [09:28.020 --> 09:32.760] And also some people don't realize but when you unplug these devices or capacitors from the wall, [09:32.760 --> 09:36.780] they can hold their charge for quite a while. So you may think you're safe, but they can zap you. [09:36.780 --> 09:41.340] This is not common in pretty much all IoT devices. But I just say this because a lot of people have [09:41.340 --> 09:45.700] this misconception if it's unplugged, it's safe. But if there's large capacitors, that's not the [09:45.700 --> 09:51.700] case. Okay, so now that we've got all of the preamble and everything out of the way, we can [09:51.700 --> 09:56.460] get on to, you know, kind of my methodology for how you can go home, get a cheap consumer IoT [09:56.460 --> 10:01.020] device and hack it. So the first thing to do is actually to pick the right target if you're [10:01.020 --> 10:06.920] learning. So I always suggest the cheaper the better when you're starting to learn. And there's [10:07.040 --> 10:11.820] a couple reasons for this. The first one is, and this isn't always the case, but usually you get [10:11.820 --> 10:17.980] what you pay for in terms of security and also hardware security. So on cheaper devices, you [10:17.980 --> 10:22.900] generally won't run into limitations on the hardware where the debug ports are locked down [10:22.900 --> 10:28.260] or the firmware is encrypted. And then the second one, which kind of goes with my second point here, [10:28.260 --> 10:33.720] is I never hack anything that I don't mind bricking or destroying. And if it's a cheap [10:33.720 --> 10:37.840] device, then you're not going to be as concerned or upset if you fry it. And, you know, I'll raise [10:37.840 --> 10:41.940] my hand and say I still, you know, fry or brick devices. It happens. I've been hardware hacking [10:41.940 --> 10:47.260] for a long time and it still happens. And if you're a follower of Joe Grand, for example, probably one [10:47.260 --> 10:52.160] of the most famous hardware hackers, he gave a talk a few DEF CONs ago. He literally just [10:52.160 --> 10:57.500] talked about all of the devices that he had bricked over the years. So it happens to all of us. [10:57.500 --> 11:02.520] If you're looking for a specific type of device, my suggestion is to go with cheap routers or cheap [11:02.520 --> 11:07.120] smart cameras. They're great to start on. They usually have vulnerabilities that you can find. [11:07.120 --> 11:12.880] And also, more importantly, they almost always run embedded Linux, which in my opinion is a much [11:12.880 --> 11:17.440] easier type of device to hack on when you're learning than something with a microcontroller [11:17.440 --> 11:23.080] like ESP32 or STM32 that's going to be running RTOS. Those are a little bit more advanced or [11:23.080 --> 11:27.420] harder when you're getting started. And I will give another shout out to dumpster diving. So [11:27.420 --> 11:33.520] on this picture here, this is one of many bins I have at my house that are just full of old devices. [11:33.700 --> 11:37.580] And I just kind of put it out into the universe, like my friends and family know that I'm this [11:37.580 --> 11:42.400] dude that likes hacking weird electronic stuff. So if they're throwing away their router or camera, [11:42.400 --> 11:48.260] then they ask me, or I find them in like disposal bins or whatever, I can't resist. So it's a great [11:48.260 --> 11:51.700] way to learn though, because usually these devices work fine. People are just, they're obsolete or [11:51.700 --> 11:56.980] whatever, but they don't have to worry about bricking them or anything. Okay, so once we've [11:56.980 --> 12:00.960] got a device, hopefully it's a smart camera or a router or something, we've got to acquire a [12:00.960 --> 12:06.200] little bit of gear to go along with this methodology. So I've got a couple of rules for [12:06.200 --> 12:09.420] that. The first one is we don't want to break the bank when we're starting out. You might not know [12:09.420 --> 12:15.660] if you want to do it or not. We don't want this to be a limitation. I also generally find that [12:15.660 --> 12:21.460] gear for IoT hacking follows the 80-20 rule. So if you're not familiar with this rule, it's kind [12:21.460 --> 12:28.440] of the idea that for any given input, that 20% of the inputs are responsible actually for 80% [12:28.440 --> 12:33.280] of the outputs. And I find that to be true with IoT hacking tools. You'll need to get a few of [12:33.280 --> 12:37.320] them and they'll do most of the heavy lifting. And then you'll need to acquire the more specialized [12:37.320 --> 12:44.380] expensive tools for specific tasks. Sure, at this point, everyone's seen a lot of the meme of this [12:44.380 --> 12:48.940] Turkish shooter guy. And I just wanted to demonstrate this. I was kind of poking fun last [12:48.940 --> 12:53.320] week in the IoT and hardware hacking community about how we all like to acquire gear. And I'll [12:53.320 --> 12:57.080] be the first one to say I'm addicted to buying gear. I've got all the stuff in the left-hand [12:57.080 --> 13:00.720] side of this picture. But really, when you're starting out with cheaper devices, you can [13:00.720 --> 13:08.160] probably get away with literally two things and spend $10. Okay, so the first piece of equipment [13:08.160 --> 13:12.660] that you should get if you don't have one already is a digital multimeter. This is like the Swiss [13:12.660 --> 13:17.900] RB knife of electronics. It can do things like measuring voltage, current, resistance, [13:17.900 --> 13:23.740] do continuity testing. Mostly, we will use this for verifying voltage levels. And also, we can [13:23.740 --> 13:28.860] actually use it to find a lot of common debug ports. Without special equipment, we can actually, [13:28.860 --> 13:35.320] you know, ID those and then do further investigation into those ports. You can literally spend $5 on [13:35.320 --> 13:40.620] this. This yellow one on here, that's $5. I got this off AliExpress. I've used it in my workshops [13:40.620 --> 13:44.880] before. I mean, I wouldn't use it for like commercial QA testing or anything. But as far [13:44.880 --> 13:50.660] as learning IoT hacking, getting started, it's not bad. I have $5 to $100 listed here. I wouldn't [13:50.660 --> 13:55.780] recommend spending more than $100, but you can. But your $5 one, honestly, it's not that bad. [13:57.240 --> 14:03.520] The second piece of equipment you'll need is a USB to X adapter. And by X, I mean the protocols [14:03.520 --> 14:08.880] that our IoT devices are going to be talking at the hardware level. So these are where those like [14:08.880 --> 14:14.860] debug and test ports come into play. The most common ones are UART, SPI, or sometimes you're [14:14.860 --> 14:21.720] referred to as SPI, I2C, JTAG, and SWD. The most common one you'll actually see and what we're [14:21.720 --> 14:27.080] going to be focusing on is UART. So you can just go and get this $2 one, and that will work for [14:27.080 --> 14:31.480] this methodology. You get these off AliExpress, Amazon, sometimes it's coming like a pack of four [14:31.480 --> 14:36.980] for $10, you get them $2.50. So if you just want to go the cheap route, you just buy this $2 one, [14:36.980 --> 14:42.080] you'll be fine. If you kind of want a future proof, and you actually want a tool to work into, [14:42.080 --> 14:46.080] I always recommend the Tigard board. I really like their board, and they have good training [14:46.080 --> 14:49.900] that's free that goes along with how to use it. And it's going to talk all of these common [14:49.900 --> 14:54.460] protocols, actually. So it'll do UART for you. And then when, you know, if you need to jump up [14:54.460 --> 15:01.180] to something JTAG, SWD, or I2C, then you can use this as well. Okay, so the last, this is the last [15:01.180 --> 15:05.000] thing that's going to be in our toolkit is some sort of flash programmer. You can get these in [15:05.000 --> 15:11.420] all varying different levels, but this is a cheap one for $10. And we will use these to mainly [15:11.420 --> 15:17.100] extract the firmware off the device if we can't get it from other methods. So most of the cheap [15:17.100 --> 15:22.440] IoT devices I see, and why I'm suggesting these routers and cameras, they all use the same like [15:22.440 --> 15:29.020] standard SPI flash chip eight pin. So you can use a flash programmer generic one like this to read [15:29.020 --> 15:33.060] it. If you did get the Tigard, you don't even need to get one of these, you can just use the [15:33.060 --> 15:37.580] SPI connection on that. And honestly, you might not even need this. So it might mean before you're [15:37.580 --> 15:41.220] seeing us, we get the firmware from the vendor, then you don't even need a flash programmer, [15:41.220 --> 15:46.820] you can just download it. Alright, so we got all our stuff, we picked the device, we've got our [15:46.820 --> 15:50.800] gear, we're ready to start hacking. The first thing we're going to take a look at is abusing [15:51.260 --> 15:58.020] debug ports and hardware interfaces. So for the most part, IoT and embedded devices, they don't [15:58.020 --> 16:03.400] have any keyboard or mouse input, they don't have a monitor, they just kind of do something. [16:03.400 --> 16:07.680] And if they're not doing that thing right, then when you're designing it, and as a designer, [16:07.680 --> 16:12.720] your debug and test interfaces, these are like your only link to that device to see what's going [16:12.720 --> 16:18.180] on, what's going wrong, what's happening, making sure things are going properly. So what happens [16:18.180 --> 16:23.500] in R&D of the cheap devices a lot of times is they will use these throughout the R&D design process, [16:23.500 --> 16:27.480] we'll get to the end, device will be ready to go and they don't want to do another revision of [16:28.020 --> 16:32.320] hardware and things like that, or maybe firmware. So they'll just leave these on the board open [16:32.320 --> 16:36.500] like they were when they were testing. In addition, a lot of times they're actually used [16:36.500 --> 16:42.600] in production devices for things like debugging, doing logging, QA testing, possibly even flashing [16:42.600 --> 16:48.660] memory or things like that. The most two common ones I see are UART and JTAG. We're just going [16:48.660 --> 16:54.280] to be focusing on UART because on the majority of cheap consumer IoT devices, that's the most [16:54.280 --> 17:02.080] present one and I almost always see UART that you can use and abuse. So this talk is like the no BS, [17:02.080 --> 17:06.300] no filler version of it, so I'm not even going to really teach you about what the UART protocol is, [17:06.300 --> 17:11.460] only the things that you need to know to hack it. It stands for Universal Asynchronous Receiver [17:11.460 --> 17:17.000] Transmitter. That just basically means there's no clock and there's two lines, one for receiving [17:17.000 --> 17:22.620] and one for transmitting on. It's a very old and common protocol for electrical communication. [17:22.620 --> 17:27.100] It's a little bit more complicated than this, but the basics of it is it literally just [17:27.100 --> 17:34.540] talks binary with voltage, so it sends plus 3.3 volts or 5 volts for a 1, 0 volts for a 0. [17:34.980 --> 17:38.700] And I got a little picture here of a capture if you're curious, but that's literally all you need [17:38.700 --> 17:46.840] to know about it as far as hacking on it. So getting a connection to a device is UART. [17:46.840 --> 17:50.240] If you're doing like a pen test or something, that would be a finding, but for the most part, [17:50.240 --> 17:55.560] manufacturers don't actually care specifically about that. However, actually getting access [17:55.560 --> 18:01.760] to the UART will make it a lot easier for us to be able to find vulnerabilities like something [18:01.760 --> 18:06.480] that could be exploited from the web. It's going to make us a lot easier to find those. [18:06.660 --> 18:10.640] And the reason for that is we can view the device as logging, so that's probably the most [18:10.640 --> 18:15.720] important thing. In embedded devices, there's usually not a lot of storage and there'll maybe [18:15.720 --> 18:21.040] almost no actual writable storage that we have, so there's no place to store logs. [18:21.080 --> 18:26.900] So instead, we're just going to dump that all out to UART. In addition, if we are encountering [18:26.900 --> 18:31.800] embedded Linux, then usually we can actually use the UART connection to get a shell into the device. [18:31.800 --> 18:35.960] We can do further enumeration that way. Sometimes we can access the bootloader, [18:35.960 --> 18:38.940] which is responsible for it actually brings up the device. And if we can get into the [18:38.940 --> 18:42.760] bootloader, we can do things like dump the firmware, see environment variables. [18:42.760 --> 18:47.060] And so yeah, getting UART is a great thing, especially for the logging. [18:47.400 --> 18:50.360] You can see in the picture here, I'm just looking at some of the boot logs, [18:50.360 --> 18:54.780] and there's actually quite a bit of detailed versioning information that we can see already. [18:56.700 --> 19:01.140] So once you start using UART, and this happens to me, like when I see a board, [19:01.140 --> 19:05.220] it's very, very easy to start picking them out. Like whenever I see a PCB now, just [19:06.200 --> 19:10.240] subconsciously, I'm like, oh, that's UART, I can see it. So I start looking for them. [19:10.240 --> 19:14.660] And once you start noticing a few characteristics, you'll be able to ID them. [19:14.940 --> 19:19.400] So generally for full duplex UART, so this means that you've got two devices, [19:19.400 --> 19:23.380] your IoT device, and then maybe your computer that has the UART adapter they're talking to, [19:23.380 --> 19:27.700] they're both talking to each other. That means there's going to be a transmit line, [19:27.700 --> 19:32.700] which you'll see abbreviated always as TX, a receive line abbreviated as RX, and a ground. [19:32.840 --> 19:37.000] Sometimes you'll see a VCC, and I'm just calling that out because if you see four pins, [19:37.000 --> 19:41.100] for our hacking purposes, you can just ignore the VCC. We don't even need to use it. [19:42.220 --> 19:47.480] So unfortunately, they won't always make it as easy like in this example here. They've gone so [19:47.480 --> 19:52.040] nice as to label them for us and all the hardware hackers, but they won't always make it this easy. [19:52.060 --> 19:57.980] Sometimes you'll have test pads like the ones here on this black circle PCB. This is a camera [19:57.980 --> 20:02.540] that I was hacking. And you'll notice there's only two pins together. But seeing those two [20:02.540 --> 20:06.360] pins together and close to the processor, I thought that they might be UART. And then I [20:06.360 --> 20:10.380] just picked up a ground elsewhere. And then we've got another router here where they've got [20:10.900 --> 20:15.700] a connector here for UART. And it's not labeled, but as soon as you see those pins together like [20:15.700 --> 20:20.860] that, it's a good indication that it's some sort of test interface. So this is where we're going [20:20.860 --> 20:27.100] to pull out our DMM, and we can use our $5 DMM to actually pick up UART. So what we're going to do [20:27.100 --> 20:32.260] is we're going to take advantage of the fact that UART is extremely chatty on boot up. So if you've [20:32.260 --> 20:36.880] ever booted up your Linux computer, even or some Windows ones, and you see all the stuff coming [20:36.880 --> 20:41.840] scrolling through the screen, telling you all those boot log information, well, embedded Linux [20:41.840 --> 20:46.600] is the same. And that's going to happen on the UART as well. And we can take advantage of that. [20:46.600 --> 20:52.180] So what we can do is use our multimeter, put it on the volts DC setting, and measure the pins of [20:52.180 --> 20:58.200] interest. So if we think there might be a UART pin, we'll just measure that from that connector, [20:58.200 --> 21:02.200] whatever it is, to ground. And then after we're doing that, we'll power on the device. So I [21:02.200 --> 21:05.760] always like to have a power bar in my workstation that has a button, it makes it a lot easier. [21:06.720 --> 21:10.920] And what you're looking for is a fluctuating voltage after that boot up. It'll usually be [21:10.920 --> 21:16.360] like a couple seconds after, take a second for like the initial boot loader to load things up, [21:16.360 --> 21:21.640] and then you'll start to see a bunch of voltage hopping up and down. You won't see it go like 0 [21:21.640 --> 21:26.660] to 3.3 volts or 0 to 5 volts, because it's going to be too fast for our multimeter to read that. So [21:26.660 --> 21:31.500] instead, what you'll see is more of an average voltage kind of moving around. A lot of times [21:31.500 --> 21:36.600] these devices operate at 3.3 volts, so you'll see like 1.5 to 2.7 volts, and you'll see that moving [21:36.600 --> 21:41.480] up and down. So if you see that, that's a really indication I should look further at this port, [21:41.480 --> 21:46.720] it's probably transmitting something. If you just power on the device and do this, you probably won't [21:46.720 --> 21:50.940] see anything, because it's not going to be as chatty, it'll maybe just send a couple messages, [21:50.940 --> 21:54.640] and it'll be really hard to even see those blips of voltage. You got to do it right at startup. [21:55.880 --> 21:59.800] Okay, so we've found this port, we've identified it, the next thing we're going to do is we can [21:59.800 --> 22:03.980] it's as easy as we can just plug it into our computer, basically. We use our UART [22:03.980 --> 22:08.580] to USB bridge adapter, plug that into our computer. The only thing you need to keep in [22:08.580 --> 22:13.600] mind for it is it's really easy to put like names together. So you want to put TX to TX, [22:13.600 --> 22:18.600] but the way that it works is one device's TX goes to the other one's RX, and vice versa. [22:18.640 --> 22:23.720] So you just need to cross those lines, grounds go to ground, ignore the VCC, you're all good. [22:24.120 --> 22:27.280] So just for reference, I got a little picture here if you're looking at the slides later, [22:27.280 --> 22:29.480] but that's the pinout that you would usually take. [22:30.900 --> 22:34.420] So unfortunately, sometimes they won't make it that easy. They won't put the header pin on, [22:34.420 --> 22:37.580] there won't be through-hole connectors. So what do we do in that scenario? [22:37.720 --> 22:42.540] Your best option is to solder. So hopefully you're hanging out at the soldering skill station. But [22:42.540 --> 22:47.820] if not, there's ways we can get around that. So if you are lucky enough to have through-hole [22:47.820 --> 22:52.560] connectors like we did, I showed in the one router, the best way to do that is to actually [22:52.560 --> 22:56.900] attach some header pins to it. And if you don't have those, there's lots of clips, [22:57.580 --> 23:02.680] adapters, and things like that where you can buy more specific to your device. Google is your [23:02.680 --> 23:06.540] friend here and they're really not that expensive. So just go out and take a look at your different [23:06.540 --> 23:11.260] options. And just to show you if you don't want to do soldering, here's two things I've done in a [23:11.260 --> 23:16.080] pinch and shown in classes where you can get away with. Generally with through-hole connectors, [23:16.080 --> 23:21.640] they'll actually be like connectivity that goes through the actual pin. So if you put a little [23:21.640 --> 23:24.860] pressure on what you're putting through it, so kind of lean to the left or right, that'll be [23:24.860 --> 23:29.780] to get good contact. And I did it here with a twist tie or that's some sticky tack. And [23:29.780 --> 23:33.680] obviously, soldering is your best option, but I don't want that to be a barrier to, [23:33.680 --> 23:37.260] you know, hacking IoT if you don't have a soldering iron or to solder. So this can be [23:37.260 --> 23:42.540] done in a pinch. If you're running on a Linux host, I mostly just included these commands here [23:42.540 --> 23:46.800] for people that are going to be taking these slides afterwards. But all we need to do to [23:46.800 --> 23:52.700] actually get a shell or connect to the device is we need to just check and see what the device ID [23:52.700 --> 23:57.720] is for our USB UART adapter. So we can do that with this command, and you'll get the device ID [23:57.720 --> 24:03.360] back. It'll most likely be TTY USB 0, but it could be 1, 2, 3. And then we can just launch a terminal [24:03.360 --> 24:09.120] emulator and use that to get a UART connection. When you're starting out, I suggest using screen [24:09.120 --> 24:13.660] because it's the easiest one. There's lots of other ones, picocom, minicom, putty if you're [24:13.660 --> 24:18.280] on Windows, they're all fine. But screen, in my opinion, is the easiest one. It requires very [24:18.280 --> 24:24.840] little setup. The only two arguments you need is that USB device ID that I showed before. And then [24:24.840 --> 24:30.440] you'll notice the last thing here, I've got a number 115,200. That is the baud rate or speed [24:30.440 --> 24:36.460] that the UART is communicating at. And since this is no BS, no filler talk, I'm not even gonna [24:36.460 --> 24:43.300] explain what baud rate is. On 99% of IoT devices I see, it is 115,200. So you can just use that. [24:43.300 --> 24:47.500] If it's not, it's probably 9600. And if it's not that, you're probably doing something wrong. [24:47.500 --> 24:51.760] There is also a very common list on Wikipedia you can look at of other [24:52.240 --> 24:55.560] ones, but it's pretty much going to be 115,200. [24:57.560 --> 25:01.660] Okay, so if everything worked with your connection, you got screen running, you power on device, [25:01.660 --> 25:06.200] you should start to actually now see those boot logs that we saw with our multimeter actually [25:06.200 --> 25:12.160] start streaming through. And do not discount the importance of actually reading through those [25:12.160 --> 25:15.580] boot logs and seeing what they are telling you. They're going to give you lots of versioning [25:15.580 --> 25:20.260] information that could be enough to even find a vulnerability on its own, seeing that it's using [25:21.540 --> 25:25.300] underlying libraries or things like that that are outdated and someone's already done the leg work [25:25.300 --> 25:29.380] and found a vulnerability in those. We'll also give you details in this one, for example, [25:29.380 --> 25:35.300] near the bottom, showing all of the partition details about the flash EEPROM that's on it. [25:35.300 --> 25:39.020] And that's going to make it a lot easier for us later to identify the different parts of the [25:39.020 --> 25:44.620] firmware. After the boot loader goes through and it's done streaming through the text, you can hit [25:44.620 --> 25:49.020] enter. And a lot of times on cheap IoT devices, that can be enough to just get a shell, they don't [25:49.020 --> 25:53.860] lock them down with a password or anything. So then we'll be in a root shell. Generally in embedded [25:53.860 --> 25:57.920] Linux, everything just runs as root, there's no like least privileges or anything, you'll just [25:57.920 --> 26:03.220] get a root shell. Again, like in the manufacturers, they're not as concerned about this as being a [26:03.220 --> 26:07.380] specific vulnerability. So I wouldn't recommend reporting this or anything, because they already [26:07.380 --> 26:11.300] know about it, they just don't necessarily care. But we're going to abuse that to find something [26:11.300 --> 26:16.140] that you care about. The majority of the routers and smart cameras, they're running embedded Linux. [26:16.140 --> 26:21.740] So that's where it's gonna make it easier to get that shell. Okay, so I always mentioned this, [26:21.740 --> 26:25.760] because you know, in cybersecurity, I feel like we all want to get a shell, everyone loves getting [26:25.760 --> 26:30.320] shells. And sometimes that's like, the end all of what we're doing, if we're doing like web app, or [26:30.320 --> 26:35.900] you know, other different types of network pen testing. But for us, actually, connecting to the [26:35.900 --> 26:40.320] UART, it's more important for us to see the logging, that's actually what we're more we're [26:40.320 --> 26:45.020] more interested in, or at least I am. So if you don't get a shell, that's okay, if you're not able [26:45.020 --> 26:50.080] to get in, that's fine. So sometimes there'll be a password, if there is, there's ways around that, [26:50.080 --> 26:54.780] we can maybe get the hash from the firmware, or Google it. But even if you can't get a shell, [26:54.780 --> 26:59.400] that's okay. The way that UART works is like, you don't need to authenticate or log in, it's a very [26:59.400 --> 27:04.380] like low level protocol, it's just going to stream those logging bits out to you, no matter what, [27:04.380 --> 27:08.600] you don't need to log in, or anything like that, you can still see the logging, unless the device [27:08.600 --> 27:14.400] like syncs or tanks the UART, which most don't. So I just got some pictures here showing some [27:14.400 --> 27:19.220] interesting things I see in logs, one of them here is just showing the location of RSA keys as it's [27:19.220 --> 27:24.140] setting up DropBear, it's common SSH protocol. And then the other two ones are interesting [27:25.260 --> 27:30.000] logging details about when I was actually interacting with the device and showing what [27:30.000 --> 27:35.020] could potentially be command injection, or one is just showing how it sets up and saves the [27:35.020 --> 27:40.700] pre-shared keys and SSIDs for a router. So if you are lucky enough to get a shell, I mean I was [27:40.700 --> 27:45.980] saying it's not as important, but it is always nice to get one. We'll be good hackers then and do our [27:45.980 --> 27:51.800] enumeration, so start poking around. Best places to actually start looking are the Etsy folders [27:51.800 --> 27:55.200] and the VAR folders, those are probably some of the places where you'll find like interesting [27:55.980 --> 28:00.620] configuration details and things like that. Some really quick wins are things I look for, [28:00.620 --> 28:05.480] their passwords, hard-coded keys, is there endpoints that maybe they don't want to expose [28:05.480 --> 28:10.320] or that we could see that's reaching out into the back end. And of course a lot of times you'll have [28:10.320 --> 28:14.320] like things like PS or Netstat, so you can see what processes are running and what network [28:14.320 --> 28:18.840] connections are going out, so that can give us a little bit of a lay of the land around the device. [28:21.040 --> 28:25.780] Okay, so at this point you know we've got our device, we've got our equipment, we use our [28:25.780 --> 28:31.160] equipment to find our debug interface. What's the next step? That's going to be to get our hands [28:31.160 --> 28:35.960] on the firmware and in my opinion this is where my favorite part starts and where we can start [28:35.960 --> 28:41.480] having some fun and find some vulnerabilities. If you're not familiar with what firmware is, [28:41.480 --> 28:46.000] this is essentially the software that is running on the device and we kind of call it firmware and [28:46.000 --> 28:50.720] differentiate it from software in that it's kind of designed specifically for that device so that [28:50.720 --> 28:54.900] that device can fulfill one function. It's not really changing, you're not going to like install [28:54.900 --> 28:59.700] any software or anything on your router or smart camera, you just get that one piece of firmware. [29:00.260 --> 29:05.720] In embedded Linux that we're talking about today, the firmware is generally comprised of four main [29:05.720 --> 29:10.420] parts. We've got the boot loader that's responsible for actually like bringing up the device on boot [29:10.420 --> 29:15.260] up, loading up the kernel. We've then got the Linux kernel itself, that's going to be one partition. [29:15.540 --> 29:20.180] We've then got the root file system, so that's actually where all of the interesting stuff is [29:20.180 --> 29:27.560] make the device do what it's going to do. All of the binary scripts, configuration documents, [29:27.560 --> 29:32.020] all that stuff is going to be in the root file system. We'll then possibly also have some sort [29:32.020 --> 29:36.760] of partition where we can store a little bit of writable data. So we'll generally want to hunt for [29:36.760 --> 29:41.200] this as well because that's where you're going to find things like passwords that users configured [29:41.200 --> 29:45.800] or like the maybe pre-shared key for their wireless or all that kind of stuff. So a lot of times you'll [29:45.800 --> 29:52.160] see that at the end of the flash memory. The root file system has the most goodies though by far, [29:52.160 --> 29:56.740] so that's all we're going to focus on today. You can find vulnerabilities in the other places in [29:56.740 --> 30:00.280] the boot loader and kernel, but when you're starting out we'll just look at the root file [30:00.280 --> 30:04.520] system and its contents and that's honestly where you'll find the majority of vulnerabilities anyway. [30:06.900 --> 30:10.880] So there's three main ways that I usually get my hands on the firmware. There are a few other [30:10.880 --> 30:18.480] ones that are more complicated, but the easiest one is a lot of cheap IoT manufacturers. They [30:18.480 --> 30:24.120] just put their firmware available on the internet from the vendor to download. The reason for this [30:24.120 --> 30:29.620] is that unfortunately they don't put any type of update mechanisms into their device, so they kind [30:29.620 --> 30:34.960] of pass that responsibility down on to the end users if there is security patching or things [30:34.960 --> 30:40.620] like that to go and, hey, make sure you go to our website, check it every day, download the firmware, [30:40.620 --> 30:44.620] and then put it on the device yourself, which I think unfortunately I'd say like 99% of users [30:44.620 --> 30:50.720] don't do. But to fulfill that obligation they put the firmware on their website on the support page [30:50.720 --> 30:54.340] and you can just google and find it and I love that because it's super easy to get our hands [30:54.340 --> 30:58.760] on the firmware. And if you do that then you can even do IoT hacking for free. You don't even need [30:58.760 --> 31:04.300] any gear, you just download the firmware. The second way is if you did get a UART shell, I would say [31:04.780 --> 31:10.680] 90% of the devices I see they have TFTP on them, so that's Trivial File Transfer Protocol. [31:10.820 --> 31:15.900] This is there because it's actually baked into the functionality of a lot of those update [31:15.900 --> 31:20.060] mechanisms. So if you have a web app or a browser or something and it allows you to do a firmware [31:20.060 --> 31:25.980] update through that, in the backend it uses TFTP, but we can abuse that or borrow it to set up our [31:25.980 --> 31:30.780] own TFTP server and then we can just bring back files of interest or if we're patient enough we [31:30.780 --> 31:35.000] can just bring the whole root file system back to our device over that and then we don't even [31:35.000 --> 31:39.180] really need to worry about dumping the firmware. And then the last one which sometimes you'll need [31:39.180 --> 31:46.280] to do is you'll just dump the firmware off of the device. So in these cheap commercial IoT devices [31:46.280 --> 31:53.840] I'm suggesting getting started on, they almost always use an 8-pin SPI flash chip and these [31:53.840 --> 32:00.760] always follow the same pinout and we can use our flash reader that I suggested getting or the [32:00.760 --> 32:04.860] TiGuard to really do a really quick read of these and we don't even need to usually take them off [32:04.860 --> 32:11.180] of the device, you can just read them in-device, in-circuit. And the way to do that is I generally [32:11.180 --> 32:16.000] recommend using FlashROM's free open source software that's great for interacting with [32:16.000 --> 32:21.020] flash chips. So again, command here for reference if you're just wanting to follow along later, but [32:21.020 --> 32:27.460] if you get a CH341A programmer which is that $10 one that I recommended from the start, [32:27.460 --> 32:31.760] you can just run this command after you put the clip on and it's as easy as that. There's also [32:31.760 --> 32:36.800] other test clips you can do to use it, but it's pretty straightforward. It lists the different [32:36.800 --> 32:42.340] pins that match the pins on the chip. You can just google standard SPI 8-pin flash and you'll [32:42.340 --> 32:46.900] see all of the pins. There's six of them that you need to use out of the eight pins. Just a heads [32:46.900 --> 32:56.790] up, so if you did get the TiGuard, you can do this with the TiGuard. Okay, so we've all this, [32:56.790 --> 33:02.550] basically everything we've been doing up until this point now has been to set us up for successful [33:02.550 --> 33:09.450] reverse engineering of the internals of the device to figure out what's going on and to [33:09.450 --> 33:15.450] hopefully find some vulnerabilities. So that's what we're going to be taking a look at now. And [33:15.450 --> 33:20.610] so one thing you can do too, if you don't want to spend any money, is you just can go and find the [33:20.610 --> 33:26.070] firmware for download and then you can do the majority of these steps as well and then you [33:26.070 --> 33:30.890] haven't even spent a dollar. Or you could also try and emulate the firmware as well. It's not [33:30.890 --> 33:34.730] something we're going into today, but I just want to give that a call out. Like if you can't get [33:34.730 --> 33:38.070] your hands on a device, you don't want to spend any money, you just kind of want to get started, [33:38.070 --> 33:42.990] you can do it for free. Just get your firmware, try and reverse engineer it, and emulation is [33:42.990 --> 33:49.650] your friend. Okay, so the first thing we do once we get our hands on the firmware is it's generally [33:49.650 --> 33:55.010] going to be in like a kind of like a blob format. So generally it's going to be in like a .bin file [33:55.010 --> 34:00.550] or binary file or maybe a hex file, possibly a .img, but it's not going to be probably readable [34:00.550 --> 34:06.030] for us at that point. So we need to go ahead and actually unpack that firmware into the different [34:06.030 --> 34:10.970] sections and files that are actually in there that we'll be able to interact with better. [34:11.270 --> 34:14.950] So the very first thing we're going to do is cross our fingers that it's not encrypted. [34:15.110 --> 34:19.270] So again, this is why I'm recommending when you're starting out, go for those cheaper devices, [34:19.270 --> 34:24.310] because most likely they're not going to use encryption for their firmware because it costs [34:24.310 --> 34:29.910] money both in software development and R&D, but also you're most likely going to need to spend a [34:29.910 --> 34:36.930] little bit more on hardware to actually rely on that to handle that decryption at the startup. [34:36.930 --> 34:41.170] If you do come across encrypted firmware and you're just getting started, my suggestion would [34:41.170 --> 34:47.050] be just save that device for later down the road. It's not like it can't be defeated. There's lots [34:47.050 --> 34:52.510] of attacks and things like that that we can do to try and defeat the encryption and find the keys [34:53.210 --> 34:56.810] obviously when it's booting up, it's going to need to actually do that decryption and we can [34:56.810 --> 35:00.650] possibly read the keys, but it's a little bit more of an advanced topic. So I'd save that for down [35:00.650 --> 35:04.890] the road after you've done a few and go and find another device and see if you can make sure that [35:04.890 --> 35:09.510] its device is not encrypted. So how do we check if it's encrypted and also how do we get the [35:09.510 --> 35:15.370] contents of that? We will use a utility called Binwalk. So there's a bunch of tools to do this [35:15.370 --> 35:21.170] and various ones and you can take a manual approach, but the easiest way is to just go [35:21.170 --> 35:27.530] ahead and use Binwalk. If we pass it two options, the capital M and the E, it will just recursively [35:27.530 --> 35:33.510] go through and anything it identifies that it can pick up as a file type that it knows, it will try [35:33.510 --> 35:39.930] and uncompress that or unzip it or whatever until it gets down to the actual it knows the file types, [35:39.930 --> 35:46.910] whether that's a binary file, a shared object, XML, whatever. And the E is telling us to extract [35:46.910 --> 35:50.230] it actually. So if you just run Binwalk without any commands, it'll actually just tell you what [35:50.230 --> 35:54.610] it sees. And then if you pass in the E, it'll go ahead and try and actually break those down. [35:54.610 --> 36:00.170] So awesome tool. It does a lot of the legwork for us. Alternatively, we saw that we had those [36:00.170 --> 36:05.410] different partitions already actually listed out for us in the boot log. So you can use DD as well [36:05.410 --> 36:09.410] if you want a manual approach just to carve it up. And sometimes you have to, but Binwalk is your [36:09.410 --> 36:17.890] friend. It works most of the time. Okay, so this is where the fun starts. So now that we've got [36:17.890 --> 36:24.170] the firmware, we're going to go and actually focus on the root file system and see what we can find. [36:24.170 --> 36:29.430] So some really low-hanging fruit is just to look for the configuration files and poke through those, [36:29.430 --> 36:35.170] see if we can find anything that shouldn't be in there. So a lot of times when I'm teaching [36:35.170 --> 36:39.890] IoT hacking, people are surprised to see, but the best tools I think are just some of the [36:39.890 --> 36:46.110] really easy basic Linux tools like Find, Strings, and Grep. They go a long way with IoT hacking. [36:46.110 --> 36:52.470] And we can use Find with the dash name argument and I like to just do like star dot extension. [36:52.470 --> 36:58.610] So I'll do star dot xml, star dot text, star dot json, and I'll just go through that and read [36:58.610 --> 37:02.550] through those documents. A lot of times see xml and sometimes they have interesting details in [37:02.550 --> 37:07.330] there. That's some low-hanging fruits. We can also use Strings. So this is a tip that I teach. [37:07.330 --> 37:13.250] If you use Strings with the dash f, the dash f tack on it, it'll bring back the file name that's [37:13.250 --> 37:17.410] attached to that string. And then we can run Strings over like a whole file system or a whole [37:17.410 --> 37:24.550] group of files. And then we can pipe that into Grep and look for things like password, API, key, [37:24.550 --> 37:30.090] all of those things. Sometimes I'll look for like .com, for example, or various TLDs just to see if [37:30.090 --> 37:35.010] we can find any endpoints. And that can just be an easy win as well using Strings and piping it [37:35.010 --> 37:42.900] into Grep. It's one of my favorite tricks when IoT hacking is to do that. The next thing we'll [37:42.900 --> 37:48.440] take a look at that is pretty easy because same with the readable files. All of the scripts, [37:48.440 --> 37:52.960] so a lot of times since it's embedded Linux, it's going to be Bash or SH scripts. You don't need to [37:52.960 --> 37:57.280] decompile them. You can just take a look at them, read through them. A lot of times the developers [37:57.280 --> 38:00.600] will put really nice comments in there telling you what they're doing because they're being [38:00.600 --> 38:04.360] good developers and putting comments and things like that. It's funny, I've seen even things like [38:04.360 --> 38:08.860] people's emails or like, you know, if you find a problem with this, email me at this email or [38:08.860 --> 38:14.100] things like that. But the one scripts that I always suggest that you should look at right [38:14.100 --> 38:19.200] when you're getting started with a device and looking at it are the RCS scripts. So most IoT [38:19.200 --> 38:26.640] devices use a tool called BusyBox, which is a way to actually combine all of the binaries into one [38:26.640 --> 38:32.700] binary to shrink them down. And then they use their init process. And the way that BusyBox works [38:32.700 --> 38:39.700] is it runs all of the RCS scripts in Etsy slash init.d. So after the bootloader is finished and [38:39.700 --> 38:44.780] Linux is done, it hands off to the BusyBox init system. And then it calls all of the scripts in [38:44.780 --> 38:49.900] there that start with RCS. And it does them in alphanumeric order. So it'll go like RCS one, [38:49.900 --> 38:54.180] two, or if you have like sometimes you see like one and it tells you what they're doing. [38:54.740 --> 38:58.300] And these scripts are great because they're responsible for actually setting up the device [38:58.300 --> 39:03.160] past Linux for what it actually does. So if it's a camera, or router, then it's probably going to, [39:03.160 --> 39:07.460] you know, bring up binaries or things like that, to actually do what the device does. Or sometimes [39:07.460 --> 39:12.220] they'll even reach out to like, back end infra or cloud infra to let it know what's up or pass [39:12.220 --> 39:16.340] back information. And again, these are human readable, like they're just bash scripts. So no [39:16.340 --> 39:21.120] decompiling, no real reverse engineering. And another tip too, is if you're not familiar with [39:21.120 --> 39:26.100] bash, like, honestly, chat GPT is really great at breaking down what bash scripts are. So you [39:26.100 --> 39:31.080] can just copy and paste these directly as firmware into our friend chat GPT, and it can help you out [39:31.080 --> 39:35.740] and tell you what's going on as well. Yeah, I frequently don't really find specific vulnerabilities [39:35.740 --> 39:39.680] in here. Sometimes you'll find things that shouldn't be in there. But most of the reason is [39:39.680 --> 39:43.860] just to get a lay of the land. And it'll tell you about like, what's going on, what binaries are [39:43.860 --> 39:51.700] being executed, things like that. Okay, so now we're at, in my opinion, the most fun part. And kind of [39:51.700 --> 39:56.140] like everything, even the other stuff before that has been leading up to setting ourselves up to be [39:56.140 --> 40:02.600] successful at reverse engineering the binaries and libraries that are on the device. So this is [40:02.600 --> 40:07.920] where you're honestly most likely to find some sort of vulnerability that you're going to report. [40:08.400 --> 40:12.460] And the one complicated or thing that I see people get stuck with on this is, where [40:12.460 --> 40:16.900] do we actually start? It's quite possible there's dozens to hundreds to maybe a thousand [40:16.900 --> 40:22.860] different libraries and binaries on the device. It takes a lot of time to reverse engineer and [40:22.860 --> 40:30.000] understand these. So which one do we pick? And how do we start? So the easiest way to actually do [40:30.000 --> 40:35.300] this is to avoid a needle in a haystack situation is to go with like a forward down approach. And [40:35.300 --> 40:39.920] this is what I teach or the methodology I teach when people are starting. And that is to start [40:39.920 --> 40:44.860] with the custom binaries and libraries that are actually unique to the device. So a lot of the [40:44.860 --> 40:49.480] libraries and binaries are going to be Linux stuff. So if you're familiar with using Linux, you might [40:49.480 --> 40:54.120] be able to just discount quite a few of these. But if you're not, or sometimes it could be hard [40:54.120 --> 40:59.080] to tell, especially with libraries, are these open source Linux things that do Linux [40:59.080 --> 41:04.640] or C stuff? Or are these ones that the designers of this device have actually created? So then we [41:04.640 --> 41:08.280] run into the problem is, how do we know they're custom? And after you start to do this for quite [41:08.380 --> 41:12.340] a while, you will start to pick out the names and stuff and go like, oh yeah, that's a custom one. [41:12.800 --> 41:18.320] But if we don't, then the thing that I suggest to do is to interact with the device and then follow [41:18.320 --> 41:25.120] that logging and trace that logging down to the underlying binaries and functions. And this is, [41:25.120 --> 41:29.600] in my opinion, the easiest way when you're starting to actually find vulnerabilities. [41:31.020 --> 41:37.140] So here in this picture, I've got an example. So this is a common router here that I like to [41:37.140 --> 41:41.440] hack on. And I went to the web browser of it. So just like most routers, it's got a web browser [41:41.440 --> 41:48.700] where you can go on, do lots of stuff, set the pre-shared key, set what type of... if it's WPA2 [41:48.700 --> 41:52.820] WAP or whatever, you know, set all that stuff. It's got a bunch of utilities. For some reason, [41:52.820 --> 41:57.300] it's got a ping test thing. You can make the router ping other stuff. So in this example, [41:57.300 --> 42:01.500] I'm just playing around with that because I kind of suspected that it might be, you know, [42:01.500 --> 42:07.140] doing bad things when we try and ping stuff. And so I wanted to find the underlying binary or [42:07.620 --> 42:12.480] function or library that's actually responsible for that. So what I do is I just go and play with [42:12.480 --> 42:17.500] all the functionality. If there's something that you can do on the device to make it do something, [42:17.500 --> 42:21.640] I do that. And I don't specifically do that, like trying injections or anything. I just, [42:21.640 --> 42:25.120] when I'm starting out, just use the device how it's supposed to be used. [42:25.760 --> 42:30.240] And I'll take a look at the logging. And a lot of times the logging will be very verbose [42:30.240 --> 42:34.800] in IoT devices when you're interacting with things. And then we can actually trace that [42:34.800 --> 42:39.800] logging back then to the underlying binaries or libraries. So in this device, and I actually [42:39.800 --> 42:43.980] see this in a decent amount of IoT devices, they were nice enough to even just put the [42:43.980 --> 42:51.280] function that's actually being called when you try and run this ping test. They put it in square [42:51.280 --> 42:56.760] brackets. That's their like logging nomenclature or whatever. So it was called util underscore [42:56.760 --> 43:00.880] exec system. So when I saw this immediately, and if you're familiar with like, you know, [43:00.880 --> 43:05.320] web pen testing or something like that, immediately looked like it was making a system call to me. [43:05.380 --> 43:09.680] And then they put a bunch of details in it, like they actually give us how the command is being [43:09.680 --> 43:13.320] formatted. So I didn't get to put the whole thing because I was running out of room. But if you [43:13.320 --> 43:19.080] can't see it, it literally says, OAL start ping, command is IP ping dash C, and it gives the whole [43:19.080 --> 43:24.740] details. And in that, you can actually see the IP address that we put in. So it definitely is kind [43:24.740 --> 43:28.200] of like giving us a hint that there's possible command injection or something we should look [43:28.200 --> 43:35.540] at deeper there. Okay. So now we have an idea that that function, that util underscore exec system [43:35.540 --> 43:40.920] is of interest to us. It could be a potential injection point. And what we should do is, you [43:40.920 --> 43:44.800] know, on the past page or like when we're doing that, like I will interact with everything I can [43:44.800 --> 43:49.380] and take a note of where all the logging is happening, what binaries and functions that [43:49.380 --> 43:54.660] logging is coming from. We'll just go back to our good friend strings piping into grep, one of my [43:54.660 --> 44:00.600] favorite tools for IoT hacking. And we can grep on that function name. So a lot of times in less [44:00.600 --> 44:05.300] expensive IoT devices, again, they're making it easier for us. They don't strip binaries and things [44:05.300 --> 44:10.120] like that. So the function names will just end up in the compiled binaries and libraries. [44:10.260 --> 44:15.160] So we can just pipe that into grep and put the function name in. So in this example here, I did [44:15.160 --> 44:20.580] that for util exec system. However, what if they do strip it? Well, if we just go back one page here, [44:20.580 --> 44:25.800] you can see the printout here. It kind of follows a format. It says OAL start ping command is and [44:25.800 --> 44:30.600] then gives the command. So that's a string that's actually in there too. And they're probably not [44:30.600 --> 44:36.820] going to obfuscate it because it's not malware. So we can also just pipe common strings that we [44:36.820 --> 44:40.460] see. So in this example, I kind of thought it was using like a print app or sprint app or something [44:40.460 --> 44:45.320] like that. So we look for a command is and we get the same hit. You can see here that actual [44:45.820 --> 44:51.820] string, how it is in that binary is %s command is %s. So it's using that formatting. So even if [44:51.820 --> 44:55.480] they do strip the function names, there's still ways to get around it and find those underlying [44:55.480 --> 45:05.640] binaries and libraries. Okay, so now that we've got our function name, we know that it's in that. [45:05.640 --> 45:09.640] So if I just go back in this one, for example, we see the hit because we use dash F. It's in this [45:09.640 --> 45:16.040] libcmm.so. So that is a custom library that the makers of this router in this example wrote that [45:16.040 --> 45:22.280] has the majority of the functionality of that router baked into it. We can pop that into Ghidra [45:22.280 --> 45:29.040] and start decompiling it. So one of the things that I find when I'm teaching IoT hacking or in [45:29.040 --> 45:32.840] my workshops is like this is the point where people usually get a little bit overwhelmed if [45:32.840 --> 45:37.180] they're not familiar with reverse engineering. And it starts to look quite complicated because [45:37.180 --> 45:42.500] the output of Ghidra can be very verbose. When it decompiles it, it is, in my opinion, [45:42.620 --> 45:47.500] a little bit more complex than just looking at regular C code. So it can be a little like [45:47.500 --> 45:51.120] discouraging. And I see some people are like, okay, I can't do this. I'm intimidated by it. But [45:51.120 --> 45:56.260] I have a few tips that I think can make it a lot easier for you to understand and read the output [45:56.260 --> 46:00.600] in here and still find vulnerabilities, even if you don't understand what the heck is going on [46:00.600 --> 46:06.720] and most of it doesn't make sense. So the very first thing I always say is because people who [46:06.720 --> 46:11.040] are in cybersecurity and have had a little bit of an intro to Ghidra or reverse engineering is [46:11.040 --> 46:16.520] it's usually looking at malware. And this is not malware. So with malware, usually good malware [46:16.520 --> 46:20.520] authors or majority of them are going to try and obfuscate what they're doing, make it confusing [46:20.520 --> 46:24.100] for reverse engineering. They're not going to use print statements. If they have strings, [46:24.100 --> 46:29.020] they're going to obfuscate those strings that are very hard to see. Instead, for IoT devices, [46:29.020 --> 46:34.480] we have developers who are trying to be good, helpful developers and write very clean, [46:34.480 --> 46:39.160] readable code so that it's easy for someone else to pick up after them. If someone's reading their [46:39.160 --> 46:44.700] code, it's going to be testable, debuggable, doing all those good things that developers do. [46:44.720 --> 46:51.040] And also in IoT devices, we do a lot of printing out to UART to tell what's going on so that we [46:51.040 --> 46:55.520] can actually do almost debugging through print statements in a production device, [46:55.520 --> 47:00.440] which is nice. It makes it really easy for us to then go and trace those back. [47:01.100 --> 47:05.080] So one of the first things that I always suggest with that in mind is to take a look [47:05.080 --> 47:10.460] at the print statements and let those guide you to what is going on. Of course, you can't always [47:10.460 --> 47:14.400] trust print statements. If you're a programmer, you know that it's not the best to always trust [47:14.400 --> 47:17.900] comments or print statements. But when you're getting started reverse engineering, I think it's [47:17.900 --> 47:22.480] okay. Just read the print statements. The very first one that I have here that's in red, it's [47:22.480 --> 47:26.880] just actually that print statement that we saw in the logging. So it helps us confirm that we're in [47:26.880 --> 47:31.220] the right spot. And then if you look down at line 32, it might be a little hard to read, but [47:31.220 --> 47:35.800] essentially what it's saying there is it's just saying system fork failed. And this, we don't [47:35.800 --> 47:40.880] care about that. It's not important to us. But if you look at the program flow and the if statements, [47:40.880 --> 47:45.040] well, now you know what that program flow does. It just checks if a system fork failed. Because [47:45.040 --> 47:52.180] before that, it says, you know, if local 234 equals FFFFFFF. Well, if I saw that, I have no [47:52.180 --> 47:55.740] idea what it was. Is it integral to the thing? Well, if you look at the print statement, it [47:55.740 --> 47:59.920] tells you exactly what it is. And you can just ignore that. The second thing you can do with [47:59.920 --> 48:04.360] print statements that makes your life a lot easier is a lot of times they'll be like printfs or [48:04.360 --> 48:09.840] sprintfs. And if you're not familiar with how those work, essentially we have a slot holder for [48:10.680 --> 48:13.780] a variable that we're going to pass into that print statement. And then the print statement [48:13.780 --> 48:20.080] basically tells you what that variable is. So in this top example here, we have the percent [48:20.080 --> 48:24.360] command is percent. And then we have two variables passed in that, you know, we wouldn't know what [48:24.360 --> 48:28.800] they were. One's param1 and one's underscore underscore S. Well, if we look and, you know, [48:28.800 --> 48:33.000] we just go back a couple to that print statement. Well, the first one, this is that identifier [48:33.000 --> 48:37.080] OAL underscore start pin command. So we know maybe that's like some sort of identifier. [48:37.120 --> 48:42.240] And then the second one, though, now we know of our interest. Well, that's the actual string [48:42.240 --> 48:48.640] that we manipulate, that we can pass the IP address in. And because of that sprintf or that [48:48.640 --> 48:52.500] printf function, well, now we know that underscore underscore S variable. We know what it is. And [48:52.500 --> 48:58.160] that's just through those print commands. The next thing I'll call out, or that's kind of like [48:58.160 --> 49:03.620] the final thing that we've been working towards, is to just start getting used to seeing unsafe [49:03.620 --> 49:10.440] things being done. So the easiest one to actually find is system command. So you can see that's in [49:10.440 --> 49:14.980] the second square there. We have a system command. And if you're not familiar with that when you're [49:14.980 --> 49:19.840] programming C, essentially, that's a way for you to just pass down to Linux to say like, hey, I [49:19.840 --> 49:24.480] want you to run this shell command. So it's essentially the same as if you're at the terminal [49:24.480 --> 49:28.860] and you type in, if you have a shell, whatever you pass into the system, it's the same way. [49:28.860 --> 49:33.360] So if you're not already thinking this, this is an extremely dangerous thing to do in your [49:33.360 --> 49:38.260] programming if you're using user variables, and especially if you're not going to be sanitizing [49:38.260 --> 49:43.580] those variables. So in this one, for example, this util underscore exec system function that [49:43.580 --> 49:48.980] they've written to make it easier to do system calls, it does no sanitization or checking. [49:48.980 --> 49:57.000] However, in this example, the caller of that, that actually initially takes in that IP address, [49:57.000 --> 50:00.980] well, it does do the sanitization. But if you look on this device, for example, [50:00.980 --> 50:08.740] there are about 500 calls to this util underscore exec system. And the person that wrote that [50:08.740 --> 50:13.740] function, this util underscore exec system that knows, okay, I need to sanitize my inputs further [50:13.740 --> 50:17.660] down the chain, they might not be the same ones writing the code. So you can actually see how it [50:17.660 --> 50:23.160] can happen to slip through where user-supplied input gets into a system call. So that's one of [50:23.160 --> 50:27.880] the easiest things when you're starting out is to just go interact with the device, [50:27.880 --> 50:32.780] chase down the inputs that you do because you know, and see where do they end up in the code. [50:32.780 --> 50:36.560] And if they end up in a system call, then I really need to look into this deeper and see [50:36.560 --> 50:42.340] if there's a way that I can do some sort of command injection. So of course, what's next [50:42.340 --> 50:46.940] after we know this? Well, we keep interacting with the device and tracing the logging back to [50:46.940 --> 50:50.900] binaries or libraries. So of course, there's other ways to approach this. You could just start with [50:50.900 --> 50:54.620] the library and look at all the system calls and go backwards. But when you're getting started, [50:54.620 --> 50:58.120] I think it's a lot easier to understand and conceptualize and not get lost in Kedra [50:58.120 --> 51:03.580] to try and start at the source, which is how we interact with it. And we know that there's [51:03.580 --> 51:08.640] like an injection point there, and then see if that actually filters down to something. [51:08.720 --> 51:13.820] So don't just use web browsers, like a lot of IoT apps, they have a mobile or IoT devices, [51:13.920 --> 51:18.400] a mobile app. So we can go use that mobile app, like do everything in the mobile app, do all the [51:18.400 --> 51:23.040] setup, check all of that, because it's going to be like a lot of times one of those lesser used [51:23.040 --> 51:28.100] places where there's some obscure setting or something you can set. Do all of that and see [51:28.100 --> 51:32.440] what logging you can get and trace that back and see where it goes. Like one example I found where [51:32.440 --> 51:38.140] I was able to crash a device is it was a camera. And if you wanted to pair it to your mobile app, [51:38.140 --> 51:42.100] you put the QR code up to the camera, and you compare it to the mobile app. And I was never [51:42.100 --> 51:46.920] able to like get any buffer overflow or anything, but I was able to crash the camera by doing like [51:47.040 --> 51:52.120] a malformed QR code. So just be creative. If there's cloud, like somewhere you can sign up [51:52.120 --> 51:56.980] in the cloud and then interact with your device, do that. Like usually there's a free 30 days or [51:56.980 --> 52:00.760] something. And you know, we're not actually pen testing the cloud thing, we don't want to be like [52:00.760 --> 52:05.240] trying to break that, but just interact with it how you're supposed to, and see how that filters [52:05.240 --> 52:10.660] down into the device. And then what we're looking for is when you're starting out, there's two main [52:10.660 --> 52:15.280] things I suggest to look for. So the first one is what we already looked at. Does it end up [52:15.280 --> 52:22.380] in an unvalidated or unsanitized system call? And like if you look at this router and go back [52:22.380 --> 52:27.940] and look at the CVs for this one I'm showing, or lots of IoT devices, you'll see lots of command [52:27.940 --> 52:32.800] injections being done. Because in cheap IoT devices, they want to save money, they don't want [52:32.800 --> 52:37.800] to write their own functionality. It's way easier to just use the built-in stuff in Linux and just [52:37.800 --> 52:42.400] hand it off to a system call. So it's not like these don't exist, you can definitely find them. [52:42.600 --> 52:46.560] The second one that's probably a little bit more common, but a little bit harder to find [52:47.360 --> 52:55.520] and abuse, is if your user input gets put into an unsafe C function. So there's a few examples of [52:55.520 --> 53:01.840] those are memcopy, stringcopy, stringcat, printf, that next one's supposed to be sprintf, getscanf. [53:01.840 --> 53:05.400] So essentially what these are doing though is they're going to be copying your data into some [53:05.400 --> 53:10.320] sort of buffer. And again, memory is limited on IoT devices, so we're always trying to be kind of [53:10.320 --> 53:15.740] stingy with our buffers. And a lot of times, if you're not sanitizing or validating [53:15.740 --> 53:22.200] those inputs, then it can end up in a buffer where we can overflow it and, you know, at the worst case, [53:22.200 --> 53:26.460] buffer overflow, or maybe just crash the device and have some sort of denial of service. [53:26.600 --> 53:31.440] So I could give a whole other talk then about where to go from here and how to actually then [53:32.080 --> 53:36.980] abuse these or actually exploit buffer overflows. But if you do get this far and you find this and [53:36.980 --> 53:42.000] like you'll be able to maybe crash the device or get some segfaults or something, then send me [53:42.120 --> 53:46.700] a message or just go out and do some further research. And there's a lot of great resources [53:46.700 --> 53:52.220] then for how to identify these buffer overflows. So that's where I'll end today. I just want to [53:52.220 --> 53:55.980] wrap up with a thank you. Thanks everyone for coming. I hope you learned something. I hope you [53:55.980 --> 54:02.220] go home and go buy a cheap IoT device when you get home. Hack it. If you do, let me know. I love [54:02.220 --> 54:06.520] to hear when people hack it. And if you want a copy of these slides, stay in touch with me. [54:06.520 --> 54:11.000] Link up, resources, anything. You can reach me at andrewbellini.com. Thanks everyone.