Well, I'll start again. So, my name is Alfredo Ortega. He is Oren Isakson. We're going to talk about exploiting digital cameras. There you go. So, we're going to talk about how to script digital cameras, basically. How we reverse this script. This will not be an exploitation at low level. This will be a high level exploitation. We actually are writing interpreted language present in almost all PowerShot digital cameras. We're going to talk about what we can do with this and what are the security consequences of it. Okay, let's start with the basics. Modern digital cameras, I'm sure you are aware, are, in fact, powerful computers. They almost all have an ARM processor and a lot of memory and they are really fast computers. We have a... The digital cameras that we are studying doesn't have a complete memory management unit. They have a memory protection unit. So, it really can run a secure operative system, but it runs an operative system nevertheless. Canon digital cameras use DryOS. It is an operative system built by Canon. And, well, that is about it. We have complete computers. Of course, we are not the first that... research into exploiting digital cameras. In fact, there is a huge project called CHDK that is... It has a few years already. And they are very, very incredible guys. They build custom firmware for Canon digital cameras. They enhance functionality. But this really can be used to attack a camera. Because we can see here... This is the main problem with this approach. For this modification to work, you must download a firmware modification inside the memory card. But the memory card must be locked before the firmware can be executed. So, this is not really a good way to exploit, to take over a digital camera. Because you have to physically access the memory card and switch the login. And also, there are other requirements like a special file system. It needs FAT16. Only working FAT16. So, this is a great modification. But really, it can be used to attack a camera. That is why this project is, in fact, very secure. We want to see if there is another way. So, we first tried to run our code, exploiting the image parsers inside the camera. This way, if we could find a bug in the image parsers, and write an exploit for it, we could take control of the camera as the user is trying to see an invalid message, an image in the camera's playback mode. The ARM processor jumps to the... an exception handler, when it tries to read or write an invalid memory address. So, what we did is write an exception handler to try to find the bugs, find bugs when passing the parsers. We did find some bugs. But before writing an exploit for them, or trying to write an exploit, we found another way that is better. The best thing about writing an exploit for the image parsers are that this is binary. And function offsets change from camera model to model. So, it would probably be very difficult to write an exploit that works in a lot of models. We found this other method, that is the interpreter, and the script, when we analyzed the film of one camera. We used AIDA Pro, and we can see a lot of interesting strings. These strings show that there is a plain text parser inside the camera. This parser is composed of two parsers, one is the JAG, that is yet another compiler compiler, and the other is FLEX, that is a lexical scanner. Well, we later found that, well, I was saying, we find this parser, and this parser are commonly found in interpreters and compilers. We assumed it was an interpreter as it makes more sense inside the camera. We later found we were not the first one to find this interpreter, but there is no public information on how to write a script for the cameras, or any information on the syntax or semantics of this language. And it is very difficult to just guess how to write a script for this language, because any error causes the camera to simply shut down, and there are no error messages that say why the script is invalid. So we found a world language activated inside every camera. So we have to reverse a complete language. That is a little difficult. What do we have? We have how to execute the language. We have what are the requirements that a memory card has to execute a script. They have a little file when the script is placed, and some tags inside the boot sector. But most importantly, it doesn't require anything more than that. It doesn't require the memory card to be locked. It doesn't require a special file system. So if you have a malware running in your computer, and you insert a memory card, this malware card injects code in your camera, because you only have to remove the memory card, insert in your camera without doing anything else, and it will execute. So I say, well, that is very useful. But we need a reverse interpreter. It's not an introduction on an algorithm, but a complete language. So let's start from the beginning. What are the structure of these interpreters? Well, it's a very standard interpreter. We have a grammatical parser here, a lexical parser. It's Lex and Jack. By the way, Lex was built with an idea of Donald Knuth, and, I'm sorry, Lex was built by Eric Schmidt, CEO of Google, and Jack was built by Donald Knuth. It's their software, open-source software, that have more than 30 years old. But they are like the standards of real interpreters. Basically, you have the script here, and the tokenizer, the Lex parser, will start reading character by character and produce tokens. These tokens can be while, print, variables, names. They are basically tokens for any language. They are a field to the grammatical parser, and the grammatical parser can either produce code, so you have a compiler, or interpret or execute functions, or execute a program, and you have an interpreter. That's all. In this case, of course, the camera inside has an interpreter, not a compiler. It would be very crazy. You have a compiler on your camera, but you have an interpreter. So this is the function that does the parsing. This is a very complex function. We have the string here is syntax error. The thing that we found, we see that this is an interpreter, in fact. Here we have a code of the lexical analyzer, and this little basic block here. We're going to start with trying to do what tokens made our language. We don't know even what language is, or any of the rules. This is a tokenizer. It's very complex, as you can see. In fact, it's a huge case. It's a case statement, the one for each token. And the tokenizer, in fact, is a table-based regular expression. Basically, it's a regular expression parser. That's why we really can't find the individual tokens in memory. The tokens are coded inside a huge table that this table is feed to a state machine, and the state machine recognizes tokens. So we couldn't find any tokens. You're looking at the film, or you're looking at the memory. We have to reverse the regular expression parser. Here is a portion of the parser. The parser is open source, so we know that we have the source code, but we don't have the tables. One idea that we have is to emulate this. In a computer, you just pick up the table from memory and emulate. There is not a single table. There is a lot of tables in a lex parser. In this diagram, we look in the memory here. This is a table, in fact. We implemented the table back to C code and just recompiled a standard lex parser and then brute-forced it. There it is. We're going to do a demonstration. We're going to run a demonstration of this brute-forcing process here. This, of course, is running in my laptop because only we stole the stock, sorry. We pick up the tables. Here it is. Yeah, we are brute-forcing every character. When you say success here, it's that a token was successfully parsed or accepted for the tokenizer. So every number is a valid token because numbers are tokens, too. Now we're going to start parsing the operators. This is our valid operator for this language. Letters are also valid tokens because we can do variables. And we have here, we have a token that is a function. Function is a valid token, too. So we have a function. We have if, which is a valid case. If with uppercase, lowercase. We have here sub. Sub is another token. We are accepting every token of this language. So we run this for a while. And we have this. We have a lot of tokens belong to this language. So maybe it's familiar to you. These are basic tokens. So this language is basic. Now we know that every camera have a basic interpreter inside. But we don't have the grammatical structure. It can be millions of variations of basics. So for that, we should build an emulator. Well, as Alfredo was saying, having the tokens was not enough. Even if we tried some basic scripts, very simple basic scripts, they appeared invalid. So we had to emulate the original firmware on an emulator. We use QEMU that has the capability to emulate an ARM processor, but can't emulate the whole camera. So we couldn't use it to boot the original firmware and try to parse a script with it. Instead what we did is capture the state of the machine, of the camera, as it was parsing a script that captures all the registers and all the memory, and dump it to the memory card. And then take that information and resume the execution inside our emulator. To do this, we couldn't just set a breakpoint inside an interpreter and take control, because we are not sure that that's even possible. We had to use the deception handlers. What we did is force the script interpreter to raise an exception as it was beginning to parse a script. We can see from the source code of the flex scanner that it tries to access an array, an array, with a value that is inside the static variable. And we change that value, and then as the processor tries to access that value, it crashed, and then we could dump all the state. To know which memory regions we need to dump, we just used the memory protection unit. Inside this unit, there are lot of, there are registers that define the valid memory regions. And we only need two regions, the my memory and the ROM. To control the execution of the emulator, we used the integrated GDB server. And also, the integration of GDB with Python. This way, we could write a Python script and control the execution from it. This Python script can set breakpoints, modify the registers, and control all aspects of the emulator. Well, we need to make some changes to the original firmware because we couldn't allow it to call the operating system because it wouldn't work. It would try to access some hardware registers that weren't emulated. So we changed it, the read function, so we could fit the emulator or script. And we did in a way that it read one character at a time. And this way, when the interpreter found an error, as it was parsing the script, we could find exactly at which point the error was found. Well, this is the general way that we found out about the syntax. We tried a script and found out the location of the error, and then we changed it until no error was found. These are three scripts. The last one is syntactically valid, but it doesn't do anything. This second slide shows that if you try to call a script a function outside the body of another function, that's an error. You can only call function from the body of other function. So this way, we realized that there must be one function that's the entry point. I'm going to show you now the emulator as it's running. The emulator is already running. I'm just going to run the Python script. You can see here in blue, the script that is about to be fit. The emulator reads all the scripts one character at a time, and finds out exactly where the error is found. In this case, var isn't defined. In this second demo, I'm going to show a valid script that has sent the entry point. So we arrive to a breakpoint that doesn't lead to code execution. This way, we later found about the entry point. This is the third demo that with the initialize function, that's the entry point. This script is totally valid, and we arrive to a breakpoint that shows that code is about to be executed. This is a complete valid script that brings hello world to the camera screen. You can see that there are a lot of predefined functions inside the camera. Alfredo is going to talk about it. At this time, we have the grammatical structure of the language, we have the tokens, but the language also has a lot of functions that we can call. In fact, this is wrong. There are 5,000 functions, sorry, 500, inside a common Canon camera, governing everything from the sensors, little motors, accelerometers, CCD, absolutely everything you can access from this language. In fact, you can access the main memory of the camera using poke and pick instructions, because it's basic, like, Commodore 64 Basic. We started to build a document and a user guide of this language. Here we are going to put it online after this. We are documenting all the functions. We don't have all, of course, because there are 500, but we have some of them. There are very interesting things about this language. For example, there are functions you read about the camera process memory, here. You can see this is the equivalent of the top Unix command inside a camera. So, how many process you think a camera can have? Well, you can have hundreds of, sorry, about 70, 70 process, processes inside a Canon camera. All these processes governing from the buttons to the display from the, for keeping the CCD warm. They are, it's a very complete operating system inside this camera. I'm going to publish this document in short so everybody can start building scripts. So, okay, well, we can do it with this language. Well, because it's difficult to do something with a camera, but you can do some stuff like we're going to show now. For example, you can the old school that we show at the beginning. Okay, here is I'm going to show this is the little school that we show at the beginning. This is not new, but this is. We're going to show this script in a lot of cameras it will work because it's basic. It's not accessing any low level system. Okay, you have, this is a cheaper camera. This is a 470 Canon. The first one was a G10, one of the high end cameras, but the script worked perfectly. Do you want to test in your camera, Oren? Well, it will work in every power shot camera. Let's see. Let's see if it will work. Show it. Okay, well, it worked perfectly. We don't have any special code to choose between cameras. It's the same code that works in every camera. Okay, so what else you can do? you can do with this script? Well, of course, we can make pictures appear. We can put fake pictures in the camera, for example. Well, just a minute, please. We're going to show a demonstration about where you can put any kind of image inside the camera, for example. We're going to erase every picture inside this memory card. Okay, it's ready. So, we're going to show that there is no picture in there. It's like a magic trick. There's no picture there, so we're going to launch the exploit. Okay, launch it. There is exploit deployed. And then we will turn on the camera again. We know there is a picture of General PerĂ³n there. Of course, this picture didn't exist before. We put it there, or just made a picture appear. So, this is not so dangerous until you start putting pictures of illegal people. It's about, maybe you have her. This exploit is very new. It's the linking exploit that was made public just a week ago. I have a SD without the files that exploit this for the camera that will launch this exploit. Okay, let's try. We don't have space for the USBs here. First, we're going to show the memory card. Nothing happened here. But this is the script. You can see it here. This is the script that launched the link exploit. It just creates a lot of links inside the memory card. We're going to run this exploit in any camera. In fact, it can be any one. We're going to launch this one. This one is the cheapest. Let's see if this works, because if it doesn't work, have a video, so you can believe us. You say exploit ready, and then you just remote the memory card. You see it is working. working, because we never tested this, really. And, whoops. Oh, well. Code execution. Well, this is the foremost link exploit that you execute when you see a memory card, it used for a, I'm sorry. Yeah, sorry. This wasn't supposed to be this way, because we forgot to reset the explorer process. The problem with this is that once we showed the empty memory card, the file will be execute code like this one, like this showing here. Of course, you can execute any kind of code. And, well, that's quantum measures. It's about quantum measures. We had, you know, So, if there are not of this files in your memory card, you are safe from this. Canon cameras use picture transfer protocol. So, you can get infected through the USB cable. But the one thing is that no antivirus can scan the whole memory card when it's connected by the USB cable . That's all. We have a language that we found inside every power shot camera. We documented it. We're going to put it online. So, if you have a digital camera, now you have a general purpose computer that you can use to program in basic, we're running every power shot camera that we test. So, that's it. Thank you very much.