1 00:00:00,000 --> 00:00:02,160 Damn, I love backtrack, I really do. 2 00:00:04,520 --> 00:00:05,380 Where's our queue? 3 00:00:07,620 --> 00:00:11,020 Alrighty, so we've got a pretty intense 50 minutes. 4 00:00:11,900 --> 00:00:15,220 We'll be going through the development life cycle of an exploit. 5 00:00:16,820 --> 00:00:20,280 The exploit is an NNM open view system. 6 00:00:21,280 --> 00:00:22,740 Are you familiar with that? 7 00:00:22,920 --> 00:00:26,460 Like that big machine that owns the whole network sort of thing. 8 00:00:26,660 --> 00:00:29,680 So if there's one box in the whole network that you want to own, 9 00:00:29,680 --> 00:00:30,540 it's probably that one. 10 00:00:32,060 --> 00:00:36,900 The whole exploit development cycle was quite interesting and a bit painful, 11 00:00:37,020 --> 00:00:39,160 and that's basically what I wanted to share, the pain, 12 00:00:39,320 --> 00:00:42,360 not to have to deal with it all by myself. 13 00:00:49,660 --> 00:00:54,000 So basically what we'll be doing today is we'll be going from bug to zero day. 14 00:00:54,080 --> 00:00:59,060 We'll just retrace all the steps that we took in order to own NNM. 15 00:01:00,180 --> 00:01:05,860 From fuzzing until the whole developing through OLLI and getting our shellcode in there, 16 00:01:05,940 --> 00:01:13,340 and we'll see that we had to face all these nasty, nasty difficulties which took a little sleep, 17 00:01:13,500 --> 00:01:18,760 and a lack of sleep, and lots of trouble with the wives sort of thing. 18 00:01:19,740 --> 00:01:20,500 I love you. 19 00:01:24,460 --> 00:01:25,980 Okay, so I think... 20 00:01:27,520 --> 00:01:28,400 I think... 21 00:01:31,280 --> 00:01:33,940 We'll just drop straight into the demo. 22 00:01:34,060 --> 00:01:36,620 I think we might be a little tight on time. 23 00:01:37,280 --> 00:01:40,260 This is basically our OpenView NNM system, 24 00:01:41,240 --> 00:01:45,000 which we were encountering, we were actually fighting with this in a pen test. 25 00:01:45,260 --> 00:01:50,260 And what we decided to do at some stage when we noticed that there weren't any plausible attack vectors 26 00:01:50,260 --> 00:01:54,660 is to start prodding the zero day angle, seeing if we could find something, 27 00:01:54,720 --> 00:01:58,860 some low-hanging fruit that would eventually give us or compromise the system. 28 00:01:59,900 --> 00:02:05,240 So a quick port scan revealed that there's all sorts of funky services running on NNM, 29 00:02:05,300 --> 00:02:08,720 from SNMP services to HTTP services and everything. 30 00:02:09,100 --> 00:02:13,560 So we went for the lowest hanging fruit and we started bashing away at the HTTP service. 31 00:02:14,960 --> 00:02:18,280 And oddly enough, in less than 60 seconds, the thing blew up. 32 00:02:18,760 --> 00:02:23,920 So I'd like to show you the whole process, the development of the spike file that we 33 00:02:23,920 --> 00:02:26,220 used, which was ridiculously simple. 34 00:02:26,920 --> 00:02:27,440 And... 35 00:02:27,440 --> 00:02:43,340 And while I'm in the intros, I'd like to say no thanks to HP, which didn't even bother returning a mail after two calls and three mails telling them that they've got an unauthenticated overflow which could lead to a system compromise, and they never even bothered returning a mail. 36 00:02:43,340 --> 00:03:07,800 So, this exploit was actually published six months ago, and it never even received a CVE, so I've been having fun pawning HP machines while everyone's been ignoring this, so hopefully this will sort of raise some attention to the topic and people will actually patch their machines or at least disable this service, because this is actually quite popular. 37 00:03:09,120 --> 00:03:12,960 Alrighty, so the service that we'll be debugging today, or... 38 00:03:13,340 --> 00:03:17,560 observing, is the OVAS service. This is their main web server. 39 00:03:19,360 --> 00:03:26,920 And what we did is we started using a very simple sort of template. 40 00:03:27,340 --> 00:03:29,540 Is the mic on? Can you hear me at the back? 41 00:03:30,500 --> 00:03:31,340 Too far. 42 00:03:32,460 --> 00:03:32,760 Ah! 43 00:03:33,840 --> 00:03:34,440 Alrighty. 44 00:03:34,680 --> 00:03:43,220 So, basically, we took a very, very overly simplistic spike template, which we started throwing. 45 00:03:43,340 --> 00:03:46,720 We started throwing out the application, and I'd like to show you the results. 46 00:03:52,460 --> 00:04:01,040 Obviously, the wonderful thing about this is that we're all doing this on backtrack, so the whole process was self-contained into one sort of debugging session. 47 00:04:01,900 --> 00:04:04,020 So, if you look at the spike file... 48 00:04:14,180 --> 00:04:19,060 Then you'll see that we've got a pretty basic sort of, you know, template here. 49 00:04:19,340 --> 00:04:25,460 We're fuzzing just like a few host... a few headers, the host header, we're not even going to be doing the actual get request. 50 00:04:26,120 --> 00:04:30,380 I've sort of dumbed it down a bit so the fuzzing won't take too long during the demo. 51 00:04:31,020 --> 00:04:38,520 Hopefully, we'll be finding that our overflow is in the host header field, so let's just give that a quick run and see what happens to our NNM machine. 52 00:04:56,020 --> 00:05:06,720 So, we'll use the audit's SPK file, HTTP SPK file, and just by running this, what am I missing? 53 00:05:06,960 --> 00:05:07,380 Port. 54 00:05:11,920 --> 00:05:13,240 Just by running this... 55 00:05:13,240 --> 00:05:13,320 Just by running this... 56 00:05:13,320 --> 00:05:21,960 We can actually see that HP NNM is reacting, it's opening threads for each session, being battered away, and in exactly 20 seconds, the thing broke. 57 00:05:22,380 --> 00:05:31,720 So, we were very happy because we thought that this is going to be a stroll in the park, you know, we'll develop this exploit, get a root shell, get home, back in time for dinner. 58 00:05:32,940 --> 00:05:34,020 Little did we know. 59 00:05:34,360 --> 00:05:35,380 Little did we know. 60 00:05:35,520 --> 00:05:42,540 So, looking at this crash, we started poking around, and very soon we realized that this was a structure... 61 00:05:42,540 --> 00:05:44,320 A structured exception handler crash. 62 00:05:44,680 --> 00:05:48,320 I can actually replicate this with a standalone Python script. 63 00:05:48,600 --> 00:05:55,100 It took us a couple of tries, you know, playing around with the buffer lengths just to see that everything was as anticipated. 64 00:06:00,180 --> 00:06:11,920 So, looking at the proof of concept, or standalone skeleton exploit, as I call them, basically what we've got here is a get request with a very, very long... 65 00:06:11,920 --> 00:06:15,340 An ugly host header, and this is where our crash comes out. 66 00:06:16,000 --> 00:06:18,900 And apart from that, everything is pretty much as usual. 67 00:06:19,000 --> 00:06:27,560 There's nothing fancy or interesting about this get request, apart from, again, this host header, which is taking around 4,000 bytes of buffer. 68 00:06:28,560 --> 00:06:31,180 So, we slammed this against our NNM machine. 69 00:06:34,700 --> 00:06:36,940 Yeah, we probably should have the debugger there. 70 00:06:50,300 --> 00:06:57,240 And we'll take the OVAS process and let it live. 71 00:06:58,840 --> 00:07:07,180 And hitting the OpenView service with our script, this is actually a bit freaky, because it takes it a few seconds to crash. 72 00:07:07,460 --> 00:07:10,300 What we'll see is that we own all these wonderful registers. 73 00:07:10,880 --> 00:07:11,900 We own a bit of everything. 74 00:07:11,900 --> 00:07:12,340 We own a bit of the stack. 75 00:07:12,840 --> 00:07:17,560 And possibly the best part of this whole thing is that we own the structured exception handler. 76 00:07:18,720 --> 00:07:23,500 Now, usually what we'd want to do in a situation like this is allow the exception to occur. 77 00:07:23,780 --> 00:07:26,520 So, I'll just simulate that by pressing Shift-F9. 78 00:07:28,140 --> 00:07:31,120 And here we have EIP, which is all ours. 79 00:07:31,240 --> 00:07:32,940 So, we're all happy and giddy about this. 80 00:07:33,040 --> 00:07:41,380 And, yes, we're going to own this thing in 30 seconds, because all we need to do now, as you usually do in structured exception handler overwrites, 81 00:07:41,900 --> 00:07:46,540 is you need to find a nice place that contains a pop-pop-ret instruction. 82 00:07:46,980 --> 00:07:49,120 And that will basically bring us right here. 83 00:07:49,700 --> 00:07:55,380 So, the rest of our buffer, which is usually where we'd shove our shellcode in, would be right here. 84 00:07:55,760 --> 00:08:01,900 Now, notice that we are pointed to four bytes before our value that overwrites EIP. 85 00:08:02,520 --> 00:08:11,000 And usually what you do in a standard structured exception handler exploit is use these four bytes to jump over this address so we don't actually execute these bytes. 86 00:08:11,000 --> 00:08:13,640 And then here you'd be putting your bind or reverse shell. 87 00:08:15,880 --> 00:08:22,160 If we look at this a bit further, we'll see that we've got around 400 or 500 bytes for shellcode, which is usually enough. 88 00:08:22,460 --> 00:08:29,100 I mean, you could probably get away with a reverse shell of 350, 400 bytes, unless you need to start encoding it. 89 00:08:31,040 --> 00:08:39,160 So, the first thing we did, all happy and joyous, is look for a pop-pop-ret command to get us back to our buffer. 90 00:08:41,000 --> 00:08:44,380 And this is where things started to get really, really ugly. 91 00:08:45,780 --> 00:08:56,020 We found an address in one of the HP DLLs, which obviously isn't compiled with safe SCH or GS or anything, it's just out there. 92 00:08:58,720 --> 00:09:02,440 So, looking for the first address, I think I might still have it here in OLLI. 93 00:09:04,480 --> 00:09:04,960 Yes. 94 00:09:05,180 --> 00:09:10,980 So, we found this address, which indeed contains a pop-pop-ret command. 95 00:09:10,980 --> 00:09:15,620 command. Now just take note of these values here, because this is going to play an interesting 96 00:09:15,620 --> 00:09:22,980 part in the next few minutes. So essentially what we'd like to do is go to our proof-of-concept 97 00:09:22,980 --> 00:09:30,280 exploit and change these 42 bytes into our address that will lead us to our pop-up ret. 98 00:09:30,880 --> 00:09:38,620 So we did this, and we just took that wonderful address, shoved it here, and it's padding 99 00:09:38,620 --> 00:09:43,740 just at the right place. Okay, I skipped a few steps of finding the right place in the 100 00:09:43,740 --> 00:09:48,160 buffer, etc. That's not what we want to deal with today. We're going to look at the harder 101 00:09:48,160 --> 00:09:50,020 aspects of developing this exploit. 102 00:09:51,300 --> 00:09:54,520 So we send this, and let's see what happens. 103 00:10:02,700 --> 00:10:08,600 Oh. Okay, now apparently the actual overflow is in the HP mechanism of fill-in, and that's 104 00:10:08,620 --> 00:10:12,180 filtering URLs and logging them, which is actually quite common. 105 00:10:12,680 --> 00:10:19,540 So once again, we've got our structured exception handler, which catches the error, but something 106 00:10:19,540 --> 00:10:24,840 is wrong here. Take a look at this. I'll show you what the original value should have been 107 00:10:25,480 --> 00:10:27,060 and what it ended up as. 108 00:10:31,460 --> 00:10:38,600 So the original value should have been 5A02EF74. And what we got here is that we've got a 109 00:10:38,620 --> 00:10:44,620 buffer. Well, I see a 02 and I see a 74, but something has gone wrong here. So we 110 00:10:44,620 --> 00:10:48,780 tried this a few times, thinking that we did something wrong, but essentially at the 111 00:10:48,780 --> 00:10:54,900 end what we realized is when we looked at the actual placement of our buffer on the 112 00:10:54,900 --> 00:10:59,420 exception handler, we saw something funky here. I'm not sure if you can see it over 113 00:10:59,420 --> 00:11:07,760 there at the back, but it looks like something expanded. Do you see that 5A right here? 114 00:11:08,620 --> 00:11:13,160 That 5A should have been the first thing to overwrite our address. 115 00:11:14,600 --> 00:11:20,220 We can see our 5A here. Let me just show you the original address. We can see our 5A. 116 00:11:22,000 --> 00:11:32,720 We can see our 02. And it looks like our EF has been mangled, because 74 is here. So 117 00:11:32,720 --> 00:11:36,760 EF was basically transformed to, what is it? AFC something. 118 00:11:36,760 --> 00:11:48,040 And that is when we understood that we're screwed, because what's going on here is some sort of translation or expansion of bytes, which are not alphanumeric. 119 00:11:48,640 --> 00:11:56,860 So suddenly we had this alphanumeric cloud over our head, and we realized that we'll need to do some encoding on our shellcode. 120 00:11:57,000 --> 00:12:01,800 Now, Metasploit actually contains a couple of really, really good alphanumeric encoders. 121 00:12:01,800 --> 00:12:09,460 So we thought that, you know, okay, so this isn't such a big deal, we'll just simply encode it with Metasploit and everything will be done with. 122 00:12:11,080 --> 00:12:21,600 So the next step was to find a nice alphanumeric return address that wouldn't be mangled after sent or after accepted by NNM. 123 00:12:21,800 --> 00:12:25,260 So we dug in a bit deeper, and this is what we found. 124 00:12:33,720 --> 00:12:39,940 All right, so this is the address, again, somewhere in NNM, one of the DLLs, lots of them to look for. 125 00:12:50,580 --> 00:12:57,180 And we'll, once again, slam our NNM server and wait patiently for the crash. 126 00:12:57,540 --> 00:13:01,780 This actually freaked me out yesterday, because I was sending the buffer and waiting for a couple of minutes. 127 00:13:01,800 --> 00:13:06,740 I thought everything had gone to hell, but thankfully it stayed. 128 00:13:08,240 --> 00:13:11,380 So, once again, we've got our structured exception handler. 129 00:13:11,480 --> 00:13:12,340 This address is good. 130 00:13:12,440 --> 00:13:18,860 This address does not get mangled in any way, and this will directly lead us to a pop-up ret instruction set. 131 00:13:19,000 --> 00:13:21,160 So I'll allow the exception to occur. 132 00:13:21,400 --> 00:13:22,700 I'll press Shift-F9. 133 00:13:22,900 --> 00:13:25,800 I'm taken to a pop-pop ret. 134 00:13:25,920 --> 00:13:28,000 Now, notice what happens here on our stack. 135 00:13:28,240 --> 00:13:30,940 We pop one, we pop one, and then we return. 136 00:13:31,300 --> 00:13:31,780 We return. 137 00:13:31,800 --> 00:13:33,260 Now, back to our buffer. 138 00:13:33,360 --> 00:13:37,640 So if we follow this and dump, these are the exact bytes that we're jumping to, 139 00:13:37,760 --> 00:13:42,000 and these are the exact bytes that constitute our return address. 140 00:13:42,420 --> 00:13:49,600 So we take the jump, and usually what we do here is we take a short jump over the return address and put our shellcode here. 141 00:13:49,840 --> 00:13:58,240 Now, a short jump would be an EB something, EB10, for example. 142 00:13:58,540 --> 00:14:01,780 And that would just very, very conveniently take us. 143 00:14:01,800 --> 00:14:01,960 It's there. 144 00:14:02,980 --> 00:14:07,500 But then we realize that EB is not in our allowed instruction set. 145 00:14:07,600 --> 00:14:13,780 In fact, we're only allowed a very limited instruction set, a limited range of bytes that we can use. 146 00:14:13,980 --> 00:14:17,140 I think I've got it somewhere here just to give you a bit of reference. 147 00:14:21,760 --> 00:14:22,520 All righty. 148 00:14:22,520 --> 00:14:25,540 So you can see that this thing isn't pure alphanumeric. 149 00:14:25,600 --> 00:14:30,400 I mean, you've got some of these bytes here, but it is a very limited instruction set, 150 00:14:30,440 --> 00:14:31,520 and we can't just do... 151 00:14:31,800 --> 00:14:33,340 You know, we can't even have our short jump. 152 00:14:33,380 --> 00:14:34,360 We can't even use EB. 153 00:14:34,780 --> 00:14:36,920 So this is where things got really, really hairy, 154 00:14:37,060 --> 00:14:41,580 and we had to think sort of very, very hard on how to do this. 155 00:14:41,980 --> 00:14:48,020 So after bashing our heads a bit, we realized that we might try to use a conditional jump, 156 00:14:48,920 --> 00:14:51,060 something like a jump zero, jump not zero. 157 00:14:51,160 --> 00:14:55,380 We just need to make sure that our zero flags are set and that jump would always be taken. 158 00:14:55,720 --> 00:14:59,680 Otherwise, these instructions will actually kill our exploit. 159 00:15:01,280 --> 00:15:08,040 So in the end, what we ended up doing here is giving a conditional jump, 160 00:15:09,500 --> 00:15:13,980 and we have to make sure that each and every time that this exploit is sent, 161 00:15:14,120 --> 00:15:15,900 that condition will always happen. 162 00:15:15,960 --> 00:15:17,580 Otherwise, we screw our exploit. 163 00:15:18,920 --> 00:15:21,000 So we've got our zero flag here. 164 00:15:21,220 --> 00:15:25,900 The jump not zero is taken, and that should take us across our return address 165 00:15:25,900 --> 00:15:28,300 and into the safe zone of our buffer. 166 00:15:28,620 --> 00:15:29,640 So we'll take that. 167 00:15:29,640 --> 00:15:29,840 That jump. 168 00:15:31,300 --> 00:15:32,400 And here we are. 169 00:15:32,600 --> 00:15:32,980 Okay? 170 00:15:33,520 --> 00:15:37,400 And from here onwards, we're free to write around 400 bytes of shellcode. 171 00:15:38,420 --> 00:15:41,200 So the first thing we do is go to the Metasploit framework, 172 00:15:41,520 --> 00:15:45,160 generate some alphanumeric shellcode, and something looks wrong 173 00:15:46,420 --> 00:15:50,820 because you'll notice that the actual encoder, 174 00:15:51,380 --> 00:15:54,920 it doesn't matter which one you use, either the alpha 2 or the pex alphanum, 175 00:15:55,060 --> 00:15:59,620 will actually contain some characters which are not alphanumeric. 176 00:15:59,640 --> 00:16:04,020 And this is a problem because, you know, looking at this, you say, 177 00:16:04,080 --> 00:16:06,740 well, okay, it doesn't matter that this is the decoder. 178 00:16:07,340 --> 00:16:11,080 It still contains a byte which will screw up our shellcode. 179 00:16:11,160 --> 00:16:12,000 We cannot have this. 180 00:16:12,120 --> 00:16:16,720 And then the very, very sad realization that Metasploit will no longer help us 181 00:16:16,720 --> 00:16:18,140 and we need to do something custom. 182 00:16:18,980 --> 00:16:21,400 And that is when things really, really got ugly. 183 00:16:22,240 --> 00:16:26,540 Because, you know, at some stage, you just get so used to using Metasploit, 184 00:16:26,540 --> 00:16:28,680 you forget how to do the basics. 185 00:16:28,720 --> 00:16:29,600 And this is... 186 00:16:29,640 --> 00:16:31,680 This is like the first time we actually got slapped around 187 00:16:31,680 --> 00:16:34,800 and forced to do some ugly stuff. 188 00:16:36,280 --> 00:16:43,080 Luckily for me, I saw this article about Venetian shellcode, 189 00:16:43,160 --> 00:16:46,980 and I got this interesting idea there that came up to me. 190 00:16:47,060 --> 00:16:48,740 And I said, maybe we can use that technique 191 00:16:48,740 --> 00:16:52,380 in order to write our own alphanumeric shellcode here. 192 00:16:52,600 --> 00:16:57,600 Now, the other problem that we have is that we only have around 400 bytes of space. 193 00:16:57,760 --> 00:16:59,460 Now, if we want to have a reverse, 194 00:16:59,520 --> 00:16:59,620 we want to have a reverse shellcode. 195 00:16:59,620 --> 00:17:03,060 A reverse shell or a bind shell, that's around, I don't know, 250, 300 bytes. 196 00:17:03,260 --> 00:17:06,640 And if we want to encode that, you're at least doubling that. 197 00:17:07,300 --> 00:17:14,380 So there's no way that our original space for our shellcode could cover all of that. 198 00:17:14,880 --> 00:17:17,920 And then we think, okay, so maybe we need a smaller payload, 199 00:17:18,640 --> 00:17:23,360 something like an egg hunter that could look for a second larger payload in memory. 200 00:17:23,500 --> 00:17:26,880 And we'd have to figure out a way of getting the second payload into memory 201 00:17:26,880 --> 00:17:29,280 and then the first payload. 202 00:17:29,280 --> 00:17:33,000 The egg hunter would actually search safely through the address space 203 00:17:33,000 --> 00:17:38,660 and find our final payload and give us a bind or reverse shell, whatever it is. 204 00:17:40,600 --> 00:17:45,620 Yes, it did get hairy, because now what that means is that we need to encode, 205 00:17:45,620 --> 00:17:49,420 manually encode, 32 bytes of egg hunter code. 206 00:17:49,640 --> 00:17:53,020 The egg hunter that we used was one of Matt Miller's creations. 207 00:17:53,160 --> 00:17:54,840 Amazing stuff, really, really. 208 00:17:56,340 --> 00:17:58,480 32 bytes of magic, if you ask me. 209 00:17:59,280 --> 00:18:01,680 So let's just take some reference. 210 00:18:01,880 --> 00:18:05,260 Take a while to look at the egg hunter shellcode itself. 211 00:18:05,900 --> 00:18:14,300 The egg, or that signature that the egg hunter will be looking for, is WOOT, W-0-0-T, all in capitals. 212 00:18:14,560 --> 00:18:19,040 And you can actually see the egg right here inside the assembly code. 213 00:18:19,180 --> 00:18:22,360 If anyone's interested in seeing the actual code, then come to me later. 214 00:18:22,360 --> 00:18:27,480 I'll show you the article by Matt Miller and give you some code examples. 215 00:18:27,920 --> 00:18:28,980 But essentially... 216 00:18:29,280 --> 00:18:34,320 See, these are the bytes that we'll need to write and encode manually. 217 00:18:38,500 --> 00:18:46,940 So, the technique that was mentioned in the Venetian shellcode article basically said that 218 00:18:47,620 --> 00:18:53,400 the right way to, or the easiest way to get past the alphanumeric situation 219 00:18:53,400 --> 00:18:57,380 is to actually carve our own shellcode in memory, in real time. 220 00:18:57,600 --> 00:18:58,560 And very... 221 00:18:59,280 --> 00:19:05,120 Elegantly place it onto the stack in a place where we anticipate that execution will reach. 222 00:19:05,940 --> 00:19:08,520 This sounds much more complex than it actually is. 223 00:19:08,640 --> 00:19:10,560 I think it's much easier to see this in action. 224 00:19:10,820 --> 00:19:17,460 So what I'll be doing now is I'll be writing the shellcode in OLLI and explaining each line, what it does. 225 00:19:36,080 --> 00:19:38,840 So that's the first part of the shellcode. 226 00:19:39,040 --> 00:19:41,560 And it's actually not too complex. 227 00:19:41,760 --> 00:19:46,820 Notice that the shellcode is composed of really, really basic instructions. 228 00:19:47,460 --> 00:19:51,540 And all the characters, all the opcodes, are allowed. 229 00:19:51,820 --> 00:19:58,800 So basically we're limited to things like add, sub, push, pop, and a few others. 230 00:19:58,940 --> 00:19:59,940 But that's pretty much it. 231 00:20:00,020 --> 00:20:06,000 And that is the instruction set that we have to start carving our shellcode in memory. 232 00:20:07,180 --> 00:20:11,180 We'll be using EAX for several calculations. 233 00:20:11,420 --> 00:20:13,720 So the first part of the shellcode basically says, 234 00:20:13,940 --> 00:20:17,300 whatever you have in EAX, zero it. 235 00:20:17,460 --> 00:20:18,360 Zero it out. 236 00:20:18,900 --> 00:20:25,260 So EAX is zero already, but let me just shove some values here so you can actually see the process happening. 237 00:20:25,860 --> 00:20:29,500 And we'll step that and step that. 238 00:20:29,900 --> 00:20:35,140 So EAX is now zero, and I know that all my calculations are beginning from a clean slate. 239 00:20:36,560 --> 00:20:40,300 The next thing I do is I want to locate my position in the stack. 240 00:20:40,500 --> 00:20:45,520 Because if I will be carving out shellcode on the stack, I need to know where it's carved. 241 00:20:45,660 --> 00:20:47,360 And I need to carve it in a place. 242 00:20:47,460 --> 00:20:51,340 A place where execution will reach after my first state shellcode. 243 00:20:51,740 --> 00:20:56,760 So looking at the actual memory dump, 244 00:20:59,660 --> 00:21:05,560 we would probably want to write our 32 bytes of egg hunter around here. 245 00:21:06,140 --> 00:21:10,520 So in order to do that, we need to find our current location in the stack. 246 00:21:10,740 --> 00:21:16,980 And we can do this by using a really cool trick by pushing ESP, the stack pointer, to the top of our stack. 247 00:21:17,460 --> 00:21:18,960 And then popping it to EAX. 248 00:21:19,180 --> 00:21:24,800 So now EAX actually holds the value of ESP, and we can start doing calculations on EAX. 249 00:21:25,840 --> 00:21:32,200 The next three lines basically align the stack to exactly the place that we want to write our shellcode. 250 00:21:33,600 --> 00:21:39,860 This is actually an interesting calculation, because if we take this, that, and the other command, 251 00:21:40,100 --> 00:21:45,280 then EAX should now be pointing to exactly this area. 252 00:21:45,620 --> 00:21:47,440 So our stack is aligned to exactly this area. 253 00:21:47,440 --> 00:21:49,720 It's aligned to the place that we want to write our shellcode. 254 00:21:51,100 --> 00:21:58,620 Now that we've got that in place, we actually write the egg hunter shellcode once again using the sub and add commands. 255 00:21:59,100 --> 00:22:02,840 So just take a look at the rest of the shellcode and see what that looks like. 256 00:22:18,980 --> 00:22:23,300 Alright, so these were the first instructions that we gave. 257 00:22:25,100 --> 00:22:26,760 Did our desktop just die? 258 00:22:36,260 --> 00:22:38,460 These were the first instructions that we gave. 259 00:22:39,700 --> 00:22:47,420 And now, once again, we zero out EAX in order to start writing and carding our shellcode. 260 00:22:47,440 --> 00:22:55,660 And just again, just to make sure that you've seen that, notice these last four bytes of our egg hunter. 261 00:22:55,840 --> 00:22:58,500 These will be the first four bytes that we write in memory. 262 00:23:03,020 --> 00:23:03,980 So, E7FFE775. 263 00:23:04,840 --> 00:23:06,220 We'll do some calculations. 264 00:23:06,500 --> 00:23:13,840 We'll work on EAX, subtract these two values, and look at the value that we have in EAX right now. 265 00:23:18,940 --> 00:23:20,880 Let me just get it to the right place. 266 00:23:26,740 --> 00:23:27,600 Do you see that? 267 00:23:27,900 --> 00:23:32,860 That's my 75, that's my E7, that's my FF, and that's my E7. 268 00:23:33,820 --> 00:23:36,360 So I've got that value on the stack now. 269 00:23:36,460 --> 00:23:42,840 And what I'm about to do is I'm going to push it to the exact place where I had it aligned to before. 270 00:23:43,100 --> 00:23:44,240 So we'll push that. 271 00:23:44,400 --> 00:23:47,420 And you should see the last four bytes of the egg hunter. 272 00:23:47,440 --> 00:23:49,240 The last four bytes of the egg hunter written to the stack. 273 00:23:50,040 --> 00:23:51,720 Oh, that ran a bit too fast. 274 00:23:53,960 --> 00:23:56,060 Okay, I've already written two lines. 275 00:23:56,240 --> 00:23:59,120 Let's do that again, just so you can see it happening in real time. 276 00:24:09,980 --> 00:24:10,780 Feel the love. 277 00:24:11,740 --> 00:24:13,640 All right, we'll crash it once again. 278 00:24:23,260 --> 00:24:24,520 We'll take the jump. 279 00:24:25,480 --> 00:24:26,940 We'll pop operet it. 280 00:24:28,560 --> 00:24:37,720 We'll gently jump over our return address. 281 00:24:39,580 --> 00:24:42,740 And we'll paste the beginning of our shellcode. 282 00:24:50,540 --> 00:24:51,100 Great. 283 00:24:52,240 --> 00:24:55,580 So once again, we zero out EAX. 284 00:24:55,780 --> 00:24:59,760 We find the location of where we are on the stack. 285 00:24:59,960 --> 00:25:03,920 We align our stack to where we want to carve our shellcode. 286 00:25:04,780 --> 00:25:07,620 And now we start writing the shellcode. 287 00:25:09,140 --> 00:25:09,700 . 288 00:25:18,920 --> 00:25:22,580 All right, so again, the first two lines, zero out EAX. 289 00:25:28,240 --> 00:25:36,060 These are the last four bytes of our shellcode, of our egg hunter shellcode. 290 00:25:36,200 --> 00:25:39,460 We push these onto the stack, and there you have them. 291 00:25:40,320 --> 00:25:44,200 And then we continue, and then we zero out EAX once again, 292 00:25:45,200 --> 00:25:50,960 and we write the next four bytes, and we push them onto the stack. 293 00:25:52,360 --> 00:25:58,880 And again, zero out EAX, and we keep on doing this with all the 32 bytes of our egg hunter, 294 00:25:58,980 --> 00:26:04,120 and slowly our egg hunter materializes just at the end of our buffer. 295 00:26:04,980 --> 00:26:09,120 Once again, zero out EAX, do the calculations for the next route, 296 00:26:09,120 --> 00:26:11,160 push it onto the stack, and so on. 297 00:26:11,760 --> 00:26:14,140 Now, where exactly are we pushing this stuff? 298 00:26:14,300 --> 00:26:18,800 Because once this loop finishes, and I've pushed all my 32 bytes onto the stack, 299 00:26:19,560 --> 00:26:25,020 well, it was aligned in such a way that as I continue the code execution, 300 00:26:26,220 --> 00:26:28,920 I will actually meet my egg hunter. 301 00:26:30,220 --> 00:26:34,040 And from here on, basically what happens is that the egg hunter kicks in 302 00:26:34,040 --> 00:26:38,800 and starts looking for the final payload, which is a bind or reverse shell. 303 00:26:40,360 --> 00:26:41,460 So let's do that. 304 00:26:41,520 --> 00:26:44,920 Let's take all these modifications, let's put them in a script, run it, 305 00:26:44,980 --> 00:26:49,740 and see how the exploit works, and also look at the egg hunter in action, 306 00:26:49,840 --> 00:26:52,740 because this is probably one of the nicest pieces of assembly 307 00:26:52,740 --> 00:26:55,880 that you could ever use in an exploit like this. 308 00:26:57,300 --> 00:27:00,340 We also had another problem, which I didn't mention. 309 00:27:02,260 --> 00:27:08,860 Where do we put this large payload, this large, I don't know, 600, 700 byte payload 310 00:27:08,860 --> 00:27:09,100 of our exploit? 311 00:27:09,100 --> 00:27:10,420 Of a bind or reverse shell. 312 00:27:12,140 --> 00:27:16,840 So mucking around with the NNM service, 313 00:27:17,040 --> 00:27:19,440 we actually saw that if we append 314 00:27:21,980 --> 00:27:27,420 an unlimited amount of data at the end of our HTTP request, 315 00:27:27,820 --> 00:27:31,900 that wouldn't actually be affected by the OV filter, 316 00:27:32,120 --> 00:27:36,180 and we wouldn't be getting any bad characters, and nothing would be mangled. 317 00:27:36,280 --> 00:27:38,460 So this is an ideal place to put, 318 00:27:38,460 --> 00:27:41,040 even 1,500 bytes of shellcode. 319 00:27:41,700 --> 00:27:45,880 So that is where our second state shellcode will reach. 320 00:27:46,200 --> 00:27:48,380 And don't forget, as always with an egg hunter, 321 00:27:48,500 --> 00:27:51,660 we always need to have that signature, that egg, 322 00:27:52,130 --> 00:27:55,880 that the egg hunter will know to identify and act upon once it sees it. 323 00:27:57,120 --> 00:28:00,180 So let me run this final working exploit 324 00:28:00,180 --> 00:28:08,440 and show you how we actually got to execute code on NNM. 325 00:28:11,380 --> 00:28:13,040 How are we doing with time? 326 00:28:16,400 --> 00:28:17,300 All righty. 327 00:28:18,520 --> 00:28:22,040 So we hit NNM once again. 328 00:28:22,140 --> 00:28:26,300 Same sort of idea, the structured exception handler. 329 00:28:28,380 --> 00:28:29,700 Yeah, it has to kick in. 330 00:28:34,300 --> 00:28:37,520 We've got our wonderful, friendly return address. 331 00:28:38,460 --> 00:28:41,340 We take the jump, we pop, pop, ret. 332 00:28:42,260 --> 00:28:47,040 We do the funky jump over the return address. 333 00:28:49,180 --> 00:28:51,460 Ugh, I wanted to do something with that. 334 00:28:51,500 --> 00:28:51,980 Hold on. 335 00:28:52,360 --> 00:28:52,860 Sorry. 336 00:28:54,620 --> 00:28:55,120 Sorry. 337 00:29:07,580 --> 00:29:08,140 I should go back. 338 00:29:08,140 --> 00:29:08,260 So we hit it. 339 00:29:08,260 --> 00:29:12,140 once again crashing it, structured exception handler kicks in. 340 00:29:13,580 --> 00:29:16,660 We take the jump, take the pop, pop, ret. 341 00:29:20,260 --> 00:29:22,260 Jump over our return address. 342 00:29:22,640 --> 00:29:25,040 And right here, I'd like to make a tiny, 343 00:29:25,040 --> 00:29:29,680 change just so any future changes are actually seen in OLLI better. We'll get 344 00:29:29,680 --> 00:29:34,880 this red highlight than just normal highlighting. So let's start 345 00:29:34,880 --> 00:29:42,020 walking through and see what happens. Once again EAX gets zeroed out. We push 346 00:29:42,020 --> 00:29:49,060 our stack location into EAX. We do some calculations on it. We align our 347 00:29:49,060 --> 00:29:54,880 stack to where we want to write our egg hunter payload, and then we start 348 00:29:54,880 --> 00:29:57,460 writing the egg hunters so ESP 349 00:30:02,900 --> 00:30:05,600 starts decoding our egg hunter shellcode 350 00:30:10,220 --> 00:30:17,880 and we end up meeting it. Now our egg hunter will look for 351 00:30:18,400 --> 00:30:19,040 coordinates on the полез.cipe.pl stack. We've said we don't need these, 352 00:30:19,040 --> 00:30:25,840 instances of Woot, capital W, zero, zero, capital T. And once it finds two of these 353 00:30:25,840 --> 00:30:33,720 in a row, it will assume that our shellcode is right after that. So what we'll do is let's 354 00:30:33,720 --> 00:30:40,880 put a couple of breakpoints in these instructions. This is basically the command that looks for 355 00:30:40,880 --> 00:30:45,900 the first instance of Woot. If that is found, then we look for another instance of Woot, 356 00:30:45,900 --> 00:30:52,580 and if that is found, we jump to the location that comes immediately after that, i.e., our 357 00:30:52,580 --> 00:30:58,720 shellcode. So let's give that a run, and we hit our first breakpoint. It's currently looking 358 00:30:58,720 --> 00:31:05,360 at this memory address, looking for these bytes, W, zero, zero, T, or the other way 359 00:31:05,360 --> 00:31:11,600 around. Okay, not here, go back, search again. Not here, go back, search again. And you can 360 00:31:11,600 --> 00:31:15,880 actually see EDX is the main counter used to search. 361 00:31:15,900 --> 00:31:20,380 Search through memory. Okay, this could take a really, really long time because we'll be, 362 00:31:20,480 --> 00:31:26,760 we might be looking through four gigs of RAM, which is, you know, a lot. So let's skip 363 00:31:26,760 --> 00:31:33,680 this breakpoint and ask the egg hunter to stop and show us what's going on after the 364 00:31:33,680 --> 00:31:37,560 first Woot has been identified. So we'll let that run. 365 00:31:46,020 --> 00:31:55,480 This could take some time. Nice seeing you all. You want to entertain them, Chris? 366 00:31:56,040 --> 00:31:56,520 No. 367 00:31:56,900 --> 00:31:57,060 No. 368 00:32:04,000 --> 00:32:05,340 Puke goes that way. 369 00:32:05,580 --> 00:32:06,780 Puke goes that way. 370 00:32:06,960 --> 00:32:07,280 Yes. 371 00:32:09,160 --> 00:32:15,580 Okay, Oli actually does add a lot of overhead to these type of things. You'll notice that when we run 372 00:32:15,580 --> 00:32:15,880 this, we're going to have a lot of overhead. So we're going to have a lot of overhead. So we're going to have a lot of overhead. 373 00:32:15,880 --> 00:32:21,720 Without Oli, it shouldn't take more than 10 seconds, but those are probably the most beautiful 374 00:32:21,720 --> 00:32:29,680 10 seconds that computer has ever seen because basically it's pawning itself. So we've hit our 375 00:32:29,680 --> 00:32:35,220 second breakpoint. Let's just take a look what EDI holds. And look at that. It's holding our 376 00:32:35,220 --> 00:32:43,640 first Woot. If we follow this memory space, look at that. That's our second Woot. That was our 377 00:32:43,640 --> 00:32:45,500 first Woot. And this? 378 00:32:45,880 --> 00:33:14,380 This is your standard bind shellcode, if I remember correctly. Okay, so let's see what happens now. The jump to continue running the egg hunter is not taken. And the next instruction that we're going to hit is jump EDI. Now, what do we have in EDI? Once again, we have a nice, unadulterated bind shell. So let's take the jump. 379 00:33:15,880 --> 00:33:44,080 And this bind shell, just in case, was encoded using the alphanumeric metasploit encoder. Even though we didn't really have to, we just thought it might be safer. If everything is sort of alphanumeric-ish, then what the hell, why don't we have the shellcode that way as well? So basically what we see now is the bind shell decoding. 380 00:33:45,880 --> 00:34:15,860 And this is actually very pretty to watch. If you look from here onwards, you'll actually see the bind shell decode in real time. So we'll single step and just look at that CLD and below. And you see that? That's like raw bind shell decoded. And this happens really, really quickly. So let's allow our bind shell to completely decode. I'll put a breakpoint here. And then we'll see what happens. 381 00:34:15,880 --> 00:34:28,540 at the beginning and in theory we have nothing listening on port four four four 382 00:34:28,540 --> 00:34:39,200 four right now if we now let this bind shell run we've got a shell 383 00:34:51,160 --> 00:35:01,580 so just to have like you know the meat and everything will do that and that's actually 384 00:35:01,580 --> 00:35:09,300 interesting we won't go into that right now what I'd like to show you though is what I'd like to 385 00:35:09,300 --> 00:35:14,300 show you is the actual exploit running in real time so you can get an estimate of how long the 386 00:35:14,300 --> 00:35:15,040 egg hunter does 387 00:35:15,880 --> 00:35:21,240 search through endless amounts of memory space and obviously also look at the process shooting 388 00:35:21,240 --> 00:35:26,100 up to 100% which again is probably you know the nicest part of this whole thing is that the 389 00:35:26,100 --> 00:35:30,840 machine is literally hacking itself because what you've done is you said well I've got a buffer 390 00:35:30,840 --> 00:35:36,520 somewhere it's got a shell code it's got a bind shell look for it and when you find it execute 391 00:35:36,520 --> 00:35:42,980 it and make me some coffee while you're at it sort of thing alrighty so 392 00:35:47,560 --> 00:36:00,280 what do we want how do you get to the task manager thing backtrack ah yes that's the one 393 00:36:03,880 --> 00:36:11,980 all right so so what's this little box right here as the as the machine gets hacked 394 00:36:19,060 --> 00:36:22,480 already so we'll send our final payload 395 00:36:24,740 --> 00:36:30,400 look at that oh come on you can do it I think I can I think I can it's probably taking some 396 00:36:30,400 --> 00:36:35,280 time to crash there you go egg hunter working machine is in pain screaming 397 00:36:38,460 --> 00:36:45,740 will probably be done a bit earlier and you know exactly when to look for the shell right 398 00:36:48,940 --> 00:36:51,200 the machine is so slow it's actually 399 00:36:51,200 --> 00:36:52,880 delaying the output of netstat 400 00:36:52,880 --> 00:36:54,780 give me a second I'll have it there 401 00:36:54,780 --> 00:36:55,440 just a sec 402 00:37:03,280 --> 00:37:04,220 isn't that beautiful 403 00:37:04,220 --> 00:37:09,180 alright so the shellcode 404 00:37:09,180 --> 00:37:10,920 the egg hunter looks like it's 405 00:37:10,920 --> 00:37:12,920 calmed down which would probably indicate 406 00:37:12,920 --> 00:37:13,960 that we've got our shell 407 00:37:23,320 --> 00:37:25,140 so just to kill 408 00:37:25,140 --> 00:37:27,220 some time last night this wasn't working 409 00:37:27,220 --> 00:37:29,200 I had the whole offset of the shellcode 410 00:37:29,200 --> 00:37:31,100 wrong and Chris takes me to 411 00:37:31,100 --> 00:37:31,340 drink 412 00:37:31,340 --> 00:37:34,440 thank you Chris thank you 413 00:37:34,440 --> 00:37:36,800 he planned an offset party last night 414 00:37:36,800 --> 00:37:38,800 yeah I sound like the godfather 415 00:37:38,800 --> 00:37:40,960 alright guys thank you very 416 00:37:40,960 --> 00:37:42,920 very much for coming thanks for the support 417 00:37:42,920 --> 00:37:43,500 applause 418 00:37:43,500 --> 00:37:43,940 applause 419 00:37:43,960 --> 00:37:44,720 applause