WEBVTT

00:00.000 --> 00:01.800
Welcome everyone.

00:01.800 --> 00:10.180
My name is Andrew Bellini and I am here today to both convince you and show you that anyone can hack IoT devices.

00:10.180 --> 00:21.100
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.

00:21.140 --> 00:26.700
Before we get into the actual specifics of that, I actually just want to start with a really quick joke.

00:26.700 --> 00:31.540
And that joke is the S in IoT stands for security.

00:31.540 --> 00:33.660
Has anyone heard that joke before here?

00:33.660 --> 00:34.820
It's one that I hear.

00:34.820 --> 00:36.880
Yeah, I see some people are hearing it.

00:36.880 --> 00:40.840
It's one that I hear tossed around the cybersecurity community.

00:40.920 --> 00:47.780
And usually when I hear that joke, it's actually by folks that don't work specifically in IoT or embedded security.

00:47.780 --> 00:55.940
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.

00:55.940 --> 01:01.040
I'll actually put my hand up and be the first to say that it is a well-deserved joke.

01:02.520 --> 01:16.480
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,

01:16.480 --> 01:19.480
you'll see greater than 15 billion, you know, estimates.

01:19.480 --> 01:22.440
That's almost two per person of IoT devices.

01:22.620 --> 01:31.980
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.

01:32.120 --> 01:40.060
And it's estimated looking at the projections, there could be 30 billion by the end of the decade.

01:40.060 --> 01:43.160
So that is a lot of things to secure.

01:43.260 --> 01:44.380
And these are everywhere.

01:44.380 --> 01:49.160
So it's not like they're just in our households from, you know, smart cameras to even smart toilets.

01:49.200 --> 01:52.100
These are also in critical infrastructure.

01:52.100 --> 01:53.400
They're in our cars.

01:53.400 --> 01:55.500
They're essentially everywhere nowadays.

01:57.000 --> 02:04.240
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.

02:04.260 --> 02:11.440
And in addition to that, there's this agreed upon kind of thing in the security community that IoT devices are not secure.

02:11.440 --> 02:15.980
So I figured there would be a lot of people doing IoT hacking.

02:16.060 --> 02:19.600
And the cyber criminals are definitely taking advantage of this.

02:19.600 --> 02:26.500
They love finding vulnerabilities in IoT devices and adding them to their botnets or using them for initial access.

02:26.500 --> 02:36.160
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.

02:36.160 --> 02:38.140
And that was kind of reaffirmed today too.

02:38.140 --> 02:43.040
I've had a booth here where we've been doing IoT hacking, and I had mostly beginners who had never done it.

02:43.040 --> 02:44.820
And it was awesome to teach them that.

02:46.220 --> 02:54.080
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.

02:54.080 --> 02:56.960
And I just want to try and dispel some of those.

02:56.960 --> 02:59.520
So the very first one is that it's too expensive.

02:59.520 --> 03:07.540
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.

03:07.880 --> 03:13.660
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.

03:13.900 --> 03:18.060
And then addition, there was really a large lack of affordable training.

03:18.220 --> 03:25.000
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.

03:26.140 --> 03:42.500
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.

03:43.520 --> 03:47.540
And in my opinion, you know, some of these are true, there is some truth to it.

03:47.540 --> 03:56.500
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.

03:56.500 --> 04:01.760
And there's a lot of great resources to learn how to do it for free or for very limited amounts of money.

04:02.840 --> 04:10.860
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.

04:10.860 --> 04:15.660
So my name again is Andrew Bellini, I go by Digital Andrew on the socials.

04:15.680 --> 04:18.680
My background is actually in electrical engineering.

04:18.680 --> 04:25.740
So before I got into cybersecurity, I did a lot of work actually designing embedded devices and industrial IoT devices.

04:25.740 --> 04:33.080
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.

04:33.520 --> 04:37.300
I now work as a content creator at TCM Security.

04:37.300 --> 04:40.360
So there I am the creator of our IoT hacking course.

04:40.360 --> 04:46.480
It's a beginner's IoT hacking course, and I also created our Practical Junior IoT tester certification.

04:46.800 --> 04:54.520
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.

04:56.460 --> 04:59.320
So a little bit of motivation for this talk.

04:59.320 --> 05:10.800
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.

05:11.080 --> 05:17.980
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.

05:17.980 --> 05:23.280
So I had one student, he actually just messaged me a couple weeks before DefCon, and I was super excited to see this.

05:23.540 --> 05:28.380
I didn't know him before, but he said, I took your course, and he had, you know, chatting with him.

05:28.380 --> 05:30.260
He had never done any IoT hacking.

05:30.380 --> 05:40.100
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.

05:40.100 --> 05:41.840
So super excited for him about that.

05:42.140 --> 05:54.380
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,

05:54.380 --> 05:58.260
because the vendor didn't want to talk to him about it, but how he found a vulnerability.

05:59.980 --> 06:02.520
So this chat is for everyone, of course, if you're here.

06:02.520 --> 06:03.780
I'm glad you're here.

06:03.780 --> 06:18.980
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.

06:20.020 --> 06:22.660
So just a really quick agenda of what we're in for today.

06:22.660 --> 06:26.600
We'll start with some, really quickly, and legal considerations.

06:26.920 --> 06:31.100
We'll then talk about what device you should actually pick if you're getting started on.

06:31.380 --> 06:36.320
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.

06:36.760 --> 06:44.380
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.

06:44.960 --> 06:49.460
Then I'm going to take a look at locating, using, and abusing hardware interfaces.

06:49.460 --> 06:53.780
We'll then talk about acquiring firmware, and then after that we get our hands on the firmware.

06:53.780 --> 06:56.400
We'll talk about analyzing and reversing engineering it.

06:56.720 --> 06:59.000
So just a really quick staying out of trouble.

06:59.000 --> 07:01.800
This is kind of like the golden rule of ethical hacking, in my opinion.

07:01.800 --> 07:04.260
Only test devices that you're authorized to.

07:04.360 --> 07:16.680
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.

07:16.860 --> 07:26.800
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.

07:26.800 --> 07:31.260
So last one's up to you, but you know, I would implore you to go that route if you find something.

07:32.360 --> 07:44.780
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.

07:44.780 --> 07:51.020
So the first thing I will say is IoT hacking is in itself very inherently safe.

07:51.020 --> 07:57.820
So hardware hacking on commercial IoT devices, and that's really if you just only follow one basic rule, you'll be fine.

07:57.960 --> 08:00.840
And that rule is that you should never work on anything high voltage.

08:00.840 --> 08:08.420
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.

08:08.480 --> 08:11.100
All of those are, for the most part, safe to work on.

08:11.100 --> 08:12.800
You won't even feel it if you touch it.

08:12.800 --> 08:16.740
The voltage from our walls and our house and stuff, that stuff can really hurt you.

08:16.740 --> 08:18.660
So just stay away from that stuff.

08:18.660 --> 08:20.820
Just work inside your device, you'll be fine.

08:21.080 --> 08:29.280
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.

08:29.560 --> 08:33.260
And then this last one is more about keeping your devices safe.

08:33.260 --> 08:36.180
But when I give workshops, I see people doing this all the time.

08:36.180 --> 08:38.780
And this is the most common way to brick or fry your device.

08:38.780 --> 08:44.620
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.

08:44.700 --> 08:51.840
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.

08:51.840 --> 08:54.840
And that's the easiest way that I see people who are learning fry their device.

08:55.060 --> 08:56.320
So it's just really good practice.

08:56.320 --> 09:01.520
If you're not using it, turn it off, plug anything in you need, then turn it on when you're done.

09:01.520 --> 09:03.920
And if you need to unclip it, you power it off, then you work on it.

09:03.920 --> 09:04.820
And it's easy to forget.

09:04.820 --> 09:08.060
I'm always walking around in the workshops warning people of that.

09:08.680 --> 09:14.980
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.

09:14.980 --> 09:17.000
You aren't really going to counter these IoT devices.

09:17.000 --> 09:28.020
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.

09:28.020 --> 09:34.300
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.

09:34.300 --> 09:36.780
So you may think you're safe, but they can zap you.

09:36.780 --> 09:39.420
This is not common in pretty much all IoT devices.

09:39.420 --> 09:43.700
But I just say this because a lot of people have this misconception if it's unplugged, it's safe.

09:43.700 --> 09:46.300
But if there's large capacitors, that's not the case.

09:47.520 --> 09:57.780
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.

09:57.780 --> 10:01.880
So the first thing to do is actually to pick the right target if you're learning.

10:02.700 --> 10:06.660
So I always suggest the cheaper the better when you're starting to learn.

10:06.660 --> 10:08.340
And there's a couple reasons for this.

10:08.340 --> 10:16.220
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.

10:16.220 --> 10:24.460
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.

10:25.040 --> 10:32.720
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.

10:33.040 --> 10:36.860
And if it's a cheap device, then you're not going to be as concerned or upset if you fry it.

10:37.120 --> 10:40.760
And, you know, I'll raise my hand and say I still, you know, fry or brick devices.

10:40.760 --> 10:41.280
It happens.

10:41.280 --> 10:43.620
I've been hardware hacking for a long time and it still happens.

10:43.900 --> 10:50.740
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.

10:50.780 --> 10:55.860
He literally just talked about all of the devices that he had bricked over the years.

10:55.860 --> 10:57.500
So it happens to all of us.

10:57.500 --> 11:03.680
If you're looking for a specific type of device, my suggestion is to go with cheap routers or cheap smart cameras.

11:03.780 --> 11:05.120
They're great to start on.

11:05.120 --> 11:07.120
They usually have vulnerabilities that you can find.

11:07.120 --> 11:21.320
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.

11:21.320 --> 11:24.620
Those are a little bit more advanced or harder when you're getting started.

11:24.800 --> 11:27.380
And I will give another shout out to dumpster diving.

11:27.380 --> 11:33.520
So 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:40.240
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.

11:40.240 --> 11:47.380
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.

11:47.380 --> 11:50.480
So it's a great way to learn though, because usually these devices work fine.

11:50.480 --> 11:54.580
People are just, they're obsolete or whatever, but they don't have to worry about bricking them or anything.

11:56.160 --> 12:03.300
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.

12:04.860 --> 12:06.240
So I've got a couple of rules for that .

12:06.240 --> 12:08.520
The first one is we don't want to break the bank when we're starting out.

12:08.520 --> 12:10.600
You might not know if you want to do it or not.

12:10.600 --> 12:12.700
We don't want this to be a limitation.

12:13.280 --> 12:18.720
I also generally find that gear for IoT hacking follows the 80-20 rule.

12:18.740 --> 12:29.720
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.

12:29.760 --> 12:32.320
And I find that to be true with IoT hacking tools.

12:32.320 --> 12:35.240
You'll need to get a few of them and they'll do most of the heavy lifting.

12:35.380 --> 12:40.040
And then you'll need to acquire the more specialized expensive tools for specific tasks.

12:41.380 --> 12:45.720
Sure, at this point, everyone's seen a lot of the meme of this Turkish shooter guy.

12:45.800 --> 12:47.520
And I just wanted to demonstrate this.

12:47.520 --> 12:53.040
I was kind of poking fun last week in the IoT and hardware hacking community about how we all like to acquire gear.

12:53.180 --> 12:55.500
And I'll be the first one to say I'm addicted to buying gear.

12:55.500 --> 12:58.240
I've got all the stuff in the left-hand side of this picture.

12:58.420 --> 13:03.220
But really, when you're starting out with cheaper devices, you can probably get away with literally two things and spend $10.

13:06.400 --> 13:11.520
Okay, so the first piece of equipment that you should get if you don't have one already is a digital multimeter.

13:11.520 --> 13:14.360
This is like the Swiss RB knife of electronics.

13:14.360 --> 13:19.540
It can do things like measuring voltage, current, resistance, do continuity testing.

13:19.560 --> 13:22.680
Mostly, we will use this for verifying voltage levels.

13:22.680 --> 13:26.540
And also, we can actually use it to find a lot of common debug ports.

13:26.540 --> 13:33.360
Without special equipment, we can actually, you know, ID those and then do further investigation into those ports.

13:33.500 --> 13:35.580
You can literally spend $5 on this.

13:35.580 --> 13:37.660
This yellow one on here, that's $5.

13:37.660 --> 13:39.180
I got this off AliExpress.

13:39.200 --> 13:41.460
I've used it in my workshops before.

13:41.460 --> 13:44.360
I mean, I wouldn't use it for like commercial QA testing or anything.

13:44.360 --> 13:48.060
But as far as learning IoT hacking, getting started, it's not bad.

13:48.180 --> 13:50.400
I have $5 to $100 listed here.

13:50.400 --> 13:53.060
I wouldn't recommend spending more than $100, but you can.

13:53.060 --> 13:55.780
But your $5 one, honestly, it's not that bad.

13:57.240 --> 14:01.560
The second piece of equipment you'll need is a USB to X adapter.

14:01.560 --> 14:07.820
And by X, I mean the protocols that our IoT devices are going to be talking at the hardware level.

14:07.840 --> 14:11.080
So these are where those like debug and test ports come into play.

14:11.180 --> 14:18.900
The most common ones are UART, SPI, or sometimes you're referred to as SPI, I2C, JTAG, and SWD.

14:19.060 --> 14:23.720
The most common one you'll actually see and what we're going to be focusing on is UART.

14:23.720 --> 14:28.200
So you can just go and get this $2 one, and that will work for this methodology.

14:28.220 --> 14:33.560
You get these off AliExpress, Amazon, sometimes it's coming like a pack of four for $10, you get them $2.50.

14:34.280 --> 14:37.900
So if you just want to go the cheap route, you just buy this $2 one, you'll be fine.

14:37.980 --> 14:43.820
If you kind of want a future proof, and you actually want a tool to work into, I always recommend the Tigard board.

14:43.820 --> 14:48.340
I really like their board, and they have good training that's free that goes along with how to use it.

14:48.340 --> 14:50.700
And it's going to talk all of these common protocols, actually.

14:50.700 --> 14:51.900
So it'll do UART for you.

14:51.900 --> 14:58.540
And then when, you know, if you need to jump up to something JTAG, SWD, or I2C, then you can use this as well.

14:59.720 --> 15:04.160
Okay, so the last, this is the last thing that's going to be in our toolkit is some sort of flash programmer.

15:04.160 --> 15:09.340
You can get these in all varying different levels, but this is a cheap one for $10.

15:09.480 --> 15:15.820
And we will use these to mainly extract the firmware off the device if we can't get it from other methods.

15:15.980 --> 15:25.960
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.

15:25.960 --> 15:29.380
So you can use a flash programmer generic one like this to read it.

15:29.380 --> 15:34.780
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.

15:34.900 --> 15:36.560
And honestly, you might not even need this.

15:36.560 --> 15:42.480
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.

15:44.240 --> 15:48.600
Alright, so we got all our stuff, we picked the device, we've got our gear, we're ready to start hacking.

15:48.600 --> 15:53.460
The first thing we're going to take a look at is abusing debug ports and hardware interfaces.

15:54.620 --> 16:03.400
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.

16:03.400 --> 16:16.960
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.

16:17.460 --> 16:30.220
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.

16:30.280 --> 16:34.020
So they'll just leave these on the board open like they were when they were testing.

16:34.460 --> 16:44.440
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.

16:44.520 --> 16:47.960
The most two common ones I see are UART and JTAG.

16:47.960 --> 16:58.460
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.

16:59.500 --> 17:08.820
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.

17:08.880 --> 17:12.160
It stands for Universal Asynchronous Receiver Transmitter.

17:12.160 --> 17:18.680
That just basically means there's no clock and there's two lines, one for receiving and one for transmitting on.

17:18.680 --> 17:22.620
It's a very old and common protocol for electrical communication.

17:22.620 --> 17:34.540
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.

17:34.980 --> 17:42.600
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.

17:43.880 --> 17:46.840
So getting a connection to a device is UART.

17:46.840 --> 17:53.940
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.

17:54.240 --> 18:03.800
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.

18:03.800 --> 18:06.480
It's going to make us a lot easier to find those.

18:06.660 --> 18:12.240
And the reason for that is we can view the device as logging, so that's probably the most important thing.

18:12.340 --> 18:21.040
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.

18:21.080 --> 18:24.040
So instead, we're just going to dump that all out to UART.

18:24.720 --> 18:31.800
In addition, if we are encountering embedded Linux, then usually we can actually use the UART connection to get a shell into the device.

18:31.800 --> 18:33.960
We can do further enumeration that way.

18:34.220 --> 18:38.220
Sometimes we can access the bootloader, which is responsible for it actually brings up the device.

18:38.220 --> 18:42.760
And if we can get into the 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:54.780
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.

18:56.700 --> 19:03.240
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.

19:03.240 --> 19:08.660
Like whenever I see a PCB now, just subconsciously, I'm like, oh, that's UART, I can see it.

19:08.660 --> 19:10.240
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:25.200
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.

19:25.200 --> 19:32.700
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.

19:32.840 --> 19:39.260
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.

19:39.260 --> 19:41.100
We don't even need to use it.

19:42.220 --> 19:46.400
So unfortunately, they won't always make it as easy like in this example here.

19:46.580 --> 19:52.040
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.

19:52.060 --> 19:57.200
Sometimes you'll have test pads like the ones here on this black circle PCB.

19:57.200 --> 19:59.100
This is a camera that I was hacking.

19:59.200 --> 20:01.120
And you'll notice there's only two pins together.

20:01.120 --> 20:05.940
But seeing those two pins together and close to the processor, I thought that they might be UART.

20:05.940 --> 20:08.060
And then I just picked up a ground elsewhere.

20:08.220 --> 20:12.660
And then we've got another router here where they've got a connector here for UART.

20:12.660 --> 20:19.040
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.

20:20.000 --> 20:25.840
So this is where we're going to pull out our DMM, and we can use our $5 DMM to actually pick up UART.

20:25.940 --> 20:31.960
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.

20:31.960 --> 20:42.680
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.

20:42.680 --> 20:45.040
And that's going to happen on the UART as well.

20:45.040 --> 20:46.600
And we can take advantage of that.

20:46.600 --> 20:52.620
So what we can do is use our multimeter, put it on the volts DC setting, and measure the pins of interest.

20:52.620 --> 20:59.760
So if we think there might be a UART pin, we'll just measure that from that connector, whatever it is, to ground.

20:59.840 --> 21:02.000
And then after we're doing that, we'll power on the device.

21:02.000 --> 21:05.760
So I 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.320
And what you're looking for is a fluctuating voltage after that boot up.

21:10.320 --> 21:19.400
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.

21:19.880 --> 21:26.560
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.

21:26.560 --> 21:31.000
So instead, what you'll see is more of an average voltage kind of moving around.

21:31.020 --> 21:37.540
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.

21:37.820 --> 21:43.300
So if you see that, that's a really indication I should look further at this port, it's probably transmitting something.

21:43.640 --> 21:53.240
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.

21:53.240 --> 21:54.640
You got to do it right at startup.

21:55.880 --> 22:03.100
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.

22:03.100 --> 22:07.100
We use our UART to USB bridge adapter, plug that into our computer.

22:07.360 --> 22:12.140
The only thing you need to keep in mind for it is it's really easy to put like names together.

22:12.140 --> 22:18.600
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.

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:29.480
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.

22:30.900 --> 22:33.280
So unfortunately, sometimes they won't make it that easy.

22:33.280 --> 22:35.820
They won't put the header pin on, there won't be through-hole connectors.

22:35.820 --> 22:37.580
So what do we do in that scenario?

22:37.720 --> 22:39.280
Your best option is to solder.

22:39.280 --> 22:42.440
So hopefully you're hanging out at the soldering skill station.

22:42.440 --> 22:45.460
But if not, there's ways we can get around that.

22:45.460 --> 22:54.600
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.

22:54.600 --> 23:02.300
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.

23:02.300 --> 23:04.480
Google is your friend here and they're really not that expensive.

23:04.480 --> 23:07.340
So just go out and take a look at your different options.

23:07.640 --> 23:13.980
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.

23:14.400 --> 23:19.660
Generally with through-hole connectors, they'll actually be like connectivity that goes through the actual pin.

23:19.720 --> 23:26.200
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.

23:26.200 --> 23:29.780
And I did it here with a twist tie or that's some sticky tack.

23:29.780 --> 23:36.720
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.

23:36.720 --> 23:38.060
So this can be done in a pinch.

23:38.980 --> 23:45.520
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.

23:45.520 --> 23:54.520
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.

23:54.520 --> 23:58.060
So we can do that with this command, and you'll get the device ID back.

23:58.060 --> 24:01.620
It'll most likely be TTY USB 0, but it could be 1, 2, 3.

24:01.840 --> 24:06.780
And then we can just launch a terminal emulator and use that to get a UART connection.

24:06.900 --> 24:10.400
When you're starting out, I suggest using screen because it's the easiest one.

24:10.400 --> 24:15.320
There's lots of other ones, picocom, minicom, putty if you're on Windows, they're all fine.

24:15.340 --> 24:17.680
But screen, in my opinion, is the easiest one.

24:17.680 --> 24:19.080
It requires very little setup.

24:19.840 --> 24:24.420
The only two arguments you need is that USB device ID that I showed before.

24:24.500 --> 24:28.480
And then you'll notice the last thing here, I've got a number 115,200.

24:28.700 --> 24:32.640
That is the baud rate or speed that the UART is communicating at.

24:32.680 --> 24:37.540
And since this is no BS, no filler talk, I'm not even gonna explain what baud rate is.

24:37.540 --> 24:42.100
On 99% of IoT devices I see, it is 115,200.

24:42.100 --> 24:43.300
So you can just use that.

24:43.300 --> 24:45.100
If it's not, it's probably 9600.

24:45.320 --> 24:47.500
And if it's not that, you're probably doing something wrong.

24:47.500 --> 24:55.560
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.

24:57.560 --> 25:08.000
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.

25:08.380 --> 25:14.080
And do not discount the importance of actually reading through those boot logs and seeing what they are telling you.

25:14.080 --> 25:26.980
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.

25:26.980 --> 25:35.300
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.

25:35.300 --> 25:39.740
And that's going to make it a lot easier for us later to identify the different parts of the firmware.

25:40.640 --> 25:45.140
After the boot loader goes through and it's done streaming through the text, you can hit enter.

25:45.140 --> 25:51.000
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.

25:51.000 --> 25:52.840
So then we'll be in a root shell.

25:53.020 --> 25:59.200
Generally in embedded Linux, everything just runs as root, there's no like least privileges or anything, you'll just get a root shell.

25:59.480 --> 26:03.720
Again, like in the manufacturers, they're not as concerned about this as being a specific vulnerability.

26:03.720 --> 26:09.300
So I wouldn't recommend reporting this or anything, because they already know about it, they just don't necessarily care.

26:09.300 --> 26:12.480
But we're going to abuse that to find something that you care about.

26:12.780 --> 26:16.140
The majority of the routers and smart cameras, they're running embedded Linux.

26:16.140 --> 26:18.520
So that's where it's gonna make it easier to get that shell.

26:19.940 --> 26:26.140
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.

26:26.140 --> 26:33.360
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.

26:33.440 --> 26:42.540
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.

26:42.700 --> 26:47.300
So if you don't get a shell, that's okay, if you're not able to get in, that's fine.

26:47.300 --> 26:53.680
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.

26:53.680 --> 26:55.580
But even if you can't get a shell, that's okay.

26:55.580 --> 27:07.860
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,

27:07.860 --> 27:11.980
unless the device like syncs or tanks the UART, which most don't.

27:12.780 --> 27:22.200
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.

27:22.200 --> 27:37.560
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.

27:38.580 --> 27:43.680
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.

27:44.260 --> 27:48.820
We'll be good hackers then and do our enumeration, so start poking around.

27:48.820 --> 27:58.040
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.

27:58.400 --> 28:08.740
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.

28:08.800 --> 28:18.840
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.

28:21.040 --> 28:27.920
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.

28:27.980 --> 28:28.980
What's the next step?

28:29.100 --> 28:37.840
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.

28:39.380 --> 28:52.840
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.

28:52.840 --> 28:59.700
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.

29:00.260 --> 29:06.300
In embedded Linux that we're talking about today, the firmware is generally comprised of four main parts.

29:06.300 --> 29:11.780
We've got the boot loader that's responsible for actually like bringing up the device on boot up, loading up the kernel.

29:11.820 --> 29:15.260
We've then got the Linux kernel itself, that's going to be one partition.

29:15.540 --> 29:22.180
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.

29:22.180 --> 29:30.000
All of the binary scripts, configuration documents, all that stuff is going to be in the root file system.

29:30.040 --> 29:35.200
We'll then possibly also have some sort of partition where we can store a little bit of writable data.

29:35.380 --> 29:44.820
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.

29:44.820 --> 29:48.660
So a lot of times you'll see that at the end of the flash memory.

29:49.240 --> 29:54.000
The root file system has the most goodies though by far, so that's all we're going to focus on today.

29:54.020 --> 30:04.520
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.

30:06.900 --> 30:10.080
So there's three main ways that I usually get my hands on the firmware.

30:10.080 --> 30:18.260
There are a few other ones that are more complicated, but the easiest one is a lot of cheap IoT manufacturers.

30:18.460 --> 30:23.100
They just put their firmware available on the internet from the vendor to download.

30:23.140 --> 30:37.980
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,

30:37.980 --> 30:45.520
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.

30:45.580 --> 30:55.160
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.

30:55.480 --> 30:58.240
And if you do that then you can even do IoT hacking for free.

30:58.240 --> 31:00.420
You don't even need any gear, you just download the firmware.

31:01.400 --> 31:10.680
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.

31:10.820 --> 31:16.580
This is there because it's actually baked into the functionality of a lot of those update mechanisms.

31:16.580 --> 31:37.220
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.

31:37.440 --> 31:42.260
And then the last one which sometimes you'll need to do is you'll just dump the firmware off of the device.

31:42.480 --> 32:05.640
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,

32:05.640 --> 32:08.580
you can just read them in-device, in-circuit.

32:08.880 --> 32:17.000
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.

32:17.180 --> 32:31.460
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.

32:31.460 --> 32:35.780
There's also other test clips you can do to use it, but it's pretty straightforward.

32:35.780 --> 32:39.000
It lists the different pins that match the pins on the chip.

32:39.060 --> 32:43.320
You can just google standard SPI 8-pin flash and you'll see all of the pins.

32:43.320 --> 32:45.940
There's six of them that you need to use out of the eight pins.

32:46.300 --> 32:49.820
Just a heads up, so if you did get the TiGuard, you can do this with the TiGuard.

32:53.870 --> 33:11.710
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.

33:12.770 --> 33:15.310
So that's what we're going to be taking a look at now.

33:15.310 --> 33:27.670
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.

33:27.790 --> 33:30.750
Or you could also try and emulate the firmware as well.

33:30.750 --> 33:34.130
It's not something we're going into today, but I just want to give that a call out.

33:34.150 --> 33:39.330
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.

33:39.330 --> 33:43.790
Just get your firmware, try and reverse engineer it, and emulation is your friend.

33:46.690 --> 33:52.210
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.

33:52.210 --> 34:02.110
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.

34:02.110 --> 34:10.970
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.

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:35.870
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.

34:36.410 --> 34:44.530
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.

34:44.530 --> 34:46.550
It's not like it can't be defeated.

34:46.550 --> 34:59.690
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.

34:59.690 --> 35:06.410
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.

35:06.570 --> 35:10.870
So how do we check if it's encrypted and also how do we get the contents of that?

35:10.970 --> 35:13.330
We will use a utility called Binwalk.

35:13.330 --> 35:22.530
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.

35:22.570 --> 35:39.930
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,

35:39.930 --> 35:43.850
whether that's a binary file, a shared object, XML, whatever.

35:44.750 --> 35:47.490
And the E is telling us to extract it actually.

35:47.490 --> 35:50.850
So if you just run Binwalk without any commands, it'll actually just tell you what it sees.

35:50.850 --> 35:54.610
And then if you pass in the E, it'll go ahead and try and actually break those down.

35:54.610 --> 35:56.050
So awesome tool.

35:56.050 --> 35:58.130
It does a lot of the legwork for us.

35:58.330 --> 36:03.290
Alternatively, we saw that we had those different partitions already actually listed out for us in the boot log.

36:03.290 --> 36:07.270
So you can use DD as well if you want a manual approach just to carve it up.

36:07.270 --> 36:09.730
And sometimes you have to, but Binwalk is your friend.

36:09.730 --> 36:12.170
It works most of the time.

36:14.270 --> 36:17.070
Okay, so this is where the fun starts.

36:17.070 --> 36:24.170
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.

36:24.170 --> 36:32.050
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.

36:32.910 --> 36:43.170
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.

36:43.170 --> 36:46.110
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:59.510
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.

36:59.510 --> 37:02.770
A lot of times see xml and sometimes they have interesting details in there.

37:02.770 --> 37:04.350
That's some low-hanging fruits.

37:04.470 --> 37:05.690
We can also use Strings.

37:05.690 --> 37:07.330
So this is a tip that I teach.

37:07.330 --> 37:14.550
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.

37:14.550 --> 37:18.850
And then we can run Strings over like a whole file system or a whole group of files.

37:19.290 --> 37:25.330
And then we can pipe that into Grep and look for things like password, API, key, all of those things.

37:25.330 --> 37:31.650
Sometimes I'll look for like .com, for example, or various TLDs just to see if we can find any endpoints.

37:31.790 --> 37:35.510
And that can just be an easy win as well using Strings and piping it into Grep.

37:35.510 --> 37:38.930
It's one of my favorite tricks when IoT hacking is to do that.

37:41.980 --> 37:47.140
The next thing we'll take a look at that is pretty easy because same with the readable files.

37:47.140 --> 37:52.220
All of the scripts, so a lot of times since it's embedded Linux, it's going to be Bash or SH scripts.

37:52.240 --> 37:53.980
You don't need to decompile them.

37:53.980 --> 37:56.220
You can just take a look at them, read through them.

37:56.220 --> 38:03.140
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.

38:03.140 --> 38:09.980
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.

38:10.660 --> 38:18.080
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.

38:18.240 --> 38:28.040
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.

38:28.040 --> 38:30.360
And then they use their init process.

38:30.860 --> 38:37.960
And the way that BusyBox works is it runs all of the RCS scripts in Etsy slash init.d.

38:37.960 --> 38:42.880
So after the bootloader is finished and Linux is done, it hands off to the BusyBox init system.

38:42.940 --> 38:46.360
And then it calls all of the scripts in there that start with RCS.

38:46.480 --> 38:48.180
And it does them in alphanumeric order.

38:48.180 --> 38:54.180
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.

38:54.740 --> 39:00.240
And these scripts are great because they're responsible for actually setting up the device past Linux for what it actually does.

39:00.240 --> 39:07.020
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.

39:07.020 --> 39:13.400
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.

39:13.520 --> 39:16.000
And again, these are human readable, like they're just bash scripts.

39:16.000 --> 39:18.580
So no decompiling, no real reverse engineering.

39:19.020 --> 39:25.920
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.

39:25.920 --> 39:33.180
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.

39:33.800 --> 39:36.240
Yeah, I frequently don't really find specific vulnerabilities in here.

39:36.240 --> 39:38.020
Sometimes you'll find things that shouldn't be in there.

39:38.020 --> 39:41.000
But most of the reason is just to get a lay of the land.

39:41.000 --> 39:45.720
And it'll tell you about like, what's going on, what binaries are being executed, things like that.

39:48.340 --> 39:51.260
Okay, so now we're at, in my opinion, the most fun part.

39:51.260 --> 40:01.780
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.

40:01.780 --> 40:07.920
So this is where you're honestly most likely to find some sort of vulnerability that you're going to report.

40:08.400 --> 40:13.760
And the one complicated or thing that I see people get stuck with on this is, where do we actually start?

40:13.760 --> 40:20.380
It's quite possible there's dozens to hundreds to maybe a thousand different libraries and binaries on the device.

40:20.380 --> 40:23.760
It takes a lot of time to reverse engineer and understand these.

40:23.760 --> 40:25.180
So which one do we pick?

40:25.200 --> 40:26.640
And how do we start?

40:28.000 --> 40:35.180
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.

40:35.180 --> 40:38.580
And this is what I teach or the methodology I teach when people are starting.

40:38.580 --> 40:44.060
And that is to start with the custom binaries and libraries that are actually unique to the device.

40:44.060 --> 40:47.560
So a lot of the libraries and binaries are going to be Linux stuff.

40:47.580 --> 40:52.020
So if you're familiar with using Linux, you might be able to just discount quite a few of these.

40:52.280 --> 40:59.820
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?

40:59.820 --> 41:03.640
Or are these ones that the designers of this device have actually created?

41:04.060 --> 41:06.820
So then we run into the problem is, how do we know they're custom?

41:06.960 --> 41:12.340
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.

41:12.800 --> 41:24.700
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.

41:24.700 --> 41:29.600
And this is, in my opinion, the easiest way when you're starting to actually find vulnerabilities.

41:31.020 --> 41:33.120
So here in this picture, I've got an example.

41:33.120 --> 41:37.840
So this is a common router here that I like to hack on.

41:37.840 --> 41:39.380
And I went to the web browser of it.

41:39.380 --> 41:50.960
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.

41:50.960 --> 41:52.160
It's got a bunch of utilities.

41:52.160 --> 41:54.060
For some reason, it's got a ping test thing.

41:54.060 --> 41:56.000
You can make the router ping other stuff.

41:56.420 --> 42:03.780
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.

42:04.180 --> 42:10.720
And so I wanted to find the underlying binary or function or library that's actually responsible for that.

42:10.820 --> 42:13.640
So what I do is I just go and play with all the functionality.

42:13.640 --> 42:18.460
If there's something that you can do on the device to make it do something, I do that.

42:18.460 --> 42:21.160
And I don't specifically do that, like trying injections or anything.

42:21.160 --> 42:25.120
I just, when I'm starting out, just use the device how it's supposed to be used.

42:25.760 --> 42:27.860
And I'll take a look at the logging.

42:27.860 --> 42:32.960
And a lot of times the logging will be very verbose in IoT devices when you're interacting with things.

42:33.000 --> 42:38.280
And then we can actually trace that logging back then to the underlying binaries or libraries.

42:38.620 --> 42:50.400
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.

42:50.400 --> 42:51.680
They put it in square brackets.

42:51.680 --> 42:55.200
That's their like logging nomenclature or whatever.

42:55.200 --> 42:57.960
So it was called util underscore exec system.

42:57.960 --> 43:05.320
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.

43:05.380 --> 43:10.240
And then they put a bunch of details in it, like they actually give us how the command is being formatted.

43:10.240 --> 43:13.040
So I didn't get to put the whole thing because I was running out of room.

43:13.040 --> 43:19.700
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.

43:19.700 --> 43:23.400
And in that, you can actually see the IP address that we put in.

43:23.460 --> 43:29.420
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.

43:30.520 --> 43:30.960
Okay.

43:31.560 --> 43:36.860
So now we have an idea that that function, that util underscore exec system is of interest to us.

43:36.860 --> 43:39.000
It could be a potential injection point.

43:39.280 --> 43:50.560
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.

43:50.840 --> 43:56.620
We'll just go back to our good friend strings piping into grep, one of my favorite tools for IoT hacking.

43:56.700 --> 43:59.000
And we can grep on that function name.

43:59.100 --> 44:03.440
So a lot of times in less expensive IoT devices, again, they're making it easier for us.

44:03.440 --> 44:05.720
They don't strip binaries and things like that.

44:05.720 --> 44:10.120
So the function names will just end up in the compiled binaries and libraries.

44:10.260 --> 44:13.880
So we can just pipe that into grep and put the function name in.

44:13.880 --> 44:17.160
So in this example here, I did that for util exec system.

44:17.160 --> 44:18.620
However, what if they do strip it?

44:18.620 --> 44:22.100
Well, if we just go back one page here, you can see the printout here.

44:22.100 --> 44:23.340
It kind of follows a format.

44:23.340 --> 44:27.060
It says OAL start ping command is and then gives the command.

44:27.420 --> 44:30.000
So that's a string that's actually in there too.

44:30.000 --> 44:32.480
And they're probably not going to obfuscate it because it's not malware.

44:32.480 --> 44:37.140
So we can also just pipe common strings that we see.

44:37.140 --> 44:41.280
So in this example, I kind of thought it was using like a print app or sprint app or something like that.

44:41.280 --> 44:43.900
So we look for a command is and we get the same hit.

44:43.900 --> 44:49.780
You can see here that actual string, how it is in that binary is %s command is %s.

44:49.780 --> 44:51.240
So it's using that formatting.

44:51.380 --> 44:57.020
So even if they do strip the function names, there's still ways to get around it and find those underlying binaries and libraries.

44:59.660 --> 45:05.640
Okay, so now that we've got our function name, we know that it's in that.

45:05.640 --> 45:08.980
So if I just go back in this one, for example, we see the hit because we use dash F.

45:09.000 --> 45:11.200
It's in this libcmm.so.

45:11.200 --> 45:20.380
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.

45:20.500 --> 45:24.340
We can pop that into Ghidra and start decompiling it.

45:25.200 --> 45:35.280
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.

45:35.280 --> 45:40.060
And it starts to look quite complicated because the output of Ghidra can be very verbose.

45:40.060 --> 45:45.780
When it decompiles it, it is, in my opinion, a little bit more complex than just looking at regular C code.

45:45.940 --> 45:48.160
So it can be a little like discouraging.

45:48.160 --> 45:49.940
And I see some people are like, okay, I can't do this.

45:49.940 --> 45:51.000
I'm intimidated by it.

45:51.000 --> 46:02.480
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.

46:03.080 --> 46:12.640
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.

46:12.860 --> 46:14.240
And this is not malware.

46:14.360 --> 46:21.880
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.

46:21.880 --> 46:23.300
They're not going to use print statements.

46:23.300 --> 46:27.340
If they have strings, they're going to obfuscate those strings that are very hard to see.

46:27.520 --> 46:38.400
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.

46:38.400 --> 46:44.700
If someone's reading their code, it's going to be testable, debuggable, doing all those good things that developers do.

46:44.720 --> 46:56.260
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.

46:56.260 --> 47:00.440
It makes it really easy for us to then go and trace those back.

47:01.100 --> 47:09.180
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.

47:09.300 --> 47:11.880
Of course, you can't always trust print statements.

47:11.880 --> 47:15.460
If you're a programmer, you know that it's not the best to always trust comments or print statements.

47:15.460 --> 47:18.180
But when you're getting started reverse engineering, I think it's okay.

47:18.180 --> 47:19.420
Just read the print statements.

47:19.580 --> 47:24.960
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.

47:24.960 --> 47:27.820
So it helps us confirm that we're in the right spot.

47:28.000 --> 47:34.840
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.

47:34.940 --> 47:36.420
And this, we don't care about that.

47:36.420 --> 47:37.400
It's not important to us.

47:37.400 --> 47:43.040
But if you look at the program flow and the if statements, well, now you know what that program flow does.

47:43.040 --> 47:44.740
It just checks if a system fork failed.

47:44.740 --> 47:50.720
Because before that, it says, you know, if local 234 equals FFFFFFF.

47:50.960 --> 47:52.960
Well, if I saw that, I have no idea what it was.

47:52.960 --> 47:54.460
Is it integral to the thing?

47:54.500 --> 47:56.800
Well, if you look at the print statement, it tells you exactly what it is.

47:56.800 --> 47:58.020
And you can just ignore that.

47:58.580 --> 48:05.500
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.

48:05.500 --> 48:12.920
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.

48:12.920 --> 48:16.740
And then the print statement basically tells you what that variable is.

48:16.740 --> 48:21.440
So in this top example here, we have the percent command is percent.

48:21.440 --> 48:24.820
And then we have two variables passed in that, you know, we wouldn't know what they were.

48:24.960 --> 48:27.780
One's param1 and one's underscore underscore S.

48:27.780 --> 48:30.720
Well, if we look and, you know, we just go back a couple to that print statement.

48:30.720 --> 48:35.100
Well, the first one, this is that identifier OAL underscore start pin command.

48:35.100 --> 48:37.080
So we know maybe that's like some sort of identifier.

48:37.120 --> 48:40.820
And then the second one, though, now we know of our interest.

48:40.820 --> 48:45.860
Well, that's the actual string that we manipulate, that we can pass the IP address in.

48:45.900 --> 48:51.740
And because of that sprintf or that printf function, well, now we know that underscore underscore S variable.

48:51.740 --> 48:52.420
We know what it is.

48:52.420 --> 48:54.920
And that's just through those print commands.

48:55.700 --> 49:05.060
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.

49:05.140 --> 49:09.620
So the easiest one to actually find is system command.

49:09.620 --> 49:11.860
So you can see that's in the second square there.

49:11.860 --> 49:13.400
We have a system command.

49:13.440 --> 49:21.840
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.

49:21.960 --> 49:28.860
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.

49:28.860 --> 49:39.360
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.

49:39.660 --> 49:48.980
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.

49:48.980 --> 49:58.900
However, in this example, the caller of that, that actually initially takes in that IP address, well, it does do the sanitization.

49:58.900 --> 50:06.820
But if you look on this device, for example, there are about 500 calls to this util underscore exec system.

50:06.920 --> 50:16.420
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.

50:16.420 --> 50:22.540
So you can actually see how it can happen to slip through where user-supplied input gets into a system call.

50:22.540 --> 50:32.780
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.

50:32.780 --> 50:39.400
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.

50:41.080 --> 50:43.220
So of course, what's next after we know this?

50:43.220 --> 50:48.120
Well, we keep interacting with the device and tracing the logging back to binaries or libraries.

50:48.120 --> 50:50.060
So of course, there's other ways to approach this.

50:50.060 --> 50:53.340
You could just start with the library and look at all the system calls and go backwards.

50:53.340 --> 51:02.080
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.

51:02.080 --> 51:08.640
And we know that there's like an injection point there, and then see if that actually filters down to something.

51:08.720 --> 51:14.980
So don't just use web browsers, like a lot of IoT apps, they have a mobile or IoT devices, a mobile app.

51:15.000 --> 51:26.360
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.

51:26.360 --> 51:31.040
Do all of that and see what logging you can get and trace that back and see where it goes.

51:31.040 --> 51:35.200
Like one example I found where I was able to crash a device is it was a camera.

51:35.200 --> 51:41.660
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.

51:41.660 --> 51:48.800
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.

51:48.800 --> 51:49.960
So just be creative.

51:49.960 --> 51:55.440
If there's cloud, like somewhere you can sign up in the cloud and then interact with your device, do that.

51:55.440 --> 51:57.720
Like usually there's a free 30 days or something.

51:57.880 --> 52:06.840
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.

52:07.160 --> 52:12.280
And then what we're looking for is when you're starting out, there's two main things I suggest to look for.

52:12.280 --> 52:14.480
So the first one is what we already looked at.

52:14.480 --> 52:19.560
Does it end up in an unvalidated or unsanitized system call?

52:19.840 --> 52:29.180
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.

52:29.180 --> 52:33.820
Because in cheap IoT devices, they want to save money, they don't want to write their own functionality.

52:33.840 --> 52:39.460
It's way easier to just use the built-in stuff in Linux and just hand it off to a system call.

52:39.680 --> 52:42.400
So it's not like these don't exist, you can definitely find them.

52:42.600 --> 52:54.040
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.

52:54.360 --> 53:01.840
So there's a few examples of those are memcopy, stringcopy, stringcat, printf, that next one's supposed to be sprintf, getscanf.

53:01.840 --> 53:06.140
So essentially what these are doing though is they're going to be copying your data into some sort of buffer.

53:06.160 --> 53:12.560
And again, memory is limited on IoT devices, so we're always trying to be kind of stingy with our buffers.

53:12.560 --> 53:26.460
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.

53:26.600 --> 53:34.540
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.

53:34.540 --> 53:44.860
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.

53:44.860 --> 53:49.120
And there's a lot of great resources then for how to identify these buffer overflows.

53:50.380 --> 53:51.800
So that's where I'll end today.

53:51.800 --> 53:53.180
I just want to wrap up with a thank you.

53:53.180 --> 53:54.880
Thanks everyone for coming.

53:54.880 --> 53:55.720
I hope you learned something.

53:55.720 --> 54:00.080
I hope you go home and go buy a cheap IoT device when you get home.

54:00.300 --> 54:00.900
Hack it.

54:00.900 --> 54:02.000
If you do, let me know.

54:02.000 --> 54:03.740
I love to hear when people hack it.

54:03.840 --> 54:06.520
And if you want a copy of these slides, stay in touch with me.

54:06.520 --> 54:08.240
Link up, resources, anything.

54:08.380 --> 54:10.140
You can reach me at andrewbellini.com.

54:10.140 --> 54:11.000
Thanks everyone.

