1 00:00:00,000 --> 00:00:02,400 How's it going, everybody? Thanks for sticking around. 2 00:00:03,000 --> 00:00:06,560 Two o'clock on Sunday, I thought it would just be Greg and I talking to ourselves in a room, 3 00:00:06,640 --> 00:00:08,520 which would suck because I don't even really like Greg. 4 00:00:11,900 --> 00:00:16,080 So today we're going to talk about a technique that you can use to decrypt information 5 00:00:16,880 --> 00:00:19,000 that Trojans have in their binary. 6 00:00:19,440 --> 00:00:25,740 I would relate the technique similar to using a calculator to solve a complex math problem. 7 00:00:27,000 --> 00:00:30,120 Sorry, I've got a piece of coffee bean stuck in my throat. 8 00:00:33,840 --> 00:00:38,300 Okay, so using a calculator to solve a complex math problem 9 00:00:38,860 --> 00:00:42,600 kind of alleviates you the hassle of going through all the math yourself. 10 00:00:42,940 --> 00:00:46,720 So I know there's probably a few people out there who could tell me very quickly 11 00:00:46,720 --> 00:00:55,720 or just using your head or using paper what 46.009 divided by 8,432.009 12 00:00:55,740 --> 00:00:58,460 can tell me the answer to that, but I can't. 13 00:00:58,560 --> 00:01:00,020 But I do know where to find my calculator. 14 00:01:00,620 --> 00:01:01,940 So am I screwed? No. 15 00:01:02,040 --> 00:01:03,780 I can still solve the problem. I can do it just as quickly. 16 00:01:04,520 --> 00:01:06,740 So that's what this technique is based on. 17 00:01:06,780 --> 00:01:10,920 We're going to use what's readily available to us to solve problems 18 00:01:10,920 --> 00:01:12,980 that would otherwise be a little bit difficult. 19 00:01:13,320 --> 00:01:14,900 So at this time I'm going to turn it over to Greg, 20 00:01:15,020 --> 00:01:17,560 and he's going to take you through some intro, some theory, 21 00:01:17,700 --> 00:01:21,440 and then we're going to hop into a bunch of real-life demos using a few malware samples. 22 00:01:21,600 --> 00:01:24,600 We're going to show you some cool stuff like the disassembly rather than just boring slides. 23 00:01:25,760 --> 00:01:26,520 Hope you enjoy it. 24 00:01:28,980 --> 00:01:32,800 Okay, so as Mike said, we're basically going to use a debugger to make... 25 00:01:35,520 --> 00:01:36,300 Is this better? 26 00:01:36,800 --> 00:01:38,200 All right. Sorry about that. 27 00:01:38,880 --> 00:01:39,700 Okay, there we go. 28 00:01:39,920 --> 00:01:40,440 All right. 29 00:01:40,580 --> 00:01:45,020 So basically what we're going to talk about is how to use a scripting debugger 30 00:01:45,020 --> 00:01:47,200 to make your life easier when it comes to reversing malware. 31 00:01:47,780 --> 00:01:52,040 As we all know, malware basically obfuscates pretty much everything it can possibly get its hands on, 32 00:01:52,120 --> 00:01:55,420 like strings, configurations, protocols, communicate back to the CNC. 33 00:01:55,960 --> 00:01:57,540 As well as the data that is stolen. 34 00:01:58,200 --> 00:02:02,660 So what we're going to do is use the functions that are already in the malware 35 00:02:02,660 --> 00:02:05,800 that are used for encryption and decryption against itself. 36 00:02:06,980 --> 00:02:09,000 And then, like Mike said, we're going to go through a couple of examples. 37 00:02:09,880 --> 00:02:10,440 All right. 38 00:02:10,580 --> 00:02:13,840 So why do malware authors obfuscate things? 39 00:02:14,100 --> 00:02:18,380 Well, as we all know, this is kind of a game between us as analysts and the malware authors 40 00:02:19,140 --> 00:02:23,120 to make our lives more difficult, to make their code more difficult to understand. 41 00:02:24,260 --> 00:02:25,720 Also, they've worked hard. 42 00:02:25,740 --> 00:02:26,580 They've worked hard to steal the data. 43 00:02:26,940 --> 00:02:32,240 So they don't want other people to take their data away from them, to see what has been stolen, 44 00:02:32,400 --> 00:02:33,760 to make forensics more difficult. 45 00:02:34,340 --> 00:02:39,860 And also, they don't want people knowing what's going to and from the command and control. 46 00:02:40,080 --> 00:02:41,600 They don't know what commands are coming down. 47 00:02:41,800 --> 00:02:43,940 They don't want you knowing what data is being sent back. 48 00:02:44,360 --> 00:02:50,200 As a result, this also makes IDS and IPS signatures and antivirus that matter more difficult to write. 49 00:02:52,000 --> 00:02:55,000 So what we want to do is the opposite of this. 50 00:02:55,000 --> 00:02:57,820 We want to make the reversing easier by making it clear text. 51 00:02:58,180 --> 00:03:01,560 We want to know what data was stolen, what the configuration of the malware is. 52 00:03:01,920 --> 00:03:05,220 As also, we want to know what data is being sent to the command and control server, 53 00:03:05,460 --> 00:03:08,520 what instructions are being received from the command and control server. 54 00:03:08,780 --> 00:03:13,600 And also, we want to have a way to protect ourselves, a way to, for lack of a better solution, 55 00:03:13,740 --> 00:03:16,480 write signatures for IDS, IPS, and antivirus. 56 00:03:17,980 --> 00:03:21,600 So there are three basic ways you can write a decryptor for this kind of data. 57 00:03:21,860 --> 00:03:24,860 The first way is by far the most difficult. 58 00:03:24,860 --> 00:03:26,560 And it requires you to understand the most. 59 00:03:26,820 --> 00:03:28,060 Which is doing it by hand. 60 00:03:28,480 --> 00:03:30,160 Throwing it into a dissembler or debugger. 61 00:03:30,520 --> 00:03:32,980 Figuring out what each function does and going that way. 62 00:03:34,220 --> 00:03:37,080 This approach is slow, painful, and no one likes to do it. 63 00:03:37,900 --> 00:03:40,580 And the more code you have, and the more complex that code is, 64 00:03:40,700 --> 00:03:42,360 the longer you're going to sit there and work on this problem. 65 00:03:43,540 --> 00:03:45,860 Now, recently, within the past year or so, I guess, 66 00:03:46,520 --> 00:03:52,600 there have been advances in decompilers that turn assembly language back into something that resembles C. 67 00:03:53,240 --> 00:03:54,840 So as we all know, C is a hard code. 68 00:03:54,860 --> 00:03:57,720 It's a whole hell of a lot easier to read than looking at straight assembly. 69 00:03:59,060 --> 00:04:00,760 But this also has its problems. 70 00:04:00,880 --> 00:04:01,940 It's still kind of in infancy. 71 00:04:03,700 --> 00:04:04,900 Things don't get typed right. 72 00:04:05,060 --> 00:04:06,260 You have pointers that look funny. 73 00:04:06,440 --> 00:04:08,560 You have data structures that just don't make any damn sense. 74 00:04:08,840 --> 00:04:12,300 So this isn't the all-encompassing solution. 75 00:04:12,780 --> 00:04:15,300 The third one, the one we're actually most of the time talking about today, 76 00:04:15,520 --> 00:04:19,040 is using a debugger that you can script to do all the work for you. 77 00:04:19,260 --> 00:04:22,980 So the malware has made the job actually easier for you. 78 00:04:23,140 --> 00:04:24,840 They have functions that encrypt and decrypt. 79 00:04:24,860 --> 00:04:25,480 They decrypt their data. 80 00:04:25,840 --> 00:04:30,640 So we can use that against it to decrypt the data. 81 00:04:31,660 --> 00:04:34,000 Now, depending on what you're trying to accomplish with this, 82 00:04:35,220 --> 00:04:38,020 not one solution is going to be the catch-all for you. 83 00:04:38,220 --> 00:04:41,340 If you're trying to write a Wireshark filter, 84 00:04:43,360 --> 00:04:45,620 you're not going to be able to do it with a scripting debugger. 85 00:04:45,700 --> 00:04:48,080 You're going to need to get there, figure out what the code's doing, 86 00:04:48,260 --> 00:04:50,220 and write something you can compile into Wireshark. 87 00:04:52,000 --> 00:04:52,500 All right. 88 00:04:52,500 --> 00:04:54,680 So there are three basic classes that we came up with 89 00:04:54,680 --> 00:04:58,180 when it comes to doing scriptable analysis. 90 00:04:58,680 --> 00:05:00,720 The first one is what we call active. 91 00:05:00,980 --> 00:05:03,980 This is where you're not letting the malcode really do its job. 92 00:05:04,080 --> 00:05:05,100 You're not letting it run natively. 93 00:05:05,620 --> 00:05:10,020 You find the functions that do the encryption and decryption, 94 00:05:10,140 --> 00:05:11,140 and you attach to that. 95 00:05:11,340 --> 00:05:14,100 You only run that function to recover what you need. 96 00:05:15,660 --> 00:05:17,900 An example would be trying to recover strings. 97 00:05:18,180 --> 00:05:20,720 Because as we all know, malware loves to obfuscate its strings, 98 00:05:20,720 --> 00:05:23,720 so you can't see what is actually being done 99 00:05:23,720 --> 00:05:25,420 just by looking through a string's output. 100 00:05:25,660 --> 00:05:27,780 So you find the function that decrypts it for it, 101 00:05:27,860 --> 00:05:30,340 and then you run every string you can find through that. 102 00:05:31,280 --> 00:05:33,160 Another way is called passive. 103 00:05:33,340 --> 00:05:37,220 This is where you more or less let the malware run as it normally would, 104 00:05:37,400 --> 00:05:40,000 with the exception that you're running it in a debugger at this point. 105 00:05:40,240 --> 00:05:43,120 And you're monitoring key aspects of it, 106 00:05:43,180 --> 00:05:46,380 either API calls that it does or internal functions. 107 00:05:47,120 --> 00:05:49,260 And we'll go through this example as well, 108 00:05:49,260 --> 00:05:51,780 where you're monitoring the Kraken traffic. 109 00:05:52,840 --> 00:05:54,900 Basically, with Kraken, it tries to encrypt... 110 00:05:54,900 --> 00:05:57,460 Well, it doesn't try, it actually does encrypt the network traffic 111 00:05:57,460 --> 00:05:58,840 going across the wire. 112 00:05:59,100 --> 00:06:01,880 So what you can do is just catch it a couple of lines before, 113 00:06:02,060 --> 00:06:05,060 where it actually encrypts the traffic. 114 00:06:05,220 --> 00:06:07,040 So when it encrypts, it's going to have you in plain text 115 00:06:07,040 --> 00:06:07,940 before it encrypts it. 116 00:06:08,040 --> 00:06:09,160 So you just capture that, 117 00:06:09,260 --> 00:06:12,560 and you can see what's going on with the network traffic. 118 00:06:13,020 --> 00:06:15,020 And the last one is kind of your catch-all solution 119 00:06:15,020 --> 00:06:16,380 when it comes to scripting. 120 00:06:16,440 --> 00:06:18,120 We call it recon and utility scripting. 121 00:06:18,660 --> 00:06:21,780 This is kind of the kitchen sink solution, 122 00:06:22,260 --> 00:06:24,920 where you're looking at things like you're taking an arbitrary file, 123 00:06:25,060 --> 00:06:27,540 like a JPEG or a PDF or whatever, 124 00:06:27,720 --> 00:06:29,840 and you want to see if that possibly has shellcode in it, 125 00:06:29,960 --> 00:06:32,740 or you want to see if there have been any shared libraries 126 00:06:32,740 --> 00:06:33,400 that have been hooked. 127 00:06:34,600 --> 00:06:37,620 Another example we have here is you can use it to unpack malware 128 00:06:37,620 --> 00:06:38,420 without actually running it. 129 00:06:40,000 --> 00:06:41,960 So what are you going to need to do this? 130 00:06:42,240 --> 00:06:43,920 Well, obviously, you need something to work on. 131 00:06:43,960 --> 00:06:44,600 You need something to analyze. 132 00:06:45,900 --> 00:06:47,500 You can go to offensive computing, 133 00:06:48,120 --> 00:06:49,280 and you can grab any number of samples. 134 00:06:50,180 --> 00:06:51,680 And more important than that 135 00:06:51,680 --> 00:06:54,260 probably is scripting debugger. 136 00:06:54,540 --> 00:06:57,800 We're going to talk about pretty much Immunity Debugger, 137 00:06:57,820 --> 00:06:59,340 which has Python built into it. 138 00:06:59,580 --> 00:07:02,340 But you can do other things like OliDebug with OliScript. 139 00:07:04,700 --> 00:07:09,900 IDA has IDC as well as plug-ins for plug-in. 140 00:07:10,800 --> 00:07:12,560 And it would be really helpful 141 00:07:12,560 --> 00:07:14,480 if you understood the concept of reverse engineering. 142 00:07:14,940 --> 00:07:16,700 You need to understand how to unpack things, 143 00:07:16,700 --> 00:07:17,500 set breakpoints, 144 00:07:17,700 --> 00:07:20,880 and just generally flow through a piece of code 145 00:07:20,880 --> 00:07:21,620 that you're reversing. 146 00:07:22,440 --> 00:07:24,800 Optionally, I think these things kind of come in handy, 147 00:07:25,060 --> 00:07:27,480 some sort of disassembler to kind of IDA 148 00:07:27,480 --> 00:07:29,020 being the obvious choice. 149 00:07:29,360 --> 00:07:31,300 And unless you really enjoy infecting yourself 150 00:07:31,300 --> 00:07:32,200 on a routine basis, 151 00:07:32,500 --> 00:07:34,480 we recommend some sort of virtual environment. 152 00:07:35,240 --> 00:07:36,880 So at this point, I'm going to hand it over to Mike, 153 00:07:36,960 --> 00:07:39,160 who's going to go through several demos 154 00:07:39,160 --> 00:07:40,520 using real malware. 155 00:07:40,940 --> 00:07:41,580 Thanks. Good job. 156 00:07:42,620 --> 00:07:45,080 I was just kidding about liking Greg, by the way. 157 00:07:45,080 --> 00:07:45,880 Greg's awesome. 158 00:07:47,980 --> 00:07:49,580 Okay, so I'm going to skip this slide 159 00:07:49,580 --> 00:07:50,220 because it's a little boring, 160 00:07:50,300 --> 00:07:53,000 and we're going to go into the first disassembly. 161 00:07:53,060 --> 00:07:55,220 So this is a copy of the Silent Banker Trojan. 162 00:07:56,380 --> 00:07:58,420 And, you know, imagine you open up this binary 163 00:07:58,420 --> 00:07:59,720 and go to the strings pane, 164 00:07:59,880 --> 00:08:01,480 and you see a bunch of stuff that you can't read. 165 00:08:03,020 --> 00:08:04,460 So you're going to go to it, 166 00:08:05,360 --> 00:08:06,940 hop over to the first cross-reference, 167 00:08:07,020 --> 00:08:08,620 and find out where that string is used in the binary. 168 00:08:09,880 --> 00:08:12,360 Right now, we can see through this little graph pane 169 00:08:12,360 --> 00:08:14,800 that the function is more or less pretty linear, 170 00:08:15,080 --> 00:08:15,900 which goes from the top to the bottom. 171 00:08:16,000 --> 00:08:18,860 Doesn't do a whole lot except for several repeating actions, 172 00:08:19,060 --> 00:08:21,180 the first of which moves a... 173 00:08:21,180 --> 00:08:23,200 I'm going to start using this one for an example. 174 00:08:24,160 --> 00:08:27,140 It moves the address of this encoded string 175 00:08:27,140 --> 00:08:28,740 into the EAX register, 176 00:08:29,300 --> 00:08:31,000 and then it pushes EAX twice 177 00:08:31,480 --> 00:08:34,000 before calling the same function over and over again. 178 00:08:34,640 --> 00:08:37,280 So before even looking into this function, 179 00:08:37,600 --> 00:08:38,940 we can pretty much determine 180 00:08:38,940 --> 00:08:40,480 that this is probably the decoding function. 181 00:08:40,880 --> 00:08:42,740 And we also know that it takes two arguments, 182 00:08:42,960 --> 00:08:44,700 a pointer to an input buffer 183 00:08:45,080 --> 00:08:45,860 and a pointer to an output buffer, 184 00:08:46,440 --> 00:08:48,760 which indicates that SilentBanker, in this case, 185 00:08:48,840 --> 00:08:51,360 is going to decode the string in place. 186 00:08:51,560 --> 00:08:52,560 It's not going to move it to the heap 187 00:08:52,560 --> 00:08:53,480 or do anything like that first. 188 00:08:54,800 --> 00:08:57,040 So if we take a look inside this function, 189 00:08:58,400 --> 00:09:00,400 it begins with a loop right here, 190 00:09:01,140 --> 00:09:02,960 and inside the loop, it calls a function, 191 00:09:03,960 --> 00:09:07,980 which looks like it's got maybe some B64 derivative 192 00:09:07,980 --> 00:09:09,300 with a special alphabet, 193 00:09:10,140 --> 00:09:12,320 and it calls a few other sub-functions, 194 00:09:12,320 --> 00:09:14,500 and there's a bunch of stuff down here. 195 00:09:14,500 --> 00:09:17,020 Do we need to manually go through 196 00:09:17,020 --> 00:09:18,160 each of these instructions, 197 00:09:18,880 --> 00:09:20,620 reverse them into C, reverse them into Python, 198 00:09:20,780 --> 00:09:22,860 in order to decrypt the same string that it's doing? 199 00:09:23,280 --> 00:09:24,540 No, we don't need to do that. 200 00:09:25,200 --> 00:09:28,720 So our technique is going to be using 201 00:09:28,720 --> 00:09:30,740 this small Python script right here. 202 00:09:30,840 --> 00:09:31,580 I hope you guys can see that. 203 00:09:31,640 --> 00:09:32,980 If not, it's on the CD. 204 00:09:34,200 --> 00:09:35,720 We're going to hard-code the address 205 00:09:35,720 --> 00:09:37,100 of that decoding function that we saw. 206 00:09:38,040 --> 00:09:39,080 We're going to loop through 207 00:09:39,080 --> 00:09:41,620 and get each cross-reference to that function. 208 00:09:42,220 --> 00:09:43,660 And for each of the cross-references, 209 00:09:44,500 --> 00:09:44,880 we're going to move the symbol backwards 210 00:09:44,880 --> 00:09:47,640 until we meet that move-eax, offset, 211 00:09:48,340 --> 00:09:49,600 and then the encoded string. 212 00:09:49,740 --> 00:09:51,400 So we're essentially finding that move-eax instruction 213 00:09:51,400 --> 00:09:53,420 so that we know the address 214 00:09:53,420 --> 00:09:54,660 of the encoded string in memory. 215 00:09:55,280 --> 00:09:57,240 At that point, we're going to read the encoded address, 216 00:09:57,860 --> 00:09:59,520 read the string at the encoded address, 217 00:10:00,340 --> 00:10:02,780 so that when we spit out a table of these results, 218 00:10:02,840 --> 00:10:04,740 we have the encoded strings here 219 00:10:04,740 --> 00:10:06,400 and then the decoded strings on the right. 220 00:10:07,360 --> 00:10:08,900 And at that point, we're just going to 221 00:10:08,900 --> 00:10:10,260 jump over the encoding function, 222 00:10:12,260 --> 00:10:13,820 which is the equivalent 223 00:10:14,500 --> 00:10:16,580 of F8 in Immunity Debugger or AliDebug. 224 00:10:17,540 --> 00:10:18,880 So once again, we're just playing 225 00:10:18,880 --> 00:10:20,740 the Trojan's own internal function, 226 00:10:21,240 --> 00:10:22,540 using it to decrypt this information, 227 00:10:23,300 --> 00:10:24,340 extracting the results from it, 228 00:10:24,400 --> 00:10:26,100 so that we have a pretty table like this. 229 00:10:27,000 --> 00:10:28,540 So I'm going to do a quick demo of how this is done. 230 00:10:32,860 --> 00:10:33,580 Can you guys see that? 231 00:10:33,780 --> 00:10:34,880 Yeah, should be able to see that all right. 232 00:10:36,660 --> 00:10:37,560 Let's do this. 233 00:10:38,940 --> 00:10:39,260 Okay. 234 00:10:41,320 --> 00:10:43,160 So we're going to just start by moving 235 00:10:43,160 --> 00:10:45,820 the SilentBanker DLL into Immunity Debugger. 236 00:10:46,660 --> 00:10:50,220 We're going to play it until the debugger's DLL loader 237 00:10:50,220 --> 00:10:53,300 takes us to DLL main of the SilentBanker Trojan. 238 00:10:54,580 --> 00:10:55,720 And then immediately, 239 00:10:55,920 --> 00:10:58,480 we're going to run SilentBanker underscore strings 240 00:10:58,480 --> 00:11:00,080 at the command down there. 241 00:11:00,500 --> 00:11:02,120 So on disk, there's a file called 242 00:11:02,120 --> 00:11:03,800 SilentBanker underscore strings dot py, 243 00:11:04,100 --> 00:11:06,200 which contains the code that we just showed you 244 00:11:06,200 --> 00:11:06,900 on the last slide. 245 00:11:08,080 --> 00:11:11,180 As you can see there, the table in the middle 246 00:11:11,180 --> 00:11:13,080 is printing out a list of the encoded strings, 247 00:11:13,160 --> 00:11:15,040 and then it's printing out 248 00:11:15,040 --> 00:11:16,560 the corresponding decoded string. 249 00:11:17,000 --> 00:11:19,680 So at the beginning, these strings aren't that interesting. 250 00:11:19,840 --> 00:11:20,680 They're just file extensions, 251 00:11:20,920 --> 00:11:22,160 but that's because we're going in order. 252 00:11:22,580 --> 00:11:25,120 So as we move on, as you can see down 253 00:11:25,120 --> 00:11:26,500 in the bottom right-hand column, 254 00:11:27,200 --> 00:11:30,200 we're decrypting in place these strings, 255 00:11:30,300 --> 00:11:32,360 which now become the HTTP headers. 256 00:11:32,560 --> 00:11:34,000 So as you can see, like, the content type. 257 00:11:36,960 --> 00:11:39,480 And here's a quick screenshot of what you might see 258 00:11:39,480 --> 00:11:40,960 down near the end of the strings list, 259 00:11:41,140 --> 00:11:43,060 showing you the exact text 260 00:11:43,160 --> 00:11:45,780 that the Trojan uses that might help determine 261 00:11:45,780 --> 00:11:47,200 what the Trojan's functionality is. 262 00:11:47,380 --> 00:11:48,660 So in this case, we can probably determine 263 00:11:48,660 --> 00:11:51,020 that it's some type of HTML injector, 264 00:11:51,080 --> 00:11:53,060 steals passwords, steals some type 265 00:11:53,060 --> 00:11:54,180 of account information from you. 266 00:11:55,880 --> 00:11:57,980 So the interesting thing about this method, 267 00:11:58,480 --> 00:11:59,940 before we get to the Q&A session 268 00:11:59,940 --> 00:12:01,840 and somebody runs up and says, 269 00:12:01,960 --> 00:12:03,760 why the hell don't you just let this Trojan run 270 00:12:03,760 --> 00:12:05,940 and then dump it out of memory with Lord PE or something 271 00:12:05,940 --> 00:12:07,200 and then run strings on that binary? 272 00:12:07,940 --> 00:12:09,500 There's a really good reason why we don't do that. 273 00:12:10,140 --> 00:12:11,180 Actually, there's two good reasons. 274 00:12:11,860 --> 00:12:13,060 The first one is that, 275 00:12:13,480 --> 00:12:15,460 imagine we've got conditionals in the Trojan 276 00:12:15,460 --> 00:12:18,900 that only decode strings if a particular trigger is occurred. 277 00:12:19,580 --> 00:12:22,520 So, for example, Trojan gets a packet on port 80, 278 00:12:22,660 --> 00:12:23,440 decodes string A. 279 00:12:23,840 --> 00:12:26,820 Trojan gets a packet on port 82, decodes string B. 280 00:12:27,480 --> 00:12:29,020 But we don't really have the time to go through 281 00:12:29,020 --> 00:12:30,200 and find out what all those triggers are. 282 00:12:31,300 --> 00:12:33,220 And if we don't find out what all those triggers are, 283 00:12:33,340 --> 00:12:34,620 then we don't decode A and B. 284 00:12:35,360 --> 00:12:37,620 So the way that we're doing this is we're finding 285 00:12:37,620 --> 00:12:39,640 all the cross-references to the decoding function, 286 00:12:39,760 --> 00:12:40,620 and we're going back. 287 00:12:41,180 --> 00:12:43,400 So there's no way that we're going to miss anything. 288 00:12:43,600 --> 00:12:46,480 We don't even have to let the Trojan run in its native environment. 289 00:12:46,700 --> 00:12:48,980 This is an example of what Greg was talking about, being active. 290 00:12:49,240 --> 00:12:51,240 So we're not letting the Trojan run from start to finish. 291 00:12:51,280 --> 00:12:54,680 We're making it run through each iteration 292 00:12:55,040 --> 00:12:56,580 of the call to the encoding function. 293 00:12:57,940 --> 00:13:01,080 So the other example that you might not get 294 00:13:01,080 --> 00:13:04,000 a comprehensive list of strings by just dumping it once it's running 295 00:13:04,820 --> 00:13:07,800 is if the Trojan does something like 296 00:13:07,800 --> 00:13:10,300 moving the encoded string to the heap first, 297 00:13:11,240 --> 00:13:13,820 decoding it there, using it, and then freeing it. 298 00:13:14,700 --> 00:13:16,520 In that case, if we dump it while it's running, 299 00:13:16,700 --> 00:13:17,960 we'll probably only get a few strings 300 00:13:18,540 --> 00:13:21,080 because they're being cleared every time they're being used. 301 00:13:21,240 --> 00:13:23,180 Whereas this case, we get them all no matter what. 302 00:13:31,540 --> 00:13:33,980 So the next example is also with SilentBanker. 303 00:13:35,100 --> 00:13:38,440 SilentBanker uses what's known as runtime dynamic linking. 304 00:13:39,920 --> 00:13:41,160 If you've ever analyzed memory, 305 00:13:41,180 --> 00:13:43,980 one of the first and easiest things to do 306 00:13:43,980 --> 00:13:45,760 to determine what the malware's capabilities are 307 00:13:46,360 --> 00:13:48,260 is by just looking at the import address table. 308 00:13:48,940 --> 00:13:52,360 So if it imports a URL download to file, 309 00:13:52,520 --> 00:13:53,600 we can pretty much assume 310 00:13:54,260 --> 00:13:56,140 that it's going to download some file off the Internet. 311 00:13:56,560 --> 00:13:58,080 But if we don't have that capability, 312 00:13:58,360 --> 00:14:00,360 it's much harder to determine what the Trojan does 313 00:14:01,420 --> 00:14:03,020 in more than 20 seconds. 314 00:14:04,400 --> 00:14:07,180 So what malware will do is use runtime dynamic linking, 315 00:14:07,340 --> 00:14:09,860 which consists of just calling load library on the DLL, 316 00:14:09,860 --> 00:14:11,820 and then calling git proc address 317 00:14:11,820 --> 00:14:15,280 to find out the function's address of URL download to file. 318 00:14:15,580 --> 00:14:18,040 But the problem with that for malware authors 319 00:14:18,040 --> 00:14:20,120 is that the URL download to file string 320 00:14:20,120 --> 00:14:21,700 is still going to be compiled in the binary. 321 00:14:21,840 --> 00:14:23,540 And if I run strings on it, then I'm still going to find out. 322 00:14:23,700 --> 00:14:25,580 So just as easy as looking at the import address table. 323 00:14:26,640 --> 00:14:28,960 So what SilentBanker does is it uses a hash-based 324 00:14:28,960 --> 00:14:30,300 import address table resolver, 325 00:14:30,500 --> 00:14:32,140 similar to what you might see in shellcode. 326 00:14:33,780 --> 00:14:36,740 And what that presents is a little bit more difficult scenario for us. 327 00:14:37,820 --> 00:14:39,660 Here is an example of... 328 00:14:39,860 --> 00:14:43,760 the import address resolving function. 329 00:14:45,680 --> 00:14:47,760 I've renamed it git proc address from hash. 330 00:14:48,200 --> 00:14:50,320 And as you can see, this function takes three arguments, 331 00:14:50,880 --> 00:14:53,460 the third of which is a 32-bit hash. 332 00:14:53,640 --> 00:14:57,220 It corresponds to a function named such as URL download to file. 333 00:14:58,720 --> 00:15:00,440 So that gets sent as an argument 334 00:15:00,440 --> 00:15:02,320 to this git proc address from hash function, 335 00:15:04,100 --> 00:15:05,240 which is going to go in here. 336 00:15:06,020 --> 00:15:08,300 It's going to begin iteration of this loop, 337 00:15:08,300 --> 00:15:11,540 which processes each export from the loaded DLL. 338 00:15:12,620 --> 00:15:14,120 And for each exported function, 339 00:15:14,880 --> 00:15:17,160 it's going to compute a hash using the same algorithm 340 00:15:17,160 --> 00:15:19,600 as that original hash was computed with. 341 00:15:20,280 --> 00:15:21,620 And then it's going to make a comparison. 342 00:15:21,780 --> 00:15:26,440 Is the hash of that function equal to what I just got passed as an argument? 343 00:15:26,980 --> 00:15:29,520 If it is, then I found the function that I'm trying to look up, 344 00:15:30,000 --> 00:15:31,380 and I'm going to save the address. 345 00:15:33,140 --> 00:15:36,220 EAX is being moved into ESI plus 18 hex right here. 346 00:15:37,120 --> 00:15:37,960 So at this point, 347 00:15:37,960 --> 00:15:41,760 we can determine that ESI points to the base address of the call table in memory. 348 00:15:43,140 --> 00:15:45,420 And what we want to do is, 349 00:15:45,540 --> 00:15:47,820 if we follow ESI up to the beginning of the function 350 00:15:47,820 --> 00:15:49,060 and try to find out where that came from, 351 00:15:50,340 --> 00:15:51,560 ESI comes from arg 0. 352 00:15:52,860 --> 00:15:55,840 So the base address of the call table in memory 353 00:15:55,840 --> 00:15:58,660 is sent as the first argument to fx table resolver. 354 00:15:59,820 --> 00:16:01,100 So to script around this, 355 00:16:02,140 --> 00:16:06,620 we want to set a breakpoint at the beginning of fx table resolver. 356 00:16:06,620 --> 00:16:09,520 We want to read arg 0 from the stack, 357 00:16:09,640 --> 00:16:10,920 find out what the address in memory is. 358 00:16:11,680 --> 00:16:13,600 We're going to set a breakpoint at the end of this function 359 00:16:14,120 --> 00:16:15,520 and just play all the way through. 360 00:16:16,160 --> 00:16:19,480 We don't care about any of these individual instructions 361 00:16:19,480 --> 00:16:21,740 or any of these individual instructions. 362 00:16:25,180 --> 00:16:29,560 And the ability to do this is based on these, what, 363 00:16:29,660 --> 00:16:31,360 five, six lines of Python code, 364 00:16:31,480 --> 00:16:34,340 which includes the table print statement. 365 00:16:34,780 --> 00:16:35,940 So it's pretty easy. 366 00:16:36,620 --> 00:16:41,500 And what we've done now is we've got a way to, 367 00:16:41,620 --> 00:16:44,840 after the silent banker trojan resolves 368 00:16:44,840 --> 00:16:45,860 all of these addresses itself, 369 00:16:46,500 --> 00:16:49,200 to reverse that and turn it back into 370 00:16:49,200 --> 00:16:50,680 something that looks like this. 371 00:16:52,340 --> 00:16:55,240 So instead of reading something like 372 00:16:55,240 --> 00:16:57,160 call dword pointer eax plus 20 373 00:16:57,720 --> 00:16:59,140 in the binary after this, 374 00:16:59,260 --> 00:17:01,640 you're going to be able to read eax plus 375 00:17:01,640 --> 00:17:03,100 git private profile int, 376 00:17:03,220 --> 00:17:05,420 which makes the IDB a whole lot more readable. 377 00:17:07,040 --> 00:17:09,860 So this code can be reused no matter 378 00:17:10,920 --> 00:17:12,240 what trojan you're dealing with. 379 00:17:12,380 --> 00:17:14,300 It's not limited to silent banker. 380 00:17:14,460 --> 00:17:16,900 It's just any trojan that uses runtime dynamic linking 381 00:17:16,900 --> 00:17:20,400 or hash-based import address tables like this. 382 00:17:22,340 --> 00:17:23,800 And this is a really quick demo. 383 00:17:24,000 --> 00:17:26,200 We're going to start by moving the silent banker DLL 384 00:17:26,200 --> 00:17:27,740 into the debugger just like we did last time. 385 00:17:30,780 --> 00:17:32,520 We're going to hit play until we get to DLL main. 386 00:17:34,200 --> 00:17:35,520 And then right here, 387 00:17:36,160 --> 00:17:37,880 you can see that execution is paused 388 00:17:38,900 --> 00:17:41,860 at the table, the function that goes through 389 00:17:41,860 --> 00:17:44,040 and resolves all of those hash-based imports. 390 00:17:45,180 --> 00:17:46,920 So we're simply going to F8 over that 391 00:17:47,740 --> 00:17:49,020 until we hit the next instruction. 392 00:17:49,800 --> 00:17:51,320 At that point, we're going to run that 393 00:17:51,320 --> 00:17:53,800 API underscore resolution script, 394 00:17:53,960 --> 00:17:55,800 which contains those six lines of code 395 00:17:55,800 --> 00:17:56,640 that you saw on the last slide. 396 00:17:57,600 --> 00:17:59,360 And immediately, it's going to spit out 397 00:17:59,360 --> 00:18:00,540 these results right here. 398 00:18:01,360 --> 00:18:02,500 So the next step is simply going to 399 00:18:02,520 --> 00:18:04,540 copy and paste this table. 400 00:18:04,740 --> 00:18:06,580 You can see it's got the offset on the left-hand side. 401 00:18:07,460 --> 00:18:09,300 And we'll just patch the IDB with that 402 00:18:09,300 --> 00:18:13,060 using IDA Python or you can use IDC or whatever. 403 00:18:13,240 --> 00:18:15,160 You can even do it manually if the list is small. 404 00:18:16,400 --> 00:18:18,740 So just a really quick five-minute way 405 00:18:18,740 --> 00:18:21,040 to patch up your IDB and make it a whole lot more readable. 406 00:18:28,260 --> 00:18:29,160 So on to the next one. 407 00:18:31,320 --> 00:18:32,600 The next one is Kraken. 408 00:18:32,800 --> 00:18:33,960 So Kraken is a spam bot. 409 00:18:34,100 --> 00:18:34,960 You've probably heard of it. 410 00:18:35,540 --> 00:18:40,040 The difficulty with Kraken is that if you run a network, 411 00:18:40,120 --> 00:18:42,120 maybe an MSS solution, maybe you've got a lot of customers 412 00:18:42,120 --> 00:18:44,440 that are worried about getting infected with this, 413 00:18:44,520 --> 00:18:47,200 they want to block in their firewall 414 00:18:47,200 --> 00:18:51,100 the hosts that Kraken will try to connect to 415 00:18:51,100 --> 00:18:51,980 for its command and control. 416 00:18:52,480 --> 00:18:53,980 So how do you preemptively know 417 00:18:54,900 --> 00:18:57,220 what hosts that a Trojan might connect to? 418 00:18:57,220 --> 00:19:00,400 If it's not hard-coded as an IP address in the binary, 419 00:19:00,620 --> 00:19:03,120 if it's not hard-coded as a host name in the binary, 420 00:19:03,580 --> 00:19:05,880 and if it's not encoded in any form in the binary. 421 00:19:06,720 --> 00:19:09,220 In this case, Kraken has an algorithm 422 00:19:09,220 --> 00:19:11,400 that generates host names dynamically 423 00:19:11,900 --> 00:19:13,080 based on this formula. 424 00:19:14,580 --> 00:19:15,880 I've written the C code right here 425 00:19:15,880 --> 00:19:18,620 that shows you essentially what it does. 426 00:19:18,800 --> 00:19:20,980 There is a loop that goes through 427 00:19:21,600 --> 00:19:24,760 and passes this getDomain function to arguments, 428 00:19:25,300 --> 00:19:27,160 the first of which is a pointer to the output 429 00:19:27,220 --> 00:19:28,700 so that's where the host name gets written. 430 00:19:29,240 --> 00:19:32,600 The second one is a simple integer 431 00:19:32,600 --> 00:19:35,660 that iterates from zero to however many number of hosts 432 00:19:35,660 --> 00:19:36,480 that you want to generate. 433 00:19:37,960 --> 00:19:40,620 So that's how the Kraken host name generation works. 434 00:19:40,880 --> 00:19:44,460 Now, for us, do we really want to let this Trojan run 435 00:19:44,460 --> 00:19:46,100 for potentially hours, potentially days, 436 00:19:46,200 --> 00:19:48,980 before we know what host names it's going to connect to? 437 00:19:49,100 --> 00:19:51,580 I want to know in an instant what host names 438 00:19:51,580 --> 00:19:54,040 this is going to connect to so that I can tell my customers, 439 00:19:54,100 --> 00:19:56,740 I can tell people to make sure you block so-and-so host. 440 00:19:59,260 --> 00:20:02,440 So let's quickly go to the Kraken example. 441 00:20:03,520 --> 00:20:05,060 And the way that we found this function 442 00:20:05,660 --> 00:20:09,940 is by getting a cross-reference to the getHostByName import, 443 00:20:10,560 --> 00:20:11,360 which is right here. 444 00:20:12,980 --> 00:20:15,400 So as you can see, the first argument to that 445 00:20:15,400 --> 00:20:17,980 is lphostname, which contains, obviously, 446 00:20:18,140 --> 00:20:19,820 you know, like moo.com or whatever. 447 00:20:20,820 --> 00:20:22,100 And we want to track this back 448 00:20:22,100 --> 00:20:23,900 and try to find out where that host name came from. 449 00:20:25,460 --> 00:20:26,520 So if you go up here, 450 00:20:27,280 --> 00:20:29,820 it is derived from a store copy call. 451 00:20:29,920 --> 00:20:30,820 It's used as the destination 452 00:20:30,820 --> 00:20:33,740 where the EAX register contains the source. 453 00:20:35,180 --> 00:20:36,740 And that source is filled in 454 00:20:36,740 --> 00:20:39,740 after the getRandomHostName function is called. 455 00:20:39,880 --> 00:20:41,840 But obviously, I've named that, so it's pretty easy to see. 456 00:20:42,200 --> 00:20:44,540 But before I named it, how am I supposed to determine 457 00:20:45,200 --> 00:20:46,940 to name this getRandomHostName? 458 00:20:47,020 --> 00:20:49,660 Well, it's because that backtracking that I just did 459 00:20:49,660 --> 00:20:52,380 and finding out that the EAX register at this point 460 00:20:52,380 --> 00:20:53,520 contains the host name. 461 00:20:54,100 --> 00:20:57,100 So if you want to take a quick look at the code inside this getRandomHostName, 462 00:20:57,220 --> 00:20:57,300 you can. 463 00:21:01,160 --> 00:21:01,940 There's a lot of math. 464 00:21:02,300 --> 00:21:04,440 There's a few conditionals, a lot of constants, 465 00:21:05,460 --> 00:21:07,960 a lot of multiplication, a lot of rotates, a lot of pushes. 466 00:21:09,100 --> 00:21:12,180 Do we need to write a formula in C or Python 467 00:21:12,180 --> 00:21:15,820 to mimic this function and spit out a list of host names? 468 00:21:16,560 --> 00:21:17,620 That might take a little bit, 469 00:21:17,700 --> 00:21:19,300 even if you're a really good reverse engineer. 470 00:21:20,760 --> 00:21:23,360 So what we did was simply looked at the input to this function. 471 00:21:23,900 --> 00:21:25,560 It takes two arguments, like I said before. 472 00:21:25,560 --> 00:21:28,200 One is the pointer to the output buffer. 473 00:21:28,680 --> 00:21:31,320 The other is a number, EAX plus four, 474 00:21:31,420 --> 00:21:33,280 which gets incremented through each iteration of the loop. 475 00:21:34,140 --> 00:21:38,660 So all we need to do is script around that function. 476 00:21:38,800 --> 00:21:40,180 We're going to replay it a thousand times. 477 00:21:41,000 --> 00:21:43,600 Each time, we're going to pass it a new number 478 00:21:43,600 --> 00:21:45,440 for that second argument, one, two, three, four, five, 479 00:21:45,520 --> 00:21:46,280 and just keep going on. 480 00:21:47,360 --> 00:21:49,980 And then every time it's finished executing, 481 00:21:50,160 --> 00:21:52,660 we're just going to read the returned host name. 482 00:21:55,020 --> 00:21:55,540 So we're going to do that. 483 00:21:55,560 --> 00:21:56,420 We're going to do a quick demo of that. 484 00:22:03,980 --> 00:22:07,360 We're going to wait until the Trojan is executed in memory. 485 00:22:07,520 --> 00:22:08,280 It starts to run. 486 00:22:08,580 --> 00:22:10,080 We're going to attach to it with the debugger. 487 00:22:12,300 --> 00:22:13,280 Type crack in host names. 488 00:22:14,040 --> 00:22:16,280 And as you can see right here, it sets several breakpoints. 489 00:22:17,000 --> 00:22:18,700 One of them is at the very beginning of the function. 490 00:22:19,420 --> 00:22:21,660 It's going to reset EIP to point to that location. 491 00:22:22,960 --> 00:22:25,220 And it's also got a breakpoint set at the end of the function, 492 00:22:25,560 --> 00:22:26,300 which is right here, that return. 493 00:22:28,120 --> 00:22:29,220 And then it's going to hop back up. 494 00:22:29,380 --> 00:22:30,300 It's going to do the same thing. 495 00:22:30,780 --> 00:22:31,360 Do it again. 496 00:22:31,580 --> 00:22:32,820 And through each iteration of that, 497 00:22:32,960 --> 00:22:35,680 it's going to output the host name that it generates into our table. 498 00:22:38,580 --> 00:22:41,200 And of course, just let that run for a little bit, 499 00:22:41,240 --> 00:22:42,540 about a thousand times or so. 500 00:22:42,800 --> 00:22:44,620 Go get lunch or something. 501 00:22:44,780 --> 00:22:47,360 You come back, and you've got a list of all the host names 502 00:22:47,360 --> 00:22:48,520 that Kraken is going to connect to 503 00:22:48,520 --> 00:22:49,740 with its command and control protocol. 504 00:22:53,120 --> 00:22:53,920 Thank you. 505 00:23:02,260 --> 00:23:04,440 So there's also something interesting that we found 506 00:23:04,440 --> 00:23:06,840 during the research with Kraken, 507 00:23:07,400 --> 00:23:09,460 that there's a vulnerability, 508 00:23:09,920 --> 00:23:11,280 or not necessarily a vulnerability, 509 00:23:11,420 --> 00:23:13,080 but there's kind of a weakness in its cryptography model. 510 00:23:13,520 --> 00:23:16,200 So if you're here, you most likely know that 511 00:23:16,200 --> 00:23:18,420 when you're encrypting something and sending it over the network, 512 00:23:18,420 --> 00:23:20,380 if it's going to be secure, 513 00:23:20,540 --> 00:23:22,540 you don't put the encryption keys in the same message 514 00:23:23,020 --> 00:23:23,940 as the encrypted data. 515 00:23:25,220 --> 00:23:25,660 Okay? 516 00:23:27,440 --> 00:23:29,200 So maybe the Kraken authors didn't know that. 517 00:23:29,720 --> 00:23:30,460 I'm not sure. 518 00:23:30,680 --> 00:23:31,660 Maybe they were just lazy. 519 00:23:31,960 --> 00:23:36,760 But they actually decided to derive the encryption keys 520 00:23:36,760 --> 00:23:39,600 based on the IP address of the host machine that's infected, 521 00:23:39,860 --> 00:23:41,820 the CPU details, and the hard drive serial number. 522 00:23:42,220 --> 00:23:45,140 So it's pretty unique for each machine that it infects. 523 00:23:45,280 --> 00:23:47,520 But does that make it harder for us 524 00:23:47,520 --> 00:23:50,720 to go through an arbitrary network's packet capture 525 00:23:50,720 --> 00:23:51,620 and decrypt the information? 526 00:23:52,220 --> 00:23:54,600 No, because of the weakness. 527 00:23:54,820 --> 00:23:57,340 They give us all the information that we would need 528 00:23:57,340 --> 00:23:58,520 to decrypt the information. 529 00:24:01,580 --> 00:24:04,180 So based on that, this is an example of something 530 00:24:04,180 --> 00:24:08,280 that you can't really use the scriptable debugger method for. 531 00:24:09,020 --> 00:24:11,120 We wanted to write a Wireshark plug-in 532 00:24:11,120 --> 00:24:13,800 so that network administrators could analyze 533 00:24:13,800 --> 00:24:16,380 their still and live network captures 534 00:24:16,380 --> 00:24:18,100 in order to find out, 535 00:24:18,140 --> 00:24:21,660 when you see this UDP447 and HTTP pulse traffic 536 00:24:21,660 --> 00:24:23,940 that Kraken generates going across the network, 537 00:24:24,820 --> 00:24:25,500 what's in it. 538 00:24:26,100 --> 00:24:29,460 And this Wireshark module that we released a few months ago 539 00:24:29,460 --> 00:24:30,620 can tell you that. 540 00:24:30,760 --> 00:24:32,460 So it parses the packet, 541 00:24:32,700 --> 00:24:34,840 and it extracts those keys that are in the header, 542 00:24:34,980 --> 00:24:37,840 and it uses those to decrypt the information. 543 00:24:38,560 --> 00:24:40,060 So we've got a little tab down here 544 00:24:40,060 --> 00:24:40,940 that shows you what it has. 545 00:24:41,060 --> 00:24:43,560 It's going to be IP addresses, the spam templates, 546 00:24:43,860 --> 00:24:45,080 anything that the Trojan needs 547 00:24:45,080 --> 00:24:47,120 to do its nefarious acts. 548 00:24:52,540 --> 00:24:54,200 I don't have a demo for that one. 549 00:25:00,720 --> 00:25:01,600 Yeah, I can show that. 550 00:25:02,520 --> 00:25:03,540 It's not actually a demo, 551 00:25:03,640 --> 00:25:05,660 but it's just a packet capture, 552 00:25:05,860 --> 00:25:07,000 a still one, 553 00:25:07,120 --> 00:25:10,740 after we've installed the Kraken module. 554 00:25:11,080 --> 00:25:14,880 So you can click on any of the packets 555 00:25:15,080 --> 00:25:15,840 that Kraken generated, 556 00:25:16,000 --> 00:25:17,500 and you can go over to the decoded payload tab. 557 00:25:18,040 --> 00:25:19,020 And as you can see here, 558 00:25:19,120 --> 00:25:20,580 it's a list of the IP addresses 559 00:25:20,580 --> 00:25:23,260 that the module is going to use 560 00:25:23,260 --> 00:25:24,920 to connect to for its command and control. 561 00:25:25,700 --> 00:25:26,840 Actually, not the command and control, 562 00:25:26,940 --> 00:25:27,900 but for, like, sending spam and stuff. 563 00:25:29,900 --> 00:25:30,680 So that's what it looks like. 564 00:25:31,600 --> 00:25:32,600 I'm going on to the next demo. 565 00:25:33,840 --> 00:25:35,340 LACMA is an information-stealing Trojan, 566 00:25:36,320 --> 00:25:38,040 and there are several components to LACMA. 567 00:25:38,160 --> 00:25:39,580 There is a client DLL 568 00:25:40,440 --> 00:25:42,400 that gets injected into windowing processes, 569 00:25:42,560 --> 00:25:45,060 like Internet Explorer or Explorer, Firefox, 570 00:25:45,080 --> 00:25:48,260 and when that gets loaded by the process, 571 00:25:48,800 --> 00:25:51,320 it hooks multiple API functions, 572 00:25:51,560 --> 00:25:53,360 such as PFX import cert store, 573 00:25:53,580 --> 00:25:54,880 HTTP send request, 574 00:25:55,220 --> 00:25:57,000 so that it can snoop on the information 575 00:25:57,000 --> 00:26:00,000 that the process sends to that API function. 576 00:26:00,440 --> 00:26:02,200 So in the case of PFX import cert store, 577 00:26:02,280 --> 00:26:02,940 it's going to be certificates. 578 00:26:03,580 --> 00:26:05,500 HTTP send request is probably going to be 579 00:26:05,500 --> 00:26:08,160 the post-payload of any logins 580 00:26:08,160 --> 00:26:09,700 that it's trying to make over the web. 581 00:26:10,660 --> 00:26:12,880 So once those API functions are triggered, 582 00:26:13,500 --> 00:26:14,920 the code that the Trojan inserts 583 00:26:15,080 --> 00:26:18,020 takes the information that it's stealing, 584 00:26:18,100 --> 00:26:20,460 and it maps a global shared memory segment 585 00:26:20,460 --> 00:26:21,920 called temp underscore exchange, 586 00:26:22,580 --> 00:26:24,060 and it writes the stolen information 587 00:26:24,060 --> 00:26:25,400 to that shared memory segment. 588 00:26:26,220 --> 00:26:28,380 And then it uses send message 589 00:26:29,540 --> 00:26:31,960 to basically alert that remote process, 590 00:26:32,100 --> 00:26:33,120 which I'm going to talk about in a second, 591 00:26:33,360 --> 00:26:36,140 that, hey, I've stolen some information. 592 00:26:36,360 --> 00:26:37,500 I put it right here for you. 593 00:26:37,600 --> 00:26:38,740 Go ahead and fetch it now. 594 00:26:39,520 --> 00:26:41,120 So over there in the other process, 595 00:26:41,800 --> 00:26:43,600 which is just a standalone executable, 596 00:26:43,600 --> 00:26:46,800 it has that actual serve window loop 597 00:26:47,500 --> 00:26:49,280 waiting for messages from the clients. 598 00:26:49,420 --> 00:26:50,820 Once it gets one, it says, 599 00:26:50,920 --> 00:26:52,200 okay, thanks for letting me know. 600 00:26:52,260 --> 00:26:53,940 I'm going to map this shared memory segment now. 601 00:26:53,980 --> 00:26:54,800 I'm going to read what you've stolen, 602 00:26:54,960 --> 00:26:56,340 and I'm going to determine if there's anything 603 00:26:56,340 --> 00:26:57,100 that I should do with it, 604 00:26:57,140 --> 00:27:00,020 such as uploading it to the stolen drop site server. 605 00:27:04,720 --> 00:27:06,960 So this is some source code that we reversed 606 00:27:06,960 --> 00:27:08,680 out of the client part, the DLL. 607 00:27:09,140 --> 00:27:11,000 This is the code that gets executed 608 00:27:11,900 --> 00:27:13,320 after the trampoline hook, 609 00:27:13,600 --> 00:27:14,020 is triggered. 610 00:27:14,340 --> 00:27:16,000 So traffic is redirected to... 611 00:27:16,000 --> 00:27:19,440 The processor is redirected to this function 612 00:27:19,440 --> 00:27:21,380 instead of executing the legitimate function. 613 00:27:21,800 --> 00:27:22,520 And as you can see, 614 00:27:22,560 --> 00:27:23,840 like a normal trampoline function does, 615 00:27:24,060 --> 00:27:25,880 it simply calls HTTP SYN request, 616 00:27:26,020 --> 00:27:26,920 the legitimate version first, 617 00:27:28,320 --> 00:27:30,040 and then it maps that shared memory segment, 618 00:27:30,520 --> 00:27:32,520 and it copies over the information that's stolen, 619 00:27:33,080 --> 00:27:34,400 and it uses find window. 620 00:27:34,640 --> 00:27:35,640 This is actually a typo. 621 00:27:35,660 --> 00:27:36,780 It shouldn't be underscore, underscore, insert. 622 00:27:36,920 --> 00:27:37,900 It should be that actual serve thing. 623 00:27:38,780 --> 00:27:40,420 And then it calls SYN message 624 00:27:40,420 --> 00:27:43,280 to let that remote process know that it's time to act. 625 00:27:46,220 --> 00:27:50,420 So if we take a look at the client DLL right here, 626 00:27:50,500 --> 00:27:51,780 this HTTP SYN request A, 627 00:27:51,900 --> 00:27:54,480 this is the exact same thing that I just showed you in C, 628 00:27:54,640 --> 00:27:56,060 but this is the disassembly version of it. 629 00:27:57,800 --> 00:28:00,000 You can see down here where it pushes 630 00:28:00,000 --> 00:28:02,020 that global temp underscore exchange string 631 00:28:02,020 --> 00:28:02,600 onto the stack, 632 00:28:02,700 --> 00:28:04,740 and then it calls map view of file and write, 633 00:28:04,840 --> 00:28:06,280 which is just an internal function that I named 634 00:28:06,280 --> 00:28:08,140 based on the code that happens inside of it. 635 00:28:09,220 --> 00:28:10,740 So we're trying to determine... 636 00:28:12,220 --> 00:28:13,520 During execution of... 637 00:28:13,600 --> 00:28:15,460 Internet Explorer, if somebody logs in, 638 00:28:15,620 --> 00:28:17,600 what exactly is this stealing? 639 00:28:17,880 --> 00:28:18,880 And I want to know in real time. 640 00:28:18,960 --> 00:28:19,420 I want to see it. 641 00:28:19,480 --> 00:28:21,800 I want to kind of snoop 642 00:28:21,800 --> 00:28:24,980 on what data it writes to the shared memory segment 643 00:28:24,980 --> 00:28:26,340 so that I can extract all the information, 644 00:28:26,480 --> 00:28:27,180 and I'll have a better idea 645 00:28:27,180 --> 00:28:28,720 of what this Trojan is capable of doing. 646 00:28:30,820 --> 00:28:32,820 So can I hook map view of file 647 00:28:32,820 --> 00:28:35,800 in order to extract the information that I want? 648 00:28:36,640 --> 00:28:38,580 It seems like a likely function 649 00:28:38,580 --> 00:28:39,860 that we would want to hook, 650 00:28:39,920 --> 00:28:40,720 but in this case, it's not, 651 00:28:40,780 --> 00:28:43,380 because at the time you hook map view of file, 652 00:28:43,380 --> 00:28:45,420 you haven't actually transferred over the stolen information. 653 00:28:45,860 --> 00:28:47,300 So it calls map view of file first, 654 00:28:47,480 --> 00:28:49,500 gets the address of that shared memory segment, 655 00:28:49,760 --> 00:28:52,940 and then it calls these two internal memcopy-like functions 656 00:28:52,940 --> 00:28:53,780 to transfer the data. 657 00:28:54,860 --> 00:28:56,120 Do we want to hook those functions? 658 00:28:56,360 --> 00:28:57,040 Probably not, 659 00:28:57,120 --> 00:28:58,780 because the address is going to be different in memory 660 00:28:58,780 --> 00:29:00,780 for each version of LACMA that gets released, 661 00:29:01,020 --> 00:29:02,980 and we don't want to have to go through 662 00:29:02,980 --> 00:29:03,800 and find it every time 663 00:29:03,800 --> 00:29:05,280 and then hard-code it into our script. 664 00:29:05,940 --> 00:29:06,860 It's a little bit more work. 665 00:29:08,160 --> 00:29:10,120 But it's very convenient that right afterward 666 00:29:10,120 --> 00:29:11,300 it calls flush view of file, 667 00:29:11,400 --> 00:29:12,600 which doesn't actually delete the contents. 668 00:29:13,380 --> 00:29:15,900 It's like flushing up contents of a file to disk. 669 00:29:16,900 --> 00:29:18,160 And the first parameter 670 00:29:18,160 --> 00:29:21,320 is the base address of the shared memory segment. 671 00:29:21,520 --> 00:29:22,860 So that is exactly what we want. 672 00:29:28,800 --> 00:29:31,020 So we'll hook that flush view of file function. 673 00:29:31,300 --> 00:29:35,360 We'll get access to the address of the shared memory segment, 674 00:29:35,560 --> 00:29:36,480 and then we can parse it 675 00:29:36,480 --> 00:29:37,920 and find out what information is stolen. 676 00:29:38,660 --> 00:29:39,680 So we're going to go to a demo. 677 00:29:40,300 --> 00:29:42,600 And on this workstation, I've installed LACMA. 678 00:29:44,220 --> 00:29:45,800 There is another component to LACMA 679 00:29:45,800 --> 00:29:46,760 that I didn't discuss there. 680 00:29:46,900 --> 00:29:48,540 It actually comes with a kernel rootkit also, 681 00:29:48,640 --> 00:29:52,440 which hides the processes and files on disk. 682 00:29:53,460 --> 00:29:55,480 So if that rootkit is enabled, 683 00:29:55,660 --> 00:29:59,020 I can't open the process that I want to debug 684 00:29:59,020 --> 00:30:00,060 in the debugger, 685 00:30:00,080 --> 00:30:01,140 because the debugger can't find it. 686 00:30:01,620 --> 00:30:03,260 But it just so happens that LACMA 687 00:30:03,260 --> 00:30:07,080 comes with that kernel rootkit. 688 00:30:07,140 --> 00:30:07,860 It's a little bit generic. 689 00:30:08,220 --> 00:30:09,380 And it's kind of funny, too, 690 00:30:09,920 --> 00:30:11,680 because the kernel-mode rootkit, 691 00:30:11,780 --> 00:30:12,860 you can actually disable it 692 00:30:12,860 --> 00:30:13,480 from user mode 693 00:30:13,480 --> 00:30:16,260 by simply sending a signal over the named pipe 694 00:30:16,260 --> 00:30:17,440 that it exposes to user mode. 695 00:30:19,800 --> 00:30:22,100 That's what you're going to see us doing right here. 696 00:30:22,220 --> 00:30:24,560 We wrote a little program called write-to-landman. 697 00:30:24,700 --> 00:30:25,700 There's the arguments. 698 00:30:26,140 --> 00:30:27,860 So if we send write-to-landman dash x, 699 00:30:27,980 --> 00:30:28,820 then it's going to deactivate 700 00:30:28,820 --> 00:30:29,700 and not hide all the items. 701 00:30:31,640 --> 00:30:32,560 So we'll do that. 702 00:30:33,520 --> 00:30:34,400 And all of a sudden, 703 00:30:34,440 --> 00:30:36,080 we're going to have a few new processes. 704 00:30:36,220 --> 00:30:37,560 See, that landman work just showed up 705 00:30:37,560 --> 00:30:39,740 and the kernel-drv.exe down there at the bottom 706 00:30:39,740 --> 00:30:40,180 just showed up. 707 00:30:41,440 --> 00:30:44,220 So we're going to open the debugger. 708 00:30:44,320 --> 00:30:48,080 We're going to attach to those processes. 709 00:30:48,420 --> 00:30:50,700 And we're going to open up an Internet Explorer window. 710 00:30:52,340 --> 00:30:54,180 Go to Gmail, just some site 711 00:30:54,180 --> 00:30:55,820 that you can type in a username and a password. 712 00:30:57,180 --> 00:30:58,360 And I'm going to let this one play. 713 00:30:58,880 --> 00:31:00,040 We're just going to type lacmaspy. 714 00:31:01,880 --> 00:31:05,320 And then we're going to go back to the Gmail window 715 00:31:05,320 --> 00:31:07,040 and enter our username and password and hit enter. 716 00:31:21,240 --> 00:31:22,040 Yeah, thanks. 717 00:31:22,700 --> 00:31:24,760 So this is an example of the passive method 718 00:31:25,900 --> 00:31:27,780 because we're simply just letting the Trojan run 719 00:31:27,780 --> 00:31:28,540 from start to finish. 720 00:31:29,340 --> 00:31:30,920 And we're essentially just monitoring. 721 00:31:31,100 --> 00:31:33,520 We're not modifying the path of execution. 722 00:31:34,020 --> 00:31:35,180 And as you just saw, 723 00:31:35,240 --> 00:31:36,900 we're able to get a real-time view 724 00:31:37,520 --> 00:31:39,440 of all the information that it steals. 725 00:31:39,440 --> 00:31:41,820 Out of the API hooks, 726 00:31:42,600 --> 00:31:44,200 which includes the post payload, 727 00:31:44,420 --> 00:31:45,940 your usernames and your passwords and everything. 728 00:31:53,700 --> 00:31:54,220 Good. 729 00:31:54,360 --> 00:31:55,200 So on to the next one. 730 00:31:56,100 --> 00:31:58,160 Torpig, another information-stealing Trojan. 731 00:31:59,060 --> 00:32:00,780 Just recently, well, not recently, 732 00:32:00,840 --> 00:32:02,800 a few, nine months maybe ago, 733 00:32:03,600 --> 00:32:04,920 incorporated the MBR rootkit. 734 00:32:06,920 --> 00:32:09,420 And the challenge to this one 735 00:32:09,440 --> 00:32:13,420 was this is the first one that I personally ran into 736 00:32:13,420 --> 00:32:17,000 that did the decryption in the kernel mode driver. 737 00:32:18,300 --> 00:32:21,400 So the immunity debugger is obviously a user mode debugger, 738 00:32:21,420 --> 00:32:24,240 which isn't going to really let you debug that kernel driver. 739 00:32:24,600 --> 00:32:26,480 So the kernel driver gets installed. 740 00:32:26,600 --> 00:32:27,140 It starts to run. 741 00:32:28,500 --> 00:32:31,680 The kernel component downloads a DLL 742 00:32:32,180 --> 00:32:35,160 and the Trojan's configuration from the web. 743 00:32:35,520 --> 00:32:37,720 You know, if you're viewing it with a packet capture, 744 00:32:37,840 --> 00:32:39,200 you're just going to see a bunch of encrypted data. 745 00:32:39,440 --> 00:32:40,880 It does the decryption in kernel memory. 746 00:32:41,840 --> 00:32:44,700 But then the stupid thing that it does 747 00:32:44,700 --> 00:32:47,920 is it makes all of that decrypted content 748 00:32:48,940 --> 00:32:51,100 available to any user mode process 749 00:32:51,780 --> 00:32:53,320 through a named pipe. 750 00:32:53,780 --> 00:32:55,160 It's bang win money. 751 00:32:57,520 --> 00:33:00,240 However, you can't just connect to that named pipe 752 00:33:00,240 --> 00:33:01,740 and do read file 753 00:33:02,420 --> 00:33:06,160 because there is an internal command and control protocol. 754 00:33:06,500 --> 00:33:07,840 So you need to send it 755 00:33:07,840 --> 00:33:10,780 the exact same sequence of bytes 756 00:33:11,500 --> 00:33:14,200 and the exact same value of bytes 757 00:33:14,820 --> 00:33:16,580 that the kernel component expects. 758 00:33:16,900 --> 00:33:18,300 You need to send it from user mode 759 00:33:18,600 --> 00:33:22,140 in order to invoke the data that you're interested in. 760 00:33:23,700 --> 00:33:25,900 So we wanted to write a script around 761 00:33:27,820 --> 00:33:29,300 the Internet Explorer process 762 00:33:31,160 --> 00:33:36,000 because the DLL that TorPig downloads decrypts 763 00:33:36,000 --> 00:33:37,680 and then it injects it into any process 764 00:33:37,840 --> 00:33:38,160 that starts. 765 00:33:38,340 --> 00:33:42,700 So we want to wait until Internet Explorer loads that DLL. 766 00:33:44,100 --> 00:33:47,280 And then we want to have a breakpoint set on create file. 767 00:33:47,520 --> 00:33:54,200 We want to wait until that DLL automatically calls create file 768 00:33:54,200 --> 00:33:55,320 for the named pipe. 769 00:33:56,200 --> 00:34:01,020 And after we detect that it's opened the transmission 770 00:34:01,640 --> 00:34:03,500 to that named pipe, 771 00:34:03,660 --> 00:34:05,980 we want to set the breakpoints for read file and write file 772 00:34:05,980 --> 00:34:07,740 so that we can inspect the exact information 773 00:34:07,840 --> 00:34:08,860 that it's sending back and forth. 774 00:34:09,580 --> 00:34:12,680 We don't want to enable read file and write file hooks 775 00:34:12,680 --> 00:34:15,540 before the create file call to bang win money 776 00:34:15,540 --> 00:34:18,680 because if you've ever monitored an Internet Explorer process 777 00:34:18,680 --> 00:34:21,480 as it's loading into memory, 778 00:34:21,600 --> 00:34:23,040 it calls create file like a million times. 779 00:34:23,200 --> 00:34:24,900 So that would be a whole lot of overhead. 780 00:34:25,120 --> 00:34:26,620 So we just want to wait until it calls create file 781 00:34:26,620 --> 00:34:27,340 and that bang win money. 782 00:34:27,420 --> 00:34:28,820 Then we're going to set the read file and write file hooks. 783 00:34:29,360 --> 00:34:31,020 And this is the Python down here to do it. 784 00:34:31,900 --> 00:34:33,380 It's equally as small. 785 00:34:35,500 --> 00:34:36,680 There's no disassembly for this one. 786 00:34:46,200 --> 00:34:49,420 So the goal of this is to extract that information 787 00:34:49,420 --> 00:34:52,800 from the kernel, which is the configuration file 788 00:34:52,800 --> 00:34:53,500 that TorPig downloads. 789 00:34:53,640 --> 00:34:57,300 It contains the list of targets that TorPig is going to try 790 00:34:57,300 --> 00:35:00,360 and steal information from, which is pretty essential 791 00:35:00,360 --> 00:35:05,060 for knowing what this Trojan is capable of doing. 792 00:35:05,060 --> 00:35:07,800 So we essentially just started the debugger. 793 00:35:07,880 --> 00:35:09,980 We began a process of Internet Explorer, 794 00:35:10,720 --> 00:35:14,300 and we're waiting for it to call create file on bang win money. 795 00:35:15,700 --> 00:35:18,420 And when it does, we're going to immediately start getting 796 00:35:19,340 --> 00:35:20,360 some results here. 797 00:35:24,880 --> 00:35:28,660 So on the left-hand column, it's saying read and write, 798 00:35:28,720 --> 00:35:32,240 which is letting you know which of the write file 799 00:35:32,240 --> 00:35:34,020 and read file hooks are being activated. 800 00:35:34,020 --> 00:35:37,140 It's telling you the size of the information that it's reading 801 00:35:37,140 --> 00:35:39,680 or writing, and it's also telling you the exact data 802 00:35:40,480 --> 00:35:41,960 that is being sent over the pipe. 803 00:35:42,680 --> 00:35:45,840 So what we did in that case, taking that information, 804 00:35:45,980 --> 00:35:50,420 was we wrote a C program that you can run on an infected machine. 805 00:35:52,480 --> 00:35:55,900 And it does exactly what the Trojan does, except for in this case, 806 00:35:55,900 --> 00:35:59,300 we're able to simply put the output on the screen. 807 00:36:06,740 --> 00:36:10,900 And so now we've got a list of all of the Trojan's targets. 808 00:36:11,740 --> 00:36:14,060 Even though the decryption occurs in kernel memory, 809 00:36:14,240 --> 00:36:18,240 even though we're not able to debug the kernel driver itself, 810 00:36:19,180 --> 00:36:22,620 but just by inspection of even what's happening in user mode, 811 00:36:22,720 --> 00:36:24,640 we're able to extract the most critical information 812 00:36:24,640 --> 00:36:26,040 that this Trojan is trying to hide. 813 00:36:27,740 --> 00:36:28,580 So that's pretty cool. 814 00:36:35,160 --> 00:36:39,720 So the last one is called TrojanX, encryption key game. 815 00:36:40,120 --> 00:36:41,980 I can't actually tell you the name of this Trojan 816 00:36:41,980 --> 00:36:43,900 because, well, for various reasons, 817 00:36:44,040 --> 00:36:45,920 none of which we can tell you. 818 00:36:49,160 --> 00:36:50,860 So this Trojan is really interesting 819 00:36:50,860 --> 00:36:52,820 because it's also an information stealer. 820 00:36:53,300 --> 00:36:54,960 And the information that it steals, 821 00:36:55,020 --> 00:36:57,700 it encrypts before posting to the drop site. 822 00:37:00,320 --> 00:37:03,380 Now, if the Trojan just generates 823 00:37:04,020 --> 00:37:05,480 a random encryption key 824 00:37:06,240 --> 00:37:08,360 and then encrypts the data with it, 825 00:37:08,440 --> 00:37:09,580 sends it to the drop site server, 826 00:37:10,120 --> 00:37:12,960 how is the attacker himself going to know 827 00:37:12,960 --> 00:37:15,440 what the encryption key is if it's generated randomly? 828 00:37:16,200 --> 00:37:17,500 He needs some way of knowing. 829 00:37:18,360 --> 00:37:20,820 And these guys aren't exactly as dumb as the other people, 830 00:37:20,940 --> 00:37:21,840 but they're pretty dumb. 831 00:37:22,760 --> 00:37:25,540 They didn't include the encryption keys 832 00:37:25,540 --> 00:37:27,960 in the same message as the encrypted data. 833 00:37:29,040 --> 00:37:31,020 What they did was they exploded, 834 00:37:31,700 --> 00:37:32,960 using arbitrary math, 835 00:37:34,020 --> 00:37:35,500 the 16-byte encryption key that it generates randomly 836 00:37:35,980 --> 00:37:37,380 into a 32-byte number, 837 00:37:37,880 --> 00:37:40,580 and it sends the 32-byte number along with the encrypted data. 838 00:37:41,220 --> 00:37:43,080 So when you recover these files on the website, 839 00:37:44,120 --> 00:37:46,740 you first need to extract the 32-byte number, 840 00:37:47,440 --> 00:37:49,500 and then you need to somehow reverse engineer that 841 00:37:49,500 --> 00:37:50,940 back to the 16-byte encryption key. 842 00:37:51,720 --> 00:37:55,200 And then you need to reverse the encryption function 843 00:37:55,200 --> 00:37:56,100 so that you can decrypt it. 844 00:37:57,720 --> 00:38:00,080 So the encryption function itself 845 00:38:00,080 --> 00:38:01,460 turned out to be pretty easy. 846 00:38:02,900 --> 00:38:06,200 And the Trojan doesn't actually have, 847 00:38:06,360 --> 00:38:08,980 in its own binary, the decryption function. 848 00:38:09,100 --> 00:38:10,740 It's different from the encryption function. 849 00:38:11,040 --> 00:38:12,860 It's not reversible. 850 00:38:14,160 --> 00:38:16,080 So we actually did need to do that by hand, 851 00:38:16,200 --> 00:38:17,380 which, like I said, wasn't too bad. 852 00:38:17,520 --> 00:38:20,580 But then we were still troubled by the fact 853 00:38:20,580 --> 00:38:22,540 that we needed to generate a 32-byte key 854 00:38:22,540 --> 00:38:23,460 from a 32-byte number. 855 00:38:24,920 --> 00:38:26,840 I'm sorry, a 16-byte key from a 32-byte number. 856 00:38:28,780 --> 00:38:31,320 So let me jump over to the disassembly real quick. 857 00:38:38,520 --> 00:38:41,120 Here's the Keegan 16 primary, as I've named it. 858 00:38:41,240 --> 00:38:42,300 This function generates, 859 00:38:42,880 --> 00:38:45,420 using their custom pseudo-random number generator, 860 00:38:45,680 --> 00:38:46,960 a 16-byte key. 861 00:38:47,900 --> 00:38:49,640 Now, there happens to be this particular vulnerability 862 00:38:49,640 --> 00:38:52,860 in the Keegan that makes that pseudo-random number 863 00:38:52,860 --> 00:38:54,000 not so random, 864 00:38:57,080 --> 00:38:59,100 which, just keep that in mind for a second. 865 00:38:59,260 --> 00:39:01,440 After that, it sends the 16-byte primary 866 00:39:01,460 --> 00:39:03,200 key, which is used for encryption, 867 00:39:03,380 --> 00:39:05,380 to the Keegan 8 secondary function, 868 00:39:06,600 --> 00:39:09,160 which outputs an 8-byte secondary key. 869 00:39:10,660 --> 00:39:12,880 And then that 8-byte secondary key 870 00:39:13,460 --> 00:39:14,620 is passed to this function, 871 00:39:15,160 --> 00:39:18,680 which generates another 8-byte key, 872 00:39:19,920 --> 00:39:21,560 which then gets sent to this function, 873 00:39:22,560 --> 00:39:24,500 which takes that 8-byte tertiary key 874 00:39:24,500 --> 00:39:26,600 and turns it into a 32-byte number. 875 00:39:28,100 --> 00:39:30,320 And if you want to just take a look at 876 00:39:30,320 --> 00:39:33,320 why I don't want to reverse this manually... 877 00:39:42,660 --> 00:39:43,900 There's a whole lot of crap in there. 878 00:39:44,820 --> 00:39:48,780 Okay, so that's a whole other world right there 879 00:39:48,780 --> 00:39:51,380 that we don't necessarily want to take the time to reverse. 880 00:39:51,640 --> 00:39:53,600 But are we screwed? No. 881 00:39:55,520 --> 00:39:57,560 So what we can do is, 882 00:39:57,700 --> 00:39:59,880 given that the 16-byte key 883 00:40:00,500 --> 00:40:02,240 is always going to be the same... 884 00:40:03,520 --> 00:40:04,820 I'm sorry, the 16-byte key 885 00:40:04,820 --> 00:40:05,680 is not always going to be the same. 886 00:40:05,740 --> 00:40:06,980 It's going to be generated pseudo-randomly 887 00:40:06,980 --> 00:40:07,980 with that vulnerability, of course. 888 00:40:08,260 --> 00:40:11,860 But given a particular 16-byte number, 889 00:40:12,520 --> 00:40:14,640 this generates the same 8-byte secondary key, 890 00:40:14,740 --> 00:40:16,880 this generates the same 8-byte tertiary key, 891 00:40:17,100 --> 00:40:19,640 and this generates the same 32-byte final key. 892 00:40:19,740 --> 00:40:20,660 And that's the one that's transmitted 893 00:40:21,200 --> 00:40:22,840 in the uploaded packet. 894 00:40:23,140 --> 00:40:26,300 So here's an example of one of the log files 895 00:40:26,300 --> 00:40:29,860 that we recovered from a rated drop site. 896 00:40:30,420 --> 00:40:32,760 So in yellow right there is the 32-byte key, 897 00:40:32,880 --> 00:40:34,800 and then in blue right after 898 00:40:34,800 --> 00:40:36,200 is the size of the encrypted data, 899 00:40:36,300 --> 00:40:37,520 and then in green is the encrypted data. 900 00:40:38,680 --> 00:40:39,840 So what we did was, 901 00:40:40,820 --> 00:40:42,900 based on that vulnerability in the keys... 902 00:40:44,100 --> 00:40:44,940 Here's demo X. 903 00:40:45,780 --> 00:40:47,620 We just simply made a wrapper 904 00:40:47,620 --> 00:40:50,140 around these few functions. 905 00:40:50,500 --> 00:40:52,400 So we called keygen 16 primary. 906 00:40:52,800 --> 00:40:53,980 We let the Trojan run 907 00:40:53,980 --> 00:40:56,700 until after this reorder bignum function. 908 00:40:58,140 --> 00:40:59,540 And at that point, you know, 909 00:40:59,540 --> 00:41:00,400 we control memory. 910 00:41:00,520 --> 00:41:01,780 We can read whatever values we want. 911 00:41:02,020 --> 00:41:05,020 So we want to save the 32-byte number 912 00:41:05,020 --> 00:41:05,660 that it generated, 913 00:41:05,800 --> 00:41:07,260 and we want to associate that 914 00:41:07,260 --> 00:41:09,500 with the 16-byte number that was input 915 00:41:09,500 --> 00:41:11,820 to this entire sequence of events. 916 00:41:12,060 --> 00:41:13,220 And then we're going to do it again. 917 00:41:13,380 --> 00:41:14,200 And then we're going to do it again. 918 00:41:14,340 --> 00:41:16,000 And we did that 5,000 times. 919 00:41:19,700 --> 00:41:22,620 And I will show you how this works. 920 00:41:27,340 --> 00:41:28,620 Based on that vulnerability, 921 00:41:29,860 --> 00:41:33,440 5,000 keys is enough to decrypt 100% 922 00:41:34,160 --> 00:41:36,380 of the records that were recovered from the website. 923 00:41:41,860 --> 00:41:43,080 So what we just did was, 924 00:41:43,200 --> 00:41:46,680 we logged into a website with Internet Explorer 925 00:41:46,680 --> 00:41:48,360 while the Trojan is infected on the machine. 926 00:41:49,480 --> 00:41:51,060 We have a breakpoint right here 927 00:41:51,060 --> 00:41:52,500 at the encrypt main function, 928 00:41:52,620 --> 00:41:54,020 which is what I just showed you in the disassembly. 929 00:41:54,120 --> 00:41:56,400 The reason we did that is because there's actually 930 00:41:56,400 --> 00:41:59,080 a second parameter to that tertiary function. 931 00:41:59,540 --> 00:42:01,880 A function besides the 8-byte secondary key. 932 00:42:02,200 --> 00:42:04,600 And it's a number that the Trojan downloads 933 00:42:04,600 --> 00:42:08,260 from the Internet and decodes from a configuration file 934 00:42:08,260 --> 00:42:09,240 and then passes to this function. 935 00:42:09,520 --> 00:42:12,180 So do I need to download that configuration file 936 00:42:12,180 --> 00:42:14,680 and decrypt it myself and then pass it to this function? 937 00:42:14,800 --> 00:42:16,320 No, I'll just let the Trojan run naturally, 938 00:42:16,420 --> 00:42:17,000 like I just did. 939 00:42:17,160 --> 00:42:18,180 I had a breakpoint set. 940 00:42:18,340 --> 00:42:19,100 I just logged into the website, 941 00:42:19,320 --> 00:42:20,640 and the Trojan did all of that itself 942 00:42:20,640 --> 00:42:21,700 once I get to this point. 943 00:42:25,180 --> 00:42:27,320 And then we're going to select the function here. 944 00:42:27,460 --> 00:42:28,480 It's going to loop through. 945 00:42:28,480 --> 00:42:30,080 1,000 times. 946 00:42:30,380 --> 00:42:31,320 No, 5,000 times. 947 00:42:31,540 --> 00:42:33,840 And it's going to generate this binary file on disk 948 00:42:33,840 --> 00:42:37,200 which contains a mapping of the 16-byte primary keys 949 00:42:37,200 --> 00:42:40,380 to the 32-byte final keys. 950 00:42:40,800 --> 00:42:43,140 And then all of those logs 951 00:42:43,140 --> 00:42:44,180 that we recovered from the website, 952 00:42:45,080 --> 00:42:46,200 we're going to process them, 953 00:42:47,160 --> 00:42:49,240 look for the 32-byte number, 954 00:42:51,360 --> 00:42:52,240 and we're going to say, 955 00:42:52,300 --> 00:42:53,860 hey, is this 32-byte number included 956 00:42:53,860 --> 00:42:55,540 in that list of 5,000 that we generated? 957 00:42:55,720 --> 00:42:58,460 If so, give me the corresponding 16-byte number. 958 00:42:58,480 --> 00:42:59,180 If not, give me the 16-byte encryption key. 959 00:42:59,880 --> 00:43:00,720 And at that point, 960 00:43:00,780 --> 00:43:02,820 we've already got the decryption code written, 961 00:43:02,940 --> 00:43:03,880 so we'll just send it through. 962 00:43:04,100 --> 00:43:04,680 And like I said, 963 00:43:04,760 --> 00:43:07,120 that was capable of decoding 100% of the logs that we found. 964 00:43:08,600 --> 00:43:09,560 So that's all for the demos, 965 00:43:09,760 --> 00:43:11,740 and Greg's going to wrap up with some utilities 966 00:43:11,740 --> 00:43:13,680 and some other things that you can do 967 00:43:13,680 --> 00:43:15,360 that are fun using a scripted debugger. 968 00:43:16,940 --> 00:43:17,420 All right. 969 00:43:18,840 --> 00:43:19,640 Put the mic here. 970 00:43:20,660 --> 00:43:22,240 Okay, so I mentioned earlier in the presentation 971 00:43:22,240 --> 00:43:24,800 about utility functions and recon functions, 972 00:43:24,940 --> 00:43:25,740 or scripts, sorry. 973 00:43:26,280 --> 00:43:27,120 One thing you can do 974 00:43:27,120 --> 00:43:28,400 is look for arbitrary shellcode, 975 00:43:28,860 --> 00:43:30,120 or shellcode arbitrary file, rather. 976 00:43:30,180 --> 00:43:30,340 I'm sorry. 977 00:43:30,640 --> 00:43:31,960 So let's say you have, you know, 978 00:43:32,840 --> 00:43:34,480 a JPEG, PDF, doc file, whatever, 979 00:43:34,560 --> 00:43:35,740 you think might have shellcode in it. 980 00:43:36,020 --> 00:43:37,400 Well, shellcode's going to have certain characteristics, 981 00:43:38,280 --> 00:43:40,560 such as it's going to jump somewhere 982 00:43:40,560 --> 00:43:41,700 within the memory that it has, 983 00:43:41,740 --> 00:43:42,840 and then start executing. 984 00:43:43,180 --> 00:43:44,140 It's kind of a trampoline. 985 00:43:44,500 --> 00:43:46,200 So one thing you can do is write a quick script 986 00:43:46,200 --> 00:43:48,720 that starts at byte zero, 987 00:43:50,180 --> 00:43:51,800 disassembles the file in memory, 988 00:43:52,420 --> 00:43:52,800 checks for, 989 00:43:52,840 --> 00:43:54,200 checks to see if it's a jump or a call or whatever. 990 00:43:55,020 --> 00:43:55,960 But if it is, 991 00:43:55,980 --> 00:43:56,860 then jump to the next, 992 00:43:57,120 --> 00:43:57,520 that location, 993 00:43:57,640 --> 00:43:59,940 see if that location's inside the memory 994 00:43:59,940 --> 00:44:01,060 that was loaded for the file. 995 00:44:01,620 --> 00:44:03,180 See if that instruction makes sense. 996 00:44:03,440 --> 00:44:04,940 So if you do jump within memory 997 00:44:04,940 --> 00:44:06,840 and you jump to like an out or an in, 998 00:44:06,860 --> 00:44:07,900 or some other privileged instructions, 999 00:44:08,320 --> 00:44:10,540 odds are that what you have is just happenstance. 1000 00:44:10,700 --> 00:44:11,200 It's curiosity. 1001 00:44:12,760 --> 00:44:14,760 But if it does jump to a valid memory, 1002 00:44:14,900 --> 00:44:15,660 a valid instruction, 1003 00:44:15,960 --> 00:44:18,500 then the odds are you have shellcode in your file. 1004 00:44:18,900 --> 00:44:20,440 So what that looks like, real quick. 1005 00:44:21,680 --> 00:44:23,380 All right, so this is what, 1006 00:44:23,440 --> 00:44:24,640 actually this script Mike wrote. 1007 00:44:25,840 --> 00:44:26,440 What it did, 1008 00:44:26,500 --> 00:44:27,100 it went through a, 1009 00:44:27,120 --> 00:44:28,460 I think this was a JPEG, right? 1010 00:44:28,800 --> 00:44:29,860 Went through a JPEG. 1011 00:44:29,960 --> 00:44:31,180 Oh no wait, it was a malicious PDF edit. 1012 00:44:31,360 --> 00:44:32,060 Oh sorry, PDF. 1013 00:44:32,900 --> 00:44:33,660 Went through a PDF, 1014 00:44:33,880 --> 00:44:34,800 did this process. 1015 00:44:35,000 --> 00:44:36,300 It started at the top, 1016 00:44:36,420 --> 00:44:36,900 disassembled, 1017 00:44:37,000 --> 00:44:38,300 if it was a jump or a call, 1018 00:44:38,880 --> 00:44:40,540 it checked to see where it went to. 1019 00:44:40,720 --> 00:44:42,880 If it was within the memory range, 1020 00:44:43,480 --> 00:44:45,360 it checked to see what instructions was next. 1021 00:44:46,180 --> 00:44:46,900 As you can see, 1022 00:44:46,980 --> 00:44:47,860 it'll produce a lot of data. 1023 00:44:47,920 --> 00:44:49,080 Not necessarily all of it useful. 1024 00:44:49,740 --> 00:44:51,340 But if you look at the highlighted portion here 1025 00:44:51,340 --> 00:44:51,840 for this demo, 1026 00:44:52,020 --> 00:44:53,520 you can see that the jump 1027 00:44:54,060 --> 00:44:55,820 landed within the memory range of the file 1028 00:44:55,820 --> 00:44:56,380 that was loaded. 1029 00:44:56,680 --> 00:44:58,500 And it looks like a valid instruction. 1030 00:44:58,680 --> 00:44:59,840 So it's doing a move from, 1031 00:44:59,880 --> 00:45:00,200 you know, 1032 00:45:00,280 --> 00:45:02,380 a known NT data structure. 1033 00:45:02,720 --> 00:45:03,180 So odds are, 1034 00:45:03,220 --> 00:45:03,840 that's your shellcode. 1035 00:45:04,080 --> 00:45:05,400 So if you jump to that location, 1036 00:45:05,540 --> 00:45:06,400 using this script, 1037 00:45:06,980 --> 00:45:08,140 you can disassemble it, 1038 00:45:08,140 --> 00:45:10,160 you can see that odds are pretty good 1039 00:45:10,160 --> 00:45:10,960 that's shellcode. 1040 00:45:12,160 --> 00:45:13,120 So I think we also, 1041 00:45:13,180 --> 00:45:14,040 please hold this to the right. 1042 00:45:14,200 --> 00:45:15,580 Is the script on the desk? 1043 00:45:16,280 --> 00:45:16,640 Yeah. 1044 00:45:16,700 --> 00:45:16,960 Yeah. 1045 00:45:17,800 --> 00:45:18,960 All right, we're running out of time. 1046 00:45:19,020 --> 00:45:19,340 Is this yours? 1047 00:45:19,780 --> 00:45:20,140 Yeah, sure. 1048 00:45:21,240 --> 00:45:22,720 Another cool thing you can do is, 1049 00:45:22,760 --> 00:45:23,100 you know, 1050 00:45:23,120 --> 00:45:23,940 you've got access to 1051 00:45:23,940 --> 00:45:25,300 that user mode memory. 1052 00:45:25,780 --> 00:45:27,320 If you want to look for trampoline hooks, 1053 00:45:27,860 --> 00:45:29,040 you can obviously do that, 1054 00:45:29,100 --> 00:45:29,260 you know, 1055 00:45:29,320 --> 00:45:30,480 like with Gmer 1056 00:45:30,480 --> 00:45:32,040 or some other rootkit detection script. 1057 00:45:32,340 --> 00:45:33,740 But assume that you want to 1058 00:45:33,740 --> 00:45:35,080 find out exactly 1059 00:45:35,080 --> 00:45:36,960 what the purpose of those API hooks are. 1060 00:45:37,120 --> 00:45:38,020 So Gmer will tell you, 1061 00:45:38,040 --> 00:45:39,720 hey, there's an API hook on internet read file, 1062 00:45:39,860 --> 00:45:42,260 and it jumps to 0x8D0000. 1063 00:45:42,600 --> 00:45:44,180 But does that, 1064 00:45:44,180 --> 00:45:44,540 you know, 1065 00:45:44,560 --> 00:45:45,240 really tell you 1066 00:45:45,240 --> 00:45:46,720 what the purpose of the hook is? 1067 00:45:48,180 --> 00:45:50,980 So with some scripts in the debugger, 1068 00:45:51,020 --> 00:45:51,820 you can number one, 1069 00:45:51,900 --> 00:45:53,500 enumerate the same trampoline hooks 1070 00:45:53,500 --> 00:45:53,880 as, 1071 00:45:55,220 --> 00:45:56,020 as Gmer, 1072 00:45:56,160 --> 00:45:58,000 and you can also set a breakpoint 1073 00:45:58,480 --> 00:46:00,280 on the destination of the trampoline hooks, 1074 00:46:00,400 --> 00:46:02,180 and you can just use the browser 1075 00:46:02,180 --> 00:46:02,860 as you normally would, 1076 00:46:02,940 --> 00:46:04,160 wait for those triggers to get hooked, 1077 00:46:04,300 --> 00:46:05,360 and then you can debug it. 1078 00:46:05,880 --> 00:46:07,860 Find out exactly what it's doing 1079 00:46:07,860 --> 00:46:08,580 with the parameters 1080 00:46:08,580 --> 00:46:09,700 that get sent to internet read file. 1081 00:46:11,380 --> 00:46:12,160 So it's pretty easy, 1082 00:46:12,240 --> 00:46:14,480 just a normal way of detecting trampoline hooks, 1083 00:46:14,560 --> 00:46:15,960 just looking at the prologue 1084 00:46:15,960 --> 00:46:16,700 of the legitimate function. 1085 00:46:17,520 --> 00:46:19,400 Does it contain a jump 1086 00:46:19,400 --> 00:46:20,260 to some arbitrary memory 1087 00:46:20,260 --> 00:46:22,560 and an arbitrary location memory, 1088 00:46:22,700 --> 00:46:23,220 or does it call 1089 00:46:23,220 --> 00:46:25,380 some arbitrary location of memory? 1090 00:46:25,500 --> 00:46:26,960 So it's pretty easy to do that. 1091 00:46:27,140 --> 00:46:28,300 This is an example of, 1092 00:46:28,420 --> 00:46:30,220 I think this is SilentBanker, 1093 00:46:30,300 --> 00:46:30,680 again, 1094 00:46:31,320 --> 00:46:32,460 as you can see over there 1095 00:46:32,460 --> 00:46:32,960 on the op code, 1096 00:46:33,940 --> 00:46:36,200 that's the instruction 1097 00:46:36,200 --> 00:46:38,020 at the prologue 1098 00:46:38,020 --> 00:46:39,700 of those respective functions 1099 00:46:39,700 --> 00:46:40,760 on the left hand side. 1100 00:46:41,100 --> 00:46:43,120 So wininet.http send request 1101 00:46:43,120 --> 00:46:43,920 down there at the bottom 1102 00:46:43,920 --> 00:46:45,220 would normally contain 1103 00:46:46,040 --> 00:46:48,500 probably like a push EBP 1104 00:46:48,500 --> 00:46:49,560 or something like that, 1105 00:46:49,700 --> 00:46:50,840 but in this case, 1106 00:46:51,680 --> 00:46:53,200 it contains a push EBP 1107 00:46:53,220 --> 00:46:55,400 of the random address, 1108 00:46:55,560 --> 00:46:55,980 well not random, 1109 00:46:56,060 --> 00:46:58,360 but the address of the hook code 1110 00:46:58,360 --> 00:46:59,820 in memory that's going to, 1111 00:46:59,940 --> 00:47:00,960 that you're going to want to follow 1112 00:47:00,960 --> 00:47:01,900 if you're trying to debug it 1113 00:47:01,900 --> 00:47:02,800 and find out what it does. 1114 00:47:05,040 --> 00:47:05,520 All right. 1115 00:47:06,440 --> 00:47:07,560 So we're pretty much done here. 1116 00:47:07,780 --> 00:47:09,100 But there are a few things 1117 00:47:09,100 --> 00:47:09,780 you need to be careful of 1118 00:47:09,780 --> 00:47:11,580 whenever you're scripting. 1119 00:47:12,160 --> 00:47:12,920 First and foremost, 1120 00:47:13,500 --> 00:47:14,560 as we pointed out, 1121 00:47:14,700 --> 00:47:16,220 scripting may not actually be 1122 00:47:16,220 --> 00:47:17,320 the best solution for you. 1123 00:47:18,060 --> 00:47:19,980 The wire structure, for example. 1124 00:47:20,380 --> 00:47:21,680 So know what you want to do, 1125 00:47:21,760 --> 00:47:22,500 know what you want to accomplish, 1126 00:47:22,500 --> 00:47:23,480 and that will tell you 1127 00:47:23,480 --> 00:47:23,840 if you want it, 1128 00:47:23,900 --> 00:47:24,760 if you can script it or not. 1129 00:47:24,980 --> 00:47:26,040 So if you're given to a customer, 1130 00:47:26,200 --> 00:47:27,200 odds are you're going to have 1131 00:47:27,200 --> 00:47:27,720 to do some manual 1132 00:47:27,720 --> 00:47:28,740 or assisted reversing, 1133 00:47:28,860 --> 00:47:30,040 and good luck with that. 1134 00:47:31,600 --> 00:47:33,500 The next thing is kernel space 1135 00:47:33,500 --> 00:47:34,640 doesn't script well. 1136 00:47:35,080 --> 00:47:36,320 You can try, 1137 00:47:37,220 --> 00:47:38,520 but we highly recommend 1138 00:47:38,520 --> 00:47:39,440 that you look at things 1139 00:47:39,440 --> 00:47:40,680 more like in the user land, 1140 00:47:40,840 --> 00:47:43,580 like hook certain calls 1141 00:47:43,580 --> 00:47:44,600 to kernel space, 1142 00:47:45,040 --> 00:47:46,520 actually happened in user space, 1143 00:47:46,760 --> 00:47:47,420 hook those instead. 1144 00:47:48,360 --> 00:47:49,740 And it's important to understand 1145 00:47:49,740 --> 00:47:50,320 that you're dealing 1146 00:47:50,320 --> 00:47:51,160 with a script here. 1147 00:47:51,160 --> 00:47:51,580 You're not, 1148 00:47:51,700 --> 00:47:52,820 you didn't compile this, 1149 00:47:52,940 --> 00:47:53,980 so it's interpreted 1150 00:47:53,980 --> 00:47:55,380 and interpretation takes time. 1151 00:47:56,220 --> 00:47:57,540 Some of the demos we had, 1152 00:47:58,060 --> 00:48:01,160 like I think the Kraken domain name, 1153 00:48:01,220 --> 00:48:02,900 actually runs for quite a bit of time, 1154 00:48:02,960 --> 00:48:03,720 so don't be surprised 1155 00:48:03,720 --> 00:48:05,080 if your script does run for a bit. 1156 00:48:05,260 --> 00:48:06,080 Like we said, go to lunch. 1157 00:48:06,920 --> 00:48:07,320 Yeah. 1158 00:48:08,180 --> 00:48:08,980 And finally, 1159 00:48:09,120 --> 00:48:10,380 since you are running your malware 1160 00:48:10,380 --> 00:48:11,220 in a debugger, 1161 00:48:11,360 --> 00:48:13,120 it may be aware of that 1162 00:48:13,120 --> 00:48:14,840 and may be a little pissy about that. 1163 00:48:15,040 --> 00:48:16,940 So there are tricks obviously you can do 1164 00:48:16,940 --> 00:48:18,620 to make your debugger 1165 00:48:18,620 --> 00:48:19,780 a little less visible to the malware, 1166 00:48:19,780 --> 00:48:20,640 so you might want to try, 1167 00:48:20,660 --> 00:48:21,320 try those. 1168 00:48:22,020 --> 00:48:23,000 So at that point, 1169 00:48:23,060 --> 00:48:24,060 we are done. 1170 00:48:25,560 --> 00:48:25,960 So, 1171 00:48:26,900 --> 00:48:27,720 can you guys go ahead? 1172 00:48:28,740 --> 00:48:29,140 Let's go.