Good afternoon everyone. My name is Damián Gómez. I'm from Argentina. I've been working at Immunity for almost two years. As a security researcher, I focus on vulnerability analysis and exploit development. I'm the leader project of the Visual Exploit framework. Among my current projects, I'm the main developer of Immunity Debugger, which is the subject of this talk. Well, anyone who has ever called an exploit will tell you that 90% of their development time was spent inside a debugger. Like with all the software engineering that exists today, the actual language implementation is somewhat irrelevant. Let's say, as soon as you can craft a string, it's more likely you're going to be able to call an exploit. Immunity last year introduced a visual algorithm. It's a graphical language for exploit development called Visual Exploit, which was based in the concept of drag-and-dropping exploit components from a toolbar to a panel and having, as a result, a readable exploit. So, you can see, the programming language is not something that will matter at the end, since an exploit is merely a solution to a problem that was solved using your debugger of choice. A problem that requires intelligent understanding of code. You can use the concepts like input-cafting of heap analysis memory manipulation. Let's say, inside a debugger, you should be able to get the first abstract approach of your bug and the last concrete goal, the shellcode execution. So, what do we want from a debugger? For a vulnerability development debugging framework. We want a specific framework. simple understandable interface. And we want to be able to script things, so we want a powerful scripting language in it. And we want it to be fast. Unfortunately, there is no perfect interface model for every project development situation. But there are some characteristics that will help us achieve what we want. And those are a GUI, a common line, and a scripting language. So why a GUI? The graphical interface will make us fail. Like, it will be easy to have a visualization of the CPU context or the stack. Let's say it's easy to see where EAX points. And a graphical interface is faster to learn for complex commands. You just don't have to learn the complex commands, but you click them. But it has a downside, and it's the slower usage than the common line. And that's why we love the common line. The common line is a faster way to interact with the debugger. But let's say there are some complex commands that will be hard to learn. And you have to remember, at least you are a full-time debugger user, so you have to be checking the manual every time you want to type these complex commands. And we don't like this. And the last thing we are looking at in this kind of debugger is the scripting language. But forget about those old, awkward scripting languages for debugging. We want a real scripting language. And Immunity Debugger has Python, like the scripting language. Python is familiar and easy to learn. I mean, it's really easy. So this characteristics will...sorry. At Immunity with Immunity Debugger integrates these three characteristics in his own vulnerability development exploit-oriented debugger. We have been using Immunity debugger for some time at Immunity, and we have great results during our testing. There is a screenshot of Immunity debugger session, which you can see there is a Python command, a Python command at the command bar dumping the heap in a custom log window right in the upper side of the screenshot. The Immunity debugger API, the Immunity debugger API is simple. It runs like cached structures to speed up the experience. That means it's pretty useful. For example, if you want to speed up the experience, you can speed up the experience by using the default searching functions when you're doing some memory deep searches. It's good to have some cache of them. The Immunity debugger API, it can not only perform debugging tasks, but it can also interact with the current GUI. You will have all the debugging tasks, like step and execution, assembly, disassembly, but also you'll be able to control the GUI. There is something extra to say that is keep in mind that when you are running a PyCommand, the information will generate runtime, so every script run is ephemeral. But how deep can we dive with the API? We can do mostly everything. For example, we can do assembly and disassembly methods and breakpoints of reading and writing and memory searching, execution and step analysis with it. As I said before, interacting with the GUI. What offers that to us? Well, creating new custom windows for displaying your data or tables, dialog boxes, input boxes, combo boxes. There is a script, a script that has a that will guide you through the execution of the script. But the best way to show how interaction with the GUI is possible is with the Python orthogonal grapher. The Python grapher is a graphic library that we can use. It will make a graph of the function, an orthogonal representation of it, and is entirely coded with the immunity divider API. Well, among immunity divider methods, we can read and write into memory, like when you're calling an exploit, it's more likely you're going to be manipulating memory all the time. So, there are a lot of methods for reading and writing. So, there are a lot of methods for reading and writing, like when you're calling an exploit, it's more likely you're going to be manipulating memory. And something else you will be doing while developing an exploit is searching. Searching for patterns in memory. So the immunity divider API has a lot of searching methods, like the simple search, which will search in memory, or, for example, searching commands. Commands are searching commands which... I don't know. You can, for example, search regular expressions with it. And if you want a deeper search, you can even use the assembled method. You can assemble a command, and then search it in memory. Okay, getting code across reference from data and code. It's also possible from the immunity divider library. Okay. And this is the immunity divider knowledge. As I said before, when you run a script inside the immunity divider, that script is run and lost in there. So there is a way to save into immunity divider memory the information of that script. The add knowledge method will do it. Like, for example, you have... You can save this view context. Inside a Python object. And save it into the immunity divider session with the add knowledge. So you can get that view context later with the add knowledge methods. There are three ways to script immunity divider. The PyCommands, the PyHooks, and PyScripts. I'm going to talk about the first two ones in this talk. Okay. Okay. Okay. Okay. Okay. All right. PY Commons are Python scripts. It will help you the creation they develop in time. These scripts are no-catching, so that means you can run, modify in a script, and re-run it without the need to restart the divider, so that's pretty useful. The Python commands are accessible by a command box. Or from the wii. And you can integrate the Python commands to the divider features. Writing a Python command is easy, you just have to create a file, import the library, and define a main function where you can instantiate the API and start using it. Then you just place that file into the PyCommons directory and you're ready to go. PyHooks. Hooks are objects that hang on the various events like access violation or breakpoint or post analysis hooks, etc. The good thing of hooking is that you can hook that event and place in the community browser session memory some code that will be executed when that event is executed. So you can create a hook on an access violation to save the CPU context at this right moment and will be executed when the access violation happens. Creating a hook is easy also. It's almost like creating a Python command with the difference that you have to define a RAM function that is the one that will be executed when the hook type happens. This RAM function will receive the CPU context as argument just to avoid thread problems, since hook is very related to thread. There is some easy way to identify a common vulnerability primitive with hooking. Let's see an example. For example, this stream and copy where the size argument, is the same as the size, the exact size of the source argument. Just with minor modifications of this script, you can find primitives in other functions. So let's see this example of hook. First of all, we start integrating the debugger clause and we're setting a breakpoint in the stream and copy function. Then we're creating our hook and adding to the immunity debugger memory. And inside our class, our hook class, we define the run. Well, when we set the leave and base it on the CPU context we receive it, we are going to read the arguments that are passed to the stream and copy function. Once we have all the arguments, we're going to ask if the length of the read argument is the same as the size argument. In that case, we are going to get the call stack and log it. This screenshot of the script running takes how the call stack is logged at the source, when the source argument is the same length as the size argument. There is another type of hooking, which is inject hooking. The inject hookings are a long hook. They are much faster since it doesn't use the debugger. You can inject assembly code directly in the function. And it's redirected to your code. The information is logged in the same memory base. So it's pretty much faster. The heap analysis tool, uses the future. However, injection hooking has some drawbacks. Since now, you can only report the results and cannot do conditions with it. In this example, we are creating this inject hooking, and we are using the add knowledge method to save the information into the debugger memory. And later, with another script, we are using the get knowledge method to get that fast hooking, and logging the result we have while debugging. There is another thing included in the debugger, and that is the heap lives. Since heap analysis is one of the most important tasks for exploit development, we have included a set of lives to help for that. These lives allow us to print the state of memory, or examine the heap, or saving our story in the heap. For example, we can get all the current heaps, or we can get a single object heap, since when you are doing some exploit development, you may want to focus just in one single heap, where you can get from this single heap, the free list, or the free list in use. And in the same way, you can get the chunks of every heap, or from a single heap object. And again, these chunks are objects itself, which has a lot of information in it. Easy to access information. You can search inside chunks. Like... Okay, you can search inside chunks. And you can specify, if you want, like, an optional heap argument, to filter by heap, the search. There is another libraries, the data type discovery libraries, which help you find types of data in memory. That's pretty useful when calling an exploit, to know where and what is in memory. For example, you can go and do a discovery of memory. Of what? Of a pointer. And that will return an object. And you can ask in that object if it's a function pointer, or a normal pointer, a data pointer, a stack pointer, and so on. Oh, there is a simple... Well, this slide should talk by itself. We have Hibby, Stack Hibby, trying to use PyCommons and PyHooks, which use the Python app, to analyze false search discover, and most important, understand what is going on inside the debugger, to create an exploit. During the past month, a new team has been calling some script that was helping us while developing exploits. These scripts include vulnerability analysis, Hibs, protocols, search infinity, and compiling memory. There are some examples of scripts created. For example, safe-c, that we showed you in a custom window. All the exception handlers in the process that are registered with safe-c. We find anti-DIP script, which will find an address to bypass software DIP. This script was used in one of immunity training, and that's why it has a wizard on it, where the first combo box asks for the first address. Then you have an input box for inserting the assembly code to search. And lastly, you have another combo box that will search for the third return address. And you can see the lower screen that shows a buffer that will help you bypass the IP. There is another script that will find memory leaks in a function. It's a hook. It will hook a function. Then you will be passing that function, and you will be getting the leaks. Check the red line where a memory leak is detected in that function, which was hooked by lexniff. Finding data types in memory is another script that will help discover what kind of data is inside the memory. Users have to specify an address and decide to read. And in the log window will appear what kind of data they discovered in the phone. And the heap, by command. With the heap code by command, you can make analysis of the heap and dump it and check what's inside, like the screenshot shows. For example, check the double link of leads that the heap, by command, found. There is another script, the chunk analyze, that is another hook, where you specify the address of the red node, and you run the hack. You place it into memory, and you start fuzzing. If you check the log window, you will be able, one of your fuzzing is overwriting a function pointer of a double linked list. The getRPC will access to RPC information, and will give function pointers to every RPC call. The duality script, the duality script will look at memory pages, and others that can be transformed into opcodes. This duality script will be described more later in the talk. In the case story I have prepared. The mod pointer script, this tool will do some data recognition, looking for function pointers, and it will overwrite them, waiting for an access violation of one of these pointers overwriting, and when the access violation occurs, it will trigger the hook, and will start logging in for the analysis. And the search script, the search script is a simple script that will search for cryptographic routines in a given branch. Look at this screenshot how a lot of different algorithm was found in a library. We have a case study here. It's a simple stack overflow in savant web server. When you send along get request to it, it will crash with a stack overflow. However, there are some details in it. For example, when you send along buffer, the stack, some stack arguments overwriting won't allow us to reach EIP. Check the screenshot lines, it's showing how an argument, a readable address, is overwriting, and getting an access violation when writing this address. So, we need to find a readable address to place as the argument there in the right offset. Once we find this, which is pretty easy, we'll be facing the second argument problem. A readable address. That's almost as easy as the first one. We just need to find a readable address. So, replacing to keep EIP, we need a readable address, that readable address, and the argument offset in our screen thing. Finding the offset should be easy, so, when we got that addresses and the offset, we can craft a buffer. That, if, if the others we found are right, we'll be able to hit EIP, like the screenshot shows, without any problem. So, once we hit EIP, in detail we have control over EVP value, AP value, what ESP point two, which is one of the arguments, and what ESP plus four point two, which is the other arguments. And we have more of, of 200 bytes of a controlled buffer. This, there is the context, I was talking right, right here. And the first thing, I could think of, with this context, is jumping back. But how? And that's the second problem. Check, where, what ESP is pointing to. Since we, since we are controlling what ESP points to, what if we couldn't find an address, to place, to place, as the overwriting argument, which, first of all, needs to be writeable, because of the first problem. And second, it can be transformed into opcodes, that would be of use here. Like, let's say a jump back, to land into our control buffer. But finding an address, with these characteristics, must, might be pretty tedious, and pretty hard. So, there is a script, with immunity valid, that we talked, some minutes ago, that would help here. The duality script. The duality script is easy, to use. You just have to, place, the common argument, to the script, you are looking for. And how duality works? Well, it creates a mask, of the search code. In this case, a jump, minus 10. And we'll get, all the memory pages. And, we'll try to find addresses, that match our masked search codes. As we can see in the screenshot, the log result, there is a, an address, marked with a red line, that may, may be of use here. So, before finishing, crafting our, string, with a brand new, address, transformable address, we'll need to find, a jump ESP, for a, for a, AIP. The search code script, will do that, really fast. You just have to, write search code, and the command, you are willing to search. So, resuming. You have, we have, bypassed the arguments problem. We have hit, AIP. We have searched, for a writeable address, that can be transformed, into an opcode. And we have searched, for a jump ESP. And, we have crafted, the string. So, if everything, goes well, we'll be able, we'll be having, our int, int three. Check the, the, the right, the right red box, where, ESP is, which is pointing, to an address, that, in the disassembly, window, is transformed, to a short, jump. Back, to run, into our, controlled, buffer. Okay. Now, I'm going to, some, immunity debugger, demo. Hmm. Hard to, check. Okay. Now, immunity debugger, demo. Okay. Let's go, for the, conclusion, then. So, immunity debugger, won't give you, an, another, of the, box, exploit. But, it will, speed up, the time, debugging. Because, of the GUI, the graphical interface, and the command line. And, it will help you, finding the bug, with the, API, and the libraries, and the immunity, and the immunity, scripts, that are provided, with, with, immunity debugger. And, will help you, crafting, crafting, your exploit. Making it, more, reliable. We have been using, immunity debugger, for months, while, we were, with, good results. And, some things, that are, inside my head, right now, is an, API server, to connect, the immunity debugger, to visual exploit, canvas, or fuzzers, or whichever, application, that could be, of use, when, doing some, vulnerability, development. More, graphing stuff, like, interaction, with the graphs. So, we can manage, the vertices, and, move, them around, and, even clicking them, to modify the assemble, and so on. And, also, a lot of, comments, that comes, every day, when we need it, we call them. And, your script, yeah, that's something, I was thinking, thinking about also. Immunity debugger, is pretty curious, about what you can do, what you can do, with immunity debugger, API. So, we have launched, a little contest, for the most useful script, where the first prize, will be a silica unit. I think, it's up to, October 10th, or something like that. So, if you're willing, to call some script, of use, just drop me a, drop me a line, later. You can download, immunity debugger, get it free, and, comment, script, idea, request, please email me. I'm willing, to answer, any questions, any questions, you might have. But, I think, that's in the question, and answer room. So, that's it. Okay.