[00:00.000 --> 00:05.620] Good morning, DEF CON. We are going to be hacking some baby monitors and Wi-Fi cameras today. [00:06.680 --> 00:10.280] So, a little bit about me. My name is Mark Mager. I'm senior manager of security research at [00:10.280 --> 00:14.560] Elastic. My background is primarily in Windows malware research and reverse engineering. [00:15.720 --> 00:21.800] So, what do we need to know about Wi-Fi cameras and baby monitors today? Basically, we're going [00:21.800 --> 00:25.660] to assume they're the exact same thing because they pretty much have the same feature set. [00:25.660 --> 00:31.940] They're literally marketed and sold as equivalent devices. So, what we're talking about is the [00:31.940 --> 00:39.920] $10 cameras you can find on Amazon that require internet connectivity to that specific vendor's [00:39.920 --> 00:45.480] cloud platform. And there's very basic operations, pan, tilt, zoom, things along those lines, [00:45.480 --> 00:50.320] motion detection, whatever. But yeah, that's what we're talking about when we say Wi-Fi cameras for [00:50.320 --> 00:58.200] today. So, why Wi-Fi cameras? Well, there's literally almost 125 million households across [00:58.200 --> 01:04.860] the world that have these cameras installed within their house. So, these things are everywhere. [01:05.160 --> 01:09.820] And they're obviously going anywhere and they're super cheap. So, you're going to find them [01:09.820 --> 01:14.620] everywhere. The attacks that are typically associated with these cameras, what you're [01:14.620 --> 01:21.600] probably going to hear about usually is people spying on babies and families, terrorizing them, [01:21.600 --> 01:27.080] that sort of thing. A bit upsetting there. And even things like Russians performing [01:28.440 --> 01:36.220] reconnaissance on targets within Ukraine. So, when we set out to evaluate the attack [01:36.220 --> 01:40.660] surface for Wi-Fi cameras, we wanted to break things down into a few different [01:40.660 --> 01:47.040] common attack vectors that broke down primarily into leak credentials and cloud vulnerabilities. [01:47.320 --> 01:53.720] Those seem to be the most common attack vectors, the most frequently seen ones [01:55.360 --> 02:01.580] in more of the attacks that we kind of see across the board. But yeah, so, kind of focusing on those [02:01.580 --> 02:08.920] two, that's certainly what we wanted to kind of dig into was any vulnerabilities specific to [02:08.920 --> 02:16.560] the cloud platforms, the applications that control the cameras, and the camera hardware itself. [02:19.500 --> 02:25.380] Hello, DEF CON. I'm Eric Forte and I'm doing the presentation with Mark. And I'm a security [02:25.380 --> 02:29.860] research engineer at Elastic. I'm on the Threat Research and Detection Engineering team, otherwise [02:29.860 --> 02:36.460] known as TRADE. And my background is in Linux software development, IoT systems, UAVs, civil [02:36.460 --> 02:42.180] space sector, and then also doing some threat research. And so when we're talking about these [02:42.180 --> 02:46.700] cameras, for the purposes of this talk, we looked at a number of different cameras, but we're [02:46.700 --> 02:53.780] going to primarily focus on the WandsView Q5 and the WandsView Q6. And as far as why we picked [02:53.780 --> 03:00.180] these cameras, it was sort of clear to see on the Amazon reviews that they might have something for [03:00.180 --> 03:04.720] us to look at, some vulnerabilities that other people had just come across because they were [03:05.360 --> 03:13.700] readily hacked enough that it took notice. So these cameras are made by WandsView, but there [03:13.700 --> 03:19.440] are other vendors that also produce cameras, such as Sonado and some others as well, which we'll [03:19.440 --> 03:25.420] touch on a little bit more in a little bit. But they're primarily under the AJ Cloud management [03:25.420 --> 03:32.260] infrastructure. And so this is going to be the cloud services that provide you with the apps, [03:32.260 --> 03:37.160] with the way of connecting to it. So the WandsView versus Sonado versus others may have [03:37.160 --> 03:41.780] their own little differences in the apps themselves. But primarily, this cloud interface [03:41.780 --> 03:48.320] is with AJ Cloud, and we'll get into a lot more of that in a minute. So when we were first with [03:48.320 --> 03:52.720] these cameras, we kind of looked at a few different approaches for how we were going to try and [03:52.720 --> 03:58.620] see if we could get some of those similar Amazon review results. So first, we were looking at [03:58.620 --> 04:03.280] remote access. So this is going to be accessing the camera through whatever companion app that [04:03.280 --> 04:08.900] ships with the camera. We also were going to look at some local attacks. So going to be some active [04:08.900 --> 04:13.960] and passive networking recon, in addition to seeing what else other services and things were [04:13.960 --> 04:20.100] running there. Also looking at some device physical manipulation, which obviously these [04:20.100 --> 04:26.080] are Wi-Fi cameras. They're not necessarily like closed circuit TV cameras. So we're expecting that [04:26.080 --> 04:30.280] there's going to be some physical attacks, which there are. We'll get to that. But [04:31.140 --> 04:38.220] this is still, again, as an attack vector, can enable some other aspects. Then finally, looking at [04:38.220 --> 04:43.500] the hardware itself. So looking at the chip and seeing what we can use, what we can either get [04:43.500 --> 04:48.040] the firmware off, what we can do to kind of, again, extend that vulnerability process, look for [04:48.040 --> 04:54.560] serial communications and things like that. Which, spoiler alert, we found some over UART. [04:54.560 --> 04:59.880] So for our lab setup, we have a number of different things that we wanted to look at, [04:59.880 --> 05:04.520] right? So we've got different apps. So we want to have a very controlled environment, [05:04.520 --> 05:09.140] because we know, say, one, they're easy to hack. So we don't want to be hacked ourselves. [05:09.140 --> 05:15.520] But on top of that, we know as these are largely, say, Chinese make cameras, that they may also want [05:15.520 --> 05:21.280] to be watching what we're doing. So we wanted to have a completely different setup. And so we have [05:21.580 --> 05:26.600] a mobile hotspot. I like the T-Mobile T9s. They're cheap. You can get them for about 20 bucks, and [05:26.600 --> 05:32.860] they do the job great. We have the camera, of course, itself. Then we needed, say, Windows and [05:32.860 --> 05:37.000] Linux operating systems. You don't actually need Linux, except I would argue that you do. But [05:37.620 --> 05:42.880] practically speaking, you don't need Linux to be able to run any of these things. But we used that. [05:42.880 --> 05:49.580] But we did need Windows to also look at the companion Windows app, in addition to the iOS [05:49.580 --> 05:56.440] and Android apps, which we had phones and virtual machines set up for as well. From a software side, [05:56.440 --> 06:01.800] we use a number of different tools, including, say, Wireshark, running Android Studio to try [06:01.800 --> 06:06.600] and see what we could find out from the app, various other sort of decompiling mechanisms, [06:06.600 --> 06:13.340] and also using the Elastic Stack to look at the network communication logs and how we can parse [06:13.340 --> 06:19.560] some of the different protocols that we saw. And we will, again, we'll talk to that more in a [06:19.560 --> 06:25.420] some peer-to-peer traffic there. From a hardware standpoint, since we wanted to do the full gamut [06:25.420 --> 06:31.400] of going from complete hardware takedown as well as looking at all the software, we had some hardware [06:31.400 --> 06:37.720] teardown tools. I like what iFixit has, but of course you can take your pick. Then we needed [06:37.720 --> 06:44.580] some USB TTY connector, right? So in this case, you know, it's just your typical Adafruit USB TTY [06:44.580 --> 06:51.700] serial connector there. We also have a, and we'll get to it more in a minute, but using the GreatFET [06:51.700 --> 06:58.080] 1 as a logic analyzer, and to be able to read voltages and things like that in case we needed [06:58.080 --> 07:03.060] to actually hard pull something off of the chip, solder something or things like that. Ultimately, [07:03.060 --> 07:09.240] we didn't need to do that, but we were prepared for that nonetheless. Raspberry Pi, because it's [07:09.240 --> 07:16.680] image and distribute, so for doing cross compilation and things like that, cheap, [07:16.680 --> 07:25.740] easy to come by. And then also, we used Alpha Wi-Fi, just a USB Wi-Fi NIC, which for us, [07:25.740 --> 07:31.440] why this was important and why you'll need some NIC that you can get active, or rather passive [07:31.440 --> 07:37.260] sniffing on, is because you're going to want to capture all of the traffic going from the camera [07:37.260 --> 07:42.740] to the cloud, and not just what will appear as network traffic, and we'll get to that in a little [07:42.740 --> 07:47.800] bit, because you're going to, to follow along, you'll need to parse some other additional [07:47.800 --> 07:53.600] protocols. So, getting a little bit into our remote and local recon, initial attacks were [07:53.600 --> 07:59.440] limited. They had a fairly locked down attack surface. The active network and local reconnaissance [07:59.440 --> 08:05.000] doesn't reveal too much or too much interesting as far as running on the traffic, or rather running [08:05.000 --> 08:11.980] on the camera. The network traffic itself is fairly mundane. It uses encrypted web sockets, [08:11.980 --> 08:15.920] which is a good sign, right, that they are at least using encryption, things like that. [08:16.560 --> 08:21.420] So, we tried to do some man-in-the-middle attacks, but ultimately, we weren't particularly [08:21.420 --> 08:26.920] successful with that. Looking at the apps themselves, they were likely obfuscated with [08:26.920 --> 08:33.600] ProGuard. We couldn't, just from the, from being, unpacking the APK, get too far there. [08:34.520 --> 08:40.340] But, so those APKs were just not easily that debuggable. But just as a quick note, [08:40.340 --> 08:44.620] ultimately, there's three lines of communication. We're going from the mobile app to the cloud, [08:44.620 --> 08:48.840] 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:04.800] It has an exposed reset button, so if you had this sitting, like, let's say, up here on stage, [09:04.800 --> 09:09.320] if you were to walk by, hit the reset button, and then flash a QR code, you could steal the camera, [09:09.320 --> 09:13.640] and then now it's yours. You have full control over it. Again, that's not particularly surprising, [09:13.640 --> 09:23.100] because that's part of the expected setup process. So, in that sense, there's no, [09:23.100 --> 09:29.500] so there's also an exposed SD card slot. So, as we came to discover later, this can be used to [09:29.500 --> 09:33.660] load alternative firmware as well. We'll get into what the bootloader looks like in a minute, too, [09:33.660 --> 09:38.960] but this, if you were to craft a malicious SD card, you could go plug it into the camera, [09:38.960 --> 09:44.340] and then also have a field day there, too. The hardware recon starts to get a little bit more [09:44.340 --> 09:52.180] interesting. So, when we look at the chip, it's an Experse T31 SoC. It's primarily a MIPS processor, [09:52.180 --> 09:57.200] but it also has a companion RISC-V processor. But the primary thing I want you to focus on, [09:57.200 --> 10:04.480] for the sake of the demonstration, is that we have an I2C and UART bus that we should, [10:04.480 --> 10:11.760] could be looking for, right, on the hardware, on the chip itself. We also have a secure boot, [10:11.760 --> 10:16.160] which may, you know, that could throw a wrench into things. And then we also have a hardware [10:16.160 --> 10:20.600] watchdog supported by this chip. Doesn't necessarily mean they're using it, but again, [10:20.600 --> 10:26.340] these are things that we can look for in our hardware recon. So, in tearing down hard the [10:26.340 --> 10:34.980] camera, we found a potential UART, UN access ports there. And so we connected a logic analyzer, [10:34.980 --> 10:42.320] the great FET1, looked at the voltages, used some of the protocol detection, saw that it appears to [10:42.320 --> 10:50.880] be UART. And if we look at the actual signal, we saw that it indeed was. So, we go ahead and [10:50.880 --> 10:55.980] use screen, but you can use, again, whatever your favorite tool is to connect over default [10:55.980 --> 11:04.320] baud rate to UART. And lo and behold, on boot, we have UBOOT. So that, of course, is useful for us. [11:04.320 --> 11:09.800] But also, we, in further expecting this, that secure boot is not enabled by default, as far [11:09.800 --> 11:16.100] on the camera, even though the chip supports it. So, we can just do a quick boot into single user [11:16.100 --> 11:20.500] mode and get a root shell so that we can start poking around further. Now, this camera was [11:20.500 --> 11:27.220] particularly easy to do this because you could just straight set the environment variables for [11:27.220 --> 11:31.420] UBOOT to be able to boot into single user mode and get root. Other cameras that we looked at [11:31.420 --> 11:35.540] were not as simple as this. And sometimes you have to use memory offsets and things like that, [11:35.540 --> 11:41.900] but this one in particular was fairly straightforward. So, again, we can hit boot [11:41.900 --> 11:46.980] and then just drop into our root shell and then be able to poke around on the camera. [11:47.060 --> 11:52.600] So, now that we're there, a few things that we want to then do to go forward. First off, [11:52.600 --> 11:57.480] we may want to try and establish persistence. But if you've done this type of attack before, [11:57.480 --> 12:02.500] going to single user mode, especially on embedded devices, and just embedded devices in general, [12:02.500 --> 12:07.940] you might see that you're on a read-only file system. Well, many times this is only read-only [12:07.940 --> 12:15.700] ish. It's not quite truly read-only. So, if we take a look at fstab, we can see that a number [12:15.700 --> 12:24.120] of these mount points are separated, but then also they are tempfs shares. So, we can then [12:24.980 --> 12:31.440] make our own tempfs partition or just mount a tempfs partition for read-write access, [12:31.440 --> 12:36.420] modify the desired settings, and we can run whatever we want, of course, and have persistence. [12:36.480 --> 12:42.140] Which, largely, for these type of devices, you will need this type of interface, whether it be [12:42.140 --> 12:48.060] for... there's other methods for logging, but again, when Linux is running, it often needs to [12:48.060 --> 12:52.500] be able to make some level modifications. So, this is just walking through one way of doing that, [12:52.500 --> 12:58.900] of saying, hey, I want to create a tempfs share for dev, and then go ahead and mount it, [12:58.900 --> 13:06.860] and then also then mount Etsy, such that I can make Etsy read-write as well, which, of course, [13:06.860 --> 13:13.560] gives us access to some other things. And so, just demonstrating there that if I run... that [13:13.560 --> 13:19.480] 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:23.200] So, if you want... so, that's just one way, of course, then you can go and do whatever you want [13:23.200 --> 13:28.640] from that perspective. But if you want to go log into the existing root user, of course, you can [13:28.640 --> 13:35.340] pull Etsy password, and then go and just use John the Ripper or something to crack that hash, [13:35.340 --> 13:40.800] and go from there. But for our purposes, again, we want to keep looking for the other software [13:40.800 --> 13:46.220] vulnerabilities. So, this gives us an easy way to pull the firmware over the serial connection. [13:46.420 --> 13:51.000] So, we... and in addition to the firmware, we're pulling a JFS to read-write partition containing [13:51.000 --> 13:57.100] any log data, again, just might be useful for us. So, this is just demonstrating how you can... one [13:57.100 --> 14:01.480] way of pulling the firmware. There are a number of different ways, but this is just how we did it [14:03.480 --> 14:08.220] using... using binwalk, and then, of course, just echoing the bytes out in the appropriate format [14:08.220 --> 14:13.420] over the serial connection. So, with that, I'm going to hand it over to Mark to see what he did [14:13.420 --> 14:21.500] with the firmware. All right. So, as Eric mentioned earlier, we definitely were running into issues [14:22.060 --> 14:28.080] with the iOS and Android apps for WandsView specifically, right? So, we're hitting our [14:28.080 --> 14:33.000] heads against the wall a little bit. So, we kind of backed things up a little bit and went directly [14:33.000 --> 14:39.660] to WandsView's site, and they host a version of WandsView Cloud that is for older versions of [14:39.660 --> 14:45.520] Windows. I think it says Windows 7 specifically on their site. But the main takeaways from that [14:45.520 --> 14:51.300] is that that app is still compatible with all WandsView devices. It does have a limited feature [14:51.300 --> 14:56.680] set. I mean, they're still trying to push you towards using the apps. You know, that's totally, [14:56.680 --> 15:02.000] you know, their sort of thing because they want everybody to sign up for their cloud plan so they [15:02.000 --> 15:08.460] can make more money off of everybody, not just the $10 sales, you know, from the device itself, [15:08.460 --> 15:15.000] right? A couple other things related to that, this Windows app, is it does generate a significantly [15:15.000 --> 15:20.680] less amount of network traffic. That's going to come in handy later. And the binaries are not [15:20.680 --> 15:28.580] packed. Eric mentioned that the APKs look like they're probably packed with ProGuard. So, you [15:28.580 --> 15:34.740] know, definitely being able to disassemble and decompile and debug pretty easily. That helps [15:34.740 --> 15:41.640] out quite a bit. And then last, but certainly not least, is that it does generate a very, very [15:41.640 --> 15:48.100] verbose debug log file, which I'm going to dig into right now. And the first thing we noticed [15:48.100 --> 15:54.540] when we ran it the first time, it logs user account credentials in clear text. That's obviously [15:54.540 --> 16:02.880] terrible. So, yeah, not a great sign of things. And as Eric mentioned before, we had significant [16:02.880 --> 16:08.000] difficulties trying to man the middle of any of the app traffic before, so we had no visibility [16:08.000 --> 16:17.320] into that. But helpfully, their developers decided to actually log all post request and response data [16:17.320 --> 16:21.480] so it's all there in the clear. Who needs to man the middle of anything when you have it in the [16:21.480 --> 16:29.700] clear on a file on disk? So, yeah. So, digging into it, yeah, we could definitely get a ton of [16:29.700 --> 16:37.180] insight into the sign-on process that we did not have before, including the actual endpoint APIs, [16:37.180 --> 16:47.300] as well as, you know, all the fields that are involved both in the requests and responses. So, [16:47.300 --> 16:55.260] it's not really a ton there. It's more just initial setup. This check is more just to see [16:55.260 --> 17:01.860] if this is a valid account that you're attempting to sign on. And then this here is where the actual, [17:01.860 --> 17:07.300] let's see, yeah, is an initial account where, but, yeah, challenge involved where [17:08.020 --> 17:13.820] the token's generated for that specific client application, and then there's a little bit of [17:13.820 --> 17:19.400] key exchange that happens. But, yeah, not too much else going on there. This is where the sign-on [17:19.400 --> 17:24.360] really begins. Assaulted and, yeah, your password is at least assaulted and hashed, so it's not [17:24.360 --> 17:31.880] set in the clear, thank God. And then, yeah, I mean, it's mostly just to initialize the session [17:31.880 --> 17:38.720] and to confirm that you are allowed to log into this account. From there, we, things really start [17:38.720 --> 17:45.160] to get interesting because now we can, now that we're logged in, we can request a list of devices [17:45.160 --> 17:50.360] that are associated with that specific account. And as you can see here, there's a specific device [17:50.360 --> 17:56.480] ID, along with some more configuration information, primarily endpoint URIs. [17:58.080 --> 18:07.340] And then there's another device configuration API endpoint that's hit. This is very notable, [18:07.340 --> 18:12.340] we're going to refer back to this later, but this is where a device ID is first transmitted [18:12.340 --> 18:21.780] from the application to the cloud. And, you know, more configuration information comes through. [18:21.980 --> 18:29.120] We'll dig into that a bit. And then the last request we really dig into is fetch infos. And [18:29.120 --> 18:39.700] this provides a much, much larger picture of the data that is stored for that specific device. [18:39.700 --> 18:46.200] And there's a lot to kind of dig into, but what you'll want to really highlight on is there's a [18:46.200 --> 18:51.980] snapshot URL that's provided. And that just happens to be publicly accessible. And that's [18:52.040 --> 19:01.680] a picture of my kitchen. So from back in April. So digging further into more of the response data, [19:01.680 --> 19:08.560] there's a few things certainly to note here that are a bit concerning, right? The firmware version, [19:08.560 --> 19:15.360] the very specific firmware version that is running on the device itself, that's referenced there, [19:15.360 --> 19:21.180] along with the next firmware version they're supposed to upgrade to, along with the actual SSID [19:21.700 --> 19:27.520] that the device is currently signed onto, along with some other network configuration information [19:27.520 --> 19:34.560] including its MAC address. And then we also have, you know, geolocation data, you know, in the form [19:34.560 --> 19:43.360] of, you know, time zone data and things like that. So going back to the device configuration request, [19:44.060 --> 19:49.640] what we tried to do first is we wanted to see if we could actually access other devices that [19:49.640 --> 19:56.220] weren't associated with our particular account. So we tried a very naive approach where all we [19:56.220 --> 20:03.440] wanted to do was simply just replace the device ID in that particular request. And without really [20:03.440 --> 20:08.060] doing a significant amount of reverse engineering, we can locate that pretty easily based off of the [20:08.060 --> 20:13.940] verbose log data because if we just look up post request, we can, you know, we can see how many [20:13.940 --> 20:20.360] times that's specifically logged to the log file. And then we can cross-reference that with [20:21.480 --> 20:28.500] the disassembly in IDA in order to target the specific device configuration post request [20:29.190 --> 20:35.860] to get a better idea of where we would want to jump in. And so digging further into the particular [20:35.860 --> 20:42.720] function, what we decided to do is we needed to set a breakpoint at this particular address, which [20:42.720 --> 20:50.680] would be before the post request actually goes out, before the JSON is fully formed as well. [20:51.040 --> 20:55.060] You know, we're going to swap out the device IDs and memory and then resume execution. So pretty [20:55.060 --> 21:01.940] straightforward. What this ends up kind of looking like is, you know, I wrote up maybe a 60-line [21:02.480 --> 21:07.560] 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:37.540] So we already have one specific camera that is tied to this account. And it's offline at the [21:37.540 --> 21:42.980] moment, so it's not really concerning that, right? We'll attempt to connect to it, but nothing's going to happen. [21:52.710 --> 21:56.670] Now, if we kick off the exploit script, what it's going to do is it's going to launch [21:57.190 --> 22:04.610] the same WandsView cloud for Windows app. We'll proceed to sign in as expected. [22:07.030 --> 22:15.710] And once we hit our breakpoint, we will swap out the device ID in memory. And then once it [22:15.710 --> 22:34.720] has finished here, it will resume execution. And we're online. So the thing is... [22:39.660 --> 22:44.340] So yeah, we can do everything in the app. We can pan and tilt. [22:46.080 --> 22:50.620] Yeah, I mean, like I said, it is a bit more limited feature set compared to [22:50.620 --> 22:59.340] the mobile apps. But basically, right, we've proven we can get access to an account or a device that's [22:59.340 --> 23:06.820] not associated with our account. 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:22.960] So you might have seen in the background that there was, you know, certainly a lot of [23:22.960 --> 23:28.700] network traffic being generated in the background. It was all primarily UDP, [23:29.200 --> 23:35.440] but we hadn't really no idea what it is in particular. Now, doing research before [23:35.440 --> 23:43.480] we submitted to DEF CON, we did come across a particular IoT peer-to-peer protocol called PPPP [23:44.300 --> 23:52.380] that was pretty significantly researched and detailed by Polymer PC. His website, [23:52.380 --> 23:59.280] he presented at DEF CON 28 in 2020, fully tearing down the protocol and all that. So [23:59.840 --> 24:05.260] 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.840] So we kind of set out to explore that by just looking for references to P2P and PPPPP. And yeah, [24:12.840 --> 24:20.280] sure enough, within the Wandscape Cloud binary itself, as well as the DLLs, we found, you know, [24:20.280 --> 24:27.120] numerous references, even references to their specific PDBs, which reference both, you know, [24:27.120 --> 24:32.960] multiple peer-to-peer terms. So yeah, we're pretty sure that we're dealing with the same [24:32.960 --> 24:40.080] protocol. And going from there then, there is a excellent dissector for this peer-to-peer [24:40.080 --> 24:46.340] protocol that is available and posted on GitHub as of last year. You know, we load it in and all [24:46.340 --> 24:52.420] of a sudden that UDP traffic, we have no idea what it is, turns into a very recognizable messaging [24:52.420 --> 24:58.960] sequence that's associated with peer-to-peer. So very, very briefly, the peer-to-peer protocol [24:58.960 --> 25:06.420] is used by a ton of IoT devices across hundreds of vendors. It's been in use for, you know, [25:06.420 --> 25:11.140] the better part of the last decade, if not longer. It uses UDP hole punching in order [25:11.140 --> 25:18.200] to circumvent restrictive network configurations. And it allows you, you know, these apps to connect [25:18.200 --> 25:22.600] to the cameras from anywhere in the world, right? They want it to be as accessible as possible, [25:22.600 --> 25:26.780] right? That's the whole point of these devices. And yeah, sometimes the connections are either [25:27.460 --> 25:31.000] direct to the camera, depending on the configuration, or they go through a relay [25:31.000 --> 25:36.320] if they have to, you know, get around certain restrictions. [25:41.320 --> 25:48.100] So now we have established some initial access, right? So we also have, as we looked at a little [25:48.100 --> 25:53.760] bit before, the firmware, which we can now go into some of that static reverse engineering. [25:53.760 --> 26:00.200] We have packet capture for the camera and the app network communications. We have log files [26:00.200 --> 26:06.440] from both the windows and the camera logs. The logs, as when we logged in before under root, [26:06.440 --> 26:11.220] we of course have access to all of the D message logs and things like that as well. [26:11.300 --> 26:18.160] And then we can get the camera logs from any of its hardware mechanisms as well for the audio [26:18.160 --> 26:22.800] and camera, pan, tilt, zoom, et cetera. So now we want to kind of establish some more [26:22.800 --> 26:28.760] advanced access for looking for some additional exploits. So one, or first, we're going to look [26:28.760 --> 26:33.620] for that live log output for some immediate feedback to determine some of the control flow. [26:33.620 --> 26:39.240] Again, from the windows app, right, we were able to see that some of the, they are logging the [26:39.240 --> 26:43.600] post request and responses. So we're hopeful that they're going to do something similar on the [26:43.600 --> 26:48.720] camera, but we also want to establish a, we want to have a debugger running on that camera so we [26:48.720 --> 26:54.920] can look at some of these applications and see what we can do. So first for live log output, [26:54.920 --> 27:00.740] it's very, very simple, very easy. You plug the serial, you just get your serial shell over, [27:00.740 --> 27:04.620] you aren't plugged into say in this case, a Raspberry Pi, but again, you could use whatever [27:04.620 --> 27:09.180] you like and it spits out the logs over serial by default. So you don't even necessarily need [27:09.180 --> 27:14.100] to use the root access or boot the single user mode to just get the logs. But again, [27:14.100 --> 27:20.000] that's just one way of doing it. But one thing that we'll quickly run into is the kernel watch [27:20.000 --> 27:25.800] dog. So if the watch dog is not written to, it reboots the camera. So this, what we're seeing [27:25.800 --> 27:33.480] here is if you try to kill the init, the primary app, or in this case, we'll get to it in a minute, [27:33.480 --> 27:38.800] but if you start to kill off things in the camera to go look at them or pause things, [27:38.800 --> 27:44.100] it will trigger the, the, the kernel watchdog process, which will then reboot the camera. [27:44.380 --> 27:48.940] This isn't the only say security mechanism. This is just the one that the primary one that you [27:48.940 --> 27:53.320] would have to get around to be able to run a debugger, to be able to look at the primary [27:53.320 --> 27:59.320] application that they're running on the camera, which they call init app, which, which handles [27:59.320 --> 28:05.100] all of the connection to the AJ cloud, providing all of the video streaming and the rest of the [28:05.100 --> 28:12.460] control of the camera. They wrap this init app in a daemon.sh script, which is just a simple while [28:12.460 --> 28:17.540] loop that says, Hey, keep kicking off the init app. If I have to kick it off more than X number of [28:17.540 --> 28:22.140] times, reboot it again, acting sort of like a, again, a catch all in case something went really [28:22.140 --> 28:28.640] wrong, but that init app is reporting into the watchdog. And so this is, that's, so if you either [28:28.640 --> 28:33.200] kill the init app or again, kill the daemon and then kill the init app, that's where you're going [28:33.200 --> 28:37.400] to end up rebooting the device. And so if you're using single user mode to get root, you're going [28:37.400 --> 28:42.880] to lose that. And I, and some of the, unless you have set up some level of persistence, you're [28:42.880 --> 28:48.840] going to lose any of the edits as well. So of course, next step is to defeat the watchdog. So [28:48.840 --> 28:53.060] there are a couple of approaches here, right? That you could do. So the first one, um, which you can [28:53.060 --> 28:59.020] actually get this example right off from the, uh, the kernel watchdog API, um, information from the, [28:59.020 --> 29:04.080] the Linux kernel, you could just simply write some C code to keep sending a live messages to the [29:04.080 --> 29:09.500] watchdog, right? And so since we have root access, we could do something like that. However, this [29:09.500 --> 29:13.860] approach is not necessarily what we want to do and not what we wanted to do either, because the [29:13.860 --> 29:20.840] problem, the fundamental problem with this is that while you could keep sending the messages, or you [29:20.840 --> 29:25.580] could even use like take hold of the kernel semaphores and keep it open just for yourself. [29:25.580 --> 29:32.460] So init app can't write to it. That doesn't necessarily help you because init app, if it [29:32.460 --> 29:37.880] can't write to it, then it's going to know that you're here and know that you're now disabling [29:37.880 --> 29:43.140] its ability to operate. And then it may change the way that it's going to operate. In this case, [29:43.140 --> 29:47.660] we know say that it, that it does, but again, that's not necessarily the approach you want to [29:47.660 --> 29:51.940] use, even though it might work for, for your environment. So there's another way. Um, there's, [29:51.940 --> 29:54.480] there's other ways other than these two, but these are just the ones we're going to talk through [29:54.480 --> 30:01.000] today. Um, there's the magic close feature, which if you go look in the Linux kernel driver, uh, [30:01.000 --> 30:07.320] what the watchdog driver API from Linux kernel 2.4.18, you can see that there, if you write a [30:07.320 --> 30:11.140] magic character, in this case, an uppercase V, there's another character that'll work as well. [30:11.140 --> 30:16.760] But if you write that to dev watchdog, and that's the last thing that gets written to [30:16.760 --> 30:22.120] dev watchdog, it then can cleanly disable the watchdog, uh, the, the kernel watchdog. [30:22.120 --> 30:28.720] Now, as a note, the camera is not running Linux kernel 2.4.18, but it does still work. Um, so [30:28.720 --> 30:33.940] your mileage may vary. It's running a three dot kernel, but, um, again, it's still, still may [30:33.940 --> 30:38.740] work. So you could write a simple script such as this, or again, however you would like to do it [30:38.740 --> 30:43.260] to just simply continuously write V. And the reason why you may want to do something like [30:43.260 --> 30:48.740] this instead of just write V and stop is something, some other process, especially as you're doing [30:48.740 --> 30:53.120] your reverse engineering might come along and reactivate the watchdog. So if you want to try [30:53.120 --> 30:58.840] and keep making it such that, that you're not going to be rebooted, or at least as have some [30:58.840 --> 31:03.720] protection against that, you, you might want to continuously write to it. So now with the [31:03.720 --> 31:08.680] watchdog generally defeated, we need to be able to run a debugger on the camera, which means we [31:08.680 --> 31:13.880] need to be able to compile binaries that can run on the camera. Um, so in this case, we discovered [31:13.880 --> 31:22.080] that our, our camera is a little Indian MIPS. Um, so just as a quick, um, example, we can compile [31:22.080 --> 31:29.860] arbitrary C code using just out of the box, um, like the MIPS Linux GCC compilers. We can run a [31:29.860 --> 31:36.420] quick hello MIPS and see. So I did not know this at the time when I was doing it. I built a tool [31:36.420 --> 31:43.000] chain and compiled, uh, compiled GDB server myself using that tool chain. But later on, we found that [31:43.000 --> 31:46.920] there is a prebuilt one that works that that's the link to be able to get to it again, again, [31:46.920 --> 31:51.440] that will be available, but what you'll need to do to be able to run GDB server, you'll need to [31:51.440 --> 31:56.040] make sure that you're exporting the proper paths to get the proper libraries that an app needs, [31:56.040 --> 32:00.680] then expose it over some port. It could be, it works over serial. I would recommend if you can [32:00.680 --> 32:04.660] use it, doing it over networking, just because the serial debugging can be very slow when you're [32:04.660 --> 32:11.840] using this many libraries. Um, and again, just an example of how to do that. Um, so we can then [32:11.840 --> 32:18.020] connect to our, um, use, and this is actually one important note. When you're using GDB to connect [32:18.020 --> 32:24.620] to GDB server, you will likely, you very likely need to use the multi-architecture version. [32:24.620 --> 32:29.600] Otherwise it will not work unless you happen to be running, um, little Indian MIPS on your [32:29.600 --> 32:36.900] laptop, which at least for me, I'm not. Um, but once you get there, again, we know that an in-app [32:36.900 --> 32:42.660] is calling out to the watchdog. So we need to overwrite those functions in memory with no ops [32:42.660 --> 32:49.480] to be able to have it not call to the watchdog at all. Is this absolutely necessary? Maybe not, [32:49.480 --> 32:52.780] but it will make it a lot cleaner for us if we just don't have to worry about it. So that's, [32:52.780 --> 32:56.540] that's what we did. And you can, at least in our case, we were able to find that, that, [32:56.540 --> 33:03.560] that those locations were where those functions were and, uh, we just overwrote them. Sure. So [33:03.560 --> 33:08.400] I'll hand it over to Mark. All right. Uh, so yeah, we're going to skip over the, the, this [33:08.400 --> 33:13.040] second demo, uh, and just kind of jump right into it. So, uh, with the peer-to-peer discovery, [33:13.040 --> 33:17.920] what we wanted to do is build a client so we could actually connect directly to our camera, [33:17.920 --> 33:23.080] uh, and, uh, issue commands to it in order to, uh, attack and exploit it, right? Uh, so the [33:23.080 --> 33:28.980] peer-to-peer, uh, servers, you can discover them, uh, using Nmap or Masscan, uh, and delivering [33:28.980 --> 33:37.080] that 4-byte payload, uh, to UDP port 607222. Um, and yeah, so very briefly how to establish a [33:37.080 --> 33:42.860] peer-to-peer connection, uh, you need to send it a hello message from the client, uh, it'll, [33:42.860 --> 33:49.000] it'll act back, uh, you need to query for a specific device ID if this peer-to-peer server [33:49.000 --> 33:54.580] has any idea of it, uh, those are device IDs are also serial numbers that are found on the bottom [33:54.580 --> 34:00.080] or on the back of these devices, um, and hopefully the peer-to-peer server will say that it knows [34:00.080 --> 34:05.380] how to access the device, uh, and then instruct you, uh, to punch a hole to a specific IP and [34:05.380 --> 34:12.840] port, um, and then once we have the idea of where we're supposed to go to, uh, we can query that [34:12.840 --> 34:19.760] specific relay server or the device itself, uh, you know, if we can connect to it, um, it should [34:19.760 --> 34:24.040] hopefully say yes, uh, and then it'll send its packets back and then, yeah, your peer-to-peer [34:24.040 --> 34:28.200] connection is ready. Uh, so yeah, there, there's a good exploit script that we kind of based some [34:28.200 --> 34:32.820] of our work on, uh, definitely check that out when you get a chance. Um, but yeah, basically, uh, [34:32.820 --> 34:37.860] in order to prove things out, uh, we, we looked at how the camera panned initially over Wireshark, [34:37.860 --> 34:43.860] uh, it was very easy to tell which specific, uh, packet belonged to a pan operation, uh, then we [34:43.860 --> 34:50.100] trace that back to, uh, debug, debug log messages from the firmware, uh, and then actually dug into [34:50.100 --> 34:56.620] the firmware itself specifically to find where, uh, where that log, uh, message is being generated [34:56.620 --> 35:03.300] and what function is primarily handling, um, a lot of the comms and all that. So, uh, very brief, [35:03.300 --> 35:11.980] uh, demo and we're gonna just kind of jump ahead to our more compelling demo of essentially what [35:11.980 --> 35:20.020] you can do, um, with our discovery of, of how to build a peer-to-peer client. So, um, what we can [35:20.020 --> 35:27.760] 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:34.960] And what we find out is that that's, that is the only way that the device knows what its own device [35:34.960 --> 35:42.180] ID is. And so there is actually a command through peer-to-peer that allows us to overwrite the [35:42.180 --> 35:48.920] contents of that INI file. So what we're trying to do is overwrite, uh, the, the serial number [35:48.920 --> 35:55.140] itself to an arbitrary value that's just going to completely brick this machine and make it [35:55.140 --> 35:59.560] completely inaccessible to the internet. And essentially the user's gonna have to throw it [35:59.560 --> 36:06.840] away because there's no way to restore that unless you have access like we do. Uh, and so we send our [36:06.840 --> 36:13.180] 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:19.180] And we actually have another command we're going to send to it that's going to crash and reboot [36:19.180 --> 36:25.680] the cam. Uh, and from there, uh, what we can see is, you know, things are kind of already going [36:25.680 --> 36:31.820] haywire a little bit. Uh, the camera is attempting to reboot right now, but what we'll find out [36:31.820 --> 36:38.660] pretty shortly here is that it has, uh, it will attempt to issue requests to AJ Cloud's [36:38.660 --> 36:43.560] infrastructure, but ultimately it's going to be unsuccessful because it's sending along [36:44.640 --> 36:48.120] absolute garbage, uh, in its curl requests. [36:50.660 --> 36:56.720] And if we kind of like skip ahead a little bit here, this is a press for time. Um, what we can [36:56.720 --> 37:09.350] see here, yeah, if you, if you kind of highlight that, there's not much there. Ah, yes. So yeah, [37:09.350 --> 37:24.480] that doesn't really look like a good curl request. Okay. So very, very briefly, um, [37:24.480 --> 37:30.320] what devices are actually affected by this, right? Uh, so Wansview, every single device [37:30.320 --> 37:35.260] associated with Wansview is affected, including pet feeders, light bulbs, indoor and outdoor [37:35.260 --> 37:40.700] cameras. Uh, Galu as well, since they're, uh, you know, an affiliate company of Wansview, [37:40.700 --> 37:46.980] uh, and Sonato as well. Um, and then also Philemi is another, uh, manufacturer that, [37:46.980 --> 37:53.240] that we, uh, were able to experiment with. Um, but ultimately the affected vendors, [37:53.240 --> 37:59.020] uh, it all stems from AJ Cloud. It's whoever's running their device firmware on their cloud [37:59.020 --> 38:05.000] platform. And this ultimately affects seven different vendors, possibly even more. We [38:05.000 --> 38:11.140] weren't able to confirm all of these. So just real quick, what are some things that the vendors [38:11.140 --> 38:15.340] did right? They have certificate web-based authentication. It was fairly difficult to do [38:15.340 --> 38:19.720] some man-in-the-middle attacks from that. They have signed and obfuscated APKs, another good [38:19.720 --> 38:24.380] thing. They have a pared-down local operating system that at least attempts to be read-only. [38:24.380 --> 38:29.260] They could have had secure boot, but again, they have a read-only-ish file system. So you [38:29.260 --> 38:34.520] have to do some work even with physical access to be able to go and attack the machine. What [38:34.520 --> 38:38.880] they did wrong, of course, unauthenticated cloud access. The demos that we showed you, again, [38:38.880 --> 38:44.440] did not require any authentication. We have significant verbose debugging in the log app, [38:44.440 --> 38:49.860] the vulnerable peer-to-peer access, and again, no secure boot despite the SoC supporting it. And [38:49.860 --> 38:55.260] it's very easy to manipulate when you have physical access. So mitigations, of course, [38:55.260 --> 38:59.060] if you want to use them, segment them off your network. The critical vulnerabilities in the [38:59.060 --> 39:03.720] cloud infrastructure will put your data at risk. So we would just recommend not using them at all. [39:03.720 --> 39:10.620] Again, restrict the inbound, outbound comms. You basically just want to block all of the [39:10.620 --> 39:15.360] different traffic that you have. You could also flash it with a different operating system. [39:15.360 --> 39:20.700] For sake of time, I'm going to kind of run through this really fast. OpenIPC, I would recommend you [39:20.700 --> 39:26.100] checking it out. At least the Q5 is directly supported. So you could flash it with that, [39:26.100 --> 39:32.400] but it supports a lot of different SoCs. So our tools that we used for this demo, [39:32.400 --> 39:38.960] we'll be releasing them shortly on GitHub. And feel free to follow along with the demo. [39:39.240 --> 39:43.800] There's some other future research opportunities. Again, apologies for having to run through this [39:43.800 --> 39:49.240] real quick. But thank you so much for coming to our talk. Special thanks to, of course, [39:49.240 --> 39:54.980] 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.