WEBVTT

00:00.000 --> 00:01.440
Good morning, DEF CON.

00:01.900 --> 00:05.620
We are going to be hacking some baby monitors and Wi-Fi cameras today.

00:06.680 --> 00:07.900
So, a little bit about me.

00:07.900 --> 00:08.740
My name is Mark Mager.

00:08.740 --> 00:11.140
I'm senior manager of security research at Elastic.

00:11.160 --> 00:14.560
My background is primarily in Windows malware research and reverse engineering.

00:15.720 --> 00:19.980
So, what do we need to know about Wi-Fi cameras and baby monitors today?

00:20.300 --> 00:25.660
Basically, we're going to assume they're the exact same thing because they pretty much have the same feature set.

00:25.660 --> 00:29.940
They're literally marketed and sold as equivalent devices.

00:29.940 --> 00:41.020
So, what we're talking about is the $10 cameras you can find on Amazon that require internet connectivity to that specific vendor's cloud platform.

00:41.020 --> 00:47.240
And there's very basic operations, pan, tilt, zoom, things along those lines, motion detection, whatever.

00:47.240 --> 00:50.980
But yeah, that's what we're talking about when we say Wi-Fi cameras for today.

00:50.980 --> 00:52.740
So, why Wi-Fi cameras?

00:52.740 --> 01:01.760
Well, there's literally almost 125 million households across the world that have these cameras installed within their house.

01:01.760 --> 01:04.860
So, these things are everywhere.

01:05.160 --> 01:08.760
And they're obviously going anywhere and they're super cheap.

01:08.760 --> 01:10.720
So, you're going to find them everywhere.

01:10.980 --> 01:22.420
The attacks that are typically associated with these cameras, what you're probably going to hear about usually is people spying on babies and families, terrorizing them, that sort of thing.

01:22.420 --> 01:23.740
A bit upsetting there.

01:23.740 --> 01:31.740
And even things like Russians performing reconnaissance on targets within Ukraine.

01:32.620 --> 01:47.040
So, when we set out to evaluate the attack surface for Wi-Fi cameras, we wanted to break things down into a few different common attack vectors that broke down primarily into leak credentials and cloud vulnerabilities.

01:47.320 --> 01:59.420
Those seem to be the most common attack vectors, the most frequently seen ones in more of the attacks that we kind of see across the board.

02:00.060 --> 02:16.560
But yeah, so, kind of focusing on those two, that's certainly what we wanted to kind of dig into was any vulnerabilities specific to the cloud platforms, the applications that control the cameras, and the camera hardware itself.

02:19.500 --> 02:20.960
Hello, DEF CON.

02:20.960 --> 02:24.460
I'm Eric Forte and I'm doing the presentation with Mark.

02:24.460 --> 02:27.260
And I'm a security research engineer at Elastic.

02:27.260 --> 02:31.160
I'm on the Threat Research and Detection Engineering team, otherwise known as TRADE.

02:31.160 --> 02:39.500
And my background is in Linux software development, IoT systems, UAVs, civil space sector, and then also doing some threat research.

02:39.820 --> 02:51.560
And so when we're talking about these cameras, for the purposes of this talk, we looked at a number of different cameras, but we're going to primarily focus on the WandsView Q5 and the WandsView Q6.

02:51.760 --> 03:09.720
And as far as why we picked these cameras, it was sort of clear to see on the Amazon reviews that they might have something for us to look at, some vulnerabilities that other people had just come across because they were readily hacked enough that it took notice.

03:10.300 --> 03:21.920
So these cameras are made by WandsView, but there are other vendors that also produce cameras, such as Sonado and some others as well, which we'll touch on a little bit more in a little bit.

03:21.920 --> 03:26.280
But they're primarily under the AJ Cloud management infrastructure.

03:26.280 --> 03:34.280
And so this is going to be the cloud services that provide you with the apps, with the way of connecting to it.

03:34.280 --> 03:39.740
So the WandsView versus Sonado versus others may have their own little differences in the apps themselves.

03:39.740 --> 03:45.960
But primarily, this cloud interface is with AJ Cloud, and we'll get into a lot more of that in a minute.

03:46.120 --> 03:56.820
So when we were first with these cameras, we kind of looked at a few different approaches for how we were going to try and see if we could get some of those similar Amazon review results.

03:57.080 --> 03:59.300
So first, we were looking at remote access.

03:59.300 --> 04:05.120
So this is going to be accessing the camera through whatever companion app that ships with the camera.

04:05.120 --> 04:07.820
We also were going to look at some local attacks.

04:07.820 --> 04:15.060
So going to be some active and passive networking recon, in addition to seeing what else other services and things were running there.

04:15.060 --> 04:21.680
Also looking at some device physical manipulation, which obviously these are Wi-Fi cameras.

04:21.680 --> 04:24.480
They're not necessarily like closed circuit TV cameras.

04:24.480 --> 04:29.020
So we're expecting that there's going to be some physical attacks, which there are.

04:29.020 --> 04:30.040
We'll get to that.

04:30.280 --> 04:35.600
But this is still, again, as an attack vector, can enable some other aspects.

04:36.100 --> 04:39.280
Then finally, looking at the hardware itself.

04:39.280 --> 04:50.280
So looking at the chip and seeing what we can use, what we can either get the firmware off, what we can do to kind of, again, extend that vulnerability process, look for serial communications and things like that.

04:50.280 --> 04:54.560
Which, spoiler alert, we found some over UART.

04:54.560 --> 05:00.060
So for our lab setup, we have a number of different things that we wanted to look at, right?

05:00.060 --> 05:01.660
So we've got different apps.

05:01.740 --> 05:07.480
So we want to have a very controlled environment, because we know, say, one, they're easy to hack.

05:07.480 --> 05:09.140
So we don't want to be hacked ourselves.

05:09.140 --> 05:17.180
But on top of that, we know as these are largely, say, Chinese make cameras, that they may also want to be watching what we're doing.

05:17.180 --> 05:20.220
So we wanted to have a completely different setup.

05:20.220 --> 05:22.920
And so we have a mobile hotspot.

05:23.080 --> 05:24.840
I like the T-Mobile T9s.

05:24.840 --> 05:25.320
They're cheap.

05:25.320 --> 05:28.280
You can get them for about 20 bucks, and they do the job great.

05:28.320 --> 05:30.060
We have the camera, of course, itself.

05:30.060 --> 05:33.900
Then we needed, say, Windows and Linux operating systems.

05:33.900 --> 05:37.000
You don't actually need Linux, except I would argue that you do.

05:37.000 --> 05:41.300
But practically speaking, you don't need Linux to be able to run any of these things.

05:41.340 --> 05:42.880
But we used that.

05:42.880 --> 05:54.140
But we did need Windows to also look at the companion Windows app, in addition to the iOS and Android apps, which we had phones and virtual machines set up for as well.

05:54.780 --> 06:15.480
From a software side, we use a number of different tools, including, say, Wireshark, running Android Studio to try and see what we could find out from the app, various other sort of decompiling mechanisms, and also using the Elastic Stack to look at the network communication logs and how we can parse some of the different protocols that we saw.

06:15.480 --> 06:21.560
And we will, again, we'll talk to that more in a some peer-to-peer traffic there.

06:21.740 --> 06:32.560
From a hardware standpoint, since we wanted to do the full gamut of going from complete hardware takedown as well as looking at all the software, we had some hardware teardown tools.

06:32.560 --> 06:36.680
I like what iFixit has, but of course you can take your pick.

06:36.680 --> 06:40.760
Then we needed some USB TTY connector, right?

06:40.760 --> 06:46.100
So in this case, you know, it's just your typical Adafruit USB TTY serial connector there.

06:46.660 --> 07:02.600
We also have a, and we'll get to it more in a minute, but using the GreatFET 1 as a logic analyzer, and to be able to read voltages and things like that in case we needed to actually hard pull something off of the chip, solder something or things like that.

07:02.600 --> 07:06.820
Ultimately, we didn't need to do that, but we were prepared for that nonetheless.

07:07.860 --> 07:17.820
Raspberry Pi, because it's image and distribute, so for doing cross compilation and things like that, cheap, easy to come by.

07:17.820 --> 07:38.760
And then also, we used Alpha Wi-Fi, just a USB Wi-Fi NIC, which for us, why this was important and why you'll need some NIC that you can get active, or rather passive sniffing on, is because you're going to want to capture all of the traffic going from the camera to the cloud,

07:38.760 --> 07:48.760
and not just what will appear as network traffic, and we'll get to that in a little bit, because you're going to, to follow along, you'll need to parse some other additional protocols.

07:48.920 --> 07:54.020
So, getting a little bit into our remote and local recon, initial attacks were limited.

07:54.020 --> 07:57.280
They had a fairly locked down attack surface.

07:57.340 --> 08:06.040
The active network and local reconnaissance doesn't reveal too much or too much interesting as far as running on the traffic, or rather running on the camera.

08:06.140 --> 08:10.620
The network traffic itself is fairly mundane.

08:10.620 --> 08:15.920
It uses encrypted web sockets, which is a good sign, right, that they are at least using encryption, things like that.

08:16.560 --> 08:23.100
So, we tried to do some man-in-the-middle attacks, but ultimately, we weren't particularly successful with that.

08:23.160 --> 08:27.840
Looking at the apps themselves, they were likely obfuscated with ProGuard.

08:27.920 --> 08:33.600
We couldn't, just from the, from being, unpacking the APK, get too far there.

08:34.520 --> 08:38.880
But, so those APKs were just not easily that debuggable.

08:38.880 --> 08:42.680
But just as a quick note, ultimately, there's three lines of communication.

08:42.680 --> 08:48.840
We're going from the mobile app to the cloud, the mobile app to the camera, and then also from the camera to the cloud, and then the mobile app.

08:48.840 --> 08:53.120
And that, just as a sort of primer, we'll get into that more in a little bit.

08:53.920 --> 08:59.720
Just as far as the physical device itself, again, we weren't really expecting it to be that secure.

08:59.720 --> 09:10.360
It has an exposed reset button, so if you had this sitting, like, let's say, up here on stage, if you were to walk by, hit the reset button, and then flash a QR code, you could steal the camera, and then now it's yours.

09:10.360 --> 09:11.600
You have full control over it.

09:11.600 --> 09:15.940
Again, that's not particularly surprising, because that's part of the expected setup process.

09:16.840 --> 09:26.960
So, in that sense, there's no, so there's also an exposed SD card slot.

09:26.960 --> 09:31.140
So, as we came to discover later, this can be used to load alternative firmware as well.

09:31.140 --> 09:41.040
We'll get into what the bootloader looks like in a minute, too, but this, if you were to craft a malicious SD card, you could go plug it into the camera, and then also have a field day there, too.

09:41.840 --> 09:45.000
The hardware recon starts to get a little bit more interesting.

09:45.040 --> 09:50.260
So, when we look at the chip, it's an Experse T31 SoC.

09:50.320 --> 09:54.720
It's primarily a MIPS processor, but it also has a companion RISC-V processor.

09:54.740 --> 10:07.240
But the primary thing I want you to focus on, for the sake of the demonstration, is that we have an I2C and UART bus that we should, could be looking for, right, on the hardware, on the chip itself.

10:07.240 --> 10:14.500
We also have a secure boot, which may, you know, that could throw a wrench into things.

10:14.500 --> 10:18.320
And then we also have a hardware watchdog supported by this chip.

10:18.320 --> 10:24.460
Doesn't necessarily mean they're using it, but again, these are things that we can look for in our hardware recon.

10:24.520 --> 10:31.980
So, in tearing down hard the camera, we found a potential UART, UN access ports there.

10:31.980 --> 10:43.240
And so we connected a logic analyzer, the great FET1, looked at the voltages, used some of the protocol detection, saw that it appears to be UART.

10:43.240 --> 10:48.820
And if we look at the actual signal, we saw that it indeed was.

10:48.940 --> 10:57.360
So, we go ahead and use screen, but you can use, again, whatever your favorite tool is to connect over default baud rate to UART.

10:57.420 --> 11:01.000
And lo and behold, on boot, we have UBOOT.

11:01.140 --> 11:03.720
So that, of course, is useful for us.

11:03.740 --> 11:12.600
But also , we, in further expecting this, that secure boot is not enabled by default, as far on the camera, even though the chip supports it.

11:12.600 --> 11:19.480
So, we can just do a quick boot into single user mode and get a root shell so that we can start poking around further.

11:19.480 --> 11:30.320
Now, this camera was particularly easy to do this because you could just straight set the environment variables for UBOOT to be able to boot into single user mode and get root.

11:30.320 --> 11:32.560
Other cameras that we looked at were not as simple as this.

11:32.560 --> 11:39.040
And sometimes you have to use memory offsets and things like that, but this one in particular was fairly straightforward.

11:39.840 --> 11:46.980
So, again, we can hit boot and then just drop into our root shell and then be able to poke around on the camera.

11:47.060 --> 11:51.980
So, now that we're there, a few things that we want to then do to go forward.

11:51.980 --> 11:55.220
First off, we may want to try and establish persistence.

11:55.220 --> 12:05.680
But if you've done this type of attack before, going to single user mode, especially on embedded devices, and just embedded devices in general, you might see that you're on a read-only file system.

12:05.680 --> 12:08.580
Well, many times this is only read-only ish.

12:08.580 --> 12:11.280
It's not quite truly read-only.

12:11.280 --> 12:22.960
So, if we take a look at fstab, we can see that a number of these mount points are separated, but then also they are tempfs shares.

12:22.960 --> 12:36.420
So, we can then make our own tempfs partition or just mount a tempfs partition for read-write access, modify the desired settings, and we can run whatever we want, of course, and have persistence.

12:36.480 --> 12:49.940
Which, largely, for these type of devices, you will need this type of interface, whether it be for... there's other methods for logging, but again, when Linux is running, it often needs to be able to make some level modifications.

12:49.960 --> 13:09.500
So, this is just walking through one way of doing that, of saying, hey, I want to create a tempfs share for dev, and then go ahead and mount it, and then also then mount Etsy, such that I can make Etsy read-write as well, which, of course, gives us access to some other things.

13:09.500 --> 13:19.480
And so, just demonstrating there that if I run... that if I just create a file, then it does, in fact, show up, as opposed to when it didn't before.

13:19.620 --> 13:24.340
So, if you want... so, that's just one way, of course, then you can go and do whatever you want from that perspective.

13:24.760 --> 13:36.980
But if you want to go log into the existing root user, of course, you can pull Etsy password, and then go and just use John the Ripper or something to crack that hash, and go from there.

13:37.080 --> 13:41.500
But for our purposes, again, we want to keep looking for the other software vulnerabilities.

13:41.500 --> 13:46.220
So, this gives us an easy way to pull the firmware over the serial connection.

13:46.420 --> 13:54.000
So , we... and in addition to the firmware, we're pulling a JFS to read-write partition containing any log data, again, just might be useful for us.

13:54.000 --> 13:58.960
So, this is just demonstrating how you can... one way of pulling the firmware.

13:59.020 --> 14:09.900
There are a number of different ways, but this is just how we did it using... using binwalk, and then, of course, just echoing the bytes out in the appropriate format over the serial connection.

14:10.240 --> 14:14.200
So, with that, I'm going to hand it over to Mark to see what he did with the firmware.

14:15.960 --> 14:16.540
All right.

14:16.680 --> 14:26.860
So, as Eric mentioned earlier, we definitely were running into issues with the iOS and Android apps for WandsView specifically, right?

14:27.080 --> 14:29.560
So, we're hitting our heads against the wall a little bit.

14:29.560 --> 14:40.000
So, we kind of backed things up a little bit and went directly to WandsView's site, and they host a version of WandsView Cloud that is for older versions of Windows.

14:40.000 --> 14:42.900
I think it says Windows 7 specifically on their site.

14:43.160 --> 14:50.080
But the main takeaways from that is that that app is still compatible with all WandsView devices.

14:50.080 --> 14:51.780
It does have a limited feature set.

14:51.780 --> 14:54.760
I mean, they're still trying to push you towards using the apps.

14:55.200 --> 15:09.100
You know, that's totally, you know, their sort of thing because they want everybody to sign up for their cloud plan so they can make more money off of everybody, not just the $10 sales, you know, from the device itself, right?

15:09.980 --> 15:17.320
A couple other things related to that, this Windows app, is it does generate a significantly less amount of network traffic.

15:17.320 --> 15:18.900
That's going to come in handy later.

15:18.900 --> 15:21.680
And the binaries are not packed.

15:21.680 --> 15:28.220
Eric mentioned that the APKs look like they're probably packed with ProGuard.

15:28.220 --> 15:33.420
So, you know, definitely being able to disassemble and decompile and debug pretty easily.

15:33.500 --> 15:35.980
That helps out quite a bit.

15:36.040 --> 15:46.580
And then last, but certainly not least, is that it does generate a very, very verbose debug log file, which I'm going to dig into right now.

15:46.580 --> 15:53.840
And the first thing we noticed when we ran it the first time, it logs user account credentials in clear text.

15:53.840 --> 15:55.720
That's obviously terrible.

15:55.880 --> 15:58.160
So, yeah, not a great sign of things.

15:58.760 --> 16:08.980
And as Eric mentioned before, we had significant difficulties trying to man the middle of any of the app traffic before, so we had no visibility into that.

16:08.980 --> 16:19.080
But helpfully, their developers decided to actually log all post request and response data so it's all there in the clear.

16:19.080 --> 16:23.780
Who needs to man the middle of anything when you have it in the clear on a file on disk?

16:25.640 --> 16:26.400
So, yeah.

16:26.400 --> 16:43.000
So, digging into it, yeah, we could definitely get a ton of insight into the sign-on process that we did not have before, including the actual endpoint APIs, as well as, you know, all the fields that are involved both in the requests and responses.

16:43.000 --> 16:49.200
So, it's not really a ton there.

16:49.200 --> 16:50.860
It's more just initial setup.

16:52.760 --> 16:58.500
This check is more just to see if this is a valid account that you're attempting to sign on.

16:59.020 --> 17:15.380
And then this here is where the actual, let's see, yeah, is an initial account where, but, yeah, challenge involved where the token's generated for that specific client application, and then there's a little bit of key exchange that happens.

17:15.660 --> 17:17.820
But, yeah, not too much else going on there.

17:17.920 --> 17:20.740
This is where the sign-on really begins.

17:20.920 --> 17:26.180
Assaulted and, yeah, your password is at least assaulted and hashed, so it's not set in the clear, thank God.

17:27.120 --> 17:35.920
And then, yeah, I mean, it's mostly just to initialize the session and to confirm that you are allowed to log into this account.

17:36.740 --> 17:47.580
From there, we, things really start to get interesting because now we can, now that we're logged in, we can request a list of devices that are associated with that specific account.

17:47.580 --> 17:56.480
And as you can see here, there's a specific device ID, along with some more configuration information, primarily endpoint URIs.

17:58.080 --> 18:04.780
And then there's another device configuration API endpoint that's hit.

18:04.820 --> 18:17.520
This is very notable, we're going to refer back to this later, but this is where a device ID is first transmitted from the application to the cloud.

18:18.300 --> 18:21.780
And, you know, more configuration information comes through.

18:21.980 --> 18:23.740
We'll dig into that a bit.

18:24.200 --> 18:28.980
And then the last request we really dig into is fetch infos.

18:28.980 --> 18:39.700
And this provides a much, much larger picture of the data that is stored for that specific device.

18:39.700 --> 18:47.720
And there's a lot to kind of dig into, but what you'll want to really highlight on is there's a snapshot URL that's provided.

18:47.780 --> 18:51.720
And that just happens to be publicly accessible.

18:51.720 --> 18:53.120
And that's a picture of my kitchen.

18:53.120 --> 18:55.300
So from back in April.

18:56.660 --> 19:06.180
So digging further into more of the response data, there's a few things certainly to note here that are a bit concerning, right?

19:06.820 --> 19:24.940
The firmware version, the very specific firmware version that is running on the device itself, that's referenced there, along with the next firmware version they're supposed to upgrade to, along with the actual SSID that the device is currently signed onto,

19:24.940 --> 19:29.240
along with some other network configuration information including its MAC address.

19:29.640 --> 19:38.380
And then we also have, you know, geolocation data, you know, in the form of, you know, time zone data and things like that.

19:39.140 --> 19:52.780
So going back to the device configuration request, what we tried to do first is we wanted to see if we could actually access other devices that weren't associated with our particular account.

19:53.340 --> 20:01.760
So we tried a very naive approach where all we wanted to do was simply just replace the device ID in that particular request.

20:01.880 --> 20:18.340
And without really doing a significant amount of reverse engineering, we can locate that pretty easily based off of the verbose log data because if we just look up post request, we can, you know, we can see how many times that's specifically logged to the log file.

20:18.340 --> 20:32.080
And then we can cross-reference that with the disassembly in IDA in order to target the specific device configuration post request to get a better idea of where we would want to jump in.

20:32.080 --> 20:50.680
And so digging further into the particular function, what we decided to do is we needed to set a breakpoint at this particular address, which would be before the post request actually goes out, before the JSON is fully formed as well.

20:51.040 --> 20:54.680
You know, we're going to swap out the device IDs and memory and then resume execution.

20:54.680 --> 20:55.960
So pretty straightforward.

20:56.160 --> 21:07.560
What this ends up kind of looking like is, you know, I wrote up maybe a 60-line Python script that does this all for us, which we will dig into right now.

21:08.510 --> 21:18.680
Okay, so what we have right here is, well, first I'll demonstrate that this account is...

21:23.620 --> 21:32.680
So we already have one specific camera that is tied to this account.

21:32.680 --> 21:38.860
And it's offline at the moment, so it's not really concerning that, right?

21:38.860 --> 21:42.980
We'll attempt to connect to it, but nothing's going to happen.

21:52.710 --> 22:00.930
Now, if we kick off the exploit script, what it's going to do is it's going to launch the same WandsView cloud for Windows app.

22:01.450 --> 22:04.610
We'll proceed to sign in as expected.

22:07.030 --> 22:13.430
And once we hit our breakpoint, we will swap out the device ID in memory.

22:13.910 --> 22:19.310
And then once it has finished here, it will resume execution.

22:30.120 --> 22:31.780
And we're online.

22:32.580 --> 22:34.720
So the thing is...

22:39.660 --> 22:43.000
So yeah, we can do everything in the app.

22:43.000 --> 22:44.340
We can pan and tilt.

22:46.080 --> 22:53.720
Yeah, I mean, like I said, it is a bit more limited feature set compared to the mobile apps.

22:53.720 --> 23:00.960
But basically, right, we've proven we can get access to an account or a device that's not associated with our account.

23:00.960 --> 23:06.820
It's obviously a very, very significant access control vulnerability.

23:08.000 --> 23:15.200
So yeah, you know, certainly that was a pretty big discovery, you know, right off the bat.

23:18.960 --> 23:26.060
So you might have seen in the background that there was, you know, certainly a lot of network traffic being generated in the background.

23:26.580 --> 23:32.000
It was all primarily UDP, but we hadn't really no idea what it is in particular.

23:33.060 --> 23:50.980
Now, doing research before we submitted to DEF CON, we did come across a particular IoT peer-to-peer protocol called PPPP that was pretty significantly researched and detailed by Polymer PC.

23:50.980 --> 23:59.220
His website, he presented at DEF CON 28 in 2020, fully tearing down the protocol and all that.

23:59.220 --> 24:05.260
So ideally, this was going to be something that, you know, maybe that was going to be in use here too.

24:05.260 --> 24:12.060
So we kind of set out to explore that by just looking for references to P2P and PPPPP.

24:12.120 --> 24:28.940
And yeah, sure enough, within the Wandscape Cloud binary itself, as well as the DLLs, we found, you know, numerous references, even references to their specific PDBs, which reference both, you know, multiple peer-to-peer terms.

24:28.940 --> 24:33.900
So yeah, we're pretty sure that we're dealing with the same protocol.

24:33.900 --> 24:44.620
And going from there then, there is a excellent dissector for this peer-to-peer protocol that is available and posted on GitHub as of last year.

24:44.800 --> 24:54.660
You know, we load it in and all of a sudden that UDP traffic, we have no idea what it is, turns into a very recognizable messaging sequence that's associated with peer-to-peer.

24:55.920 --> 25:03.600
So very, very briefly, the peer-to-peer protocol is used by a ton of IoT devices across hundreds of vendors.

25:03.600 --> 25:08.840
It's been in use for, you know, the better part of the last decade, if not longer.

25:09.240 --> 25:14.540
It uses UDP hole punching in order to circumvent restrictive network configurations.

25:14.800 --> 25:20.320
And it allows you, you know, these apps to connect to the cameras from anywhere in the world, right?

25:20.320 --> 25:22.760
They want it to be as accessible as possible, right?

25:22.760 --> 25:24.340
That's the whole point of these devices.

25:25.320 --> 25:36.320
And yeah, sometimes the connections are either direct to the camera, depending on the configuration, or they go through a relay if they have to, you know, get around certain restrictions.

25:41.320 --> 25:45.020
So now we have established some initial access, right?

25:45.020 --> 25:53.760
So we also have, as we looked at a little bit before, the firmware, which we can now go into some of that static reverse engineering.

25:53.760 --> 25:58.820
We have packet capture for the camera and the app network communications.

25:58.880 --> 26:03.020
We have log files from both the windows and the camera logs.

26:03.020 --> 26:11.220
The logs, as when we logged in before under root, we of course have access to all of the D message logs and things like that as well.

26:11.300 --> 26:20.860
And then we can get the camera logs from any of its hardware mechanisms as well for the audio and camera, pan, tilt, zoom, et cetera.

26:21.140 --> 26:26.200
So now we want to kind of establish some more advanced access for looking for some additional exploits.

26:26.200 --> 26:33.620
So one, or first, we're going to look for that live log output for some immediate feedback to determine some of the control flow.

26:33.620 --> 26:41.600
Again, from the windows app, right, we were able to see that some of the, they are logging the post request and responses.

26:41.600 --> 26:52.040
So we're hopeful that they're going to do something similar on the camera, but we also want to establish a, we want to have a debugger running on that camera so we can look at some of these applications and see what we can do.

26:52.040 --> 26:57.100
So first for live log output, it's very, very simple, very easy.

26:57.100 --> 27:07.980
You plug the serial, you just get your serial shell over, you aren't plugged into say in this case, a Raspberry Pi, but again, you could use whatever you like and it spits out the logs over serial by default.

27:07.980 --> 27:13.400
So you don't even necessarily need to use the root access or boot the single user mode to just get the logs.

27:13.400 --> 27:16.120
But again, that's just one way of doing it.

27:16.260 --> 27:20.720
But one thing that we'll quickly run into is the kernel watch dog.

27:20.720 --> 27:24.760
So if the watch dog is not written to, it reboots the camera.

27:24.760 --> 27:41.800
So this, what we're seeing here is if you try to kill the init, the primary app, or in this case, we'll get to it in a minute, but if you start to kill off things in the camera to go look at them or pause things, it will trigger the, the, the kernel watchdog process,

27:41.800 --> 27:44.100
which will then reboot the camera.

27:44.380 --> 27:46.600
This isn't the only say security mechanism.

27:46.600 --> 28:02.360
This is just the one that the primary one that you would have to get around to be able to run a debugger, to be able to look at the primary application that they're running on the camera, which they call init app, which, which handles all of the connection to the AJ cloud,

28:02.360 --> 28:05.940
providing all of the video streaming and the rest of the control of the camera.

28:06.100 --> 28:15.200
They wrap this init app in a daemon.sh script, which is just a simple while loop that says, Hey, keep kicking off the init app.

28:15.200 --> 28:26.560
If I have to kick it off more than X number of times, reboot it again, acting sort of like a, again, a catch all in case something went really wrong, but that init app is reporting into the watchdog.

28:26.560 --> 28:34.740
And so this is, that's, so if you either kill the init app or again, kill the daemon and then kill the init app, that's where you're going to end up rebooting the device.

28:34.740 --> 28:38.580
And so if you're using single user mode to get root, you're going to lose that.

28:38.580 --> 28:45.460
And I, and some of the, unless you have set up some level of persistence, you're going to lose any of the edits as well.

28:45.860 --> 28:48.720
So of course, next step is to defeat the watchdog.

28:48.720 --> 28:50.460
So there are a couple of approaches here, right?

28:50.460 --> 28:51.240
That you could do.

28:51.240 --> 29:04.800
So the first one, um, which you can actually get this example right off from the, uh, the kernel watchdog API, um, information from the, the Linux kernel, you could just simply write some C code to keep sending a live messages to the watchdog, right?

29:04.800 --> 29:08.400
And so since we have root access, we could do something like that.

29:08.400 --> 29:25.580
However, this approach is not necessarily what we want to do and not what we wanted to do either, because the problem, the fundamental problem with this is that while you could keep sending the messages, or you could even use like take hold of the kernel semaphores and keep it open just for yourself.

29:25.580 --> 29:27.220
So init app can't write to it.

29:27.380 --> 29:39.880
That doesn't necessarily help you because init app, if it can't write to it, then it's going to know that you're here and know that you're now disabling its ability to operate.

29:39.880 --> 29:42.680
And then it may change the way that it's going to operate.

29:42.680 --> 29:49.680
In this case, we know say that it, that it does, but again, that's not necessarily the approach you want to use, even though it might work for, for your environment.

29:50.040 --> 29:51.120
So there's another way.

29:51.300 --> 29:54.900
Um, there's, there's other ways other than these two, but these are just the ones we're going to talk through today.

29:55.000 --> 30:11.140
Um, there's the magic close feature, which if you go look in the Linux kernel driver, uh, what the watchdog driver API from Linux kernel 2.4.18, you can see that there, if you write a magic character, in this case, an uppercase V, there's another character that'll work as well.

30:11.140 --> 30:22.120
But if you write that to dev watchdog, and that's the last thing that gets written to dev watchdog, it then can cleanly disable the watchdog, uh, the, the kernel watchdog.

30:22.120 --> 30:28.060
Now, as a note, the camera is not running Linux kernel 2.4.18, but it does still work.

30:28.060 --> 30:29.840
Um, so your mileage may vary.

30:29.840 --> 30:34.180
It's running a three dot kernel, but, um, again, it's still, still may work.

30:34.180 --> 30:41.360
So you could write a simple script such as this, or again, however you would like to do it to just simply continuously write V.

30:41.360 --> 30:52.140
And the reason why you may want to do something like this instead of just write V and stop is something, some other process, especially as you're doing your reverse engineering might come along and reactivate the watchdog.

30:52.140 --> 31:02.540
So if you want to try and keep making it such that, that you're not going to be rebooted, or at least as have some protection against that, you, you might want to continuously write to it.

31:02.740 --> 31:11.920
So now with the watchdog generally defeated, we need to be able to run a debugger on the camera, which means we need to be able to compile binaries that can run on the camera.

31:12.180 --> 31:17.500
Um, so in this case, we discovered that our, our camera is a little Indian MIPS.

31:17.520 --> 31:28.260
Um, so just as a quick, um, example, we can compile arbitrary C code using just out of the box, um, like the MIPS Linux GCC compilers.

31:28.260 --> 31:32.180
We can run a quick hello MIPS and see.

31:32.180 --> 31:35.300
So I did not know this at the time when I was doing it.

31:35.300 --> 31:41.280
I built a tool chain and compiled, uh, compiled GDB server myself using that tool chain.

31:41.280 --> 31:56.040
But later on, we found that there is a prebuilt one that works that that's the link to be able to get to it again, again, that will be available, but what you'll need to do to be able to run GDB server, you'll need to make sure that you're exporting the proper paths to get the proper libraries that an app needs,

31:56.040 --> 31:57.900
then expose it over some port.

31:57.900 --> 31:59.380
It could be, it works over serial.

31:59.380 --> 32:06.280
I would recommend if you can use it, doing it over networking, just because the serial debugging can be very slow when you're using this many libraries.

32:06.320 --> 32:09.340
Um, and again, just an example of how to do that.

32:09.440 --> 32:16.440
Um, so we can then connect to our, um, use, and this is actually one important note.

32:16.440 --> 32:24.620
When you're using GDB to connect to GDB server, you will likely, you very likely need to use the multi-architecture version.

32:24.620 --> 32:32.220
Otherwise it will not work unless you happen to be running, um, little Indian MIPS on your laptop, which at least for me, I'm not.

32:32.420 --> 32:38.300
Um, but once you get there, again, we know that an in-app is calling out to the watchdog.

32:38.320 --> 32:46.140
So we need to overwrite those functions in memory with no ops to be able to have it not call to the watchdog at all.

32:46.260 --> 32:48.400
Is this absolutely necessary?

32:48.740 --> 32:52.420
Maybe not, but it will make it a lot cleaner for us if we just don't have to worry about it.

32:52.420 --> 32:53.560
So that's, that's what we did.

32:53.560 --> 33:01.500
And you can, at least in our case, we were able to find that, that, that those locations were where those functions were and, uh, we just overwrote them.

33:02.260 --> 33:02.980
Sure.

33:03.200 --> 33:04.820
So I'll hand it over to Mark.

33:05.040 --> 33:05.820
All right.

33:05.820 --> 33:10.960
Uh, so yeah, we're going to skip over the, the, this second demo, uh, and just kind of jump right into it.

33:10.960 --> 33:22.360
So, uh, with the peer-to-peer discovery, what we wanted to do is build a client so we could actually connect directly to our camera, uh, and, uh, issue commands to it in order to, uh, attack and exploit it, right?

33:22.360 --> 33:33.320
Uh, so the peer-to-peer, uh, servers, you can discover them, uh, using Nmap or Masscan, uh, and delivering that 4-byte payload, uh, to UDP port 607222.

33:34.120 --> 33:50.340
Um, and yeah, so very briefly how to establish a peer-to-peer connection, uh, you need to send it a hello message from the client, uh, it'll, it'll act back, uh, you need to query for a specific device ID if this peer-to-peer server has any idea of it,

33:50.340 --> 34:06.400
uh, those are device IDs are also serial numbers that are found on the bottom or on the back of these devices, um, and hopefully the peer-to-peer server will say that it knows how to access the device, uh, and then instruct you, uh, to punch a hole to a specific IP and port,

34:06.400 --> 34:23.420
um, and then once we have the idea of where we're supposed to go to, uh, we can query that specific relay server or the device itself, uh, you know, if we can connect to it, um, it should hopefully say yes, uh, and then it'll send its packets back and then,

34:23.420 --> 34:25.100
yeah, your peer-to-peer connection is ready.

34:25.280 --> 34:30.960
Uh, so yeah, there, there's a good exploit script that we kind of based some of our work on, uh, definitely check that out when you get a chance.

34:31.220 --> 34:46.020
Um, but yeah, basically, uh, in order to prove things out, uh, we, we looked at how the camera panned initially over Wireshark, uh, it was very easy to tell which specific, uh, packet belonged to a pan operation, uh, then we trace that back to, uh, debug,

34:46.020 --> 35:01.640
debug log messages from the firmware, uh, and then actually dug into the firmware itself specifically to find where, uh, where that log, uh, message is being generated and what function is primarily handling, um, a lot of the comms and all that.

35:01.640 --> 35:18.080
So, uh, very brief, uh, demo and we're gonna just kind of jump ahead to our more compelling demo of essentially what you can do, um, with our discovery of, of how to build a peer-to-peer client.

35:18.080 --> 35:27.760
So, um, what we can see here is there is a, uh, there's an INI file on the camera itself that has the serial number.

35:27.760 --> 35:36.340
And what we find out is that that's, that is the only way that the device knows what its own device ID is.

35:36.340 --> 35:44.360
And so there is actually a command through peer-to-peer that allows us to overwrite the contents of that INI file.

35:44.360 --> 35:57.540
So what we're trying to do is overwrite, uh, the, the serial number itself to an arbitrary value that's just going to completely brick this machine and make it completely inaccessible to the internet.

35:57.700 --> 36:04.800
And essentially the user's gonna have to throw it away because there's no way to restore that unless you have access like we do.

36:04.800 --> 36:13.180
Uh, and so we send our packets, uh, and what we can see here is we pulled up the same INI file and now it's full of garbage.

36:15.260 --> 36:20.100
And we actually have another command we're going to send to it that's going to crash and reboot the cam.

36:20.100 --> 36:26.980
Uh, and from there, uh, what we can see is, you know, things are kind of already going haywire a little bit.

36:26.980 --> 36:45.740
Uh, the camera is attempting to reboot right now, but what we'll find out pretty shortly here is that it has, uh, it will attempt to issue requests to AJ Cloud's infrastructure, but ultimately it's going to be unsuccessful because it's sending along absolute garbage,

36:45.740 --> 36:48.120
uh, in its curl requests.

36:50.660 --> 36:54.620
And if we kind of like skip ahead a little bit here, this is a press for time.

36:55.280 --> 37:05.630
Um, what we can see here, yeah, if you, if you kind of highlight that, there's not much there.

37:06.730 --> 37:08.170
Ah, yes.

37:08.530 --> 37:12.090
So yeah, that doesn't really look like a good curl request.

37:20.180 --> 37:21.100
Okay.

37:21.100 --> 37:26.860
So very, very briefly, um, what devices are actually affected by this, right?

37:26.860 --> 37:35.940
Uh, so Wansview, every single device associated with Wansview is affected, including pet feeders, light bulbs, indoor and outdoor cameras.

37:35.940 --> 37:43.000
Uh, Galu as well, since they're, uh, you know, an affiliate company of Wansview, uh, and Sonato as well.

37:43.140 --> 37:49.820
Um, and then also Philemi is another, uh, manufacturer that, that we, uh, were able to experiment with.

37:50.180 --> 37:54.840
Um, but ultimately the affected vendors, uh, it all stems from AJ Cloud.

37:54.840 --> 37:59.660
It's whoever's running their device firmware on their cloud platform.

37:59.900 --> 38:04.920
And this ultimately affects seven different vendors, possibly even more.

38:04.920 --> 38:06.700
We weren't able to confirm all of these.

38:08.460 --> 38:11.860
So just real quick, what are some things that the vendors did right?

38:11.860 --> 38:14.120
They have certificate web-based authentication.

38:14.120 --> 38:17.040
It was fairly difficult to do some man-in-the-middle attacks from that.

38:17.040 --> 38:20.320
They have signed and obfuscated APKs, another good thing.

38:20.320 --> 38:24.380
They have a pared-down local operating system that at least attempts to be read-only.

38:24.380 --> 38:29.020
They could have had secure boot, but again, they have a read-only-ish file system.

38:29.020 --> 38:34.360
So you have to do some work even with physical access to be able to go and attack the machine.

38:34.360 --> 38:37.240
What they did wrong, of course, unauthenticated cloud access.

38:37.240 --> 38:40.680
The demos that we showed you, again, did not require any authentication.

38:40.800 --> 38:49.820
We have significant verbose debugging in the log app, the vulnerable peer-to-peer access, and again, no secure boot despite the SoC supporting it.

38:49.820 --> 38:53.300
And it's very easy to manipulate when you have physical access.

38:53.500 --> 38:57.940
So mitigations, of course, if you want to use them, segment them off your network.

38:57.940 --> 39:01.360
The critical vulnerabilities in the cloud infrastructure will put your data at risk.

39:01.360 --> 39:03.720
So we would just recommend not using them at all.

39:03.720 --> 39:07.380
Again, restrict the inbound, outbound comms.

39:07.940 --> 39:12.440
You basically just want to block all of the different traffic that you have.

39:12.440 --> 39:15.360
You could also flash it with a different operating system.

39:15.360 --> 39:19.220
For sake of time, I'm going to kind of run through this really fast.

39:19.500 --> 39:21.580
OpenIPC, I would recommend you checking it out.

39:21.580 --> 39:24.600
At least the Q5 is directly supported.

39:24.600 --> 39:28.880
So you could flash it with that, but it supports a lot of different SoCs.

39:29.040 --> 39:34.700
So our tools that we used for this demo, we'll be releasing them shortly on GitHub.

39:35.660 --> 39:38.960
And feel free to follow along with the demo.

39:39.240 --> 39:41.500
There's some other future research opportunities.

39:41.520 --> 39:44.460
Again, apologies for having to run through this real quick.

39:44.460 --> 39:47.380
But thank you so much for coming to our talk.

39:47.840 --> 39:54.980
Special thanks to, of course, the following here, and definitely follow us on Twitter, and Elastic Security Labs.

39:54.980 --> 39:56.580
So again, thank you very much, DEF CON.

