1 00:00:13,620 --> 00:00:18,540 kind of put together a number of different panel ideas this year this year we wanted to do a little 2 00:00:18,540 --> 00:00:24,680 more in the technical side so that it so it wasn't all just script kiddies so I can take 3 00:00:24,680 --> 00:00:32,080 it by the attendance here that that was a good idea all right all right I guess we'll keep doing 4 00:00:32,080 --> 00:00:37,920 that tomorrow we've got a pretty full session in all three rooms and we'll try to get things 5 00:00:37,920 --> 00:00:42,280 more organized certainly appreciate your patience I know a lot of you've been waiting outside trying 6 00:00:42,280 --> 00:00:50,440 to get in here I can tell you that typically Saturday was our big busy day today I think we 7 00:00:50,440 --> 00:00:54,660 broke all the records in one day of what we did last year so the attendance is still pretty good 8 00:00:54,660 --> 00:00:58,760 attendance has been really great, and we thank you all for making that possible, and we hope 9 00:00:58,760 --> 00:01:02,840 we've put together a good conference for you and a lot of party, a lot of fun. Hey, it's 10 00:01:02,840 --> 00:01:08,900 Vegas. Fucking A, man. You should have a great time. All right, so not to delay things any 11 00:01:08,900 --> 00:01:14,020 longer, try to keep a little bit on schedule if possible. New Hack City, the man himself, 12 00:01:14,260 --> 00:01:17,840 Giroux, the one you've been waiting for. I'm going to turn the mic over to him, and here 13 00:01:17,840 --> 00:01:30,120 you go. My name is Giroux. I'm going to talk about advanced evasion of IDS buffer flow 14 00:01:30,120 --> 00:01:37,680 detection. This came about on a discussion on Pound CDC. I was talking with T12 and Java 15 00:01:37,680 --> 00:01:43,140 Man about the way that IDSs are looking for strings and buffer overflows. Can you hit 16 00:01:43,140 --> 00:01:43,460 the slide? 17 00:01:46,760 --> 00:01:47,640 This is a... 18 00:01:47,640 --> 00:01:47,820 This is a... 19 00:01:48,900 --> 00:01:53,840 A little background on me. I worked in embedded systems. I'm doing...working on IDSs right 20 00:01:53,840 --> 00:01:59,220 now. I've been...I'm a part of New Hack City, a collective in San Francisco, working on 21 00:01:59,220 --> 00:02:01,840 a couple different projects, and of course, we have T-shirts available. 22 00:02:08,420 --> 00:02:13,400 I'm going to start out with a brief overview of buffer overflows. I'm going to cover, just 23 00:02:13,400 --> 00:02:17,760 as a refresher, the stuff that was in the Alpha 1 article, just to get everyone up to speed and 24 00:02:17,760 --> 00:02:22,000 in case, I don't know, forgot something. Then I'm also going to go over, like, the 25 00:02:22,000 --> 00:02:26,660 kinds of signatures that IDSs are looking for, and then the techniques to code around 26 00:02:26,660 --> 00:02:32,600 the signatures, so that you can bypass the IDS, get your attack through, and no one 27 00:02:32,600 --> 00:02:32,900 will notice. 28 00:02:37,460 --> 00:02:38,460 You hit the next one. 29 00:02:40,060 --> 00:02:47,240 This is the stack on most computers, and what you're trying to do is these local variables 30 00:02:47,240 --> 00:02:47,480 here. 31 00:02:47,540 --> 00:02:47,740 Here you go. 32 00:02:47,740 --> 00:02:52,980 You're trying to overwrite up this way, and overwrite the return address. Once you can 33 00:02:52,980 --> 00:02:58,640 get the return address to point back into your buffer, then you can execute your own 34 00:02:58,640 --> 00:02:58,900 code. 35 00:03:02,660 --> 00:03:06,640 This is the shell code that was provided in the Alpha 1 article. I'm going to step 36 00:03:06,640 --> 00:03:10,620 through it a little bit and cover what's going on. 37 00:03:11,120 --> 00:03:17,320 At the top, you're going to have a...you have a jump with an offset that's going to this 38 00:03:17,320 --> 00:03:17,620 column. 39 00:03:17,620 --> 00:03:22,080 The reason you need a jump and a call is that you have no way of knowing the current 40 00:03:22,920 --> 00:03:30,320 execution pointer, the EIP. You need to know the EIP for...because most of the buffer 41 00:03:30,320 --> 00:03:38,260 overflows, you're going to try to execute a shell. The execv call requires a binsh string 42 00:03:38,880 --> 00:03:46,940 in memory, a pointer to that string, the address of the string, and a null. In order to insert 43 00:03:46,940 --> 00:03:47,600 these things, you're going to need a jump and a call. 44 00:03:47,600 --> 00:03:52,320 In the proper registers, we're going to need to know the actual address. 45 00:03:53,100 --> 00:03:59,520 The first thing that happens is you overwrite the...can you go back one? 46 00:04:01,940 --> 00:04:07,080 You overwrite this return address to point somewhere into here. You're usually going 47 00:04:07,080 --> 00:04:11,600 to pad this with no ops because you don't know the exact address. You're kind of just 48 00:04:11,600 --> 00:04:16,280 guessing here. The no ops provides some padding so you can guess in here. Usually, your code 49 00:04:16,280 --> 00:04:16,920 will be like... 50 00:04:17,600 --> 00:04:23,420 Maybe 50 bytes, and this might be a 1K buffer, so you have all kinds of space for no ops, 51 00:04:23,480 --> 00:04:25,600 so it's pretty easy to get in there. 52 00:04:30,000 --> 00:04:36,760 Okay, after you do the jump call, the address after the call is going to be pushed onto 53 00:04:36,760 --> 00:04:44,620 the stack. Then to get the address, you pop it back into ESI, which is a stack index. 54 00:04:45,300 --> 00:04:46,700 You could really use any... 55 00:04:47,600 --> 00:04:52,880 If you register in protected mode, it doesn't matter. There's no restrictions on base index, 56 00:04:53,120 --> 00:04:59,480 so this is what was shown in the article, but there's other ways to do it so that it 57 00:04:59,480 --> 00:05:01,320 avoids the common signatures that are out there. 58 00:05:03,240 --> 00:05:10,580 After that, you put the address of this in a location right after the string. That's 59 00:05:10,580 --> 00:05:13,940 going to be your pointer to the string. Then you clear out EAX. 60 00:05:17,600 --> 00:05:25,940 You use the low byte AL and put that seven locations after ESI, after here. That's terminating 61 00:05:25,940 --> 00:05:33,760 the string. That's how you terminate the string. After that, you take EAX, which still 62 00:05:33,760 --> 00:05:38,840 has zeros, and put it 12 locations after this, which there's nothing there, and that'll 63 00:05:38,840 --> 00:05:45,940 be your null string. There's four bytes of nulls. After that, you move B into AL, ESI 64 00:05:45,940 --> 00:05:46,900 into EBX. 65 00:05:47,620 --> 00:05:53,840 Load the addresses of the pointer into ECX, and the address of the nulls into EDX. You 66 00:05:53,840 --> 00:05:58,340 do an interrupt 80. This is code specifically to Linux, because that's how it handles it. 67 00:05:58,460 --> 00:06:04,580 That's the kernel interface. This does the execve call. This call right here is exit 68 00:06:04,580 --> 00:06:07,480 in case anything goes wrong here. You can exit out, and you won't keep pulling stuff 69 00:06:07,480 --> 00:06:10,580 off the stack. That's just a basic overview. 70 00:06:14,040 --> 00:06:15,900 Here's some signatures from Snort. 71 00:06:17,600 --> 00:06:24,340 This is what it's looking for over the wire. This is a common overflow. This is 2.4.2 WooFTP 72 00:06:24,920 --> 00:06:32,760 run by ADM. Right here, these are the instructions it's looking for. This right here up to here 73 00:06:32,760 --> 00:06:38,760 is an SUID call, and here's another SUID call. It's looking for the instructions in 74 00:06:38,760 --> 00:06:42,560 the packet. Similar to here, this is, I believe, a jump. 75 00:06:45,360 --> 00:06:46,800 Here's one of the most common ones. 76 00:06:47,600 --> 00:06:51,180 It's looking for long strings of no ops. It usually means that someone's trying to overflow 77 00:06:51,180 --> 00:06:54,620 a buffer, because they're using those for padding. We'll show how to go around that. 78 00:06:55,380 --> 00:07:00,860 This right here, lots of people use the slash bin SH to execute a shell, so people are 79 00:07:00,860 --> 00:07:01,620 looking for this, too. 80 00:07:07,060 --> 00:07:11,280 In order to avoid detection, you have to code a little differently. You can change the 81 00:07:11,280 --> 00:07:15,640 location, or the order of the instructions you're using, so that the signature is different. 82 00:07:16,080 --> 00:07:17,420 You can use different instructions. 83 00:07:17,600 --> 00:07:24,960 You can use different registers within the instructions. You can replace no ops with 84 00:07:24,960 --> 00:07:27,920 other one-byte instructions, or you can encrypt your payload. 85 00:07:34,420 --> 00:07:42,160 This code is copies from the code I showed earlier. You see that it's zeroing it out 86 00:07:42,160 --> 00:07:42,740 here first. 87 00:07:45,140 --> 00:07:45,660 You can see that it's zeroing it out here first. 88 00:07:45,660 --> 00:07:46,640 And then... 89 00:07:48,840 --> 00:07:52,220 All that's being changed is the order of moving this into AL. 90 00:07:54,000 --> 00:07:57,440 So if you move it around, the signature will come out differently. 91 00:08:02,460 --> 00:08:08,140 Different instructions for the same objective. Instead of doing this type of call with a 92 00:08:08,700 --> 00:08:14,180 static offset, you can zero register, move that into the register, and call the register. 93 00:08:14,480 --> 00:08:17,440 And this will produce a different signature than the original one. 94 00:08:19,620 --> 00:08:23,680 And another thing you can do, instead of using, let's say, XOR to zero it out, you can use the 95 00:08:23,680 --> 00:08:24,720 subtraction to zero it out. 96 00:08:25,020 --> 00:08:30,160 And these are all simple techniques that people have used before, but it'll evade signatures. 97 00:08:38,180 --> 00:08:41,740 Go ahead and go back. 98 00:08:43,480 --> 00:08:47,440 The idea here is, like, at the top of the buffer overflow, there was a... 99 00:08:47,440 --> 00:08:47,580 There was a... 100 00:08:47,580 --> 00:08:48,820 A pop ESI. 101 00:08:48,920 --> 00:08:55,300 You could pop, let's say, EBX, and then the address of the string is already located in 102 00:08:55,300 --> 00:08:56,760 EBX, which you'd use for later. 103 00:08:56,920 --> 00:09:00,220 So it's actually optimizing the code, and it changes it around a little bit. 104 00:09:00,380 --> 00:09:03,320 Protected mode doesn't matter what registers you use. 105 00:09:03,440 --> 00:09:06,480 With certain limitations, you can't push into EIP and stuff like that. 106 00:09:06,660 --> 00:09:09,440 But most of the general purpose registers, you can do anything you want with. 107 00:09:13,820 --> 00:09:15,640 A lot of people use... 108 00:09:15,640 --> 00:09:16,040 I don't know. 109 00:09:18,620 --> 00:09:19,060 Dope. 110 00:09:22,480 --> 00:09:23,640 Pretend this is not here. 111 00:09:31,040 --> 00:09:36,580 The idea behind the no ops is you're trying to provide some kind of padding to be able to jump into your exploit, 112 00:09:36,720 --> 00:09:37,920 because you don't know exactly where it's at. 113 00:09:38,500 --> 00:09:40,640 So no ops are used because they don't do anything. 114 00:09:40,960 --> 00:09:46,560 But you can use other instructions that are also one byte long that will not affect the outcome of your exploit. 115 00:09:46,760 --> 00:09:47,560 You could use... 116 00:09:47,560 --> 00:09:53,220 You could use, like, CLC, clear the query flag, or set the query flag, or set the direction flag, clear the direction flag. 117 00:09:53,360 --> 00:09:55,420 There's all kinds of one byte instructions you can use. 118 00:09:55,560 --> 00:10:01,800 It will not affect your exploit in any way, but it will avoid the signature that's looking for all no ops. 119 00:10:05,980 --> 00:10:06,920 I'm covering that next. 120 00:10:09,400 --> 00:10:11,660 The types of encryption are really simple. 121 00:10:11,860 --> 00:10:15,320 All we're trying to do is avoid the known signature. 122 00:10:17,040 --> 00:10:17,540 We're not... 123 00:10:17,560 --> 00:10:22,500 We don't have a lot of space, so the first tile would be, like, some kind of ROT13-ish. 124 00:10:22,540 --> 00:10:24,980 Just add a constant offset, or subtract a constant offset. 125 00:10:25,440 --> 00:10:27,920 The second one would be an XOR with a constant. 126 00:10:28,520 --> 00:10:31,380 And the last one would be an XOR with a variable where you... 127 00:10:31,900 --> 00:10:35,200 Your XOR is based on the outcome of your previous instruction. 128 00:10:35,560 --> 00:10:38,020 It will provide a little bit more protection. 129 00:10:43,060 --> 00:10:44,220 Self-modifying code. 130 00:10:44,400 --> 00:10:45,060 There's been a... 131 00:10:45,060 --> 00:10:47,040 Like, IMAP exploit, you had to add... 132 00:10:47,560 --> 00:10:50,680 A 50-byte offset to the bin SH to get it through. 133 00:10:50,900 --> 00:10:51,960 There's filters. 134 00:10:52,160 --> 00:10:56,080 Sometimes HTTP filters won't allow certain characters through. 135 00:10:56,320 --> 00:10:58,260 So people have used self-modifying code. 136 00:10:58,820 --> 00:11:00,940 And someone pointed out this week... 137 00:11:01,560 --> 00:11:07,620 Someone on this side right here wrote some encrypted shellcode that would encrypt just the bin SH string at the end. 138 00:11:08,160 --> 00:11:13,020 But the rest of the payload is still detectable by signatures. 139 00:11:14,500 --> 00:11:16,420 This is the architecture that I chose. 140 00:11:19,440 --> 00:11:22,760 This is the decryption block, and this is an encrypted payload. 141 00:11:24,200 --> 00:11:27,240 So the decryption block is up here. 142 00:11:27,500 --> 00:11:29,740 First you start with a jump, and then you have a call. 143 00:11:30,000 --> 00:11:32,960 On your stack, you'll have the first address of the encrypted instructions. 144 00:11:35,480 --> 00:11:41,440 Then in here, you start reading in the data, either adding a constant offset or doing an XOR with a constant, 145 00:11:41,580 --> 00:11:43,000 and writing data back out. 146 00:11:43,320 --> 00:11:47,220 Once this drops through and it's down, you jump into the first instruction of your payload. 147 00:11:47,560 --> 00:11:48,680 And then execute your exploit. 148 00:11:53,660 --> 00:11:57,800 This is probably really small to see, but it's the same thing I said. 149 00:11:57,980 --> 00:11:59,160 You start here. 150 00:11:59,200 --> 00:11:59,740 Here's the jump. 151 00:12:00,340 --> 00:12:01,500 It goes to the call. 152 00:12:03,080 --> 00:12:07,660 This code right here is not encrypted for demonstration purposes, so you wouldn't be able to see what it was. 153 00:12:08,040 --> 00:12:15,080 And then you go back up, start decrypting, go through the loop, drop down, jump into the instructions. 154 00:12:17,560 --> 00:12:18,380 It's pretty simple. 155 00:12:20,100 --> 00:12:24,060 I had a couple demos working. 156 00:12:25,000 --> 00:12:29,400 Working exploits have been converted to this, but we don't have the setup to have a live demo. 157 00:12:31,220 --> 00:12:34,540 I'm going to release the paper probably within a week. 158 00:12:34,600 --> 00:12:38,080 I had Spark code written, but it's not fully tested and needs a little more work. 159 00:12:38,440 --> 00:12:41,720 So either I'm going to release the paper in about a week with the x86 code, 160 00:12:41,800 --> 00:12:45,680 or maybe two weeks and have both x86 and Spark code examples. 161 00:12:47,560 --> 00:12:48,460 GCC sucks. 162 00:12:48,920 --> 00:12:52,840 You don't want to use GCC to code exploits. 163 00:12:53,340 --> 00:12:54,460 There's lots of instructions. 164 00:12:54,680 --> 00:12:55,680 It will not compile. 165 00:12:56,220 --> 00:13:00,420 It took me forever to figure out why I couldn't get the instructions to compile. 166 00:13:01,140 --> 00:13:08,820 The assembler GCC uses is called GAST, and they chose not to implement any instructions that have 8-bit offsets. 167 00:13:09,060 --> 00:13:13,260 And we're working with such little code that we're never going to go past 8-bit offsets. 168 00:13:13,320 --> 00:13:16,100 So a loop instruction can't use. 169 00:13:16,500 --> 00:13:17,540 So if you're... 170 00:13:17,560 --> 00:13:19,520 If you're going to write exploits, use NASM. 171 00:13:20,080 --> 00:13:23,140 NASM supports the full i3-6 instruction set. 172 00:13:23,440 --> 00:13:25,340 And this is what you want to use for optimization. 173 00:13:26,440 --> 00:13:26,880 Yeah? 174 00:13:27,040 --> 00:13:27,640 Do you have a choice? 175 00:13:27,740 --> 00:13:28,740 Do you use or do you not? 176 00:13:28,860 --> 00:13:29,600 Do you use Spark? 177 00:13:32,300 --> 00:13:34,860 The question is, you don't have a choice on Spark. 178 00:13:35,220 --> 00:13:36,420 I don't know how... 179 00:13:36,420 --> 00:13:39,220 I haven't looked into if Spark doesn't do all the instructions, 180 00:13:39,460 --> 00:13:42,460 because all of Spark's instructions are 32-bit, 181 00:13:43,260 --> 00:13:47,060 because I haven't been writing anything for 64-bit stuff. 182 00:13:47,560 --> 00:13:48,700 But they're all 32-bit. 183 00:13:48,720 --> 00:13:49,540 They're all the same size. 184 00:13:49,580 --> 00:13:50,040 It's risk. 185 00:13:50,220 --> 00:13:52,340 So I'm assuming it would support all the instructions. 186 00:13:57,060 --> 00:14:01,240 The comment is, GCC-295 on Solaris does support all the instructions. 187 00:14:02,440 --> 00:14:02,900 What's that? 188 00:14:04,260 --> 00:14:05,280 On Solaris 8. 189 00:14:13,180 --> 00:14:14,580 And that's it. 190 00:14:14,680 --> 00:14:15,400 Is there any questions? 191 00:14:18,460 --> 00:14:19,020 Yeah. 192 00:14:20,040 --> 00:14:24,140 How is this different from the other stuff that's being used to evade virus? 193 00:14:26,800 --> 00:14:34,140 The question is, how is this different from techniques virus writers use to evade detection? 194 00:14:37,820 --> 00:14:39,700 Like a portable execution compressor? 195 00:14:40,060 --> 00:14:42,280 I mean, I'm not saying that these are new techniques. 196 00:14:42,520 --> 00:14:46,260 I'm just saying these are things available that you can do to avoid detection. 197 00:14:48,300 --> 00:14:48,740 Yeah. 198 00:14:51,740 --> 00:14:52,180 Yeah. 199 00:14:55,540 --> 00:14:57,700 If you're looking to detect this, 200 00:14:59,600 --> 00:15:03,040 in the paper I'm writing, it's going to have a sample decryption header. 201 00:15:03,360 --> 00:15:05,960 So the best way probably would be to look at the header, 202 00:15:06,140 --> 00:15:08,040 get a signature for the header, and look at that. 203 00:15:08,220 --> 00:15:11,360 But if anyone's writing an exploit and wants to go around detection, 204 00:15:11,640 --> 00:15:15,000 you just write your own decryption header and go around anything you want to. 205 00:15:15,280 --> 00:15:15,720 Okay. 206 00:15:16,960 --> 00:15:17,760 Any other questions? 207 00:15:35,260 --> 00:15:38,680 I couldn't hear the whole question, but I think it was, how would you go about, 208 00:15:38,820 --> 00:15:41,280 what if someone wrote a signature to detect a decryption technique? 209 00:15:43,420 --> 00:15:45,560 This is the standard decryption technique. 210 00:15:45,720 --> 00:15:46,180 This is the standard decryption technique that I'm releasing, 211 00:15:46,340 --> 00:15:50,540 but if you write assembly, you can write your own decryption technique that will be different, 212 00:15:50,660 --> 00:15:51,560 that will have a different signature. 213 00:15:52,160 --> 00:15:55,860 Most of the signature-based IDSs are looking for known attacks that already exist. 214 00:15:56,180 --> 00:15:58,520 They have problems finding new attacks. 215 00:15:58,920 --> 00:16:02,080 And what they try to use for new attacks is look for strings of no-ops, 216 00:16:02,220 --> 00:16:08,180 look for slash-bin SHs, and these little tricks to try to look for new attacks, 217 00:16:08,440 --> 00:16:09,780 but you can go around them. 218 00:16:12,200 --> 00:16:13,100 Any more questions? 219 00:16:18,940 --> 00:16:20,060 Go buy T-shirts. 220 00:16:20,680 --> 00:16:21,960 Go buy T-shirts.