1 00:00:00,000 --> 00:00:01,440 Good morning, DEF CON. 2 00:00:01,900 --> 00:00:05,620 We are going to be hacking some baby monitors and Wi-Fi cameras today. 3 00:00:06,680 --> 00:00:07,900 So, a little bit about me. 4 00:00:07,900 --> 00:00:08,740 My name is Mark Mager. 5 00:00:08,740 --> 00:00:11,140 I'm senior manager of security research at Elastic. 6 00:00:11,160 --> 00:00:14,560 My background is primarily in Windows malware research and reverse engineering. 7 00:00:15,720 --> 00:00:19,980 So, what do we need to know about Wi-Fi cameras and baby monitors today? 8 00:00:20,300 --> 00:00:25,660 Basically, we're going to assume they're the exact same thing because they pretty much have the same feature set. 9 00:00:25,660 --> 00:00:29,940 They're literally marketed and sold as equivalent devices. 10 00:00:29,940 --> 00: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. 11 00:00:41,020 --> 00:00:47,240 And there's very basic operations, pan, tilt, zoom, things along those lines, motion detection, whatever. 12 00:00:47,240 --> 00:00:50,980 But yeah, that's what we're talking about when we say Wi-Fi cameras for today. 13 00:00:50,980 --> 00:00:52,740 So, why Wi-Fi cameras? 14 00:00:52,740 --> 00:01:01,760 Well, there's literally almost 125 million households across the world that have these cameras installed within their house. 15 00:01:01,760 --> 00:01:04,860 So, these things are everywhere. 16 00:01:05,160 --> 00:01:08,760 And they're obviously going anywhere and they're super cheap. 17 00:01:08,760 --> 00:01:10,720 So, you're going to find them everywhere. 18 00:01:10,980 --> 00: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. 19 00:01:22,420 --> 00:01:23,740 A bit upsetting there. 20 00:01:23,740 --> 00:01:31,740 And even things like Russians performing reconnaissance on targets within Ukraine. 21 00:01:32,620 --> 00: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. 22 00:01:47,320 --> 00: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. 23 00:02:00,060 --> 00: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. 24 00:02:19,500 --> 00:02:20,960 Hello, DEF CON. 25 00:02:20,960 --> 00:02:24,460 I'm Eric Forte and I'm doing the presentation with Mark. 26 00:02:24,460 --> 00:02:27,260 And I'm a security research engineer at Elastic. 27 00:02:27,260 --> 00:02:31,160 I'm on the Threat Research and Detection Engineering team, otherwise known as TRADE. 28 00:02:31,160 --> 00:02:39,500 And my background is in Linux software development, IoT systems, UAVs, civil space sector, and then also doing some threat research. 29 00:02:39,820 --> 00: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. 30 00:02:51,760 --> 00: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. 31 00:03:10,300 --> 00: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. 32 00:03:21,920 --> 00:03:26,280 But they're primarily under the AJ Cloud management infrastructure. 33 00:03:26,280 --> 00: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. 34 00:03:34,280 --> 00:03:39,740 So the WandsView versus Sonado versus others may have their own little differences in the apps themselves. 35 00:03:39,740 --> 00: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. 36 00:03:46,120 --> 00: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. 37 00:03:57,080 --> 00:03:59,300 So first, we were looking at remote access. 38 00:03:59,300 --> 00:04:05,120 So this is going to be accessing the camera through whatever companion app that ships with the camera. 39 00:04:05,120 --> 00:04:07,820 We also were going to look at some local attacks. 40 00:04:07,820 --> 00: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. 41 00:04:15,060 --> 00:04:21,680 Also looking at some device physical manipulation, which obviously these are Wi-Fi cameras. 42 00:04:21,680 --> 00:04:24,480 They're not necessarily like closed circuit TV cameras. 43 00:04:24,480 --> 00:04:29,020 So we're expecting that there's going to be some physical attacks, which there are. 44 00:04:29,020 --> 00:04:30,040 We'll get to that. 45 00:04:30,280 --> 00:04:35,600 But this is still, again, as an attack vector, can enable some other aspects. 46 00:04:36,100 --> 00:04:39,280 Then finally, looking at the hardware itself. 47 00:04:39,280 --> 00: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. 48 00:04:50,280 --> 00:04:54,560 Which, spoiler alert, we found some over UART. 49 00:04:54,560 --> 00:05:00,060 So for our lab setup, we have a number of different things that we wanted to look at, right? 50 00:05:00,060 --> 00:05:01,660 So we've got different apps. 51 00:05:01,740 --> 00:05:07,480 So we want to have a very controlled environment, because we know, say, one, they're easy to hack. 52 00:05:07,480 --> 00:05:09,140 So we don't want to be hacked ourselves. 53 00:05:09,140 --> 00: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. 54 00:05:17,180 --> 00:05:20,220 So we wanted to have a completely different setup. 55 00:05:20,220 --> 00:05:22,920 And so we have a mobile hotspot. 56 00:05:23,080 --> 00:05:24,840 I like the T-Mobile T9s. 57 00:05:24,840 --> 00:05:25,320 They're cheap. 58 00:05:25,320 --> 00:05:28,280 You can get them for about 20 bucks, and they do the job great. 59 00:05:28,320 --> 00:05:30,060 We have the camera, of course, itself. 60 00:05:30,060 --> 00:05:33,900 Then we needed, say, Windows and Linux operating systems. 61 00:05:33,900 --> 00:05:37,000 You don't actually need Linux, except I would argue that you do. 62 00:05:37,000 --> 00:05:41,300 But practically speaking, you don't need Linux to be able to run any of these things. 63 00:05:41,340 --> 00:05:42,880 But we used that. 64 00:05:42,880 --> 00: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. 65 00:05:54,780 --> 00: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. 66 00:06:15,480 --> 00:06:21,560 And we will, again, we'll talk to that more in a some peer-to-peer traffic there. 67 00:06:21,740 --> 00: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. 68 00:06:32,560 --> 00:06:36,680 I like what iFixit has, but of course you can take your pick. 69 00:06:36,680 --> 00:06:40,760 Then we needed some USB TTY connector, right? 70 00:06:40,760 --> 00:06:46,100 So in this case, you know, it's just your typical Adafruit USB TTY serial connector there. 71 00:06:46,660 --> 00: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. 72 00:07:02,600 --> 00:07:06,820 Ultimately, we didn't need to do that, but we were prepared for that nonetheless. 73 00:07:07,860 --> 00: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. 74 00:07:17,820 --> 00: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, 75 00:07:38,760 --> 00: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. 76 00:07:48,920 --> 00:07:54,020 So, getting a little bit into our remote and local recon, initial attacks were limited. 77 00:07:54,020 --> 00:07:57,280 They had a fairly locked down attack surface. 78 00:07:57,340 --> 00: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. 79 00:08:06,140 --> 00:08:10,620 The network traffic itself is fairly mundane. 80 00:08:10,620 --> 00:08:15,920 It uses encrypted web sockets, which is a good sign, right, that they are at least using encryption, things like that. 81 00:08:16,560 --> 00:08:23,100 So, we tried to do some man-in-the-middle attacks, but ultimately, we weren't particularly successful with that. 82 00:08:23,160 --> 00:08:27,840 Looking at the apps themselves, they were likely obfuscated with ProGuard. 83 00:08:27,920 --> 00:08:33,600 We couldn't, just from the, from being, unpacking the APK, get too far there. 84 00:08:34,520 --> 00:08:38,880 But, so those APKs were just not easily that debuggable. 85 00:08:38,880 --> 00:08:42,680 But just as a quick note, ultimately, there's three lines of communication. 86 00:08:42,680 --> 00: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. 87 00:08:48,840 --> 00:08:53,120 And that, just as a sort of primer, we'll get into that more in a little bit. 88 00:08:53,920 --> 00:08:59,720 Just as far as the physical device itself, again, we weren't really expecting it to be that secure. 89 00:08:59,720 --> 00: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. 90 00:09:10,360 --> 00:09:11,600 You have full control over it. 91 00:09:11,600 --> 00:09:15,940 Again, that's not particularly surprising, because that's part of the expected setup process. 92 00:09:16,840 --> 00:09:26,960 So, in that sense, there's no, so there's also an exposed SD card slot. 93 00:09:26,960 --> 00:09:31,140 So, as we came to discover later, this can be used to load alternative firmware as well. 94 00:09:31,140 --> 00: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. 95 00:09:41,840 --> 00:09:45,000 The hardware recon starts to get a little bit more interesting. 96 00:09:45,040 --> 00:09:50,260 So, when we look at the chip, it's an Experse T31 SoC. 97 00:09:50,320 --> 00:09:54,720 It's primarily a MIPS processor, but it also has a companion RISC-V processor. 98 00:09:54,740 --> 00: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. 99 00:10:07,240 --> 00:10:14,500 We also have a secure boot, which may, you know, that could throw a wrench into things. 100 00:10:14,500 --> 00:10:18,320 And then we also have a hardware watchdog supported by this chip. 101 00:10:18,320 --> 00: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. 102 00:10:24,520 --> 00:10:31,980 So, in tearing down hard the camera, we found a potential UART, UN access ports there. 103 00:10:31,980 --> 00: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. 104 00:10:43,240 --> 00:10:48,820 And if we look at the actual signal, we saw that it indeed was. 105 00:10:48,940 --> 00: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. 106 00:10:57,420 --> 00:11:01,000 And lo and behold, on boot, we have UBOOT. 107 00:11:01,140 --> 00:11:03,720 So that, of course, is useful for us. 108 00:11:03,740 --> 00: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. 109 00:11:12,600 --> 00: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. 110 00:11:19,480 --> 00: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. 111 00:11:30,320 --> 00:11:32,560 Other cameras that we looked at were not as simple as this. 112 00:11:32,560 --> 00:11:39,040 And sometimes you have to use memory offsets and things like that, but this one in particular was fairly straightforward. 113 00:11:39,840 --> 00: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. 114 00:11:47,060 --> 00:11:51,980 So, now that we're there, a few things that we want to then do to go forward. 115 00:11:51,980 --> 00:11:55,220 First off, we may want to try and establish persistence. 116 00:11:55,220 --> 00: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. 117 00:12:05,680 --> 00:12:08,580 Well, many times this is only read-only ish. 118 00:12:08,580 --> 00:12:11,280 It's not quite truly read-only. 119 00:12:11,280 --> 00: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. 120 00:12:22,960 --> 00: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. 121 00:12:36,480 --> 00: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. 122 00:12:49,960 --> 00: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. 123 00:13:09,500 --> 00: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. 124 00:13:19,620 --> 00: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. 125 00:13:24,760 --> 00: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. 126 00:13:37,080 --> 00:13:41,500 But for our purposes, again, we want to keep looking for the other software vulnerabilities. 127 00:13:41,500 --> 00:13:46,220 So, this gives us an easy way to pull the firmware over the serial connection. 128 00:13:46,420 --> 00: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. 129 00:13:54,000 --> 00:13:58,960 So, this is just demonstrating how you can... one way of pulling the firmware. 130 00:13:59,020 --> 00: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. 131 00:14:10,240 --> 00:14:14,200 So, with that, I'm going to hand it over to Mark to see what he did with the firmware. 132 00:14:15,960 --> 00:14:16,540 All right. 133 00:14:16,680 --> 00:14:26,860 So, as Eric mentioned earlier, we definitely were running into issues with the iOS and Android apps for WandsView specifically, right? 134 00:14:27,080 --> 00:14:29,560 So, we're hitting our heads against the wall a little bit. 135 00:14:29,560 --> 00: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. 136 00:14:40,000 --> 00:14:42,900 I think it says Windows 7 specifically on their site. 137 00:14:43,160 --> 00:14:50,080 But the main takeaways from that is that that app is still compatible with all WandsView devices. 138 00:14:50,080 --> 00:14:51,780 It does have a limited feature set. 139 00:14:51,780 --> 00:14:54,760 I mean, they're still trying to push you towards using the apps. 140 00:14:55,200 --> 00: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? 141 00:15:09,980 --> 00:15:17,320 A couple other things related to that, this Windows app, is it does generate a significantly less amount of network traffic. 142 00:15:17,320 --> 00:15:18,900 That's going to come in handy later. 143 00:15:18,900 --> 00:15:21,680 And the binaries are not packed. 144 00:15:21,680 --> 00:15:28,220 Eric mentioned that the APKs look like they're probably packed with ProGuard. 145 00:15:28,220 --> 00:15:33,420 So, you know, definitely being able to disassemble and decompile and debug pretty easily. 146 00:15:33,500 --> 00:15:35,980 That helps out quite a bit. 147 00:15:36,040 --> 00: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. 148 00:15:46,580 --> 00:15:53,840 And the first thing we noticed when we ran it the first time, it logs user account credentials in clear text. 149 00:15:53,840 --> 00:15:55,720 That's obviously terrible. 150 00:15:55,880 --> 00:15:58,160 So, yeah, not a great sign of things. 151 00:15:58,760 --> 00: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. 152 00:16:08,980 --> 00: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. 153 00:16:19,080 --> 00:16:23,780 Who needs to man the middle of anything when you have it in the clear on a file on disk? 154 00:16:25,640 --> 00:16:26,400 So, yeah. 155 00:16:26,400 --> 00: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. 156 00:16:43,000 --> 00:16:49,200 So, it's not really a ton there. 157 00:16:49,200 --> 00:16:50,860 It's more just initial setup. 158 00:16:52,760 --> 00:16:58,500 This check is more just to see if this is a valid account that you're attempting to sign on. 159 00:16:59,020 --> 00: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. 160 00:17:15,660 --> 00:17:17,820 But, yeah, not too much else going on there. 161 00:17:17,920 --> 00:17:20,740 This is where the sign-on really begins. 162 00:17:20,920 --> 00:17:26,180 Assaulted and, yeah, your password is at least assaulted and hashed, so it's not set in the clear, thank God. 163 00:17:27,120 --> 00: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. 164 00:17:36,740 --> 00: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. 165 00:17:47,580 --> 00:17:56,480 And as you can see here, there's a specific device ID, along with some more configuration information, primarily endpoint URIs. 166 00:17:58,080 --> 00:18:04,780 And then there's another device configuration API endpoint that's hit. 167 00:18:04,820 --> 00: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. 168 00:18:18,300 --> 00:18:21,780 And, you know, more configuration information comes through. 169 00:18:21,980 --> 00:18:23,740 We'll dig into that a bit. 170 00:18:24,200 --> 00:18:28,980 And then the last request we really dig into is fetch infos. 171 00:18:28,980 --> 00:18:39,700 And this provides a much, much larger picture of the data that is stored for that specific device. 172 00:18:39,700 --> 00: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. 173 00:18:47,780 --> 00:18:51,720 And that just happens to be publicly accessible. 174 00:18:51,720 --> 00:18:53,120 And that's a picture of my kitchen. 175 00:18:53,120 --> 00:18:55,300 So from back in April. 176 00:18:56,660 --> 00: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? 177 00:19:06,820 --> 00: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, 178 00:19:24,940 --> 00:19:29,240 along with some other network configuration information including its MAC address. 179 00:19:29,640 --> 00: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. 180 00:19:39,140 --> 00: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. 181 00:19:53,340 --> 00: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. 182 00:20:01,880 --> 00: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. 183 00:20:18,340 --> 00: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. 184 00:20:32,080 --> 00: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. 185 00:20:51,040 --> 00:20:54,680 You know, we're going to swap out the device IDs and memory and then resume execution. 186 00:20:54,680 --> 00:20:55,960 So pretty straightforward. 187 00:20:56,160 --> 00: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. 188 00:21:08,510 --> 00:21:18,680 Okay, so what we have right here is, well, first I'll demonstrate that this account is... 189 00:21:23,620 --> 00:21:32,680 So we already have one specific camera that is tied to this account. 190 00:21:32,680 --> 00:21:38,860 And it's offline at the moment, so it's not really concerning that, right? 191 00:21:38,860 --> 00:21:42,980 We'll attempt to connect to it, but nothing's going to happen. 192 00:21:52,710 --> 00: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. 193 00:22:01,450 --> 00:22:04,610 We'll proceed to sign in as expected. 194 00:22:07,030 --> 00:22:13,430 And once we hit our breakpoint, we will swap out the device ID in memory. 195 00:22:13,910 --> 00:22:19,310 And then once it has finished here, it will resume execution. 196 00:22:30,120 --> 00:22:31,780 And we're online. 197 00:22:32,580 --> 00:22:34,720 So the thing is... 198 00:22:39,660 --> 00:22:43,000 So yeah, we can do everything in the app. 199 00:22:43,000 --> 00:22:44,340 We can pan and tilt. 200 00:22:46,080 --> 00:22:53,720 Yeah, I mean, like I said, it is a bit more limited feature set compared to the mobile apps. 201 00:22:53,720 --> 00: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. 202 00:23:00,960 --> 00:23:06,820 It's obviously a very, very significant access control vulnerability. 203 00:23:08,000 --> 00:23:15,200 So yeah, you know, certainly that was a pretty big discovery, you know, right off the bat. 204 00:23:18,960 --> 00: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. 205 00:23:26,580 --> 00:23:32,000 It was all primarily UDP, but we hadn't really no idea what it is in particular. 206 00:23:33,060 --> 00: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. 207 00:23:50,980 --> 00:23:59,220 His website, he presented at DEF CON 28 in 2020, fully tearing down the protocol and all that. 208 00:23:59,220 --> 00:24:05,260 So ideally, this was going to be something that, you know, maybe that was going to be in use here too. 209 00:24:05,260 --> 00:24:12,060 So we kind of set out to explore that by just looking for references to P2P and PPPPP. 210 00:24:12,120 --> 00: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. 211 00:24:28,940 --> 00:24:33,900 So yeah, we're pretty sure that we're dealing with the same protocol. 212 00:24:33,900 --> 00: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. 213 00:24:44,800 --> 00: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. 214 00:24:55,920 --> 00:25:03,600 So very, very briefly, the peer-to-peer protocol is used by a ton of IoT devices across hundreds of vendors. 215 00:25:03,600 --> 00:25:08,840 It's been in use for, you know, the better part of the last decade, if not longer. 216 00:25:09,240 --> 00:25:14,540 It uses UDP hole punching in order to circumvent restrictive network configurations. 217 00:25:14,800 --> 00:25:20,320 And it allows you, you know, these apps to connect to the cameras from anywhere in the world, right? 218 00:25:20,320 --> 00:25:22,760 They want it to be as accessible as possible, right? 219 00:25:22,760 --> 00:25:24,340 That's the whole point of these devices. 220 00:25:25,320 --> 00: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. 221 00:25:41,320 --> 00:25:45,020 So now we have established some initial access, right? 222 00:25:45,020 --> 00: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. 223 00:25:53,760 --> 00:25:58,820 We have packet capture for the camera and the app network communications. 224 00:25:58,880 --> 00:26:03,020 We have log files from both the windows and the camera logs. 225 00:26:03,020 --> 00: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. 226 00:26:11,300 --> 00: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. 227 00:26:21,140 --> 00:26:26,200 So now we want to kind of establish some more advanced access for looking for some additional exploits. 228 00:26:26,200 --> 00: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. 229 00:26:33,620 --> 00: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. 230 00:26:41,600 --> 00: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. 231 00:26:52,040 --> 00:26:57,100 So first for live log output, it's very, very simple, very easy. 232 00:26:57,100 --> 00: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. 233 00:27:07,980 --> 00: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. 234 00:27:13,400 --> 00:27:16,120 But again, that's just one way of doing it. 235 00:27:16,260 --> 00:27:20,720 But one thing that we'll quickly run into is the kernel watch dog. 236 00:27:20,720 --> 00:27:24,760 So if the watch dog is not written to, it reboots the camera. 237 00:27:24,760 --> 00: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, 238 00:27:41,800 --> 00:27:44,100 which will then reboot the camera. 239 00:27:44,380 --> 00:27:46,600 This isn't the only say security mechanism. 240 00:27:46,600 --> 00: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, 241 00:28:02,360 --> 00:28:05,940 providing all of the video streaming and the rest of the control of the camera. 242 00:28:06,100 --> 00: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. 243 00:28:15,200 --> 00: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. 244 00:28:26,560 --> 00: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. 245 00:28:34,740 --> 00:28:38,580 And so if you're using single user mode to get root, you're going to lose that. 246 00:28:38,580 --> 00: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. 247 00:28:45,860 --> 00:28:48,720 So of course, next step is to defeat the watchdog. 248 00:28:48,720 --> 00:28:50,460 So there are a couple of approaches here, right? 249 00:28:50,460 --> 00:28:51,240 That you could do. 250 00:28:51,240 --> 00: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? 251 00:29:04,800 --> 00:29:08,400 And so since we have root access, we could do something like that. 252 00:29:08,400 --> 00: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. 253 00:29:25,580 --> 00:29:27,220 So init app can't write to it. 254 00:29:27,380 --> 00: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. 255 00:29:39,880 --> 00:29:42,680 And then it may change the way that it's going to operate. 256 00:29:42,680 --> 00: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. 257 00:29:50,040 --> 00:29:51,120 So there's another way. 258 00:29:51,300 --> 00: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. 259 00:29:55,000 --> 00: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. 260 00:30:11,140 --> 00: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. 261 00:30:22,120 --> 00:30:28,060 Now, as a note, the camera is not running Linux kernel 2.4.18, but it does still work. 262 00:30:28,060 --> 00:30:29,840 Um, so your mileage may vary. 263 00:30:29,840 --> 00:30:34,180 It's running a three dot kernel, but, um, again, it's still, still may work. 264 00:30:34,180 --> 00: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. 265 00:30:41,360 --> 00: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. 266 00:30:52,140 --> 00: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. 267 00:31:02,740 --> 00: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. 268 00:31:12,180 --> 00:31:17,500 Um, so in this case, we discovered that our, our camera is a little Indian MIPS. 269 00:31:17,520 --> 00: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. 270 00:31:28,260 --> 00:31:32,180 We can run a quick hello MIPS and see. 271 00:31:32,180 --> 00:31:35,300 So I did not know this at the time when I was doing it. 272 00:31:35,300 --> 00:31:41,280 I built a tool chain and compiled, uh, compiled GDB server myself using that tool chain. 273 00:31:41,280 --> 00: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, 274 00:31:56,040 --> 00:31:57,900 then expose it over some port. 275 00:31:57,900 --> 00:31:59,380 It could be, it works over serial. 276 00:31:59,380 --> 00: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. 277 00:32:06,320 --> 00:32:09,340 Um, and again, just an example of how to do that. 278 00:32:09,440 --> 00:32:16,440 Um, so we can then connect to our, um, use, and this is actually one important note. 279 00:32:16,440 --> 00: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. 280 00:32:24,620 --> 00: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. 281 00:32:32,420 --> 00:32:38,300 Um, but once you get there, again, we know that an in-app is calling out to the watchdog. 282 00:32:38,320 --> 00: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. 283 00:32:46,260 --> 00:32:48,400 Is this absolutely necessary? 284 00:32:48,740 --> 00: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. 285 00:32:52,420 --> 00:32:53,560 So that's, that's what we did. 286 00:32:53,560 --> 00: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. 287 00:33:02,260 --> 00:33:02,980 Sure. 288 00:33:03,200 --> 00:33:04,820 So I'll hand it over to Mark. 289 00:33:05,040 --> 00:33:05,820 All right. 290 00:33:05,820 --> 00: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. 291 00:33:10,960 --> 00: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? 292 00:33:22,360 --> 00: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. 293 00:33:34,120 --> 00: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, 294 00:33:50,340 --> 00: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, 295 00:34:06,400 --> 00: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, 296 00:34:23,420 --> 00:34:25,100 yeah, your peer-to-peer connection is ready. 297 00:34:25,280 --> 00: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. 298 00:34:31,220 --> 00: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, 299 00:34:46,020 --> 00: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. 300 00:35:01,640 --> 00: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. 301 00:35:18,080 --> 00: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. 302 00:35:27,760 --> 00: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. 303 00:35:36,340 --> 00: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. 304 00:35:44,360 --> 00: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. 305 00:35:57,700 --> 00: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. 306 00:36:04,800 --> 00: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. 307 00:36:15,260 --> 00: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. 308 00:36:20,100 --> 00: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. 309 00:36:26,980 --> 00: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, 310 00:36:45,740 --> 00:36:48,120 uh, in its curl requests. 311 00:36:50,660 --> 00:36:54,620 And if we kind of like skip ahead a little bit here, this is a press for time. 312 00:36:55,280 --> 00:37:05,630 Um, what we can see here, yeah, if you, if you kind of highlight that, there's not much there. 313 00:37:06,730 --> 00:37:08,170 Ah, yes. 314 00:37:08,530 --> 00:37:12,090 So yeah, that doesn't really look like a good curl request. 315 00:37:20,180 --> 00:37:21,100 Okay. 316 00:37:21,100 --> 00:37:26,860 So very, very briefly, um, what devices are actually affected by this, right? 317 00:37:26,860 --> 00:37:35,940 Uh, so Wansview, every single device associated with Wansview is affected, including pet feeders, light bulbs, indoor and outdoor cameras. 318 00:37:35,940 --> 00:37:43,000 Uh, Galu as well, since they're, uh, you know, an affiliate company of Wansview, uh, and Sonato as well. 319 00:37:43,140 --> 00:37:49,820 Um, and then also Philemi is another, uh, manufacturer that, that we, uh, were able to experiment with. 320 00:37:50,180 --> 00:37:54,840 Um, but ultimately the affected vendors, uh, it all stems from AJ Cloud. 321 00:37:54,840 --> 00:37:59,660 It's whoever's running their device firmware on their cloud platform. 322 00:37:59,900 --> 00:38:04,920 And this ultimately affects seven different vendors, possibly even more. 323 00:38:04,920 --> 00:38:06,700 We weren't able to confirm all of these. 324 00:38:08,460 --> 00:38:11,860 So just real quick, what are some things that the vendors did right? 325 00:38:11,860 --> 00:38:14,120 They have certificate web-based authentication. 326 00:38:14,120 --> 00:38:17,040 It was fairly difficult to do some man-in-the-middle attacks from that. 327 00:38:17,040 --> 00:38:20,320 They have signed and obfuscated APKs, another good thing. 328 00:38:20,320 --> 00:38:24,380 They have a pared-down local operating system that at least attempts to be read-only. 329 00:38:24,380 --> 00:38:29,020 They could have had secure boot, but again, they have a read-only-ish file system. 330 00:38:29,020 --> 00:38:34,360 So you have to do some work even with physical access to be able to go and attack the machine. 331 00:38:34,360 --> 00:38:37,240 What they did wrong, of course, unauthenticated cloud access. 332 00:38:37,240 --> 00:38:40,680 The demos that we showed you, again, did not require any authentication. 333 00:38:40,800 --> 00: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. 334 00:38:49,820 --> 00:38:53,300 And it's very easy to manipulate when you have physical access. 335 00:38:53,500 --> 00:38:57,940 So mitigations, of course, if you want to use them, segment them off your network. 336 00:38:57,940 --> 00:39:01,360 The critical vulnerabilities in the cloud infrastructure will put your data at risk. 337 00:39:01,360 --> 00:39:03,720 So we would just recommend not using them at all. 338 00:39:03,720 --> 00:39:07,380 Again, restrict the inbound, outbound comms. 339 00:39:07,940 --> 00:39:12,440 You basically just want to block all of the different traffic that you have. 340 00:39:12,440 --> 00:39:15,360 You could also flash it with a different operating system. 341 00:39:15,360 --> 00:39:19,220 For sake of time, I'm going to kind of run through this really fast. 342 00:39:19,500 --> 00:39:21,580 OpenIPC, I would recommend you checking it out. 343 00:39:21,580 --> 00:39:24,600 At least the Q5 is directly supported. 344 00:39:24,600 --> 00:39:28,880 So you could flash it with that, but it supports a lot of different SoCs. 345 00:39:29,040 --> 00:39:34,700 So our tools that we used for this demo, we'll be releasing them shortly on GitHub. 346 00:39:35,660 --> 00:39:38,960 And feel free to follow along with the demo. 347 00:39:39,240 --> 00:39:41,500 There's some other future research opportunities. 348 00:39:41,520 --> 00:39:44,460 Again, apologies for having to run through this real quick. 349 00:39:44,460 --> 00:39:47,380 But thank you so much for coming to our talk. 350 00:39:47,840 --> 00:39:54,980 Special thanks to, of course, the following here, and definitely follow us on Twitter, and Elastic Security Labs. 351 00:39:54,980 --> 00:39:56,580 So again, thank you very much, DEF CON.