1 00:00:00,000 --> 00:00:02,420 Okay, my name is Nick Harbour. I work at a company called Mandiant. 2 00:00:03,000 --> 00:00:05,420 It's at the bottom of the slide. We're an incident response company. 3 00:00:05,580 --> 00:00:09,980 Me, personally, I lead the malware analysis team at Mandiant, so reversing's my thing. 4 00:00:11,580 --> 00:00:14,800 This talk is going to be kind of primarily aimed at reverse engineers 5 00:00:14,800 --> 00:00:17,220 or people who are getting into reverse engineers. 6 00:00:17,740 --> 00:00:21,060 And there will be a lot of code on the slides. 7 00:00:21,180 --> 00:00:23,860 There will be some assembly code that freaks you guys out. 8 00:00:23,940 --> 00:00:26,420 You can go ahead and bail now. I won't be offended. 9 00:00:27,160 --> 00:00:28,860 You don't have to understand every bit of it, though. 10 00:00:28,860 --> 00:00:32,580 There's still going to be a lot of content in here for people who are absolutely brand new, 11 00:00:32,700 --> 00:00:34,460 don't know how to code, that sort of thing. 12 00:00:36,760 --> 00:00:41,280 All right, so as far as the agenda, I'm going to start out, get some terminology out of the way 13 00:00:41,280 --> 00:00:45,620 so nobody's mystified whenever I start throwing out some terms. 14 00:00:46,540 --> 00:00:49,400 I'm going to talk about the history of dynamic analysis 15 00:00:49,400 --> 00:00:51,760 and the current techniques that people are using in the field 16 00:00:51,760 --> 00:00:55,440 and the current techniques that I use when I'm doing malware analysis. 17 00:00:56,540 --> 00:00:58,460 And like I said, this is a reverse engineering talk, 18 00:00:58,480 --> 00:00:58,840 and I'm going to talk about the history of dynamic analysis 19 00:00:58,860 --> 00:01:03,740 and since I'm a malware analysis guy, it's always going to be with a hint of malware analysis. 20 00:01:03,940 --> 00:01:05,860 I know there's several different disciplines of reversing. 21 00:01:06,840 --> 00:01:09,900 I'm pretty much always going to take the discipline of malware. 22 00:01:12,080 --> 00:01:16,560 So basically, at the end, the carrot at the end of the stick for this talk will be a new tool, 23 00:01:17,040 --> 00:01:19,480 and I'm going to basically give you a mini setting it up throughout the talk 24 00:01:19,480 --> 00:01:22,980 and how it compares and contrasts with other tools that are currently out there. 25 00:01:25,400 --> 00:01:27,800 All right, so a little bit about reverse engineering. 26 00:01:27,800 --> 00:01:30,240 We split it off into two different... 27 00:01:31,180 --> 00:01:32,420 Actually, let me just take this out. 28 00:01:32,700 --> 00:01:33,540 This is really annoying. 29 00:01:41,500 --> 00:01:44,020 All real hackers have their dog as their background. 30 00:01:45,520 --> 00:01:46,240 Yeah, he is. 31 00:01:46,940 --> 00:01:47,820 Oh, okay. 32 00:01:52,080 --> 00:01:52,520 Yeah. 33 00:01:53,860 --> 00:01:54,460 All right. 34 00:01:56,140 --> 00:01:57,780 All right, so we split off reverse. 35 00:01:57,800 --> 00:01:59,580 Reverse engineering into two main disciplines, 36 00:01:59,900 --> 00:02:01,000 or two main categories. 37 00:02:01,060 --> 00:02:04,580 Static analysis, which is everything that doesn't involve actually running the code. 38 00:02:05,440 --> 00:02:07,200 Analogy there being like an autopsy. 39 00:02:07,200 --> 00:02:07,760 You know, it's dead. 40 00:02:07,840 --> 00:02:08,460 You're picking it apart. 41 00:02:08,780 --> 00:02:09,780 You're figuring out what it does. 42 00:02:10,000 --> 00:02:12,700 The other half of the picture is dynamic analysis, 43 00:02:12,980 --> 00:02:15,080 which is, you know, you're letting the malware run. 44 00:02:15,280 --> 00:02:17,220 You're seeing what it does, observing its behavior. 45 00:02:18,060 --> 00:02:19,800 So the tool that I'm going to be presenting about 46 00:02:20,380 --> 00:02:22,340 and the techniques we're going to be talking about 47 00:02:22,340 --> 00:02:27,000 are solely contained within the dynamic analysis family of techniques. 48 00:02:28,220 --> 00:02:30,740 So you're actually going to have to run the software 49 00:02:30,740 --> 00:02:33,060 to actually use these analysis techniques. 50 00:02:36,100 --> 00:02:38,700 So the current approaches out there are... 51 00:02:41,680 --> 00:02:42,380 Wait for it. 52 00:02:43,840 --> 00:02:44,560 Network monitoring. 53 00:02:44,620 --> 00:02:46,320 Yeah, of course, you know, setting up virtual networks. 54 00:02:46,440 --> 00:02:47,820 A lot of this is accomplished with VMware. 55 00:02:48,140 --> 00:02:49,180 It's what we currently use. 56 00:02:49,600 --> 00:02:53,120 This is certainly accomplished by people at the very basic level. 57 00:02:53,180 --> 00:02:56,500 Before you know anything about disassembly or any of that, 58 00:02:56,540 --> 00:02:57,420 you can set up Wireshark. 59 00:02:57,800 --> 00:03:00,680 You know, do some basic behavioral analysis on malware. 60 00:03:01,320 --> 00:03:04,940 Getting more complicated, expensive solutions like Norman Sandbox 61 00:03:04,940 --> 00:03:08,360 and CWSandbox, which these products are good. 62 00:03:08,480 --> 00:03:10,840 They can pretty much do everything that my tool is going to do. 63 00:03:10,960 --> 00:03:11,860 My tool is free. 64 00:03:12,000 --> 00:03:14,560 Their tool is tens of thousands of dollars. 65 00:03:14,660 --> 00:03:18,960 So I'm not going to claim to be, you know, beating everybody at everything free 66 00:03:18,960 --> 00:03:21,420 because this is a project in my own personal time, 67 00:03:22,480 --> 00:03:23,620 which is not copious. 68 00:03:25,820 --> 00:03:27,780 Oh, and the main tool I personally use, 69 00:03:27,800 --> 00:03:31,060 because it is also free and we get pretty good results from our analysis, 70 00:03:31,180 --> 00:03:32,860 is Sysinternals Process Monitor. 71 00:03:33,320 --> 00:03:35,000 I think quite a few of you have used it. 72 00:03:35,020 --> 00:03:35,740 It's very, very popular. 73 00:03:36,980 --> 00:03:38,560 I'm going to be comparing mainly with that. 74 00:03:38,780 --> 00:03:40,420 And debuggers can do a lot of this stuff. 75 00:03:40,580 --> 00:03:42,400 The whole point of my tool, though, is going to be, 76 00:03:42,420 --> 00:03:46,440 I'm going to be doing a lot of process tracing and API interception and all that 77 00:03:46,440 --> 00:03:47,980 without acting as a debugger. 78 00:03:48,080 --> 00:03:51,280 So if you've been thinking of, you know, heckling me with a question like, 79 00:03:51,340 --> 00:03:53,400 why don't you just use Immunity Debugger or whatever, 80 00:03:54,080 --> 00:03:56,400 the whole point is to be not using a debugger. 81 00:03:56,540 --> 00:03:57,780 I'm sure a debugger can do that. 82 00:03:57,800 --> 00:04:00,440 I think it would work great in most circumstances for these things. 83 00:04:00,780 --> 00:04:03,060 Just there needs to be a tool out there to do that kind of thing 84 00:04:03,060 --> 00:04:04,800 without being a debugger at all. 85 00:04:06,920 --> 00:04:07,440 All right. 86 00:04:08,160 --> 00:04:09,060 Kernel-level monitoring. 87 00:04:09,260 --> 00:04:14,660 So this is the technique employed by Process Monitor, by Sysinternals. 88 00:04:15,540 --> 00:04:19,840 Here's a normal kind of graph of what happens when you do a system call in Windows. 89 00:04:20,760 --> 00:04:27,520 You have a user mode process like, I don't know, notepad.exe. 90 00:04:27,800 --> 00:04:30,360 It issues a call called create file. 91 00:04:30,500 --> 00:04:35,000 This is something that's issued to the programmer in the application that can make this function call. 92 00:04:35,280 --> 00:04:38,720 And the code for that initially is provided by libraries. 93 00:04:38,880 --> 00:04:42,840 In this case, kernel32 is the library that provides that call. 94 00:04:43,060 --> 00:04:48,540 And all that happens in kernel32, which is totally in user space, is it performs a system call. 95 00:04:48,880 --> 00:04:54,640 The system calls have to be implemented in this SSDT, the system service descriptor table. 96 00:04:54,800 --> 00:04:56,920 So it's kind of like an array of pointers in the kernel. 97 00:04:57,920 --> 00:05:02,220 Essentially, I'm going to oversimplify the hell out of this whole process just for the sake of time. 98 00:05:03,020 --> 00:05:06,700 And then these go, and the kernel maps these to the actual handlers of the functions. 99 00:05:07,920 --> 00:05:14,280 So how Process Monitor works is they basically load a driver that hooks these SSDT entries. 100 00:05:14,440 --> 00:05:17,820 And so every time one of these is called, they'll eventually call the real thing. 101 00:05:18,100 --> 00:05:22,200 But along the way, they're going to report back and say, hey, somebody called this. 102 00:05:22,420 --> 00:05:24,680 You know, capture the event and take note of it. 103 00:05:28,000 --> 00:05:32,300 So advantages to that technique, every system call will be captured. 104 00:05:32,480 --> 00:05:36,360 You'll have a, that's a pretty good coverage as long as you're capturing everything in that table. 105 00:05:37,140 --> 00:05:38,980 Really kind of difficult to get around it. 106 00:05:39,640 --> 00:05:49,100 Certainly no way that I know of from user land that you can do something like create file without actually calling the actual service. 107 00:05:51,340 --> 00:05:56,520 Disadvantages, not every important function that we care about from the malware analysis or reverse engineering perspective 108 00:05:56,520 --> 00:05:59,500 is implemented as a actual system call. 109 00:05:59,680 --> 00:06:05,260 So there's important things like if you're wanting to see what functions, piece of malware is trying to load for later on, 110 00:06:05,300 --> 00:06:08,200 you'll see process function calls like get proc address. 111 00:06:08,440 --> 00:06:12,160 That's completely implemented in kernel 32, I believe. 112 00:06:12,500 --> 00:06:16,400 And that's never going to be a system call, but you're still going to want to see it happen. 113 00:06:19,560 --> 00:06:22,860 And also calls to internal DLLs, of course, will never be trapped. 114 00:06:23,000 --> 00:06:26,100 You're only going to see that the actual system call that happens from the process. 115 00:06:26,580 --> 00:06:32,880 That's implemented in kernel 32 or DLL directly into the actual kernel itself. 116 00:06:35,560 --> 00:06:38,460 Another disadvantage, you're going to see a lot of like housekeeping stuff. 117 00:06:38,640 --> 00:06:43,340 So every time you launch a process, like you make a hello world program, all it does is print hello world to the screen. 118 00:06:44,180 --> 00:06:47,080 You can use process monitor to fire up hello world. 119 00:06:47,340 --> 00:06:52,700 You're going to see thousands upon thousands of system calls happening just for hello world.exe. 120 00:06:53,880 --> 00:06:55,920 Now with skill, you can kind of filter that down. 121 00:06:55,920 --> 00:06:58,100 And weed it down and get down to the beat. 122 00:06:58,260 --> 00:07:00,160 But still, it's not a perfect system. 123 00:07:00,280 --> 00:07:02,080 You're seeing a lot more data than you really care about. 124 00:07:02,900 --> 00:07:04,180 I think we can do a little better. 125 00:07:05,640 --> 00:07:07,480 Well, here's a screenshot of process monitor. 126 00:07:07,840 --> 00:07:10,160 Initially, when I put this in, I was going to talk in detail about it. 127 00:07:10,200 --> 00:07:13,220 But we'll just look at it whenever we get to the actual demo. 128 00:07:13,420 --> 00:07:19,080 Basically, I'm going to fire up some stuff, monitor with process monitor, process monitor, and then monitor with my tool. 129 00:07:19,640 --> 00:07:20,740 You can see the difference. 130 00:07:20,960 --> 00:07:22,480 I think it'll be pretty apparent. 131 00:07:22,720 --> 00:07:25,160 But basically, this is a list of every system call that's happening. 132 00:07:25,920 --> 00:07:28,240 And this is currently filtered just for notepad.exe. 133 00:07:28,340 --> 00:07:30,820 So you can see all I did was fire up notepad. 134 00:07:31,240 --> 00:07:40,240 And I have 132,000 events, which is the system calls, of which it's currently showing 793 on the screen. 135 00:07:40,400 --> 00:07:42,340 And this is really nothing important happening at all. 136 00:07:45,780 --> 00:07:51,380 So another technique to do API call monitoring for reverse engineering is using a debugger, which is pretty good. 137 00:07:51,440 --> 00:07:54,240 You can trap function calls all day long. 138 00:07:55,000 --> 00:07:56,160 Not just system calls. 139 00:07:56,320 --> 00:07:59,820 A lot of that same stuff I'm going to be doing you can certainly implement in a debugger. 140 00:08:00,000 --> 00:08:02,180 Certainly a scriptable debugger is a very good solution. 141 00:08:04,520 --> 00:08:11,200 And the trap calls are going to be, you can potentially get them to be more highly relevant to the trap program using techniques that I'll be talking about later. 142 00:08:11,980 --> 00:08:15,700 The only disadvantages, well, the main disadvantages, you have to act as a debugger. 143 00:08:16,020 --> 00:08:24,000 Once you act as a debugger, then you're kind of thrown into the fight of this cat and mouse game of debugging and anti-debugging and anti-anti-debugging. 144 00:08:24,240 --> 00:08:27,320 You can play in that game if you want. 145 00:08:28,120 --> 00:08:33,480 I was just kind of looking for an easy, cheap way to get, circumvent the whole thing and not have a debugger involved whatsoever. 146 00:08:37,880 --> 00:08:39,440 All right, so there's lots of different types of hooks. 147 00:08:39,600 --> 00:08:41,920 I'm specifically going to be talking about inline hooks. 148 00:08:42,020 --> 00:08:43,500 This is the technique I chose. 149 00:08:43,700 --> 00:08:47,460 I think it's probably the most robust technique for the long haul. 150 00:08:47,540 --> 00:08:50,440 So I chose to implement it first and not even bother with other hooking types. 151 00:08:53,500 --> 00:08:53,860 Anyway. 152 00:08:54,240 --> 00:08:57,580 Inline hooks can basically, you can trap any function call, not just system calls. 153 00:08:57,920 --> 00:08:59,860 Currently the tool I'm going to be talking about only traps. 154 00:09:00,180 --> 00:09:02,860 It can only walk through exports of DLLs and trap those. 155 00:09:03,080 --> 00:09:05,480 But on down the line, who knows, we can do anything. 156 00:09:08,280 --> 00:09:16,480 The trap calls can be highly relevant to the program's operation because we're not going to be seeing any of those process housekeeping system calls like we saw for Notepad. 157 00:09:18,360 --> 00:09:19,680 No device driver required. 158 00:09:21,000 --> 00:09:22,420 Not operating as a debugger. 159 00:09:22,420 --> 00:09:24,980 The only disadvantage is it's kind of a pain. 160 00:09:25,160 --> 00:09:27,420 I mean there's really a lot of issues with it. 161 00:09:27,500 --> 00:09:30,380 And the tool that I'm going to be releasing certainly is going to show that. 162 00:09:30,560 --> 00:09:37,600 It's not fully, I mean this isn't, it's not on the Mandiant site yet because it's not a full, it's not bulletproof yet. 163 00:09:37,640 --> 00:09:38,440 It's very much prototype. 164 00:09:38,580 --> 00:09:41,740 You can play around with it, kick the tires, write some scripts, that sort of thing. 165 00:09:42,380 --> 00:09:44,600 It is not the be all end all tool yet. 166 00:09:44,760 --> 00:09:48,780 I think it will be a great piece of work maybe in a couple months. 167 00:09:48,900 --> 00:09:49,280 Check back. 168 00:09:50,220 --> 00:09:50,720 But anyway. 169 00:09:51,080 --> 00:09:51,760 It is a pain. 170 00:09:52,800 --> 00:09:54,020 Here's the whole idea. 171 00:09:54,640 --> 00:10:05,900 With inline hooks, we basically load stuff in the user space that handles, that traps the functions we're interested in and handles them all in user space so the kernel is never affected. 172 00:10:08,300 --> 00:10:13,320 It's basically the same graph we saw earlier, just you see the difference in where the hook handling is moved. 173 00:10:14,860 --> 00:10:15,440 All right. 174 00:10:15,500 --> 00:10:16,800 So what the heck is an inline hook? 175 00:10:16,940 --> 00:10:21,400 Inline hook is basically you're going to where the function exists and you're modifying the code. 176 00:10:21,400 --> 00:10:22,600 At that actual function. 177 00:10:23,320 --> 00:10:25,160 The assembled code for the function. 178 00:10:26,400 --> 00:10:31,040 And to implement these, just a little background in case you have no idea what the heck, how this all works. 179 00:10:31,340 --> 00:10:32,800 You basically have to find a function of interest. 180 00:10:33,220 --> 00:10:35,240 You have to disassemble the beginning of a function. 181 00:10:35,460 --> 00:10:36,200 And this is very important. 182 00:10:36,660 --> 00:10:39,480 And this differs from the way a lot of malware will do it. 183 00:10:39,680 --> 00:10:47,320 For example, if malware is going to install an inline hook to trap like the send function in Winsock to, you know, so it can monitor every outbound packet. 184 00:10:48,440 --> 00:10:51,380 They can pretty much know exactly what code is going to be at the send function. 185 00:10:51,380 --> 00:10:55,580 They don't need to disassemble it on the fly to figure out if they can install a hook or not. 186 00:10:55,660 --> 00:10:58,160 They can just blast over it and be done with it. 187 00:10:59,260 --> 00:11:04,380 Since we have a very general solution where things aren't known at the beginning, we have to disassemble. 188 00:11:04,640 --> 00:11:06,520 So I'll talk more on that in a minute. 189 00:11:06,900 --> 00:11:07,540 We disassemble. 190 00:11:07,800 --> 00:11:12,600 If possible, we overwrite the beginning bytes of the function with a jump or a call instruction. 191 00:11:13,280 --> 00:11:20,160 And the jump or call instruction that we write at the very beginning of the function points to our own block of code that's loaded into the process somewhere. 192 00:11:23,640 --> 00:11:26,260 Now, like I said, we're going to talk about why we disassemble. 193 00:11:26,540 --> 00:11:28,720 Take, for example, this little function right here. 194 00:11:28,880 --> 00:11:31,400 XOR, EAX, EAX and return. 195 00:11:31,600 --> 00:11:33,620 This is a very simple function that just returns zero. 196 00:11:34,860 --> 00:11:35,900 It's only three bytes. 197 00:11:37,600 --> 00:11:41,800 A call or a jump instruction of the type that we need is five bytes. 198 00:11:42,000 --> 00:11:47,800 If we overwrite this three byte function with five bytes of data, we're overwriting two bytes of God knows what. 199 00:11:48,100 --> 00:11:50,440 It might be just padding, but it might not be. 200 00:11:50,440 --> 00:11:58,140 So for safety, we're going to disassemble just for the purpose of figuring out if we have enough space to overwrite. 201 00:11:58,660 --> 00:12:00,760 Actually, there's one other purpose, and I'll get to that in a second. 202 00:12:03,020 --> 00:12:04,360 So here's a more complicated function. 203 00:12:04,480 --> 00:12:05,920 This is more like what you would actually see. 204 00:12:06,460 --> 00:12:08,260 This is a function prolog at the beginning. 205 00:12:08,340 --> 00:12:10,240 It basically just sets up the stack for a function. 206 00:12:10,440 --> 00:12:11,540 You don't need to worry about it. 207 00:12:12,540 --> 00:12:16,240 Just note that these four instructions are at the very beginning of this function. 208 00:12:16,580 --> 00:12:19,160 Once the hook is installed, I've installed a jump hook right here. 209 00:12:19,160 --> 00:12:23,000 You can see we overwrote basically, was it five bytes? 210 00:12:23,200 --> 00:12:28,440 So these two instructions and two bytes of this third instruction have been overwritten. 211 00:12:28,760 --> 00:12:33,860 So every piece of data starting after this first five bytes here is just unused. 212 00:12:34,620 --> 00:12:39,660 Because theoretically, whatever our jump handler is doing, if it's going to recreate these instructions, 213 00:12:39,900 --> 00:12:42,580 it has to jump back right here to let the program continue. 214 00:12:42,740 --> 00:12:44,340 These are just kind of unused. 215 00:12:45,200 --> 00:12:48,640 And there's different schools of thought on how you actually implement the hook handler. 216 00:12:48,640 --> 00:12:51,920 If you want to completely do something else and never return to the function. 217 00:12:52,800 --> 00:12:56,920 In my tool, what I actually do is I implement it with a call right here instead of a jump. 218 00:12:57,240 --> 00:13:03,920 And eventually the handler jumps back to this exact point after it's recreated the functionality that it overwrote. 219 00:13:04,300 --> 00:13:11,080 So that's another reason I use a disassembler is to figure out exactly what I need to do once I've finished playing with the function. 220 00:13:14,360 --> 00:13:17,140 All right, so once you have the hook function, what the heck do you do with it? 221 00:13:18,640 --> 00:13:19,620 You can inspect it. 222 00:13:19,680 --> 00:13:20,960 This is the terminology I use. 223 00:13:21,120 --> 00:13:22,760 I'm sure other people use different terminology. 224 00:13:22,860 --> 00:13:24,020 There's no standardization. 225 00:13:25,780 --> 00:13:27,500 I say inspect and intercept. 226 00:13:27,760 --> 00:13:32,640 Inspect being I want to let the function continue once I'm done doing whatever I'm doing. 227 00:13:33,260 --> 00:13:38,820 I just want to look at the stack, see what arguments are being passed in, do things like that. 228 00:13:39,120 --> 00:13:42,620 Intercept is I want to look at the stack and look at the arguments and all that junk. 229 00:13:43,060 --> 00:13:46,040 I just don't want to actually call the function once it's finished. 230 00:13:46,960 --> 00:13:47,960 So in this tool, 231 00:13:48,640 --> 00:13:52,940 it has the capability to basically, you can script a response whenever you hook something. 232 00:13:53,140 --> 00:13:53,840 So I can hook. 233 00:13:55,680 --> 00:13:58,260 The example I like using here is get host by name, 234 00:13:58,420 --> 00:14:02,480 which is the function in the Winsock library to do a DNS lookup. 235 00:14:02,640 --> 00:14:09,980 So we can script a response to get host by name to basically always kick back the same IP address for every DNS response, 236 00:14:10,300 --> 00:14:12,720 which is a good first step in sandboxing. 237 00:14:13,560 --> 00:14:16,100 And that would be an intercept operation as opposed to inspect. 238 00:14:16,400 --> 00:14:18,360 If we're just monitoring the API calls, 239 00:14:18,640 --> 00:14:19,320 as the program runs, 240 00:14:19,740 --> 00:14:20,680 that's all interception. 241 00:14:24,660 --> 00:14:27,000 So I kind of jumped the gun there on the rolling your own sandbox. 242 00:14:27,500 --> 00:14:32,260 Get host by name is my favorite to start out with because it's very easy to understand, 243 00:14:32,400 --> 00:14:33,260 very clear to implement. 244 00:14:34,780 --> 00:14:36,140 I'll show you the code to implement it. 245 00:14:38,000 --> 00:14:39,640 You can do much more complex things, 246 00:14:39,740 --> 00:14:40,660 and this will all be down the road. 247 00:14:40,740 --> 00:14:42,000 I don't have much of this implemented yet, 248 00:14:42,160 --> 00:14:47,140 but you can do things like you can trap the call to connect to just kick back like a pseudo handle 249 00:14:47,140 --> 00:14:52,460 so that every successive send or receive to that pseudo handle, 250 00:14:52,740 --> 00:14:55,360 you just check if it's like the value dead beef, 251 00:14:55,520 --> 00:14:56,340 and if it is, 252 00:14:56,960 --> 00:15:00,980 handle it with your own Python code as opposed to letting Winsock handle it 253 00:15:00,980 --> 00:15:02,780 and really send it out across the wire. 254 00:15:03,060 --> 00:15:05,560 Same thing could happen with the file handles. 255 00:15:06,180 --> 00:15:08,400 Create file, read file, write file, all that stuff. 256 00:15:09,220 --> 00:15:10,380 We can do the same thing. 257 00:15:13,600 --> 00:15:16,480 All right, before we get too far, I'm just going to... 258 00:15:16,480 --> 00:15:18,320 This technique hasn't been documented anywhere, 259 00:15:18,460 --> 00:15:21,280 and it's a technique I use for unpacking on a daily basis, 260 00:15:21,800 --> 00:15:26,260 and it's kind of what got me in the mindset of thinking about inline hooks for so many years. 261 00:15:27,040 --> 00:15:30,300 I'm just going to go ahead and briefly talk about this pack, 262 00:15:30,480 --> 00:15:32,140 the technique I use for unpacking. 263 00:15:32,420 --> 00:15:36,140 The reason I use this technique is it doesn't involve debuggers whatsoever. 264 00:15:37,100 --> 00:15:40,880 With just some basic hooking, we can easily unpack code. 265 00:15:42,600 --> 00:15:45,520 The first thing you need to do to unpack code with inline hooks 266 00:15:45,520 --> 00:15:47,700 is disable this thing called known DLLs. 267 00:15:49,240 --> 00:15:51,880 Basically, if you have a DLL listed in known DLLs, 268 00:15:51,880 --> 00:15:53,820 which most of the important system DLLs are, 269 00:15:54,360 --> 00:15:59,680 it'll always use the version that's in C colon backslash Windows system 32. 270 00:16:00,120 --> 00:16:03,160 For example, kernel 32 is always in that directory, 271 00:16:03,360 --> 00:16:05,160 and it's always listed in this key, 272 00:16:05,280 --> 00:16:08,620 so it's always going to use that regardless of the regular DLL search path. 273 00:16:08,920 --> 00:16:11,920 The DLL search always goes to the current directory, 274 00:16:12,160 --> 00:16:13,960 the application startup directory, 275 00:16:13,960 --> 00:16:16,720 and then eventually works its way back to the system directories. 276 00:16:17,400 --> 00:16:20,780 We disable this key, which in my malware VM, 277 00:16:20,920 --> 00:16:23,400 that's what I have disabled all the time so I can easily do this. 278 00:16:23,640 --> 00:16:25,280 You disable this key, you reboot. 279 00:16:25,640 --> 00:16:32,440 I copy kernel32.dll to the current directory that I have the malware in that's packed. 280 00:16:34,140 --> 00:16:35,820 Now, basically, whenever I run that malware, 281 00:16:35,900 --> 00:16:38,120 it's going to use the local copy that I just copied 282 00:16:38,120 --> 00:16:40,660 as opposed to the actual system 32 copy. 283 00:16:40,900 --> 00:16:42,660 The difference here is we're going to be modifying 284 00:16:42,660 --> 00:16:44,480 that version of kernel 32. 285 00:16:44,800 --> 00:16:46,660 If we tried to modify the one in system 32, 286 00:16:47,340 --> 00:16:49,180 we can't because of Windows file protection. 287 00:16:49,760 --> 00:16:50,860 Theoretically, you could disable it, 288 00:16:50,960 --> 00:16:53,000 but you don't want to do it, trust me, 289 00:16:53,040 --> 00:16:55,000 because we're going to install a hook, 290 00:16:55,120 --> 00:16:56,520 and that would be bad to do system-wide. 291 00:16:58,580 --> 00:17:00,400 Next thing we need to do is find a function 292 00:17:00,400 --> 00:17:02,780 that's likely to be used in the unpacked code. 293 00:17:02,960 --> 00:17:05,340 I like writefile, git command line is good. 294 00:17:05,820 --> 00:17:08,080 Basically, packer stubs, when they go to unpack a binary, 295 00:17:09,000 --> 00:17:12,640 there's not a whole lot of win32 functions there. 296 00:17:12,660 --> 00:17:15,900 We need to find one that the unpacked binary is going to use 297 00:17:15,900 --> 00:17:17,960 that the packer stub isn't going to use. 298 00:17:18,720 --> 00:17:20,100 I've never seen a packer stub, 299 00:17:20,320 --> 00:17:22,720 which in this process of unpacking the binary, 300 00:17:22,900 --> 00:17:23,920 calls writefile. 301 00:17:25,120 --> 00:17:26,640 Potentially, they could call git command line, 302 00:17:26,760 --> 00:17:27,880 but writefile is my favorite. 303 00:17:28,580 --> 00:17:30,460 I always hook that first, and if it doesn't work, 304 00:17:30,680 --> 00:17:31,680 eh, I move on. 305 00:17:33,800 --> 00:17:35,680 Then you've got to find the location of that function 306 00:17:35,680 --> 00:17:36,540 within kernel 32. 307 00:17:38,740 --> 00:17:41,580 I'm talking about the physical location within the file 308 00:17:41,580 --> 00:17:42,620 that that function starts. 309 00:17:42,840 --> 00:17:44,640 I'm going to omit the details of that process. 310 00:17:44,900 --> 00:17:46,920 It's a lot of math and calculating. 311 00:17:50,600 --> 00:17:52,580 Once you find where that function actually starts, 312 00:17:52,860 --> 00:17:54,820 you just replace the first two bytes with EBFE, 313 00:17:55,000 --> 00:17:56,680 which is an infinite loop in Intel. 314 00:17:57,420 --> 00:17:58,600 Just do that with a hex editor, 315 00:17:58,780 --> 00:18:00,140 and then you launch the packed binary, 316 00:18:00,400 --> 00:18:01,640 and as long as it calls that function 317 00:18:01,640 --> 00:18:04,000 that you just installed that little hook to, 318 00:18:04,200 --> 00:18:05,940 as soon as it hits that function call, 319 00:18:06,320 --> 00:18:10,260 the CPU usage spikes and the process is effectively hung. 320 00:18:10,260 --> 00:18:12,620 At this point, then I just attach to it 321 00:18:12,620 --> 00:18:14,160 and dump process memory. 322 00:18:14,620 --> 00:18:17,080 It's basically hung in a place 323 00:18:17,080 --> 00:18:19,060 where it can't do any anti-debugger checks 324 00:18:19,060 --> 00:18:21,620 unless potentially they have another thread running 325 00:18:21,620 --> 00:18:22,340 or something like that. 326 00:18:22,800 --> 00:18:24,200 I just thought I'd throw this in here, 327 00:18:24,280 --> 00:18:26,620 two slides to officially document something 328 00:18:26,620 --> 00:18:27,960 which I use on a daily basis, 329 00:18:28,060 --> 00:18:29,900 which I haven't seen anybody else document. 330 00:18:30,740 --> 00:18:31,400 Move on. 331 00:18:35,720 --> 00:18:37,900 Now I'm going to talk about the actual tool. 332 00:18:38,100 --> 00:18:39,240 I've named it API thief. 333 00:18:40,260 --> 00:18:41,880 There were better names out there at some point in time, 334 00:18:42,000 --> 00:18:43,800 but I'm searching on the net. 335 00:18:43,900 --> 00:18:45,080 Everybody's taking all the good ones, 336 00:18:45,200 --> 00:18:46,600 so I'm left with API thief. 337 00:18:49,780 --> 00:18:50,720 How this thing works, 338 00:18:50,840 --> 00:18:53,900 as opposed to doing the on disk API hooking 339 00:18:53,900 --> 00:18:55,820 like the Microsoft detours library 340 00:18:55,820 --> 00:18:57,400 or the technique I just showed you, 341 00:18:57,500 --> 00:18:59,980 this thing operates completely in memory. 342 00:19:00,160 --> 00:19:03,120 What we do is we launch a process in a suspended state, 343 00:19:03,320 --> 00:19:04,780 then we use process injection 344 00:19:05,300 --> 00:19:07,220 to inject the DLL into that process. 345 00:19:07,580 --> 00:19:09,040 This is interesting to note 346 00:19:09,040 --> 00:19:11,020 because we launched it in a suspended state. 347 00:19:11,160 --> 00:19:13,720 We do process injection to get that DLL loaded. 348 00:19:14,000 --> 00:19:15,380 That's operating on a thread 349 00:19:15,380 --> 00:19:17,820 that's executing before main thread ever starts. 350 00:19:18,200 --> 00:19:21,540 If you've ever played with processes in a suspended state, 351 00:19:22,360 --> 00:19:23,440 there's nothing going on. 352 00:19:23,520 --> 00:19:25,200 If it imports like 50 DLLs, 353 00:19:25,200 --> 00:19:27,040 as long as it's still in that suspended state, 354 00:19:27,220 --> 00:19:28,480 none of those DLLs get loaded. 355 00:19:28,600 --> 00:19:31,180 They only get loaded after you resume that main thread. 356 00:19:31,560 --> 00:19:34,420 This DLL that we inject operates completely 357 00:19:34,420 --> 00:19:37,540 before the actual main code of that program. 358 00:19:39,060 --> 00:19:40,660 It's the job of this injected DLL 359 00:19:40,660 --> 00:19:43,580 to run through the Win32 API functions 360 00:19:43,580 --> 00:19:44,980 and Kernel32 and all that 361 00:19:44,980 --> 00:19:47,120 and anything that we specify, really, 362 00:19:47,220 --> 00:19:49,240 to go through and hook them. 363 00:19:54,700 --> 00:19:57,480 Basically how it operates is it installs these hooks 364 00:19:57,480 --> 00:20:00,500 and they all point back to a single function dispatcher 365 00:20:00,500 --> 00:20:02,060 and then that function dispatcher is responsible 366 00:20:02,060 --> 00:20:03,960 for figuring out what it needs to do 367 00:20:03,960 --> 00:20:05,660 once the hooked function has actually been called. 368 00:20:06,640 --> 00:20:08,660 I'll talk about the design of it here in just a second, 369 00:20:08,720 --> 00:20:11,160 but basically there's Python on the back end 370 00:20:11,160 --> 00:20:12,820 which is responsible for figuring out 371 00:20:13,280 --> 00:20:14,980 A, if you should hook a function, 372 00:20:15,100 --> 00:20:17,200 and if so, what kind of hook should you install, 373 00:20:17,460 --> 00:20:20,820 and also once a hooked function has been called, 374 00:20:21,060 --> 00:20:22,020 what do you do with it? 375 00:20:22,120 --> 00:20:23,560 Do you intercept? Do you inspect? 376 00:20:23,960 --> 00:20:25,740 Do you write data to the process? 377 00:20:25,920 --> 00:20:28,920 Do you fix the return value to be a certain value? 378 00:20:29,500 --> 00:20:31,220 All that stuff is handled by Python. 379 00:20:33,100 --> 00:20:34,400 Quick note on the design. 380 00:20:36,100 --> 00:20:38,360 The injectable DLL is written completely in C 381 00:20:38,360 --> 00:20:39,740 with a lot of inline assembler. 382 00:20:40,380 --> 00:20:41,700 Not just because I love assembler, 383 00:20:41,760 --> 00:20:43,240 but there's very specific reasons 384 00:20:43,240 --> 00:20:46,900 the way that that function dispatcher needs to operate, 385 00:20:47,060 --> 00:20:47,900 and I'll show you that in a minute. 386 00:20:48,260 --> 00:20:49,980 It needs to be an assembler. 387 00:20:51,460 --> 00:20:53,100 It has a built-in disassembler. 388 00:20:53,120 --> 00:20:54,440 It's actually a complete disassembler, 389 00:20:54,460 --> 00:20:56,540 which is probably a bit more than is really needed 390 00:20:56,540 --> 00:20:59,200 for this function, but maybe on down the road 391 00:20:59,200 --> 00:21:00,140 we can do more with it. 392 00:21:00,280 --> 00:21:01,800 The GUI is written in C sharp. 393 00:21:04,400 --> 00:21:05,240 The iron Python is embedded, 394 00:21:05,360 --> 00:21:08,100 which is basically Python implemented 395 00:21:08,100 --> 00:21:09,700 in the .NET framework, 396 00:21:09,920 --> 00:21:13,680 so it's not going to be used in the same Python environment 397 00:21:13,680 --> 00:21:16,560 that may be installed on your box. 398 00:21:16,800 --> 00:21:17,520 So just be aware of that. 399 00:21:19,120 --> 00:21:21,640 But it does have a complete Python library along with it, 400 00:21:22,540 --> 00:21:24,640 and it pretty much works the same as you would imagine. 401 00:21:27,000 --> 00:21:27,560 All right. 402 00:21:27,860 --> 00:21:30,080 Now, how I differ from other types of inline hooking. 403 00:21:32,360 --> 00:21:33,500 The main difference is, 404 00:21:33,500 --> 00:21:35,800 I implement the hooks with a call instead of a jump. 405 00:21:36,120 --> 00:21:37,020 That's pretty rare. 406 00:21:37,760 --> 00:21:39,240 Normally, like from a malware perspective 407 00:21:39,240 --> 00:21:40,320 or a rootkit perspective, 408 00:21:40,760 --> 00:21:41,760 you're installing a hook, 409 00:21:41,900 --> 00:21:44,080 everybody just throws it into a jump, 410 00:21:44,160 --> 00:21:45,000 and they're fine, 411 00:21:45,200 --> 00:21:47,720 because they typically have like a one-to-one mapping 412 00:21:47,720 --> 00:21:48,940 on functions that they hook 413 00:21:49,420 --> 00:21:50,920 to handlers that they've installed. 414 00:21:51,080 --> 00:21:53,120 So if they hook create file, 415 00:21:53,320 --> 00:21:56,020 they have a function which handles create file 416 00:21:56,020 --> 00:21:57,420 and does all the create file stuff. 417 00:21:57,800 --> 00:22:00,300 We don't have that luxury with this tool, 418 00:22:00,420 --> 00:22:02,040 because this solution is very generic. 419 00:22:02,040 --> 00:22:04,140 At the time we're writing the tool, 420 00:22:04,280 --> 00:22:06,340 you have no idea how many functions you're going to hook, 421 00:22:06,460 --> 00:22:07,720 or what those functions are, 422 00:22:07,900 --> 00:22:08,760 or any of that stuff. 423 00:22:08,900 --> 00:22:10,020 That's all up to the Python code, 424 00:22:10,160 --> 00:22:11,480 which could be customized 425 00:22:11,480 --> 00:22:14,120 or actually written at runtime of the program. 426 00:22:14,480 --> 00:22:16,820 So we can't have individual functions 427 00:22:16,820 --> 00:22:18,220 inserted into the process 428 00:22:18,220 --> 00:22:20,180 which handle each one of these things uniquely. 429 00:22:20,680 --> 00:22:23,320 So basically, we use a call instruction instead of a jump 430 00:22:23,320 --> 00:22:25,980 so that all, every hook we install, 431 00:22:26,520 --> 00:22:28,480 they all point back to the same function 432 00:22:28,480 --> 00:22:29,440 which handles that hook. 433 00:22:29,780 --> 00:22:32,020 And if you know the difference between a call and a jump, 434 00:22:32,040 --> 00:22:34,660 is a call pushes a return address on the stack. 435 00:22:34,980 --> 00:22:37,880 So if we put the call instruction 436 00:22:37,880 --> 00:22:40,040 at the first few bytes of, let's say, create file, 437 00:22:40,280 --> 00:22:42,660 that return value that it pushes on the stack 438 00:22:42,660 --> 00:22:44,320 when it calls our dispatcher 439 00:22:44,320 --> 00:22:46,160 is going to be different than the return value 440 00:22:46,160 --> 00:22:48,320 coming from, let's say, write file. 441 00:22:48,560 --> 00:22:50,000 There are going to be two completely different values. 442 00:22:50,260 --> 00:22:53,080 And we can know exactly which function we're coming from, 443 00:22:53,260 --> 00:22:55,720 which hooked function, based on that return value. 444 00:22:55,920 --> 00:23:00,600 So we can write a single general hook handler 445 00:23:00,600 --> 00:23:02,660 which can handle any hook function, 446 00:23:02,840 --> 00:23:04,400 and we can hook as many functions as we want, 447 00:23:04,540 --> 00:23:05,380 and they're all fine. 448 00:23:06,800 --> 00:23:10,440 So that's just a little segue 449 00:23:10,440 --> 00:23:11,960 into why I'm using hook instead of jump. 450 00:23:12,180 --> 00:23:13,420 Nobody probably cares. 451 00:23:16,020 --> 00:23:18,360 All right, so all hooks point to the same dispatcher. 452 00:23:19,100 --> 00:23:20,780 Currently, I'm using named pipes 453 00:23:20,780 --> 00:23:22,120 to communicate back to the GUI. 454 00:23:22,260 --> 00:23:24,040 That can be sockets in the future. 455 00:23:24,120 --> 00:23:24,620 I don't really care. 456 00:23:25,380 --> 00:23:28,440 This was just, initially, I was just only thinking locally, 457 00:23:28,560 --> 00:23:30,580 and I just simply named pipes. 458 00:23:30,600 --> 00:23:31,640 No big deal. 459 00:23:34,500 --> 00:23:36,440 And there's a persistent thread running 460 00:23:36,440 --> 00:23:37,580 in the target process, 461 00:23:37,800 --> 00:23:41,700 which could be used for communications. 462 00:23:41,840 --> 00:23:43,400 For example, if the process is running 463 00:23:43,400 --> 00:23:45,780 and you just need to get a list of loaded modules 464 00:23:45,780 --> 00:23:46,900 or install a new hook, 465 00:23:47,820 --> 00:23:50,300 that's all happening in another behind-the-scenes thread. 466 00:23:50,840 --> 00:23:53,200 So you don't have to wait for a hooked function to be called 467 00:23:53,200 --> 00:23:55,640 to actually have some interaction with that process. 468 00:23:56,980 --> 00:23:57,640 All right. 469 00:23:59,020 --> 00:23:59,980 And like I said before, 470 00:23:59,980 --> 00:24:01,700 the Python layer handles all the logic 471 00:24:01,700 --> 00:24:03,820 on what functions to hook. 472 00:24:04,060 --> 00:24:05,580 So we're going to see some plug-ins and whatnot 473 00:24:05,580 --> 00:24:08,760 that go through and specify lists of functions to hook 474 00:24:08,760 --> 00:24:09,300 and whatnot, 475 00:24:09,540 --> 00:24:11,320 but all that stuff can be written by you 476 00:24:11,320 --> 00:24:12,360 once you download the package. 477 00:24:12,560 --> 00:24:15,640 The entire plug-in framework is in the Python layer, 478 00:24:15,740 --> 00:24:17,300 so it's completely up to you. 479 00:24:19,200 --> 00:24:20,860 Here's the actual function dispatcher. 480 00:24:20,920 --> 00:24:23,440 Like I said, there would be some assembly in the slides, 481 00:24:23,600 --> 00:24:25,760 so this is it, the next two slides. 482 00:24:26,480 --> 00:24:28,780 Just for anybody who is morbidly curious enough 483 00:24:28,780 --> 00:24:30,980 to know exactly how this thing is working, 484 00:24:31,200 --> 00:24:32,920 basically, you have to... 485 00:24:32,920 --> 00:24:35,220 This is a declspec naked function, 486 00:24:35,360 --> 00:24:36,120 which is in C, 487 00:24:36,600 --> 00:24:38,760 a function in which you yourself are responsible 488 00:24:38,760 --> 00:24:41,060 for setting up and destroying your own stack frame. 489 00:24:41,300 --> 00:24:43,440 It's kind of crazy, but the reason we have to do that is 490 00:24:43,440 --> 00:24:46,780 we need access to the actual return pointer on the stack. 491 00:24:46,960 --> 00:24:47,960 So we have that call instruction 492 00:24:47,960 --> 00:24:49,600 from wherever the hook is installed 493 00:24:49,600 --> 00:24:51,220 calling this function. 494 00:24:51,600 --> 00:24:54,100 This function needs to look at that return pointer 495 00:24:54,100 --> 00:24:56,060 on the stack so that it knows 496 00:24:56,060 --> 00:24:58,060 exactly what function called it. 497 00:24:58,060 --> 00:25:00,140 And the only way you can do that that I know of 498 00:25:01,120 --> 00:25:02,160 is declspec naked. 499 00:25:02,740 --> 00:25:03,880 That's portable, at least. 500 00:25:06,940 --> 00:25:09,660 We also grab the pointer from the stack 501 00:25:09,660 --> 00:25:12,480 of the original function that called this. 502 00:25:12,700 --> 00:25:14,840 The reason we actually look at that original pointer 503 00:25:14,840 --> 00:25:16,400 is so that we can filter out 504 00:25:18,680 --> 00:25:21,160 between where that API call got called from. 505 00:25:21,380 --> 00:25:23,460 So we're really only interested in calls 506 00:25:23,460 --> 00:25:24,960 that are coming from, like, our executable. 507 00:25:25,360 --> 00:25:27,980 So if I launch Notepad, I only care about calls 508 00:25:28,060 --> 00:25:28,820 from Notepad. 509 00:25:28,940 --> 00:25:31,820 I don't care about if Notepad calls kernel 32 510 00:25:32,280 --> 00:25:33,920 and kernel 32 calls something. 511 00:25:34,160 --> 00:25:35,200 I don't want to see that call. 512 00:25:35,360 --> 00:25:38,160 I only want to see the call from Notepad to kernel 32. 513 00:25:38,540 --> 00:25:40,220 So this is one reason that I'm going to get 514 00:25:40,220 --> 00:25:43,160 much more condensed data than Process Monitor. 515 00:25:43,360 --> 00:25:45,320 Process Monitor's not going to do any type of filtering 516 00:25:45,320 --> 00:25:47,920 based on where the API call is coming from. 517 00:25:48,820 --> 00:25:50,160 You're just going to get a dump of everything. 518 00:25:50,500 --> 00:25:52,520 So recursive calls, you're going to get all that 519 00:25:52,520 --> 00:25:53,340 in Process Monitor. 520 00:25:54,120 --> 00:25:54,780 Not in mine. 521 00:25:58,060 --> 00:25:59,000 Some people might be thinking, 522 00:25:59,080 --> 00:26:00,600 well, if you're going to be intercepting calls, 523 00:26:00,760 --> 00:26:03,320 there's kind of an issue here with standard call 524 00:26:03,320 --> 00:26:04,780 versus C-deckle calls. 525 00:26:05,700 --> 00:26:07,060 Mainly, there's a difference here between 526 00:26:07,060 --> 00:26:10,660 which function is responsible for fixing the stack 527 00:26:10,660 --> 00:26:12,460 based on the number of parameters passed in. 528 00:26:12,660 --> 00:26:14,600 It's kind of an issue, but here's basically 529 00:26:14,600 --> 00:26:15,340 how I handle that. 530 00:26:16,680 --> 00:26:19,140 It's up to, this is where we actually call 531 00:26:19,140 --> 00:26:20,380 process inspection commands. 532 00:26:20,460 --> 00:26:22,200 This will get commands from the GUI 533 00:26:22,200 --> 00:26:23,580 on what to do to the process. 534 00:26:23,820 --> 00:26:25,740 So it's actually responsible, it's the responsibility 535 00:26:25,740 --> 00:26:29,040 of the Python code to tell the hooked process 536 00:26:29,040 --> 00:26:32,020 how many bytes it needs to subtract off the stack 537 00:26:32,020 --> 00:26:33,820 at the beginning, or add to the stack 538 00:26:33,820 --> 00:26:34,620 at the end of the function. 539 00:26:35,100 --> 00:26:36,880 So it basically does that fix-ups 540 00:26:36,880 --> 00:26:39,760 as long as the Python code has done its job right. 541 00:26:39,920 --> 00:26:42,420 And you've told it, hey, this thing had two parameters, 542 00:26:42,620 --> 00:26:45,120 you know, fix the stack and let the program continue. 543 00:26:45,380 --> 00:26:47,820 And it basically puts a value on the stack 544 00:26:47,820 --> 00:26:50,880 and then plays with the stack pointer and returns to it. 545 00:26:50,960 --> 00:26:53,900 At this return, it actually jumps back to the original caller, 546 00:26:54,060 --> 00:26:55,060 not to where that hook is. 547 00:26:56,120 --> 00:26:58,040 So, and this is for an intercept, by the way. 548 00:26:58,100 --> 00:26:59,920 This is not for an inspect. 549 00:27:00,200 --> 00:27:01,800 Remember, inspect, it actually lets 550 00:27:01,800 --> 00:27:03,720 the original function get called. 551 00:27:03,880 --> 00:27:05,240 This is only in the case that we're actually 552 00:27:05,240 --> 00:27:07,580 intercepting that call and doing something else 553 00:27:07,580 --> 00:27:08,280 instead of it. 554 00:27:10,380 --> 00:27:10,940 All right. 555 00:27:11,940 --> 00:27:13,420 API Thief has a full protocol. 556 00:27:14,020 --> 00:27:15,180 There's other tools out there. 557 00:27:15,240 --> 00:27:18,100 Before I, actually, after I started this process, 558 00:27:18,220 --> 00:27:20,060 I learned about, like, iDefense had a tool 559 00:27:20,060 --> 00:27:22,480 called API Logger, which did similar. 560 00:27:22,580 --> 00:27:24,740 It installed a few fixed inline hooks 561 00:27:24,740 --> 00:27:26,920 and handled them in a very simple way. 562 00:27:27,300 --> 00:27:30,200 And it just kicked, blindly kicked data over a socket 563 00:27:30,600 --> 00:27:31,400 back to the GUI. 564 00:27:32,080 --> 00:27:34,220 The problem with this, though, not thread safe. 565 00:27:34,420 --> 00:27:36,720 So if you had multiple threads kicking stuff back, 566 00:27:37,280 --> 00:27:39,780 you're basically getting, you're going to get overlap data. 567 00:27:40,060 --> 00:27:42,100 You know, if one system call had a whole bunch of data, 568 00:27:42,180 --> 00:27:44,720 it's passing back and it did it over several sends. 569 00:27:45,520 --> 00:27:47,800 You're going to get all that data just kind of garbled together, 570 00:27:48,320 --> 00:27:50,020 presented to you, the reverse engineer. 571 00:27:50,320 --> 00:27:52,300 So as long as you, by implementing a protocol 572 00:27:52,300 --> 00:27:54,000 and having it all thread safe and all that, 573 00:27:54,740 --> 00:27:57,360 it gets nice, clean output back all the time. 574 00:27:57,940 --> 00:27:59,340 So that's why I went down that path. 575 00:28:01,920 --> 00:28:04,000 And the protocol supports a few primitives. 576 00:28:04,320 --> 00:28:06,160 And this is, these are commands that can be sent 577 00:28:06,160 --> 00:28:08,500 to the hooked function to get back data. 578 00:28:09,060 --> 00:28:11,640 So when a hooked function is called, 579 00:28:11,820 --> 00:28:15,040 the GUI can send it a request to get the ESP value, 580 00:28:15,200 --> 00:28:16,100 which is the stack pointer. 581 00:28:16,320 --> 00:28:18,360 And from that, then we can basically figure out 582 00:28:18,360 --> 00:28:19,980 what arguments are on the stack and all that jazz. 583 00:28:20,500 --> 00:28:22,060 You can also get the FS register, 584 00:28:22,300 --> 00:28:24,420 if you guys are familiar with what that points to. 585 00:28:24,740 --> 00:28:26,340 All the good juicy tidbits you can get 586 00:28:26,340 --> 00:28:27,800 once you know the value of that. 587 00:28:29,920 --> 00:28:31,800 We can set the EAX value. 588 00:28:31,960 --> 00:28:34,980 This is what the return value of the function will be. 589 00:28:35,260 --> 00:28:37,100 So in the case that we actually intercept a function, 590 00:28:37,680 --> 00:28:39,240 instead of just inspecting it, 591 00:28:39,300 --> 00:28:41,100 we want to set a return value, you know, 592 00:28:41,120 --> 00:28:43,040 so the rest of the program can continue. 593 00:28:43,400 --> 00:28:46,040 And this is the command that will actually set that. 594 00:28:46,380 --> 00:28:48,420 Set param size is what I was talking about earlier, 595 00:28:48,540 --> 00:28:50,300 where you want to set the number of arguments 596 00:28:50,300 --> 00:28:52,160 that are passed to the function. 597 00:28:52,980 --> 00:28:53,680 No big deal. 598 00:28:56,040 --> 00:28:58,320 Here's an example of the protocol being called. 599 00:28:58,480 --> 00:29:00,540 Here's a hooked function gets called. 600 00:29:00,620 --> 00:29:03,240 It sends a request to say, hey, a hook was called. 601 00:29:03,560 --> 00:29:06,660 The GUI tells it whether or not to do an intercept 602 00:29:06,660 --> 00:29:10,660 or to do an inspect with another packet that comes back. 603 00:29:11,680 --> 00:29:12,540 Message, technically. 604 00:29:14,580 --> 00:29:17,540 And we have a type message called response success. 605 00:29:17,680 --> 00:29:19,260 This is actually going to contain the data. 606 00:29:19,360 --> 00:29:22,660 So when he says, for example, get ESP value, 607 00:29:22,660 --> 00:29:25,900 the response success message is actually going to contain 608 00:29:25,900 --> 00:29:27,820 the four byte value of the ESP register. 609 00:29:29,460 --> 00:29:32,500 So this is just a little example of doing an intercept. 610 00:29:35,620 --> 00:29:37,620 All right, looking at the actual Python API, 611 00:29:37,740 --> 00:29:39,860 you don't have to know really much 612 00:29:39,860 --> 00:29:41,900 of how the protocol works. 613 00:29:42,120 --> 00:29:45,040 It's pretty much easy to handle from the Python layer. 614 00:29:45,220 --> 00:29:47,580 So the Python scripts have the ability, 615 00:29:47,760 --> 00:29:49,480 you have the functions inspect and intercept. 616 00:29:50,880 --> 00:29:52,640 So once your hook handler gets called, 617 00:29:52,660 --> 00:29:55,660 it's up to you in Python to know, hey, 618 00:29:55,740 --> 00:29:57,460 do I want to inspect this or do I want to intercept it? 619 00:29:57,620 --> 00:29:59,000 And you just simply say inspect, 620 00:29:59,340 --> 00:30:01,220 and it'll go down that path. 621 00:30:01,620 --> 00:30:03,460 Once you're finished doing whatever you want to do, 622 00:30:03,660 --> 00:30:06,420 you call continue, and then the program continues on. 623 00:30:06,880 --> 00:30:08,580 So you could potentially, like, if you wanted, like, 624 00:30:08,580 --> 00:30:10,960 a message box to pop up or something like that, 625 00:30:11,040 --> 00:30:14,200 you can have, or a mechanism to have you step through 626 00:30:14,200 --> 00:30:15,800 a program and making you click something 627 00:30:15,800 --> 00:30:18,440 to actually click through each system call, 628 00:30:18,580 --> 00:30:20,440 it's perfectly doable because it won't continue 629 00:30:20,440 --> 00:30:22,040 until you actually tell it to continue. 630 00:30:23,160 --> 00:30:25,580 Report is how we get information to the GUI console. 631 00:30:25,760 --> 00:30:29,060 You'll see it have a nice little scrolling window 632 00:30:29,060 --> 00:30:32,820 of messages coming out, and that's how you send a message. 633 00:30:34,080 --> 00:30:36,900 I have some wrappers here called git arg and git args. 634 00:30:36,900 --> 00:30:39,180 In Python, this will return either a single argument 635 00:30:39,180 --> 00:30:41,360 or an array of arguments to the function, 636 00:30:41,520 --> 00:30:44,140 and it's just going to return the D words on the stack. 637 00:30:44,340 --> 00:30:46,360 So it's, if the D word actually points to a string, 638 00:30:46,920 --> 00:30:48,100 you'll have to do some other things 639 00:30:48,100 --> 00:30:49,380 to actually go out and get that string. 640 00:30:49,660 --> 00:30:52,020 I have wrappers for read asking, read uniting, 641 00:30:52,040 --> 00:30:52,380 and code string. 642 00:30:55,520 --> 00:30:56,460 Set return value. 643 00:30:56,840 --> 00:30:59,100 And last but not least, alloc read and write. 644 00:30:59,260 --> 00:31:01,040 So we can allocate memory in the other process, 645 00:31:01,180 --> 00:31:02,220 read and write memory. 646 00:31:02,740 --> 00:31:05,260 These are just called the win32 functions behind them, 647 00:31:05,320 --> 00:31:07,040 so no big secret there. 648 00:31:07,180 --> 00:31:10,300 But once you have the ability to intercept a function 649 00:31:10,300 --> 00:31:12,960 and read, write, and allocate memory into it 650 00:31:12,960 --> 00:31:14,760 and set the return values, 651 00:31:15,260 --> 00:31:17,220 you can really pretty much do anything you want. 652 00:31:17,360 --> 00:31:19,080 You can recreate any API function 653 00:31:19,900 --> 00:31:21,520 and screw with it however you want. 654 00:31:23,220 --> 00:31:24,920 So here's an example Python script. 655 00:31:25,120 --> 00:31:28,260 This is actually a plug-in that handles beep. 656 00:31:28,500 --> 00:31:30,000 And this is the complete plug-in. 657 00:31:30,040 --> 00:31:31,420 I know it's hard to see in the back. 658 00:31:31,780 --> 00:31:35,540 I'll get to the important functionalities down here 659 00:31:35,960 --> 00:31:37,260 in the actual beep handler. 660 00:31:37,680 --> 00:31:39,260 And you can see back on this slide, 661 00:31:39,360 --> 00:31:40,720 I just called it register hook 662 00:31:40,720 --> 00:31:42,060 and told it what I wanted to hook. 663 00:31:42,480 --> 00:31:44,520 Register hook is implemented in Python too, 664 00:31:44,620 --> 00:31:45,860 so if you didn't like the way that works, 665 00:31:46,060 --> 00:31:47,020 you can do it yourself. 666 00:31:48,640 --> 00:31:50,180 So here's the handler for beep. 667 00:31:50,180 --> 00:31:53,080 And beep is just a function which supposedly takes 668 00:31:53,080 --> 00:31:58,140 the frequency to beep and the duration to beep. 669 00:31:58,860 --> 00:32:00,400 If you don't have the device driver, 670 00:32:00,540 --> 00:32:02,400 it's just going to error out. 671 00:32:02,660 --> 00:32:05,140 But it's a useless function pretty much nowadays. 672 00:32:05,700 --> 00:32:07,960 So I'm just showing it here to demonstrate. 673 00:32:08,200 --> 00:32:10,480 This particular function is going to intercept it, 674 00:32:10,520 --> 00:32:12,360 so the real beep is never going to get called. 675 00:32:13,180 --> 00:32:15,860 It's going to get the arguments that were passed into it. 676 00:32:15,900 --> 00:32:16,880 Like I said, there's two arguments. 677 00:32:17,040 --> 00:32:18,920 It's going to report those to our GUI console. 678 00:32:20,180 --> 00:32:22,480 And since this is a standard call function 679 00:32:22,480 --> 00:32:23,860 as opposed to a CDECL call, 680 00:32:24,080 --> 00:32:27,200 we have to set the stack pointer back 681 00:32:27,200 --> 00:32:28,480 because it's up to this function 682 00:32:28,480 --> 00:32:31,180 to adjust the stack after the call, 683 00:32:31,360 --> 00:32:32,860 not the function that called it. 684 00:32:33,100 --> 00:32:34,720 So we have to call set param size 685 00:32:34,720 --> 00:32:36,180 and tell it to set 8 bytes. 686 00:32:36,500 --> 00:32:38,280 And then I set the return value to 1, 687 00:32:38,460 --> 00:32:41,220 which in this case means success or true. 688 00:32:41,900 --> 00:32:43,260 And this will actually get handled. 689 00:32:46,560 --> 00:32:49,240 Here's an example of a get host by name sandbox function. 690 00:32:49,240 --> 00:32:50,460 Very simple. 691 00:32:50,660 --> 00:32:52,020 At the beginning, we call intercept. 692 00:32:52,720 --> 00:32:55,660 I get the first argument to the function with git arg. 693 00:32:55,900 --> 00:32:58,120 I read the ASCII string that that points to 694 00:32:58,120 --> 00:32:59,720 because you just passed it the name, 695 00:32:59,860 --> 00:33:01,520 the DNS name that you want to look up. 696 00:33:02,140 --> 00:33:04,960 So at this point, host contains that DNS name. 697 00:33:05,200 --> 00:33:06,920 I go ahead and report that to the console 698 00:33:06,920 --> 00:33:08,160 so we know what we're looking up. 699 00:33:08,900 --> 00:33:10,080 Then I allocate memory. 700 00:33:10,300 --> 00:33:11,280 I allocate 4 bytes. 701 00:33:11,800 --> 00:33:14,080 And I write this value into it. 702 00:33:14,280 --> 00:33:16,900 And that's 127.0.0.1. 703 00:33:17,200 --> 00:33:19,120 And then I set the return value to be 704 00:33:19,240 --> 00:33:20,880 that pointer that we just allocated. 705 00:33:21,160 --> 00:33:23,940 So this is going to handle git host by name. 706 00:33:24,080 --> 00:33:27,500 And git host by name is always going to return 127.0.0.1. 707 00:33:27,800 --> 00:33:29,740 And it's also going to report to the screen 708 00:33:30,180 --> 00:33:31,260 what we're trying to look up. 709 00:33:32,040 --> 00:33:33,740 And so you can see it's not all that complicated. 710 00:33:34,000 --> 00:33:34,680 And I apologize. 711 00:33:34,780 --> 00:33:36,180 I'm not the greatest Python programmer. 712 00:33:36,480 --> 00:33:37,960 I just implemented it here 713 00:33:37,960 --> 00:33:40,760 to have a decent little convenient extension language. 714 00:33:40,960 --> 00:33:42,860 I'm not a purist or anything. 715 00:33:42,980 --> 00:33:44,380 So if I'm doing stupid stuff, 716 00:33:45,320 --> 00:33:46,320 you can tell me about it. 717 00:33:46,360 --> 00:33:46,660 I don't care. 718 00:33:53,100 --> 00:33:53,880 All right. 719 00:33:59,920 --> 00:34:02,960 So here's API Thief. 720 00:34:03,880 --> 00:34:05,380 Like I said, it's very prototype-ish, 721 00:34:05,460 --> 00:34:06,420 so I don't have an icon yet. 722 00:34:08,740 --> 00:34:09,680 So what we have here, 723 00:34:09,860 --> 00:34:11,280 hopefully everybody can see, 724 00:34:11,440 --> 00:34:12,600 down here at the bottom, 725 00:34:12,660 --> 00:34:15,700 there's a text box where you can specify the command line. 726 00:34:15,900 --> 00:34:17,640 You can specify a full command line 727 00:34:17,640 --> 00:34:18,660 with arguments and everything. 728 00:34:19,460 --> 00:34:21,340 I'm just going to simplify the process here 729 00:34:21,340 --> 00:34:22,980 by clicking on the three dots 730 00:34:22,980 --> 00:34:24,900 to let you select an executable. 731 00:34:25,240 --> 00:34:26,660 And I wrote a small binary here 732 00:34:26,660 --> 00:34:28,000 just to get a really simple test. 733 00:34:29,320 --> 00:34:31,280 All this thing does is call, like, create file, 734 00:34:31,460 --> 00:34:32,000 then it calls beep, 735 00:34:32,460 --> 00:34:33,740 and it calls a few other things. 736 00:34:36,880 --> 00:34:38,320 So once I've selected that, 737 00:34:38,360 --> 00:34:39,600 here's the command line down here. 738 00:34:40,120 --> 00:34:41,800 There's really nothing happening yet. 739 00:34:42,000 --> 00:34:43,500 We have to hit this initialize button. 740 00:34:44,480 --> 00:34:45,840 What initialize is going to do 741 00:34:45,840 --> 00:34:48,660 is spawn the process in a suspended state, 742 00:34:48,820 --> 00:34:49,780 then inject the DLL. 743 00:34:51,760 --> 00:34:53,060 Whenever I hit initialize, though, 744 00:34:53,120 --> 00:34:55,120 I have to make sure that my plug-ins are selected, 745 00:34:55,200 --> 00:34:56,800 because I can't change those after the fact. 746 00:34:58,180 --> 00:34:59,380 And the plug-ins I have here 747 00:34:59,380 --> 00:35:01,300 is a basic Win32 API monitor, 748 00:35:01,500 --> 00:35:02,800 which I'll show you some of the code for. 749 00:35:02,880 --> 00:35:03,420 It's really simple. 750 00:35:04,180 --> 00:35:05,720 And that git host by name trap, 751 00:35:06,080 --> 00:35:07,660 I'm going to go ahead and enable that plug-in. 752 00:35:07,800 --> 00:35:10,000 There's another one that comes with the package on my website 753 00:35:10,000 --> 00:35:11,700 called the load library hook. 754 00:35:12,180 --> 00:35:13,600 I'm not going to use this for these demos. 755 00:35:13,720 --> 00:35:15,820 Basically, you'll need this plug-in 756 00:35:15,840 --> 00:35:18,260 if you need to hook a DLL 757 00:35:18,260 --> 00:35:21,640 that gets called later by load library at runtime, 758 00:35:21,960 --> 00:35:24,800 go ahead and load the load library hook plug-in. 759 00:35:24,960 --> 00:35:26,980 So it'll basically recurse down anything 760 00:35:26,980 --> 00:35:28,540 that's loaded at runtime, 761 00:35:28,800 --> 00:35:30,100 because currently it's only going to hook 762 00:35:30,100 --> 00:35:32,600 what it's going to see in memory to begin with. 763 00:35:33,740 --> 00:35:35,660 So I call initialize. 764 00:35:37,580 --> 00:35:39,340 And you see create a process, 765 00:35:40,300 --> 00:35:42,200 injected API thief dot DLL. 766 00:35:43,660 --> 00:35:45,200 API thief initialized, 767 00:35:45,220 --> 00:35:45,740 ready to launch. 768 00:35:45,840 --> 00:35:48,020 So the next step would be to click launch. 769 00:35:48,280 --> 00:35:49,740 Let me go ahead and browse a few things. 770 00:35:50,420 --> 00:35:52,300 This is kind of useless data at this point, 771 00:35:52,420 --> 00:35:54,980 but it went ahead and reported back to me 772 00:35:54,980 --> 00:35:56,920 a list of loaded modules in this process space. 773 00:35:57,620 --> 00:35:58,980 I also have down here, 774 00:35:59,100 --> 00:36:00,720 I can browse the hooks that are installed. 775 00:36:01,020 --> 00:36:04,100 So I have that basic Win32 API plug-in loaded, 776 00:36:04,280 --> 00:36:08,420 and that's hooking a whole bunch of important API functions. 777 00:36:08,500 --> 00:36:09,460 So I can browse the list. 778 00:36:09,600 --> 00:36:11,280 It's quite extensive, and I apologize 779 00:36:11,280 --> 00:36:12,520 it's not in alphabetical order. 780 00:36:14,480 --> 00:36:17,500 And I loaded the plug-in for git host by name, 781 00:36:17,700 --> 00:36:18,480 and you can see 782 00:36:20,680 --> 00:36:23,460 Winsock232.dll has git host by name hooked. 783 00:36:23,940 --> 00:36:25,480 You probably can't see all the way in the back, 784 00:36:25,560 --> 00:36:26,960 but there's magnifying glasses, 785 00:36:27,100 --> 00:36:28,340 which mean inspect, 786 00:36:28,620 --> 00:36:29,900 and then there's the little script icons, 787 00:36:30,100 --> 00:36:31,300 which means it's going to intercept. 788 00:36:31,620 --> 00:36:32,360 It's going to run a script 789 00:36:32,360 --> 00:36:34,120 instead of calling that function. 790 00:36:35,920 --> 00:36:38,340 And there's also a script window. 791 00:36:38,500 --> 00:36:40,500 This is, to be perfectly honest, 792 00:36:40,540 --> 00:36:41,660 completely useless right now. 793 00:36:41,660 --> 00:36:43,360 In this release of the tool, 794 00:36:43,520 --> 00:36:45,300 eventually, maybe it'll be cool. 795 00:36:47,620 --> 00:36:48,060 Oops. 796 00:36:49,820 --> 00:36:50,260 But... 797 00:36:51,080 --> 00:36:52,300 Oh, I've got to launch it first. 798 00:36:53,680 --> 00:36:54,720 Let me go ahead and launch. 799 00:36:56,020 --> 00:36:57,180 The script broke. 800 00:36:57,460 --> 00:36:57,680 Anyway. 801 00:36:59,400 --> 00:37:00,280 I launched... 802 00:37:00,280 --> 00:37:01,720 So I went ahead and clicked launch, 803 00:37:01,940 --> 00:37:04,040 and it kind of... 804 00:37:04,040 --> 00:37:05,080 Oh, Tim? Okay. 805 00:37:06,540 --> 00:37:09,480 You can see it called git system time is file time. 806 00:37:09,620 --> 00:37:10,360 That's something that happens 807 00:37:10,360 --> 00:37:12,600 in the C runtime code at startup. 808 00:37:12,900 --> 00:37:13,960 And in this case, 809 00:37:14,020 --> 00:37:16,140 that's the only kernel 32 function that was called. 810 00:37:16,360 --> 00:37:17,840 There are more functions that get called. 811 00:37:17,920 --> 00:37:19,560 It's just I only have the plug-in 812 00:37:19,560 --> 00:37:21,260 to trap kernel 32 functions. 813 00:37:21,500 --> 00:37:22,940 So it caught that one. 814 00:37:23,040 --> 00:37:25,400 It caught a load library call on PSAPI, 815 00:37:25,480 --> 00:37:26,600 which is in the code. 816 00:37:27,300 --> 00:37:28,640 Caught a call to create file, 817 00:37:28,860 --> 00:37:30,420 C column backslash test dot text. 818 00:37:31,220 --> 00:37:32,620 You can see here it called beep, 819 00:37:32,820 --> 00:37:33,560 and then it called sleep. 820 00:37:34,120 --> 00:37:36,320 Sleep is an interesting one for malware analysis, too, 821 00:37:36,400 --> 00:37:38,060 because if we can intercept sleep 822 00:37:38,060 --> 00:37:40,260 and just report that it's trying to sleep, 823 00:37:40,360 --> 00:37:41,360 and then not actually sleep, 824 00:37:41,500 --> 00:37:43,320 that can simplify a lot of people's lives. 825 00:37:43,420 --> 00:37:43,900 Because a lot of times, 826 00:37:43,900 --> 00:37:44,800 malware will try to wait 827 00:37:44,800 --> 00:37:46,780 for some crazy amount of time, 828 00:37:46,880 --> 00:37:47,860 and you'd have to go through 829 00:37:47,860 --> 00:37:49,280 and do a lot of static analysis 830 00:37:49,280 --> 00:37:50,960 to figure out how long it's trying to wait for. 831 00:37:51,620 --> 00:37:52,440 In this case, 832 00:37:52,560 --> 00:37:55,360 we can basically just tell it never sleep. 833 00:37:56,420 --> 00:37:59,020 So this is a very simple list of functions, 834 00:37:59,120 --> 00:38:00,700 and this basically maps exactly 835 00:38:00,700 --> 00:38:02,900 to the function of this program. 836 00:38:03,000 --> 00:38:03,700 The main function, 837 00:38:03,800 --> 00:38:05,300 I just coded a few things really quick, 838 00:38:05,440 --> 00:38:06,640 and you see that's all I get. 839 00:38:07,700 --> 00:38:08,960 I should have launched... 840 00:38:09,340 --> 00:38:11,160 I should have been monitoring with process monitor 841 00:38:11,160 --> 00:38:11,740 while I did that. 842 00:38:12,080 --> 00:38:12,340 Oh, well. 843 00:38:12,400 --> 00:38:13,120 On the next demo, 844 00:38:13,880 --> 00:38:14,500 we'll do that. 845 00:38:15,060 --> 00:38:15,420 Oops. 846 00:38:17,980 --> 00:38:19,760 So let me do a more complicated one. 847 00:38:20,060 --> 00:38:20,780 I'm going to do... 848 00:38:20,780 --> 00:38:21,260 Oops. 849 00:38:21,680 --> 00:38:24,580 I'm going to do notepad dot exe. 850 00:38:26,320 --> 00:38:27,120 Just so you can see, 851 00:38:27,160 --> 00:38:28,240 I'm not completely full of shit 852 00:38:28,240 --> 00:38:29,060 and using rigged demos. 853 00:38:29,740 --> 00:38:30,360 Notepad is... 854 00:38:30,360 --> 00:38:32,280 It's not the most complicated program in the world, 855 00:38:32,320 --> 00:38:33,420 but it's at least complicated enough 856 00:38:33,420 --> 00:38:35,200 that it will screw up your life. 857 00:38:36,320 --> 00:38:38,620 I'm going to just do the basic Win32 API, 858 00:38:38,840 --> 00:38:38,940 but I'm going to do 859 00:38:38,960 --> 00:38:39,100 process monitor, 860 00:38:39,980 --> 00:38:40,860 click initialize, 861 00:38:41,620 --> 00:38:42,060 and... 862 00:38:42,680 --> 00:38:43,120 Oh. 863 00:38:43,820 --> 00:38:45,580 Go ahead and launch process monitor here. 864 00:38:47,820 --> 00:38:48,420 All right. 865 00:38:49,520 --> 00:38:50,900 I already have a filter set up. 866 00:38:50,960 --> 00:38:51,260 That's why. 867 00:38:51,420 --> 00:38:51,740 Anyway. 868 00:38:52,320 --> 00:38:52,880 All right. 869 00:38:53,000 --> 00:38:54,160 So I launched notepad. 870 00:38:54,260 --> 00:38:55,400 Notepad is now popped up 871 00:38:55,400 --> 00:38:56,260 on the screen over here. 872 00:38:56,900 --> 00:38:58,080 You can see my data. 873 00:38:58,260 --> 00:38:59,440 I don't have very much. 874 00:38:59,680 --> 00:39:00,580 I have, you know, 875 00:39:00,660 --> 00:39:01,760 get proc address here 876 00:39:01,760 --> 00:39:02,780 for register pin app. 877 00:39:03,020 --> 00:39:04,820 I have a few string compare functions. 878 00:39:05,180 --> 00:39:06,860 These are implemented in kernel 32. 879 00:39:07,040 --> 00:39:07,780 There's string comparison, 880 00:39:08,040 --> 00:39:08,560 string cat, 881 00:39:08,960 --> 00:39:09,380 all that. 882 00:39:09,520 --> 00:39:10,540 And this is something 883 00:39:10,540 --> 00:39:11,560 you're never going to see 884 00:39:11,560 --> 00:39:12,640 with procmon. 885 00:39:12,700 --> 00:39:13,320 You're never going to see 886 00:39:13,320 --> 00:39:14,140 that this process 887 00:39:14,140 --> 00:39:15,200 was doing a string comparison. 888 00:39:15,440 --> 00:39:16,540 For example, you know, 889 00:39:16,560 --> 00:39:17,760 untitled notepad, 890 00:39:18,020 --> 00:39:18,880 a string cat, 891 00:39:19,100 --> 00:39:20,440 because that's not a system call. 892 00:39:20,600 --> 00:39:23,520 That's only a kernel 32 function call. 893 00:39:23,800 --> 00:39:24,920 So here I am scrolling through 894 00:39:24,920 --> 00:39:26,020 the process monitor output, 895 00:39:26,220 --> 00:39:28,140 and I have 327 events. 896 00:39:29,780 --> 00:39:31,380 Most of this has nothing to do 897 00:39:31,380 --> 00:39:32,660 with what the programmers 898 00:39:32,660 --> 00:39:34,680 of notepad.exe designed. 899 00:39:34,840 --> 00:39:36,080 This is just stuff that's happening. 900 00:39:36,280 --> 00:39:36,900 For example, 901 00:39:36,900 --> 00:39:38,200 every DLL that gets loaded, 902 00:39:38,200 --> 00:39:39,160 you have to, 903 00:39:39,180 --> 00:39:40,320 there has to be a create file 904 00:39:40,320 --> 00:39:41,020 for that DLL 905 00:39:41,020 --> 00:39:42,420 and all this other stuff. 906 00:39:42,780 --> 00:39:44,040 There's a lot of registry keys 907 00:39:44,040 --> 00:39:44,700 that just happen. 908 00:39:44,940 --> 00:39:46,200 This is stuff we don't care about 909 00:39:46,200 --> 00:39:47,780 for malware analysis, 910 00:39:48,020 --> 00:39:49,400 or for the most part, 911 00:39:49,420 --> 00:39:49,960 reverse engineering. 912 00:39:52,720 --> 00:39:53,800 In this particular example, 913 00:39:53,920 --> 00:39:55,040 I really needed to hook more 914 00:39:55,040 --> 00:39:56,440 user 32 functions 915 00:39:56,440 --> 00:39:57,040 to get, 916 00:39:57,060 --> 00:39:58,000 to get the idea 917 00:39:58,000 --> 00:39:58,440 of what's going on, 918 00:39:58,520 --> 00:39:59,380 but you can see the idea 919 00:39:59,380 --> 00:40:00,260 of where we're going with this. 920 00:40:02,600 --> 00:40:02,960 Yeah. 921 00:40:05,580 --> 00:40:06,540 Go ahead and close that. 922 00:40:07,280 --> 00:40:07,640 Okay. 923 00:40:07,820 --> 00:40:08,180 So, 924 00:40:10,220 --> 00:40:11,080 oh, actually, 925 00:40:12,720 --> 00:40:13,440 there's one more thing 926 00:40:13,440 --> 00:40:14,380 I wanted to do with notepad. 927 00:40:23,080 --> 00:40:24,720 I have to do notepad. 928 00:40:26,620 --> 00:40:28,240 Go ahead and launch this again. 929 00:40:30,700 --> 00:40:31,280 I want to, 930 00:40:31,340 --> 00:40:31,460 like, 931 00:40:31,460 --> 00:40:32,300 save a file out. 932 00:40:32,540 --> 00:40:32,940 So, 933 00:40:32,940 --> 00:40:33,260 I'm going to say, 934 00:40:33,320 --> 00:40:33,460 you know, 935 00:40:33,520 --> 00:40:33,800 hi, 936 00:40:34,420 --> 00:40:35,040 DEF CON, 937 00:40:36,740 --> 00:40:37,480 save as. 938 00:40:37,760 --> 00:40:38,160 Okay. 939 00:40:39,660 --> 00:40:40,620 Test.txt. 940 00:40:41,960 --> 00:40:42,680 And then, 941 00:40:42,740 --> 00:40:43,580 down here at the bottom, 942 00:40:43,680 --> 00:40:44,780 you'll see what 943 00:40:44,780 --> 00:40:45,680 the functions are called. 944 00:40:45,800 --> 00:40:46,680 There's the string cat 945 00:40:46,680 --> 00:40:48,140 on test.txt. 946 00:40:48,300 --> 00:40:49,580 There was a create file up here, 947 00:40:49,740 --> 00:40:50,920 and I called a write file. 948 00:40:52,160 --> 00:40:53,120 Set into file. 949 00:40:53,300 --> 00:40:54,380 Much less data 950 00:40:54,380 --> 00:40:55,720 than this, 951 00:40:55,920 --> 00:40:56,600 which is showing us 952 00:40:56,600 --> 00:40:58,140 15,000 events 953 00:40:58,140 --> 00:40:59,280 for this same process. 954 00:41:00,380 --> 00:41:00,860 Yeah. 955 00:41:02,140 --> 00:41:02,620 . 956 00:41:02,620 --> 00:41:02,920 . 957 00:41:02,920 --> 00:41:03,480 . 958 00:41:04,120 --> 00:41:04,600 . 959 00:41:04,600 --> 00:41:04,780 . 960 00:41:04,780 --> 00:41:05,480 . 961 00:41:05,480 --> 00:41:05,520 . 962 00:41:05,520 --> 00:41:05,760 . 963 00:41:05,760 --> 00:41:06,120 . 964 00:41:07,680 --> 00:41:08,160 . 965 00:41:09,860 --> 00:41:10,660 And,全 966 00:41:11,960 --> 00:41:12,760 I think 967 00:41:12,760 --> 00:41:13,980 I'm getting , um, 968 00:41:15,760 --> 00:41:16,160 ushered 969 00:41:16,160 --> 00:41:16,380 off the 970 00:41:16,380 --> 00:41:17,560 stage here in like one minute. 971 00:41:17,840 --> 00:41:18,240 So, 972 00:41:19,020 --> 00:41:20,060 uh, my tools 973 00:41:20,060 --> 00:41:20,440 are available 974 00:41:20,440 --> 00:41:20,860 right now 975 00:41:20,860 --> 00:41:22,180 at rnicrosoft.net. 976 00:41:22,340 --> 00:41:23,780 That's not an M. , 977 00:41:23,780 --> 00:41:25,220 and don't sue me if 978 00:41:25,220 --> 00:41:25,320 you 979 00:41:25,320 --> 00:41:26,380 are, work for a 980 00:41:26,380 --> 00:41:27,780 company that might take 981 00:41:27,780 --> 00:41:29,480 offense. Um, 982 00:41:30,660 --> 00:41:31,060 eventually, 983 00:41:31,200 --> 00:41:31,600 the tool will be 984 00:41:31,600 --> 00:41:31,880 up on 985 00:41:31,880 --> 00:41:32,260 mandiant 986 00:41:32,260 --> 00:41:33,300 .com, and you 987 00:41:33,300 --> 00:41:34,800 can contact me here. If 988 00:41:34,800 --> 00:41:36,400 you have major bug reports, uh, 989 00:41:36,520 --> 00:41:37,520 in the next couple months, 990 00:41:38,180 --> 00:41:38,780 Don't even bother. 991 00:41:38,900 --> 00:41:41,280 I know anybody can send an email. 992 00:41:41,800 --> 00:41:44,100 There's tons of bugs right now, 993 00:41:44,200 --> 00:41:47,700 so maybe hold off a little bit on calling me out 994 00:41:47,700 --> 00:41:49,640 and trying to yell at me and scream at me. 995 00:41:50,140 --> 00:41:51,020 Just be nice. 996 00:41:51,760 --> 00:41:52,680 I'll show you a puppy. 997 00:41:55,160 --> 00:41:56,180 Yeah, be nice. 998 00:41:59,480 --> 00:42:00,780 All right, well, thank you. 999 00:42:00,860 --> 00:42:01,500 You guys have been great. 1000 00:42:02,720 --> 00:42:03,440 Thank you.