1 00:00:00,000 --> 00:00:01,580 It's about time, so I'm going to go ahead and get started. 2 00:00:02,160 --> 00:00:03,200 My name is Chris Eagle. 3 00:00:03,380 --> 00:00:07,640 I am on the staff at a place called the Naval Postgraduate School in Monterey, 4 00:00:07,720 --> 00:00:14,700 and today I'm going to talk about sort of attacking obfuscated code using IDA Pro as the analysis tool. 5 00:00:18,180 --> 00:00:25,720 Go through the introduction, talk about the operation of this tool that I'm going to introduce, 6 00:00:25,860 --> 00:00:28,440 and then we'll do some demos of the tool and work. 7 00:00:29,520 --> 00:00:33,400 First thing, I highly recommend that you move closer to the screens, not in, 8 00:00:33,480 --> 00:00:35,520 because I guess we have two screens, so you can move out. 9 00:00:37,020 --> 00:00:42,400 But I'm going to be doing some demos in IDA Pro, and you cannot change the font size in IDA. 10 00:00:42,520 --> 00:00:47,220 So we're going to get what we get, and if you're up close, you'll probably see the stuff, 11 00:00:47,380 --> 00:00:52,700 and if you're in the back, you're going to probably strain your eyes or miss the finer details. 12 00:00:52,840 --> 00:00:53,960 I'll try and talk through it all. 13 00:00:54,000 --> 00:00:55,160 If you want to stay back there, that's fine. 14 00:00:57,180 --> 00:00:57,500 Okay. 15 00:00:57,600 --> 00:00:58,420 So a little bit about IDA Pro. 16 00:00:59,220 --> 00:01:03,000 IDA Pro, for those who don't know, hopefully most of you all are familiar with it, 17 00:01:03,860 --> 00:01:08,600 is perhaps one of the premier reverse engineering tools that's out there. 18 00:01:08,740 --> 00:01:13,100 It's a disassembler that can handle many families of assembly language, 19 00:01:13,200 --> 00:01:19,400 understands many executable file formats, and automates a lot of analysis tasks. 20 00:01:19,540 --> 00:01:23,660 It really makes life easy on the reverse engineering front. 21 00:01:24,600 --> 00:01:27,740 It's a Windows tool, so forgive me if you're not a Windows fan, 22 00:01:27,800 --> 00:01:28,420 but that's why I'm in. 23 00:01:28,440 --> 00:01:30,400 I'm in Windows today, so I can run IDA. 24 00:01:31,100 --> 00:01:33,640 As I understand it, and there's probably smarter people out here, 25 00:01:33,800 --> 00:01:37,020 they are working on a Linux, at least, analysis engine. 26 00:01:37,480 --> 00:01:45,040 Maybe not the GUI side, but it may be running on the Linux side of the house in the near future, 27 00:01:45,660 --> 00:01:46,860 or not so near future. 28 00:01:46,980 --> 00:01:48,300 It depends on when it is time to get to it. 29 00:01:49,840 --> 00:01:52,840 So what I'm going to talk about today is a plug-in that I've developed, 30 00:01:53,820 --> 00:01:58,120 and for lack of anything better, it's this x86 emulator plug-in. 31 00:01:59,540 --> 00:02:05,300 And what it does is it allows you to do some emulated execution of instructions within IDA. 32 00:02:05,380 --> 00:02:09,160 So basically, you're looking at the disassembly in IDA. 33 00:02:09,200 --> 00:02:12,980 Only x86 is all I ever intend to work on. 34 00:02:14,420 --> 00:02:17,380 But one of the things I find useful when I'm reverse engineering, 35 00:02:17,620 --> 00:02:20,040 A, I end up doing a lot of hand tracing through code. 36 00:02:20,240 --> 00:02:21,080 What is this code doing? 37 00:02:21,340 --> 00:02:23,080 Keeping track of register values and whatnot. 38 00:02:23,560 --> 00:02:27,340 And I had always wished I had something that would do it for me. 39 00:02:27,380 --> 00:02:28,140 Just step, step, step. 40 00:02:28,440 --> 00:02:29,600 Boom, you know, what's in EAX now? 41 00:02:30,160 --> 00:02:33,260 Okay, well, you can do emulated execution. 42 00:02:33,440 --> 00:02:35,000 You can see the code right there in front of you. 43 00:02:35,060 --> 00:02:37,100 Let somebody else execute it, and that's what the plug-in does. 44 00:02:37,520 --> 00:02:38,660 Okay, it's written in C++. 45 00:02:38,860 --> 00:02:41,740 It's a visual C++ project at the moment, 46 00:02:41,800 --> 00:02:45,240 and you can get it for free out at SourceForge right now. 47 00:02:45,700 --> 00:02:51,100 I think the latest release of the tool is also on the conference CD. 48 00:02:53,360 --> 00:02:56,200 Again, you know, why I did it, hand tracing through assembly language of pain. 49 00:02:58,900 --> 00:03:03,620 So, anti-reverse engineering techniques, which is why I really developed this thing, 50 00:03:04,140 --> 00:03:06,560 work very hard to try to obfuscate the code. 51 00:03:07,020 --> 00:03:09,220 Okay, so whether they're doing really unusual things, 52 00:03:09,380 --> 00:03:10,740 whether they're obfuscating the code path, 53 00:03:10,900 --> 00:03:14,020 jumping to the middle of instructions, self-modifying code, 54 00:03:14,300 --> 00:03:15,300 all this kind of stuff. 55 00:03:15,640 --> 00:03:20,060 If it's self-modifying code, IDA is just going to show you the original unmodified code. 56 00:03:20,520 --> 00:03:22,380 Okay, so how are you going to get at the underlying code 57 00:03:22,380 --> 00:03:24,800 once it's been unrolled at runtime? 58 00:03:25,160 --> 00:03:26,740 Yeah, you're never going to do it in IDA 59 00:03:26,740 --> 00:03:28,420 unless you modify it. 60 00:03:28,420 --> 00:03:29,680 Modify the stuff yourself. 61 00:03:29,840 --> 00:03:30,900 You can do it with IDA scripts, 62 00:03:31,180 --> 00:03:35,080 or I've taken an angle of doing it with a plug-in. 63 00:03:38,000 --> 00:03:41,920 So, you know, there's a lot of reasons you might obfuscate code, 64 00:03:42,000 --> 00:03:44,520 and I'm not going to get into the merits of any of them, 65 00:03:44,600 --> 00:03:47,360 but a big place you see this stuff these days 66 00:03:47,360 --> 00:03:51,620 is in virtually any worm or virus that comes rolling around the Internet 67 00:03:52,240 --> 00:03:54,980 is usually obfuscated in some way. 68 00:03:56,200 --> 00:03:58,020 Okay, there's a couple of examples there. 69 00:03:58,080 --> 00:03:58,400 UPS. 70 00:03:58,420 --> 00:03:59,260 PDX is pretty common. 71 00:03:59,420 --> 00:03:59,860 TLOC. 72 00:04:00,080 --> 00:04:00,520 ASPAC. 73 00:04:01,000 --> 00:04:03,540 In fact, IDA itself is protected with ASPAC. 74 00:04:03,720 --> 00:04:05,660 So if you want to reverse engineer IDA, 75 00:04:05,720 --> 00:04:07,700 you've got to get through the ASPAC protection. 76 00:04:08,340 --> 00:04:09,700 In the Linux world, 77 00:04:10,020 --> 00:04:12,360 TESO released BurnEye a few years ago, 78 00:04:12,540 --> 00:04:14,440 and there's another tool out there called Shiva. 79 00:04:14,700 --> 00:04:17,960 We don't see worms protected with this stuff so much, 80 00:04:18,560 --> 00:04:21,220 but it does the same sort of thing, right? 81 00:04:21,260 --> 00:04:23,760 It obfuscates code and makes it difficult to see what's underneath. 82 00:04:23,980 --> 00:04:25,900 So whether it's hostile code or not, 83 00:04:26,500 --> 00:04:28,160 you still have to fight through this, 84 00:04:28,160 --> 00:04:30,360 this layer just to see what might be underneath. 85 00:04:32,880 --> 00:04:36,400 So the reason to do this is to get at the underlying executable. 86 00:04:36,480 --> 00:04:38,240 The last thing you want to do is spend your time reverse engineering 87 00:04:38,240 --> 00:04:40,860 the obfuscation piece. 88 00:04:41,400 --> 00:04:43,900 Most of these things start up, you have this obfuscation piece. 89 00:04:44,120 --> 00:04:45,440 The first thing that's going to happen at runtime 90 00:04:45,440 --> 00:04:49,380 is the deobfuscation runs initially 91 00:04:50,640 --> 00:04:54,480 that reconstitutes the original binary in some form 92 00:04:54,480 --> 00:04:57,140 and then passes control off to that binary. 93 00:04:57,260 --> 00:04:58,140 Now, Shiva takes a little bit of time to do that, but it's not going to happen. 94 00:04:58,140 --> 00:04:58,820 It's a little different approach. 95 00:05:00,040 --> 00:05:03,500 But essentially, you've got to unprotect the binary 96 00:05:03,500 --> 00:05:05,760 before you can ever pass execution to it. 97 00:05:06,160 --> 00:05:08,300 So we want to get at the stuff underneath. 98 00:05:10,000 --> 00:05:11,280 Again, worms, viruses, 99 00:05:11,440 --> 00:05:13,980 so it's nice to be able to get at that stuff quickly 100 00:05:13,980 --> 00:05:16,580 so that you can turn around and the antivirus vendors 101 00:05:16,580 --> 00:05:18,520 develop in signatures or what have you. 102 00:05:18,580 --> 00:05:20,720 Maybe you want to know if there's hidden functionality, 103 00:05:20,940 --> 00:05:23,760 backdoor functionality in the worm or the virus, 104 00:05:23,920 --> 00:05:26,960 and you want to get at it for further analysis of the code. 105 00:05:27,120 --> 00:05:28,040 I mean, it's easy to see that. 106 00:05:28,040 --> 00:05:28,900 This thing propagates. 107 00:05:28,940 --> 00:05:30,440 It's easy to see that a worm propagates 108 00:05:31,280 --> 00:05:33,160 through a particular vulnerability, perhaps. 109 00:05:33,540 --> 00:05:36,560 But the more detailed analysis tells you 110 00:05:36,560 --> 00:05:39,100 whether there's some time-delayed feature in there 111 00:05:39,100 --> 00:05:41,040 like Code Red had that was going to do 112 00:05:41,040 --> 00:05:42,900 the denial of service on the White House 113 00:05:42,900 --> 00:05:44,200 or whatever it was, 114 00:05:44,340 --> 00:05:46,140 or whether there's any other backdoor features 115 00:05:46,140 --> 00:05:50,700 that aren't apparent in the worm's propagation mechanism. 116 00:05:51,500 --> 00:05:52,840 And so that's the challenge, 117 00:05:53,000 --> 00:05:54,800 and that's why I developed the plug-ins. 118 00:05:54,880 --> 00:05:57,540 It's to work through in IDA, 119 00:05:57,540 --> 00:05:59,740 without running a binary, a malicious piece of code, 120 00:05:59,860 --> 00:06:02,960 to get to the real reverse engineering, 121 00:06:03,200 --> 00:06:05,140 which was what is the underlying code doing. 122 00:06:06,180 --> 00:06:07,820 So the way this thing works is, 123 00:06:08,720 --> 00:06:10,920 in IDA Pro, for those who have never used it, 124 00:06:11,320 --> 00:06:12,380 I'll go through some demos, 125 00:06:12,540 --> 00:06:14,560 but you load a binary up into IDA. 126 00:06:14,620 --> 00:06:15,460 It does a lot of analysis, 127 00:06:15,540 --> 00:06:17,720 decides what type of executable it is. 128 00:06:17,840 --> 00:06:19,840 Is it, say, a Linux ELF? 129 00:06:19,920 --> 00:06:21,600 Is it a Windows PE executable? 130 00:06:22,860 --> 00:06:23,720 Parses all the headers, 131 00:06:23,860 --> 00:06:25,460 parses the different segments and so on, 132 00:06:25,880 --> 00:06:27,340 and then does the disassembly. 133 00:06:27,340 --> 00:06:28,480 So it goes to the entry point, basically, 134 00:06:28,480 --> 00:06:30,520 starts from there and takes it apart, 135 00:06:30,700 --> 00:06:32,040 disassembles, recognizes functions, 136 00:06:32,400 --> 00:06:34,620 recognizes stack-declared locals, 137 00:06:34,820 --> 00:06:37,800 recognizes function parameters, and so on. 138 00:06:37,880 --> 00:06:39,980 And it makes a lot of annotations. 139 00:06:39,980 --> 00:06:41,220 It's really, really nice. 140 00:06:42,660 --> 00:06:45,120 And what it's doing all along the way 141 00:06:45,120 --> 00:06:47,020 is it's taking basically every byte 142 00:06:47,020 --> 00:06:49,000 out of that binary image off your disk 143 00:06:49,380 --> 00:06:50,920 and sticking it in a database. 144 00:06:51,260 --> 00:06:52,880 So IDA builds a database, 145 00:06:53,140 --> 00:06:57,040 and then you as a reverse engineer are interacting with 146 00:06:57,040 --> 00:06:57,460 a database. 147 00:06:57,740 --> 00:06:59,920 You're not really interacting with a binary anymore. 148 00:07:00,380 --> 00:07:02,540 You're making annotations into a database, 149 00:07:03,140 --> 00:07:04,240 and that's all it is. 150 00:07:04,280 --> 00:07:06,440 Every byte is marked it's executable or it's data. 151 00:07:06,680 --> 00:07:08,020 You can reformat things, 152 00:07:08,880 --> 00:07:12,360 but IDA is essentially a pretty front end to their database, 153 00:07:12,440 --> 00:07:14,420 and you can make annotations and keep working from there. 154 00:07:16,160 --> 00:07:17,760 So it doesn't run any code, 155 00:07:17,860 --> 00:07:21,040 although the new version has a Windows debugger built into it, 156 00:07:21,060 --> 00:07:22,920 which I've never really played with. 157 00:07:23,080 --> 00:07:24,020 But that doesn't help you 158 00:07:24,020 --> 00:07:25,280 if you want to look at Linux code anyway. 159 00:07:28,640 --> 00:07:30,400 Okay, obfuscated code gets tougher, 160 00:07:31,360 --> 00:07:35,380 because all you're going to see is the de-obfuscation piece, 161 00:07:35,660 --> 00:07:37,820 because that's the only executable piece 162 00:07:38,420 --> 00:07:39,700 that sits on the file. 163 00:07:39,900 --> 00:07:44,140 Everything else is data from an immediate perspective. 164 00:07:44,400 --> 00:07:46,500 You have the de-obfuscator sitting there. 165 00:07:46,580 --> 00:07:47,520 That's what's going to run. 166 00:07:47,640 --> 00:07:50,000 You have all the data that's been obfuscated in some way, 167 00:07:50,080 --> 00:07:52,560 whether it's been just encrypted or encoded or what have you. 168 00:07:53,880 --> 00:07:57,020 And so IDA will show you the de-obfuscation code, 169 00:07:57,040 --> 00:07:57,580 the obfuscator portion, 170 00:07:57,840 --> 00:07:59,660 but everything else is just going to group together as data. 171 00:08:00,360 --> 00:08:02,580 Okay, hard to reverse engineer that stuff. 172 00:08:03,620 --> 00:08:08,900 And usually you're only going to get sensible output in IDA 173 00:08:08,900 --> 00:08:10,000 for the entry point function, 174 00:08:10,200 --> 00:08:12,000 and then it's going to start falling apart. 175 00:08:12,340 --> 00:08:15,220 And if they do things like jumping in the middle of instructions, 176 00:08:15,660 --> 00:08:16,980 IDA really can't follow that. 177 00:08:17,120 --> 00:08:18,500 It's got to find some instruction boundaries. 178 00:08:18,940 --> 00:08:21,320 It can't show you the same instruction twice split 179 00:08:21,320 --> 00:08:22,720 in the middle of an instruction 180 00:08:22,720 --> 00:08:24,840 for different instruction starts or so on. 181 00:08:26,660 --> 00:08:28,700 So, you know, IDA, we've got to work through that. 182 00:08:28,860 --> 00:08:31,900 And if you're going to use IDA to reverse engineer, 183 00:08:32,080 --> 00:08:33,580 we've got to get through that easily. 184 00:08:34,040 --> 00:08:36,040 You can do it manually, and it's kind of a pain. 185 00:08:36,340 --> 00:08:38,340 Okay, anybody who's done it can tell you. 186 00:08:38,560 --> 00:08:41,380 Now, the plug-in that I developed has two pieces. 187 00:08:41,760 --> 00:08:43,060 It's a user interface piece, 188 00:08:43,200 --> 00:08:44,540 and I'm not a user interface person, 189 00:08:44,620 --> 00:08:46,000 so you can laugh at it all you want. 190 00:08:46,020 --> 00:08:46,380 That's fine. 191 00:08:47,440 --> 00:08:49,520 And I will generally chalk up, you know, 192 00:08:49,520 --> 00:08:52,860 quick and dirty user interface hacks, you know, as ugly. 193 00:08:52,920 --> 00:08:54,620 And it got the job done for me. 194 00:08:54,680 --> 00:08:54,820 And I'm happy with that. 195 00:08:54,840 --> 00:08:55,760 And I can work on that in the future. 196 00:08:55,900 --> 00:08:58,180 But the user interface is all supposed 197 00:08:58,180 --> 00:09:01,300 to be Windows GUI-specific, you know, code. 198 00:09:01,700 --> 00:09:03,500 Okay, it throws up the dialog boxes 199 00:09:03,500 --> 00:09:05,180 that this emulator needs and so on. 200 00:09:05,260 --> 00:09:09,620 And then there is an x86 emulator piece, okay, 201 00:09:09,660 --> 00:09:12,740 which handles instruction fetching and decoding 202 00:09:12,740 --> 00:09:13,880 and executing and so on. 203 00:09:14,200 --> 00:09:17,440 And it interacts with the database to pull 204 00:09:17,440 --> 00:09:20,540 out different bytes, you know, instruction bytes and so on. 205 00:09:20,900 --> 00:09:24,040 And the emulator piece is mostly platform independent. 206 00:09:24,060 --> 00:09:24,800 I'm trying to keep it 207 00:09:24,800 --> 00:09:27,280 platform independent so that you can actually do, 208 00:09:27,420 --> 00:09:30,320 you can pull it outside and do stand-alone emulation. 209 00:09:30,820 --> 00:09:34,520 And you can actually integrate it into your own sort 210 00:09:34,520 --> 00:09:39,040 of stand-alone unrollers, okay, which is what I did. 211 00:09:39,180 --> 00:09:42,320 And there's reference to a talk about reverse engineering Shiva, 212 00:09:42,940 --> 00:09:45,280 which was this Linux protector. 213 00:09:45,720 --> 00:09:50,040 And I took the emulator out of this, just the emulator code, 214 00:09:50,760 --> 00:09:54,420 and used it in the stand-alone to create a stand-alone unwrapper 215 00:09:54,420 --> 00:09:54,860 for Shiva. 216 00:09:55,080 --> 00:09:57,400 So that's why I'm trying to keep the emulator separate, 217 00:09:57,520 --> 00:10:00,860 so I could pull it aside and run it, say, on Linux, if I wanted to. 218 00:10:02,580 --> 00:10:06,040 But what it's really designed to do is execute a single instruction 219 00:10:06,040 --> 00:10:08,860 at a time and then pass control back over to the GUI side, 220 00:10:08,960 --> 00:10:10,080 so you can step through this code. 221 00:10:11,300 --> 00:10:13,660 And, you know, we can talk on the side 222 00:10:13,660 --> 00:10:15,160 on why I didn't go find any other. 223 00:10:15,320 --> 00:10:19,100 There's plenty of x86 emulators out there, and I'll talk 224 00:10:19,100 --> 00:10:22,240 to you offline if you want to know why I did my own, okay, 225 00:10:22,300 --> 00:10:23,480 sort of reinvented the wheel there. 226 00:10:23,560 --> 00:10:24,400 But the integration, you know, is really important. 227 00:10:24,400 --> 00:10:26,940 Integration is what's sort of new here. 228 00:10:27,580 --> 00:10:29,720 So the GUI gives you this console. 229 00:10:30,040 --> 00:10:33,180 If you're in IDA, and we'll see samples here, it throws up this console. 230 00:10:33,360 --> 00:10:36,520 And it's sort of like a pseudo-debugging console, okay? 231 00:10:36,600 --> 00:10:38,860 It's going to show you register displays, and you can drill in, 232 00:10:38,880 --> 00:10:40,900 and you can get at the segment registers if you really want to. 233 00:10:41,940 --> 00:10:44,460 It's going to show you the only memory display it has 234 00:10:44,460 --> 00:10:48,120 at the moment is the stack display, which sits down there at the bottom. 235 00:10:49,080 --> 00:10:50,880 Over to the right, you have some control buttons. 236 00:10:51,060 --> 00:10:52,020 We can step through code. 237 00:10:52,140 --> 00:10:53,980 We can just jump over code or jump 238 00:10:53,980 --> 00:10:54,380 to a specific code. 239 00:10:54,380 --> 00:10:57,600 There's a specific spot in the code, which is just resetting the instruction pointer. 240 00:10:58,320 --> 00:11:02,240 You can skip over code, just, you know, skip a statement entirely if you don't want 241 00:11:02,240 --> 00:11:06,620 to descend into a subroutine, or more importantly, in dynamic-linked code, 242 00:11:06,820 --> 00:11:12,740 IDA is only loaded up the binary, but you don't have access to any of the DLLs, okay? 243 00:11:12,820 --> 00:11:16,740 So if you're going to descend, if you see that the code makes a call 244 00:11:16,740 --> 00:11:19,840 to a library function, you don't have the disassembled code 245 00:11:19,840 --> 00:11:21,260 to that function, we can't execute it. 246 00:11:21,400 --> 00:11:23,100 So you can just skip the call entirely. 247 00:11:23,340 --> 00:11:24,360 Of course, you have to fudge it. 248 00:11:24,360 --> 00:11:28,280 You have to fudge the results in EAX, perhaps, in order to be able to continue. 249 00:11:28,900 --> 00:11:33,000 You can skip forward, set the cursor somewhere in the future, and run the cursor, 250 00:11:33,120 --> 00:11:36,580 and cross your fingers that you get there, because if you don't get there, 251 00:11:36,740 --> 00:11:40,620 you've basically locked up the emulator, okay, while it's fetching from who knows where. 252 00:11:40,980 --> 00:11:43,480 Okay, that's, you know, an improvement that can be made. 253 00:11:43,580 --> 00:11:44,760 And then hide just makes it go away. 254 00:11:45,380 --> 00:11:49,240 For manipulating stack data, the push data button down towards the bottom, 255 00:11:49,280 --> 00:11:52,700 it actually lets you push your own data onto the stack, which is kind of nice. 256 00:11:52,740 --> 00:11:54,340 If you want to just run one file, you can do that. 257 00:11:54,340 --> 00:11:56,800 If you want to just run one function out of the program, then you know it needs some arguments. 258 00:11:57,400 --> 00:12:01,340 Okay, push the arguments on the stack, and then start stepping through the program. 259 00:12:01,500 --> 00:12:04,300 And the program will retrieve the arguments off of the stack. 260 00:12:04,480 --> 00:12:09,280 And I'll explain the memory layout, memory architecture of the plugin in just a moment. 261 00:12:10,580 --> 00:12:15,240 So using this thing is, it's brought up in IDA with Alt F8, and this hopefully will all become clear 262 00:12:15,240 --> 00:12:16,400 when I start working through demos. 263 00:12:17,220 --> 00:12:22,500 Wherever you have the cursor, when you bring up the emulator, that's where EIP is going to be set. 264 00:12:22,680 --> 00:12:24,120 So you can, you'll start stepping. 265 00:12:24,340 --> 00:12:26,760 If you want to, from wherever the cursor is. 266 00:12:27,160 --> 00:12:29,380 And then you just, you step and go, okay? 267 00:12:29,740 --> 00:12:34,880 And the plugin will interact with IDA. 268 00:12:35,200 --> 00:12:40,040 It'll, you know, fetch a byte out of the IDA database, which it's going to assume is code, 269 00:12:40,180 --> 00:12:42,080 because you told it to, you told it to step there. 270 00:12:42,340 --> 00:12:46,680 The emulator then decodes the instruction, fetches more bytes from IDA, 271 00:12:46,680 --> 00:12:51,640 if it's a multi-byte instruction, and then modifies all the registers accordingly. 272 00:12:51,820 --> 00:12:53,460 On that control panel that you just saw, 273 00:12:53,460 --> 00:12:56,960 the registers will all update as you step through the code, okay? 274 00:12:58,900 --> 00:13:04,840 And every time you step, the emulator also tells IDA, okay, this is going to be code, 275 00:13:04,900 --> 00:13:06,880 because EIP is pointing at this thing. 276 00:13:07,340 --> 00:13:12,900 So the emulator will tell IDA, now reorganize whatever is at this location to look like code. 277 00:13:12,980 --> 00:13:15,420 So if you're jumping into the middle of instructions, 278 00:13:15,880 --> 00:13:19,200 then the emulator will automatically reorganize your IDA display 279 00:13:19,740 --> 00:13:21,760 to mark the new beginning of an instruction. 280 00:13:22,060 --> 00:13:23,440 It undefines the old instructions. 281 00:13:23,460 --> 00:13:27,760 It unselects the new instruction and redefines a new instruction at the current EIP location. 282 00:13:28,780 --> 00:13:31,380 And I'll show you a lot of this sort of code reorganizing, 283 00:13:31,400 --> 00:13:34,620 jumping to the middle of the instructions in some of the demos that are coming up. 284 00:13:36,280 --> 00:13:39,800 This just describes, well, the run to cursor. 285 00:13:40,320 --> 00:13:44,400 I don't do breakpoints yet, okay, but in theory, you could have a list of breakpoints. 286 00:13:44,700 --> 00:13:48,380 Just go to any address in IDA and then add a breakpoint into the emulator 287 00:13:48,380 --> 00:13:50,000 and then run until you got there. 288 00:13:50,080 --> 00:13:51,380 That's really not easy to do. 289 00:13:51,420 --> 00:13:52,460 All you have to do is monitor EIP. 290 00:13:54,400 --> 00:13:56,440 The plugin supplies its own stack. 291 00:13:56,560 --> 00:13:59,660 Remember, IDA is just a binary image that sits on the disk. 292 00:14:00,260 --> 00:14:03,540 Okay, so that's a lot of code and some static data, 293 00:14:03,740 --> 00:14:08,660 but your heap doesn't sit in that file and your stack doesn't sit in that file. 294 00:14:08,920 --> 00:14:12,660 So if you want to really run through any code, you're going to need perhaps a heap 295 00:14:12,660 --> 00:14:17,560 and at least a stack, okay, available as you fetch instructions. 296 00:14:17,640 --> 00:14:20,080 I mean, push anything and that's got to go somewhere. 297 00:14:20,360 --> 00:14:22,760 You're not going to push that data into the IDA database. 298 00:14:23,460 --> 00:14:26,020 Okay, because that's really not what's sitting on your file. 299 00:14:26,160 --> 00:14:32,200 So the emulator provides a stack and it looks at memory references and sorts them out based 300 00:14:32,200 --> 00:14:36,540 on where are we retrieving from, where are we writing to, where are we reading from, 301 00:14:36,580 --> 00:14:37,240 makes a decision. 302 00:14:37,460 --> 00:14:38,300 Is this code? 303 00:14:38,960 --> 00:14:41,140 Am I going to go fetch this out of the IDA database? 304 00:14:41,280 --> 00:14:41,880 Is it stack? 305 00:14:42,060 --> 00:14:44,320 Am I going to go throw it in the emulated stack? 306 00:14:44,640 --> 00:14:47,120 Is it out in the emulated heap? 307 00:14:47,600 --> 00:14:50,300 Okay, so the plugin supplies both of those two things. 308 00:14:50,400 --> 00:14:51,860 It requires some manual setup. 309 00:14:53,460 --> 00:14:54,620 It works. 310 00:14:56,500 --> 00:14:58,300 Limitations on a plugin, it's slow. 311 00:14:58,880 --> 00:15:01,740 It's emulated execution through a database. 312 00:15:02,540 --> 00:15:07,080 A, we've got to do all this database interaction to fetch things and B, we're emulating every 313 00:15:07,080 --> 00:15:07,500 instruction. 314 00:15:07,820 --> 00:15:12,020 So don't think that you're going to get high performance execution of these executables. 315 00:15:12,140 --> 00:15:17,440 But the real goal is to just get through the obfuscation, which should be done fairly quickly 316 00:15:18,060 --> 00:15:22,180 and leave you to reverse engineer the underlying binary. 317 00:15:22,740 --> 00:15:23,320 Okay. 318 00:15:23,460 --> 00:15:26,300 Why not follow calls into dynamically linked functions? 319 00:15:26,980 --> 00:15:29,000 Because IDA doesn't load that code up. 320 00:15:30,280 --> 00:15:32,660 It doesn't load up DLL. 321 00:15:32,920 --> 00:15:34,380 There's nothing more I can say about that. 322 00:15:34,480 --> 00:15:40,780 But if you're calling, say, printf, we don't have the disassembled version of printf to 323 00:15:40,780 --> 00:15:41,400 descend into. 324 00:15:42,320 --> 00:15:44,460 So that's a limitation on this thing. 325 00:15:44,580 --> 00:15:46,700 And IDA won't load them up at the same time. 326 00:15:48,040 --> 00:15:50,860 Can't follow system calls into static and linked executables. 327 00:15:50,900 --> 00:15:52,440 Say you're looking at a Linux binary. 328 00:15:52,440 --> 00:15:54,100 And you're doing some int80s. 329 00:15:54,420 --> 00:15:56,140 You descend down to an int80. 330 00:15:56,340 --> 00:15:57,960 It's not going to follow that system call. 331 00:15:58,400 --> 00:16:02,700 So you're going to have to fake the results and throw something into EAX and press on 332 00:16:02,700 --> 00:16:03,640 if you can. 333 00:16:08,100 --> 00:16:11,060 So the emulator memory, I sort of went over the layout of this. 334 00:16:11,680 --> 00:16:13,540 Code gets fetched from the IDA database. 335 00:16:13,660 --> 00:16:14,600 So that's database interaction. 336 00:16:15,000 --> 00:16:19,080 And then the other references are resolved to either the emulated heap or the emulated 337 00:16:19,080 --> 00:16:19,440 stack. 338 00:16:19,740 --> 00:16:21,140 Every memory reference is checked. 339 00:16:21,140 --> 00:16:26,480 So we could actually output information about, you know, where are we reading to and writing 340 00:16:26,480 --> 00:16:31,100 from, or vice versa, or whatever that was supposed to be said. 341 00:16:31,720 --> 00:16:35,160 In the heap, you could add sort of valgrind-type analysis. 342 00:16:35,520 --> 00:16:39,660 You can actually observe that you're flowing out the end of a heap-allocated block. 343 00:16:40,120 --> 00:16:43,760 You could potentially see some heap overflows in that way. 344 00:16:43,820 --> 00:16:46,860 Because we can mark every access to and from the heap. 345 00:16:46,940 --> 00:16:49,640 Although it's just a toy implementation of a heap algorithm. 346 00:16:50,240 --> 00:16:50,560 It could. 347 00:16:51,140 --> 00:16:57,260 It could be replaced by any of the actual heap algorithms, or heap management algorithms 348 00:16:57,260 --> 00:16:59,260 that are in use in the world. 349 00:17:01,720 --> 00:17:04,520 Memory layout you control by bringing up a little dialog box. 350 00:17:04,780 --> 00:17:07,280 And you can set your stack top. 351 00:17:07,480 --> 00:17:08,400 You can set your stack size. 352 00:17:08,700 --> 00:17:11,060 You can set your heap base address. 353 00:17:11,320 --> 00:17:12,260 You can set a heap size. 354 00:17:12,440 --> 00:17:13,580 And it'll just go grab that memory. 355 00:17:14,220 --> 00:17:18,400 It's not very smart about growing the stack if it needs to, or growing the heap anymore 356 00:17:18,400 --> 00:17:19,100 if it needs to. 357 00:17:19,540 --> 00:17:21,000 But if you set reasonable limits. 358 00:17:21,140 --> 00:17:26,840 In here, you should be able to accomplish what my primary goal here, which is unrolling 359 00:17:26,840 --> 00:17:28,840 the obfuscated code. 360 00:17:31,040 --> 00:17:34,080 Emulated stack operations all go to the stack. 361 00:17:34,180 --> 00:17:37,880 So pushes and pops and things like that all interact with the stack. 362 00:17:38,040 --> 00:17:40,960 The stack contents are displayed down in that bottom scrolling window. 363 00:17:41,840 --> 00:17:45,240 Currently I don't have, the heap was one of the last things I added in. 364 00:17:45,320 --> 00:17:47,800 I don't have a way to display heap memory at the moment. 365 00:17:48,160 --> 00:17:48,600 Okay. 366 00:17:48,600 --> 00:17:50,560 You can always display code. 367 00:17:50,680 --> 00:17:51,120 You can always display code. 368 00:17:51,140 --> 00:17:51,720 In IDA. 369 00:17:52,000 --> 00:17:54,600 You can scroll through IDA and see what the code is looking like. 370 00:17:54,660 --> 00:17:56,940 You can scroll through the stack window and see what the stack is looking like. 371 00:17:57,260 --> 00:18:01,240 But I do need to come up with a more generic way of looking through memory so you can see 372 00:18:01,600 --> 00:18:02,980 the state of the heap at any moment. 373 00:18:06,100 --> 00:18:06,620 Let's see. 374 00:18:08,880 --> 00:18:12,960 And you do have the capability of pushing data onto the stack sort of outside of program 375 00:18:12,960 --> 00:18:13,380 control. 376 00:18:13,620 --> 00:18:14,880 Let's just throw some data on there. 377 00:18:15,020 --> 00:18:16,740 Grab some stack space if you want to. 378 00:18:16,780 --> 00:18:17,420 Push some parameters. 379 00:18:17,720 --> 00:18:19,220 And then step into a function. 380 00:18:19,420 --> 00:18:19,740 Okay. 381 00:18:20,760 --> 00:18:21,120 All right. 382 00:18:21,140 --> 00:18:21,580 Looks like this. 383 00:18:21,580 --> 00:18:27,040 If you want to push some data, you can throw some data up in the, it brings up a dialog 384 00:18:27,040 --> 00:18:30,340 box, asks you what the data that you want to push, puts your numbers in there. 385 00:18:30,440 --> 00:18:31,520 It's kind of like calling a function. 386 00:18:32,120 --> 00:18:32,440 Okay. 387 00:18:32,440 --> 00:18:34,340 The stuff gets pushed in right to left order. 388 00:18:34,700 --> 00:18:37,200 So you put on the parameters just like you want to call a function. 389 00:18:37,840 --> 00:18:38,160 Okay. 390 00:18:38,180 --> 00:18:43,260 And then the stack, the stuff gets jammed onto the stack and the stack pointer gets 391 00:18:43,260 --> 00:18:44,040 updated accordingly. 392 00:18:44,580 --> 00:18:44,900 Okay. 393 00:18:44,920 --> 00:18:45,980 So that's all sort of integrated. 394 00:18:47,760 --> 00:18:50,960 Emulated heap is just a real simple linked list memory allocator. 395 00:18:50,960 --> 00:18:53,140 It doesn't do inline control information. 396 00:18:53,440 --> 00:18:57,780 So if you do heap overwrites, if you see any of that stuff, or if you were able to look 397 00:18:57,780 --> 00:19:02,180 at heap memory, you wouldn't see links to the next free block, next empty block, any 398 00:19:02,180 --> 00:19:02,560 of that stuff. 399 00:19:02,640 --> 00:19:03,280 It's not in memory. 400 00:19:03,380 --> 00:19:11,380 It's just a simple way to satisfy memory requests that are made by the binary being looked at. 401 00:19:13,680 --> 00:19:17,040 It can detect access outside of allocated blocks though. 402 00:19:17,060 --> 00:19:20,740 So in theory, you could watch and see if the heap overflow is going to take place. 403 00:19:23,100 --> 00:19:23,860 Function hooking. 404 00:19:24,580 --> 00:19:30,940 So while it doesn't descend into dynamically linked libraries, it turned out that one 405 00:19:30,940 --> 00:19:36,460 of the unpackers I was looking at did want to call a malloc-type function. 406 00:19:36,980 --> 00:19:39,320 And so I was out of luck. 407 00:19:39,660 --> 00:19:42,780 I couldn't get any farther unless I could implement the malloc. 408 00:19:42,940 --> 00:19:48,700 So A, I had to implement a heap, and B, I had to hook the heap alloc call that was being 409 00:19:48,700 --> 00:19:50,160 made in this Windows binary. 410 00:19:50,920 --> 00:19:59,100 So I added sort of function hooking, and I've mimicked a few, very few, library calls 411 00:19:59,440 --> 00:20:06,340 that I found I needed to get through this one particular protection. 412 00:20:06,980 --> 00:20:11,660 And what happens, so then if it's going to call heap alloc, if you see, hey, at this 413 00:20:11,660 --> 00:20:17,580 location it's going to call heap alloc, you can hook that call to heap alloc and divert 414 00:20:17,580 --> 00:20:20,080 it into our emulated heap. 415 00:20:20,080 --> 00:20:21,340 Heap allocator. 416 00:20:21,780 --> 00:20:28,940 And so any time it says call heap alloc, then you jump out to the emulated heap and it returns 417 00:20:28,940 --> 00:20:32,420 you a pointer to a block of memory the size that you requested. 418 00:20:32,680 --> 00:20:34,920 It looks into the stack as you've set it up for that call. 419 00:20:35,180 --> 00:20:40,400 And so if it occurs in a loop or as it occurs over and over again, now we're allocating 420 00:20:40,400 --> 00:20:43,940 memory without having to have a library function available. 421 00:20:46,620 --> 00:20:49,360 And you can also just run the functions if you want to. 422 00:20:49,440 --> 00:20:50,060 If you just want to run the functions, you can do that. 423 00:20:50,060 --> 00:20:53,920 If you want to run malloc and you want to have a block of, say, 1K, you can just push 424 00:20:53,920 --> 00:20:59,140 the number on the stack and then just run malloc and you'll get a pointer back in EAX. 425 00:20:59,640 --> 00:21:04,000 And then you can use that pointer manually later on if you know you need a block, a 426 00:21:04,000 --> 00:21:06,540 pointer to a buffer to pass into, say, some other function. 427 00:21:06,820 --> 00:21:10,480 But the automatic function hooking is a little more interesting, and we'll see that in one 428 00:21:10,480 --> 00:21:11,520 of the demos coming up. 429 00:21:13,100 --> 00:21:15,100 A manual function hooking just looks like this. 430 00:21:15,120 --> 00:21:16,420 It's not really manual function hooking. 431 00:21:16,500 --> 00:21:18,280 It's just sort of running a function. 432 00:21:19,160 --> 00:21:19,840 Choose a function. 433 00:21:20,060 --> 00:21:24,920 If you want to run, make sure you push the parameters on the stack, and then just select 434 00:21:24,920 --> 00:21:28,020 the function that you want to run off the dropdown, and it'll run the function, pull 435 00:21:28,020 --> 00:21:29,880 the parameters, and give you a result in EAX. 436 00:21:30,540 --> 00:21:32,400 So you can sort of play along. 437 00:21:33,020 --> 00:21:34,140 No change to EIP. 438 00:21:35,700 --> 00:21:40,720 We're sort of executing that function outside of the binary for administrative purposes, 439 00:21:40,780 --> 00:21:45,160 like to grab a large block of memory out in the heap that we may use later on. 440 00:21:46,220 --> 00:21:49,120 Automatic function hooking works like this. 441 00:21:49,580 --> 00:21:50,940 We go choose an address. 442 00:21:51,280 --> 00:21:53,180 Actually, I think I changed the way this is implemented. 443 00:21:55,160 --> 00:21:59,900 But what we would do is we set the address of the function. 444 00:21:59,940 --> 00:22:03,360 So here you see a place where it does a call to malloc. 445 00:22:04,100 --> 00:22:10,300 We're going to change that address so that not just this call, but every other call to malloc 446 00:22:10,300 --> 00:22:16,700 would get diverted into our whatever function we hook in its place over here, malloc in this case. 447 00:22:18,200 --> 00:22:19,100 There's only those five. 448 00:22:19,100 --> 00:22:20,760 Five functions were implemented, because that's all I needed. 449 00:22:21,220 --> 00:22:23,800 And again, I'm going to demo that coming up. 450 00:22:25,500 --> 00:22:31,940 Another place I had to struggle was there is a – some of these unpackers like to generate 451 00:22:31,940 --> 00:22:34,740 exceptions for sort of anti-debugging purposes. 452 00:22:35,040 --> 00:22:38,300 So a lot of the Windows unpackers will throw exceptions left and right. 453 00:22:39,040 --> 00:22:41,940 Divide by zero, they'll throw in threes. 454 00:22:42,140 --> 00:22:43,580 They do a lot of strange stuff. 455 00:22:44,500 --> 00:22:49,080 And so to get through those, the emulator has to – the emulator has to do a lot of 456 00:22:49,080 --> 00:22:54,720 this to handle these exceptions in a manner that the binary expects. 457 00:22:54,960 --> 00:22:58,920 Well, these are Windows binaries, and they're expecting to get sort of the Windows-structured 458 00:22:58,920 --> 00:23:03,140 exception handling data thrown on the stack and then jump to the exception handler. 459 00:23:03,240 --> 00:23:04,920 So I threw that in there. 460 00:23:04,980 --> 00:23:05,860 The emulator will do that. 461 00:23:05,920 --> 00:23:11,460 If it's a PE binary, then the emulator will try to catch exceptions. 462 00:23:12,180 --> 00:23:19,000 And when it sees the exception, it'll push all the stack data required for an exception. 463 00:23:19,000 --> 00:23:23,860 So if it's an exception handler in Windows, follow the exception handler links through 464 00:23:23,860 --> 00:23:30,580 FS colon zero and try to transfer the control to the exception handler, which then can play 465 00:23:30,580 --> 00:23:34,720 with all the data, all the saved registers that are thrown up on the stack before returning 466 00:23:34,720 --> 00:23:35,740 control to the binary. 467 00:23:35,900 --> 00:23:37,620 And we'll work through that a little bit. 468 00:23:40,540 --> 00:23:42,440 And it only recognizes a couple things. 469 00:23:42,580 --> 00:23:48,200 It does the divide by zero right now in three single-stepping, the trace flag being turned on. 470 00:23:49,000 --> 00:23:53,620 The debug registers, which is, again, because T-Lock insisted on doing all that stuff. 471 00:23:56,280 --> 00:24:00,100 The emulator program has to set up an exception handler, obviously, to use all of this stuff. 472 00:24:00,300 --> 00:24:04,200 And then the emulator creates the data structures and throws them on the stack before transferring 473 00:24:04,200 --> 00:24:05,320 control to the exception handler. 474 00:24:07,040 --> 00:24:08,800 Okay, so demos. 475 00:24:09,480 --> 00:24:13,740 We'll start off with UPX because it's the easiest, and it's the most likely demo to succeed. 476 00:24:15,180 --> 00:24:16,960 It's a pretty common obfuscator. 477 00:24:17,080 --> 00:24:18,280 It's not terribly sophisticated. 478 00:24:18,280 --> 00:24:20,220 Because all it really is is a compressor. 479 00:24:21,040 --> 00:24:25,760 It just compresses the binary, throws a decompression stub on the front. 480 00:24:25,960 --> 00:24:29,940 And so when you run it, it decompresses and transfers control back to the original binary. 481 00:24:30,580 --> 00:24:31,920 It's very straightforward. 482 00:24:32,360 --> 00:24:39,160 They don't make any attempt to obfuscate themselves, obfuscate the decompression algorithm. 483 00:24:40,340 --> 00:24:48,120 And in fact, if you don't take measures to prevent it, UPX will. 484 00:24:49,080 --> 00:24:51,140 Unroll a UPX protected binary. 485 00:24:51,820 --> 00:24:54,660 Okay, UPX will reverse itself at the command line. 486 00:24:54,920 --> 00:24:59,580 Okay, so there are other tools out there that will tweak a UPX-packed binary so that it 487 00:24:59,580 --> 00:25:07,020 at least breaks the UPX part where you can't just use UPX to unwrap UPX, a UPX protected binary. 488 00:25:07,580 --> 00:25:08,740 But it's really simple. 489 00:25:10,000 --> 00:25:12,060 There's a simple, straightforward loop. 490 00:25:12,160 --> 00:25:15,060 There's really no tricks involved, and it's really no problem for the plug-in. 491 00:25:15,160 --> 00:25:18,260 And the only place that I wish... 492 00:25:18,280 --> 00:25:20,700 you know, I could do better is the import table. 493 00:25:20,880 --> 00:25:26,880 All these things, after they get done deobfuscating, they need to go back and rebuild the import tables. 494 00:25:27,120 --> 00:25:32,340 Okay, they have to sort of do their own linking because all that stuff has been hidden from the operating system linker 495 00:25:32,340 --> 00:25:35,480 when the program is loaded off the disk. 496 00:25:36,580 --> 00:25:43,480 So I don't rebuild the import table here, but it's not too tough to do, either with a script or manually. 497 00:25:43,820 --> 00:25:45,380 So let me see if I can get out of this. 498 00:25:59,940 --> 00:26:01,800 So I'm going to go ahead and find a UPX binary on the list here. 499 00:26:02,000 --> 00:26:02,720 Bear with me. 500 00:26:05,560 --> 00:26:06,580 That's not going to get any bigger. 501 00:26:06,680 --> 00:26:06,940 Come on. 502 00:26:13,280 --> 00:26:13,620 Hmm. 503 00:26:17,840 --> 00:26:18,260 I'm lost. 504 00:26:18,280 --> 00:26:18,560 I'm locked up. 505 00:26:35,820 --> 00:26:42,100 Okay, this thing is a Slackbot IRC Trojan, and we'll just call it malware here. 506 00:26:42,200 --> 00:26:43,320 We load it up in IDA. 507 00:26:43,820 --> 00:26:46,820 It correctly identifies it as a Windows PE. 508 00:26:48,280 --> 00:26:52,640 It tells us that the import segment seems to have been destroyed, which it was because the thing was compressed. 509 00:26:53,840 --> 00:27:02,280 And we let it open up, and the resolution on this thing is so low that I hope we don't have problems with the demo. 510 00:27:02,340 --> 00:27:04,200 The emulator is going to take up the whole screen, I'm afraid. 511 00:27:08,340 --> 00:27:12,820 Okay, so IDA gives you a names window over here, any names that are recognized in the program, and we see a few. 512 00:27:12,900 --> 00:27:18,260 There are a couple key imports that function, or some unpacked. 513 00:27:18,280 --> 00:27:21,660 Backers need, you know, the standard sort of Windows stuff, load library, get proc address. 514 00:27:22,200 --> 00:27:26,000 Over here, you get a strings window, and mostly we see that it's full of garbage. 515 00:27:27,540 --> 00:27:30,900 Okay, so there are not a lot of recognized strings right now in this binary. 516 00:27:31,480 --> 00:27:40,880 Okay, the strings windows is helpful in de-obfuscating something, because usually if you're successful in de-obfuscating something, 517 00:27:41,440 --> 00:27:44,040 you will unravel, strings will become available. 518 00:27:44,540 --> 00:27:47,740 Okay, so it's sort of a hint that you're maybe on the right track. 519 00:27:48,660 --> 00:27:52,180 So we're set up to go here at the entry point of this program. 520 00:27:52,740 --> 00:27:54,420 This is going to be really tough with this resolution. 521 00:27:57,860 --> 00:28:01,600 I should try to remove all these window, or these toolbars. 522 00:28:06,300 --> 00:28:07,620 See if I gain some more space. 523 00:28:21,360 --> 00:28:23,180 Yeah, we're not getting very far. 524 00:28:23,320 --> 00:28:25,520 Let me bring up the plug-in, see what we get. 525 00:28:26,180 --> 00:28:27,320 Takes up the whole damn screen. 526 00:28:28,460 --> 00:28:32,320 Can we get any better resolution out of these monitors? 527 00:28:32,440 --> 00:28:32,580 Nope. 528 00:28:33,080 --> 00:28:33,440 Okay. 529 00:28:38,620 --> 00:28:40,380 Okay, we'll run it way down here. 530 00:28:41,640 --> 00:28:42,940 We'll start stepping through code. 531 00:28:44,800 --> 00:28:46,840 Okay, you can see, so I hit the step button. 532 00:28:46,840 --> 00:28:49,460 The cursor advances over here in IDA. 533 00:28:49,700 --> 00:28:51,120 Okay, we're on the next instruction. 534 00:28:51,860 --> 00:28:55,800 Okay, we see some stack activity has taken place. 535 00:28:56,020 --> 00:29:00,000 It was a push all instruction, so the stack has grown. 536 00:29:00,740 --> 00:29:02,340 ESP is updated and so on. 537 00:29:02,420 --> 00:29:05,220 And we can step, and you'll see that the registers change and so on. 538 00:29:05,600 --> 00:29:07,500 Okay, the stack is growing. 539 00:29:08,240 --> 00:29:10,520 Okay, we're working our way down through this thing. 540 00:29:12,200 --> 00:29:16,620 But it's going to be a lot easier if I just descend. 541 00:29:18,340 --> 00:29:20,240 And you can see it's very straightforward. 542 00:29:20,520 --> 00:29:22,820 The code paths don't appear to be obfuscated. 543 00:29:23,200 --> 00:29:24,940 Okay, we can see all the loops. 544 00:29:25,120 --> 00:29:30,160 I don't know if you all can see these branching things. 545 00:29:30,260 --> 00:29:32,700 They're kind of in a bad shade of gray over there on the side. 546 00:29:32,900 --> 00:29:37,520 It's just control paths in IDA that display the branching. 547 00:29:38,780 --> 00:29:42,800 So we work our way down to a point where 548 00:29:46,840 --> 00:29:47,880 we encounter this call instruction. 549 00:29:48,260 --> 00:29:49,760 And why is that dangerous at this point? 550 00:29:50,020 --> 00:29:51,500 Because we don't know what's going to get called. 551 00:29:52,420 --> 00:30:00,500 Okay, so as I walk through this stuff, a call to code whose address I don't know right here 552 00:30:00,500 --> 00:30:04,860 because it's going to be dependent on whatever ESI ends up holding at this point, 553 00:30:05,440 --> 00:30:06,880 that's sort of a danger point for me. 554 00:30:06,920 --> 00:30:08,300 I don't want to run any farther than that. 555 00:30:08,420 --> 00:30:09,880 For all I know, it could be a library function. 556 00:30:10,340 --> 00:30:11,900 And in this case, it actually is. 557 00:30:12,480 --> 00:30:16,660 So I'm going to back up to this point right beside it. 558 00:30:16,660 --> 00:30:16,820 Before I move on. 559 00:30:16,820 --> 00:30:17,300 Before the loop. 560 00:30:19,480 --> 00:30:20,200 Right here. 561 00:30:20,760 --> 00:30:22,620 We're going to get back, maybe... 562 00:30:26,600 --> 00:30:27,960 Okay, back to the emulator window. 563 00:30:31,400 --> 00:30:33,200 And I'm just going to run it to the cursor. 564 00:30:35,240 --> 00:30:36,980 And you saw it thinking there for a second. 565 00:30:37,160 --> 00:30:38,480 It ran all the way down to here. 566 00:30:40,060 --> 00:30:41,360 Okay, I know this is terribly exciting. 567 00:30:42,300 --> 00:30:44,980 And the question is, did we get anything done? 568 00:30:45,380 --> 00:30:45,740 Well... 569 00:30:47,500 --> 00:30:48,960 This loop, it turns out... 570 00:30:48,960 --> 00:30:49,900 And I won't go into it. 571 00:30:49,940 --> 00:30:51,200 You still have to do some reverse engineering. 572 00:30:51,440 --> 00:30:53,140 But this loop is what rebuilds the import table. 573 00:30:53,880 --> 00:30:56,080 Okay, after UPX has decompressed it. 574 00:30:56,160 --> 00:30:58,740 So we're going to skip all that because I don't have get proc address available. 575 00:30:59,620 --> 00:31:01,760 Okay, so we're not going to be able to rebuild the import table. 576 00:31:02,000 --> 00:31:03,680 So we'll run down here to the end. 577 00:31:05,440 --> 00:31:06,960 Okay, these last couple of instructions. 578 00:31:07,540 --> 00:31:09,140 Pop all the registers off the stack. 579 00:31:09,300 --> 00:31:13,040 And then jump up to some other location. 580 00:31:13,460 --> 00:31:14,460 Okay, well this is... 581 00:31:14,460 --> 00:31:16,320 At that point, the code is done. 582 00:31:16,320 --> 00:31:17,700 So I'm going to jump down there. 583 00:31:17,760 --> 00:31:20,360 It changes the EIP to that cursor location over here. 584 00:31:20,640 --> 00:31:22,160 We step through a couple locations. 585 00:31:23,020 --> 00:31:24,860 The EIP will make a big jump. 586 00:31:25,640 --> 00:31:27,540 Okay, and now I'm somewhere else. 587 00:31:27,660 --> 00:31:28,520 I'm way up here. 588 00:31:29,100 --> 00:31:31,160 Okay, you can see where it's pointing. 589 00:31:33,200 --> 00:31:33,640 And... 590 00:31:35,480 --> 00:31:37,380 Everything appears to be... 591 00:31:37,380 --> 00:31:39,120 It doesn't look like it's code. 592 00:31:39,920 --> 00:31:40,360 Okay. 593 00:31:41,260 --> 00:31:44,080 But IDA hasn't been asked to reformat this yet. 594 00:31:44,460 --> 00:31:46,180 Okay, this is code that used to be data. 595 00:31:46,820 --> 00:31:51,680 Okay, the stub is transferring control to the newly unpacked code. 596 00:31:52,560 --> 00:31:56,500 Okay, we've transformed the code in IDA through database interactions. 597 00:31:57,260 --> 00:31:59,920 And as soon as I step once... 598 00:32:00,520 --> 00:32:01,040 Okay. 599 00:32:01,800 --> 00:32:04,600 The emulator tells IDA, hey, reorganize that. 600 00:32:04,620 --> 00:32:05,080 That's code. 601 00:32:06,060 --> 00:32:10,140 Okay, and many of you will recognize that's a standard function prolog. 602 00:32:10,640 --> 00:32:11,620 Okay, right there. 603 00:32:11,740 --> 00:32:12,720 And we can in fact... 604 00:32:12,720 --> 00:32:15,880 Working with IDA now, let's turn that into a function. 605 00:32:16,780 --> 00:32:19,840 Okay, and things start to look a little bit more interesting. 606 00:32:20,060 --> 00:32:24,480 And at this point, we can actually start reverse engineering the program. 607 00:32:24,680 --> 00:32:26,800 And ultimately down here, we call main. 608 00:32:26,940 --> 00:32:27,860 This is a Windows binary. 609 00:32:29,420 --> 00:32:32,540 But one of the interesting things that happened when I stepped into that function, 610 00:32:32,640 --> 00:32:35,660 when I called it code, IDA does more analysis. 611 00:32:36,380 --> 00:32:39,720 And you can see it's reanalyzed the whole program at this point. 612 00:32:39,840 --> 00:32:43,160 And it's showing up a lot of strings that were not there before. 613 00:32:44,420 --> 00:32:44,820 Okay. 614 00:32:44,820 --> 00:32:47,280 It shows those are the same old imports that we had before. 615 00:32:47,880 --> 00:32:48,280 Okay. 616 00:32:48,340 --> 00:32:50,200 But we have a lot more information to work with. 617 00:32:50,300 --> 00:32:54,560 And if we go back and rework the strings window, which does not get automatically updated. 618 00:32:55,700 --> 00:32:58,380 Okay, we still see a lot of garbage over there. 619 00:32:58,940 --> 00:33:00,980 Okay, if we ask it to rescan for strings. 620 00:33:02,720 --> 00:33:03,120 Okay. 621 00:33:05,780 --> 00:33:08,540 Okay, now we have a whole lot of other stuff. 622 00:33:09,900 --> 00:33:10,700 Okay, somewhere. 623 00:33:10,860 --> 00:33:11,220 Let's see. 624 00:33:13,300 --> 00:33:13,700 Okay. 625 00:33:13,700 --> 00:33:17,860 And so you see some of the static strings that were previously hidden. 626 00:33:19,100 --> 00:33:19,460 Okay. 627 00:33:19,740 --> 00:33:21,300 And these are all slack bot strings. 628 00:33:21,440 --> 00:33:23,560 You see IRC type stuff and so on. 629 00:33:23,880 --> 00:33:24,240 Okay. 630 00:33:24,260 --> 00:33:25,100 So that's UPX. 631 00:33:26,800 --> 00:33:32,380 And as I said, I really wish I could make this thing not so small. 632 00:33:32,520 --> 00:33:34,660 I mean, this thing is too big and I don't think I can resize it. 633 00:33:36,120 --> 00:33:37,420 So we're going to hide that. 634 00:33:37,480 --> 00:33:38,540 We'll get out of UPX. 635 00:33:39,040 --> 00:33:40,060 Open something different. 636 00:33:43,080 --> 00:33:43,440 Okay. 637 00:33:43,440 --> 00:33:45,060 And clearly you could save that and continue working. 638 00:33:45,180 --> 00:33:49,480 And now it becomes a reverse engineering problem, a reverse engineering slack bot. 639 00:33:49,960 --> 00:33:50,360 Okay. 640 00:33:50,360 --> 00:33:51,580 Which that happens to be. 641 00:33:51,700 --> 00:33:54,400 And so, you know, but you're beyond the obfuscation. 642 00:33:54,400 --> 00:33:55,680 You can get onto the meat of your work. 643 00:33:57,820 --> 00:33:58,220 Okay. 644 00:33:58,240 --> 00:34:03,580 So next we'll take a look at ASPAC. 645 00:34:06,340 --> 00:34:07,600 See if I can do this right. 646 00:34:10,360 --> 00:34:10,760 Okay. 647 00:34:10,760 --> 00:34:12,140 So this is a GAO bot. 648 00:34:12,340 --> 00:34:13,860 It's another IRC type trojan. 649 00:34:14,840 --> 00:34:16,320 Comes along in a lot of emails. 650 00:34:17,900 --> 00:34:19,780 And same problem, broken imports. 651 00:34:23,100 --> 00:34:29,220 And this code is a lot more challenging. 652 00:34:30,300 --> 00:34:30,820 Okay. 653 00:34:31,080 --> 00:34:32,640 IDA gives you about three statements. 654 00:34:33,420 --> 00:34:40,600 And if we go look at this, in fact, we see that the first instruction, well, after the 655 00:34:40,760 --> 00:34:43,580 push A, we're going to call into the middle of another instruction. 656 00:34:44,920 --> 00:34:45,320 Okay. 657 00:34:45,360 --> 00:34:46,560 We can go up to this location. 658 00:34:46,740 --> 00:34:48,360 But you see how it says location plus three? 659 00:34:51,320 --> 00:34:51,960 Where am I? 660 00:34:52,680 --> 00:34:53,080 Okay. 661 00:34:53,160 --> 00:34:55,580 Because 455007 is right here. 662 00:34:56,960 --> 00:34:57,360 Okay. 663 00:34:57,420 --> 00:35:00,800 But after the call instruction, remember, IDA is just parsing instructions. 664 00:35:01,620 --> 00:35:04,340 The next instruction, right, the call takes some data. 665 00:35:04,680 --> 00:35:05,820 The data is an address. 666 00:35:06,080 --> 00:35:09,760 And the next instruction boundary would be this jump near pointer 458251. 667 00:35:09,760 --> 00:35:10,800 45825, whatever. 668 00:35:11,580 --> 00:35:12,100 Okay. 669 00:35:12,140 --> 00:35:16,440 The next instruction that IDA can show us isn't even going to be executed. 670 00:35:17,580 --> 00:35:18,100 Okay. 671 00:35:18,100 --> 00:35:25,800 Because this thing says the next statement to be executed should be at 45500A, right? 672 00:35:26,440 --> 00:35:26,960 Okay. 673 00:35:27,020 --> 00:35:29,800 Which is in the middle of that jump instruction. 674 00:35:30,440 --> 00:35:33,700 Because the jump spans 007 to 00C, right? 675 00:35:34,780 --> 00:35:35,300 Okay. 676 00:35:35,360 --> 00:35:38,260 So how does the emulator handle that? 677 00:35:38,320 --> 00:35:38,940 What happens then? 678 00:35:40,000 --> 00:35:40,740 What am I doing? 679 00:35:40,820 --> 00:35:41,400 ASPAC, right? 680 00:35:43,500 --> 00:35:43,860 Okay. 681 00:35:44,600 --> 00:35:49,520 So I've got to consult my cheat sheet and make sure I don't blow the demo. 682 00:35:50,980 --> 00:35:51,340 Okay. 683 00:35:54,300 --> 00:35:55,120 Oh, come on. 684 00:35:58,380 --> 00:35:58,740 Okay. 685 00:35:59,060 --> 00:36:01,680 ASPAC is one of these tools that needs a heap. 686 00:36:02,720 --> 00:36:06,800 So the first thing I need to do, and why I don't do it automatically, don't ask me, 687 00:36:06,900 --> 00:36:09,160 but is we need to set up a heap. 688 00:36:12,740 --> 00:36:15,440 And I'm not a Windows programmer, so I don't know where Windows heaps live. 689 00:36:15,760 --> 00:36:16,120 Okay. 690 00:36:16,160 --> 00:36:17,180 But that's good enough for me. 691 00:36:17,560 --> 00:36:17,920 Okay. 692 00:36:17,980 --> 00:36:22,140 It's outside the programmer space, and it's outside the stack space, and it'll work for 693 00:36:22,140 --> 00:36:22,800 our purposes here. 694 00:36:24,460 --> 00:36:24,820 Okay. 695 00:36:25,600 --> 00:36:27,840 So we have a stack, and we have a heap. 696 00:36:28,760 --> 00:36:29,120 Okay. 697 00:36:29,880 --> 00:36:32,220 And that's what ASPAC's going to need. 698 00:36:32,820 --> 00:36:33,180 Yeah. 699 00:36:34,760 --> 00:36:35,740 This one doesn't need it. 700 00:36:35,780 --> 00:36:35,880 Okay. 701 00:36:35,880 --> 00:36:38,660 So I'm going to step through the code. 702 00:36:39,000 --> 00:36:39,320 Okay. 703 00:36:39,400 --> 00:36:41,480 Make sure that I'm probably not where I want to be. 704 00:36:42,200 --> 00:36:42,520 Okay. 705 00:36:42,600 --> 00:36:43,560 I need to get up here. 706 00:36:43,860 --> 00:36:45,120 I need to jump to that location. 707 00:36:45,360 --> 00:36:47,000 So we start execution from there. 708 00:36:48,040 --> 00:36:48,360 455001. 709 00:36:48,420 --> 00:36:49,020 Everybody sees that? 710 00:36:49,780 --> 00:36:50,100 Okay. 711 00:36:50,160 --> 00:36:50,480 Hopefully. 712 00:36:51,300 --> 00:36:52,740 And we're just going to start stepping. 713 00:36:52,900 --> 00:36:57,920 And I'll push this way down, and maybe we'll see the way that the emulator handles this 714 00:36:58,260 --> 00:36:58,820 sort of code. 715 00:36:58,920 --> 00:37:00,560 So we just did the push all. 716 00:37:00,800 --> 00:37:01,980 You see the cursor jump down. 717 00:37:02,060 --> 00:37:04,520 The next thing we're going to do is the call to the middle of the instruction. 718 00:37:04,700 --> 00:37:05,480 So we hit enter. 719 00:37:05,480 --> 00:37:06,580 We do that. 720 00:37:07,240 --> 00:37:07,660 Okay. 721 00:37:07,720 --> 00:37:08,900 And you see it reorganize the code. 722 00:37:08,960 --> 00:37:09,660 The jump went away. 723 00:37:10,440 --> 00:37:10,860 Okay. 724 00:37:10,900 --> 00:37:14,060 The first three bytes of the jump are now just anonymous data right here. 725 00:37:14,700 --> 00:37:15,120 Okay. 726 00:37:15,160 --> 00:37:17,560 The call was reformatted. 727 00:37:18,160 --> 00:37:18,580 Okay. 728 00:37:18,660 --> 00:37:20,400 It's no longer 07 plus 3. 729 00:37:20,660 --> 00:37:22,800 It is now correctly 00A. 730 00:37:23,400 --> 00:37:23,820 Okay. 731 00:37:23,880 --> 00:37:29,620 And the next few instructions at the point that we just jumped to are reformatted as 732 00:37:29,620 --> 00:37:29,820 code. 733 00:37:30,760 --> 00:37:31,180 Okay. 734 00:37:31,200 --> 00:37:32,800 So we can continue to step through these. 735 00:37:34,040 --> 00:37:35,320 And we work our way through. 736 00:37:35,320 --> 00:37:38,380 And it's just going to keep going wherever it needs to go. 737 00:37:38,460 --> 00:37:40,980 Here's another call into the middle of an instruction, 13 plus 1. 738 00:37:41,540 --> 00:37:41,920 Okay. 739 00:37:41,920 --> 00:37:42,620 It reformats. 740 00:37:43,380 --> 00:37:43,760 Okay. 741 00:37:43,780 --> 00:37:45,120 So now we're down to pop EBP. 742 00:37:46,300 --> 00:37:46,680 Okay. 743 00:37:46,740 --> 00:37:48,200 Continue to step, step. 744 00:37:48,460 --> 00:37:51,720 And I've got to be careful here and see where we are. 745 00:37:54,640 --> 00:37:55,020 Okay. 746 00:37:55,120 --> 00:37:58,380 We're up here at 35. 747 00:37:58,960 --> 00:38:02,600 And you can see I have, again, what I consider one of these danger points coming up. 748 00:38:03,180 --> 00:38:03,560 Okay. 749 00:38:03,560 --> 00:38:05,240 A call to who knows where. 750 00:38:05,540 --> 00:38:06,020 Right. 751 00:38:06,100 --> 00:38:11,140 Something that's completely reliant on whatever EBP happens to be at the moment. 752 00:38:11,700 --> 00:38:12,180 Okay. 753 00:38:13,000 --> 00:38:15,620 So I'm going to step again. 754 00:38:16,460 --> 00:38:16,940 Okay. 755 00:38:17,000 --> 00:38:19,860 So we're going to push EAX and call this function. 756 00:38:20,020 --> 00:38:25,020 So whatever parameter I need to sit in EAX, which I can examine, I can see it's 455441, 757 00:38:25,160 --> 00:38:26,100 whatever that means. 758 00:38:26,900 --> 00:38:27,380 Okay. 759 00:38:27,460 --> 00:38:32,560 And I could use that address in IDA. 760 00:38:32,560 --> 00:38:35,800 I could go examine that address and see what is the parameter to this function. 761 00:38:36,640 --> 00:38:36,880 Okay. 762 00:38:36,920 --> 00:38:38,640 And I can also just do a computation. 763 00:38:38,720 --> 00:38:41,220 Here's EBP at 455013. 764 00:38:42,540 --> 00:38:42,940 Okay. 765 00:38:43,000 --> 00:38:46,480 And I could add this F4D to that. 766 00:38:47,080 --> 00:38:48,940 And we can figure out where are we going. 767 00:38:50,140 --> 00:38:50,540 Okay. 768 00:38:50,580 --> 00:38:52,560 Well, I did it in advance, fortunately. 769 00:38:53,360 --> 00:38:58,960 And we are going to, I think, let's see, 455. 770 00:38:59,700 --> 00:39:00,700 I blew that. 771 00:39:02,140 --> 00:39:02,540 Okay. 772 00:39:04,960 --> 00:39:07,000 455F60, okay, is what the math works out to. 773 00:39:07,080 --> 00:39:10,900 If we take EBP and we add on F4D or whatever that is, that's where we're going. 774 00:39:11,040 --> 00:39:13,280 So in IDA, we'll jump down there and see what it is. 775 00:39:14,560 --> 00:39:14,920 Okay. 776 00:39:14,960 --> 00:39:18,640 Well, that's the import for this unpacker's get module handle. 777 00:39:19,400 --> 00:39:19,760 Okay. 778 00:39:19,800 --> 00:39:21,920 So the unpacker is trying to get a module handle. 779 00:39:22,480 --> 00:39:22,840 Great. 780 00:39:22,940 --> 00:39:24,260 So we're going to skip that function call. 781 00:39:25,880 --> 00:39:26,380 All right. 782 00:39:26,420 --> 00:39:27,180 Let me see where we are. 783 00:39:28,800 --> 00:39:29,160 Okay. 784 00:39:29,340 --> 00:39:31,720 I'm just going to skip these two statements. 785 00:39:31,720 --> 00:39:32,960 I don't care about them. 786 00:39:32,980 --> 00:39:35,100 I can't call get module handle from this emulator. 787 00:39:35,860 --> 00:39:36,240 Okay. 788 00:39:36,420 --> 00:39:39,640 So I'm going to come down here and skip two statements. 789 00:39:39,760 --> 00:39:40,540 I'm going to skip the push. 790 00:39:40,580 --> 00:39:41,320 I'm going to skip the call. 791 00:39:41,560 --> 00:39:44,200 I'm going to skip moving EAX because it doesn't hold anything anyway. 792 00:39:45,560 --> 00:39:45,940 Okay. 793 00:39:46,600 --> 00:39:48,340 Skip the move EAX to EDI. 794 00:39:50,680 --> 00:39:51,700 And we're going to continue. 795 00:39:53,060 --> 00:39:53,440 Okay. 796 00:39:53,920 --> 00:39:59,220 And so at this point, we see the same sort of situation coming up. 797 00:40:01,780 --> 00:40:02,140 Okay. 798 00:40:02,480 --> 00:40:03,260 We're right here. 799 00:40:03,320 --> 00:40:04,960 It's going to do EBP plus F49. 800 00:40:05,780 --> 00:40:06,140 Okay. 801 00:40:06,160 --> 00:40:07,060 I have the same problem. 802 00:40:07,240 --> 00:40:08,860 So the emulator doesn't fix everything. 803 00:40:09,020 --> 00:40:10,340 We still have to do a little bit of investigation. 804 00:40:11,840 --> 00:40:13,360 But where are we going this time? 805 00:40:13,460 --> 00:40:15,220 Well, F49 is just four less than F4D. 806 00:40:16,080 --> 00:40:16,440 Okay. 807 00:40:16,480 --> 00:40:18,500 So we can jump down to roughly the same spot. 808 00:40:19,820 --> 00:40:20,180 Okay. 809 00:40:20,240 --> 00:40:25,100 And see that four less than get module handle is get proc address. 810 00:40:26,200 --> 00:40:26,560 Okay. 811 00:40:26,600 --> 00:40:28,080 So now it's going to call get proc address. 812 00:40:28,780 --> 00:40:29,140 Okay. 813 00:40:29,140 --> 00:40:30,400 Well, what proc does it want? 814 00:40:30,400 --> 00:40:32,400 What procedure is it trying to get the address of? 815 00:40:33,380 --> 00:40:34,640 So we jump back. 816 00:40:37,320 --> 00:40:38,400 And where am I? 817 00:40:38,760 --> 00:40:39,160 4A. 818 00:40:40,700 --> 00:40:41,100 Okay. 819 00:40:41,140 --> 00:40:42,300 So we're right here. 820 00:40:42,680 --> 00:40:43,080 Okay. 821 00:40:43,120 --> 00:40:47,300 So we need to get EAX and EBX will be our two parameters to get proc address. 822 00:40:48,380 --> 00:40:48,780 Okay. 823 00:40:48,820 --> 00:40:50,540 But EAX is just the module handle. 824 00:40:50,620 --> 00:40:54,820 So the interesting thing here with EBX should tell us the procedure I'm getting the address for. 825 00:40:55,320 --> 00:40:55,740 All right. 826 00:40:55,780 --> 00:40:57,760 So as long as I load up EBX here by stepping. 827 00:40:58,780 --> 00:40:59,180 Okay. 828 00:40:59,180 --> 00:41:01,380 EBX is 455071. 829 00:41:02,740 --> 00:41:03,100 Okay. 830 00:41:03,100 --> 00:41:09,340 And we go over here and scroll down a little bit to 455071, which happens to be right here. 831 00:41:09,660 --> 00:41:13,520 And if we reformat it, you see they're trying to get the address of virtual alloc. 832 00:41:13,800 --> 00:41:16,320 And very shortly, they'll try to get the address of virtual free. 833 00:41:17,380 --> 00:41:17,740 Okay. 834 00:41:17,760 --> 00:41:20,420 And so, you know, this motivated me to develop the heap. 835 00:41:20,520 --> 00:41:22,100 And we'll continue from here. 836 00:41:22,160 --> 00:41:22,900 But we're going to skip that. 837 00:41:23,320 --> 00:41:23,980 We don't care. 838 00:41:25,240 --> 00:41:25,600 Okay. 839 00:41:27,520 --> 00:41:28,440 Well, now we do care. 840 00:41:28,440 --> 00:41:32,460 Because this is where function hooking gets interesting or comes into play. 841 00:41:33,680 --> 00:41:34,120 Okay. 842 00:41:34,200 --> 00:41:35,520 So here's where we are. 843 00:41:36,200 --> 00:41:39,320 We need to – no, we're not there yet. 844 00:41:41,440 --> 00:41:41,880 Okay. 845 00:41:42,000 --> 00:41:42,740 We're up here. 846 00:41:43,060 --> 00:41:44,420 Getting ready to call get proc address. 847 00:41:45,320 --> 00:41:46,400 So we're going to skip it. 848 00:41:46,740 --> 00:41:47,320 Don't care. 849 00:41:48,260 --> 00:41:48,700 Okay. 850 00:41:48,760 --> 00:41:55,580 At this point, back from get proc address, though, I have what should be the address for virtual alloc. 851 00:41:56,940 --> 00:41:57,380 Okay. 852 00:41:57,380 --> 00:42:00,140 And what I'm going to do here is I'm going to hook something. 853 00:42:00,920 --> 00:42:01,140 Okay. 854 00:42:01,180 --> 00:42:04,800 So the address of get proc or virtual alloc should be an EAX, right? 855 00:42:05,460 --> 00:42:05,860 Okay. 856 00:42:05,880 --> 00:42:07,900 So I'm just going to throw in a one there for kicks. 857 00:42:08,960 --> 00:42:09,360 Okay. 858 00:42:09,740 --> 00:42:11,940 So something that's out of range, out of bounds. 859 00:42:12,720 --> 00:42:13,120 Okay. 860 00:42:13,160 --> 00:42:19,420 And then what I'm going to go do over here on the emulator is I am going to hook a function. 861 00:42:20,540 --> 00:42:20,940 Okay. 862 00:42:21,480 --> 00:42:22,740 Program location one. 863 00:42:24,280 --> 00:42:24,680 Okay. 864 00:42:24,700 --> 00:42:26,440 And the available functions. 865 00:42:28,400 --> 00:42:29,340 There we go. 866 00:42:29,380 --> 00:42:29,920 Virtual alloc. 867 00:42:30,480 --> 00:42:30,880 Okay. 868 00:42:30,940 --> 00:42:37,720 So if we ever call one, okay, we're going to jump aside and call the emulated virtual alloc. 869 00:42:38,980 --> 00:42:39,380 Okay. 870 00:42:39,420 --> 00:42:41,680 So I trick get proc address. 871 00:42:42,560 --> 00:42:42,960 Okay. 872 00:42:43,060 --> 00:42:44,100 We're going to shove a one. 873 00:42:44,140 --> 00:42:48,000 We're going to set a one in its sort of import for virtual alloc there. 874 00:42:48,200 --> 00:42:48,580 Okay. 875 00:42:48,700 --> 00:42:55,420 And whenever we come back, now as I step through the code, okay, we'll save the one as a result of get proc address. 876 00:42:55,900 --> 00:42:56,300 Okay. 877 00:42:56,440 --> 00:43:00,420 And in the future when we see a call to one, we'll step aside and we'll allocate some memory. 878 00:43:01,200 --> 00:43:01,640 Okay. 879 00:43:01,800 --> 00:43:03,520 So same thing down here. 880 00:43:04,680 --> 00:43:05,700 F49, F49. 881 00:43:05,820 --> 00:43:07,280 We're going to call get proc address again. 882 00:43:07,460 --> 00:43:08,520 What are we calling though? 883 00:43:08,680 --> 00:43:09,760 Look at EBX. 884 00:43:10,560 --> 00:43:11,000 Okay. 885 00:43:11,120 --> 00:43:18,320 EBX is now 07E, which is virtual free. 886 00:43:19,180 --> 00:43:19,620 Okay. 887 00:43:19,660 --> 00:43:20,340 So same thing. 888 00:43:21,320 --> 00:43:21,760 Okay. 889 00:43:21,840 --> 00:43:24,340 I want to now skip the push there. 890 00:43:24,460 --> 00:43:25,320 Skip the call there. 891 00:43:25,320 --> 00:43:29,600 And here I'm just going to give it a different address. 892 00:43:29,720 --> 00:43:30,020 So two. 893 00:43:31,700 --> 00:43:32,060 Okay. 894 00:43:32,180 --> 00:43:33,680 Make up any, you know, it could be anything you want. 895 00:43:35,120 --> 00:43:35,480 Okay. 896 00:43:35,520 --> 00:43:36,720 And I'm going to hook that function. 897 00:43:38,600 --> 00:43:42,120 Program location two is going to get virtual free. 898 00:43:45,180 --> 00:43:45,540 Okay. 899 00:43:45,620 --> 00:43:46,840 And all that does is set it aside. 900 00:43:46,880 --> 00:43:52,320 So now the emulator will step aside into the emulated heat memory, heat management functions. 901 00:43:53,340 --> 00:43:53,700 Okay. 902 00:43:53,700 --> 00:43:56,180 And now we can move forward. 903 00:43:57,880 --> 00:43:58,400 Okay. 904 00:43:58,500 --> 00:44:00,440 We still haven't deobfuscated much of anything. 905 00:44:01,760 --> 00:44:02,280 Okay. 906 00:44:03,000 --> 00:44:09,120 So we need to, hopefully we're at 66 and we start stepping through there. 907 00:44:10,620 --> 00:44:11,140 Okay. 908 00:44:11,300 --> 00:44:12,280 We're down to here. 909 00:44:12,920 --> 00:44:13,960 Step, step. 910 00:44:14,120 --> 00:44:15,280 That gets us down below. 911 00:44:17,160 --> 00:44:17,680 Okay. 912 00:44:17,740 --> 00:44:19,560 And we're working our way down here. 913 00:44:21,820 --> 00:44:22,340 Okay. 914 00:44:22,340 --> 00:44:24,000 And now, let's see. 915 00:44:25,020 --> 00:44:25,380 Okay. 916 00:44:25,420 --> 00:44:28,200 Here's an example right here. 917 00:44:29,700 --> 00:44:30,940 54D, that's virtual alloc. 918 00:44:31,260 --> 00:44:31,620 Okay. 919 00:44:31,660 --> 00:44:37,240 That's where they stored the address of virtual alloc. 920 00:44:37,300 --> 00:44:38,440 And if I step one more time. 921 00:44:38,720 --> 00:44:39,080 Okay. 922 00:44:39,120 --> 00:44:39,880 Watch EAX. 923 00:44:40,760 --> 00:44:41,120 Okay. 924 00:44:41,360 --> 00:44:42,940 I grabbed some heat memory. 925 00:44:43,020 --> 00:44:43,700 I know that was exciting. 926 00:44:44,040 --> 00:44:44,400 Okay. 927 00:44:44,440 --> 00:44:47,300 But remember I set the heap up at C0000, right? 928 00:44:47,600 --> 00:44:52,100 So I just asked for some memory off the heap and it gave me a block right at the start of the heap. 929 00:44:53,020 --> 00:44:53,340 Okay. 930 00:44:53,440 --> 00:44:54,300 And if we keep stepping. 931 00:44:55,000 --> 00:44:55,320 Okay. 932 00:44:55,400 --> 00:44:56,300 I think it's going to come up. 933 00:44:56,380 --> 00:44:58,060 And you see that it asked for 1800 bytes. 934 00:44:59,060 --> 00:45:00,000 1800 hex, right? 935 00:45:00,240 --> 00:45:00,560 Okay. 936 00:45:00,620 --> 00:45:01,540 Whatever that works out to. 937 00:45:02,440 --> 00:45:02,760 Okay. 938 00:45:03,040 --> 00:45:03,840 One and a half K. 939 00:45:05,020 --> 00:45:05,340 Okay. 940 00:45:05,380 --> 00:45:06,920 You see down here, we're going to call it again. 941 00:45:07,780 --> 00:45:08,100 Okay. 942 00:45:08,160 --> 00:45:09,260 So we can continue to step. 943 00:45:13,840 --> 00:45:14,160 Okay. 944 00:45:14,200 --> 00:45:15,540 We're going to call virtual alloc again. 945 00:45:15,640 --> 00:45:16,500 And you can see EAX. 946 00:45:16,560 --> 00:45:18,020 Can you ever see EAX at the bottom there? 947 00:45:18,240 --> 00:45:18,560 Barely. 948 00:45:19,380 --> 00:45:19,700 Okay. 949 00:45:20,700 --> 00:45:21,020 C1804. 950 00:45:21,700 --> 00:45:22,020 Okay. 951 00:45:22,080 --> 00:45:32,200 So it's basically 1800 hex bytes into the heap and you can sort of get the feel that indeed we're allocating memory out of this toy heap that I've built. 952 00:45:33,060 --> 00:45:33,400 Okay. 953 00:45:33,540 --> 00:45:35,280 So now we're on a roll, sort of. 954 00:45:36,920 --> 00:45:37,280 Okay. 955 00:45:37,340 --> 00:45:38,320 So we keep stepping through. 956 00:45:39,120 --> 00:45:43,060 We've got the two functions hooked that are of interest to us, virtual alloc and virtual free. 957 00:45:43,600 --> 00:45:48,480 And then the way this works is, and I have a bad angle on this, is we're looking for loops. 958 00:45:48,620 --> 00:45:49,760 I shouldn't have done that. 959 00:45:49,760 --> 00:45:51,840 So now I'm just stepping through. 960 00:45:52,020 --> 00:45:54,480 And it's got all these functions and I don't really want to step into them. 961 00:45:55,280 --> 00:46:00,480 Every time you have a function that gets called, an IDA that's sub here, subroutine. 962 00:46:01,340 --> 00:46:01,720 Okay. 963 00:46:01,760 --> 00:46:05,580 You sort of have to descend into it and verify that it's not going to make any library calls. 964 00:46:06,320 --> 00:46:06,700 Okay. 965 00:46:06,720 --> 00:46:08,100 When you're doing this for the first time. 966 00:46:08,220 --> 00:46:11,920 You don't want to get hung up and sent out to fetch from the middle of nowhere. 967 00:46:13,120 --> 00:46:13,500 Okay. 968 00:46:13,860 --> 00:46:19,660 So we work our way through this function and you can see a loop that's formed here. 969 00:46:19,700 --> 00:46:19,740 Okay. 970 00:46:20,220 --> 00:46:21,300 We don't need it, I guess. 971 00:46:22,900 --> 00:46:23,380 Yeah, we do. 972 00:46:23,580 --> 00:46:23,860 Okay. 973 00:46:23,900 --> 00:46:25,360 So we're going around and around this loop. 974 00:46:25,940 --> 00:46:26,760 I don't want to do that. 975 00:46:28,360 --> 00:46:29,240 How am I doing on time? 976 00:46:29,580 --> 00:46:30,500 Got a ways to go, right? 977 00:46:31,720 --> 00:46:32,000 Okay. 978 00:46:32,000 --> 00:46:32,880 So we'll run to cursor. 979 00:46:33,520 --> 00:46:33,820 What's that? 980 00:46:33,920 --> 00:46:34,540 Still have a half hour? 981 00:46:35,220 --> 00:46:36,100 Plenty of time to screw up. 982 00:46:38,840 --> 00:46:39,120 Okay. 983 00:46:39,160 --> 00:46:40,620 So what I'm going to do is I'm going to look at all. 984 00:46:40,660 --> 00:46:41,600 I've been through all these functions. 985 00:46:41,700 --> 00:46:42,480 You're going to have to trust me. 986 00:46:43,520 --> 00:46:43,800 Okay. 987 00:46:43,820 --> 00:46:46,980 I'm going to work my way down and we're just going to run out to the function return here. 988 00:46:47,720 --> 00:46:48,000 Okay. 989 00:46:49,460 --> 00:46:49,740 So we're going to run through all these functions. 990 00:46:50,420 --> 00:46:50,860 Okay. 991 00:46:50,940 --> 00:46:55,240 If we get hourglass cursor for a while, then the demo's gone south. 992 00:46:55,480 --> 00:46:58,220 But we'll step out of there, continue stepping. 993 00:47:03,120 --> 00:47:03,560 Okay. 994 00:47:03,560 --> 00:47:05,920 Again, I'm not going to step into that. 995 00:47:07,520 --> 00:47:09,000 I need more screen real estate. 996 00:47:14,400 --> 00:47:14,840 Okay. 997 00:47:16,840 --> 00:47:17,280 Okay. 998 00:47:17,320 --> 00:47:18,580 We've worked our way out of that function. 999 00:47:21,540 --> 00:47:21,860 Okay. 1000 00:47:21,860 --> 00:47:23,260 Don't want to go into that either. 1001 00:47:24,520 --> 00:47:27,840 And the idea is at this point, cross your fingers. 1002 00:47:31,420 --> 00:47:31,740 Okay. 1003 00:47:31,780 --> 00:47:31,920 Good. 1004 00:47:32,020 --> 00:47:32,380 It came back. 1005 00:47:33,040 --> 00:47:33,360 Okay. 1006 00:47:33,800 --> 00:47:35,360 Run to cursor is a dangerous thing, right? 1007 00:47:35,400 --> 00:47:36,440 Because you have to hit that address. 1008 00:47:37,280 --> 00:47:37,600 Okay. 1009 00:47:37,620 --> 00:47:40,480 If you don't ever hit that address, you're not going to get control back from the emulator. 1010 00:47:40,620 --> 00:47:42,200 But fortunately it worked today. 1011 00:47:42,880 --> 00:47:43,760 It's been known not to. 1012 00:47:46,080 --> 00:47:47,340 And we work our way down. 1013 00:47:48,240 --> 00:47:48,560 Okay. 1014 00:47:52,180 --> 00:47:53,300 We get out of this function. 1015 00:47:55,660 --> 00:47:57,120 Don't let me step into any more functions. 1016 00:47:58,280 --> 00:47:59,160 It takes too long. 1017 00:48:05,820 --> 00:48:06,140 Okay. 1018 00:48:07,100 --> 00:48:09,040 Now we're in a trouble spot, right? 1019 00:48:09,080 --> 00:48:09,600 Call EDI. 1020 00:48:11,680 --> 00:48:12,760 Well, that might not be so bad. 1021 00:48:15,820 --> 00:48:16,340 I don't know. 1022 00:48:16,520 --> 00:48:17,280 Let's see what happens. 1023 00:48:20,420 --> 00:48:21,280 Oh, that's okay. 1024 00:48:21,320 --> 00:48:23,260 That's a little trick they have. 1025 00:48:24,020 --> 00:48:24,940 Setting up more stuff. 1026 00:48:25,180 --> 00:48:34,940 At some point, at any rate, we get to a point where – I've lost my addresses. 1027 00:48:35,500 --> 00:48:42,120 This thing has been unrolled enough that the original binary will sort of start poking out. 1028 00:48:42,420 --> 00:48:42,800 Okay. 1029 00:48:47,720 --> 00:48:54,780 And the trick is really – the point that I'm making on this one is that with the heap emulation, you can get through all this stuff. 1030 00:48:54,900 --> 00:48:56,760 It's just a matter of stepping a little farther. 1031 00:48:57,360 --> 00:49:05,780 And at some point, we're going to come up against them rebuilding their import table, if I recall correctly. 1032 00:49:09,240 --> 00:49:09,720 Let's see. 1033 00:49:15,380 --> 00:49:15,700 Okay. 1034 00:49:15,740 --> 00:49:17,140 I think I'm in some sort of loop over here. 1035 00:49:17,360 --> 00:49:18,120 Yes, I am. 1036 00:49:18,280 --> 00:49:19,560 I keep jumping back to the top. 1037 00:49:19,880 --> 00:49:30,240 So what I want to do is work my way down, try and find where this loop rolls out, which, again, is a dangerous thing. 1038 00:49:33,840 --> 00:49:36,580 And if I don't get my cursor back, we'll just jump to a new demo. 1039 00:49:43,500 --> 00:49:43,800 Okay. 1040 00:49:44,300 --> 00:49:44,980 Reorganize some code. 1041 00:49:45,180 --> 00:49:45,740 Keep on going. 1042 00:49:55,020 --> 00:49:55,320 Okay. 1043 00:49:55,500 --> 00:49:56,580 Not sure where we're going there. 1044 00:49:56,740 --> 00:50:03,220 So – well, these are memory allocators, if I recall. 1045 00:50:04,200 --> 00:50:05,560 Yeah, we want to get out of this business. 1046 00:50:09,820 --> 00:50:11,740 So at some point, what I would like to get to – 1047 00:50:16,620 --> 00:50:19,640 and we're sort of back up to the top of that too – 1048 00:50:23,400 --> 00:50:32,100 is I find the end of this loop, which is difficult with this screen. 1049 00:50:34,240 --> 00:50:34,600 Okay. 1050 00:50:35,500 --> 00:50:35,860 All right. 1051 00:50:36,640 --> 00:50:37,360 All right. 1052 00:50:41,300 --> 00:50:41,660 All right. 1053 00:50:41,740 --> 00:50:45,880 Ideally, what you want to do is sort of find the end of a loop that you know is safe to run through and then hit run to cursor. 1054 00:50:56,900 --> 00:50:58,720 Without any dangerous calls in the middle. 1055 00:51:01,460 --> 00:51:04,540 And, again, I'm going to gamble right here. 1056 00:51:10,000 --> 00:51:10,860 And we made it. 1057 00:51:19,120 --> 00:51:26,080 And what I'm going to do is try to – is cheat and see if maybe we're somewhere useful. 1058 00:51:33,820 --> 00:51:34,380 Okay. 1059 00:51:38,220 --> 00:51:39,280 With no strings. 1060 00:51:39,280 --> 00:51:41,840 No strings to speak of. 1061 00:51:43,760 --> 00:51:45,480 Although there's – let's see what we get. 1062 00:51:48,820 --> 00:51:49,220 Okay. 1063 00:51:49,360 --> 00:51:52,300 And now you can see a variety of other strings have come into play. 1064 00:51:53,440 --> 00:51:53,840 Okay. 1065 00:51:53,900 --> 00:51:55,820 Which means that we've probably got good code. 1066 00:51:55,960 --> 00:51:57,800 You can see some IRC-type stuff in here. 1067 00:51:58,680 --> 00:51:59,080 Okay. 1068 00:51:59,300 --> 00:52:05,240 So the way to do this is then you want to try to find the end of that loop. 1069 00:52:05,380 --> 00:52:09,140 You want to try to find the control transfer point where you leave the – 1070 00:52:09,140 --> 00:52:12,480 the obfuscation part and you jump to the original code. 1071 00:52:12,740 --> 00:52:15,200 And then you're going to – then you're able to start your reverse engineering. 1072 00:52:15,560 --> 00:52:15,880 Okay. 1073 00:52:15,880 --> 00:52:16,320 But it's there. 1074 00:52:16,900 --> 00:52:17,340 Okay. 1075 00:52:17,540 --> 00:52:19,060 And hopefully the strings convince you it's there. 1076 00:52:19,140 --> 00:52:21,920 We shouldn't have these strings unless we actually correctly decrypted the binary. 1077 00:52:22,500 --> 00:52:22,940 Okay. 1078 00:52:22,960 --> 00:52:26,200 So I'll leave it at that and move on to the next one. 1079 00:52:26,260 --> 00:52:27,780 Any questions from anybody? 1080 00:52:28,000 --> 00:52:29,160 Let's start over here. 1081 00:52:31,200 --> 00:52:31,640 . 1082 00:52:37,560 --> 00:52:44,160 A lot of these things will do anti-debugging type things where if they detect the presence of a debugger, they'll shut down. 1083 00:52:45,060 --> 00:52:45,420 Okay. 1084 00:52:46,680 --> 00:52:50,880 My personal – I don't like running malicious code even in a debugger in a sandbox. 1085 00:52:51,480 --> 00:52:51,880 Okay. 1086 00:52:51,900 --> 00:52:56,660 There are ways – you can run some of these things like in a sandbox environment and then use a tool like Lord PE. 1087 00:52:57,340 --> 00:52:57,740 Okay. 1088 00:52:57,800 --> 00:53:01,280 Just grab the memory image and then you can just debug the memory image. 1089 00:53:01,340 --> 00:53:01,580 Okay. 1090 00:53:01,640 --> 00:53:09,760 Or you can reverse engineer the memory image because IDA will take that Lord PE dump and load it up just fine. 1091 00:53:10,600 --> 00:53:10,700 Okay. 1092 00:53:10,760 --> 00:53:11,680 But there are other tools. 1093 00:53:12,000 --> 00:53:14,700 Again, what really motivated the development of this thing was Shiva. 1094 00:53:15,560 --> 00:53:16,000 Okay. 1095 00:53:16,300 --> 00:53:17,460 Which runs on Linux. 1096 00:53:17,560 --> 00:53:21,180 And we can jump over – and this will also do Linux binaries. 1097 00:53:21,920 --> 00:53:22,360 Okay. 1098 00:53:22,380 --> 00:53:24,220 So it's x86 code in general. 1099 00:53:24,260 --> 00:53:31,220 So we can run Linux binaries in an emulated fashion on IDA running on Windows and get at those as well. 1100 00:53:31,220 --> 00:53:36,860 So there are people that probably would prefer to do it in a debugger. 1101 00:53:37,380 --> 00:53:37,860 Okay. 1102 00:53:37,920 --> 00:53:39,540 I prefer not to run hostile code. 1103 00:53:39,800 --> 00:53:42,060 And so that's what it buys me anyway. 1104 00:53:42,940 --> 00:53:43,420 Okay. 1105 00:53:43,460 --> 00:53:44,680 There was another question back here. 1106 00:53:45,400 --> 00:53:45,880 . 1107 00:53:50,880 --> 00:53:51,360 No. 1108 00:53:52,240 --> 00:53:54,280 But that's a good thing to put on the to-do list. 1109 00:53:55,000 --> 00:53:55,480 Yeah. 1110 00:53:55,480 --> 00:53:55,640 Yeah. 1111 00:53:55,660 --> 00:53:59,120 It's definitely worth saving state at some point. 1112 00:53:59,820 --> 00:54:00,300 Okay. 1113 00:54:00,300 --> 00:54:03,600 So that you could get back into the binary and sort of resume wherever you left off. 1114 00:54:04,160 --> 00:54:04,560 Okay. 1115 00:54:04,580 --> 00:54:05,940 But it is not in there right now. 1116 00:54:06,540 --> 00:54:06,960 Okay. 1117 00:54:08,000 --> 00:54:09,280 Any other questions? 1118 00:54:10,440 --> 00:54:10,860 Okay. 1119 00:54:10,960 --> 00:54:12,360 TLOC we'll do next. 1120 00:54:13,960 --> 00:54:14,380 Okay. 1121 00:54:14,420 --> 00:54:16,520 Which is – so this is a so big virus. 1122 00:54:17,200 --> 00:54:17,620 Okay. 1123 00:54:18,620 --> 00:54:21,480 And like everything else, it's got broken imports. 1124 00:54:23,000 --> 00:54:25,060 And we got one instruction out of that. 1125 00:54:26,740 --> 00:54:27,160 Okay. 1126 00:54:27,220 --> 00:54:28,440 Although it just jumps up here. 1127 00:54:28,440 --> 00:54:32,880 And then starts doing crazy stuff. 1128 00:54:33,160 --> 00:54:33,280 Okay. 1129 00:54:33,340 --> 00:54:34,580 Like jumping to the middle of instructions. 1130 00:54:34,840 --> 00:54:35,100 Okay. 1131 00:54:35,120 --> 00:54:36,020 Pretty common stuff. 1132 00:54:36,900 --> 00:54:39,080 So we'll go back down here to the start location. 1133 00:54:41,200 --> 00:54:42,900 And bring up the emulator. 1134 00:54:44,080 --> 00:54:47,060 Don't need a heap in this case. 1135 00:54:47,900 --> 00:54:51,540 But I do need a threat environment block. 1136 00:54:52,100 --> 00:54:52,620 Okay. 1137 00:54:52,680 --> 00:54:53,980 Because this thing is going to generate exceptions. 1138 00:54:55,160 --> 00:54:55,680 Okay. 1139 00:54:55,700 --> 00:54:58,100 So the way I do that is I'll just – 1140 00:54:58,100 --> 00:55:00,900 steal some space down here at the end of the stack. 1141 00:55:06,020 --> 00:55:08,300 So basically that memory is mine. 1142 00:55:09,140 --> 00:55:09,540 Okay. 1143 00:55:09,800 --> 00:55:15,280 Those, you know, whatever 16 – you know, those 64 bytes I just pushed on the stack. 1144 00:55:15,460 --> 00:55:17,020 Everything gets pushed as a 4 byte int. 1145 00:55:17,360 --> 00:55:19,340 So I just push 64 bytes on the stack. 1146 00:55:19,400 --> 00:55:20,440 That memory belongs to me. 1147 00:55:20,860 --> 00:55:24,800 Because as far as the program is concerned, the stack pointer is starting at FFC0 right there. 1148 00:55:25,400 --> 00:55:25,800 Okay. 1149 00:55:25,800 --> 00:55:33,440 So I can play around and point – I can put the FS base up in that space that belongs to me. 1150 00:55:34,060 --> 00:55:34,460 Okay. 1151 00:55:34,500 --> 00:55:39,340 I need at least the first part of that, the first two words of that, so that I can link the exception handlers. 1152 00:55:40,120 --> 00:55:40,520 Okay. 1153 00:55:41,220 --> 00:55:44,120 So we'll stick FS base up there. 1154 00:55:53,440 --> 00:55:55,100 And I'll just stick it at D0. 1155 00:55:55,100 --> 00:55:55,800 Okay. 1156 00:55:56,360 --> 00:55:58,940 So, you know, that's the setup for this thing. 1157 00:55:59,300 --> 00:55:59,660 Okay. 1158 00:55:59,800 --> 00:56:02,160 Because TLOC wants to set up exception handlers. 1159 00:56:02,720 --> 00:56:03,080 Okay. 1160 00:56:03,120 --> 00:56:05,000 So it's going to write to FS colon 0. 1161 00:56:05,660 --> 00:56:07,200 So we – that's got to be writable. 1162 00:56:07,340 --> 00:56:08,560 It's got to be something that we can see. 1163 00:56:08,840 --> 00:56:09,200 Okay. 1164 00:56:09,500 --> 00:56:11,780 So that we can build the chain of exception handlers. 1165 00:56:11,860 --> 00:56:15,400 Now I don't have a default exception handler or anything like that to go by. 1166 00:56:15,700 --> 00:56:18,120 But with TLOC we're okay. 1167 00:56:19,120 --> 00:56:19,480 Okay. 1168 00:56:19,520 --> 00:56:20,780 So we start stepping over here. 1169 00:56:22,200 --> 00:56:23,400 See how big I can make that. 1170 00:56:23,720 --> 00:56:24,080 Okay. 1171 00:56:28,680 --> 00:56:30,460 And again, it's going to reformat everything. 1172 00:56:32,440 --> 00:56:32,780 Okay. 1173 00:56:32,880 --> 00:56:38,040 And you'll notice that – well, you'll see some strange disassembly like this VX decal and so on. 1174 00:56:38,100 --> 00:56:43,280 But that will end up going away as we reformat all the code. 1175 00:56:46,520 --> 00:56:52,060 And what I need to do is get over here. 1176 00:56:52,560 --> 00:56:52,900 Okay. 1177 00:56:54,500 --> 00:56:56,000 So we just keep working our way through. 1178 00:56:56,380 --> 00:56:59,020 And TLOC's pretty well behaved except for the exception handlers. 1179 00:56:59,500 --> 00:57:02,380 And here's a loop that it's in. 1180 00:57:02,680 --> 00:57:05,080 So we're going to want to jump down here to the end of the loop. 1181 00:57:05,400 --> 00:57:07,300 You've got to be very careful how far you jump. 1182 00:57:08,040 --> 00:57:08,400 Okay. 1183 00:57:08,420 --> 00:57:09,180 When you do this stuff. 1184 00:57:09,300 --> 00:57:11,300 Yeah, I want to jump past the end of the loop. 1185 00:57:12,120 --> 00:57:12,480 Okay. 1186 00:57:13,260 --> 00:57:18,340 But it turns out that this loop is unraveling all of these bytes right immediately after it. 1187 00:57:19,060 --> 00:57:19,420 Okay. 1188 00:57:19,440 --> 00:57:21,320 So if I chose this instruction right here, 1189 00:57:21,320 --> 00:57:24,200 that might not be the start of an instruction in the future. 1190 00:57:25,300 --> 00:57:25,600 Okay. 1191 00:57:25,660 --> 00:57:29,660 So you've got to be – and if I said run to cursor, then I'm off in Never Never Land, right? 1192 00:57:31,120 --> 00:57:32,700 So you've got to be pretty careful. 1193 00:57:32,800 --> 00:57:35,260 So I'll choose the first instruction right after the loop. 1194 00:57:35,340 --> 00:57:37,880 I mean, that's going to be the fall through when this JG fails. 1195 00:57:39,000 --> 00:57:39,360 Okay. 1196 00:57:39,420 --> 00:57:40,680 And I'll take that. 1197 00:57:41,040 --> 00:57:44,420 Regardless of whether the JCXZ gets reformatted into another instruction, 1198 00:57:44,620 --> 00:57:47,860 at least the boundary's going to fall at 3C right here. 1199 00:57:48,680 --> 00:57:49,940 So we run to cursor. 1200 00:57:52,120 --> 00:57:52,480 Okay. 1201 00:57:52,580 --> 00:57:57,520 And you'll see that VXD call actually will go away as the code gets reformatted. 1202 00:58:01,220 --> 00:58:02,880 You've just got to follow along. 1203 00:58:03,060 --> 00:58:07,020 I apologize if I'm going too fast through the stepping and it doesn't make sense. 1204 00:58:07,700 --> 00:58:09,380 I want to make sure I get all the demos in. 1205 00:58:09,460 --> 00:58:13,560 But the things I'm looking for are calls to library functions that I don't want to follow. 1206 00:58:16,960 --> 00:58:20,160 Anything that looks like it's going to do a fetch that isn't going to work out. 1207 00:58:21,040 --> 00:58:21,440 Okay. 1208 00:58:22,600 --> 00:58:23,640 So here you go. 1209 00:58:23,700 --> 00:58:25,760 You can see TLOC's starting to set up an exception handler. 1210 00:58:26,500 --> 00:58:26,900 Okay. 1211 00:58:26,920 --> 00:58:30,480 Zeroes out ECX, writes to FS colon zero right here. 1212 00:58:31,080 --> 00:58:31,480 Okay. 1213 00:58:32,580 --> 00:58:34,700 After, well, it's done some strange stuff. 1214 00:58:35,160 --> 00:58:35,560 Okay. 1215 00:58:35,620 --> 00:58:37,380 But it's setting up the exception handler. 1216 00:58:38,260 --> 00:58:38,660 Okay. 1217 00:58:38,780 --> 00:58:39,620 Skips a breakpoint. 1218 00:58:39,700 --> 00:58:41,660 Div ECX at this point is a divide by zero. 1219 00:58:42,940 --> 00:58:43,340 Okay. 1220 00:58:43,380 --> 00:58:48,040 And causes, let's see if we can see some stack growth here. 1221 00:58:48,440 --> 00:58:48,840 FF70. 1222 00:58:48,840 --> 00:58:50,800 So the stack is really sitting right here. 1223 00:58:51,440 --> 00:58:55,060 The divide by zero, notice that the stack jumps all the way down to C44. 1224 00:58:55,660 --> 00:58:56,140 Okay. 1225 00:58:56,160 --> 00:58:59,240 Because the emulator's jammed all that SCH stuff on top of the stack. 1226 00:59:00,040 --> 00:59:00,520 Okay. 1227 00:59:00,680 --> 00:59:02,260 It recognized that exception occurred. 1228 00:59:02,760 --> 00:59:03,240 Okay. 1229 00:59:03,260 --> 00:59:04,980 And it's jumped us. 1230 00:59:06,120 --> 00:59:06,600 Okay. 1231 00:59:06,660 --> 00:59:12,820 If we step one more time, maybe not. 1232 00:59:15,660 --> 00:59:16,140 Okay. 1233 00:59:16,160 --> 00:59:16,600 Next demo. 1234 00:59:16,600 --> 00:59:16,740 Next demo. 1235 00:59:17,880 --> 00:59:18,900 That didn't work out. 1236 00:59:19,000 --> 00:59:20,640 I'm not sure what I did there. 1237 00:59:20,740 --> 00:59:23,120 But you can see EIP down here at 0004. 1238 00:59:23,960 --> 00:59:24,400 Okay. 1239 00:59:24,460 --> 00:59:27,460 So I'll come back to that one. 1240 00:59:28,260 --> 00:59:28,700 Okay. 1241 00:59:29,360 --> 00:59:30,820 Something went awry right there. 1242 00:59:31,100 --> 00:59:32,960 It's usually this ice BP screws me up. 1243 00:59:33,220 --> 00:59:34,340 I should have skipped it. 1244 00:59:39,920 --> 00:59:40,360 Okay. 1245 00:59:40,760 --> 00:59:42,440 So one failed demo out of three. 1246 00:59:43,240 --> 00:59:43,680 Okay. 1247 00:59:43,700 --> 00:59:44,240 Moving on. 1248 00:59:44,940 --> 00:59:45,380 Okay. 1249 00:59:45,420 --> 00:59:45,860 Burn eye. 1250 00:59:46,140 --> 00:59:46,580 Burn eye. 1251 00:59:47,780 --> 00:59:48,180 I'll try to get that. 1252 00:59:48,180 --> 00:59:54,120 So the first one is a Linux obfuscator, and it can operate in a couple different ways. 1253 00:59:55,160 --> 00:59:55,560 Okay. 1254 00:59:55,680 --> 00:59:57,580 Meaningless declarations and so on. 1255 00:59:59,100 --> 01:00:02,640 And in its simplest form, it's really not difficult to get through. 1256 01:00:02,780 --> 01:00:03,060 Okay. 1257 01:00:03,080 --> 01:00:05,080 They can add password protection on top of it. 1258 01:00:05,660 --> 01:00:06,060 Okay. 1259 01:00:06,100 --> 01:00:09,400 In which case, you know, we can't go anywhere unless we supply the password, because they 1260 01:00:09,400 --> 01:00:10,180 use it to decrypt. 1261 01:00:10,380 --> 01:00:11,900 They actually encrypt the binary. 1262 01:00:12,520 --> 01:00:12,920 Okay. 1263 01:00:12,980 --> 01:00:14,340 So you really can't get too far in. 1264 01:00:14,360 --> 01:00:16,580 There's other tools that will do burn eye on the FLI. 1265 01:00:18,300 --> 01:00:19,680 from the command line. 1266 01:00:19,860 --> 01:00:25,060 So this is just an example of running through Linux code in IDA. 1267 01:00:25,120 --> 01:00:27,500 It's x86 code, so we don't really care what platform it's from. 1268 01:00:29,380 --> 01:00:33,840 And so we bring it up. 1269 01:00:35,740 --> 01:00:36,680 Alt F8. 1270 01:00:37,940 --> 01:00:39,220 Don't really need much here. 1271 01:00:42,000 --> 01:00:43,280 And we start running. 1272 01:00:44,320 --> 01:00:46,380 And a loop becomes evidence very quickly. 1273 01:00:47,480 --> 01:00:51,780 Okay, and again, in its simplest form, it really doesn't do much. 1274 01:00:52,080 --> 01:00:54,780 You can see this loop that works right there. 1275 01:00:58,660 --> 01:01:00,620 And I'm just going to run it all the way down to here. 1276 01:01:03,860 --> 01:01:04,220 Okay. 1277 01:01:05,320 --> 01:01:11,820 In theory, I should show you that we have no useful strings at the moment. 1278 01:01:12,740 --> 01:01:14,220 There's kind of a bunch of garbage in here. 1279 01:01:15,920 --> 01:01:16,280 Right? 1280 01:01:17,660 --> 01:01:18,920 Come back over here. 1281 01:01:20,220 --> 01:01:21,100 Run the cursor. 1282 01:01:25,240 --> 01:01:25,740 Okay. 1283 01:01:26,620 --> 01:01:28,020 Go back to the strings window. 1284 01:01:29,380 --> 01:01:29,880 Rescan. 1285 01:01:32,860 --> 01:01:39,660 Okay, and now we see that, indeed, this was a TASO burn-eye encrypted binary. 1286 01:01:40,020 --> 01:01:42,880 And you start to see some of these strings that have popped out. 1287 01:01:43,360 --> 01:01:43,860 Okay. 1288 01:01:44,040 --> 01:01:46,200 Now, this takes further reversing. 1289 01:01:46,580 --> 01:01:51,940 It takes the burn-eye itself to figure out, where do I go next? 1290 01:01:52,820 --> 01:01:54,920 Because burn-eye does a little bit different. 1291 01:01:54,960 --> 01:02:00,700 It actually embeds the entire protected binary as a piece of data in here. 1292 01:02:00,880 --> 01:02:02,440 And then it's going to go through some loading. 1293 01:02:02,500 --> 01:02:03,780 It's going to push it all over into memory. 1294 01:02:03,880 --> 01:02:07,600 It doesn't transfer control directly to the start function. 1295 01:02:08,080 --> 01:02:08,520 Okay. 1296 01:02:08,560 --> 01:02:09,320 It loads it up. 1297 01:02:09,360 --> 01:02:12,500 It acts as a loader now for the embedded binary. 1298 01:02:13,140 --> 01:02:13,580 Okay. 1299 01:02:13,620 --> 01:02:15,920 So we would have to go find that binary in here. 1300 01:02:16,580 --> 01:02:22,780 And it's, again, you know, being able to work through this doesn't necessarily relieve you 1301 01:02:22,780 --> 01:02:24,460 from reverse engineering responsibilities. 1302 01:02:27,680 --> 01:02:31,580 So, you know, the way burn-eye works is you've got the embedded binary. 1303 01:02:31,660 --> 01:02:33,120 So we can go look for the ELF headers. 1304 01:02:33,880 --> 01:02:34,280 Okay. 1305 01:02:34,300 --> 01:02:45,320 So if we go over here in hex view, okay, what I want to do is find 454C46, which is ELF. 1306 01:02:45,920 --> 01:02:46,320 Okay. 1307 01:02:46,360 --> 01:02:46,560 Okay. 1308 01:02:46,560 --> 01:02:46,740 In hex. 1309 01:02:48,340 --> 01:02:49,980 And we can search through it. 1310 01:02:50,020 --> 01:02:50,920 And it occurs here. 1311 01:02:52,020 --> 01:02:52,440 Okay. 1312 01:02:53,740 --> 01:03:01,520 And, you know, because I happen to know this binary and the way burn-eye works is this is not the embedded binary yet. 1313 01:03:01,920 --> 01:03:02,340 Okay. 1314 01:03:02,380 --> 01:03:03,380 We want to go find it again. 1315 01:03:03,980 --> 01:03:04,400 Okay. 1316 01:03:04,440 --> 01:03:06,980 And we find ELF again down here. 1317 01:03:07,840 --> 01:03:08,260 Okay. 1318 01:03:08,320 --> 01:03:10,300 And it turns out that this is the embedded binary. 1319 01:03:11,340 --> 01:03:16,180 And we want to go over to the view window sort of follows along. 1320 01:03:16,720 --> 01:03:18,540 And this looks like all a bunch of data. 1321 01:03:18,860 --> 01:03:19,260 Okay. 1322 01:03:19,320 --> 01:03:22,120 Because IDA couldn't understand what it was initially. 1323 01:03:22,320 --> 01:03:23,140 But we've unrolled it. 1324 01:03:23,160 --> 01:03:24,360 We've actually changed all of this. 1325 01:03:24,500 --> 01:03:27,260 We need to undefine all of this stuff. 1326 01:03:27,960 --> 01:03:29,620 And I'm probably going to go have to search again. 1327 01:03:30,300 --> 01:03:30,700 Okay. 1328 01:03:30,800 --> 01:03:31,400 You know. 1329 01:03:32,740 --> 01:03:33,140 Okay. 1330 01:03:33,240 --> 01:03:33,440 Okay. 1331 01:03:33,620 --> 01:03:36,280 So that takes me down to where I am in my hex view. 1332 01:03:36,440 --> 01:03:37,220 Back over here. 1333 01:03:37,540 --> 01:03:38,580 Scroll a little further. 1334 01:03:39,840 --> 01:03:40,240 Okay. 1335 01:03:40,280 --> 01:03:44,340 And right here is the start of the ELF header. 1336 01:03:44,960 --> 01:03:45,360 Okay. 1337 01:03:45,400 --> 01:03:46,400 For the embedded. 1338 01:03:46,560 --> 01:03:47,260 Protected binary. 1339 01:03:48,000 --> 01:03:50,320 And a way to sort of yank that out of IDA. 1340 01:03:50,420 --> 01:03:52,180 Or the way that I do it anyway is. 1341 01:03:54,600 --> 01:03:55,940 Figure out where I put the emulator. 1342 01:03:57,900 --> 01:03:58,300 Okay. 1343 01:03:59,000 --> 01:03:59,400 And. 1344 01:04:00,560 --> 01:04:01,800 I built in a dump routine. 1345 01:04:02,880 --> 01:04:04,840 So we can just dump from the database. 1346 01:04:04,960 --> 01:04:06,120 And the arbitrary range. 1347 01:04:07,120 --> 01:04:07,520 Okay. 1348 01:04:07,580 --> 01:04:08,940 So we dump. 1349 01:04:09,120 --> 01:04:11,260 It automatically chooses current cursor location. 1350 01:04:12,380 --> 01:04:12,780 Okay. 1351 01:04:12,780 --> 01:04:13,840 Over to the end of the file. 1352 01:04:15,580 --> 01:04:15,980 Okay. 1353 01:04:16,000 --> 01:04:16,540 And I'm going to go ahead. 1354 01:04:16,560 --> 01:04:17,560 And I'm going to save it as three. 1355 01:04:17,660 --> 01:04:18,940 Because I've already done it a couple times. 1356 01:04:23,680 --> 01:04:24,080 Save. 1357 01:04:24,380 --> 01:04:24,780 Okay. 1358 01:04:24,840 --> 01:04:26,780 So we just basically took the embedded binary. 1359 01:04:26,920 --> 01:04:27,860 Dumped it out to disk. 1360 01:04:28,280 --> 01:04:29,460 And then if we were to go. 1361 01:04:30,360 --> 01:04:31,500 We won't save this one. 1362 01:04:32,040 --> 01:04:33,640 Go yank this thing off the disk. 1363 01:04:34,560 --> 01:04:34,960 Okay. 1364 01:04:36,200 --> 01:04:38,200 IDA recognizes it as an ELF. 1365 01:04:39,060 --> 01:04:40,540 Doesn't complain that anything's broken. 1366 01:04:41,800 --> 01:04:42,200 Okay. 1367 01:04:42,260 --> 01:04:43,800 And throws this in at the start function. 1368 01:04:44,640 --> 01:04:45,040 Okay. 1369 01:04:45,100 --> 01:04:46,200 But you can see all the names. 1370 01:04:46,200 --> 01:04:46,760 That are defined. 1371 01:04:46,960 --> 01:04:51,200 And now we can reverse the embedded ELF. 1372 01:04:51,280 --> 01:04:52,400 That was formerly protected. 1373 01:04:53,460 --> 01:04:53,980 Okay. 1374 01:04:55,460 --> 01:04:56,280 And then. 1375 01:04:57,300 --> 01:04:58,220 Last one. 1376 01:04:59,380 --> 01:05:00,120 Doing okay. 1377 01:05:00,200 --> 01:05:00,680 Ten minutes. 1378 01:05:02,700 --> 01:05:03,220 Okay. 1379 01:05:03,240 --> 01:05:03,580 It's Shiva. 1380 01:05:06,080 --> 01:05:06,600 Okay. 1381 01:05:06,640 --> 01:05:08,580 Shiva is the whole story in and of itself. 1382 01:05:10,360 --> 01:05:10,880 Okay. 1383 01:05:11,220 --> 01:05:12,180 Shiva is. 1384 01:05:12,320 --> 01:05:13,000 It really. 1385 01:05:14,340 --> 01:05:16,080 Takes a lot of interesting steps. 1386 01:05:16,200 --> 01:05:18,020 At protecting a binary. 1387 01:05:18,920 --> 01:05:19,560 A. 1388 01:05:19,740 --> 01:05:20,320 It obfuscates. 1389 01:05:20,780 --> 01:05:22,620 Just like all the other things that we've seen. 1390 01:05:23,420 --> 01:05:23,800 Okay. 1391 01:05:24,420 --> 01:05:25,660 But instead of. 1392 01:05:25,720 --> 01:05:26,860 Just embedding it. 1393 01:05:27,080 --> 01:05:29,040 A deobfuscation stub. 1394 01:05:29,960 --> 01:05:31,460 With the protected binary. 1395 01:05:31,940 --> 01:05:33,980 Shiva actually comes with a pretty complex. 1396 01:05:34,100 --> 01:05:34,900 Runtime environment. 1397 01:05:35,960 --> 01:05:36,280 Okay. 1398 01:05:36,340 --> 01:05:36,660 So. 1399 01:05:36,680 --> 01:05:37,080 It. 1400 01:05:37,140 --> 01:05:39,060 It tacks on a runtime environment. 1401 01:05:40,100 --> 01:05:41,560 With the protected binary. 1402 01:05:42,320 --> 01:05:43,520 And this runtime environment. 1403 01:05:44,400 --> 01:05:45,040 Is. 1404 01:05:45,540 --> 01:05:46,180 Responsible. 1405 01:05:46,180 --> 01:05:46,600 For. 1406 01:05:47,160 --> 01:05:47,900 Sort of demand. 1407 01:05:50,220 --> 01:05:50,580 Decrypting. 1408 01:05:50,980 --> 01:05:52,260 Blocks of the protected binary. 1409 01:05:53,020 --> 01:05:53,380 Okay. 1410 01:05:53,380 --> 01:05:53,920 On the fly. 1411 01:05:54,140 --> 01:05:54,460 So. 1412 01:05:55,940 --> 01:05:56,300 No. 1413 01:05:56,680 --> 01:05:57,840 So the protected binary. 1414 01:05:58,020 --> 01:05:58,680 Is never. 1415 01:05:59,360 --> 01:05:59,720 Deep. 1416 01:05:59,760 --> 01:06:00,900 Fully decrypted in memory. 1417 01:06:00,980 --> 01:06:01,620 At any one time. 1418 01:06:03,020 --> 01:06:03,380 Okay. 1419 01:06:03,580 --> 01:06:03,940 And. 1420 01:06:04,020 --> 01:06:04,300 You know. 1421 01:06:04,340 --> 01:06:04,600 That's. 1422 01:06:04,600 --> 01:06:05,360 That's the big thing. 1423 01:06:05,420 --> 01:06:05,560 Right. 1424 01:06:05,580 --> 01:06:05,860 If you. 1425 01:06:05,900 --> 01:06:07,120 If you run these things in debuggers. 1426 01:06:07,220 --> 01:06:07,380 Or. 1427 01:06:07,480 --> 01:06:09,080 If you just let them run on the fly. 1428 01:06:09,200 --> 01:06:09,620 Your goal. 1429 01:06:09,720 --> 01:06:10,380 Your hope is. 1430 01:06:10,540 --> 01:06:10,900 Well. 1431 01:06:10,940 --> 01:06:12,060 I'll just let it run. 1432 01:06:12,620 --> 01:06:14,020 And then once it's steady state. 1433 01:06:14,300 --> 01:06:15,640 I'll dump the process out of memory. 1434 01:06:16,480 --> 01:06:16,840 Okay. 1435 01:06:16,920 --> 01:06:17,280 But Shiva. 1436 01:06:18,180 --> 01:06:19,120 Keeps you from doing that. 1437 01:06:19,180 --> 01:06:19,420 Because. 1438 01:06:19,520 --> 01:06:20,300 The entire thing. 1439 01:06:20,360 --> 01:06:20,520 Again. 1440 01:06:20,560 --> 01:06:21,240 Is never decrypted. 1441 01:06:21,300 --> 01:06:21,500 In fact. 1442 01:06:21,580 --> 01:06:23,000 No more than about a third of it. 1443 01:06:23,060 --> 01:06:24,440 Is decrypted at any one time. 1444 01:06:25,220 --> 01:06:26,000 And they do it. 1445 01:06:26,760 --> 01:06:27,120 Question. 1446 01:06:31,260 --> 01:06:32,480 I know of no Windows. 1447 01:06:32,740 --> 01:06:33,100 Encrypters. 1448 01:06:33,200 --> 01:06:33,580 That'll do that. 1449 01:06:33,840 --> 01:06:34,200 Yeah. 1450 01:06:35,220 --> 01:06:36,340 The way it works. 1451 01:06:36,400 --> 01:06:37,220 Is that it just. 1452 01:06:37,240 --> 01:06:38,760 It fills the process space. 1453 01:06:39,020 --> 01:06:40,040 With CC hex. 1454 01:06:40,220 --> 01:06:41,040 Which is an int three. 1455 01:06:42,040 --> 01:06:42,400 Okay. 1456 01:06:42,880 --> 01:06:43,240 And. 1457 01:06:43,380 --> 01:06:44,720 It puts small blocks. 1458 01:06:44,720 --> 01:06:46,860 Of the decrypted binary. 1459 01:06:46,980 --> 01:06:48,340 Into that process space. 1460 01:06:48,740 --> 01:06:48,900 And so. 1461 01:06:49,000 --> 01:06:50,540 You're going to run off the end of a block. 1462 01:06:51,180 --> 01:06:52,420 And you're going to hit an int three. 1463 01:06:53,160 --> 01:06:54,120 Which it handles. 1464 01:06:55,380 --> 01:06:55,780 Okay. 1465 01:06:55,860 --> 01:06:56,500 And then sees. 1466 01:06:56,580 --> 01:06:56,780 Okay. 1467 01:06:56,860 --> 01:06:57,380 Where am I? 1468 01:06:57,420 --> 01:06:58,440 What's EIP right now? 1469 01:06:59,260 --> 01:07:01,100 Because it's P tracing the binary too. 1470 01:07:01,380 --> 01:07:01,700 Right. 1471 01:07:01,720 --> 01:07:02,400 There's a lot of overhead. 1472 01:07:03,080 --> 01:07:03,480 And. 1473 01:07:03,700 --> 01:07:04,440 Then it goes. 1474 01:07:04,500 --> 01:07:05,400 And grabs the. 1475 01:07:05,460 --> 01:07:07,000 The next portion of the program. 1476 01:07:07,660 --> 01:07:09,760 After overwriting some other portion of the program. 1477 01:07:10,160 --> 01:07:11,140 Decrypts the next portion. 1478 01:07:11,300 --> 01:07:12,840 And then allows execution to resume. 1479 01:07:13,680 --> 01:07:14,080 Okay. 1480 01:07:14,100 --> 01:07:14,280 That's. 1481 01:07:14,280 --> 01:07:14,420 That's. 1482 01:07:14,620 --> 01:07:14,660 That's. 1483 01:07:14,720 --> 01:07:15,620 One of the things it does. 1484 01:07:15,740 --> 01:07:15,880 So. 1485 01:07:16,020 --> 01:07:18,080 You have to be able to get at all of those things. 1486 01:07:19,040 --> 01:07:19,400 And. 1487 01:07:20,120 --> 01:07:20,480 So. 1488 01:07:20,540 --> 01:07:21,840 You had the initial deobfuscation. 1489 01:07:22,420 --> 01:07:23,000 And then. 1490 01:07:23,040 --> 01:07:23,880 You had this runtime. 1491 01:07:23,980 --> 01:07:24,960 Time encryption piece. 1492 01:07:25,100 --> 01:07:26,040 That you have to get past. 1493 01:07:26,220 --> 01:07:27,640 Which means that there are embedded keys. 1494 01:07:28,180 --> 01:07:28,920 In this runtime. 1495 01:07:29,880 --> 01:07:30,480 Because that. 1496 01:07:30,500 --> 01:07:31,460 That stuff is actually encrypted. 1497 01:07:31,640 --> 01:07:32,880 So you have to do some key recovery. 1498 01:07:33,120 --> 01:07:34,580 And that's part of the reverse engineering of Shiva. 1499 01:07:35,200 --> 01:07:35,920 Which gets. 1500 01:07:36,080 --> 01:07:36,420 Again. 1501 01:07:36,620 --> 01:07:37,240 Pretty complicated. 1502 01:07:38,580 --> 01:07:38,940 Okay. 1503 01:07:38,980 --> 01:07:39,900 And Shiva is all about. 1504 01:07:40,060 --> 01:07:40,380 You know. 1505 01:07:40,500 --> 01:07:41,320 Obfuscated code paths. 1506 01:07:41,560 --> 01:07:42,860 It does that all over the place. 1507 01:07:42,860 --> 01:07:43,060 So. 1508 01:07:48,040 --> 01:07:49,140 We can bring this up. 1509 01:07:49,220 --> 01:07:49,600 And we don't. 1510 01:07:49,600 --> 01:07:50,540 Need anything special. 1511 01:07:50,680 --> 01:07:50,920 And again. 1512 01:07:51,000 --> 01:07:51,220 You know. 1513 01:07:51,260 --> 01:07:52,700 We're running through a Linux binary on Windows. 1514 01:07:53,400 --> 01:07:54,320 So that's kind of nice. 1515 01:07:56,200 --> 01:07:57,500 And it becomes a matter of. 1516 01:07:57,520 --> 01:07:58,480 Just stepping on through here. 1517 01:07:58,680 --> 01:08:00,420 And the idea is to recognize some loops. 1518 01:08:01,400 --> 01:08:03,040 And this stuff will reorganize itself. 1519 01:08:06,380 --> 01:08:07,700 So let me get back over here. 1520 01:08:10,820 --> 01:08:11,840 And I lost the emulator. 1521 01:08:16,660 --> 01:08:18,420 And hopefully we can see some loops forming. 1522 01:08:18,600 --> 01:08:19,080 And that's the idea. 1523 01:08:19,200 --> 01:08:19,260 You know. 1524 01:08:19,260 --> 01:08:20,760 IDA is pretty nice about. 1525 01:08:21,680 --> 01:08:22,840 Showing you branching and everything. 1526 01:08:23,160 --> 01:08:24,000 So we can see. 1527 01:08:24,020 --> 01:08:25,740 There is in fact a loop over here. 1528 01:08:25,840 --> 01:08:26,700 With again more screen. 1529 01:08:26,860 --> 01:08:27,420 We would see that. 1530 01:08:27,480 --> 01:08:27,980 So right here. 1531 01:08:28,060 --> 01:08:28,860 We want to run the cursor. 1532 01:08:31,940 --> 01:08:32,300 Okay. 1533 01:08:32,340 --> 01:08:33,460 And then we want to continue stepping. 1534 01:08:33,660 --> 01:08:34,760 Until we find some more loops. 1535 01:08:35,400 --> 01:08:37,280 Here are three of them that Shiva forms. 1536 01:08:44,980 --> 01:08:45,940 At some point. 1537 01:08:47,380 --> 01:08:48,700 I think that was the bottom. 1538 01:08:50,740 --> 01:08:51,260 Okay. 1539 01:08:52,440 --> 01:08:54,000 Lose all my addressing information. 1540 01:08:56,000 --> 01:08:56,520 Okay. 1541 01:08:56,540 --> 01:08:57,900 So we'll go over here. 1542 01:08:59,280 --> 01:09:00,220 Run the cursor. 1543 01:09:05,460 --> 01:09:07,300 I just screwed something up. 1544 01:09:08,160 --> 01:09:08,680 Okay. 1545 01:09:11,780 --> 01:09:12,300 So we'll go over here. 1546 01:09:12,300 --> 01:09:12,380 So I'm going to do. 1547 01:09:18,220 --> 01:09:21,000 Okay, we're on the cursor, we're going to continue looking for the next loop. 1548 01:09:35,500 --> 01:09:36,960 This is getting pretty dry, I know. 1549 01:09:38,200 --> 01:09:39,860 You get the idea, hopefully. 1550 01:09:39,860 --> 01:09:43,780 I can talk more about Shiva afterwards, because I think we're going to end up running out 1551 01:09:43,780 --> 01:09:44,040 of time. 1552 01:09:44,160 --> 01:09:49,440 I'd rather field any questions that are out there, and if there are none, I'll cut you 1553 01:09:49,440 --> 01:09:49,580 loose. 1554 01:09:51,400 --> 01:09:52,280 Question over here again? 1555 01:09:52,580 --> 01:09:54,620 What would you do to build a better obfuscator? 1556 01:09:55,300 --> 01:09:57,140 What would I do to build a better obfuscator? 1557 01:10:04,460 --> 01:10:06,240 Shiva is a good step in the right direction. 1558 01:10:06,380 --> 01:10:09,620 There's actually some tricks in Shiva that are far more advanced. 1559 01:10:09,620 --> 01:10:14,420 They actually do instruction replacement. 1560 01:10:15,720 --> 01:10:22,960 They'll scan the binary that they're trying to protect, and they have a couple different 1561 01:10:22,960 --> 01:10:26,560 types of instructions that they'll emulate, because they're p-tracing that binary. 1562 01:10:27,280 --> 01:10:31,380 They'll go through that binary, and they'll replace them with int3s. 1563 01:10:33,120 --> 01:10:37,280 Those int3s don't cause a new block to be loaded. 1564 01:10:37,520 --> 01:10:38,940 They drop over. 1565 01:10:39,080 --> 01:10:39,600 They say, okay. 1566 01:10:39,620 --> 01:10:42,920 That's an int3, because that instruction, we're going to emulate that instruction. 1567 01:10:43,140 --> 01:10:44,480 They go over and emulate the instruction. 1568 01:10:45,840 --> 01:10:49,700 There are about six different instructions that they emulate, and only in a few places. 1569 01:10:50,480 --> 01:10:54,420 What makes it tricky is, even if you did manage to get the entire binary decrypted 1570 01:10:54,420 --> 01:11:00,220 in memory at one time, or you were able to watch memory, and through the process of one 1571 01:11:00,220 --> 01:11:04,600 third of it being loaded, after enough time, you should have seen all of the blocks loaded. 1572 01:11:05,380 --> 01:11:06,240 Say, okay. 1573 01:11:06,300 --> 01:11:07,120 Now I got the whole thing. 1574 01:11:07,200 --> 01:11:08,200 Well, you don't have the whole thing. 1575 01:11:08,200 --> 01:11:09,180 You don't have the whole thing. 1576 01:11:09,180 --> 01:11:12,320 Because they've inserted these int3s randomly throughout the program. 1577 01:11:13,060 --> 01:11:17,480 What you don't get, even if you capture all of those blocks, is what is supposed to 1578 01:11:17,480 --> 01:11:24,400 be in place of those int3s, which they save aside as a list of ... The int3 at location 1579 01:11:24,400 --> 01:11:28,440 one, two, three, four is supposed to be a push EAX. 1580 01:11:30,020 --> 01:11:33,040 When they hit that int3, they jump over, because they're p-tracing. 1581 01:11:33,160 --> 01:11:34,840 They run the push EAX. 1582 01:11:34,940 --> 01:11:36,040 They manipulate ESP. 1583 01:11:36,160 --> 01:11:37,960 They manipulate memory. 1584 01:11:38,060 --> 01:11:38,180 Okay. 1585 01:11:38,200 --> 01:11:40,860 Then they return control back to the binary. 1586 01:11:41,040 --> 01:11:42,300 So it's really tricky stuff. 1587 01:11:43,800 --> 01:11:46,680 I don't know if Neil's here or not, but probably not. 1588 01:11:47,400 --> 01:11:48,480 Oh, there you are. 1589 01:11:48,580 --> 01:11:49,000 Okay. 1590 01:11:51,240 --> 01:11:56,720 Here's what I would say, is you emulate all these instructions. 1591 01:11:56,900 --> 01:11:58,020 I say there's five of them. 1592 01:11:58,400 --> 01:11:58,440 Okay. 1593 01:11:58,560 --> 01:12:02,260 You have a broader class of instructions that you emulate, because it's really ... You 1594 01:12:02,260 --> 01:12:08,100 have to spend time reverse engineering Shiva to know what instructions are being emulated. 1595 01:12:08,620 --> 01:12:11,500 Then you can ... Your emulation list is fixed. 1596 01:12:11,960 --> 01:12:16,180 You can go, you can pull out the emulation list, and then you can repair them. 1597 01:12:16,420 --> 01:12:20,920 After you've done enough reverse engineering, you know what all the replacements are supposed 1598 01:12:20,920 --> 01:12:21,420 to do. 1599 01:12:21,500 --> 01:12:25,480 You can walk the emulation list and replace the CCs with what is supposed to be there. 1600 01:12:26,800 --> 01:12:26,840 Okay. 1601 01:12:26,920 --> 01:12:35,600 So if you have a broader class of emulations that you do, then you choose a subset for 1602 01:12:35,600 --> 01:12:36,580 each new binary. 1603 01:12:36,840 --> 01:12:38,180 Maybe you could do 20 emulations. 1604 01:12:38,180 --> 01:12:41,360 For each new binary, you only pick a random five. 1605 01:12:42,260 --> 01:12:48,460 So that every binary is ... So there's no way to know ahead of time what emulations 1606 01:12:48,460 --> 01:12:49,320 are going to be used. 1607 01:12:49,500 --> 01:12:51,980 I always know ahead of time what emulations you're going to use right now. 1608 01:12:52,700 --> 01:12:53,100 Okay. 1609 01:12:53,120 --> 01:12:55,920 But if I don't know ahead of time what emulations you're going to use, then I have to spend 1610 01:12:55,920 --> 01:13:00,480 a significant amount of time just to recover your emulation list, and then figure out, 1611 01:13:00,500 --> 01:13:03,300 for each new binary, what is that emulation doing? 1612 01:13:04,660 --> 01:13:05,060 Okay. 1613 01:13:05,380 --> 01:13:07,980 So that's what I ... 1614 01:13:07,980 --> 01:13:11,820 I think that the techniques that Shiva uses would make things very difficult. 1615 01:13:12,000 --> 01:13:17,800 If they were incorporated on the Windows side, it would be among the best sort of obfuscators 1616 01:13:17,800 --> 01:13:18,320 that are out there. 1617 01:13:18,600 --> 01:13:23,300 The SEH stuff is kind of a pain to work through, but it's doable. 1618 01:13:23,560 --> 01:13:28,780 But the Shiva stuff makes ... Not only do you have to reverse, get through the obfuscation, 1619 01:13:28,980 --> 01:13:32,980 but then you have to reverse the way Shiva works, because it's the Shiva runtime that's 1620 01:13:32,980 --> 01:13:33,740 controlling everything. 1621 01:13:34,740 --> 01:13:35,220 Right? 1622 01:13:35,220 --> 01:13:39,980 And so you have to deal with the Shiva runtime just to be able to see the other obfuscated 1623 01:13:39,980 --> 01:13:40,240 code. 1624 01:13:41,460 --> 01:13:41,680 Okay. 1625 01:13:43,760 --> 01:13:44,160 Halvar. 1626 01:13:45,360 --> 01:13:45,760 . 1627 01:13:54,900 --> 01:13:56,580 I can barely hear you. 1628 01:13:56,600 --> 01:13:58,420 There are a lot of commercial encryptors that do that? 1629 01:13:58,900 --> 01:13:59,300 . 1630 01:14:03,500 --> 01:14:03,900 . 1631 01:14:03,900 --> 01:14:03,920 . 1632 01:14:03,920 --> 01:14:04,020 . 1633 01:14:04,020 --> 01:14:04,240 . 1634 01:14:04,240 --> 01:14:04,680 . 1635 01:14:06,360 --> 01:14:06,840 . 1636 01:14:21,060 --> 01:14:27,560 Yeah, that's the way to defeat this kind of thing, is that you make ... Even after 1637 01:14:27,560 --> 01:14:33,180 the obfuscation is done, you've got to do so much reverse engineering that this still 1638 01:14:33,180 --> 01:14:34,320 doesn't help you so much. 1639 01:14:35,360 --> 01:14:35,800 Okay. 1640 01:14:36,920 --> 01:14:37,840 Any other questions? 1641 01:14:39,680 --> 01:14:40,120 Okay. 1642 01:14:40,240 --> 01:14:41,600 I guess, oh, wait, one over here. 1643 01:14:42,120 --> 01:14:44,040 So how did you learn more about Shiva? 1644 01:14:44,360 --> 01:14:45,460 How many calls? 1645 01:14:45,740 --> 01:14:46,580 How do I know? 1646 01:14:46,620 --> 01:14:50,660 Well, I went to Neil's talk last year here where he talked about Shiva, 1647 01:14:50,700 --> 01:14:52,220 and they presented it a couple of times. 1648 01:14:52,860 --> 01:14:54,720 So there is a presentation on Shiva. 1649 01:14:55,180 --> 01:14:59,800 And then I gave a presentation on reversing Shiva. 1650 01:15:00,420 --> 01:15:01,840 So you can go get that. 1651 01:15:01,840 --> 01:15:04,860 And in the process of developing that one, 1652 01:15:05,160 --> 01:15:08,020 then that's what motivated sort of development of this. 1653 01:15:08,160 --> 01:15:14,980 And so I tried to – the development that's gone on on this project has been to make it more generic, 1654 01:15:15,020 --> 01:15:18,080 to handle more classes of obfuscators. 1655 01:15:19,040 --> 01:15:19,560 Yes. 1656 01:15:19,860 --> 01:15:26,120 The plug-in, I've been using it since 4.5 and forward. 1657 01:15:26,380 --> 01:15:29,080 You just have to compile it with the matching SDK. 1658 01:15:29,940 --> 01:15:30,460 Okay. 1659 01:15:30,460 --> 01:15:30,540 Yeah. 1660 01:15:34,300 --> 01:15:36,320 Yeah, the plug-in is free open source. 1661 01:15:36,440 --> 01:15:39,100 The URL is in the slides. 1662 01:15:39,220 --> 01:15:40,520 It's available at SourceForge. 1663 01:15:42,400 --> 01:15:45,920 Any other questions? 1664 01:15:47,600 --> 01:15:48,040 Okay. 1665 01:15:48,080 --> 01:15:48,700 Thank you very much. 1666 01:15:48,960 --> 01:15:49,420 Thank you.