1 00:00:00,000 --> 00:00:07,800 Good afternoon everyone. My name is Damián Gómez. I'm from Argentina. I've been working at Immunity for almost two years. 2 00:00:08,280 --> 00:00:13,720 As a security researcher, I focus on vulnerability analysis and exploit development. 3 00:00:14,340 --> 00:00:19,000 I'm the leader project of the Visual Exploit framework. 4 00:00:20,840 --> 00:00:28,500 Among my current projects, I'm the main developer of Immunity Debugger, which is the subject of this talk. 5 00:00:30,460 --> 00:00:38,160 Well, anyone who has ever called an exploit will tell you that 90% of their development time was spent inside a debugger. 6 00:00:38,580 --> 00:00:44,860 Like with all the software engineering that exists today, the actual language implementation is somewhat irrelevant. 7 00:00:46,320 --> 00:00:52,100 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. 8 00:00:54,320 --> 00:00:58,380 Immunity last year introduced a visual algorithm. 9 00:00:58,500 --> 00:01:10,320 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. 10 00:01:11,860 --> 00:01:24,880 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. 11 00:01:25,360 --> 00:01:28,480 A problem that requires intelligent understanding of code. 12 00:01:28,500 --> 00:01:32,940 You can use the concepts like input-cafting of heap analysis memory manipulation. 13 00:01:38,460 --> 00:01:47,100 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. 14 00:01:47,620 --> 00:01:50,220 So, what do we want from a debugger? 15 00:01:50,420 --> 00:01:56,380 For a vulnerability development debugging framework. 16 00:01:57,060 --> 00:01:58,480 We want a specific framework. 17 00:01:58,480 --> 00:02:06,240 simple understandable interface. And we want to be able to script things, so we want a 18 00:02:06,240 --> 00:02:13,340 powerful scripting language in it. And we want it to be fast. Unfortunately, there is 19 00:02:13,340 --> 00:02:22,300 no perfect interface model for every project development situation. But there are some 20 00:02:22,300 --> 00:02:28,580 characteristics that will help us achieve what we want. And those are a GUI, a common 21 00:02:28,580 --> 00:02:30,240 line, and a scripting language. 22 00:02:32,480 --> 00:02:42,900 So why a GUI? The graphical interface will make us fail. Like, it will be easy to have 23 00:02:43,900 --> 00:02:51,120 a visualization of the CPU context or the stack. Let's say it's easy to see where EAX 24 00:02:51,120 --> 00:02:51,660 points. 25 00:02:54,200 --> 00:03:01,500 And a graphical interface is faster to learn for complex commands. You just don't have 26 00:03:01,500 --> 00:03:08,020 to learn the complex commands, but you click them. But it has a downside, and it's the 27 00:03:08,020 --> 00:03:14,060 slower usage than the common line. And that's why we love the common line. The common line 28 00:03:14,060 --> 00:03:20,660 is a faster way to interact with the debugger. But let's say there are some complex commands 29 00:03:20,660 --> 00:03:22,280 that will be hard to learn. 30 00:03:22,280 --> 00:03:28,740 And you have to remember, at least you are a full-time debugger user, so you have to 31 00:03:29,380 --> 00:03:34,320 be checking the manual every time you want to type these complex commands. And we don't 32 00:03:34,320 --> 00:03:34,860 like this. 33 00:03:36,700 --> 00:03:43,880 And the last thing we are looking at in this kind of debugger is the scripting language. 34 00:03:44,300 --> 00:03:50,960 But forget about those old, awkward scripting languages for debugging. We want a real scripting 35 00:03:50,960 --> 00:03:59,420 language. And Immunity Debugger has Python, like the scripting language. Python is familiar 36 00:03:59,420 --> 00:04:09,640 and easy to learn. I mean, it's really easy. So this characteristics will...sorry. At Immunity 37 00:04:09,640 --> 00:04:16,020 with Immunity Debugger integrates these three characteristics in his own vulnerability 38 00:04:16,020 --> 00:04:18,820 development exploit-oriented debugger. 39 00:04:19,960 --> 00:04:27,380 We have been using Immunity debugger for some time at Immunity, and we have great results 40 00:04:28,220 --> 00:04:29,780 during our testing. 41 00:04:32,420 --> 00:04:38,560 There is a screenshot of Immunity debugger session, which you can see there is a Python 42 00:04:38,560 --> 00:04:46,320 command, a Python command at the command bar dumping the heap in a custom log window right 43 00:04:46,320 --> 00:04:49,660 in the upper side of the screenshot. 44 00:04:51,300 --> 00:04:56,260 The Immunity debugger API, the Immunity debugger API is simple. 45 00:04:58,440 --> 00:05:04,400 It runs like cached structures to speed up the experience. 46 00:05:04,700 --> 00:05:07,780 That means it's pretty useful. 47 00:05:07,940 --> 00:05:08,540 For example, if you want to speed up the experience, you can speed up the experience by using the 48 00:05:08,560 --> 00:05:12,420 default searching functions when you're doing some memory deep searches. 49 00:05:12,980 --> 00:05:15,700 It's good to have some cache of them. 50 00:05:17,300 --> 00:05:24,160 The Immunity debugger API, it can not only perform debugging tasks, but it can also interact 51 00:05:24,160 --> 00:05:25,240 with the current GUI. 52 00:05:25,740 --> 00:05:31,900 You will have all the debugging tasks, like step and execution, assembly, disassembly, 53 00:05:31,920 --> 00:05:36,800 but also you'll be able to control the GUI. 54 00:05:37,660 --> 00:05:43,740 There is something extra to say that is keep in mind that when you are running a PyCommand, 55 00:05:45,980 --> 00:05:53,080 the information will generate runtime, so every script run is ephemeral. 56 00:05:54,560 --> 00:05:58,120 But how deep can we dive with the API? 57 00:05:59,560 --> 00:06:02,600 We can do mostly everything. 58 00:06:05,560 --> 00:06:10,940 For example, we can do assembly and disassembly methods and breakpoints of reading and writing 59 00:06:10,940 --> 00:06:15,200 and memory searching, execution and step analysis with it. 60 00:06:18,900 --> 00:06:21,620 As I said before, interacting with the GUI. 61 00:06:22,220 --> 00:06:24,220 What offers that to us? 62 00:06:24,480 --> 00:06:31,160 Well, creating new custom windows for displaying your data or tables, dialog boxes, input 63 00:06:31,160 --> 00:06:32,340 boxes, combo boxes. 64 00:06:32,340 --> 00:06:43,200 There is a script, a script that has a that will guide you through the execution 65 00:06:43,200 --> 00:06:43,860 of the script. 66 00:06:46,920 --> 00:06:55,380 But the best way to show how interaction with the GUI is possible is with the Python 67 00:06:55,380 --> 00:06:56,340 orthogonal grapher. 68 00:06:56,540 --> 00:07:02,320 The Python grapher is a graphic library that we can use. 69 00:07:02,320 --> 00:07:08,920 It will make a graph of the function, an orthogonal representation of it, and is entirely 70 00:07:08,920 --> 00:07:11,160 coded with the immunity divider API. 71 00:07:14,320 --> 00:07:22,740 Well, among immunity divider methods, we can read and write into memory, like when 72 00:07:22,740 --> 00:07:28,320 you're calling an exploit, it's more likely you're going to be manipulating memory all 73 00:07:28,320 --> 00:07:28,680 the time. 74 00:07:28,840 --> 00:07:31,800 So, there are a lot of methods for reading and writing. 75 00:07:31,800 --> 00:07:32,300 So, there are a lot of methods for reading and writing, like when you're calling an exploit, 76 00:07:32,300 --> 00:07:32,540 it's more likely you're going to be manipulating memory. 77 00:07:33,820 --> 00:07:38,980 And something else you will be doing while developing an exploit is searching. 78 00:07:39,040 --> 00:07:40,840 Searching for patterns in memory. 79 00:07:41,060 --> 00:07:50,560 So the immunity divider API has a lot of searching methods, like the simple search, which will 80 00:07:50,560 --> 00:07:56,160 search in memory, or, for example, searching commands. 81 00:07:56,780 --> 00:08:01,220 Commands are searching commands which... 82 00:08:01,220 --> 00:08:02,280 I don't know. 83 00:08:02,300 --> 00:08:06,880 You can, for example, search regular expressions with it. 84 00:08:09,380 --> 00:08:14,700 And if you want a deeper search, you can even use the assembled method. 85 00:08:15,080 --> 00:08:18,620 You can assemble a command, and then search it in memory. 86 00:08:24,540 --> 00:08:28,800 Okay, getting code across reference from data and code. 87 00:08:29,060 --> 00:08:31,400 It's also possible from the immunity divider library. 88 00:08:31,680 --> 00:08:32,280 Okay. 89 00:08:34,340 --> 00:08:37,160 And this is the immunity divider knowledge. 90 00:08:37,780 --> 00:08:46,400 As I said before, when you run a script inside the immunity divider, that script is run and 91 00:08:46,400 --> 00:08:47,500 lost in there. 92 00:08:47,640 --> 00:08:54,740 So there is a way to save into immunity divider memory the information of that script. 93 00:08:55,140 --> 00:08:57,120 The add knowledge method will do it. 94 00:08:57,500 --> 00:08:59,840 Like, for example, you have... 95 00:08:59,840 --> 00:09:01,920 You can save this view context. 96 00:09:01,920 --> 00:09:03,600 Inside a Python object. 97 00:09:03,840 --> 00:09:07,480 And save it into the immunity divider session with the add knowledge. 98 00:09:08,160 --> 00:09:13,840 So you can get that view context later with the add knowledge methods. 99 00:09:15,280 --> 00:09:18,420 There are three ways to script immunity divider. 100 00:09:18,580 --> 00:09:22,440 The PyCommands, the PyHooks, and PyScripts. 101 00:09:23,100 --> 00:09:27,460 I'm going to talk about the first two ones in this talk. 102 00:09:28,700 --> 00:09:29,340 Okay. 103 00:09:29,800 --> 00:09:30,040 Okay. 104 00:09:30,340 --> 00:09:30,980 Okay. 105 00:09:31,260 --> 00:09:31,900 Okay. 106 00:09:31,900 --> 00:09:31,980 Okay. 107 00:09:32,240 --> 00:09:32,440 All right. 108 00:09:32,440 --> 00:09:33,620 PY Commons are Python scripts. 109 00:09:34,220 --> 00:09:37,680 It will help you the creation they develop in time. 110 00:09:38,420 --> 00:09:46,020 These scripts are no-catching, so that means you can run, modify in a script, and re-run 111 00:09:46,020 --> 00:09:49,860 it without the need to restart the divider, so that's pretty useful. 112 00:09:51,180 --> 00:09:54,960 The Python commands are accessible by a command box. 113 00:09:55,100 --> 00:09:56,100 Or from the wii. 114 00:09:57,580 --> 00:10:01,080 And you can integrate the Python commands to the divider features. 115 00:10:02,940 --> 00:10:08,380 Writing a Python command is easy, you just have to create a file, import the library, 116 00:10:08,700 --> 00:10:16,220 and define a main function where you can instantiate the API and start using it. 117 00:10:16,520 --> 00:10:21,080 Then you just place that file into the PyCommons directory and you're ready to go. 118 00:10:23,900 --> 00:10:32,640 PyHooks. Hooks are objects that hang on the various events like access violation or breakpoint 119 00:10:32,640 --> 00:10:45,000 or post analysis hooks, etc. The good thing of hooking is that you can hook that event 120 00:10:45,000 --> 00:10:50,460 and place in the community browser session memory some code that will be executed when 121 00:10:50,460 --> 00:10:51,060 that event is executed. 122 00:10:51,080 --> 00:10:59,900 So you can create a hook on an access violation to save the CPU context at this right moment 123 00:10:59,900 --> 00:11:04,360 and will be executed when the access violation happens. 124 00:11:06,660 --> 00:11:12,860 Creating a hook is easy also. It's almost like creating a Python command with the difference 125 00:11:12,860 --> 00:11:19,840 that you have to define a RAM function that is the one that will be executed when the hook type 126 00:11:19,840 --> 00:11:20,240 happens. 127 00:11:21,080 --> 00:11:28,800 This RAM function will receive the CPU context as argument just to avoid thread problems, 128 00:11:30,160 --> 00:11:33,660 since hook is very related to thread. 129 00:11:37,840 --> 00:11:44,160 There is some easy way to identify a common vulnerability primitive with hooking. 130 00:11:44,400 --> 00:11:45,780 Let's see an example. 131 00:11:45,960 --> 00:11:50,440 For example, this stream and copy where the size argument, 132 00:11:50,440 --> 00:11:56,780 is the same as the size, the exact size of the source argument. 133 00:11:57,620 --> 00:12:05,020 Just with minor modifications of this script, you can find primitives in other functions. 134 00:12:05,460 --> 00:12:08,160 So let's see this example of hook. 135 00:12:09,460 --> 00:12:18,460 First of all, we start integrating the debugger clause and we're setting a breakpoint in the 136 00:12:18,460 --> 00:12:19,720 stream and copy function. 137 00:12:19,720 --> 00:12:25,400 Then we're creating our hook and adding to the immunity debugger memory. 138 00:12:27,860 --> 00:12:33,300 And inside our class, our hook class, we define the run. 139 00:12:33,660 --> 00:12:38,160 Well, when we set the leave and base it on the CPU context we receive it, 140 00:12:38,320 --> 00:12:43,520 we are going to read the arguments that are passed to the stream and copy function. 141 00:12:44,420 --> 00:12:48,680 Once we have all the arguments, we're going to ask 142 00:12:48,680 --> 00:12:54,580 if the length of the read argument is the same as the size argument. 143 00:12:54,900 --> 00:13:01,940 In that case, we are going to get the call stack and log it. 144 00:13:04,460 --> 00:13:10,520 This screenshot of the script running takes how the call stack is logged at the source, 145 00:13:11,440 --> 00:13:16,220 when the source argument is the same length as the size argument. 146 00:13:18,860 --> 00:13:22,300 There is another type of hooking, which is inject hooking. 147 00:13:22,760 --> 00:13:25,380 The inject hookings are a long hook. 148 00:13:25,620 --> 00:13:29,240 They are much faster since it doesn't use the debugger. 149 00:13:29,480 --> 00:13:32,560 You can inject assembly code directly in the function. 150 00:13:33,420 --> 00:13:36,020 And it's redirected to your code. 151 00:13:36,580 --> 00:13:38,940 The information is logged in the same memory base. 152 00:13:39,160 --> 00:13:43,480 So it's pretty much faster. 153 00:13:44,860 --> 00:13:46,920 The heap analysis tool, 154 00:13:46,920 --> 00:13:49,040 uses the future. 155 00:13:49,700 --> 00:13:52,940 However, injection hooking has some drawbacks. 156 00:13:54,660 --> 00:14:00,060 Since now, you can only report the results and cannot do conditions with it. 157 00:14:01,560 --> 00:14:05,400 In this example, we are creating this inject hooking, 158 00:14:05,600 --> 00:14:11,240 and we are using the add knowledge method to save the information into the debugger memory. 159 00:14:11,680 --> 00:14:15,920 And later, with another script, we are using the get knowledge method 160 00:14:15,920 --> 00:14:18,180 to get that fast hooking, 161 00:14:18,320 --> 00:14:20,800 and logging the result we have while debugging. 162 00:14:23,260 --> 00:14:26,240 There is another thing included in the debugger, 163 00:14:26,240 --> 00:14:28,400 and that is the heap lives. 164 00:14:28,720 --> 00:14:33,240 Since heap analysis is one of the most important tasks for exploit development, 165 00:14:34,460 --> 00:14:38,340 we have included a set of lives to help for that. 166 00:14:39,700 --> 00:14:42,160 These lives allow us to print the state of memory, 167 00:14:42,340 --> 00:14:43,620 or examine the heap, 168 00:14:43,860 --> 00:14:45,840 or saving our story in the heap. 169 00:14:48,480 --> 00:14:51,460 For example, we can get all the current heaps, 170 00:14:51,620 --> 00:14:53,780 or we can get a single object heap, 171 00:14:53,920 --> 00:14:59,260 since when you are doing some exploit development, 172 00:14:59,780 --> 00:15:02,720 you may want to focus just in one single heap, 173 00:15:02,900 --> 00:15:05,640 where you can get from this single heap, 174 00:15:06,560 --> 00:15:08,760 the free list, or the free list in use. 175 00:15:09,880 --> 00:15:14,660 And in the same way, you can get the chunks of every heap, 176 00:15:14,660 --> 00:15:17,560 or from a single heap object. 177 00:15:18,840 --> 00:15:22,860 And again, these chunks are objects itself, 178 00:15:23,440 --> 00:15:27,160 which has a lot of information in it. 179 00:15:28,360 --> 00:15:29,420 Easy to access information. 180 00:15:30,060 --> 00:15:32,360 You can search inside chunks. 181 00:15:33,740 --> 00:15:34,500 Like... 182 00:15:36,540 --> 00:15:39,560 Okay, you can search inside chunks. 183 00:15:40,420 --> 00:15:42,760 And you can specify, if you want, 184 00:15:42,940 --> 00:15:43,580 like, 185 00:15:43,580 --> 00:15:46,600 an optional heap argument, 186 00:15:47,300 --> 00:15:50,620 to filter by heap, the search. 187 00:15:51,260 --> 00:15:52,860 There is another libraries, 188 00:15:53,040 --> 00:15:54,680 the data type discovery libraries, 189 00:15:55,580 --> 00:16:00,020 which help you find types of data in memory. 190 00:16:00,260 --> 00:16:03,180 That's pretty useful when calling an exploit, 191 00:16:03,520 --> 00:16:06,100 to know where and what is in memory. 192 00:16:10,200 --> 00:16:11,260 For example, 193 00:16:11,260 --> 00:16:14,240 you can go and do a discovery of memory. 194 00:16:15,020 --> 00:16:16,580 Of what? Of a pointer. 195 00:16:16,800 --> 00:16:19,020 And that will return an object. 196 00:16:19,280 --> 00:16:20,800 And you can ask in that object 197 00:16:20,800 --> 00:16:23,840 if it's a function pointer, or a normal pointer, 198 00:16:24,120 --> 00:16:27,440 a data pointer, a stack pointer, and so on. 199 00:16:28,300 --> 00:16:30,000 Oh, there is a simple... 200 00:16:30,000 --> 00:16:33,080 Well, this slide should talk by itself. 201 00:16:33,960 --> 00:16:35,740 We have Hibby, 202 00:16:35,840 --> 00:16:39,480 Stack Hibby, trying to use PyCommons and PyHooks, 203 00:16:39,480 --> 00:16:41,180 which use the Python app, 204 00:16:41,260 --> 00:16:43,460 to analyze false search discover, 205 00:16:43,900 --> 00:16:44,920 and most important, 206 00:16:45,160 --> 00:16:47,880 understand what is going on inside the debugger, 207 00:16:47,940 --> 00:16:49,340 to create an exploit. 208 00:16:52,920 --> 00:16:55,840 During the past month, 209 00:16:56,060 --> 00:16:59,020 a new team has been calling some script 210 00:16:59,020 --> 00:17:01,560 that was helping us 211 00:17:01,950 --> 00:17:04,240 while developing exploits. 212 00:17:04,460 --> 00:17:08,480 These scripts include vulnerability analysis, 213 00:17:09,090 --> 00:17:10,860 Hibs, protocols, search infinity, 214 00:17:11,260 --> 00:17:11,760 and compiling memory. 215 00:17:13,950 --> 00:17:16,380 There are some examples of scripts created. 216 00:17:16,740 --> 00:17:17,740 For example, 217 00:17:17,940 --> 00:17:19,240 safe-c, 218 00:17:19,990 --> 00:17:22,360 that we showed you in a custom window. 219 00:17:24,050 --> 00:17:26,420 All the exception handlers in the process 220 00:17:26,420 --> 00:17:28,580 that are registered with safe-c. 221 00:17:30,360 --> 00:17:32,420 We find anti-DIP script, 222 00:17:32,840 --> 00:17:36,180 which will find an address to bypass software DIP. 223 00:17:36,970 --> 00:17:40,420 This script was used in one of immunity training, 224 00:17:40,420 --> 00:17:44,020 and that's why it has a wizard on it, 225 00:17:44,160 --> 00:17:47,800 where the first combo box asks for the first address. 226 00:17:48,020 --> 00:17:50,600 Then you have an input box 227 00:17:50,600 --> 00:17:54,300 for inserting the assembly code to search. 228 00:17:54,580 --> 00:17:57,060 And lastly, you have another combo box 229 00:17:57,060 --> 00:18:00,340 that will search for the third return address. 230 00:18:01,260 --> 00:18:06,040 And you can see the lower screen 231 00:18:06,040 --> 00:18:08,680 that shows a buffer 232 00:18:08,680 --> 00:18:11,240 that will help you bypass the IP. 233 00:18:16,380 --> 00:18:17,740 There is another script 234 00:18:17,740 --> 00:18:21,580 that will find memory leaks in a function. 235 00:18:21,920 --> 00:18:23,020 It's a hook. 236 00:18:23,580 --> 00:18:25,820 It will hook a function. 237 00:18:26,240 --> 00:18:29,160 Then you will be passing that function, 238 00:18:29,440 --> 00:18:32,680 and you will be getting the leaks. 239 00:18:32,920 --> 00:18:35,040 Check the red line 240 00:18:35,040 --> 00:18:36,780 where a memory leak is detected 241 00:18:36,780 --> 00:18:38,380 in that function, 242 00:18:38,660 --> 00:18:40,520 which was hooked by lexniff. 243 00:18:46,080 --> 00:18:47,860 Finding data types in memory 244 00:18:47,860 --> 00:18:49,280 is another script 245 00:18:49,280 --> 00:18:51,160 that will help discover 246 00:18:51,520 --> 00:18:54,060 what kind of data is inside the memory. 247 00:18:54,360 --> 00:18:56,520 Users have to specify an address 248 00:18:56,520 --> 00:18:58,380 and decide to read. 249 00:18:58,640 --> 00:19:00,460 And in the log window will appear 250 00:19:00,460 --> 00:19:01,900 what kind of data 251 00:19:03,440 --> 00:19:04,980 they discovered in the phone. 252 00:19:05,300 --> 00:19:06,520 And the heap, 253 00:19:06,780 --> 00:19:07,180 by command. 254 00:19:07,420 --> 00:19:08,700 With the heap code by command, 255 00:19:08,800 --> 00:19:11,140 you can make analysis of the heap 256 00:19:11,780 --> 00:19:13,600 and dump it 257 00:19:13,600 --> 00:19:15,620 and check what's inside, 258 00:19:15,860 --> 00:19:17,460 like the screenshot shows. 259 00:19:19,120 --> 00:19:22,180 For example, check the double link of leads 260 00:19:22,180 --> 00:19:24,580 that the heap, by command, found. 261 00:19:29,120 --> 00:19:31,800 There is another script, 262 00:19:32,040 --> 00:19:33,400 the chunk analyze, 263 00:19:34,540 --> 00:19:36,020 that is another hook, 264 00:19:36,020 --> 00:19:37,200 where you specify 265 00:19:37,940 --> 00:19:39,400 the address of the red node, 266 00:19:39,620 --> 00:19:41,400 and you run the hack. 267 00:19:41,580 --> 00:19:42,720 You place it into memory, 268 00:19:43,580 --> 00:19:44,960 and you start fuzzing. 269 00:19:45,180 --> 00:19:47,220 If you check the log window, 270 00:19:47,520 --> 00:19:49,580 you will be able, 271 00:19:49,740 --> 00:19:50,880 one of your fuzzing 272 00:19:50,880 --> 00:19:53,100 is overwriting a function pointer 273 00:19:53,100 --> 00:19:54,740 of a double linked list. 274 00:19:58,860 --> 00:20:03,240 The getRPC will access to RPC information, 275 00:20:03,600 --> 00:20:05,340 and will give function pointers 276 00:20:06,020 --> 00:20:07,400 to every RPC call. 277 00:20:09,720 --> 00:20:10,880 The duality script, 278 00:20:11,200 --> 00:20:13,140 the duality script will look 279 00:20:13,140 --> 00:20:14,720 at memory pages, 280 00:20:14,920 --> 00:20:16,540 and others that can be transformed 281 00:20:16,540 --> 00:20:17,620 into opcodes. 282 00:20:18,180 --> 00:20:20,800 This duality script will be described more 283 00:20:20,800 --> 00:20:22,500 later in the talk. 284 00:20:24,700 --> 00:20:27,000 In the case story I have prepared. 285 00:20:28,840 --> 00:20:30,900 The mod pointer script, 286 00:20:31,640 --> 00:20:34,320 this tool will do some data recognition, 287 00:20:34,320 --> 00:20:36,380 looking for function pointers, 288 00:20:37,100 --> 00:20:39,180 and it will overwrite them, 289 00:20:40,200 --> 00:20:42,400 waiting for an access violation 290 00:20:43,200 --> 00:20:46,460 of one of these pointers overwriting, 291 00:20:46,660 --> 00:20:48,720 and when the access violation occurs, 292 00:20:48,980 --> 00:20:50,680 it will trigger the hook, 293 00:20:50,740 --> 00:20:52,380 and will start logging in 294 00:20:52,380 --> 00:20:54,460 for the analysis. 295 00:20:56,900 --> 00:20:58,340 And the search script, 296 00:20:58,520 --> 00:21:00,400 the search script is a simple script 297 00:21:00,400 --> 00:21:03,640 that will search for cryptographic routines 298 00:21:03,640 --> 00:21:04,780 in a given branch. 299 00:21:04,980 --> 00:21:06,020 Look at this screenshot 300 00:21:06,020 --> 00:21:09,500 how a lot of different algorithm 301 00:21:09,500 --> 00:21:11,400 was found in a library. 302 00:21:15,310 --> 00:21:17,380 We have a case study here. 303 00:21:17,740 --> 00:21:20,120 It's a simple stack overflow 304 00:21:20,980 --> 00:21:23,040 in savant web server. 305 00:21:24,460 --> 00:21:28,180 When you send along get request to it, 306 00:21:28,300 --> 00:21:30,900 it will crash with a stack overflow. 307 00:21:31,300 --> 00:21:31,940 However, 308 00:21:31,940 --> 00:21:35,400 there are some details in it. 309 00:21:35,580 --> 00:21:36,320 For example, 310 00:21:36,460 --> 00:21:39,180 when you send along buffer, 311 00:21:39,620 --> 00:21:40,540 the stack, 312 00:21:40,660 --> 00:21:42,960 some stack arguments overwriting 313 00:21:42,960 --> 00:21:45,500 won't allow us to reach EIP. 314 00:21:46,790 --> 00:21:48,180 Check the screenshot lines, 315 00:21:48,560 --> 00:21:51,340 it's showing how an argument, 316 00:21:51,420 --> 00:21:52,740 a readable address, 317 00:21:52,980 --> 00:21:53,920 is overwriting, 318 00:21:55,000 --> 00:21:57,120 and getting an access violation 319 00:21:57,120 --> 00:21:58,960 when writing this address. 320 00:21:59,960 --> 00:22:00,700 So, 321 00:22:00,700 --> 00:22:03,020 we need to find a readable address 322 00:22:03,020 --> 00:22:04,880 to place as the argument there 323 00:22:04,880 --> 00:22:06,960 in the right offset. 324 00:22:07,740 --> 00:22:09,100 Once we find this, 325 00:22:09,240 --> 00:22:10,560 which is pretty easy, 326 00:22:10,780 --> 00:22:14,220 we'll be facing the second argument problem. 327 00:22:14,760 --> 00:22:16,260 A readable address. 328 00:22:16,700 --> 00:22:19,840 That's almost as easy as the first one. 329 00:22:19,960 --> 00:22:22,260 We just need to find a readable address. 330 00:22:23,280 --> 00:22:23,880 So, 331 00:22:23,880 --> 00:22:25,560 replacing to keep EIP, 332 00:22:25,780 --> 00:22:27,220 we need a readable address, 333 00:22:27,380 --> 00:22:29,020 that readable address, 334 00:22:29,020 --> 00:22:30,600 and the argument offset 335 00:22:30,600 --> 00:22:32,620 in our screen thing. 336 00:22:34,100 --> 00:22:35,900 Finding the offset should be easy, 337 00:22:36,000 --> 00:22:36,160 so, 338 00:22:36,940 --> 00:22:39,960 when we got that addresses 339 00:22:39,960 --> 00:22:41,300 and the offset, 340 00:22:41,540 --> 00:22:42,900 we can craft a buffer. 341 00:22:44,040 --> 00:22:44,720 That, 342 00:22:44,860 --> 00:22:45,840 if, 343 00:22:46,040 --> 00:22:49,320 if the others we found are right, 344 00:22:49,540 --> 00:22:52,260 we'll be able to hit EIP, 345 00:22:52,500 --> 00:22:53,720 like the screenshot shows, 346 00:22:54,080 --> 00:22:55,440 without any problem. 347 00:22:57,720 --> 00:22:58,400 So, 348 00:22:59,160 --> 00:23:00,580 once we hit EIP, 349 00:23:00,740 --> 00:23:02,680 in detail we have control over 350 00:23:02,680 --> 00:23:03,660 EVP value, 351 00:23:04,000 --> 00:23:05,160 AP value, 352 00:23:05,660 --> 00:23:07,820 what ESP point two, 353 00:23:08,040 --> 00:23:09,420 which is one of the arguments, 354 00:23:09,660 --> 00:23:12,220 and what ESP plus four point two, 355 00:23:12,340 --> 00:23:13,700 which is the other arguments. 356 00:23:14,000 --> 00:23:16,020 And we have more of, 357 00:23:16,040 --> 00:23:18,300 of 200 bytes 358 00:23:18,300 --> 00:23:20,000 of a controlled buffer. 359 00:23:22,140 --> 00:23:22,480 This, 360 00:23:26,220 --> 00:23:27,840 there is the context, 361 00:23:28,000 --> 00:23:28,800 I was talking right, 362 00:23:30,060 --> 00:23:30,900 right here. 363 00:23:31,780 --> 00:23:33,160 And the first thing, 364 00:23:33,400 --> 00:23:34,780 I could think of, 365 00:23:35,000 --> 00:23:36,080 with this context, 366 00:23:36,280 --> 00:23:37,080 is jumping back. 367 00:23:37,520 --> 00:23:38,280 But how? 368 00:23:38,520 --> 00:23:39,600 And that's the second problem. 369 00:23:40,280 --> 00:23:40,540 Check, 370 00:23:41,260 --> 00:23:41,820 where, 371 00:23:42,480 --> 00:23:44,640 what ESP is pointing to. 372 00:23:47,060 --> 00:23:47,980 Since we, 373 00:23:48,000 --> 00:23:50,620 since we are controlling what ESP points to, 374 00:23:50,800 --> 00:23:52,860 what if we couldn't find an address, 375 00:23:53,060 --> 00:23:53,880 to place, 376 00:23:54,000 --> 00:23:54,660 to place, 377 00:23:54,660 --> 00:23:57,020 as the overwriting argument, 378 00:23:57,180 --> 00:23:57,480 which, 379 00:23:57,680 --> 00:23:58,820 first of all, 380 00:23:58,820 --> 00:23:59,960 needs to be writeable, 381 00:24:00,140 --> 00:24:01,420 because of the first problem. 382 00:24:01,920 --> 00:24:02,540 And second, 383 00:24:02,880 --> 00:24:05,080 it can be transformed into opcodes, 384 00:24:05,300 --> 00:24:06,880 that would be of use here. 385 00:24:07,580 --> 00:24:08,200 Like, 386 00:24:08,300 --> 00:24:09,500 let's say a jump back, 387 00:24:10,370 --> 00:24:12,240 to land into our control buffer. 388 00:24:13,520 --> 00:24:15,240 But finding an address, 389 00:24:15,340 --> 00:24:16,380 with these characteristics, 390 00:24:16,760 --> 00:24:17,180 must, 391 00:24:17,420 --> 00:24:18,940 might be pretty tedious, 392 00:24:19,180 --> 00:24:20,400 and pretty hard. 393 00:24:20,800 --> 00:24:21,420 So, 394 00:24:21,560 --> 00:24:22,500 there is a script, 395 00:24:22,700 --> 00:24:23,840 with immunity valid, 396 00:24:24,660 --> 00:24:25,580 that we talked, 397 00:24:25,700 --> 00:24:26,520 some minutes ago, 398 00:24:26,660 --> 00:24:27,580 that would help here. 399 00:24:27,760 --> 00:24:28,680 The duality script. 400 00:24:30,660 --> 00:24:32,800 The duality script is easy, 401 00:24:33,060 --> 00:24:33,780 to use. 402 00:24:34,060 --> 00:24:35,220 You just have to, 403 00:24:35,220 --> 00:24:36,020 place, 404 00:24:36,220 --> 00:24:37,600 the common argument, 405 00:24:37,980 --> 00:24:38,600 to the script, 406 00:24:38,760 --> 00:24:39,760 you are looking for. 407 00:24:40,180 --> 00:24:41,480 And how duality works? 408 00:24:41,920 --> 00:24:42,120 Well, 409 00:24:42,280 --> 00:24:43,300 it creates a mask, 410 00:24:43,460 --> 00:24:44,320 of the search code. 411 00:24:44,620 --> 00:24:45,320 In this case, 412 00:24:45,320 --> 00:24:45,700 a jump, 413 00:24:45,820 --> 00:24:46,840 minus 10. 414 00:24:47,280 --> 00:24:48,400 And we'll get, 415 00:24:48,500 --> 00:24:49,420 all the memory pages. 416 00:24:50,160 --> 00:24:50,720 And, 417 00:24:50,900 --> 00:24:52,160 we'll try to find addresses, 418 00:24:52,420 --> 00:24:54,180 that match our masked search codes. 419 00:24:54,180 --> 00:24:55,980 As we can see in the screenshot, 420 00:24:56,260 --> 00:24:56,980 the log result, 421 00:24:57,260 --> 00:24:58,000 there is a, 422 00:24:59,260 --> 00:25:00,140 an address, 423 00:25:00,300 --> 00:25:01,500 marked with a red line, 424 00:25:01,680 --> 00:25:02,660 that may, 425 00:25:02,780 --> 00:25:04,560 may be of use here. 426 00:25:06,100 --> 00:25:06,640 So, 427 00:25:06,860 --> 00:25:08,000 before finishing, 428 00:25:08,080 --> 00:25:08,780 crafting our, 429 00:25:08,840 --> 00:25:09,360 string, 430 00:25:10,060 --> 00:25:11,300 with a brand new, 431 00:25:11,480 --> 00:25:12,020 address, 432 00:25:13,380 --> 00:25:14,340 transformable address, 433 00:25:14,620 --> 00:25:15,560 we'll need to find, 434 00:25:15,620 --> 00:25:16,520 a jump ESP, 435 00:25:16,660 --> 00:25:17,080 for a, 436 00:25:17,120 --> 00:25:18,220 for a, 437 00:25:18,220 --> 00:25:18,860 AIP. 438 00:25:19,640 --> 00:25:20,960 The search code script, 439 00:25:21,220 --> 00:25:21,860 will do that, 440 00:25:21,880 --> 00:25:22,660 really fast. 441 00:25:22,660 --> 00:25:24,020 You just have to, 442 00:25:24,020 --> 00:25:24,960 write search code, 443 00:25:25,120 --> 00:25:25,640 and the command, 444 00:25:25,860 --> 00:25:27,460 you are willing to search. 445 00:25:28,820 --> 00:25:29,340 So, 446 00:25:29,360 --> 00:25:29,820 resuming. 447 00:25:31,980 --> 00:25:32,740 You have, 448 00:25:32,760 --> 00:25:33,200 we have, 449 00:25:33,300 --> 00:25:34,640 bypassed the arguments problem. 450 00:25:35,000 --> 00:25:35,920 We have hit, 451 00:25:36,020 --> 00:25:36,480 AIP. 452 00:25:36,760 --> 00:25:37,800 We have searched, 453 00:25:37,900 --> 00:25:39,100 for a writeable address, 454 00:25:39,360 --> 00:25:40,480 that can be transformed, 455 00:25:40,720 --> 00:25:41,580 into an opcode. 456 00:25:42,160 --> 00:25:43,460 And we have searched, 457 00:25:43,620 --> 00:25:44,760 for a jump ESP. 458 00:25:46,140 --> 00:25:46,660 And, 459 00:25:46,760 --> 00:25:47,500 we have crafted, 460 00:25:47,620 --> 00:25:48,020 the string. 461 00:25:48,420 --> 00:25:48,940 So, 462 00:25:49,900 --> 00:25:50,880 if everything, 463 00:25:51,040 --> 00:25:51,680 goes well, 464 00:25:51,920 --> 00:25:52,640 we'll be able, 465 00:25:52,640 --> 00:25:53,120 we'll be having, 466 00:25:54,660 --> 00:25:55,780 our int, 467 00:25:55,780 --> 00:25:56,640 int three. 468 00:25:57,240 --> 00:25:57,900 Check the, 469 00:25:57,900 --> 00:25:58,460 the, 470 00:25:58,460 --> 00:25:59,860 the right, 471 00:25:59,880 --> 00:26:01,440 the right red box, 472 00:26:01,660 --> 00:26:02,160 where, 473 00:26:02,360 --> 00:26:03,400 ESP is, 474 00:26:03,620 --> 00:26:04,960 which is pointing, 475 00:26:05,060 --> 00:26:05,900 to an address, 476 00:26:06,080 --> 00:26:06,340 that, 477 00:26:06,500 --> 00:26:07,680 in the disassembly, 478 00:26:07,680 --> 00:26:08,020 window, 479 00:26:08,300 --> 00:26:08,980 is transformed, 480 00:26:09,220 --> 00:26:09,900 to a short, 481 00:26:10,120 --> 00:26:10,620 jump. 482 00:26:11,440 --> 00:26:11,780 Back, 483 00:26:12,680 --> 00:26:13,600 to run, 484 00:26:13,720 --> 00:26:14,540 into our, 485 00:26:14,740 --> 00:26:15,800 controlled, 486 00:26:15,940 --> 00:26:16,380 buffer. 487 00:26:19,160 --> 00:26:19,840 Okay. 488 00:26:22,920 --> 00:26:23,380 Now, 489 00:26:23,480 --> 00:26:24,100 I'm going to, 490 00:26:24,220 --> 00:26:24,600 some, 491 00:26:25,360 --> 00:26:26,280 immunity debugger, 492 00:26:26,280 --> 00:26:26,480 demo. 493 00:26:29,000 --> 00:26:29,460 Hmm. 494 00:26:30,960 --> 00:26:31,740 Hard to, 495 00:26:31,780 --> 00:26:32,020 check. 496 00:26:34,780 --> 00:26:35,240 Okay. 497 00:26:35,520 --> 00:26:35,800 Now, 498 00:26:35,860 --> 00:26:36,500 immunity debugger, 499 00:26:36,500 --> 00:26:36,720 demo. 500 00:26:40,740 --> 00:26:41,200 Okay. 501 00:26:42,160 --> 00:26:42,640 Let's go, 502 00:26:42,720 --> 00:26:43,020 for the, 503 00:26:43,060 --> 00:26:43,300 conclusion, 504 00:26:43,540 --> 00:26:43,700 then. 505 00:26:44,000 --> 00:26:44,340 So, 506 00:26:44,860 --> 00:26:45,760 immunity debugger, 507 00:26:45,760 --> 00:26:46,420 won't give you, 508 00:26:46,480 --> 00:26:46,680 an, 509 00:26:46,680 --> 00:26:47,120 another, 510 00:26:47,320 --> 00:26:47,640 of the, 511 00:26:47,720 --> 00:26:47,940 box, 512 00:26:47,960 --> 00:26:48,300 exploit. 513 00:26:48,960 --> 00:26:49,420 But, 514 00:26:49,560 --> 00:26:49,960 it will, 515 00:26:50,020 --> 00:26:50,520 speed up, 516 00:26:50,560 --> 00:26:51,040 the time, 517 00:26:51,080 --> 00:26:51,320 debugging. 518 00:26:52,640 --> 00:26:52,920 Because, 519 00:26:53,000 --> 00:26:53,660 of the GUI, 520 00:26:53,720 --> 00:26:54,680 the graphical interface, 521 00:26:54,840 --> 00:26:55,780 and the command line. 522 00:26:56,640 --> 00:26:57,140 And, 523 00:26:57,300 --> 00:26:58,200 it will help you, 524 00:26:58,200 --> 00:26:58,880 finding the bug, 525 00:26:59,060 --> 00:26:59,680 with the, 526 00:26:59,780 --> 00:27:00,260 API, 527 00:27:00,540 --> 00:27:01,340 and the libraries, 528 00:27:01,660 --> 00:27:02,360 and the immunity, 529 00:27:02,440 --> 00:27:03,300 and the immunity, 530 00:27:04,380 --> 00:27:04,880 scripts, 531 00:27:05,260 --> 00:27:05,960 that are provided, 532 00:27:06,300 --> 00:27:06,700 with, 533 00:27:07,940 --> 00:27:08,440 with, 534 00:27:09,760 --> 00:27:10,700 immunity debugger. 535 00:27:10,940 --> 00:27:11,440 And, 536 00:27:11,520 --> 00:27:12,080 will help you, 537 00:27:12,120 --> 00:27:12,440 crafting, 538 00:27:12,440 --> 00:27:12,700 crafting, 539 00:27:12,880 --> 00:27:13,300 your exploit. 540 00:27:13,920 --> 00:27:14,640 Making it, 541 00:27:14,680 --> 00:27:14,900 more, 542 00:27:14,920 --> 00:27:15,200 reliable. 543 00:27:16,340 --> 00:27:17,620 We have been using, 544 00:27:17,720 --> 00:27:18,440 immunity debugger, 545 00:27:18,440 --> 00:27:18,880 for months, 546 00:27:19,020 --> 00:27:19,460 while, 547 00:27:19,460 --> 00:27:19,540 we were, 548 00:27:20,680 --> 00:27:21,240 with, 549 00:27:21,560 --> 00:27:22,500 good results. 550 00:27:23,480 --> 00:27:24,040 And, 551 00:27:24,280 --> 00:27:25,080 some things, 552 00:27:25,140 --> 00:27:25,720 that are, 553 00:27:25,860 --> 00:27:26,660 inside my head, 554 00:27:26,800 --> 00:27:27,300 right now, 555 00:27:27,460 --> 00:27:28,120 is an, 556 00:27:28,180 --> 00:27:28,780 API server, 557 00:27:28,940 --> 00:27:29,300 to connect, 558 00:27:29,540 --> 00:27:31,000 the immunity debugger, 559 00:27:31,100 --> 00:27:32,200 to visual exploit, 560 00:27:32,860 --> 00:27:33,420 canvas, 561 00:27:33,720 --> 00:27:34,560 or fuzzers, 562 00:27:34,560 --> 00:27:35,120 or whichever, 563 00:27:35,280 --> 00:27:35,640 application, 564 00:27:36,000 --> 00:27:37,300 that could be, 565 00:27:37,320 --> 00:27:37,680 of use, 566 00:27:37,960 --> 00:27:38,600 when, 567 00:27:38,680 --> 00:27:39,580 doing some, 568 00:27:39,660 --> 00:27:40,080 vulnerability, 569 00:27:41,840 --> 00:27:42,400 development. 570 00:27:43,840 --> 00:27:44,400 More, 571 00:27:44,500 --> 00:27:44,980 graphing stuff, 572 00:27:45,320 --> 00:27:45,600 like, 573 00:27:46,060 --> 00:27:46,560 interaction, 574 00:27:46,640 --> 00:27:47,180 with the graphs. 575 00:27:47,340 --> 00:27:47,600 So, 576 00:27:47,620 --> 00:27:48,360 we can manage, 577 00:27:49,460 --> 00:27:49,840 the vertices, 578 00:27:50,700 --> 00:27:51,220 and, 579 00:27:51,340 --> 00:27:51,700 move, 580 00:27:51,920 --> 00:27:52,440 them around, 581 00:27:52,820 --> 00:27:53,280 and, 582 00:27:53,440 --> 00:27:54,380 even clicking them, 583 00:27:54,620 --> 00:27:55,740 to modify the assemble, 584 00:27:56,020 --> 00:27:56,980 and so on. 585 00:27:57,840 --> 00:27:58,360 And, 586 00:27:58,500 --> 00:27:58,820 also, 587 00:27:59,000 --> 00:27:59,760 a lot of, 588 00:27:59,760 --> 00:28:00,080 comments, 589 00:28:00,520 --> 00:28:01,200 that comes, 590 00:28:01,340 --> 00:28:01,960 every day, 591 00:28:02,100 --> 00:28:03,400 when we need it, 592 00:28:03,420 --> 00:28:04,240 we call them. 593 00:28:05,000 --> 00:28:05,520 And, 594 00:28:05,800 --> 00:28:06,260 your script, 595 00:28:06,460 --> 00:28:06,600 yeah, 596 00:28:06,680 --> 00:28:07,240 that's something, 597 00:28:07,360 --> 00:28:08,060 I was thinking, 598 00:28:08,100 --> 00:28:09,580 thinking about also. 599 00:28:10,080 --> 00:28:10,780 Immunity debugger, 600 00:28:10,780 --> 00:28:11,400 is pretty curious, 601 00:28:11,480 --> 00:28:12,500 about what you can do, 602 00:28:12,600 --> 00:28:14,140 what you can do, 603 00:28:14,840 --> 00:28:16,280 with immunity debugger, 604 00:28:16,340 --> 00:28:16,620 API. 605 00:28:17,020 --> 00:28:17,440 So, 606 00:28:17,440 --> 00:28:18,440 we have launched, 607 00:28:18,560 --> 00:28:19,820 a little contest, 608 00:28:20,180 --> 00:28:22,300 for the most useful script, 609 00:28:22,700 --> 00:28:24,220 where the first prize, 610 00:28:24,480 --> 00:28:25,940 will be a silica unit. 611 00:28:26,420 --> 00:28:27,580 I think, 612 00:28:27,580 --> 00:28:28,980 it's up to, 613 00:28:29,040 --> 00:28:30,180 October 10th, 614 00:28:30,180 --> 00:28:31,040 or something like that. 615 00:28:31,280 --> 00:28:31,580 So, 616 00:28:31,700 --> 00:28:32,420 if you're willing, 617 00:28:32,540 --> 00:28:33,720 to call some script, 618 00:28:33,980 --> 00:28:34,640 of use, 619 00:28:35,440 --> 00:28:36,660 just drop me a, 620 00:28:36,740 --> 00:28:37,840 drop me a line, 621 00:28:37,980 --> 00:28:38,380 later. 622 00:28:44,000 --> 00:28:45,020 You can download, 623 00:28:45,220 --> 00:28:46,280 immunity debugger, 624 00:28:46,360 --> 00:28:47,280 get it free, 625 00:28:47,440 --> 00:28:48,220 and, 626 00:28:48,340 --> 00:28:48,900 comment, 627 00:28:49,080 --> 00:28:49,620 script, 628 00:28:49,820 --> 00:28:50,240 idea, 629 00:28:50,420 --> 00:28:50,820 request, 630 00:28:51,140 --> 00:28:52,560 please email me. 631 00:28:53,500 --> 00:28:54,280 I'm willing, 632 00:28:54,520 --> 00:28:55,300 to answer, 633 00:28:55,360 --> 00:28:56,240 any questions, 634 00:28:56,260 --> 00:28:57,020 any questions, 635 00:28:57,060 --> 00:28:57,520 you might have. 636 00:28:58,100 --> 00:28:58,660 But, 637 00:28:58,780 --> 00:28:59,360 I think, 638 00:28:59,360 --> 00:29:00,460 that's in the question, 639 00:29:00,520 --> 00:29:01,140 and answer room. 640 00:29:01,820 --> 00:29:02,380 So, 641 00:29:03,720 --> 00:29:04,360 that's it. 642 00:29:05,800 --> 00:29:06,360 Okay.