00:00:00.067,00:00:06.073 >>Good morning, camera nerds! [cheering] Yeah! [cheering] A few of us in here. Uhm, I'm 00:00:06.073,00:00:10.110 pretty excited about this talk, uhm, I was also pretty excited to make sure that I had 00:00:10.110,00:00:14.248 Bluetooth turned off on my camera when I showed up. [laughter] Uhm, so I guess, uh, 00:00:14.248,00:00:18.852 if everybody wants to go ahead and turn on the WiFi on their camera now... No? No? [laughter] 00:00:18.852,00:00:25.392 Okay! Okay, that's fine. How many, uh, so, so, camera, how many people, camera people do we 00:00:25.392,00:00:31.031 have here? Awesome! How many people find that the software on their camera is, uh, something 00:00:31.031,00:00:36.436 other than complete a**? [laughter] Well, that's a surprise! [laughter] We'll get 00:00:36.436,00:00:40.874 you up on stage! Maybe, maybe you work for Nikon, who, who knew, who knows? [laughter] So, 00:00:40.874,00:00:44.544 I think we've all struggled with this and have probably thought "Well, this isn't terribly well 00:00:44.544,00:00:48.749 thought out". Uhm, and then, of course, you go and buy a Canon printer these days and you get a 00:00:48.749,00:00:54.321 CD with all the software on it - like, really? What year is this? Anyhow, I could, I could, I 00:00:54.321,00:00:59.259 could complain about that for days. Uhm, right now, we are going to learn about, uh, how, 00:00:59.259,00:01:04.865 how kind of "broken" the software on our cameras is and how vulnerable that can be when 00:01:04.865,00:01:10.203 we are out and shooting and wanting to take advantage of some of these fancy features 00:01:10.203,00:01:15.509 that, uh, these camera manufacturers think we all need to pay extra for in the first 00:01:15.509,00:01:20.647 place. Let's give Eyal a big round of applause! [applause] Have a great time, man! 00:01:20.647,00:01:25.652 [applause] >>Thanks. [applause] Hi everybody, hi everyone. Thank you for coming. Uh, I'm Eyal and 00:01:32.459,00:01:38.198 I'm going to talk today about my recent research called "Say Cheese" or "How I Ransomwared 00:01:38.198,00:01:43.670 Your DSLR Camera". Before I start, let's have a brief interview, uhm, I'm Eyal Itkin, 00:01:43.670,00:01:49.409 I'm, uh, vulnerability researcher at checkpoint, uh, research group. In my research 00:01:49.409,00:01:55.615 projects I usually tend to focus on embedded devices or network protocols and you can usually 00:01:55.615,00:02:01.521 read about my recent publications on my twitter. Now, that we've finished with the 00:02:01.521,00:02:08.395 introduction, let's start! Being a vulnerability researcher usually means you study, a, a 00:02:08.395,00:02:14.034 program, and embedded device - you find vulnerabilities in it. You responsibly disclose this to 00:02:14.034,00:02:18.338 the vendor, uh, you wait for a conference, hopefully you get accepted and that's it, right? 00:02:18.338,00:02:20.340 But after you finish up with the research, starts, uh, the most complicated part, uh, routine of 00:02:20.340,00:02:22.342 a vulnerability researcher and this is finding the idea for the next, uh, research. And looking 00:02:22.342,00:02:24.344 for new research ideas is always tough, uh, it don't simply fall off a truck and that's it. Uhm, 00:02:24.344,00:02:29.349 for this, uh, part of my daily work, uh, I have real practices for finding new leads for a 00:02:32.019,00:02:37.024 research projects. Uhm, the first of which is check up new technologies, uh, that just got 00:02:56.043,00:03:02.449 published. Uhm, if it's new and fresh less eyes looked upon it and maybe I will find something 00:03:02.449,00:03:08.989 interesting in that product. The second is attend conferences, like DefCon, and hope for a good 00:03:08.989,00:03:15.529 idea to pop up - and that's, uh, usually helpful. And the last, uh, uh, the last part in which 00:03:15.529,00:03:21.568 help in this specific research is ask friends, family what software and hardware they 00:03:21.568,00:03:28.308 usually use on a daily basis. If many people use this product, it's probably interesting. Uhm, 00:03:28.308,00:03:33.447 and if we find vulnerabilities in it, uh, it would be a good publication and interesting 00:03:33.447,00:03:39.419 research. For this specific research, as you, as you probably already understood, 00:03:39.419,00:03:45.325 we're going to focus on hardware - and what specifically? My dad's camera. [laughter] Because 00:03:45.325,00:03:50.330 my dad has a camera and he takes it around to, uh, family events, uh, important life events, trips 00:03:52.365,00:03:58.071 - and no one is allowed to actually touch the camera or do anything with it. So, I was 00:03:58.071,00:04:04.811 interesting to find out if I can "hijack" the camera and, uh, exploit it. So, we are going to 00:04:04.811,00:04:11.218 talk, to talk today about cameras. And, if you look on cameras from a security 00:04:11.218,00:04:16.223 perspective as a black hat, we can see we have a good, a good field in cameras, we have 00:04:18.658,00:04:23.797 photography which is a very common hobby. Being a common hobby also means that many 00:04:23.797,00:04:29.703 potential victims, we have many people that use cameras, take them with them and to important 00:04:29.703,00:04:35.342 places. If you can do something to cameras, you'll have many potential victims, uh, you could 00:04:35.342,00:04:41.681 infect. In addition, people buy expensive cameras and I actually found out that the lens is the 00:04:41.681,00:04:46.987 most expensive part but, yea, people buy expensive cameras and equipment and we treat them with 00:04:46.987,00:04:52.325 care. Because you have special backpacks for your camera, you don't let anyone touch it, uhm, 00:04:52.325,00:04:58.732 and this also means that if the target is expensive you probably have money, and if you have 00:04:58.732,00:05:03.670 money you have good potential to take your money and, get it to our own. And the last part is 00:05:06.439,00:05:12.345 camera store, uh, memories from special life events. If you go on a trip to Japan you travel to 00:05:12.345,00:05:17.350 DefCon, you store all your picture, pictures on your camera and if someone will take your 00:05:20.587,00:05:27.127 camera or hijack your images, you'll get emotionally involved. You'll get dramatic, you won't 00:05:27.127,00:05:33.567 think clearly and that's a good fear. You have many people with money that think clearly when 00:05:33.567,00:05:39.839 something happens to their camera. And we are thinking, like, assuming I can take over 00:05:39.839,00:05:45.011 your camera, your target DSLR camera, mirrorless camera any, anything like it. What can I do 00:05:45.011,00:05:50.917 with it? [tick noise] Well, uh, I can break it but I really don't know why people still do 00:05:50.917,00:05:57.757 IOT breaking this year, uh, but it's a thing. It's a good espionage tool, it already takes 00:05:57.757,00:06:04.464 pictures with high quality. But, we're going to focus today on the third part which is 00:06:04.464,00:06:10.337 ransomware. If I can lock up your camera and encrypt all of your images, I can ask for cash 00:06:10.337,00:06:17.077 back. And, as most of you have cameras, and you are attached to them, the important question to 00:06:17.077,00:06:22.549 be asked is that, if I encrypt your camera, all your images in the camera and lock the camera 00:06:22.549,00:06:27.554 itself. Would you pay to get your camera back? And we really think that the answer is "Yes". 00:06:31.491,00:06:37.163 People will pay, this is an interesting attack vector, so let's try to install ransomware 00:06:37.163,00:06:42.168 on your cameras. Let's get started. So, meet our target for this specific research, we had 00:06:46.573,00:06:53.179 decided to focus on a Canon EOS 80D, we chose this specific model because it supports both 00:06:53.179,00:06:58.184 USB and WiFi, so we could test, uh, both interfaces for this specific camera. In addition we 00:07:00.387,00:07:05.191 chose to focus on Canon because Canon controls more than half of the market share, so it was 00:07:05.191,00:07:11.498 quite easy to decide. I think that all of the people I know of which have Canon cameras - so 00:07:11.498,00:07:18.405 that was quite obvious. After we chose Canon we saw that Canon has an extensive modding 00:07:18.405,00:07:24.210 community called "Magic Lantern". And, actually, there are a few modding communities 00:07:24.210,00:07:29.215 for Canon cameras and other cameras as well, we have Magic Lantern and we have CHDK which 00:07:31.284,00:07:36.523 stands for "Canon Hack Development Kit". Essentially, we can think about it as 00:07:36.523,00:07:42.796 "jailbroken" camera, uh, both communities extend the original functionality, they solve bugs, 00:07:42.796,00:07:48.735 they add new features, uh, it's really easy, uh, jailbroken camera with an open source 00:07:48.735,00:07:54.708 community behind it. So, we have, uh, researchers which reversed engineered the hardware 00:07:54.708,00:07:58.712 and the firmware of the camera. And, essentially they wanna build up an emulation 00:07:58.712,00:08:02.916 environment. So, developers would be able to develop open source features for their 00:08:02.916,00:08:08.088 cameras. Reading through the forums, we, I actually saw that several developers don't have 00:08:08.088,00:08:14.561 enough money to buy the camera, so, they only have, uh, emulated camera on their computer because 00:08:14.561,00:08:20.800 they don't have enough money to actually buy a physical camera of their own. So, being an open 00:08:20.800,00:08:24.604 source community, you have all of the benefits - we have extensive wiki pages which 00:08:24.604,00:08:29.743 document how the camera works, they actually document even important stuff inside the 00:08:29.743,00:08:35.615 firmware and symbols - meaning addresses in the firmware itself, as we can see here, we 00:08:35.615,00:08:41.187 have the documentation for that method, called, "task create" which creates a new task on the, 00:08:41.187,00:08:46.693 uh, camera. We have the documentation for all of the, or most of the, parameters of the 00:08:46.693,00:08:50.964 function and we can see on the documentation itself, that the arguments are not really known 00:08:50.964,00:08:57.070 yet, or not all of them known. And that's because it's community based - some entry;s 00:08:57.070,00:09:01.274 still missing from the documentation. But, uh, nevertheless, it's still a gold 00:09:01.274,00:09:06.980 mine. When we start our own research. I don't need to, uh, understand in full all of the, 00:09:06.980,00:09:12.485 uh, internal data structures of the camera, uh, what's the operating system? And find out a 00:09:12.485,00:09:18.191 few important functions because Magic Lantern already did it for us - documented on their wiki 00:09:18.191,00:09:24.264 pages. That's a really good start for any embedded research. Just as an important note before 00:09:24.264,00:09:28.701 we continue, at the time of our research, and I think it even today, fix me if I'm wrong, 00:09:28.701,00:09:33.706 there was no Magic Lantern port yet for this specific camera. Which means, if you install 00:09:36.543,00:09:40.213 Magic Lantern, on your Canon Camera, it comes with, basically, bugging 00:09:40.213,00:09:45.185 functionality. Uh, you have the capabilities to read memory from the camera, write memory to the 00:09:45.185,00:09:52.025 camera, and even execute lower scripts for some reason. Uhm, we don't have it, we don't have ML 00:09:52.025,00:09:57.764 port for our camera, we only had the documentation and, uh, the internet. It's really useful, 00:09:57.764,00:10:03.870 it's better than nothing but we don't have any debugger for our own camera. The attack that we 00:10:03.870,00:10:09.542 are going to focus on is called PTP - and when you Google up PTP you can see that the PTP 00:10:09.542,00:10:14.547 protocol stands for "I" triple "E" "15" ,"88" - which is, uh, "precision time protocol" and I 00:10:16.883,00:10:21.421 did my thesis on this protocol so I can talk to you for hours about how the master clock is 00:10:21.421,00:10:27.660 going to send a precise timestamps to the slave clock, what does it have to do with 00:10:27.660,00:10:33.633 camera? Well, it, it, it don't. It turns out that PTP also stands for the "Picture Transfer 00:10:33.633,00:10:35.768 Protocol". [laughter] Which makes more sense, right? [laughter] Uh, that's actually 00:10:35.768,00:10:37.770 going to be the second time we break the PTP protocol, uhm, uh, PTP stands for uh, "Picture 00:10:37.770,00:10:39.772 Transfer Protocol", initially we only had USB to connect our camera to the computer. And, 00:10:39.772,00:10:41.774 nowadays, our cameras also support Bluetooth and WiFi, so the protocol was extended and 00:10:41.774,00:10:46.779 not it also supports PTP over IP. But, we have to remember that it's the same old protocol 00:11:01.828,00:11:06.833 from the USB and, uh, we're going to it in the next slide. In addition, although the 00:11:09.035,00:11:13.106 protocol is called "Picture Transfer Protocol", it's supports a surprisingly high 00:11:13.106,00:11:18.211 amount of commands, uh, you can query the camera for the battery level, for the, uh, firmware 00:11:18.211,00:11:23.917 version, and actually, there a lot of the different commands in it, you'll see in the next 00:11:23.917,00:11:30.623 slide. So it's, uh, it looks like a promising attack vector. There was some prior work about 00:11:30.623,00:11:37.497 this protocol and this was, uhm, uh, 6 years ago in Hack in the Box, and, uh, Daniel Mende, uh, 00:11:37.497,00:11:43.803 presented his talk called "Paparazzi over IP". In this talk he, he also talked about, 00:11:43.803,00:11:50.143 uh, PTP and he showed that, uhm, it's a fairly naive network protocol since it was developed 00:11:50.143,00:11:56.482 from the USB protocol to IP. No one thought about adding some authentication or encryption to 00:11:56.482,00:12:01.588 it, which means if you're on the same WiFi network with the camera - you can send messages 00:12:01.588,00:12:07.627 straight. And that's good for our, uh, attack vector. We are going to focus on implementation 00:12:07.627,00:12:12.398 vulnerabilities in this protocol and not the original functionality it offers. So, we 00:12:12.398,00:12:17.403 hope to find vulnerability in implementation and take over the camera. Thanks. Time to analyse 00:12:19.572,00:12:24.577 the firmware itself. This was a classic case in the research, you simply download the 00:12:31.618,00:12:36.856 firmware's update file from the vendor's website, it's called a "dot F I R" file, supposedly 00:12:36.856,00:12:43.196 it's, uh, firmware. Uhm, when we open it in our Hex editor we initially saw a problem - in a 00:12:43.196,00:12:48.267 byte histogram you can see we haven't even distribution of all of the bytes which usually means 00:12:48.267,00:12:53.506 that the firmware, the firmware is probably encrypted or compressed. So, we look back on 00:12:53.506,00:12:59.979 Magic Lantern and what do they have to say about it? And it's actually AES encrypted which is 00:12:59.979,00:13:05.818 bad news, uh, I consulted with a friend which told me, "Yea, even if it's encrypted you probably 00:13:05.818,00:13:12.625 could find a key in Google and that's it."` And this didn't work. Uhm, Magic Lantern do have 00:13:12.625,00:13:18.097 the key but we don't share it because they want to use it for their product, so, the key is 00:13:18.097,00:13:24.337 not available online and we can't decrypt the firmware. Uh, at this point, at this point it 00:13:24.337,00:13:30.009 looks like a dead end, uh, we have a camera, can we we somehow maybe dump the firmware from the 00:13:30.009,00:13:36.683 camera itself? Uh, it's a nice camera, we don't want to break it, we actually bought a new 00:13:36.683,00:13:42.155 camera, uh, it works. Uhm, how did Magic Lantern research their own cameras? And it turns out 00:13:42.155,00:13:47.860 that they developed something called a "ROM Dumper". And the ROM Dumper is a firmware update 00:13:47.860,00:13:53.933 file that they created and signed, uhm, which you load into your camera and it downloads the 00:13:53.933,00:13:59.639 firmware to your SD card. So, I used ROM Dumper and as we can see, it actually, uh, worked 00:13:59.639,00:14:04.177 quite nicely. And now we have the firmware on our SD card without breaking the camera 00:14:04.177,00:14:09.182 which is quite good. Now, we load it into our disassembler. Uh, Magic Lantern even gives you 00:14:11.484,00:14:16.489 instructions on how to load dump, uh, fixed on to IDA and we then verify all the basic 00:14:18.491,00:14:23.162 functions we found, again, in the Magic Lantern documentation. So, so, everything aligns 00:14:23.162,00:14:28.167 correctly. The firmware itself, uh, uhm, is an arm, uh, firmware and that's because the camera 00:14:30.303,00:14:35.308 uses it as an ARM CPU - a 32-bit MDM RM CPU. Which usually means once you load it into IDA, you 00:14:38.478,00:14:43.116 now have to manually improve IDAs ARM analysis because it doesn't disting, distinguish 00:14:43.116,00:14:47.954 quite clearly between ARM code sections and thumb code sections, so, we have to 00:14:47.954,00:14:53.793 manually improve it. Luckily for you, uh, you don't have to do it yourself, we developed an IDA 00:14:53.793,00:14:58.798 plug-in just for this case which called "Thumbs Up". Thumbs Up is a really, uh, basic IDA plugin 00:15:00.867,00:15:06.472 that uses really, really basic machine learning calling basic false-classifiers and that's it. 00:15:06.472,00:15:11.144 And it improves the analysis, uh, you can read all about it in our research blog post and it's 00:15:11.144,00:15:17.850 already on GitHub. Uhm, Thumbs Up was designed to improve the analysis, uh, focused on ARM 00:15:17.850,00:15:23.956 assembly, uh, to distinguish correctly between thumb and ARM code sections. And it was used 00:15:23.956,00:15:29.328 as part of preprocess phase for an additional IDA plugin called "Karta" which matched open 00:15:29.328,00:15:34.400 source when statically inserted into the firmware. In our case, we couldn't find any, uh, such 00:15:34.400,00:15:39.639 open sources because it says that Canon implement everything on their own - which is a good 00:15:39.639,00:15:44.410 sense because we are going to find vulnerabilities if they reimplemented everything in your 00:15:44.410,00:15:51.317 camera. Just to get a sense of, uh, why did we need to improve the analysis before we started 00:15:51.317,00:15:56.989 and, uh, and just loaded to to IDA, we saw this, uh, navigation bar and all of the brown 00:15:56.989,00:16:02.995 rectangles stands for code sections without functions. It means that IDA analysed it as 00:16:02.995,00:16:09.268 code but couldn't distinguish any functions inside it. And we have a lot of, uh, these brown 00:16:09.268,00:16:15.908 rectangles. After you execute Thumbs Up, it looks like this - you no longer have any brown 00:16:15.908,00:16:21.380 rectangle and we actually found a few more function pointers and swings in the data sections as 00:16:21.380,00:16:27.486 well as we can see in the wide swipes in the green bar. So, use Thumbs Up, uh, it runs quite 00:16:27.486,00:16:32.291 fast, it's already on our GitHub, don't do manually what a script can do for you, uh, uh, 00:16:32.291,00:16:39.098 at home. Now that we've finished analysing it and loading it into IDA, uh, the operating, uh, 00:16:39.098,00:16:45.938 system itself is called "DryOS". DryOS is a proprietary real-time operating system, uh, Canon 00:16:45.938,00:16:51.777 actually developed it especially or their own cameras, and I'll repeat that - Canon especially 00:16:51.777,00:16:56.782 implemented their own real-time operating system just for their cameras. Which is quite insane, 00:16:59.151,00:17:04.724 I haven't saw it in, uh, in other products. However, from our perspective it's just a 00:17:04.724,00:17:09.629 real-time operating system, it's flat memory out of space - everything is fixed, you will 00:17:09.629,00:17:15.668 find a vulnerability in a single task - you can hijack the entire camera and that's it. And the 00:17:15.668,00:17:21.841 bonus of this operating system is that the camera reboots in 3seconds which you probably saw 00:17:21.841,00:17:26.846 it on your own where you have your own cameras but this also means that when I develop the 00:17:26.846,00:17:32.985 exploit and I debug it because exploit doesn't usually work on the first attempt. Rebooting the 00:17:32.985,00:17:38.858 camera only takes 3 seconds - not a minute, not 7 minutes, not 20 minutes like any other 00:17:38.858,00:17:45.765 embedded device - it only take 3 seconds. And that saved us a lot of time during our research. 00:17:45.765,00:17:50.770 Time to break up the PTP protocol. The first part is "locate the code" and the PTP 00:17:53.306,00:17:58.344 protocol is a command-based protocol - we send requests to the camera and we get response 00:17:58.344,00:18:03.282 back. Every command has a unique identifier called an "opcode" and thanks to an anonymous dot 00:18:05.351,00:18:10.156 net programmer, here we can see the PTP commands from the SDK. Which was found in Magic 00:18:10.156,00:18:16.295 Lantern's development group and you have the link to almost a full list. Here we can see a 00:18:16.295,00:18:22.435 partial list, we have commands to open a session to the camera, close a session, create an 00:18:22.435,00:18:28.140 object or what they have there in their recommendation and we can see that, uh, each command 00:18:28.140,00:18:34.180 has a unique identifier and we can find them in the firmware. So, the next part is gonna be, 00:18:34.180,00:18:40.586 to locate the code simple search these constants in the firmware. We actually did this search and 00:18:40.586,00:18:46.726 we found a massive function with a unique code pattern, as we, as we can see here. We have the 00:18:46.726,00:18:53.699 constraints to close a session, cto open a session - to get uh, the device's info and the upcode 00:18:53.699,00:18:58.771 is always the forced argument to the function to our zero. Another one, we have a function 00:18:58.771,00:19:04.677 pointer which has gone we, the function handler for this command and the third argument 00:19:04.677,00:19:11.117 is always 0. Probably flags that no one uses. This means the function we actually, uh, 00:19:11.117,00:19:17.556 located is a function which is responsible to register in the PTP-handler. This means we now 00:19:17.556,00:19:22.662 have the, uh, full mapping between each opcode and the respective function pointer. So, 00:19:22.662,00:19:27.166 now it's going to be quite easy to, uh, scan all of the functions and check for 00:19:27.166,00:19:34.040 vulnerabilities in them. We verified our findings with trace strings, we left trace strings 00:19:34.040,00:19:38.811 inside the firmware itself. So, we have the, uh, handler for open session. It includes 00:19:38.811,00:19:45.317 strings such as open session so we know we're on the right track. Just as a basic recap for 00:19:45.317,00:19:50.322 now - we have almost 150 unique handlers. I really wasn't kidding when I told you that 00:19:52.992,00:19:57.229 protocols supports dozens of dozens of dozens of commands - that actually supports 00:19:57.229,00:20:02.234 additional commands but some of them are duplicate. So, we have 148 unique handlers. Usually the 00:20:05.004,00:20:10.209 rule of thumb is if you find 10 handlers you'll find one vulnerability so we're going to 00:20:10.209,00:20:16.949 find vulnerabilities somewhere in the different handlers. The second stage is to understand 00:20:16.949,00:20:23.422 API. Uhm, since we have a fixed function which reduces all of the different handlers - we all 00:20:23.422,00:20:27.960 implement the same API. Each handler can receive up to 5 different arguments which are 00:20:27.960,00:20:32.965 integer types, 32 bits. And some of the request can also be included with an input data 00:20:34.967,00:20:41.207 buffer. Every handler will used a fixed context called "PTP context" that uses function 00:20:41.207,00:20:47.713 pointers to analyse a process and send back data to us. Without knowing about these 00:20:47.713,00:20:53.152 function pointers, it, the call itself looks like gibberish but Magic Lantern happily documented 00:20:53.152,00:20:59.158 this block for us, so we just code use it and that's it. Although we started with almost 00:20:59.158,00:21:05.231 150 unique command handlers, uhm, a quick scan shows there's only 38 different commands which 00:21:05.231,00:21:10.302 actually receive an input buffer which makes sense because a protocol is used to query 00:21:10.302,00:21:16.075 information from the camera and not just sending information to the camera. So, most of the time 00:21:16.075,00:21:21.747 you only get back information and we don't send data. Although it's a massive reduction to the 00:21:21.747,00:21:27.353 storage space, it's still better than nothing and if, uh, apply to the same rule of thumb we are 00:21:27.353,00:21:32.358 going to probably find 3 or 4 vulnerabilities in the firmware. At this point you can probably 00:21:34.627,00:21:39.398 think of "Okay, simply fuzz all of the different commands, uh, you'll find a vulnerabilities, 00:21:39.398,00:21:45.137 the camera will crash and that's it." But, you have cameras, you know it doesn't work that way. 00:21:45.137,00:21:49.842 Even when I connected the camera to the USB, and tried to send messages in Python to read and 00:21:49.842,00:21:56.015 it crashed. So, uh, the camera always crashes, uh, fuzzing is not going to work and I don't 00:21:56.015,00:22:01.954 have any external mechanism to physically reboot the camera each time. In addition to the 00:22:01.954,00:22:07.459 fact that sometimes when the camera, re, uh, gets stuck, you actually need to plug off the 00:22:07.459,00:22:13.999 battery and reinsert it, so fuzzing is gonna be quite slow. Instead I choose to, uh, 00:22:13.999,00:22:19.705 manually, uh, finding vulnerabilities in the firmware, Google code added and that's it. 00:22:19.705,00:22:24.443 Hoping to find some vulnerabilities but one good vulnerability, uh, will be 00:22:24.443,00:22:30.316 enough for us. And it actually worked quite well. Uh, we found 3 Remote Call Execution 00:22:30.316,00:22:34.920 vulnerabilities right on the first scan and here you can see the CVEs for these 00:22:34.920,00:22:40.492 vulnerabilities. One important thing to note is that 2 of the vulnerabilities are in 00:22:40.492,00:22:46.432 Bluetooth-related commands and if you had this specific camera model, you might know that the 00:22:46.432,00:22:51.437 Canon EOS 80D doesn't even support Bluetooth, uh, but hey, uh, I'm not complaining. Uhm, 00:22:55.274,00:23:00.779 maybe it's a left over from a different model. Maybe it's for future support, I dunno but we 00:23:00.779,00:23:06.085 have vulnerabilities in an interface we don't even have in the camera. Of the 3 00:23:06.085,00:23:10.623 vulnerabilities we' found are Buffer overflow and the Globals - buffer overflow on the stack 00:23:10.623,00:23:15.194 and buffer overflow of the heap. So, we have all of the vulnerabilities we need and we 00:23:15.194,00:23:20.866 choose to focus on, uh, a vulnerability over the stack because it’s easiest to exploit. 00:23:20.866,00:23:25.871 Time to build the exploit for our camera. [drinking water] Here we can see the code snippet 00:23:35.681,00:23:41.120 for the vulnerable part, and the first line we query the packet for its size and store it in a 00:23:41.120,00:23:46.558 fireball. Without using this size or going to prepare, uh, local stack buffer of fixed 00:23:46.558,00:23:53.132 size, we fill up the response packet in advance and then we read the data from the network, 00:23:53.132,00:23:59.338 according to the attacker's size into a fixed-sized buffer. And this usually means it's a 00:23:59.338,00:24:04.176 classic buffer overflow. We use the attacker's size, uh, size without check that it's smaller 00:24:04.176,00:24:09.982 than the size of the buffer on the stack. We can simply overflow the data and change the 00:24:09.982,00:24:15.754 return address, however, we don't stop here. Uhm, before we actually returned on a function, 00:24:15.754,00:24:22.094 we can see some mystery call back, uh, but it's used to process the fan, uh, incoming 00:24:22.094,00:24:26.965 packet. We don't have a debugger, we don't know what does this mystery call back, uh, 00:24:26.965,00:24:33.272 do, we simply hope we can, uh, bypass it freely and return back from the function so it could 00:24:33.272,00:24:38.277 execute our own code. Please remember this mystery call back, we'll see it here in advance and 00:24:40.379,00:24:46.051 the next slide. When building the exploit, we need to remember we don't have a debugger, we 00:24:46.051,00:24:51.657 only have a camera and that's it. Uhm, it's a nice little black box, uh, we can see it but 00:24:51.657,00:24:56.695 we don't have a debugger for it. Uhm, in such cases, I usually prefer to use, what I like to 00:24:56.695,00:25:01.266 call "sleep based debugging". You simply find the function for a sleep somewhere in the 00:25:01.266,00:25:08.173 firmware and you add a call to sleep - 1, 2, or 5 somewhere inside your exploit. If your 00:25:08.173,00:25:13.679 exploit took 5 seconds and then it crossed, you know you've reached your breakpoint. If the 00:25:13.679,00:25:19.051 code crashed, immediately, you didn't reach your breakpoint, this way you can debug your 00:25:19.051,00:25:24.623 exploit without having a debugger. Uh, it does mean that you actually use a watch and 00:25:24.623,00:25:30.629 time up your exploit every time. But, it's better than nothing, and this way you can distinguish 00:25:30.629,00:25:36.034 where did we reach thus far in the exploit? Uhm, you can hold the breakpoint around to check 00:25:36.034,00:25:40.005 where the exploit failed - usually it fails right at the start, but you can move it 00:25:40.005,00:25:45.010 around. And, usually, uh, embedded devices and your computer... Crash. They can show 00:25:50.149,00:25:53.452 you a notification when they crash,when you have a vulnerability in the windows 00:25:53.452,00:25:58.757 kernel for example, you will see a nice little bluescreen of death, which looked like this. 00:25:58.757,00:26:03.562 And in the embedded devices you'll see something similar. Uh, and up until now, I had 00:26:03.562,00:26:07.900 fetched results from last year and we have a screen for the printer and now we have a screen 00:26:07.900,00:26:13.739 folder and the camera itself. So, uh, it, it really does look the same. On an Office jet 00:26:13.739,00:26:19.378 printer you have screen, on the screen of the printer. And on the camera you have "Error 70". 00:26:19.378,00:26:23.782 Sometimes you get "error 80" - which, I don't know what does it mean, but "Error 70" is what you 00:26:23.782,00:26:29.321 usually get. And after you get the error you need to, uh, reboot the camera, sometimes it 00:26:29.321,00:26:35.928 means you have to plug off the battery and reinsert it. But, that's quite straightforward. 00:26:35.928,00:26:41.633 However, we didn't have enough luck in our research, for some reason the camera usually hangs 00:26:41.633,00:26:48.474 instead of crashing. And, this means if I sleep for 5 seconds, and the hang indefinitely, or 00:26:48.474,00:26:54.313 hang indefinitely, it look exactly the same. So, we can't see our breakpoint. Uh, it's not 00:26:54.313,00:26:59.918 really useful. [tick noise] And we want an, uh, alternative trace point that we actually can 00:26:59.918,00:27:05.657 see. At this point it's too, too complicated to print something to the screen and sleeping 00:27:05.657,00:27:12.130 doesn't work. The camera doesn't do any noise that I know of, so, we don't have a lot of options. 00:27:12.130,00:27:17.135 Uhm, I decided to change tactics and, uhm, use, use a different approach. Instead of sleeping, 00:27:20.038,00:27:25.711 call an address that always crashes. Uhm, but how do we find an address that always crashes? 00:27:25.711,00:27:31.149 We don't have a debugger. Uhm, turns out that when you jump to address "0" the camera hangs; 00:27:31.149,00:27:36.755 when you jump to address "1" the camera hangs, address "minus 1" the camera hangs. Uh, after a 00:27:36.755,00:27:42.828 few hours and a lot of guesswork we found this address. If you call this address the func, the 00:27:42.828,00:27:48.166 camera crashes. I don't know what's important in this specific address but it works. 00:27:48.166,00:27:53.171 So, now we're going to use this address as out breakpoint. Uhm, if we saw nothing, we hang 00:27:55.207,00:27:59.244 before breakpoint. And if we crashed it means we reached our breakpoint and that's it. And, 00:27:59.244,00:28:04.416 essentially, we're going to do this experiment. Coyote wants to get to the end of the tunnel, if 00:28:04.416,00:28:09.588 he crashed into the mountain. we got our breakpoint. If it stopped before the mountain we 00:28:09.588,00:28:14.693 stop before our breakpoint. So that's the experiment we're going to do time and time again 00:28:14.693,00:28:21.533 until we fix all of the bugs in our exploit and execute code over the camera. And it worked, 00:28:21.533,00:28:27.005 uhm, this blind crash-based debugging actually worked, we have a remote code execution. 00:28:27.005,00:28:32.644 Uh, time to, uh, use our debugger, boot it into the camera and study and the camera 00:28:32.644,00:28:39.184 and more intensively. Usually I allowed my own debugger called "Scout" to start dynamic reverse 00:28:39.184,00:28:44.189 engineering. And, up until now, if you remember, we use PTP over USB while Scout uses TCP - it's 00:28:47.693,00:28:52.698 a network-based debugger. And the TCP fails. It looks like we either have USB without network 00:28:55.601,00:29:02.341 or we have WiFi without USB. So, we can't have both USB and both WiFi on. So, even if we exploit 00:29:02.341,00:29:08.547 a vulnerability over the USB, Scout gets stuck inside. So, it can phone home back to us and we 00:29:08.547,00:29:15.520 can debug a camera. Uhm, we'll have to do something else. The camera already supports WiFi, 00:29:15.520,00:29:20.525 let's migrate our exploit to WiFi and hope it works, uh, this time. Initially we used a 00:29:26.231,00:29:31.036 project called "PTPy" Uh, you can find it on a GitHub link. It's a Python implementation for 00:29:31.036,00:29:36.074 the PTP protocol, uh, like any other open source, it didn't work out of the box but it was 00:29:36.074,00:29:41.079 better than nothing. Uh, when we reached the, uh, part of the PTP over IP for WiFi we turned out 00:29:43.315,00:29:48.787 that we haven't actually implemented this feature. We have an open issue about it for 00:29:48.787,00:29:54.126 3 years or 2 years or something. But we don't, we don't have it implemented. So, we read for the 00:29:54.126,00:29:59.431 specs, we implemented the, uh, the part needed for the WiFi and now we're, we're able to send 00:29:59.431,00:30:05.203 messages to our own camera over WiFi. Which wasn't quite stable because the WiFi for camera 00:30:05.203,00:30:11.309 isn't, is shakey to say the least. Uhm, but if you recall, we have a vulnerability in the 00:30:11.309,00:30:17.683 application layer in the PTP protocol. It's the same protocol over USB and over WiFi. So, the 00:30:17.683,00:30:22.688 same exploits creeped this time over WiFi should work, right? Uhm, no, uhm, earlier we 00:30:25.424,00:30:29.094 exploited a vulnerability in a Bluetooth-related command. Something about notifying the 00:30:29.094,00:30:34.599 camera about a Bluetooth connection and now it hangs instead of executing code. Uh, 00:30:34.599,00:30:41.239 we can't debug it because we don't have a debugger but essentially, uh, it looks like 00:30:41.239,00:30:47.646 the same mystery callback we saw earlier - it now hangs instead of simply working. And this is 00:30:47.646,00:30:52.951 because we assume that the WiFi system on cheap hangs when we're reminded it doesn't support 00:30:52.951,00:30:58.590 Bluetooth. When we used USB, Bluetooth was fine. But when we're using WiFi, it actually 00:30:58.590,00:31:03.995 sees "No, we don't have Bluetooth, I already have WiFi, that's it, simply hang and 00:31:03.995,00:31:09.000 that's all". So, we don't have a vulnerability, we don't have an exploit, uhm, time to think 00:31:11.703,00:31:18.110 again - find something, something new to actually exploit the camera. We need more 00:31:18.110,00:31:23.448 vulnerabilities, uhm, time to scan for, uh, additional vulnerabilities in the PTP 00:31:23.448,00:31:29.521 handlers. Ons the first scan we only identify, identified shallow bugs. Uhm, maybe we 00:31:29.521,00:31:35.660 missed something. ANd it turns out we did - we actually missed, uh, 2 vulnerabilities that are 00:31:35.660,00:31:40.499 quite similar and this is a snippet for these vulnerabilities. Initially we 00:31:40.499,00:31:45.403 get the inside of the packet, just as we did before and this time we check it against the 00:31:45.403,00:31:52.410 fixed, known size of the packet. For this case it's 100. If we send a packet which is longer or 00:31:52.410,00:31:57.415 shorter, uh, there will be an error log, uh, debug printer and then nothing. Because, we have 00:32:00.685,00:32:06.258 an error log and then "no return". So, if I send, if I send and large packet of 200 00:32:06.258,00:32:12.998 bytes, it's not 100 - we'll see an error log and then we'll use 200 to read bytes from my packet 00:32:12.998,00:32:19.070 to the local stock buffer and that's it. So, they know we're attacking them but then don't do 00:32:19.070,00:32:24.943 anything with it. So, I checked it up and it is indeed only a debug print - not an error that 00:32:24.943,00:32:30.415 crashes the camera. So, we once again have to, uh, stop this buffer overflows that we 00:32:30.415,00:32:37.022 actually know of but we haven't fixed. Okay, so, I'm not complaining, it works. Uh, I 00:32:37.022,00:32:42.928 adjusted all of the constants in the exploit script and now we have successfully exploited 00:32:42.928,00:32:49.201 remote code execution this time over WiFi. SO, we have 5 vulnerable PTP handlers - all of 00:32:49.201,00:32:54.773 our PoCs worked over USB but only 3 of them worked over WiFi. So, the next time someone says 00:32:54.773,00:32:59.945 to you "This vulnerability is exploitable" - it's not! You need to check it cause some 00:32:59.945,00:33:05.250 mystery call back will interfere with a PoC and only 3 or 4 vulnerabilities actually worked 00:33:05.250,00:33:10.255 over WiFi. So, always test everything before you say it's remote code execution. No that 00:33:12.324,00:33:17.963 we've demonstrated, uh, the code execution over USB and WiFi, ad the question rises - have we 00:33:17.963,00:33:22.968 finished? And, no. Our goal was ransomware and as attackers are profit-maximizers which is a 00:33:26.638,00:33:32.777 good term for "I'm being lazy", uhm, we want to implement ransomware but we don't want to 00:33:32.777,00:33:37.782 develop, uh, our own crypto for it. And, uh, you should really don't, uh, shouldn't implement 00:33:40.018,00:33:46.191 your own crypto and why should you? You can simply steal the crypto from someone else. Canon 00:33:46.191,00:33:52.197 already implemented crypto for their own firmware update. Something about AES, so, this 00:33:52.197,00:33:57.869 time we can use our own debugger, search these, uh, functions and hopefully we could 00:33:57.869,00:34:03.642 use, uh, Canon's own crypto functions for our, our ransomware. Time to look for 00:34:03.642,00:34:08.647 these functions. [drinking water] So, best scheme for the design of the firmware update, 00:34:18.189,00:34:24.129 uh, the firmware has 2 symmetric AES keys - being symmetric, meaning that it's probably not 00:34:24.129,00:34:29.901 the best firmware update but it works that, in a way that you have 1 key to verify the 00:34:29.901,00:34:36.107 firmware update but it could also be used to sign a new one. And what, uh, additional key the 00:34:36.107,00:34:41.846 crypto firmware update but you could also use it to encrypt your own file. And we use an 00:34:41.846,00:34:47.719 HMAC-based signature which is again, symmetric. When we search to, uh, through the crypto 00:34:47.719,00:34:53.525 functions, we actually found the keys in the firmware itself and what a huge jackpot! We can 00:34:53.525,00:34:58.830 actually use the keys we found to encrypt our own firmware update and simply send it to the 00:34:58.830,00:35:04.469 camera. So, let's see how it works, uh, when we looked upon the crypto functions, uh we saw 00:35:04.469,00:35:10.208 that Canon uses a proprietary key derivation that IDA can't even decompile. Uhm, we have 00:35:10.208,00:35:15.280 multiple different crypto functions, uh, which doesn't make a lot of sense. We can even 00:35:15.280,00:35:20.452 see in this main copy that actually lose some of the bytes of the hash recalculator because 00:35:20.452,00:35:27.058 the buffer isn't big enough. So, they copy only 12 bytes out of 20. And we simply lose 8 bytes 00:35:27.058,00:35:32.063 for some reason. Uhm, don't implement your own crypto. Uhm, the encryption is OFB type mode 00:35:34.366,00:35:39.504 of operation. And that's mainly because it looks like Output Feedback Block, it matches the 00:35:39.504,00:35:45.143 Wikipedia page of Output Feedback Block, but, when tested against Python's crypto library, 00:35:45.143,00:35:50.148 it doesn't work. Uhm, the AES block matches my calculation but the second block doesn't. Maybe 00:35:52.417,00:35:57.322 it's some problem with the [inaudible], I don't know. But at this phase, it really looked, 00:35:57.322,00:36:03.728 uh, wrong to simply implement it in Python. Uhm, too many proprietary calculations - IDA 00:36:03.728,00:36:09.501 can't even decompile it, uh, it's simply felt wrong to try to implement it. uh, on my 00:36:09.501,00:36:16.274 computer. So, instead, we chose a different approach. For our attack, we simply im, 00:36:16.274,00:36:21.246 implemented the Scout instruction that calculates the crypto. Uh, this means, instead 00:36:21.246,00:36:25.817 of understanding how the proprietary key derivation works, I simply told my debugger 00:36:25.817,00:36:31.056 to call their function, and that's it. So, I found the others in memory of, of the key 00:36:31.056,00:36:36.061 derivation function and told my debugger to execute this function and now I don't need to 00:36:36.061,00:36:42.467 implement it on my own. So, now the camera can, uh, my , uh, camera after I compromised it 00:36:42.467,00:36:46.604 can calculate for me the correct signatures, so, uh, we can think about something like, uh, 00:36:46.604,00:36:52.710 signature error code on our own camera. And after which I also implemented an additional 00:36:52.710,00:36:59.017 command to encrypt or decrypt the firmware update, so this was quite useful when we had to test 00:36:59.017,00:37:04.989 Canon's patch - because we could de, uh, decrypt newly updated firmware and test the, uh, 00:37:04.989,00:37:09.994 fixes. Which brings us to our tech, at home, using the already compromised camera, I can send a 00:37:12.363,00:37:18.369 user firmware update to the camera. The camera will decrypt it and now we have the plain 00:37:18.369,00:37:24.409 firmware on our computer. Now we can add any backdoor vulnerability feature we want to 00:37:24.409,00:37:29.814 this firmware to have our own malicious firmware and send it back to the camera. The camera 00:37:29.814,00:37:36.221 will encrypt it, sign it and now we have our own, legit, malicious firmware update. Which 00:37:36.221,00:37:42.060 brings us to the vulnerability itself. It turns out the PTP protocol has a command for 00:37:42.060,00:37:47.799 firmware update, so we can take the malicious firmware update, send it over WiFi to the target 00:37:47.799,00:37:53.438 camera and without any user interaction, we just took over the camera without any 00:37:53.438,00:37:59.244 vulnerability. And, it turns out we have no user interaction for, uh, firmware update for some 00:37:59.244,00:38:06.017 reason. So, we did it in a test with, uh, Magic Lantern's ROM dumper and we can see that we 00:38:06.017,00:38:11.222 now have checkpoint research ROM dumper, instead of Magic Lantern. So, we have our own 00:38:11.222,00:38:16.027 firmware update file, we can simply send it to the camera - no need for any vulnerability. 00:38:16.027,00:38:21.032 Uh, please don't use symmetric crypto for your firmware update. Time to connect the dots, uh, 00:38:23.168,00:38:27.238 once we're finished with the firmware update, we turn back to the ransomware. Uh, we 00:38:27.238,00:38:32.477 implemented the logic to encrypt all of the pictures using, uh, Canon's, uh, crypto functions so 00:38:32.477,00:38:38.449 now we read, uh, pictures from the SD card encrypt them and store them there. Uh, time for a 00:38:38.449,00:38:43.454 demo. So, here you can see my laptop and a camera without any cables. And then just to show 00:38:55.500,00:39:00.438 you, the camera works. Uh, so, we use the camera, we took some pictures, and we now have 3 00:39:02.473,00:39:07.478 images on our own camera. Now I exploit the vulnerabilities with SIM using exploit script. Uhm, 00:39:14.085,00:39:18.156 we need to wait a bit for some events and then we send out malicious payload to the camera. 00:39:20.458,00:39:24.362 We've just infected the camera and you can see blinks on the SD card meaning that we are now 00:39:24.362,00:39:29.601 encrypting the images and storing them to the SD card and after we finish, we actually 00:39:29.601,00:39:34.305 show the ransom message to the user. [background message] So, we've just installed our own 00:39:34.305,00:39:39.310 ransomware! [applause] And as we can now see, all of the images were encrypted and the camera 00:39:42.247,00:39:47.252 can't show them and playback. So, responsible disclosure - uh, we reported all of the 00:39:50.321,00:39:54.158 vulnerabilities to Canon and worked quite, uh, closely with the to, uh, patch all of the 00:39:54.158,00:40:00.231 vulnerabilities, uhm, Canon confirmed all of them rated as "high" or "critical" and, uh, 00:40:00.231,00:40:06.070 issued a patch. They have a secure advisory already on their website - you should really test 00:40:06.070,00:40:10.708 f you have a firmware update for your specific camera and download it. You can find all of 00:40:10.708,00:40:17.148 the, uh, details in our blogpost in this links - links also to cameras, uh, Canon's advisory in 00:40:17.148,00:40:23.521 Englsiha and in Japanese - any languages you want. Just as a side note - after we received a 00:40:23.521,00:40:30.194 patch we also tested with Magic Lantern's ROM dumper also works and it still works. So, please 00:40:30.194,00:40:35.566 don't ask me for the crypto keys, I deleted them from my computer if Canon will exchange 00:40:35.566,00:40:41.939 the keys with new pair Magic Lantern won't be able to sign, uh, uh, their version or the ROM 00:40:41.939,00:40:46.511 dumper. And I really don't want Magic Lantern to work harder extracting new keys, so I don't 00:40:46.511,00:40:51.349 no longer have my keys - so please don't send me any email about it. [laughter] 00:40:51.349,00:40:56.621 Conclusions, we found many vulnerabilities in the PTP implementation and one design 00:40:56.621,00:41:02.427 issue in the extension that Canon implemented for the firmware update. Uhm, they might 00:41:02.427,00:41:07.432 also apply for other vendors. They surely will apply for other, uh, DSLR models, uh, of 00:41:09.801,00:41:15.707 Canon, maybe mirrorless cameras as well. If your camera uses PTP to connect to something - to 00:41:15.707,00:41:20.311 your computer, your mobile phone - the vendor will need to check if it has similar 00:41:20.311,00:41:26.217 vulnerabilities and maybe issue an additional patch. The PTP protocol itself has no network 00:41:26.217,00:41:31.589 level protection so that's not a good idea. Uh, anyone can simply send messages and attack your 00:41:31.589,00:41:36.594 camera if you're not using WiFi turn it off. Uh, if you're not using Bluetooth, turn it off. 00:41:38.830,00:41:44.402 You don't want anyone, especially. [chuckle] In DefCon to connect, uh, to for the WiFi 00:41:44.402,00:41:50.508 to your camera and ransomware it. So, if you're not using something, turn it off. And, 00:41:50.508,00:41:54.612 just last note. Canon implemented proprietary key derivation for their crypto for 00:41:54.612,00:42:01.018 some unknown reason. Uh, it didn't get additional security and it didn't actually stop me, 00:42:01.018,00:42:06.290 uh, implementing anything. So, bypassing it was easy. We used our debugger to invoke their 00:42:06.290,00:42:11.429 function and that's it. So, I don't know how the [inaudible] works, but I bypassed it. So, 00:42:11.429,00:42:16.434 there's no actual reason to reimplement or invent your own crypto. It doesn't work. Last 00:42:18.936,00:42:25.109 slide, uh, I used a few tools, uh, which I developed and are already accessible on our GitHub 00:42:25.109,00:42:30.214 account. We had Karta - and IDA plug-in to match open sources and binaries and this time Canon 00:42:30.214,00:42:36.487 didn't use any open source. Uh, we had Thumbs Up to, uh, improve IDA's analysis which works quite 00:42:36.487,00:42:42.493 well even in my, uh, ongoing research and my embedded debugger that actually used - 00:42:42.493,00:42:47.899 Scout, you load it as your exploit shellcode into the camera, load your own debugger 00:42:47.899,00:42:53.571 and that's it - you can compile your C-code, execute it on your camera and decrypt th, uh, image 00:42:53.571,00:42:58.443 from Canon. So, all of it is accessible on our GitHub account, use them if you have 00:42:58.443,00:43:04.682 any questions. Send me an email, uh, please use these tools, don't do anything manually and 00:43:04.682,00:43:09.687 don't reinvent the wheel. That's it! Thank you for coming! [applause]