start	end	text
0	7360	Welcome everyone. My name is Andrew Bellini and I am here today to both convince you and show you
7360	13200	that anyone can hack IoT devices. So in the talk today, I'm hoping to both convince you that and
13200	18580	I'm also going to walk you through a methodology that you can go take home, buy a cheap consumer
18580	24000	IoT device and hopefully hack it. Before we get into the actual specifics of that, I actually
24000	31540	just want to start with a really quick joke. And that joke is the S in IoT stands for security.
31540	36160	Has anyone heard that joke before here? It's one that I hear. Yeah, I see some people are hearing
36160	41960	it. It's one that I hear tossed around the cybersecurity community. And usually when I
41960	47780	hear that joke, it's actually by folks that don't work specifically in IoT or embedded security.
47780	53780	But as someone who actually has a background working in industrial IoT devices and embedded
53780	58760	devices, I won't say I'm not salty about it. I'll actually put my hand up and be the first to say
58760	65000	that it is a well-deserved joke. So the thing about that joke is, and we can all, you know,
65000	70640	have a laugh at IoT devices and their lack of security, but the reality is if you, you know,
70640	76480	check out and look at how many estimates for IoT devices there are connected in the world right now,
76480	80600	you'll see greater than 15 billion, you know, estimates. That's almost two per person
80600	87360	of IoT devices. And in addition to that, we're expecting there to be a big surge of IoT devices
87360	92940	because of AI and machine learning, how they're going to be used for edge devices. And it's
92940	100640	estimated looking at the projections, there could be 30 billion by the end of the decade. So that is
100840	105460	a lot of things to secure. And these are everywhere. So it's not like they're just in our
105460	110940	households from, you know, smart cameras to even smart toilets. These are also in critical
110940	118620	infrastructure. They're in our cars. They're essentially everywhere nowadays. So one of the
118620	123060	things that I kind of thought when I was starting to get interested in IoT security is there's so
123060	128620	many devices. And in addition to that, there's this agreed upon kind of thing in the security
128620	134860	community that IoT devices are not secure. So I figured there would be a lot of people doing IoT
134860	140880	hacking. And the cyber criminals are definitely taking advantage of this. They love finding
140880	146500	vulnerabilities in IoT devices and adding them to their botnets or using them for initial access.
146500	150800	But my experience was in the ethical hacking community when I started meeting hackers and
150800	156160	things like that and asking them if they hack IoT devices, a lot of times the answer was no.
156160	161240	And that was kind of reaffirmed today too. I've had a booth here where we've been doing IoT hacking,
161240	164820	and I had mostly beginners who had never done it. And it was awesome to teach them that.
166220	170920	So one of the things that, you know, when I ask people, why aren't you doing IoT hacking,
170920	176960	there's a few misconceptions that I hear about it. And I just want to try and dispel some of those.
176960	182360	So the very first one is that it's too expensive. So you need to buy expensive gear, you need like,
182360	188420	you know, an oscilloscope or like a microscope or expensive tools to get into it. When you're
188420	192340	starting out, and this is a reality, you're probably going to need to buy the devices you
192340	198060	want to hack on. And then addition, there was really a large lack of affordable training.
198220	203460	When I was looking to learn even, you know, five years back, it was like $5,000 for a course,
203560	209680	a lot of them were in person. And then the second misconception I hear is that it's very complicated,
209680	213600	you need to like have an engineering degree, you need to know about electronics, you need about
213600	219540	hardware, circuits, all of that stuff, you need to know about special protocols, in addition to just
219540	225860	the normal things that you need to know about hacking. And in my opinion, you know, some of
225860	229800	these are true, there is some truth to it. But I actually think there are ways that you can actually
229800	236500	learn to hack IoT devices, commercial IoT devices off the shelf, without spending that much money.
236500	241160	And there's a lot of great resources to learn how to do it for free or for very limited amounts of
241160	246700	money. Okay, so I've been chatting for a little bit, I just wanted to give a quick intro to who
246700	252880	I am and why I know a little bit about IoT and IoT security. So my name again is Andrew Bellini,
252880	258680	I go by Digital Andrew on the socials. My background is actually in electrical engineering.
258680	263800	So before I got into cybersecurity, I did a lot of work actually designing embedded devices and
263800	268920	industrial IoT devices. So that's a little bit where I learned about it, not specifically in
268920	275020	security, but just actually, you know, designing the devices that we use. I now work as a content
275020	281400	creator at TCM Security. So there I am the creator of our IoT hacking course. It's a beginner's IoT
281400	287220	hacking course, and I also created our Practical Junior IoT tester certification. And if you do
287220	290760	want to link up with me, you want a copy of these slides, you want to see what I'm working on,
290760	294520	I got lots of free blog resources or anything like that, check out my website.
296460	302120	So a little bit of motivation for this talk. I have one specific goal, and that is to provide you
302120	308640	with a methodology, specific tools, and knowledge to find vulnerabilities, aka hack,
308640	314360	in commercial IoT devices. And I have a couple messages here from some of my previous students,
314360	318320	just to give you some motivation and also proof that this methodology works. So I had
318320	322460	one student, he actually just messaged me a couple weeks before DefCon, and I was super excited to
322460	327920	see this. I didn't know him before, but he said, I took your course, and he had, you know, chatting
327920	332500	with him. He had never done any IoT hacking. He took my suggestion, he went and got a cheap
332960	338280	smart camera off Amazon, and he actually was able to find three vulnerabilities in it, got in touch
338280	342340	with the vendor, and he's got three CVs coming. So super excited for him about that. And then
342340	346180	there's another message, this person didn't want me to put their name up, but he took my course as
346180	351200	well, and then he bought a cheap router, and he found a remote code execution vulnerability in it,
351200	355580	and I just was chatting with him about how he could submit that to a CNA, because the vendor
355580	361540	didn't want to talk to him about it, but how he found a vulnerability. So this chat is for everyone,
361540	366920	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
366920	372400	curious, as I say, this talk is specifically catered to people who are new or just curious
372400	378980	about IoT, and it's going to assume you have limited or no experience with IoT or embedded systems.
380020	384340	So just a really quick agenda of what we're in for today. We'll start with some, really quickly,
384340	389400	and legal considerations. We'll then talk about what device you should actually pick
389400	393680	if you're getting started on. So if you want to go home and buy something off Amazon, what you
393680	397840	should look for, if you're going to go dumpster diving, for example. We'll then talk about how
397840	401660	you can build out an affordable toolkit, and what stuff you should buy, or what stuff you should
401660	406340	avoid, and how to not, you know, break the bank doing this. Then I'm going to take a look at
406340	412060	locating, using, and abusing hardware interfaces. We'll then talk about acquiring firmware, and then
412060	416400	after that we get our hands on the firmware. We'll talk about analyzing and reversing engineering it.
416720	420600	So just a really quick staying out of trouble. This is kind of like the golden rule of ethical
420600	425520	hacking, in my opinion. Only test devices that you're authorized to. And then this is my personal
425520	430420	suggestion, since I am giving a talk about potentially how to go out and find CVs and
430420	435640	IoT devices, but I always recommend being ethical and following responsible disclosure if you do
435640	441060	find things. Unfortunately for a lot of IoT devices, they don't have bug bounty programs,
441060	445680	but they do have responsible disclosure, so you can at least report it, get some credit, and get a
445680	450240	CV that way or something. So last one's up to you, but you know, I would implore you to go that route
450240	456080	if you find something. Okay, so I did want to just give a little chat about staying safe, because
456080	460740	sometimes I give workshops or things like that, and I teach people about IoT and hardware hacking,
460740	464780	and they're a little bit nervous about opening up a device and working on the hardware of it.
464780	471400	So the first thing I will say is IoT hacking is in itself very inherently safe. So hardware
471400	476980	hacking on commercial IoT devices, and that's really if you just only follow one basic rule,
476980	481100	you'll be fine. And that rule is that you should never work on anything high voltage. So when you
481100	485540	open up the device, you're working on it, most of these devices are going to be like 12 volts, 9
485540	491180	volts, 3.3 volts, 5 volts operating voltage. All of those are, for the most part, safe to work on. You
491180	495820	won't even feel it if you touch it. The voltage from our walls and our house and stuff, that stuff
495820	500120	can really hurt you. So just stay away from that stuff. Just work inside your device, you'll be
500120	505160	fine. Never use any damaged or modified power supplies, because that's how we can accidentally
505600	510400	introduce those higher voltages into the device, damage our device ourselves. And then this last
510400	515200	one is more about keeping your devices safe. But when I give workshops, I see people doing this
515200	520000	all the time. And this is the most common way to brick or fry your device. But if you have it open
520000	524980	and you're working on it, then that's not how the manufacturer intended you to be using it. And if
524980	529620	you're plugging in clips or wires or things like that, if you have it powered on, it's easy to
529620	533780	bridge something and do a short circuit. And that's the easiest way that I see people who are learning
533780	538740	fry their device. So it's just really good practice. If you're not using it, turn it off,
538740	542500	plug anything in you need, then turn it on when you're done. And if you need to unclip it,
542500	545860	you power it off, then you work on it. And it's easy to forget. I'm always walking around
545860	550380	in the workshops warning people of that. Last thing I just want to give a really quick shout
550380	555120	out to because people have gotten seriously injured from this or hurt doing this. You
555120	558680	aren't really going to counter these IoT devices. But if you take your hardware hacking skills that
558680	562560	you learn from this to other things that have larger power supplies, is watch out for large
562560	568020	capacitors because these can actually pack a punch as far as the amount of energy they store.
568020	572760	And also some people don't realize but when you unplug these devices or capacitors from the wall,
572760	576780	they can hold their charge for quite a while. So you may think you're safe, but they can zap you.
576780	581340	This is not common in pretty much all IoT devices. But I just say this because a lot of people have
581340	585700	this misconception if it's unplugged, it's safe. But if there's large capacitors, that's not the
585700	591700	case. Okay, so now that we've got all of the preamble and everything out of the way, we can
591700	596460	get on to, you know, kind of my methodology for how you can go home, get a cheap consumer IoT
596460	601020	device and hack it. So the first thing to do is actually to pick the right target if you're
601020	606920	learning. So I always suggest the cheaper the better when you're starting to learn. And there's
607040	611820	a couple reasons for this. The first one is, and this isn't always the case, but usually you get
611820	617980	what you pay for in terms of security and also hardware security. So on cheaper devices, you
617980	622900	generally won't run into limitations on the hardware where the debug ports are locked down
622900	628260	or the firmware is encrypted. And then the second one, which kind of goes with my second point here,
628260	633720	is I never hack anything that I don't mind bricking or destroying. And if it's a cheap
633720	637840	device, then you're not going to be as concerned or upset if you fry it. And, you know, I'll raise
637840	641940	my hand and say I still, you know, fry or brick devices. It happens. I've been hardware hacking
641940	647260	for a long time and it still happens. And if you're a follower of Joe Grand, for example, probably one
647260	652160	of the most famous hardware hackers, he gave a talk a few DEF CONs ago. He literally just
652160	657500	talked about all of the devices that he had bricked over the years. So it happens to all of us.
657500	662520	If you're looking for a specific type of device, my suggestion is to go with cheap routers or cheap
662520	667120	smart cameras. They're great to start on. They usually have vulnerabilities that you can find.
667120	672880	And also, more importantly, they almost always run embedded Linux, which in my opinion is a much
672880	677440	easier type of device to hack on when you're learning than something with a microcontroller
677440	683080	like ESP32 or STM32 that's going to be running RTOS. Those are a little bit more advanced or
683080	687420	harder when you're getting started. And I will give another shout out to dumpster diving. So
687420	693520	on this picture here, this is one of many bins I have at my house that are just full of old devices.
693700	697580	And I just kind of put it out into the universe, like my friends and family know that I'm this
697580	702400	dude that likes hacking weird electronic stuff. So if they're throwing away their router or camera,
702400	708260	then they ask me, or I find them in like disposal bins or whatever, I can't resist. So it's a great
708260	711700	way to learn though, because usually these devices work fine. People are just, they're obsolete or
711700	716980	whatever, but they don't have to worry about bricking them or anything. Okay, so once we've
716980	720960	got a device, hopefully it's a smart camera or a router or something, we've got to acquire a
720960	726200	little bit of gear to go along with this methodology. So I've got a couple of rules for
726200	729420	that. The first one is we don't want to break the bank when we're starting out. You might not know
729420	735660	if you want to do it or not. We don't want this to be a limitation. I also generally find that
735660	741460	gear for IoT hacking follows the 80-20 rule. So if you're not familiar with this rule, it's kind
741460	748440	of the idea that for any given input, that 20% of the inputs are responsible actually for 80%
748440	753280	of the outputs. And I find that to be true with IoT hacking tools. You'll need to get a few of
753280	757320	them and they'll do most of the heavy lifting. And then you'll need to acquire the more specialized
757320	764380	expensive tools for specific tasks. Sure, at this point, everyone's seen a lot of the meme of this
764380	768940	Turkish shooter guy. And I just wanted to demonstrate this. I was kind of poking fun last
768940	773320	week in the IoT and hardware hacking community about how we all like to acquire gear. And I'll
773320	777080	be the first one to say I'm addicted to buying gear. I've got all the stuff in the left-hand
777080	780720	side of this picture. But really, when you're starting out with cheaper devices, you can
780720	788160	probably get away with literally two things and spend $10. Okay, so the first piece of equipment
788160	792660	that you should get if you don't have one already is a digital multimeter. This is like the Swiss
792660	797900	RB knife of electronics. It can do things like measuring voltage, current, resistance,
797900	803740	do continuity testing. Mostly, we will use this for verifying voltage levels. And also, we can
803740	808860	actually use it to find a lot of common debug ports. Without special equipment, we can actually,
808860	815320	you know, ID those and then do further investigation into those ports. You can literally spend $5 on
815320	820620	this. This yellow one on here, that's $5. I got this off AliExpress. I've used it in my workshops
820620	824880	before. I mean, I wouldn't use it for like commercial QA testing or anything. But as far
824880	830660	as learning IoT hacking, getting started, it's not bad. I have $5 to $100 listed here. I wouldn't
830660	835780	recommend spending more than $100, but you can. But your $5 one, honestly, it's not that bad.
837240	843520	The second piece of equipment you'll need is a USB to X adapter. And by X, I mean the protocols
843520	848880	that our IoT devices are going to be talking at the hardware level. So these are where those like
848880	854860	debug and test ports come into play. The most common ones are UART, SPI, or sometimes you're
854860	861720	referred to as SPI, I2C, JTAG, and SWD. The most common one you'll actually see and what we're
861720	867080	going to be focusing on is UART. So you can just go and get this $2 one, and that will work for
867080	871480	this methodology. You get these off AliExpress, Amazon, sometimes it's coming like a pack of four
871480	876980	for $10, you get them $2.50. So if you just want to go the cheap route, you just buy this $2 one,
876980	882080	you'll be fine. If you kind of want a future proof, and you actually want a tool to work into,
882080	886080	I always recommend the Tigard board. I really like their board, and they have good training
886080	889900	that's free that goes along with how to use it. And it's going to talk all of these common
889900	894460	protocols, actually. So it'll do UART for you. And then when, you know, if you need to jump up
894460	901180	to something JTAG, SWD, or I2C, then you can use this as well. Okay, so the last, this is the last
901180	905000	thing that's going to be in our toolkit is some sort of flash programmer. You can get these in
905000	911420	all varying different levels, but this is a cheap one for $10. And we will use these to mainly
911420	917100	extract the firmware off the device if we can't get it from other methods. So most of the cheap
917100	922440	IoT devices I see, and why I'm suggesting these routers and cameras, they all use the same like
922440	929020	standard SPI flash chip eight pin. So you can use a flash programmer generic one like this to read
929020	933060	it. If you did get the Tigard, you don't even need to get one of these, you can just use the
933060	937580	SPI connection on that. And honestly, you might not even need this. So it might mean before you're
937580	941220	seeing us, we get the firmware from the vendor, then you don't even need a flash programmer,
941220	946820	you can just download it. Alright, so we got all our stuff, we picked the device, we've got our
946820	950800	gear, we're ready to start hacking. The first thing we're going to take a look at is abusing
951260	958020	debug ports and hardware interfaces. So for the most part, IoT and embedded devices, they don't
958020	963400	have any keyboard or mouse input, they don't have a monitor, they just kind of do something.
963400	967680	And if they're not doing that thing right, then when you're designing it, and as a designer,
967680	972720	your debug and test interfaces, these are like your only link to that device to see what's going
972720	978180	on, what's going wrong, what's happening, making sure things are going properly. So what happens
978180	983500	in R&D of the cheap devices a lot of times is they will use these throughout the R&D design process,
983500	987480	we'll get to the end, device will be ready to go and they don't want to do another revision of
988020	992320	hardware and things like that, or maybe firmware. So they'll just leave these on the board open
992320	996500	like they were when they were testing. In addition, a lot of times they're actually used
996500	1002600	in production devices for things like debugging, doing logging, QA testing, possibly even flashing
1002600	1008660	memory or things like that. The most two common ones I see are UART and JTAG. We're just going
1008660	1014280	to be focusing on UART because on the majority of cheap consumer IoT devices, that's the most
1014280	1022080	present one and I almost always see UART that you can use and abuse. So this talk is like the no BS,
1022080	1026300	no filler version of it, so I'm not even going to really teach you about what the UART protocol is,
1026300	1031460	only the things that you need to know to hack it. It stands for Universal Asynchronous Receiver
1031460	1037000	Transmitter. That just basically means there's no clock and there's two lines, one for receiving
1037000	1042620	and one for transmitting on. It's a very old and common protocol for electrical communication.
1042620	1047100	It's a little bit more complicated than this, but the basics of it is it literally just
1047100	1054540	talks binary with voltage, so it sends plus 3.3 volts or 5 volts for a 1, 0 volts for a 0.
1054980	1058700	And I got a little picture here of a capture if you're curious, but that's literally all you need
1058700	1066840	to know about it as far as hacking on it. So getting a connection to a device is UART.
1066840	1070240	If you're doing like a pen test or something, that would be a finding, but for the most part,
1070240	1075560	manufacturers don't actually care specifically about that. However, actually getting access
1075560	1081760	to the UART will make it a lot easier for us to be able to find vulnerabilities like something
1081760	1086480	that could be exploited from the web. It's going to make us a lot easier to find those.
1086660	1090640	And the reason for that is we can view the device as logging, so that's probably the most
1090640	1095720	important thing. In embedded devices, there's usually not a lot of storage and there'll maybe
1095720	1101040	almost no actual writable storage that we have, so there's no place to store logs.
1101080	1106900	So instead, we're just going to dump that all out to UART. In addition, if we are encountering
1106900	1111800	embedded Linux, then usually we can actually use the UART connection to get a shell into the device.
1111800	1115960	We can do further enumeration that way. Sometimes we can access the bootloader,
1115960	1118940	which is responsible for it actually brings up the device. And if we can get into the
1118940	1122760	bootloader, we can do things like dump the firmware, see environment variables.
1122760	1127060	And so yeah, getting UART is a great thing, especially for the logging.
1127400	1130360	You can see in the picture here, I'm just looking at some of the boot logs,
1130360	1134780	and there's actually quite a bit of detailed versioning information that we can see already.
1136700	1141140	So once you start using UART, and this happens to me, like when I see a board,
1141140	1145220	it's very, very easy to start picking them out. Like whenever I see a PCB now, just
1146200	1150240	subconsciously, I'm like, oh, that's UART, I can see it. So I start looking for them.
1150240	1154660	And once you start noticing a few characteristics, you'll be able to ID them.
1154940	1159400	So generally for full duplex UART, so this means that you've got two devices,
1159400	1163380	your IoT device, and then maybe your computer that has the UART adapter they're talking to,
1163380	1167700	they're both talking to each other. That means there's going to be a transmit line,
1167700	1172700	which you'll see abbreviated always as TX, a receive line abbreviated as RX, and a ground.
1172840	1177000	Sometimes you'll see a VCC, and I'm just calling that out because if you see four pins,
1177000	1181100	for our hacking purposes, you can just ignore the VCC. We don't even need to use it.
1182220	1187480	So unfortunately, they won't always make it as easy like in this example here. They've gone so
1187480	1192040	nice as to label them for us and all the hardware hackers, but they won't always make it this easy.
1192060	1197980	Sometimes you'll have test pads like the ones here on this black circle PCB. This is a camera
1197980	1202540	that I was hacking. And you'll notice there's only two pins together. But seeing those two
1202540	1206360	pins together and close to the processor, I thought that they might be UART. And then I
1206360	1210380	just picked up a ground elsewhere. And then we've got another router here where they've got
1210900	1215700	a connector here for UART. And it's not labeled, but as soon as you see those pins together like
1215700	1220860	that, it's a good indication that it's some sort of test interface. So this is where we're going
1220860	1227100	to pull out our DMM, and we can use our $5 DMM to actually pick up UART. So what we're going to do
1227100	1232260	is we're going to take advantage of the fact that UART is extremely chatty on boot up. So if you've
1232260	1236880	ever booted up your Linux computer, even or some Windows ones, and you see all the stuff coming
1236880	1241840	scrolling through the screen, telling you all those boot log information, well, embedded Linux
1241840	1246600	is the same. And that's going to happen on the UART as well. And we can take advantage of that.
1246600	1252180	So what we can do is use our multimeter, put it on the volts DC setting, and measure the pins of
1252180	1258200	interest. So if we think there might be a UART pin, we'll just measure that from that connector,
1258200	1262200	whatever it is, to ground. And then after we're doing that, we'll power on the device. So I
1262200	1265760	always like to have a power bar in my workstation that has a button, it makes it a lot easier.
1266720	1270920	And what you're looking for is a fluctuating voltage after that boot up. It'll usually be
1270920	1276360	like a couple seconds after, take a second for like the initial boot loader to load things up,
1276360	1281640	and then you'll start to see a bunch of voltage hopping up and down. You won't see it go like 0
1281640	1286660	to 3.3 volts or 0 to 5 volts, because it's going to be too fast for our multimeter to read that. So
1286660	1291500	instead, what you'll see is more of an average voltage kind of moving around. A lot of times
1291500	1296600	these devices operate at 3.3 volts, so you'll see like 1.5 to 2.7 volts, and you'll see that moving
1296600	1301480	up and down. So if you see that, that's a really indication I should look further at this port,
1301480	1306720	it's probably transmitting something. If you just power on the device and do this, you probably won't
1306720	1310940	see anything, because it's not going to be as chatty, it'll maybe just send a couple messages,
1310940	1314640	and it'll be really hard to even see those blips of voltage. You got to do it right at startup.
1315880	1319800	Okay, so we've found this port, we've identified it, the next thing we're going to do is we can
1319800	1323980	it's as easy as we can just plug it into our computer, basically. We use our UART
1323980	1328580	to USB bridge adapter, plug that into our computer. The only thing you need to keep in
1328580	1333600	mind for it is it's really easy to put like names together. So you want to put TX to TX,
1333600	1338600	but the way that it works is one device's TX goes to the other one's RX, and vice versa.
1338640	1343720	So you just need to cross those lines, grounds go to ground, ignore the VCC, you're all good.
1344120	1347280	So just for reference, I got a little picture here if you're looking at the slides later,
1347280	1349480	but that's the pinout that you would usually take.
1350900	1354420	So unfortunately, sometimes they won't make it that easy. They won't put the header pin on,
1354420	1357580	there won't be through-hole connectors. So what do we do in that scenario?
1357720	1362540	Your best option is to solder. So hopefully you're hanging out at the soldering skill station. But
1362540	1367820	if not, there's ways we can get around that. So if you are lucky enough to have through-hole
1367820	1372560	connectors like we did, I showed in the one router, the best way to do that is to actually
1372560	1376900	attach some header pins to it. And if you don't have those, there's lots of clips,
1377580	1382680	adapters, and things like that where you can buy more specific to your device. Google is your
1382680	1386540	friend here and they're really not that expensive. So just go out and take a look at your different
1386540	1391260	options. And just to show you if you don't want to do soldering, here's two things I've done in a
1391260	1396080	pinch and shown in classes where you can get away with. Generally with through-hole connectors,
1396080	1401640	they'll actually be like connectivity that goes through the actual pin. So if you put a little
1401640	1404860	pressure on what you're putting through it, so kind of lean to the left or right, that'll be
1404860	1409780	to get good contact. And I did it here with a twist tie or that's some sticky tack. And
1409780	1413680	obviously, soldering is your best option, but I don't want that to be a barrier to,
1413680	1417260	you know, hacking IoT if you don't have a soldering iron or to solder. So this can be
1417260	1422540	done in a pinch. If you're running on a Linux host, I mostly just included these commands here
1422540	1426800	for people that are going to be taking these slides afterwards. But all we need to do to
1426800	1432700	actually get a shell or connect to the device is we need to just check and see what the device ID
1432700	1437720	is for our USB UART adapter. So we can do that with this command, and you'll get the device ID
1437720	1443360	back. It'll most likely be TTY USB 0, but it could be 1, 2, 3. And then we can just launch a terminal
1443360	1449120	emulator and use that to get a UART connection. When you're starting out, I suggest using screen
1449120	1453660	because it's the easiest one. There's lots of other ones, picocom, minicom, putty if you're
1453660	1458280	on Windows, they're all fine. But screen, in my opinion, is the easiest one. It requires very
1458280	1464840	little setup. The only two arguments you need is that USB device ID that I showed before. And then
1464840	1470440	you'll notice the last thing here, I've got a number 115,200. That is the baud rate or speed
1470440	1476460	that the UART is communicating at. And since this is no BS, no filler talk, I'm not even gonna
1476460	1483300	explain what baud rate is. On 99% of IoT devices I see, it is 115,200. So you can just use that.
1483300	1487500	If it's not, it's probably 9600. And if it's not that, you're probably doing something wrong.
1487500	1491760	There is also a very common list on Wikipedia you can look at of other
1492240	1495560	ones, but it's pretty much going to be 115,200.
1497560	1501660	Okay, so if everything worked with your connection, you got screen running, you power on device,
1501660	1506200	you should start to actually now see those boot logs that we saw with our multimeter actually
1506200	1512160	start streaming through. And do not discount the importance of actually reading through those
1512160	1515580	boot logs and seeing what they are telling you. They're going to give you lots of versioning
1515580	1520260	information that could be enough to even find a vulnerability on its own, seeing that it's using
1521540	1525300	underlying libraries or things like that that are outdated and someone's already done the leg work
1525300	1529380	and found a vulnerability in those. We'll also give you details in this one, for example,
1529380	1535300	near the bottom, showing all of the partition details about the flash EEPROM that's on it.
1535300	1539020	And that's going to make it a lot easier for us later to identify the different parts of the
1539020	1544620	firmware. After the boot loader goes through and it's done streaming through the text, you can hit
1544620	1549020	enter. And a lot of times on cheap IoT devices, that can be enough to just get a shell, they don't
1549020	1553860	lock them down with a password or anything. So then we'll be in a root shell. Generally in embedded
1553860	1557920	Linux, everything just runs as root, there's no like least privileges or anything, you'll just
1557920	1563220	get a root shell. Again, like in the manufacturers, they're not as concerned about this as being a
1563220	1567380	specific vulnerability. So I wouldn't recommend reporting this or anything, because they already
1567380	1571300	know about it, they just don't necessarily care. But we're going to abuse that to find something
1571300	1576140	that you care about. The majority of the routers and smart cameras, they're running embedded Linux.
1576140	1581740	So that's where it's gonna make it easier to get that shell. Okay, so I always mentioned this,
1581740	1585760	because you know, in cybersecurity, I feel like we all want to get a shell, everyone loves getting
1585760	1590320	shells. And sometimes that's like, the end all of what we're doing, if we're doing like web app, or
1590320	1595900	you know, other different types of network pen testing. But for us, actually, connecting to the
1595900	1600320	UART, it's more important for us to see the logging, that's actually what we're more we're
1600320	1605020	more interested in, or at least I am. So if you don't get a shell, that's okay, if you're not able
1605020	1610080	to get in, that's fine. So sometimes there'll be a password, if there is, there's ways around that,
1610080	1614780	we can maybe get the hash from the firmware, or Google it. But even if you can't get a shell,
1614780	1619400	that's okay. The way that UART works is like, you don't need to authenticate or log in, it's a very
1619400	1624380	like low level protocol, it's just going to stream those logging bits out to you, no matter what,
1624380	1628600	you don't need to log in, or anything like that, you can still see the logging, unless the device
1628600	1634400	like syncs or tanks the UART, which most don't. So I just got some pictures here showing some
1634400	1639220	interesting things I see in logs, one of them here is just showing the location of RSA keys as it's
1639220	1644140	setting up DropBear, it's common SSH protocol. And then the other two ones are interesting
1645260	1650000	logging details about when I was actually interacting with the device and showing what
1650000	1655020	could potentially be command injection, or one is just showing how it sets up and saves the
1655020	1660700	pre-shared keys and SSIDs for a router. So if you are lucky enough to get a shell, I mean I was
1660700	1665980	saying it's not as important, but it is always nice to get one. We'll be good hackers then and do our
1665980	1671800	enumeration, so start poking around. Best places to actually start looking are the Etsy folders
1671800	1675200	and the VAR folders, those are probably some of the places where you'll find like interesting
1675980	1680620	configuration details and things like that. Some really quick wins are things I look for,
1680620	1685480	their passwords, hard-coded keys, is there endpoints that maybe they don't want to expose
1685480	1690320	or that we could see that's reaching out into the back end. And of course a lot of times you'll have
1690320	1694320	like things like PS or Netstat, so you can see what processes are running and what network
1694320	1698840	connections are going out, so that can give us a little bit of a lay of the land around the device.
1701040	1705780	Okay, so at this point you know we've got our device, we've got our equipment, we use our
1705780	1711160	equipment to find our debug interface. What's the next step? That's going to be to get our hands
1711160	1715960	on the firmware and in my opinion this is where my favorite part starts and where we can start
1715960	1721480	having some fun and find some vulnerabilities. If you're not familiar with what firmware is,
1721480	1726000	this is essentially the software that is running on the device and we kind of call it firmware and
1726000	1730720	differentiate it from software in that it's kind of designed specifically for that device so that
1730720	1734900	that device can fulfill one function. It's not really changing, you're not going to like install
1734900	1739700	any software or anything on your router or smart camera, you just get that one piece of firmware.
1740260	1745720	In embedded Linux that we're talking about today, the firmware is generally comprised of four main
1745720	1750420	parts. We've got the boot loader that's responsible for actually like bringing up the device on boot
1750420	1755260	up, loading up the kernel. We've then got the Linux kernel itself, that's going to be one partition.
1755540	1760180	We've then got the root file system, so that's actually where all of the interesting stuff is
1760180	1767560	make the device do what it's going to do. All of the binary scripts, configuration documents,
1767560	1772020	all that stuff is going to be in the root file system. We'll then possibly also have some sort
1772020	1776760	of partition where we can store a little bit of writable data. So we'll generally want to hunt for
1776760	1781200	this as well because that's where you're going to find things like passwords that users configured
1781200	1785800	or like the maybe pre-shared key for their wireless or all that kind of stuff. So a lot of times you'll
1785800	1792160	see that at the end of the flash memory. The root file system has the most goodies though by far,
1792160	1796740	so that's all we're going to focus on today. You can find vulnerabilities in the other places in
1796740	1800280	the boot loader and kernel, but when you're starting out we'll just look at the root file
1800280	1804520	system and its contents and that's honestly where you'll find the majority of vulnerabilities anyway.
1806900	1810880	So there's three main ways that I usually get my hands on the firmware. There are a few other
1810880	1818480	ones that are more complicated, but the easiest one is a lot of cheap IoT manufacturers. They
1818480	1824120	just put their firmware available on the internet from the vendor to download. The reason for this
1824120	1829620	is that unfortunately they don't put any type of update mechanisms into their device, so they kind
1829620	1834960	of pass that responsibility down on to the end users if there is security patching or things
1834960	1840620	like that to go and, hey, make sure you go to our website, check it every day, download the firmware,
1840620	1844620	and then put it on the device yourself, which I think unfortunately I'd say like 99% of users
1844620	1850720	don't do. But to fulfill that obligation they put the firmware on their website on the support page
1850720	1854340	and you can just google and find it and I love that because it's super easy to get our hands
1854340	1858760	on the firmware. And if you do that then you can even do IoT hacking for free. You don't even need
1858760	1864300	any gear, you just download the firmware. The second way is if you did get a UART shell, I would say
1864780	1870680	90% of the devices I see they have TFTP on them, so that's Trivial File Transfer Protocol.
1870820	1875900	This is there because it's actually baked into the functionality of a lot of those update
1875900	1880060	mechanisms. So if you have a web app or a browser or something and it allows you to do a firmware
1880060	1885980	update through that, in the backend it uses TFTP, but we can abuse that or borrow it to set up our
1885980	1890780	own TFTP server and then we can just bring back files of interest or if we're patient enough we
1890780	1895000	can just bring the whole root file system back to our device over that and then we don't even
1895000	1899180	really need to worry about dumping the firmware. And then the last one which sometimes you'll need
1899180	1906280	to do is you'll just dump the firmware off of the device. So in these cheap commercial IoT devices
1906280	1913840	I'm suggesting getting started on, they almost always use an 8-pin SPI flash chip and these
1913840	1920760	always follow the same pinout and we can use our flash reader that I suggested getting or the
1920760	1924860	TiGuard to really do a really quick read of these and we don't even need to usually take them off
1924860	1931180	of the device, you can just read them in-device, in-circuit. And the way to do that is I generally
1931180	1936000	recommend using FlashROM's free open source software that's great for interacting with
1936000	1941020	flash chips. So again, command here for reference if you're just wanting to follow along later, but
1941020	1947460	if you get a CH341A programmer which is that $10 one that I recommended from the start,
1947460	1951760	you can just run this command after you put the clip on and it's as easy as that. There's also
1951760	1956800	other test clips you can do to use it, but it's pretty straightforward. It lists the different
1956800	1962340	pins that match the pins on the chip. You can just google standard SPI 8-pin flash and you'll
1962340	1966900	see all of the pins. There's six of them that you need to use out of the eight pins. Just a heads
1966900	1976790	up, so if you did get the TiGuard, you can do this with the TiGuard. Okay, so we've all this,
1976790	1982550	basically everything we've been doing up until this point now has been to set us up for successful
1982550	1989450	reverse engineering of the internals of the device to figure out what's going on and to
1989450	1995450	hopefully find some vulnerabilities. So that's what we're going to be taking a look at now. And
1995450	2000610	so one thing you can do too, if you don't want to spend any money, is you just can go and find the
2000610	2006070	firmware for download and then you can do the majority of these steps as well and then you
2006070	2010890	haven't even spent a dollar. Or you could also try and emulate the firmware as well. It's not
2010890	2014730	something we're going into today, but I just want to give that a call out. Like if you can't get
2014730	2018070	your hands on a device, you don't want to spend any money, you just kind of want to get started,
2018070	2022990	you can do it for free. Just get your firmware, try and reverse engineer it, and emulation is
2022990	2029650	your friend. Okay, so the first thing we do once we get our hands on the firmware is it's generally
2029650	2035010	going to be in like a kind of like a blob format. So generally it's going to be in like a .bin file
2035010	2040550	or binary file or maybe a hex file, possibly a .img, but it's not going to be probably readable
2040550	2046030	for us at that point. So we need to go ahead and actually unpack that firmware into the different
2046030	2050970	sections and files that are actually in there that we'll be able to interact with better.
2051270	2054950	So the very first thing we're going to do is cross our fingers that it's not encrypted.
2055110	2059270	So again, this is why I'm recommending when you're starting out, go for those cheaper devices,
2059270	2064310	because most likely they're not going to use encryption for their firmware because it costs
2064310	2069910	money both in software development and R&D, but also you're most likely going to need to spend a
2069910	2076930	little bit more on hardware to actually rely on that to handle that decryption at the startup.
2076930	2081170	If you do come across encrypted firmware and you're just getting started, my suggestion would
2081170	2087050	be just save that device for later down the road. It's not like it can't be defeated. There's lots
2087050	2092510	of attacks and things like that that we can do to try and defeat the encryption and find the keys
2093210	2096810	obviously when it's booting up, it's going to need to actually do that decryption and we can
2096810	2100650	possibly read the keys, but it's a little bit more of an advanced topic. So I'd save that for down
2100650	2104890	the road after you've done a few and go and find another device and see if you can make sure that
2104890	2109510	its device is not encrypted. So how do we check if it's encrypted and also how do we get the
2109510	2115370	contents of that? We will use a utility called Binwalk. So there's a bunch of tools to do this
2115370	2121170	and various ones and you can take a manual approach, but the easiest way is to just go
2121170	2127530	ahead and use Binwalk. If we pass it two options, the capital M and the E, it will just recursively
2127530	2133510	go through and anything it identifies that it can pick up as a file type that it knows, it will try
2133510	2139930	and uncompress that or unzip it or whatever until it gets down to the actual it knows the file types,
2139930	2146910	whether that's a binary file, a shared object, XML, whatever. And the E is telling us to extract
2146910	2150230	it actually. So if you just run Binwalk without any commands, it'll actually just tell you what
2150230	2154610	it sees. And then if you pass in the E, it'll go ahead and try and actually break those down.
2154610	2160170	So awesome tool. It does a lot of the legwork for us. Alternatively, we saw that we had those
2160170	2165410	different partitions already actually listed out for us in the boot log. So you can use DD as well
2165410	2169410	if you want a manual approach just to carve it up. And sometimes you have to, but Binwalk is your
2169410	2177890	friend. It works most of the time. Okay, so this is where the fun starts. So now that we've got
2177890	2184170	the firmware, we're going to go and actually focus on the root file system and see what we can find.
2184170	2189430	So some really low-hanging fruit is just to look for the configuration files and poke through those,
2189430	2195170	see if we can find anything that shouldn't be in there. So a lot of times when I'm teaching
2195170	2199890	IoT hacking, people are surprised to see, but the best tools I think are just some of the
2199890	2206110	really easy basic Linux tools like Find, Strings, and Grep. They go a long way with IoT hacking.
2206110	2212470	And we can use Find with the dash name argument and I like to just do like star dot extension.
2212470	2218610	So I'll do star dot xml, star dot text, star dot json, and I'll just go through that and read
2218610	2222550	through those documents. A lot of times see xml and sometimes they have interesting details in
2222550	2227330	there. That's some low-hanging fruits. We can also use Strings. So this is a tip that I teach.
2227330	2233250	If you use Strings with the dash f, the dash f tack on it, it'll bring back the file name that's
2233250	2237410	attached to that string. And then we can run Strings over like a whole file system or a whole
2237410	2244550	group of files. And then we can pipe that into Grep and look for things like password, API, key,
2244550	2250090	all of those things. Sometimes I'll look for like .com, for example, or various TLDs just to see if
2250090	2255010	we can find any endpoints. And that can just be an easy win as well using Strings and piping it
2255010	2262900	into Grep. It's one of my favorite tricks when IoT hacking is to do that. The next thing we'll
2262900	2268440	take a look at that is pretty easy because same with the readable files. All of the scripts,
2268440	2272960	so a lot of times since it's embedded Linux, it's going to be Bash or SH scripts. You don't need to
2272960	2277280	decompile them. You can just take a look at them, read through them. A lot of times the developers
2277280	2280600	will put really nice comments in there telling you what they're doing because they're being
2280600	2284360	good developers and putting comments and things like that. It's funny, I've seen even things like
2284360	2288860	people's emails or like, you know, if you find a problem with this, email me at this email or
2288860	2294100	things like that. But the one scripts that I always suggest that you should look at right
2294100	2299200	when you're getting started with a device and looking at it are the RCS scripts. So most IoT
2299200	2306640	devices use a tool called BusyBox, which is a way to actually combine all of the binaries into one
2306640	2312700	binary to shrink them down. And then they use their init process. And the way that BusyBox works
2312700	2319700	is it runs all of the RCS scripts in Etsy slash init.d. So after the bootloader is finished and
2319700	2324780	Linux is done, it hands off to the BusyBox init system. And then it calls all of the scripts in
2324780	2329900	there that start with RCS. And it does them in alphanumeric order. So it'll go like RCS one,
2329900	2334180	two, or if you have like sometimes you see like one and it tells you what they're doing.
2334740	2338300	And these scripts are great because they're responsible for actually setting up the device
2338300	2343160	past Linux for what it actually does. So if it's a camera, or router, then it's probably going to,
2343160	2347460	you know, bring up binaries or things like that, to actually do what the device does. Or sometimes
2347460	2352220	they'll even reach out to like, back end infra or cloud infra to let it know what's up or pass
2352220	2356340	back information. And again, these are human readable, like they're just bash scripts. So no
2356340	2361120	decompiling, no real reverse engineering. And another tip too, is if you're not familiar with
2361120	2366100	bash, like, honestly, chat GPT is really great at breaking down what bash scripts are. So you
2366100	2371080	can just copy and paste these directly as firmware into our friend chat GPT, and it can help you out
2371080	2375740	and tell you what's going on as well. Yeah, I frequently don't really find specific vulnerabilities
2375740	2379680	in here. Sometimes you'll find things that shouldn't be in there. But most of the reason is
2379680	2383860	just to get a lay of the land. And it'll tell you about like, what's going on, what binaries are
2383860	2391700	being executed, things like that. Okay, so now we're at, in my opinion, the most fun part. And kind of
2391700	2396140	like everything, even the other stuff before that has been leading up to setting ourselves up to be
2396140	2402600	successful at reverse engineering the binaries and libraries that are on the device. So this is
2402600	2407920	where you're honestly most likely to find some sort of vulnerability that you're going to report.
2408400	2412460	And the one complicated or thing that I see people get stuck with on this is, where
2412460	2416900	do we actually start? It's quite possible there's dozens to hundreds to maybe a thousand
2416900	2422860	different libraries and binaries on the device. It takes a lot of time to reverse engineer and
2422860	2430000	understand these. So which one do we pick? And how do we start? So the easiest way to actually do
2430000	2435300	this is to avoid a needle in a haystack situation is to go with like a forward down approach. And
2435300	2439920	this is what I teach or the methodology I teach when people are starting. And that is to start
2439920	2444860	with the custom binaries and libraries that are actually unique to the device. So a lot of the
2444860	2449480	libraries and binaries are going to be Linux stuff. So if you're familiar with using Linux, you might
2449480	2454120	be able to just discount quite a few of these. But if you're not, or sometimes it could be hard
2454120	2459080	to tell, especially with libraries, are these open source Linux things that do Linux
2459080	2464640	or C stuff? Or are these ones that the designers of this device have actually created? So then we
2464640	2468280	run into the problem is, how do we know they're custom? And after you start to do this for quite
2468380	2472340	a while, you will start to pick out the names and stuff and go like, oh yeah, that's a custom one.
2472800	2478320	But if we don't, then the thing that I suggest to do is to interact with the device and then follow
2478320	2485120	that logging and trace that logging down to the underlying binaries and functions. And this is,
2485120	2489600	in my opinion, the easiest way when you're starting to actually find vulnerabilities.
2491020	2497140	So here in this picture, I've got an example. So this is a common router here that I like to
2497140	2501440	hack on. And I went to the web browser of it. So just like most routers, it's got a web browser
2501440	2508700	where you can go on, do lots of stuff, set the pre-shared key, set what type of... if it's WPA2
2508700	2512820	WAP or whatever, you know, set all that stuff. It's got a bunch of utilities. For some reason,
2512820	2517300	it's got a ping test thing. You can make the router ping other stuff. So in this example,
2517300	2521500	I'm just playing around with that because I kind of suspected that it might be, you know,
2521500	2527140	doing bad things when we try and ping stuff. And so I wanted to find the underlying binary or
2527620	2532480	function or library that's actually responsible for that. So what I do is I just go and play with
2532480	2537500	all the functionality. If there's something that you can do on the device to make it do something,
2537500	2541640	I do that. And I don't specifically do that, like trying injections or anything. I just,
2541640	2545120	when I'm starting out, just use the device how it's supposed to be used.
2545760	2550240	And I'll take a look at the logging. And a lot of times the logging will be very verbose
2550240	2554800	in IoT devices when you're interacting with things. And then we can actually trace that
2554800	2559800	logging back then to the underlying binaries or libraries. So in this device, and I actually
2559800	2563980	see this in a decent amount of IoT devices, they were nice enough to even just put the
2563980	2571280	function that's actually being called when you try and run this ping test. They put it in square
2571280	2576760	brackets. That's their like logging nomenclature or whatever. So it was called util underscore
2576760	2580880	exec system. So when I saw this immediately, and if you're familiar with like, you know,
2580880	2585320	web pen testing or something like that, immediately looked like it was making a system call to me.
2585380	2589680	And then they put a bunch of details in it, like they actually give us how the command is being
2589680	2593320	formatted. So I didn't get to put the whole thing because I was running out of room. But if you
2593320	2599080	can't see it, it literally says, OAL start ping, command is IP ping dash C, and it gives the whole
2599080	2604740	details. And in that, you can actually see the IP address that we put in. So it definitely is kind
2604740	2608200	of like giving us a hint that there's possible command injection or something we should look
2608200	2615540	at deeper there. Okay. So now we have an idea that that function, that util underscore exec system
2615540	2620920	is of interest to us. It could be a potential injection point. And what we should do is, you
2620920	2624800	know, on the past page or like when we're doing that, like I will interact with everything I can
2624800	2629380	and take a note of where all the logging is happening, what binaries and functions that
2629380	2634660	logging is coming from. We'll just go back to our good friend strings piping into grep, one of my
2634660	2640600	favorite tools for IoT hacking. And we can grep on that function name. So a lot of times in less
2640600	2645300	expensive IoT devices, again, they're making it easier for us. They don't strip binaries and things
2645300	2650120	like that. So the function names will just end up in the compiled binaries and libraries.
2650260	2655160	So we can just pipe that into grep and put the function name in. So in this example here, I did
2655160	2660580	that for util exec system. However, what if they do strip it? Well, if we just go back one page here,
2660580	2665800	you can see the printout here. It kind of follows a format. It says OAL start ping command is and
2665800	2670600	then gives the command. So that's a string that's actually in there too. And they're probably not
2670600	2676820	going to obfuscate it because it's not malware. So we can also just pipe common strings that we
2676820	2680460	see. So in this example, I kind of thought it was using like a print app or sprint app or something
2680460	2685320	like that. So we look for a command is and we get the same hit. You can see here that actual
2685820	2691820	string, how it is in that binary is %s command is %s. So it's using that formatting. So even if
2691820	2695480	they do strip the function names, there's still ways to get around it and find those underlying
2695480	2705640	binaries and libraries. Okay, so now that we've got our function name, we know that it's in that.
2705640	2709640	So if I just go back in this one, for example, we see the hit because we use dash F. It's in this
2709640	2716040	libcmm.so. So that is a custom library that the makers of this router in this example wrote that
2716040	2722280	has the majority of the functionality of that router baked into it. We can pop that into Ghidra
2722280	2729040	and start decompiling it. So one of the things that I find when I'm teaching IoT hacking or in
2729040	2732840	my workshops is like this is the point where people usually get a little bit overwhelmed if
2732840	2737180	they're not familiar with reverse engineering. And it starts to look quite complicated because
2737180	2742500	the output of Ghidra can be very verbose. When it decompiles it, it is, in my opinion,
2742620	2747500	a little bit more complex than just looking at regular C code. So it can be a little like
2747500	2751120	discouraging. And I see some people are like, okay, I can't do this. I'm intimidated by it. But
2751120	2756260	I have a few tips that I think can make it a lot easier for you to understand and read the output
2756260	2760600	in here and still find vulnerabilities, even if you don't understand what the heck is going on
2760600	2766720	and most of it doesn't make sense. So the very first thing I always say is because people who
2766720	2771040	are in cybersecurity and have had a little bit of an intro to Ghidra or reverse engineering is
2771040	2776520	it's usually looking at malware. And this is not malware. So with malware, usually good malware
2776520	2780520	authors or majority of them are going to try and obfuscate what they're doing, make it confusing
2780520	2784100	for reverse engineering. They're not going to use print statements. If they have strings,
2784100	2789020	they're going to obfuscate those strings that are very hard to see. Instead, for IoT devices,
2789020	2794480	we have developers who are trying to be good, helpful developers and write very clean,
2794480	2799160	readable code so that it's easy for someone else to pick up after them. If someone's reading their
2799160	2804700	code, it's going to be testable, debuggable, doing all those good things that developers do.
2804720	2811040	And also in IoT devices, we do a lot of printing out to UART to tell what's going on so that we
2811040	2815520	can actually do almost debugging through print statements in a production device,
2815520	2820440	which is nice. It makes it really easy for us to then go and trace those back.
2821100	2825080	So one of the first things that I always suggest with that in mind is to take a look
2825080	2830460	at the print statements and let those guide you to what is going on. Of course, you can't always
2830460	2834400	trust print statements. If you're a programmer, you know that it's not the best to always trust
2834400	2837900	comments or print statements. But when you're getting started reverse engineering, I think it's
2837900	2842480	okay. Just read the print statements. The very first one that I have here that's in red, it's
2842480	2846880	just actually that print statement that we saw in the logging. So it helps us confirm that we're in
2846880	2851220	the right spot. And then if you look down at line 32, it might be a little hard to read, but
2851220	2855800	essentially what it's saying there is it's just saying system fork failed. And this, we don't
2855800	2860880	care about that. It's not important to us. But if you look at the program flow and the if statements,
2860880	2865040	well, now you know what that program flow does. It just checks if a system fork failed. Because
2865040	2872180	before that, it says, you know, if local 234 equals FFFFFFF. Well, if I saw that, I have no
2872180	2875740	idea what it was. Is it integral to the thing? Well, if you look at the print statement, it
2875740	2879920	tells you exactly what it is. And you can just ignore that. The second thing you can do with
2879920	2884360	print statements that makes your life a lot easier is a lot of times they'll be like printfs or
2884360	2889840	sprintfs. And if you're not familiar with how those work, essentially we have a slot holder for
2890680	2893780	a variable that we're going to pass into that print statement. And then the print statement
2893780	2900080	basically tells you what that variable is. So in this top example here, we have the percent
2900080	2904360	command is percent. And then we have two variables passed in that, you know, we wouldn't know what
2904360	2908800	they were. One's param1 and one's underscore underscore S. Well, if we look and, you know,
2908800	2913000	we just go back a couple to that print statement. Well, the first one, this is that identifier
2913000	2917080	OAL underscore start pin command. So we know maybe that's like some sort of identifier.
2917120	2922240	And then the second one, though, now we know of our interest. Well, that's the actual string
2922240	2928640	that we manipulate, that we can pass the IP address in. And because of that sprintf or that
2928640	2932500	printf function, well, now we know that underscore underscore S variable. We know what it is. And
2932500	2938160	that's just through those print commands. The next thing I'll call out, or that's kind of like
2938160	2943620	the final thing that we've been working towards, is to just start getting used to seeing unsafe
2943620	2950440	things being done. So the easiest one to actually find is system command. So you can see that's in
2950440	2954980	the second square there. We have a system command. And if you're not familiar with that when you're
2954980	2959840	programming C, essentially, that's a way for you to just pass down to Linux to say like, hey, I
2959840	2964480	want you to run this shell command. So it's essentially the same as if you're at the terminal
2964480	2968860	and you type in, if you have a shell, whatever you pass into the system, it's the same way.
2968860	2973360	So if you're not already thinking this, this is an extremely dangerous thing to do in your
2973360	2978260	programming if you're using user variables, and especially if you're not going to be sanitizing
2978260	2983580	those variables. So in this one, for example, this util underscore exec system function that
2983580	2988980	they've written to make it easier to do system calls, it does no sanitization or checking.
2988980	2997000	However, in this example, the caller of that, that actually initially takes in that IP address,
2997000	3000980	well, it does do the sanitization. But if you look on this device, for example,
3000980	3008740	there are about 500 calls to this util underscore exec system. And the person that wrote that
3008740	3013740	function, this util underscore exec system that knows, okay, I need to sanitize my inputs further
3013740	3017660	down the chain, they might not be the same ones writing the code. So you can actually see how it
3017660	3023160	can happen to slip through where user-supplied input gets into a system call. So that's one of
3023160	3027880	the easiest things when you're starting out is to just go interact with the device,
3027880	3032780	chase down the inputs that you do because you know, and see where do they end up in the code.
3032780	3036560	And if they end up in a system call, then I really need to look into this deeper and see
3036560	3042340	if there's a way that I can do some sort of command injection. So of course, what's next
3042340	3046940	after we know this? Well, we keep interacting with the device and tracing the logging back to
3046940	3050900	binaries or libraries. So of course, there's other ways to approach this. You could just start with
3050900	3054620	the library and look at all the system calls and go backwards. But when you're getting started,
3054620	3058120	I think it's a lot easier to understand and conceptualize and not get lost in Kedra
3058120	3063580	to try and start at the source, which is how we interact with it. And we know that there's
3063580	3068640	like an injection point there, and then see if that actually filters down to something.
3068720	3073820	So don't just use web browsers, like a lot of IoT apps, they have a mobile or IoT devices,
3073920	3078400	a mobile app. So we can go use that mobile app, like do everything in the mobile app, do all the
3078400	3083040	setup, check all of that, because it's going to be like a lot of times one of those lesser used
3083040	3088100	places where there's some obscure setting or something you can set. Do all of that and see
3088100	3092440	what logging you can get and trace that back and see where it goes. Like one example I found where
3092440	3098140	I was able to crash a device is it was a camera. And if you wanted to pair it to your mobile app,
3098140	3102100	you put the QR code up to the camera, and you compare it to the mobile app. And I was never
3102100	3106920	able to like get any buffer overflow or anything, but I was able to crash the camera by doing like
3107040	3112120	a malformed QR code. So just be creative. If there's cloud, like somewhere you can sign up
3112120	3116980	in the cloud and then interact with your device, do that. Like usually there's a free 30 days or
3116980	3120760	something. And you know, we're not actually pen testing the cloud thing, we don't want to be like
3120760	3125240	trying to break that, but just interact with it how you're supposed to, and see how that filters
3125240	3130660	down into the device. And then what we're looking for is when you're starting out, there's two main
3130660	3135280	things I suggest to look for. So the first one is what we already looked at. Does it end up
3135280	3142380	in an unvalidated or unsanitized system call? And like if you look at this router and go back
3142380	3147940	and look at the CVs for this one I'm showing, or lots of IoT devices, you'll see lots of command
3147940	3152800	injections being done. Because in cheap IoT devices, they want to save money, they don't want
3152800	3157800	to write their own functionality. It's way easier to just use the built-in stuff in Linux and just
3157800	3162400	hand it off to a system call. So it's not like these don't exist, you can definitely find them.
3162600	3166560	The second one that's probably a little bit more common, but a little bit harder to find
3167360	3175520	and abuse, is if your user input gets put into an unsafe C function. So there's a few examples of
3175520	3181840	those are memcopy, stringcopy, stringcat, printf, that next one's supposed to be sprintf, getscanf.
3181840	3185400	So essentially what these are doing though is they're going to be copying your data into some
3185400	3190320	sort of buffer. And again, memory is limited on IoT devices, so we're always trying to be kind of
3190320	3195740	stingy with our buffers. And a lot of times, if you're not sanitizing or validating
3195740	3202200	those inputs, then it can end up in a buffer where we can overflow it and, you know, at the worst case,
3202200	3206460	buffer overflow, or maybe just crash the device and have some sort of denial of service.
3206600	3211440	So I could give a whole other talk then about where to go from here and how to actually then
3212080	3216980	abuse these or actually exploit buffer overflows. But if you do get this far and you find this and
3216980	3222000	like you'll be able to maybe crash the device or get some segfaults or something, then send me
3222120	3226700	a message or just go out and do some further research. And there's a lot of great resources
3226700	3232220	then for how to identify these buffer overflows. So that's where I'll end today. I just want to
3232220	3235980	wrap up with a thank you. Thanks everyone for coming. I hope you learned something. I hope you
3235980	3242220	go home and go buy a cheap IoT device when you get home. Hack it. If you do, let me know. I love
3242220	3246520	to hear when people hack it. And if you want a copy of these slides, stay in touch with me.
3246520	3251000	Link up, resources, anything. You can reach me at andrewbellini.com. Thanks everyone.
