So good morning and welcome. I know this is kind of early Sunday morning, so I really appreciate you guys all being here. Today we're going to be talking about hacking and implanting a drop cam. So we both work at the R&D team at Cinec. Cinec does crowdsource vulnerability discovery with vetted security researchers. My name is Patrick Wardle. I've worked at various acronymed places, but currently I'm the director of research at Cinec. And I'm Colby Moore. I formerly worked at VRL and currently work at Cinec as a security research engineer. More like a security ninja, I think. All right. So what are we going to talk about today? First, a brief overview of drop cam. Then how we got a root shell on the device. Following that, we're going to talk about some vulnerabilities that we found. And then finally, we want to present a persistent implant that we designed for drop cam. So first let's talk a little bit, give a little bit of an overview, talk about some background information, talk about what drop cam is. Before jumping in, though, I always think it's a good idea to concisely define any possible ambiguous terms, especially since we're in Vegas, so there could be some confusion. So in the talk, when we talk about implants, we're talking about persistent code that is malicious. Hooking means intercepting function calls, usually by installing a hook or a detour. A Trojan is a malicious piece of software that pretends to be something legitimate. Injection is all about getting code into a remote process. And finally, a backdoor is some code that provides, you know, undetected remote control of the device. Now, it's a little sad when I hear these terms. I actually now think of the computer term first. But my wife likes that, so I guess that's the silver lining there. So what is a drop cam? Well, as you can see from their definition, it's a cloud-based video Wi-Fi solution. And at the core of it is the camera, the actual drop cam device. So besides an incredible simple set-up process, it's got some cool features, such as cloud recording, night vision, two-way talk and intelligent alerts. Now, one of the main appeals of drop cam is its trivial set-up process. Really all the camera needs to get set up is the name or SSID and password of your wireless network. Now, there's two ways to do this. This configuration can be done by either plugging the camera into the computer via USB or with a smartphone that has Bluetooth. Now, once the set-up is complete, the camera will be connected to the Wi-Fi network. From then on, it's pretty much fully autonomous. You really don't have to worry about it anymore. It's going to stream audio and video to the cloud and beacon to the drop cam servers for updates on a regular basis. So there's a lot of IP-based video solutions out there. So what's special about drop cam? Why did we choose to go after it? Well, now drop cam is owned by Google. And Google has indicated it will become the core of their push into the connected home. So in other words, soon there's going to be drop cams everywhere. Now, when we started this research, we didn't know that Google would buy drop cam. If we had, we probably would have tried to get hired there, get some equity. But it was still a pretty appealing target. For one, it's really popular. You see all over the Bay Area, it's a best-selling device on Amazon. Secondly, it shows up in interesting places like homes and offices. Again, the Bay Area, all the start-ups pretty much use drop cams for their security solutions. So good target in that point of view. And finally, it's kind of a juicy target because it has some really cool capabilities that, you know, we thought were pretty powerful and were just begging to be abused. Now Colby is going to talk about routing a drop cam. So based on the network footprint, we figured taking a hardware approach would be best. So naturally the first thing to do was crack the camera open. Conveniently, drop cam left us this mysterious header right here. Probing around revealed what looked like a 3.3 volt UART on there. So we hooked it up to the FTDI to serial to USB connector that you guys are all familiar with. And here's a little photo showing our ground connection and transmit and receive on pins 3 and 4, respectively, if you guys want to try this at home. So after a quick reboot, we have a serial console and major credit to drop cam for the sweet ASCII art right there. We wrote a serial brute forcer to try admin, admin, admin password, all the standards, but really no luck. So at this point we should probably mention the drop cam is running essentially just Linux. It's a miniature computer. It's running a Linux system on chip from a company called Ambarella based in the Santa Clara Bay area. And so, you know, we figured we'd take more of a Linux approach to maybe getting root in this box. So we decided to go after the boot loader. So if you hold enter on power on or you short the transmit and receive lines and power on the device, it should drop you to the boot loader. Now, this is Ambarella's custom boot loader. Now, looking at the boot loader, we got a couple options here. The set EMV one looked pretty promising. And it looks like there's an option to change the boot parameters. So we went ahead and just like, you know, root in a standard Linux box that you have physical access to, we went ahead and changed the parameter to slash bin slash SH and hope it drops us to a root shell. And yeah, that worked. So now we got to get rid of that password so we can get on the system, right? So we checked out Etsy shadow and it wouldn't open. So it looks like it was SIM linked to mount drop cam shadow. So we checked out Etsy F stab and it gave us the necessary information we needed to mount up that share. So we went ahead and mounted it up and now we have access to the shadow file. I went ahead and just knocked out that hash and saved. Went ahead and rebooted and reset the boot parameters in the boot loader and rebooted, boom, we have a full-featured root shell on the device. So there's some other research done previously and they really didn't find any vulnerabilities in the drop cam but we tend to have a little bit of a different opinion. So we're going to talk a little bit about the vulnerabilities that we found. So first let's talk about the environment. Since we have a root shell we can now poke around and explore. The drop cam is running ARM 32 bit Linux custom distribution and the heart of the drop cam is this connect executable. We're going to talk about that a lot later. They also left all sorts of goodies on the device for us, you know, drop bear, FTP, Telnet, GDB server, you know, thanks guys. So overall the drop cam is decently secure. There were no open ports or exposed network services. All communications were SSLed properly. And the drop cam employs device specific provisioning from the factory. That's likely why we couldn't crack the root password because each device has its own unique password. It also employs automatic updates. It beacons out regularly and checks drop cam for updates and they're pushed down and the whole device is reflashed. So it's pretty robust in that sense. But let's take a look at the first bug. The camera is using open SSL for comms to drop cam servers. But it's running an old version of open SSL so it's vulnerable to heart bleed. So what can we do with that? Drop cam says our cameras won't communicate with anyone on the Internet, only drop cam's cloud servers. But that's not really true. If we spoof DNS responses and trigger a client side heart bleed attack, we're able to download the camera's private and public SSL keys among other system information. So realistically now that we have these keys, what can we do? Normally the drop cam talks to the cloud via SSL and then you use your devices to view the video from the cloud. But you should note that it authenticates using the very same certificates that we stole. So a hacker with these certs could spoof a drop cam video feed providing false video to the cloud DVR. So should a user really trust what they're seeing? For the record, we notified drop cam of this heart bleed bug and they patched it fairly recently. However, they haven't rotated the camera's certificates so if anybody happened to have a bucket full of these certificates, we don't. There's nothing the consumer can really do at this point. So then for most of its functionality, drop cam runs busy box. But unfortunately the version is outdated and vulnerable. Basically it's an old bug that allows command injection via malicious DFCP response. So a user is able to inject commands via the host name parameter and they get propagated into the system host name. This is really only triggered if the host name is used by another utility. But we checked out the vulnerable source code and compared it to the disassembly from drop cam and it definitely matches. So we weren't able to trigger this bug right now because drop cam isn't using the host name in a way that would trigger this, but it could come back to bite them later. So all those bugs are pretty cool, but we had to open up the camera. So wouldn't it be nice if we could implant the device without opening it up? Luckily there's an app for that. It's called direct USB and we found a copy somewhere in the dark corners of the internet, specifically Russia. If you hold down the button on the back of the camera, the button that drop cam swears does nothing according to official docs, and you hold it down while you're powering the camera on, it enters a firmware update mode. And we believe this is how the devices are provisioned at the factory. When we questioned drop cam about this, they didn't deny it. Ultimately we were able to read and write unsigned data to the camera. So realistically an attacker could walk into the home, plug into a drop cam, reflash with malicious software in minutes. And back to Patrick. So there's more to drop cam than just the software that runs on the camera. So recall that a user may use their computer to initially configure the device. So to do this, the camera is plugged into the computer and then it mounts part of the camera as a share, which contains the setup utility. This utility, which requests root privileges to run, gets the SSID and password of the Wi-Fi network and then propagates that back to the camera. The end result is a connected and configured camera. Unfortunately, this application which runs at root is world writable. So in a proof of concept, a non-privileged host-based attacker can wait until any drop cam is plugged in. They can then inject a malicious payload into the mounted drop cam setup utility. Now when the application is run and elevated, so is the attacker's code. Now the Windows installer setup configuration utility has a similar privilege escalation vulnerability as well. Drop cam is still patching that so we can't go into details at this time. Now as Colby mentioned, the CEO of drop cam said that their cameras only talk to drop cam servers, which discounting things like Heartbleed is pretty much true. However, the same cannot be said for their iOS application. Now SSL pinning is an extra layer of security that ensures the client will only communicate with a well-defined set of servers. Now since the drop cam iOS application does not use SSL pinning, a man in the middle attack can occur. So if an attacker has a compromised root certificate or can coerce the user to install a certificate, for example, sending them an email, the connection can be man in the middle. So here we have a burp capture showing a man in the middle attack in action actually against my own phone, which is non-jailbroken. It reveals a username and password for a drop cam account. Now since drop cam does not use dual factor authentication or any shared or duplicate session alerts, an attacker with these credentials can persistently and surreptitiously spy on the user at any time. Now this is really good for the bad guys, not good for the rest of us. So now that we have a good way to implant the camera, let's have some fun. Introducing our full featured implant, cuckoo's egg. For those who are unaware, the cuckoo lays its egg in other nests. See how many you guys get it. Given the robust capability of the drop cam, our malicious software should. C, we want to be able to intercept video. Here, we want to hot mic a room. Propagate, we want to infect other hosts when they connect to the drop cam or it's plugged in. We want to be able to geolocate the drop cam, so if we send a bunch out in the wild, we know where they ended up. We want to be able to infill and exfil files in case we need to upload our new exploit or tool so we can pivot into the network. We want to be able to drop to a command shell to use our tools. And we want to be able to connect a basic network survey and a device survey. So conceptually the drop cam will sit on a corporate network and talk out to the drop cam's cloud. But with our implant, it will also talk out to us. We also need a method for other devices on the drop cam's network. We also need a method, sorry. What? Okay. Well, anyway. So our implant even comes with its own slogan. He sees you when you're sleeping, he knows when you're awake, he knows if you've been bad or good, just like the NSA JK. So in a real world scenario, how do we install our malicious software? We don't have remote code execution but there's a lot of options. We can intercept the package in transit, we could maybe gift a drop cam to somebody that's already been implanted or we could break and enter and modify it in the house. Realistically that stuff never happens, right? No further comment. We approached drop cam about this and they were convinced the adversary wouldn't be able to reshrink the drop cam as nicely as it was done to the factory. And that alone would be an appropriate anti tamper mechanism. What do you guys think? Now what about sending one as a gift? Recently a friend's incubator space was broken into. Is it too far-fetched to think that management might send them security cameras to implement? Probably not. Is a break in entering scenario really plausible? Maybe. Drop cam's argument was that you would see an attacker coming. However, only one third of users sign up for drop cam's cloud recording. Even then, if you just showed up with a Wi-Fi jammer, the camera doesn't cache any video locally so the video wouldn't get sent to the server. Now what makes drop cam a good target? The drop cam CEO said all software products are susceptible to jail breaking. And that's true. We tend to agree with that. But the drop cam really is the low hanging fruit. Here are the other options. Someone could go after a computer that often has full disk crypto, boot password and there's no forensic tools. They could go after a printer but it runs a proprietary operating system. You've got to crack it open. A printer can't see, can't hear. There's a lot of things it can't do. They could go after a gaming console but again, it runs sign code and has DRM protection. You've got to crack it open and it's generally turned off. Or they could go after a mobile phone but it's normally pass locked, again, runs sign code and it's really off person. So the drop cam, you don't need to open it up, no boot password, no disk crypto, no sign code, the operating system is open source, it's always on, has tons of capabilities and who's going to suspect that the security camera is spying on you. So in order to create an advanced implant, we needed to fully understand how the drop cam worked. In other words, we had to answer questions such as how does it hear, see or think? Where is its core logic, the main module of the brain? And finally, can this be manipulated or rewired? The drop cam has many hardware and software components. However, these all kind of come together in the connect binary, which I'll be talking about a lot. This binary is really the brain of the camera as it contains most of the drop cam specific operations such as talking to the audio and video devices, streaming content to the cloud and then also handling or executing commands that are received from drop cam servers. Unfortunately, the connect binary is packed with UPX, which is not normally a problem. Unfortunately, when we tried to unpack it, it failed. Now, since we wanted a full unpack, that would make everything easier from debugging to static analysis, we decided to look into this a little more. Now, the unpacker stub matched the UPX source code, indicating it wasn't a custom version of UPX. So we figured perhaps the binary was perhaps modified after the fact in some way to prevent unpacking. Now, I single stepped through the unpacking stub's instructions and followed along in the UPX source code, which was not fun. But this revealed exactly where the unpacking exception occurred. The code was checking a value within the binary's ELF header and then branching into a code path for unpacking shared library. That unfortunately then errored out. Now, connect is a normal ELF executable. It's not a shared library. So I was a little confused why I was taking this code path. So we decided to write a small Python script that simply unset the value in the ELF header that the UPX unpacking code was looking at. Once we did this, we then re-invoked UPX to attempt to unpack the binary and that worked. Connect was fully unpacked and even fully runnable, which is really nice. And actually using the inverse of this technique, so setting that member in the ELF header, we were actually able to create unpackable binaries as well. So I guess thanks to Dropcam for that. So now that we've talked about all these cool capabilities, let's talk about the core of our implant. We wanted to create something simple, portable to other devices and have the ability to leverage third-party libraries. So since we don't have to be too stealthy, Python seemed like a natural choice. We cross-compiled and stripped down Python to reduce the disk footprint. And then Python is then extracted to RAM disk on boot and our implant is kicked off all through an energy script. It's great that we have an implanted camera and all, but how is it going to talk to us? All comms are done over HTTPS and call out through the secure networks firewall. Our command and control and streaming data are sent over separate channels and our CNC server is set up on Amazon AWS infrastructure, the same as Dropcam's. Given the nature of our comms and by putting our CNC server on AWS, it really wouldn't be that easy to tell the difference between our regular Dropcam traffic and our implant by looking at network traffic or even to create appropriate IDS rules. Which connection is legit? What about if we wanted to ship a ton of these cameras out in the wild? How will we know where they end up? Cuckoo's egg runs a camera side Wi-Fi survey and ships it back to the CNC server. The CNC server then sends the survey back to Google's geolocation APIs and returns the device location. Thanks, Google. We also wanted our implant to autonomously propagate to Windows or Mac-based computers. Since we control the camera, we actually control the set-up application as well. So we simply replace it with a malicious implant installer. Now, whenever the user runs the implant or the set-up application, they're actually running the implant installer first. And that's executed with root privileges. We also use a homograph attack so that it's really difficult to actually tell which binary is the malicious one by simply looking at their names. We also made sure to disable the Bluetooth set-up feature so that the user was forced to plug the camera into the computer in order to configure it, which for us ensured that they would then infect their PC or Mac-based computer. So Apple loves to tout their many anti-malware mitigations. However, some of these are trivially bypassed while others can be avoided altogether, which allows our implant to execute freely. It's not detected at all. So if you want some more information, we gave a talk about the stuff at ShakaCon and also released an open source tool that can detect persistent OSX malware, which would also detect our implant on OSX. This talk describes bypasses for XProtect, which is Apple's antivirus product, Gatekeeper, the OSX sandbox, and even signed coding requirements. For example, it's able to load unsigned kernel module into the kernel. So sorry, Apple. Now a major component of our implant is the ability to grab and manipulate audio and video. Now I mentioned the Kinect binary talks to both the audio and video cards that reside in kernel mode. Data is read from these devices and then is streamed to the DropCam's cloud servers where it is consumed by the user. So first I'm going to talk about how our implant is able to hot mic the camera in order to listen in to everything. Since the Kinect binary exclusively opens the audio card, we have to inject a module into the Kinect process. So here are the various relevant components. The Kinect binary is continually reading the audio stream. But our injected module can then install a hook and gain access to the audio stream and then exfil it to our command and control servers. Now DropCam uses a standard Linux framework to read audio, which is kind of cool. So to get the audio, it invokes the send PCM read end function, which retrieves audio frames containing audio buffers. This is where the implant installs its audio hook. Again, the goal was to clone the audio and stream it to the cuckoo's egg server while letting it stream in parallel up to DropCam so the user wouldn't notice anything was amiss. So here is the code that is inserted as an audio hook. This code gets a pointer to the original send PCM read function, invokes it, and then simply exfiltrates any data or audio that's captured. So pretty straightforward. All right. Now on to video. So by disassembling the Kinect binary, we were able to uncover how the camera accesses and streams video to the cloud. In the disassembly, you can see it opening the video device, which is slash dev slash IAV. Now this device is backed by an umbrella chip that does all the video processing and H264 encoding in hardware, obviously for performance reasons. The second disassembly snippet shows the Kinect binary talking to this video device to get the actual video via an eye octal. The eye octals are all undocumented and many take undocumented structures. Luckily, there were some comments or error messages in the disassembly so we could maybe kind of get the name of the eye octal, which gave us some insight into perhaps what it was doing. So I mentioned we wanted to clone the video and stream it to the implant servers. Now, undocumented eye octals and structures result in a ton of reverse engineering and a ton of seg faults. However, we eventually got it all figured out and we wanted to describe that here. So first you open the slash dev slash IAV device. Then you get the H264 encoding parameter so that the stream you exfil can be decoded. You then map the bit stream buffer memory and the digital signal processor memory. Now, after you check that the video is actually being recorded, the video stream can finally be read with the IAV IOC read bit stream, yeah, bit stream EX eye octal. Now, besides this being really useful for an implant, this actually allows you to stream the video to a server or DVR of a choice. So this saves you money because you don't have to pay DropCam $30 a month to store your video and it also prevents Google from seeing what's going on, say, inside your house. So that's kind of a cool feature. I don't want Google seeing what I'm up to. So now we could clone the video feed, send it to an implant server while it was also streaming in parallel to DropCam. But we thought we wanted to take this a step farther and actually manipulate the live video stream on the device to do cool things like in the movies, for example, making an attacker invisible. So again, here are the various relevant components. The video card is going to generate frames which will, in this example, show the attacker, you know, breaking in or doing his bad things. So we really don't want that. However, the injected module will intercept these frames and inject other frames. These injected frames will then be streamed to the cloud instead and ultimately back to the user which will hide the attacker. So take a little bit of a closer look. Here's the video device and the connect binary which is reading frames. The injected module installs another hook. This time it's an IOCTL hook and watches for the IOC read bit streams EX IOCTL. Now when this IOCTL is called, it populates a structure with various values. Through reverse engineering, we were able to determine what these values were. Some of the relevant ones include the frame number, the address to the frame's raw H264 encoded data, the frame type, and finally the frame size. Now the easiest way to manipulate the video stream is just to wait for a frame type of JPEG full. Then moving forward, you can either just replay this frame to lock or freeze the video frame or actually inject other full frames as well. The other frames are not ideal because H26 encoding pretty much just encodes deltas. So if you're trying to intercept and manipulate a frame, a lot of times you don't actually have the full frame. These JPEG full frames happen every second so it's pretty easy to wait for them and then use them moving forward. All right. So video demo time. I wanted to show you how we can transparently lock the video stream. If you look at the top left is the drop cam feed. So this is what the user is going to see and this is what we are manipulating. The top right is a shot from an external camera. Bottom left is the sys log output and bottom right is the attacker's console. All right. So you see a mom coming to tuck her kid in. If you look at the attacker's window, they're going to then run the enable cam to activate the video lock. We then see... an attacker that somehow looks like Colby. Got to work on your disguises. The video now is locked to frame. It's injecting these JPEG full frames in so the video is frozen. But you can see the camera is still counting up so the user is not going to notice. Then we run the disable command which tells the camera feed to resync and then it's going to flip back to the baby. Now, I'm sure the mom is going to accept this child as one of their own. Well... apparently not. All right. Back to Colby. All right. So we built this awesome implant that does everything an attacker could dream of. But how do we control it? So naturally a sleek web control panel is needed. On the main screen all the cameras call back with their name and location so targeting is super easy. From there it's easy to select a target and a job to be sent down to the drop cam. We support all the commands we talked about previously. The camera calls home to the server at a standard interval to report job results and retrieve new jobs from the queue. We have a series of completed and unsent jobs. Queued up is an execute and execute task whereas there are several completed surveys. Results are reported in a convenient JSON format. For this next part we need a bit of disclaimer. The stuff we're about to do is theoretically possible on any device, not just drop cam. However, we were just kind of curious how far we could take things. Since physical access is easy enough and there's lots of free space inside the drop cam, it's conceivable to think that someone could add some extra hardware. Could someone turn this network device into a true cyber weapon? Most embedded systems contain what are called general purpose input and output, GPIO for short. What if we use this camera's GPIO pins to control something external? However, since we don't have a device schematic and toggling random pins is generally kind of frowned upon, we wanted to use a known quantity. In this case we decided to interface with the drop cam status LED seen circled up above. The status LED is really just tied to one of the drop cam's GPIO pins. But we needed a way to do this intelligently because the light comes on randomly and we didn't really want to be setting off whatever we're doing intermittently. So here's some pseudocode to show what we did. We figured out how to toggle the status LED at a set frequency, just in a loop up there. Then we installed a microcontroller to listen for the square wave that we're generating on the LED. So it's listening for that specific frequency. And then when the microcontroller gets the frequency it's looking for, something amazing happens. If your camera starts blinking, get out of the way. So here's one possible scenario. Please note that the following was performed in compliance with all local laws and you should not try this at home. Oh, that's tragic. Well, that's a wrap. You probably heard that the Internet of things is blowing up. So remember you saw it first here at DEF CON 22. Again, I'm Patrick and this is my coworker Colby. Feel free to contact us. We probably won't plug in any devices you send us. Any questions now? We have a few extra minutes. Yes, in the front. Great. So the question was, you know, while we're hooking the video and audio stream, did we see any degradation in the performance of the device? Since we were hooking pretty low level, where the IOPTLs are coming in, we're pretty much just mem copying them off and then putting that in a shared buffer where exfiltrate code would just pick it up and do that. So in our testing, we didn't see any specific degradation or anything. And sometimes the video stream goes in and out anyway. So independent of us. Any other questions? Awesome. Well, thanks again. Remember, don't trust cameras from strangers.