1 00:00:12,280 --> 00:00:23,960 Parts, not very technical, it's just kind of, I'm going to make some points about how you can abstractify your payload and separate it from your injection vector, and I'll cover some stuff in that, it's kind of interesting. 2 00:00:23,960 --> 00:00:40,400 The second part of the talk has towards the middle, I'm going to talk about injection vectors, which is how to get control of the instruction pointer on a target system, and there's a lot of little tricks to do that, and then finally the last part will be payload, which is of course the funnest, you know, all the nasty things you can do once you're on the system. 3 00:00:42,460 --> 00:00:52,780 I'd like to thank Ryan Russell, I don't know if he's here, but he recently busted his ass to get this book printed, and I believe they have copies of it here, about a hundred or so. 4 00:00:52,780 --> 00:01:11,660 I wrote chapter 8, which is specifically on buffer overflows, the name of the book is Hackproofing Your Network, RFP's in here, Elias from BugTrack, Cesar, if you know Riley, Cesar, he's pretty cool, he's in here too, talking about stuff, Jeremy Roche, there's a lot of good authors in this book. 5 00:01:12,300 --> 00:01:20,320 So anyways, if you want to come up after the talk, I can give you the ISB number or whatever, or you can go find the security focus guys, and they should have a copy of it up there. 6 00:01:23,680 --> 00:01:26,400 Oh, the question was, who's the publisher? 7 00:01:27,960 --> 00:01:28,400 Singris. 8 00:01:30,840 --> 00:01:48,780 Okay, so, these slides are not posted, I can post them, I believe that Jeff has probably already got something set up on the website to post them, as well as this entire audio and video feeds are all, of course, posted as well, so you should be able to get to this. 9 00:01:49,540 --> 00:01:52,220 Okay, so this talk is going to talk about some... 10 00:01:52,880 --> 00:01:53,780 Some ideas here. 11 00:01:53,860 --> 00:01:55,500 Our first one is formalizing your attack method. 12 00:01:56,980 --> 00:02:10,360 So I'm going to talk kind of like a military person for a little while, and talk about, if you were like a military organization, how you would design your cyber warfare group to take advantage of buffer overflows and payloads, and how you can reuse your attack code. 13 00:02:11,320 --> 00:02:16,840 You can have a group of goons over here doing something like building a bunch of payloads, kind of like a missile with a warhead. 14 00:02:17,020 --> 00:02:22,700 You don't have to always send a nuclear warhead, you can send a biological warhead, or an EMP warhead, whatever it is. 15 00:02:22,780 --> 00:02:25,220 But the delivery mechanism is still the same missile. 16 00:02:25,380 --> 00:02:29,940 So we're going to talk about how you can combine the payloads and injection vectors in this way. 17 00:02:30,740 --> 00:02:32,520 So that's separating deployment from the payload. 18 00:02:33,240 --> 00:02:35,600 Of course, payloads can be chosen for desired effect. 19 00:02:36,080 --> 00:02:46,400 And then when we get more technical later in the talk, I'm going to talk about the restraints, and some of the details of getting around those restraints, when you have, like, for instance, limited size on the stack and things like that. 20 00:02:48,440 --> 00:02:49,520 So what is an exploit? 21 00:02:49,620 --> 00:02:51,680 I'm not going to linger here, because everybody knows what that is. 22 00:02:52,940 --> 00:02:54,420 It's really easy to find bugs. 23 00:02:54,800 --> 00:02:58,800 If you watch USSR labs, you see they post, like, I don't know, three advisories a day or something. 24 00:02:59,160 --> 00:02:59,820 It's ridiculous. 25 00:03:00,700 --> 00:03:04,560 What they do is, or how you do it, is to simply run automated testing tools. 26 00:03:04,820 --> 00:03:06,060 It's very simple to do this. 27 00:03:06,120 --> 00:03:07,780 I've written several in the lab that I have. 28 00:03:08,180 --> 00:03:12,300 I can download a bunch of software off of 2000, and in one day find 10 buffer overflows. 29 00:03:12,380 --> 00:03:13,300 It's ridiculously simple. 30 00:03:13,760 --> 00:03:16,140 All I have to say is code sucks. 31 00:03:16,480 --> 00:03:20,860 The quality of code that you have on your systems is absolutely treacherous, horrible. 32 00:03:21,240 --> 00:03:22,300 And that's why. 33 00:03:22,300 --> 00:03:25,600 That's why you're going to continue to see buffer overflows from now and years from now. 34 00:03:25,960 --> 00:03:29,780 I think companies over the next few years are going to start to realize this, and there 35 00:03:29,780 --> 00:03:33,840 will be a lot more attention paid to testing, due diligence, and things like that in the 36 00:03:33,840 --> 00:03:36,840 labs before critical infrastructure software is released. 37 00:03:38,140 --> 00:03:43,120 So obviously an exploit is a bug, takes advantage of a bug for some desired effect. 38 00:03:44,820 --> 00:03:46,820 So on a bad day I can just crash my machine. 39 00:03:48,440 --> 00:03:50,400 Machine crashing is getting harder to do these days. 40 00:03:50,480 --> 00:03:51,920 I mean, obviously on Windows 95 it's really easy. 41 00:03:52,660 --> 00:03:56,480 On Windows NT it's slightly harder because typically you're going to be exploiting a 42 00:03:56,480 --> 00:03:57,240 user level process. 43 00:03:57,640 --> 00:03:59,240 It's not going to crash the kernel generally. 44 00:03:59,600 --> 00:04:03,420 However, a lot of times it's very simple to cause it to DOS the machine, or lock it 45 00:04:03,420 --> 00:04:05,160 up, which is almost equivalent to crashing it. 46 00:04:06,580 --> 00:04:12,040 If it's a VIP process, a very important process such as CSRSS or something like that, and 47 00:04:12,040 --> 00:04:15,640 you manage to get into a 100% CPU loop, that's pretty much crashing the machine because it's 48 00:04:15,640 --> 00:04:16,120 not going anywhere. 49 00:04:17,040 --> 00:04:18,740 Most common, of course, is an application crash. 50 00:04:18,840 --> 00:04:21,020 If I don't get my payload right, I'll bomb the application. 51 00:04:21,240 --> 00:04:22,280 The application just goes away. 52 00:04:23,760 --> 00:04:25,600 Another possibility is recoverable exception. 53 00:04:26,240 --> 00:04:28,580 Does everybody here know what exception handling is all about? 54 00:04:29,920 --> 00:04:32,800 Exception handling does not prevent buffer overflows from working. 55 00:04:34,340 --> 00:04:39,140 Exception handlers, the code that takes care of dealing with an exception, is all on the 56 00:04:39,140 --> 00:04:39,400 stack. 57 00:04:39,560 --> 00:04:42,900 So if I just keep going down the stack with my buffer overflow, I'll just overwrite that. 58 00:04:43,060 --> 00:04:45,900 It actually makes it easier to exploit the buffer overflow because I don't have to worry 59 00:04:45,900 --> 00:04:46,600 about offsets. 60 00:04:46,860 --> 00:04:50,940 I can have the EIP, which is the instruction pointer on Intel, go anywhere I want to go, 61 00:04:50,980 --> 00:04:52,280 and when it throws an exception, which is the EIP, it's going to go anywhere I want 62 00:04:52,300 --> 00:04:52,320 to go. 63 00:04:52,320 --> 00:04:52,920 Which is all they're going to do. 64 00:04:53,420 --> 00:04:56,640 My exception handler, that I just conveniently put in there for it, gets called. 65 00:04:58,080 --> 00:04:59,640 Oh, this all totally applies to Win32. 66 00:04:59,920 --> 00:05:00,260 Absolutely. 67 00:05:02,700 --> 00:05:04,600 Oh, no, the handler for it is on the stack. 68 00:05:04,680 --> 00:05:04,980 You're right. 69 00:05:05,080 --> 00:05:05,280 It is. 70 00:05:06,160 --> 00:05:10,400 FS0, offset 0, from FS is where the exception handler structure is called, but the previous 71 00:05:10,400 --> 00:05:11,740 exception handler is right there on the stack. 72 00:05:12,740 --> 00:05:14,300 There's code which explains that. 73 00:05:14,420 --> 00:05:17,700 If you want to come up after I get done talking, I can give all that to you. 74 00:05:19,400 --> 00:05:21,780 So recoverable exception is a possible thing that can happen. 75 00:05:22,300 --> 00:05:24,920 Of course, if we're successful, we'll get mobile code onto the system. 76 00:05:24,960 --> 00:05:26,640 Mobile code, obviously, is very, very deadly. 77 00:05:26,820 --> 00:05:28,040 It can do a number of things. 78 00:05:29,280 --> 00:05:34,400 You're all familiar with viruses, and if you were around in the early scene, you saw lots 79 00:05:34,400 --> 00:05:35,120 of really cool stuff. 80 00:05:35,180 --> 00:05:37,320 Viruses were doing all kinds of neat things back in the day. 81 00:05:37,540 --> 00:05:38,900 This all can be done today. 82 00:05:39,020 --> 00:05:41,700 There's no reason that you have to limit yourself. 83 00:05:42,400 --> 00:05:46,380 Obviously reading and writing files on the system is another possibility, and of course, 84 00:05:46,380 --> 00:05:47,300 it's done all sorts of tech. 85 00:05:47,820 --> 00:05:48,220 Thank you. 86 00:05:49,100 --> 00:05:49,500 Thank you. 87 00:05:51,880 --> 00:05:52,280 Thank you. 88 00:05:53,080 --> 00:05:55,320 Sorry I'm going so fast, but I've got to get through these slides. 89 00:05:57,340 --> 00:05:58,860 Exploits can obviously be grouped. 90 00:05:59,100 --> 00:06:00,740 There are certain bugs that keep coming back. 91 00:06:01,360 --> 00:06:06,720 If you go through all the lists, 8LGM, bug track, and you go through them all and classify 92 00:06:06,720 --> 00:06:08,840 the bugs, you're going to see certain groups of them. 93 00:06:09,100 --> 00:06:13,920 This book actually covers, chapter by chapter, each one of these subjects, like improper 94 00:06:13,920 --> 00:06:19,640 filtering, content-based attacks, balance overflows, impersonation, bad authentication, 95 00:06:20,140 --> 00:06:21,320 obfuscation, which they call encryption. 96 00:06:21,320 --> 00:06:25,500 In other words, we just need better testing on the software. 97 00:06:26,360 --> 00:06:28,740 What I was going to get to with this military and missile thing. 98 00:06:29,460 --> 00:06:31,560 Your attack payload is not the same as your entry point. 99 00:06:34,080 --> 00:06:38,280 Let's say you have a given bug on a given version of Exchange on a given service pack. 100 00:06:38,800 --> 00:06:41,300 That's going to all dictate how your injection vector looks. 101 00:06:41,420 --> 00:06:45,320 When I say injection vector, I mean the code that gets the instruction pointer owned by 102 00:06:45,320 --> 00:06:45,660 you. 103 00:06:46,320 --> 00:06:49,600 Once you have that, however, the payload can be anything at once. 104 00:06:49,960 --> 00:06:51,300 So what you can have is a system that's going to be able to do all sorts of things. 105 00:06:51,300 --> 00:06:54,760 Let's say you have a situation where you've got a group of goons over here all writing 106 00:06:54,760 --> 00:06:57,420 injection vectors for all these qualified hosts. 107 00:06:57,620 --> 00:07:02,620 I have 335 different buffer overflows in this collection over here, and it applies 108 00:07:02,620 --> 00:07:04,400 to these 2,048 machines. 109 00:07:05,040 --> 00:07:10,660 I send out my scanner crew, and they scan out and find 27 eligible hosts on this network. 110 00:07:10,820 --> 00:07:14,460 Then I go over here, my other group of goons is all writing the payloads, and I can then 111 00:07:14,460 --> 00:07:17,280 select from the payloads that I want to use and deploy into their network. 112 00:07:17,360 --> 00:07:21,280 Maybe I have a payload that shoots out ICMP redirects so I can screw with their SWAT. 113 00:07:21,300 --> 00:07:25,360 Maybe I have another one that does an ARP spoof across the network and floods their entire 114 00:07:25,360 --> 00:07:25,920 subnet. 115 00:07:26,060 --> 00:07:27,900 Maybe I have another one that DOSes their router. 116 00:07:28,360 --> 00:07:30,620 So this is like missile versus warhead technology. 117 00:07:31,780 --> 00:07:36,180 All of the governments of the world are investing time and money into doing this. 118 00:07:39,720 --> 00:07:41,160 So I just talked about this. 119 00:07:41,200 --> 00:07:45,280 Obviously there's a difference here, and you can keep them separate and match them as you 120 00:07:45,280 --> 00:07:45,460 need. 121 00:07:50,320 --> 00:07:50,760 Yes. 122 00:07:50,920 --> 00:07:51,280 In general. 123 00:07:51,300 --> 00:07:51,720 There are different injection vectors. 124 00:07:52,240 --> 00:07:53,400 They're target-dependent. 125 00:07:53,980 --> 00:07:57,620 What this means is that if you have a different service pack, for instance, you might have 126 00:07:57,620 --> 00:08:00,640 to have a completely different injection vector, but the payload can be the same. 127 00:08:01,040 --> 00:08:05,140 So injection vectors are tied explicitly with the environment you're about to exploit. 128 00:08:05,340 --> 00:08:10,880 A different version of Exchange, a different version of IIS, you know, one service pack 129 00:08:10,880 --> 00:08:11,220 is different. 130 00:08:11,280 --> 00:08:14,780 Maybe a different version of kernel 32 DLL in the system makes all the difference, and 131 00:08:14,780 --> 00:08:18,060 now I have to have a new injection vector, but the payload all the time remains the same. 132 00:08:18,280 --> 00:08:20,680 So it's very OS dependent, target dependent. 133 00:08:22,340 --> 00:08:25,960 And, oh, yes, encoding dependent, that's very important as well. 134 00:08:26,060 --> 00:08:31,840 If I'm sending the exploit through anything that does content filtering, a URL request, 135 00:08:31,980 --> 00:08:36,480 for instance, only has certain valid characters, mine encoding as well, then that's going 136 00:08:36,480 --> 00:08:41,320 to limit the number of characters, a character set, that is, that I can use. 137 00:08:41,820 --> 00:08:45,160 Well, when I'm thinking about character set, what I'm really thinking about is the number 138 00:08:45,160 --> 00:08:48,420 of assembly language instructions which are available to me, right? 139 00:08:48,520 --> 00:08:50,160 So I might have a limited set. 140 00:08:50,680 --> 00:08:52,980 I might have a limited set of instructions that I can use for my injection vector. 141 00:08:55,200 --> 00:08:58,260 The payload is independent of the injection vector in most cases. 142 00:08:59,380 --> 00:09:01,900 It'll still depend on the architecture of the machine, of course. 143 00:09:02,180 --> 00:09:03,600 You're going to have an Intel payload. 144 00:09:03,720 --> 00:09:05,480 It may not work on a Spark machine. 145 00:09:06,240 --> 00:09:09,860 However, I can tell you that there are payloads that will work on multiple hardware platforms, 146 00:09:10,140 --> 00:09:11,420 and that's a pretty elite trick. 147 00:09:15,120 --> 00:09:16,280 Think of it like a virus. 148 00:09:16,440 --> 00:09:17,640 Just think payload, think virus. 149 00:09:17,700 --> 00:09:18,380 It's almost the same thing. 150 00:09:19,180 --> 00:09:20,660 Once it's established, it can expand. 151 00:09:20,680 --> 00:09:21,900 It can spread by any means. 152 00:09:22,420 --> 00:09:26,020 Trust relationships, obviously, are the easiest, and then another one is scanning for more 153 00:09:26,020 --> 00:09:26,220 bugs. 154 00:09:26,500 --> 00:09:31,020 There are worms on the internet now that are crawling all over the place using buffer overflows. 155 00:09:31,560 --> 00:09:34,900 We don't hear about it very often, but if you read CERT, you'll see that ADM worm has 156 00:09:34,900 --> 00:09:38,740 been rooting machines for almost a year now, and it's amazing, it's the same bind vulnerability 157 00:09:38,740 --> 00:09:41,560 and it's been around forever, and you see that. 158 00:09:41,700 --> 00:09:43,180 So there is evidence of this occurring. 159 00:09:45,720 --> 00:09:47,640 The payload, these are some of the things you could do. 160 00:09:47,780 --> 00:09:48,740 Denial of service, obviously. 161 00:09:49,120 --> 00:09:49,840 I could use it. 162 00:09:49,840 --> 00:09:54,400 The machine I exploit, I could use it as a launching point for distributed, or I could 163 00:09:54,400 --> 00:09:57,040 get several of them, perhaps, into a DDoS attack. 164 00:09:57,900 --> 00:10:01,360 Remote shell is one you probably have all seen at some point or another. 165 00:10:02,040 --> 00:10:05,440 The remote shell does not have to be telnet-like or netcat-like. 166 00:10:05,500 --> 00:10:07,340 It can also just be some sort of covert channel. 167 00:10:07,660 --> 00:10:08,980 I could put some code on the system. 168 00:10:09,080 --> 00:10:13,940 For instance, it looks at offset 48 in any packet coming through the system and looks 169 00:10:13,940 --> 00:10:17,200 there for a special character, and if it sees that, it interprets the next five characters 170 00:10:17,200 --> 00:10:17,780 as some command. 171 00:10:17,920 --> 00:10:18,880 It's a covert channel. 172 00:10:18,880 --> 00:10:20,940 I could embed those in ICMP packets. 173 00:10:21,800 --> 00:10:24,940 If I don't have access to kernel mode, in other words, I can't promiscuously sniff 174 00:10:24,940 --> 00:10:27,200 under NT, I could just patch IIS. 175 00:10:27,440 --> 00:10:32,780 I could go into the IIS process space, let's say that's the one that I exploited, and 176 00:10:32,780 --> 00:10:37,280 I could just go and find where it does all the URL moniker, where it parses all the URLs. 177 00:10:37,500 --> 00:10:40,880 Well, then I could just use that as a covert channel and send all my commands through a 178 00:10:40,880 --> 00:10:43,120 URL, and nobody would be none the wiser. 179 00:10:44,180 --> 00:10:48,800 Obviously the worms are the most dangerous of all, and rootkit is obviously for stuff. 180 00:10:51,620 --> 00:10:55,100 You can say that an injector will only work on a certain number of qualified hosts. 181 00:10:55,420 --> 00:11:00,800 I think when Barnaby Jack and EI wrote the IIS injector back last year, about this time 182 00:11:00,800 --> 00:11:04,080 actually, it worked about on 20% of the web hosts currently online. 183 00:11:04,300 --> 00:11:08,340 That was enough to cause insane amounts of damage to the e-commerce world. 184 00:11:09,500 --> 00:11:10,060 It's real. 185 00:11:10,260 --> 00:11:12,740 When you find a buffer overflow, it means something. 186 00:11:13,040 --> 00:11:17,280 There are plenty of them out there that can root tons and tons of machines, a lot of them 187 00:11:17,280 --> 00:11:18,040 that nobody knows about. 188 00:11:22,160 --> 00:11:24,380 Obviously, there's two types of injection. 189 00:11:24,900 --> 00:11:26,440 First type is content-based. 190 00:11:26,660 --> 00:11:30,100 What that means is I'm sending some content that's being interpreted by an application 191 00:11:30,100 --> 00:11:33,080 server of some kind, and I'm going to bend its arm. 192 00:11:33,180 --> 00:11:35,000 I'm going to say, hey, dude, I want you to do this over here. 193 00:11:35,240 --> 00:11:36,560 The process remains in control. 194 00:11:36,640 --> 00:11:38,880 It's doing something it shouldn't do, but it remains in control. 195 00:11:39,100 --> 00:11:40,500 That's the content-based attack. 196 00:11:40,660 --> 00:11:43,640 That's doing things like what Rainforest Puppy did with the RDS exploit. 197 00:11:44,180 --> 00:11:45,320 Then there's buffer overflow. 198 00:11:45,600 --> 00:11:48,860 This is different significantly because the process is no longer in control. 199 00:11:48,860 --> 00:11:53,960 I have removed that process from the ability to control where it's going. 200 00:11:54,080 --> 00:11:59,160 I've changed the instruction pointer on the chip, and I'm going to make it point to my 201 00:11:59,160 --> 00:11:59,580 own code. 202 00:12:01,800 --> 00:12:07,280 Trust-based, content-based stuff, trust-based spreading could be like any of the stuff 203 00:12:07,280 --> 00:12:13,140 you've known for years with the virus underground, boot floppies, things like that. 204 00:12:14,020 --> 00:12:15,160 Let me go through here. 205 00:12:15,260 --> 00:12:18,840 Melissa is obviously another good example of a trust-based spread. 206 00:12:18,860 --> 00:12:19,740 Trust-based exploitation. 207 00:12:20,180 --> 00:12:22,680 I'm opening mail from somebody I thought I knew. 208 00:12:26,060 --> 00:12:29,020 I have a couple slides talking about the government's stuff. 209 00:12:29,380 --> 00:12:30,980 There's a couple declassified reports. 210 00:12:31,160 --> 00:12:32,880 They originally were classified, but they were released. 211 00:12:33,400 --> 00:12:38,480 As early as 1995, they had evidence of Cuba doing virus teams. 212 00:12:39,000 --> 00:12:42,820 You can bet your ass that today they're still doing it, and they're using buffer overflows. 213 00:12:43,120 --> 00:12:46,240 The Russian KGB, as early as 1991, was involved in this type of stuff. 214 00:12:46,600 --> 00:12:48,320 And then E&Y reports. 215 00:12:48,420 --> 00:12:48,840 I had to call them. 216 00:12:48,840 --> 00:12:51,340 There's a couple that came up just talking about virus and mobile code. 217 00:12:52,100 --> 00:12:55,620 Over 50% of the people they interviewed reported this is a problem. 218 00:12:55,920 --> 00:12:57,380 The UK, same deal. 219 00:12:58,160 --> 00:13:02,160 Costing almost $8,000 per incident on average to repair these things. 220 00:13:02,300 --> 00:13:02,900 So it's very expensive. 221 00:13:04,560 --> 00:13:06,800 Does everybody remember the Morris worm, or at least heard of it? 222 00:13:07,460 --> 00:13:08,620 Yeah, real famous. 223 00:13:08,920 --> 00:13:10,180 It shut down most of the internet. 224 00:13:10,380 --> 00:13:12,660 Of course, most of the internet back then wasn't very big. 225 00:13:12,960 --> 00:13:14,820 So today, we have the same problem. 226 00:13:15,000 --> 00:13:18,820 You see, the Morris worm worked really well because everything on the systems that it 227 00:13:18,840 --> 00:13:20,060 was attacking was all the same. 228 00:13:20,180 --> 00:13:21,100 It was like a monoculture. 229 00:13:21,300 --> 00:13:25,420 And I believe it was a single buffer overflow in Finger D and in some Sendmail exploit. 230 00:13:25,780 --> 00:13:27,960 And they used both of them, if I remember correctly. 231 00:13:29,760 --> 00:13:34,320 And it spread rapidly, and it took over most of the systems because there was this monoculture. 232 00:13:34,420 --> 00:13:36,000 Well, today, we still have that monoculture. 233 00:13:36,140 --> 00:13:38,180 We have that Wintel platform out there. 234 00:13:38,300 --> 00:13:40,500 And then we also have the Linux and Apache platform. 235 00:13:41,020 --> 00:13:43,740 Together, those two things make up most of the web server market. 236 00:13:43,880 --> 00:13:47,480 And that's pretty amazing to think that if I had one really good buffer overflow, I could 237 00:13:47,480 --> 00:13:48,820 take out half of the web server market. 238 00:13:48,840 --> 00:13:50,620 The web server market out there. 239 00:13:53,560 --> 00:13:55,100 In 89, there was another worm. 240 00:13:55,280 --> 00:13:58,440 I just did this just to show that there are worms, and they've been reported. 241 00:13:58,580 --> 00:13:59,300 It was called Wank. 242 00:13:59,520 --> 00:14:07,440 It hit NASA, and it spread into HEPnet, which is a high-energy physics network by the U.S. 243 00:14:07,660 --> 00:14:08,020 DOE. 244 00:14:08,700 --> 00:14:10,960 And it took two weeks to get to clean all those systems up. 245 00:14:10,980 --> 00:14:11,700 So there's evidence of that. 246 00:14:13,060 --> 00:14:13,420 Okay. 247 00:14:13,460 --> 00:14:15,100 So let's get into buffer overflows a little more. 248 00:14:19,800 --> 00:14:21,660 There are a couple ways to do it. 249 00:14:21,880 --> 00:14:25,820 The most common is a stack overflow, but I'm sure you've all heard of a heap overflow as well. 250 00:14:25,980 --> 00:14:27,340 I'm going to talk about both of those. 251 00:14:27,940 --> 00:14:31,640 The goal of a buffer overflow is to own the instruction pointer. 252 00:14:32,260 --> 00:14:33,200 That is the goal. 253 00:14:35,540 --> 00:14:37,720 So I'm going to get it to point to something that I control. 254 00:14:38,640 --> 00:14:42,780 Now, how many of you here think that the only place you could put instruction code is on the stack itself? 255 00:14:44,780 --> 00:14:46,420 I could put my instruction code anywhere. 256 00:14:46,420 --> 00:14:49,460 I could put my instruction code on the heap, on the stack. 257 00:14:49,760 --> 00:14:56,080 Any transaction that's recently taken place in any form on the system is probably going to be floating around in memory somewhere. 258 00:14:57,020 --> 00:14:59,020 That's usually going to be on the heap in many cases. 259 00:14:59,240 --> 00:15:03,340 So there we have a lot of room to play if we can get at least some of our code into the system anywhere. 260 00:15:03,480 --> 00:15:11,860 The stack portion of the overflow may just be enough information to get us to jump to the other place in the code where we have the rest of our goodies waiting to be run. 261 00:15:13,220 --> 00:15:13,620 Okay. 262 00:15:13,640 --> 00:15:16,340 So the challenge is with all of this, just injecting and owning the IP. 263 00:15:16,340 --> 00:15:16,400 Okay. 264 00:15:16,420 --> 00:15:20,060 So the challenge with the IP is there's obviously size restrictions many times. 265 00:15:20,440 --> 00:15:23,860 And depending on those size restrictions, we might have to make some very tight code. 266 00:15:24,560 --> 00:15:27,820 However, I can tell you it's amazing what you can do with 100 bytes. 267 00:15:29,500 --> 00:15:34,200 Assembly language is very interesting in that you can do a lot with, like, a few bytes. 268 00:15:34,360 --> 00:15:36,020 Two bytes is a very important instruction. 269 00:15:36,860 --> 00:15:42,600 Well, if I had every instruction with only two bytes long and I had 100 bytes, that's 50 instructions. 270 00:15:42,740 --> 00:15:44,500 Believe me, I can do a lot with 50 instructions. 271 00:15:46,740 --> 00:15:48,020 Is somebody asking a question? 272 00:15:48,920 --> 00:15:49,300 Okay. 273 00:15:51,700 --> 00:15:53,520 Obviously, I'm going to be sending a payload as well. 274 00:15:53,720 --> 00:16:05,260 If the injector part and the payload part are in the same buffer, for example, all on the stack together, which is typical in most of these that you see, we have to make sure that they don't step on each other. 275 00:16:05,380 --> 00:16:06,660 So I'm going to talk about that a little bit. 276 00:16:07,860 --> 00:16:09,640 Then there's this whole thing called offsets. 277 00:16:09,680 --> 00:16:12,580 You typically see these under Unix systems and not so much under NT. 278 00:16:12,960 --> 00:16:17,060 When you don't know where you are in memory, you don't know where your code ended up, so you kind of have to guess. 279 00:16:17,300 --> 00:16:18,680 So I'm going to talk about that a little bit. 280 00:16:18,860 --> 00:16:21,800 And then, obviously, you probably all know the issue with null characters. 281 00:16:22,900 --> 00:16:26,680 If you're doing a store copy and there's a null in there, the store copy stops at the null. 282 00:16:27,360 --> 00:16:32,620 So, obviously, we can't have a null character just floating around in the middle of our payload or we're going to have half a payload when we get done. 283 00:16:33,120 --> 00:16:34,700 So there's a couple of encoding tricks. 284 00:16:35,140 --> 00:16:36,400 You can go a little further with this. 285 00:16:36,440 --> 00:16:38,080 I'm just going to talk about null characters today. 286 00:16:38,500 --> 00:16:40,900 But in this book is some information on some other stuff. 287 00:16:40,900 --> 00:16:46,280 If you have other types of encoding, for instance, URL or MIME, there are certain characters you cannot use. 288 00:16:46,600 --> 00:16:49,020 So there's just some tricks for getting around this problem. 289 00:16:49,160 --> 00:16:51,320 And they're actually explained in Chapter 8 in this book here. 290 00:16:53,740 --> 00:16:56,160 Okay, so, oh, Ryan, hi. 291 00:16:56,260 --> 00:16:57,080 Thank you very much. 292 00:16:57,200 --> 00:16:59,900 I'm going to ask a couple questions, I guess, sometime. 293 00:17:00,200 --> 00:17:01,120 And I'll try to think of good ones. 294 00:17:01,260 --> 00:17:03,480 And then if you get the question right, I'll give you a book. 295 00:17:06,120 --> 00:17:08,060 So this one, someone let me borrow. 296 00:17:08,160 --> 00:17:09,300 I'm hiding it over here. 297 00:17:12,920 --> 00:17:15,280 Okay, so I'm going to go through this. 298 00:17:15,360 --> 00:17:17,120 I'm going to tell you why Stack Overflow works. 299 00:17:17,440 --> 00:17:21,720 The stack keeps track of a lot more information than just user-supplied information. 300 00:17:21,840 --> 00:17:24,500 It keeps track of what we might call housekeeping data. 301 00:17:24,800 --> 00:17:30,260 And housekeeping data is essentially what we're going to try to overwrite in order to own the instruction pointer. 302 00:17:31,520 --> 00:17:33,140 So there's a couple of issues there. 303 00:17:33,200 --> 00:17:38,560 Obviously, if we're filling a buffer, that buffer should be growing towards our housekeeping data that we want to nuke. 304 00:17:38,700 --> 00:17:38,980 Right? 305 00:17:38,980 --> 00:17:40,740 And we then must overwrite it. 306 00:17:41,640 --> 00:17:42,640 So I'm going to talk about that. 307 00:17:43,080 --> 00:17:49,240 When we make a subroutine call in the architecture of any processor, we've got to store the location of where we just were. 308 00:17:49,700 --> 00:17:51,140 Otherwise, we won't know how to get back. 309 00:17:51,380 --> 00:17:52,620 So typically, we're moving along. 310 00:17:52,740 --> 00:17:53,980 We're running, ba-da-da-da-da, you know. 311 00:17:54,080 --> 00:17:56,960 And we're jumping here, jumping there, jumping here, jumping there, jumping there, jumping there. 312 00:17:56,960 --> 00:17:57,720 Oh, I'm done here. 313 00:17:57,800 --> 00:17:58,740 Okay, so now I've got to get back. 314 00:17:58,880 --> 00:17:59,900 I've got to remember how to get back to here. 315 00:17:59,980 --> 00:18:02,420 And then I've got to remember how to get back to here, to here, to here. 316 00:18:02,500 --> 00:18:05,120 So all of that information is what the stack is for. 317 00:18:05,540 --> 00:18:06,820 It keeps track of all this information. 318 00:18:07,100 --> 00:18:08,840 So let me do this little animation for you. 319 00:18:09,980 --> 00:18:11,240 This IP appears. 320 00:18:11,340 --> 00:18:12,320 That's an instruction pointer. 321 00:18:12,580 --> 00:18:17,060 This block right here is actually kind of my little version of the Intel processor. 322 00:18:17,400 --> 00:18:19,640 It would look different depending on what processor you have. 323 00:18:19,840 --> 00:18:21,340 But the concept is the same. 324 00:18:22,160 --> 00:18:24,800 So the instruction pointer is pointing out into a code page. 325 00:18:24,980 --> 00:18:25,360 You see that? 326 00:18:25,400 --> 00:18:26,300 It says code at the bottom. 327 00:18:26,580 --> 00:18:30,340 And that little pink square is supposed to mean there's some code there that's important to us. 328 00:18:30,420 --> 00:18:31,100 And we're running. 329 00:18:31,140 --> 00:18:33,300 Now, let's say that code calls some other subroutine. 330 00:18:33,480 --> 00:18:36,700 So we have to take the instruction pointer and put it on the stack. 331 00:18:37,720 --> 00:18:38,160 Okay? 332 00:18:38,840 --> 00:18:39,540 Then the stack grows. 333 00:18:40,440 --> 00:18:43,060 Oh, then the IP, of course, is updated to point to a new location. 334 00:18:43,300 --> 00:18:44,660 The stack grows up. 335 00:18:45,640 --> 00:18:51,760 And that area up in here is going to be used as temporary scratch pad while this other subroutine does its things. 336 00:18:51,860 --> 00:18:55,200 All the automatic variables on that subroutine will be stored here on the stack. 337 00:18:55,380 --> 00:19:01,600 And that means, you know, arrays and buffers as well as, like, integers, whatever it's using. 338 00:19:03,920 --> 00:19:06,620 So then the stack pointer is updated to point to the top. 339 00:19:06,700 --> 00:19:07,300 And we run. 340 00:19:07,300 --> 00:19:10,740 And then when we're done, it goes away. 341 00:19:10,860 --> 00:19:15,120 It's kind of like deallocation, even though it's really just adjusting the stack pointer back to where it was. 342 00:19:15,300 --> 00:19:18,660 And the old IP is put back in originally where we were. 343 00:19:19,280 --> 00:19:22,160 That's the essence of the stack operation here. 344 00:19:22,560 --> 00:19:25,620 Now, obviously, what we're going to try to do is change this value. 345 00:19:28,680 --> 00:19:30,360 So the stack overflow works like this. 346 00:19:30,480 --> 00:19:33,640 There's our housekeeping data or return pointer, whatever you want to call it. 347 00:19:33,880 --> 00:19:34,900 The stack grows. 348 00:19:35,140 --> 00:19:36,460 Now let's say it's going to fill a buffer. 349 00:19:37,100 --> 00:19:38,780 Like a store copy, let's say. 350 00:19:39,120 --> 00:19:43,020 The buffers grow down towards the information, towards the housekeeping data. 351 00:19:43,260 --> 00:19:45,260 So it grows, see, right over the top. 352 00:19:45,660 --> 00:19:46,620 That's how it works. 353 00:19:47,240 --> 00:19:49,580 Now, the problem with a null character would be this. 354 00:19:49,680 --> 00:19:51,740 Same exact slide, pretty much. 355 00:19:52,020 --> 00:19:53,220 Store the housekeeping data. 356 00:19:53,480 --> 00:19:54,200 Grows up. 357 00:19:54,380 --> 00:19:55,400 We grow down. 358 00:19:55,500 --> 00:19:56,440 But we hit a null character. 359 00:19:56,620 --> 00:19:57,020 Guess what? 360 00:19:57,200 --> 00:19:57,880 We stop. 361 00:19:58,440 --> 00:20:01,240 So, essentially, we can't have a null character in our payload. 362 00:20:01,340 --> 00:20:02,000 That's the problem. 363 00:20:02,800 --> 00:20:06,280 Now, I'm going to show you a trick which will allow you to have a null character. 364 00:20:07,260 --> 00:20:08,700 In one particular instance. 365 00:20:11,320 --> 00:20:16,900 Obviously, if we're going to overwrite the housekeeping data, we need to be able to make sure the null is past that, right? 366 00:20:17,580 --> 00:20:18,580 Does everybody get that? 367 00:20:19,840 --> 00:20:20,420 Okay, great. 368 00:20:20,600 --> 00:20:20,880 Good. 369 00:20:21,740 --> 00:20:24,620 Okay, so, I'm going to talk a little about little and big N-D in numbers. 370 00:20:25,140 --> 00:20:26,740 Has everybody here at least heard of this term? 371 00:20:29,980 --> 00:20:32,080 This might be basic for some of you out there. 372 00:20:32,880 --> 00:20:35,260 And, you know, I know I said advanced buffer overflow techniques. 373 00:20:35,260 --> 00:20:40,680 But if you want to get some more insane stuff, I'll be around, you know, later on tonight. 374 00:20:40,920 --> 00:20:42,660 And I can show you some really insane stuff. 375 00:20:42,840 --> 00:20:44,680 But I'll just go over some of the things I have here. 376 00:20:45,080 --> 00:20:46,340 Okay, so big and little N-D in. 377 00:20:46,700 --> 00:20:49,780 The Intel processor stores numbers backwards, in my opinion. 378 00:20:50,080 --> 00:20:57,980 What this means is if I have a number 004010FF stored internally on the processor, it's actually FF10400. 379 00:21:00,860 --> 00:21:03,700 Spark architecture, I believe, is big N-D in, which means it doesn't do that. 380 00:21:05,880 --> 00:21:08,100 So, okay, the least significant byte goes first. 381 00:21:08,220 --> 00:21:09,560 I think everybody can understand this, right? 382 00:21:09,620 --> 00:21:10,160 It's just backwards. 383 00:21:10,580 --> 00:21:12,160 So, I'm going to store an address somewhere. 384 00:21:12,340 --> 00:21:14,800 I actually do have to store it this way on an Intel processor. 385 00:21:14,880 --> 00:21:16,280 I have to store it in its reverse form here. 386 00:21:19,400 --> 00:21:23,940 So, I'd say these colors might look a little screwed up. 387 00:21:24,020 --> 00:21:24,280 I'm sorry. 388 00:21:24,340 --> 00:21:25,880 I apologize if you can't read it from the back. 389 00:21:26,480 --> 00:21:27,840 So, here's our housekeeping data. 390 00:21:28,660 --> 00:21:29,700 Same image as before. 391 00:21:29,920 --> 00:21:31,300 We have an original return address. 392 00:21:31,820 --> 00:21:33,280 This one here up in 7F. 393 00:21:33,280 --> 00:21:35,300 7F is probably talking in NTDLL somewhere. 394 00:21:35,880 --> 00:21:36,240 Typical. 395 00:21:36,580 --> 00:21:37,100 All right. 396 00:21:37,160 --> 00:21:38,280 So, then our stack's going to grow. 397 00:21:39,200 --> 00:21:40,320 And then we're going to override it. 398 00:21:41,360 --> 00:21:42,900 And we're going to be able to put a null there. 399 00:21:43,000 --> 00:21:43,380 Now, watch. 400 00:21:44,160 --> 00:21:45,540 Now, I know that's really hard to see. 401 00:21:45,920 --> 00:21:48,620 This says 0C20400. 402 00:21:49,220 --> 00:21:50,960 It's this address, I believe, right here. 403 00:21:51,700 --> 00:21:52,060 Yeah. 404 00:21:52,340 --> 00:21:56,260 So, does everybody see how I can put a null in there and they still have it work? 405 00:21:57,380 --> 00:21:59,300 This stack starts in an address. 406 00:21:59,540 --> 00:22:01,660 It runs in an address range, which starts with 00. 407 00:22:01,660 --> 00:22:05,740 But that doesn't prevent me because of the little Indian-ness of the x86 processor. 408 00:22:05,880 --> 00:22:08,140 I can now jump into that area. 409 00:22:08,280 --> 00:22:10,180 I've put an address in there that is valid. 410 00:22:10,760 --> 00:22:12,000 So, injection is complete. 411 00:22:13,240 --> 00:22:14,420 We've put in an address. 412 00:22:16,320 --> 00:22:18,540 Now, let's talk about where we can put the payload. 413 00:22:20,540 --> 00:22:23,820 Does everybody get how, like, I guess I didn't explain that very well. 414 00:22:25,200 --> 00:22:29,040 Because I put that there, when we return from the function that we were in, 415 00:22:29,040 --> 00:22:33,760 and we replace EIP, that's going to be taken from the housekeeping data that we replaced. 416 00:22:33,860 --> 00:22:34,620 Does everybody understand that? 417 00:22:35,180 --> 00:22:35,540 Okay. 418 00:22:36,900 --> 00:22:37,280 What's that? 419 00:22:38,460 --> 00:22:39,520 How do I put the... 420 00:22:41,920 --> 00:22:45,320 You have to supply more... 421 00:22:45,320 --> 00:22:47,040 Okay, the question was, how do you actually overflow? 422 00:22:47,960 --> 00:22:53,320 What you have to do is depend on the fact that there's going to be some software out there that does no bounds checking. 423 00:22:53,480 --> 00:22:58,020 It's going to look for a null character, like I showed you in the previous slide, to stop that overflow. 424 00:22:58,020 --> 00:23:01,880 Now, if you don't supply that null character, and it doesn't check for it, 425 00:23:01,960 --> 00:23:05,640 it happily will continue copying as long as you want. 426 00:23:06,100 --> 00:23:10,100 That's essentially the problem with some calls like sprintf or strcopy. 427 00:23:10,200 --> 00:23:15,480 They look for a null character, and they don't allow you, the programmer, to specify the size of the buffer. 428 00:23:15,620 --> 00:23:19,620 They assume that whatever you supply will be smaller than the buffer that was allocated. 429 00:23:20,460 --> 00:23:20,700 Okay. 430 00:23:21,200 --> 00:23:25,440 So, after we've done this, let's talk about where you can put the actual code that you want to run, okay? 431 00:23:26,160 --> 00:23:27,700 So, here's our housekeeping data. 432 00:23:28,020 --> 00:23:28,520 We have a stack. 433 00:23:29,660 --> 00:23:30,320 We overflow. 434 00:23:30,640 --> 00:23:31,540 There's our new address. 435 00:23:32,340 --> 00:23:33,260 The null is okay. 436 00:23:34,540 --> 00:23:35,960 So, it jumps back into here. 437 00:23:37,020 --> 00:23:38,680 And then, that's our payload area. 438 00:23:38,800 --> 00:23:40,040 We can put our instruction code in that. 439 00:23:40,860 --> 00:23:42,800 That is the simplest form of stack overflow. 440 00:23:43,480 --> 00:23:46,840 That's not going to give me a whole lot of room, unfortunately, but it would work. 441 00:23:48,160 --> 00:23:51,180 So, now let me talk about a little way to make some more room. 442 00:24:01,860 --> 00:24:05,100 The question was, how do you find out where the instruction pointer is stored on the stack? 443 00:24:05,920 --> 00:24:07,300 It'll be in a known location. 444 00:24:07,560 --> 00:24:08,700 You will have soft ice. 445 00:24:08,840 --> 00:24:14,760 You will explode it, and you will know that it is exactly, you know, X number of characters in in this particular buffer. 446 00:24:15,420 --> 00:24:20,440 A trick that I use is I send, when I'm sending the buffer overflow initially, kind of black box testing. 447 00:24:20,600 --> 00:24:24,800 I'm supplying large buffers, you know, with a Perl script or something into an application. 448 00:24:25,140 --> 00:24:27,940 You know, I'm giving a username that is 300 characters long. 449 00:24:27,940 --> 00:24:31,640 The characters that I send, I alternate them in a predictable way. 450 00:24:31,740 --> 00:24:33,540 And, again, the algorithm for that is in this book. 451 00:24:33,840 --> 00:24:41,320 And they alternate in a predictable way so that if I get a crash, you know, when I get a crash, it's going to tell me what address it crashed on. 452 00:24:41,600 --> 00:24:45,840 So, I see that, and I'll know exactly what four characters it crashed on because it will tell me. 453 00:24:45,900 --> 00:24:47,620 And I'll know exactly what the offset is. 454 00:24:47,700 --> 00:24:48,840 It's just a little trick for debugging. 455 00:24:54,460 --> 00:24:55,240 Oh, probably. 456 00:24:57,160 --> 00:24:57,520 Sorry. 457 00:24:58,460 --> 00:24:59,500 As long as you get it. 458 00:25:02,040 --> 00:25:02,360 Okay. 459 00:25:02,380 --> 00:25:06,420 So, let's say we were dealing with the previous slide here, and we have a very confined payload. 460 00:25:06,540 --> 00:25:07,420 So, we have confined payload. 461 00:25:07,540 --> 00:25:08,540 What are some of the things we can do? 462 00:25:09,240 --> 00:25:10,180 What are the restrictions? 463 00:25:10,560 --> 00:25:11,740 How can we get around this restriction? 464 00:25:11,960 --> 00:25:20,880 So, we can compress our payload and then have a little decompressor in there that will grow it out larger somewhere else, maybe on the heap or further down the stack. 465 00:25:21,420 --> 00:25:23,240 We can use preloaded functions. 466 00:25:23,440 --> 00:25:27,920 Obviously, any process that's running on the computer is going to have a bazillion functions. 467 00:25:27,920 --> 00:25:30,840 Already loaded and ready to use, that's how it works. 468 00:25:31,120 --> 00:25:33,460 So, as long as we know where they are, we can just call them. 469 00:25:33,580 --> 00:25:35,180 We don't have to load them or do anything weird. 470 00:25:35,800 --> 00:25:37,260 And oftentimes, this works fine. 471 00:25:38,780 --> 00:25:41,300 That means that my payload doesn't have to build what's called a jump table. 472 00:25:42,460 --> 00:25:45,920 Of course, the key is that all these functions I want to use have to already be loaded. 473 00:25:46,360 --> 00:25:47,740 I can use hard-coded addresses. 474 00:25:48,140 --> 00:25:49,860 There's two ways to use a preloaded function. 475 00:25:50,080 --> 00:25:57,740 I can either go scan for it and find it because I don't trust that it's always going to be in the same place, or I'm just going to believe to myself that it's always going to be in the same place. 476 00:25:57,740 --> 00:25:59,360 So, I hard-code the address to it. 477 00:25:59,740 --> 00:26:06,040 I wrote a buffer overflow about a year ago that had the hard-coded address for regopenkey and regwritekey, and those worked fine. 478 00:26:06,140 --> 00:26:07,380 The hard-coded address worked fine. 479 00:26:08,140 --> 00:26:08,960 So, it was very small. 480 00:26:10,260 --> 00:26:12,740 Once again, this has to be predictable, and it has to always be there. 481 00:26:14,400 --> 00:26:19,060 And, of course, if you're sending a payload, you're going to also have data probably sent along with the payload, and I'm going to show that in a second. 482 00:26:19,320 --> 00:26:24,100 You can't put very much data on something if you have this confined space problem. 483 00:26:25,700 --> 00:26:27,320 So, let's say we want to use more stack. 484 00:26:27,740 --> 00:26:30,420 Okay, now, you were complaining about the typo. 485 00:26:30,660 --> 00:26:32,200 I'll pre-empt you here. 486 00:26:32,280 --> 00:26:33,200 This is also a typo. 487 00:26:33,280 --> 00:26:35,220 Our stack should be 0040. 488 00:26:36,260 --> 00:26:37,740 Okay, so ignore that 77. 489 00:26:39,780 --> 00:26:40,800 We're going to use more stack. 490 00:26:41,000 --> 00:26:41,740 So, here we are. 491 00:26:41,800 --> 00:26:42,840 Here's our hallux heaping data. 492 00:26:43,180 --> 00:26:43,960 Da-da-da-da-da. 493 00:26:44,920 --> 00:26:46,680 Now, we go down the stack. 494 00:26:46,840 --> 00:26:48,240 We put a whole bunch of stuff on it. 495 00:26:49,740 --> 00:26:53,920 Now, when we overwrite this address, notice I didn't put a 00 at the end. 496 00:26:54,260 --> 00:26:55,960 We have to pick an address. 497 00:26:56,620 --> 00:27:00,080 Now, the code page has plenty of stuff that's not in 00 range, right? 498 00:27:00,280 --> 00:27:02,420 Most of it, in fact, I don't believe is in 00 range. 499 00:27:03,200 --> 00:27:06,660 We can pick an address out there anywhere, and it'll jump to it, right? 500 00:27:06,800 --> 00:27:07,820 So, that's the key. 501 00:27:07,900 --> 00:27:10,020 We cannot have a null in the address, and I'll show you the trick. 502 00:27:12,920 --> 00:27:15,120 So, here's our larger version of the stack. 503 00:27:15,400 --> 00:27:16,860 We overflow a long ways. 504 00:27:17,320 --> 00:27:19,420 You see we went quite a distance here. 505 00:27:20,000 --> 00:27:21,000 So, we've got plenty of room. 506 00:27:21,980 --> 00:27:25,380 We're still going to have to overwrite this guy, though, because it's a return pointer. 507 00:27:25,960 --> 00:27:27,140 So, we go down there, bonk. 508 00:27:27,440 --> 00:27:28,780 We still overwrite this guy. 509 00:27:29,360 --> 00:27:35,080 We make it point somewhere that ends up getting the instruction pointer to point back into this buffer. 510 00:27:35,840 --> 00:27:37,300 I'll show that trick in a second. 511 00:27:39,400 --> 00:27:43,020 Essentially, we jump to here, and then we begin execution. 512 00:27:43,320 --> 00:27:44,440 Much more room now. 513 00:27:47,080 --> 00:27:47,940 Everybody get that? 514 00:27:50,440 --> 00:27:52,840 So, when does the address contain a null character? 515 00:27:53,500 --> 00:27:55,000 I call it a lowland address. 516 00:27:55,000 --> 00:27:57,320 Under NT, the stack is stored in lowland. 517 00:27:57,420 --> 00:28:00,860 What that means is that there's a 00 in the first part of the address. 518 00:28:04,540 --> 00:28:05,700 Limits the size of our payload. 519 00:28:06,080 --> 00:28:08,540 I believe the stack under Linux is not stored in lowland. 520 00:28:08,580 --> 00:28:09,140 It's stored in highland. 521 00:28:09,280 --> 00:28:11,600 I think it starts with 77 or BF or BB. 522 00:28:12,700 --> 00:28:14,080 Hobbs was in the audience earlier. 523 00:28:14,220 --> 00:28:15,300 He probably knows that. 524 00:28:16,720 --> 00:28:17,160 BF? 525 00:28:18,800 --> 00:28:19,240 Okay. 526 00:28:19,820 --> 00:28:22,820 So, Linux wouldn't have this problem with the lowland address. 527 00:28:23,220 --> 00:28:24,980 I am an NT user. 528 00:28:24,980 --> 00:28:25,060 I'm an IT guy. 529 00:28:25,240 --> 00:28:26,600 So, this is what I'm going to talk about mostly. 530 00:28:27,020 --> 00:28:27,520 Yes, sir? 531 00:28:28,180 --> 00:28:29,640 The question that was asked earlier. 532 00:28:29,840 --> 00:28:33,140 You're trying to populate IP with an address inside the stack. 533 00:28:33,380 --> 00:28:34,940 How do you know what that address is going to be? 534 00:28:35,020 --> 00:28:36,740 The stack is constantly growing and shrinking. 535 00:28:37,200 --> 00:28:44,400 The question was, if I populate the instruction pointer with an address which points into the stack, how do I know where I am? 536 00:28:44,640 --> 00:28:46,440 Remember when I was talking about guessing offsets? 537 00:28:46,800 --> 00:28:48,220 That's exactly what that's about. 538 00:28:48,420 --> 00:28:49,260 I have to guess. 539 00:28:49,660 --> 00:28:52,660 And I'm going to show you a trick in a moment that makes guessing it very easy. 540 00:28:53,320 --> 00:29:01,340 In some other cases, I'm going to actually grab that address out of a register or something else. 541 00:29:01,460 --> 00:29:02,480 And I'll show you that trick as well. 542 00:29:03,480 --> 00:29:03,720 Okay. 543 00:29:03,780 --> 00:29:06,740 So, highland address is no zeros in the address. 544 00:29:06,860 --> 00:29:07,000 Okay. 545 00:29:07,040 --> 00:29:08,160 So, you guys all understand that. 546 00:29:08,180 --> 00:29:08,540 It's no big deal. 547 00:29:09,100 --> 00:29:09,460 Okay. 548 00:29:09,480 --> 00:29:12,180 So, under NT, you're going to be dealing with large payload, lowland address. 549 00:29:12,860 --> 00:29:17,040 We cannot use the lowland address directly because it will limit our payload size, typically. 550 00:29:17,980 --> 00:29:22,640 So, we're going to have to figure out a way to get back to the stack without directly using it. 551 00:29:22,640 --> 00:29:28,420 Without directly hard-coding the address of a stack, of the stack itself in there. 552 00:29:28,560 --> 00:29:28,680 Okay. 553 00:29:28,740 --> 00:29:30,160 So, I'm going to show a couple tricks. 554 00:29:30,300 --> 00:29:32,220 And I have a couple more that are in slides, but I'll talk about them. 555 00:29:32,460 --> 00:29:33,820 We can use a CPU register. 556 00:29:34,100 --> 00:29:38,020 Typically, the CPU is going to have a bunch of information stored in the registers, right? 557 00:29:38,120 --> 00:29:45,180 And oftentimes, one of those registers or even more than one will be pointing to locations on the stack near or about the area I'm going to overflow. 558 00:29:45,680 --> 00:29:52,140 And what this means is if I can get my payload or my overflow to cover that area, all I have to do is just make sure my payload starts right there. 559 00:29:52,140 --> 00:29:53,220 And it'll jump to it. 560 00:29:53,320 --> 00:29:54,300 I'll show that trick. 561 00:29:56,640 --> 00:29:58,820 So, we have a register pointing into the stack somewhere. 562 00:29:58,980 --> 00:29:59,980 Let's say it's the D register. 563 00:30:02,360 --> 00:30:05,880 I overflow far enough so that I can begin putting payload information here. 564 00:30:07,980 --> 00:30:09,620 Here's our housekeeping data we overflow. 565 00:30:10,880 --> 00:30:15,300 And we do something that makes the value of D end up in IP. 566 00:30:15,980 --> 00:30:20,040 And what this does then is, boom, we're now executing right here. 567 00:30:20,900 --> 00:30:22,480 That's the basics of the trick. 568 00:30:23,160 --> 00:30:24,800 How do we really do that technically? 569 00:30:25,240 --> 00:30:30,260 Well, if I could find an FFD0, two bytes in there somewhere, that's call EAX. 570 00:30:30,440 --> 00:30:41,200 What that means is if EAX has the address of something on the stack, if I can just get EIP to point to somewhere in location in memory somewhere that has these two bytes, then boom. 571 00:30:41,740 --> 00:30:44,440 I'm now going to call through EAX and be on the stack. 572 00:30:44,980 --> 00:30:47,700 The key thing to remember about this is I don't actually... 573 00:30:47,700 --> 00:30:55,880 When I put that address there in the housekeeping data, all it has to do, that address, has to simply be the location of these two bytes. 574 00:30:55,980 --> 00:30:56,900 It doesn't have to be in code. 575 00:30:56,980 --> 00:30:57,780 It could be in data. 576 00:30:58,460 --> 00:30:58,940 Okay? 577 00:30:59,160 --> 00:31:00,580 The computer doesn't care. 578 00:31:02,660 --> 00:31:05,620 Call EBX, call ECX, just a couple examples of the same thing. 579 00:31:08,740 --> 00:31:17,400 Another way to do it is to find a push of the particular register we're interested in followed at some point in the future by a return. 580 00:31:17,700 --> 00:31:19,020 Just as long as there's only one push. 581 00:31:19,360 --> 00:31:23,560 That means the topmost value on the stack is going to be what we pushed, right? 582 00:31:23,700 --> 00:31:26,540 Let's say it's the D register, the one we just showed in the slide. 583 00:31:26,840 --> 00:31:28,560 So now D's sitting on the top of the stack. 584 00:31:28,740 --> 00:31:31,460 And then maybe a couple instructions later, we see a return. 585 00:31:32,460 --> 00:31:32,780 Boom. 586 00:31:32,820 --> 00:31:36,780 It pops the top of the stack off what was the D register and puts it in EIP. 587 00:31:36,960 --> 00:31:39,100 Same exact thing, just a different way to do it. 588 00:31:40,860 --> 00:31:43,280 I don't have a slide for this one, but I'll talk about it. 589 00:31:43,320 --> 00:31:43,900 It's another one I found. 590 00:31:45,200 --> 00:31:46,940 A couple layers down on the stack. 591 00:31:47,040 --> 00:31:47,680 Let's say it's not a register. 592 00:31:47,700 --> 00:31:49,320 There's nothing in the register we can use. 593 00:31:52,080 --> 00:31:57,740 But let's say that a couple of 32-bit values down on the stack, we have an address of something on the stack. 594 00:31:58,300 --> 00:31:59,480 Self-referencing in a way. 595 00:31:59,580 --> 00:32:03,500 That happens all the time, especially if you're passing arguments from subroutine to subroutine to subroutine. 596 00:32:03,900 --> 00:32:07,760 I pass the automatic variable of one subroutine to a parameter of a second subroutine, 597 00:32:07,900 --> 00:32:11,800 the original's going to point back into the first one, which has its own little area there on the stack frame. 598 00:32:14,300 --> 00:32:15,280 Where was I going with this? 599 00:32:15,300 --> 00:32:15,480 Oh yes. 600 00:32:15,600 --> 00:32:17,260 So if it's down there a couple layers, 601 00:32:17,260 --> 00:32:21,200 as long as I can go out there and code and I can find a bunch of pops all in a row, 602 00:32:21,300 --> 00:32:22,120 pop, pop, pop, pop, 603 00:32:22,200 --> 00:32:24,560 I can peel off the stack, if you will, 604 00:32:24,660 --> 00:32:25,920 until I get to the value I want, 605 00:32:26,040 --> 00:32:27,220 and then there has to be a return. 606 00:32:27,640 --> 00:32:28,780 This works all the time. 607 00:32:29,040 --> 00:32:32,880 There's plenty of places in NTDLL where you can find code that'll pop three or four, 608 00:32:33,040 --> 00:32:34,300 and then you can get a return. 609 00:32:38,340 --> 00:32:38,660 Okay. 610 00:32:39,820 --> 00:32:42,680 So I'm going to talk a little bit about what you were saying about the offset 611 00:32:42,680 --> 00:32:45,040 and how we can reduce the precision of that a little bit. 612 00:32:48,420 --> 00:32:50,280 We can use no-ops. 613 00:32:50,660 --> 00:32:52,120 Does everybody know what a no-op is? 614 00:32:52,260 --> 00:32:54,780 It's a single byte instruction, hex 90, 615 00:32:55,620 --> 00:32:58,240 and it runs and does nothing, right? 616 00:32:58,680 --> 00:33:00,860 So there's this thing called a no-op sled, 617 00:33:01,520 --> 00:33:04,840 and what we can do is make an area of just no-ops, 618 00:33:04,840 --> 00:33:06,260 and if we jump anywhere in there, 619 00:33:06,380 --> 00:33:09,560 we can be sure we're going to kind of slide through it and end up somewhere else. 620 00:33:09,840 --> 00:33:11,120 I call that a no-op sled. 621 00:33:11,660 --> 00:33:12,260 Excuse me. 622 00:33:15,740 --> 00:33:16,620 So I illustrated. 623 00:33:17,780 --> 00:33:18,480 We grow. 624 00:33:19,580 --> 00:33:20,460 There's our null, yeah, 625 00:33:20,580 --> 00:33:23,020 and then we're going to overwrite that data there, 626 00:33:23,680 --> 00:33:24,400 housekeeping data. 627 00:33:25,680 --> 00:33:30,200 And this area of the code down here that we filled would be all no-ops, okay? 628 00:33:30,960 --> 00:33:33,620 This would be real payload up here, and this would be all no-ops. 629 00:33:33,700 --> 00:33:34,520 We're going to guess. 630 00:33:35,220 --> 00:33:37,280 We know it kind of changes from system to system, 631 00:33:37,380 --> 00:33:39,520 but we're going to guess that within this range anywhere, 632 00:33:40,220 --> 00:33:41,860 if we can put an address in there, 633 00:33:41,980 --> 00:33:43,320 we're going to hit the no-op sled. 634 00:33:43,320 --> 00:33:44,320 So here's what will happen. 635 00:33:44,640 --> 00:33:45,360 We guess. 636 00:33:46,220 --> 00:33:47,480 We hit the no-op sled, 637 00:33:47,960 --> 00:33:49,100 and then if we're successful, 638 00:33:49,580 --> 00:33:51,100 we then slide through it, 639 00:33:51,180 --> 00:33:54,220 and boom, begin executing real payload right there. 640 00:33:55,180 --> 00:33:55,600 Happiness. 641 00:34:03,020 --> 00:34:05,300 If you're anything like I was last night, 642 00:34:05,440 --> 00:34:07,680 you probably didn't get any sleep and you drank way too much. 643 00:34:08,000 --> 00:34:09,280 So forgive me if I'm a little slow. 644 00:34:09,480 --> 00:34:11,060 I'm just guzzling this water down here. 645 00:34:12,220 --> 00:34:12,640 Okay. 646 00:34:13,320 --> 00:34:14,660 Let's talk about heap a little bit. 647 00:34:14,780 --> 00:34:15,580 Heap is kind of fun. 648 00:34:16,880 --> 00:34:18,820 If we only have a limited size on the stack, 649 00:34:19,060 --> 00:34:21,740 we can probably use the stack enough to get to the heap. 650 00:34:22,060 --> 00:34:23,740 That's one way to exploit the heap, 651 00:34:23,860 --> 00:34:27,100 which means if we can somehow put something in a recent transaction, 652 00:34:27,160 --> 00:34:30,120 perhaps in a URL request where you have all the weird MIME types 653 00:34:30,120 --> 00:34:32,520 and stuff that are passed right after the get, 654 00:34:33,320 --> 00:34:34,760 that might be stored on the heap, for instance, 655 00:34:34,880 --> 00:34:36,140 so we could put some shellcode in there 656 00:34:36,140 --> 00:34:38,340 and just do the stack part enough to jump to it, 657 00:34:38,380 --> 00:34:39,160 and that's an interesting idea. 658 00:34:39,440 --> 00:34:42,040 So we can store parts in different places in the program. 659 00:34:43,640 --> 00:34:45,180 Interesting places to inject, of course, 660 00:34:45,220 --> 00:34:46,680 are like HTTP headers, for instance. 661 00:34:47,500 --> 00:34:48,660 Other ones are files. 662 00:34:48,700 --> 00:34:50,280 If files are being opened and closed, 663 00:34:50,320 --> 00:34:51,300 you can control those files. 664 00:34:52,280 --> 00:34:54,080 Oftentimes, information that was in those files 665 00:34:54,080 --> 00:34:54,980 will be stored on the heap somewhere. 666 00:34:56,700 --> 00:34:58,280 And this is a simplistic slide, 667 00:34:58,400 --> 00:35:01,220 but we do enough to get EIP to point to the heap. 668 00:35:01,800 --> 00:35:02,200 Okay. 669 00:35:04,420 --> 00:35:05,800 Here's another interesting thing. 670 00:35:05,960 --> 00:35:07,740 Let's say we don't do a stack overflow at all. 671 00:35:07,820 --> 00:35:09,860 We do 100% homegrown heap overflow. 672 00:35:10,480 --> 00:35:11,460 Here's an interesting one. 673 00:35:11,460 --> 00:35:12,740 We have two C++ objects. 674 00:35:12,920 --> 00:35:14,420 Anybody here program in C++? 675 00:35:15,680 --> 00:35:18,540 Okay, so you know about inheritance and virtual, right? 676 00:35:18,780 --> 00:35:21,220 And operator overloading and V tables? 677 00:35:21,900 --> 00:35:22,980 That's what we're going to talk about. 678 00:35:24,020 --> 00:35:27,700 A C++ object stores its own function pointers 679 00:35:27,700 --> 00:35:31,280 if those functions can be modified by its children, okay? 680 00:35:31,360 --> 00:35:32,960 That's called inheritance and polymorphism. 681 00:35:34,340 --> 00:35:35,800 I'll show a diagram of that. 682 00:35:36,080 --> 00:35:38,180 The other thing to remember about C++ objects 683 00:35:38,180 --> 00:35:39,500 is that member variables, 684 00:35:39,600 --> 00:35:41,060 information stored within the object itself, 685 00:35:42,420 --> 00:35:44,560 is subject to the same types of buffer overflows 686 00:35:44,560 --> 00:35:45,780 as a stack object, okay? 687 00:35:47,800 --> 00:35:50,140 Here's the V table on a C++ object under NTA. 688 00:35:51,900 --> 00:35:53,760 So the V table is stored at the very beginning. 689 00:35:54,140 --> 00:35:56,180 And this is where all the member variables are stored. 690 00:35:56,240 --> 00:35:57,360 Now, let's say we have a buffer in there. 691 00:35:58,700 --> 00:36:00,260 Now, if we fill that buffer, 692 00:36:00,380 --> 00:36:02,320 it's going to fill away from the V table. 693 00:36:03,320 --> 00:36:06,200 Obviously, this is going to be a problem, right? 694 00:36:06,320 --> 00:36:08,300 I mean, because we want to grow towards something 695 00:36:08,300 --> 00:36:09,960 that's important in housekeeping data. 696 00:36:12,460 --> 00:36:14,180 So let's say we have two of them in an array 697 00:36:15,000 --> 00:36:16,880 or near each other somewhere on the heap. 698 00:36:17,240 --> 00:36:18,220 This is very interesting. 699 00:36:19,200 --> 00:36:20,820 See? I went over a second guy. 700 00:36:21,220 --> 00:36:22,400 Just to show you again, I overflow 701 00:36:24,880 --> 00:36:26,260 over the V table pointer. 702 00:36:27,140 --> 00:36:30,660 Okay, so where do we make the V table pointer point? 703 00:36:31,000 --> 00:36:33,140 Well, we have to supply our own V table pointer. 704 00:36:33,200 --> 00:36:33,960 How kind of us. 705 00:36:36,280 --> 00:36:38,380 We make it point back into the buffer we just overfilled. 706 00:36:39,880 --> 00:36:40,240 Um... 707 00:36:41,740 --> 00:36:44,040 If you were at Black Hat, you can't answer this question. 708 00:36:45,360 --> 00:36:46,500 Okay, if you saw that. 709 00:36:47,140 --> 00:36:49,720 But what would be a very convenient function 710 00:36:50,460 --> 00:36:53,280 to change if I was overflowing the V table pointer? 711 00:36:53,660 --> 00:36:55,260 Somebody please, don't everybody yell it out. 712 00:36:55,320 --> 00:36:56,620 Just raise your hands and I'll call on somebody. 713 00:36:56,860 --> 00:36:57,960 And you can win this book. 714 00:36:58,260 --> 00:37:00,480 What would be the most convenient function 715 00:37:00,480 --> 00:37:03,340 to overflow in the, or to change in the V table pointer? 716 00:37:05,680 --> 00:37:08,500 The destructor, absolutely. 717 00:37:16,440 --> 00:37:17,780 The same as RET. 718 00:37:18,540 --> 00:37:19,080 Yep. 719 00:37:20,380 --> 00:37:23,500 So the destructor is usually always virtual. 720 00:37:24,210 --> 00:37:26,980 So it's almost guaranteed to be there no matter what. 721 00:37:27,460 --> 00:37:30,420 And so that obviously makes the best choice. 722 00:37:31,260 --> 00:37:33,380 You could overwrite any function that matters, 723 00:37:33,480 --> 00:37:35,300 but that just, I mean, why? 724 00:37:35,480 --> 00:37:36,280 I mean, that one's the best. 725 00:37:36,500 --> 00:37:36,800 Yes? 726 00:37:37,000 --> 00:37:39,440 I was told last night that GCC 727 00:37:39,440 --> 00:37:41,340 always puts in a destructor 728 00:37:41,460 --> 00:37:43,000 even if you're only using it in C mode. 729 00:37:44,280 --> 00:37:47,140 Ryan mentioned that GCC always puts in a destructor 730 00:37:47,140 --> 00:37:48,980 even if you're only using it in C mode. 731 00:37:50,140 --> 00:37:51,220 Okay, sounds interesting. 732 00:37:53,160 --> 00:37:55,000 Okay, so injection is complete at this point. 733 00:37:56,320 --> 00:37:57,800 So here's some information. 734 00:37:58,220 --> 00:38:01,000 These are things I'm not talking about in this talk here, 735 00:38:01,120 --> 00:38:02,980 but this is some of the stuff that can happen. 736 00:38:03,100 --> 00:38:05,020 The first one I'd like you to all know 737 00:38:05,020 --> 00:38:07,820 is that kernel mode buffer overflows are a reality, 738 00:38:07,860 --> 00:38:09,460 and they're all over in Windows NT. 739 00:38:10,120 --> 00:38:12,460 It's mostly third-party drivers 740 00:38:13,680 --> 00:38:15,760 with iOctl calls, which are not checked. 741 00:38:16,200 --> 00:38:19,040 iOctl calls can be made by anybody on the system, usually, 742 00:38:19,140 --> 00:38:22,000 because they put improper permissions on the device handle. 743 00:38:23,420 --> 00:38:25,240 Kernel mode buffer overflows are very interesting, 744 00:38:25,300 --> 00:38:26,760 considering I can put anything I want in there, 745 00:38:26,840 --> 00:38:29,620 like the rootkit and like flint. 746 00:38:30,640 --> 00:38:32,920 Another one I'm not really going to talk a whole lot about 747 00:38:33,420 --> 00:38:35,140 is the off-by-one errors caused by... 748 00:38:35,140 --> 00:38:37,800 An off-by-one error can cause a frame pointer overwrite, 749 00:38:37,880 --> 00:38:39,320 but there was an article in FRAC 750 00:38:39,460 --> 00:38:39,980 about that recently. 751 00:38:40,660 --> 00:38:42,020 FRAC 55, I believe, 752 00:38:42,160 --> 00:38:44,000 and I think the guy that wrote it was Klog. 753 00:38:45,440 --> 00:38:46,940 The other one is multistage attacks, 754 00:38:47,460 --> 00:38:49,620 where you have to get the target into a particular state 755 00:38:49,620 --> 00:38:50,980 before you supply the buffer overflow. 756 00:38:51,360 --> 00:38:53,520 Has everybody here heard of RSA ref, the overflow? 757 00:38:54,520 --> 00:38:55,480 That's how that worked. 758 00:38:55,880 --> 00:38:56,780 It was complicated. 759 00:38:57,720 --> 00:38:59,860 And then a little bit of this stuff, 760 00:38:59,980 --> 00:39:02,220 the URL and MIMA coding is actually covered in the book, 761 00:39:03,020 --> 00:39:03,960 how to get around that. 762 00:39:05,300 --> 00:39:06,380 So let's talk about payload. 763 00:39:06,520 --> 00:39:07,380 Let me see where I am in time. 764 00:39:08,520 --> 00:39:11,080 I'm five minutes from when I'm supposed to end, 765 00:39:11,940 --> 00:39:13,700 so I've actually got a number of slides left. 766 00:39:13,780 --> 00:39:14,820 I'm going to try to go as fast as I can. 767 00:39:22,280 --> 00:39:23,420 So things with the payload. 768 00:39:23,560 --> 00:39:24,520 We can use loaded functions, 769 00:39:24,720 --> 00:39:26,100 functions that are already located in memory. 770 00:39:26,640 --> 00:39:27,560 I'm going to also show you 771 00:39:27,560 --> 00:39:29,700 how you can load your own functions and DOLs 772 00:39:29,700 --> 00:39:31,360 if you don't have the functionality you need, 773 00:39:32,200 --> 00:39:33,780 how to encode your data portion, 774 00:39:35,320 --> 00:39:37,360 and obviously things that the payload can do. 775 00:39:37,380 --> 00:39:37,960 What I'm going to do is make a shell. 776 00:39:38,620 --> 00:39:40,860 I'm not actually going to show the actual process 777 00:39:40,860 --> 00:39:42,120 of making a shell up here, 778 00:39:42,280 --> 00:39:44,020 but I'll just talk about it a little bit. 779 00:39:44,980 --> 00:39:47,360 So the payload typically will look something like this. 780 00:39:47,480 --> 00:39:48,160 You'll have a knop sled, 781 00:39:48,440 --> 00:39:49,460 you'll have real code, 782 00:39:49,680 --> 00:39:50,880 and you'll have a data portion. 783 00:39:51,640 --> 00:39:53,400 This is stuff you're going to use later 784 00:39:53,400 --> 00:39:55,920 for arguments to function calls, typically. 785 00:39:56,900 --> 00:39:58,860 Or if you remember Dildog's paper, 786 00:39:59,700 --> 00:40:01,320 the DAO Windows Buffer Overflow, 787 00:40:01,480 --> 00:40:03,140 he stored in here a URL 788 00:40:03,140 --> 00:40:05,160 to go download a file from somewhere and execute it. 789 00:40:05,220 --> 00:40:07,200 So the URL was stored in this part. 790 00:40:07,380 --> 00:40:09,180 So there's lots of things you can store here 791 00:40:09,180 --> 00:40:10,360 in this data portion. 792 00:40:13,640 --> 00:40:15,140 Okay, so the first thing that has to happen 793 00:40:15,140 --> 00:40:16,000 when our payload is executed 794 00:40:16,000 --> 00:40:17,700 is we have to find out where we are in memory. 795 00:40:17,960 --> 00:40:19,740 We could be anywhere, we have no idea. 796 00:40:21,380 --> 00:40:22,840 So once again, if you're a black hat, 797 00:40:22,880 --> 00:40:23,580 you can't answer this question. 798 00:40:24,300 --> 00:40:25,760 I'm going to ask one in just a moment. 799 00:40:26,400 --> 00:40:27,840 But what we can do is a short call, 800 00:40:28,300 --> 00:40:29,420 which means call forward, 801 00:40:30,960 --> 00:40:31,600 one instruction, 802 00:40:32,720 --> 00:40:34,460 and then that next instruction will be pop EDI. 803 00:40:34,620 --> 00:40:35,600 When you do a call, 804 00:40:35,600 --> 00:40:37,180 the first thing that happens is, 805 00:40:37,300 --> 00:40:39,080 it thinks you're going to do a subroutine call, right? 806 00:40:39,200 --> 00:40:40,920 So it takes the current instruction pointer 807 00:40:40,920 --> 00:40:42,820 and puts it on the stack. 808 00:40:44,160 --> 00:40:46,720 Well, then when we get to where we called to, 809 00:40:46,900 --> 00:40:48,340 we pop it back off the stack 810 00:40:48,340 --> 00:40:49,440 and store it somewhere for later. 811 00:40:49,960 --> 00:40:50,680 Pop EDI. 812 00:40:50,820 --> 00:40:52,500 Let's say EDI is a convenient place to store it. 813 00:40:52,920 --> 00:40:55,060 What we've done is we now know, 814 00:40:55,140 --> 00:40:56,100 let me go back to the previous slide, 815 00:40:57,280 --> 00:40:59,060 where this location is right here. 816 00:40:59,640 --> 00:41:00,700 And because we know that, 817 00:41:00,740 --> 00:41:02,660 we can calculate the offset to get to our data. 818 00:41:02,740 --> 00:41:04,480 This is very important because we have to use this data. 819 00:41:07,120 --> 00:41:08,220 Okay, so we've got our, 820 00:41:08,240 --> 00:41:09,140 I call it getting bearings. 821 00:41:09,620 --> 00:41:11,500 The problem with this instruction, however, 822 00:41:11,540 --> 00:41:14,040 is that it's EB00000000. 823 00:41:14,660 --> 00:41:15,580 That's how it's encoded. 824 00:41:16,460 --> 00:41:17,740 Obviously, four null characters 825 00:41:17,740 --> 00:41:19,200 isn't going to do our payload any good. 826 00:41:19,620 --> 00:41:21,680 So the quiz question for the next book is, 827 00:41:21,800 --> 00:41:23,280 how would I change this 828 00:41:23,860 --> 00:41:25,440 such that there are no null characters 829 00:41:25,440 --> 00:41:26,700 but it's equivalent? 830 00:41:28,020 --> 00:41:28,900 You, sir, over there. 831 00:41:29,500 --> 00:41:29,900 Yeah. 832 00:41:30,340 --> 00:41:30,740 . 833 00:41:34,120 --> 00:41:35,580 X or the instruction with itself 834 00:41:35,600 --> 00:41:36,380 to receive zero. 835 00:41:37,500 --> 00:41:37,940 . 836 00:41:49,720 --> 00:41:52,400 You're on a track that is good, 837 00:41:52,460 --> 00:41:53,940 but it wouldn't work in this case for this. 838 00:41:55,040 --> 00:41:55,480 . 839 00:41:56,020 --> 00:41:56,680 Somebody else. 840 00:41:56,820 --> 00:41:57,320 Yes, sir. 841 00:41:59,100 --> 00:41:59,540 . 842 00:42:02,020 --> 00:42:02,460 . 843 00:42:03,040 --> 00:42:03,480 . 844 00:42:07,740 --> 00:42:07,780 . 845 00:42:12,280 --> 00:42:12,320 . 846 00:42:12,900 --> 00:42:12,940 . 847 00:42:13,060 --> 00:42:13,100 . 848 00:42:13,980 --> 00:42:14,020 . 849 00:42:15,000 --> 00:42:15,040 . 850 00:42:15,040 --> 00:42:15,060 . 851 00:42:15,060 --> 00:42:15,140 . 852 00:42:15,140 --> 00:42:15,160 . 853 00:42:15,160 --> 00:42:15,180 . 854 00:42:15,180 --> 00:42:15,200 . 855 00:42:15,200 --> 00:42:15,220 . 856 00:42:15,220 --> 00:42:15,240 . 857 00:42:15,240 --> 00:42:15,260 . 858 00:42:15,260 --> 00:42:15,280 . 859 00:42:15,280 --> 00:42:15,300 . 860 00:42:15,300 --> 00:42:15,340 . 861 00:42:15,340 --> 00:42:15,360 . 862 00:42:15,360 --> 00:42:15,380 . 863 00:42:15,380 --> 00:42:15,400 . 864 00:42:15,400 --> 00:42:15,420 . 865 00:42:16,000 --> 00:42:16,040 . 866 00:42:20,220 --> 00:42:20,260 . 867 00:42:31,440 --> 00:42:32,240 so no 868 00:42:32,240 --> 00:42:33,500 no null bytes 869 00:42:35,200 --> 00:42:36,360 we make a call 870 00:42:36,360 --> 00:42:36,920 backwards 871 00:42:38,180 --> 00:42:40,440 I have it written down a little differently than you described it 872 00:42:40,440 --> 00:42:41,660 but you're on exactly the same wavelength 873 00:42:41,660 --> 00:42:43,540 the call goes backwards, see 874 00:42:43,540 --> 00:42:46,300 and then I simply make the next instruction 875 00:42:46,300 --> 00:42:48,140 a jump to get over that part 876 00:42:48,140 --> 00:42:49,740 because we're done with that, right, we don't want to run that twice 877 00:42:49,740 --> 00:42:51,000 and then 878 00:42:51,560 --> 00:42:53,860 we pop EDI, that translates 879 00:42:55,840 --> 00:42:56,280 EBFFFFFFFE 880 00:42:57,240 --> 00:42:57,960 no null 881 00:42:57,960 --> 00:43:00,420 characters and we essentially have done exactly the same thing 882 00:43:03,020 --> 00:43:03,800 okay, now like 883 00:43:03,800 --> 00:43:06,140 what you were talking about earlier, sir, is the XOR 884 00:43:06,140 --> 00:43:08,000 protection, we have a 885 00:43:08,000 --> 00:43:10,120 data payload, right, we can't have any 886 00:43:10,120 --> 00:43:12,140 null characters in that either, but we're going to probably put 887 00:43:12,140 --> 00:43:13,620 a lot of strings and weird stuff in there 888 00:43:13,620 --> 00:43:15,600 and strings need to be null terminated, so 889 00:43:15,600 --> 00:43:17,920 here's the trick to make your 890 00:43:17,920 --> 00:43:19,660 payload safe from this 891 00:43:19,660 --> 00:43:20,680 you simply XOR it 892 00:43:20,680 --> 00:43:23,580 the entire thing with a byte, which then the result 893 00:43:23,580 --> 00:43:25,000 turns out not to have any null characters 894 00:43:25,000 --> 00:43:27,620 you have to choose a byte that works for the payload 895 00:43:27,620 --> 00:43:29,220 or, excuse me, the data portion that you have 896 00:43:29,940 --> 00:43:31,680 so we XOR every single byte 897 00:43:31,680 --> 00:43:33,380 and make it safe 898 00:43:33,380 --> 00:43:34,880 there are no null characters 899 00:43:34,880 --> 00:43:37,480 it looks garbly, it's not encrypted 900 00:43:37,480 --> 00:43:39,940 of course, it's just pseudo-obfuscated 901 00:43:39,940 --> 00:43:40,740 I guess, in a way 902 00:43:41,680 --> 00:43:43,560 does everybody understand how XOR works here? 903 00:43:43,760 --> 00:43:45,200 we XOR every single byte across 904 00:43:45,200 --> 00:43:47,840 and if there was a zero, it'll now be the value 905 00:43:47,840 --> 00:43:49,280 of whatever XOR, whatever 906 00:43:49,660 --> 00:43:51,260 we're XORing it with, and it'll just look 907 00:43:51,260 --> 00:43:52,640 kind of like gobbledygook when we're done 908 00:43:52,640 --> 00:43:55,460 the key is, of course, we can XOR it back to the original 909 00:43:56,920 --> 00:43:57,800 so here's our 910 00:43:57,800 --> 00:43:58,860 typical payload 911 00:43:58,860 --> 00:44:01,100 our instruction code begins there 912 00:44:01,100 --> 00:44:03,680 the first thing our instruction code is going to do 913 00:44:03,680 --> 00:44:05,420 after, of course, it knows where it is in memory 914 00:44:05,420 --> 00:44:07,900 by doing that call, is going to begin to decode 915 00:44:07,900 --> 00:44:08,900 so it'll go down here 916 00:44:09,580 --> 00:44:10,960 and decode it back to the original 917 00:44:10,960 --> 00:44:13,380 this is on the remote computer once we've already 918 00:44:13,380 --> 00:44:13,920 got it online 919 00:44:16,320 --> 00:44:17,040 okay, so 920 00:44:17,420 --> 00:44:19,440 let's say we've decoded, we have a bunch of 921 00:44:19,660 --> 00:44:19,980 function names 922 00:44:20,820 --> 00:44:22,260 in here, names like 923 00:44:23,260 --> 00:44:24,100 what's a good function? 924 00:44:26,320 --> 00:44:26,920 what was that? 925 00:44:31,680 --> 00:44:32,800 system, yeah that's a good one 926 00:44:32,800 --> 00:44:34,320 alright, so 927 00:44:34,320 --> 00:44:36,320 we don't know the address of that call 928 00:44:37,320 --> 00:44:37,720 yet 929 00:44:38,540 --> 00:44:40,420 because, remember, our compiler didn't 930 00:44:40,420 --> 00:44:42,760 the compiler that the remote system used to make this program 931 00:44:42,760 --> 00:44:45,100 didn't happily compile our non-existent code into it 932 00:44:45,100 --> 00:44:47,500 so we have to go find out where that function lives in memory 933 00:44:48,100 --> 00:44:49,440 so we can put the string 934 00:44:50,440 --> 00:44:51,920 um, system, right here 935 00:44:51,920 --> 00:44:53,020 somewhere in this thing 936 00:44:53,020 --> 00:44:54,840 and we can reference it to a call 937 00:44:56,640 --> 00:44:57,820 to get proc address 938 00:44:57,820 --> 00:44:59,640 which is not the slide I wanted, oh no 939 00:45:00,060 --> 00:45:00,680 hold on 940 00:45:02,300 --> 00:45:04,020 okay, I'm going to go back and forth here 941 00:45:04,020 --> 00:45:05,100 get proc address 942 00:45:05,100 --> 00:45:07,900 and give it the pointer to the name that we just supplied 943 00:45:07,900 --> 00:45:09,660 and boom, we have the address 944 00:45:10,620 --> 00:45:11,660 when we have the address 945 00:45:11,660 --> 00:45:12,740 we can actually use it 946 00:45:13,980 --> 00:45:14,360 okay 947 00:45:15,060 --> 00:45:16,920 another way to do it is if we don't know where 948 00:45:16,920 --> 00:45:19,640 or if we do know exactly where it is and we don't want to try to 949 00:45:19,660 --> 00:45:21,000 find it, we can just hard code it in 950 00:45:21,000 --> 00:45:23,440 and this is, in this example, we just simply call 951 00:45:23,440 --> 00:45:25,400 the addresses directly 952 00:45:29,760 --> 00:45:31,660 yes, I'll talk about that in a moment 953 00:45:33,100 --> 00:45:33,660 oh, yeah 954 00:45:33,660 --> 00:45:34,980 so what this fellow said is 955 00:45:34,980 --> 00:45:37,800 in order to call get proc address, you have to know where it is 956 00:45:38,360 --> 00:45:38,720 clearly 957 00:45:40,160 --> 00:45:41,360 and I'll talk about pe 958 00:45:41,860 --> 00:45:43,240 executable header to talk about that 959 00:45:44,180 --> 00:45:45,780 okay, so the pros and cons to hard coding 960 00:45:46,240 --> 00:45:47,420 pros, it makes obviously 961 00:45:47,420 --> 00:45:48,280 the code smaller 962 00:45:49,660 --> 00:45:51,560 if the function isn't in the same place 963 00:45:51,560 --> 00:45:52,140 that's a con 964 00:45:53,200 --> 00:45:55,360 if dynamically loaded DLLs are an example 965 00:45:55,360 --> 00:45:56,960 it's typically not going to be in the same place 966 00:45:56,960 --> 00:45:59,760 some DLLs, however, are always in the same place 967 00:45:59,760 --> 00:46:01,000 well, most of the time 968 00:46:01,000 --> 00:46:02,860 and kernel 32 is an example of one of those 969 00:46:05,500 --> 00:46:07,140 okay, so dynamic function loading 970 00:46:07,540 --> 00:46:08,620 we're going to use load library 971 00:46:09,100 --> 00:46:10,260 and get proc address 972 00:46:10,260 --> 00:46:12,380 load library loads new DLLs 973 00:46:12,380 --> 00:46:15,320 get proc address loads functions from DLLs 974 00:46:15,320 --> 00:46:16,460 which are currently loaded in memory 975 00:46:17,640 --> 00:46:19,640 now, in reference to what you just said 976 00:46:19,660 --> 00:46:21,380 the function calls 977 00:46:21,380 --> 00:46:24,020 load library and get proc address are always in the same place 978 00:46:24,020 --> 00:46:26,060 so we can hard code the addresses of them 979 00:46:26,420 --> 00:46:27,740 if we don't want to do that 980 00:46:27,740 --> 00:46:29,200 we can go into the pe executable header 981 00:46:29,200 --> 00:46:30,980 and the first two entries in the idata table 982 00:46:30,980 --> 00:46:32,620 will be these two calls 983 00:46:32,620 --> 00:46:34,260 always, I've never seen it any other way 984 00:46:35,060 --> 00:46:36,220 so we can load a new DLL 985 00:46:36,220 --> 00:46:38,540 and find any function by its ASCII name 986 00:46:38,540 --> 00:46:40,020 I will note that sometimes 987 00:46:41,140 --> 00:46:42,300 functions are loaded by ordinal 988 00:46:42,300 --> 00:46:44,200 and I'm not actually talking about that in this talk 989 00:46:44,860 --> 00:46:46,460 most of the time I've seen them by ASCII name 990 00:46:48,340 --> 00:46:49,620 okay, so this was the slide you saw 991 00:46:49,660 --> 00:46:50,600 you call get proc address 992 00:46:50,600 --> 00:46:53,420 pass up the ASCII of the function name you want to load 993 00:46:54,280 --> 00:46:56,020 now, this is called building a jump table 994 00:46:56,020 --> 00:46:57,180 we do the same thing 995 00:46:57,180 --> 00:46:58,280 get proc address 996 00:46:58,280 --> 00:47:01,200 when we get the address, we store it away for later 997 00:47:01,200 --> 00:47:03,740 and we do this for all the functions we're planning on using 998 00:47:03,740 --> 00:47:04,980 there might be six or seven 999 00:47:04,980 --> 00:47:07,500 so we just keep storing them as we load them 1000 00:47:07,500 --> 00:47:08,840 and we build a jump table 1001 00:47:09,480 --> 00:47:10,780 when we have the jump table complete 1002 00:47:10,780 --> 00:47:11,940 we begin doing useful things 1003 00:47:12,340 --> 00:47:14,040 jump through it, making the calls 1004 00:47:17,520 --> 00:47:18,620 everybody kind of get that? 1005 00:47:23,640 --> 00:47:24,040 okay 1006 00:47:25,260 --> 00:47:26,540 now here's an elite thing 1007 00:47:26,540 --> 00:47:27,580 hash loading 1008 00:47:28,820 --> 00:47:30,960 I don't like having payloads 1009 00:47:31,520 --> 00:47:32,340 with data portions 1010 00:47:32,340 --> 00:47:35,660 of these huge string names for every function I need to load 1011 00:47:35,660 --> 00:47:37,540 well it turns out you don't need to do that 1012 00:47:37,540 --> 00:47:38,920 what you can do is take a hash 1013 00:47:38,920 --> 00:47:40,560 of the string itself 1014 00:47:40,560 --> 00:47:42,920 which turns out to be a 4 byte value in this case 1015 00:47:42,920 --> 00:47:44,120 and just store those 1016 00:47:44,120 --> 00:47:46,800 and then you can go into the process itself 1017 00:47:46,800 --> 00:47:48,920 and just hash everything that's loaded and if it matches 1018 00:47:49,760 --> 00:47:51,800 there's almost no chance of a collision here 1019 00:47:52,340 --> 00:47:54,440 so we can locate any loaded function 1020 00:47:54,440 --> 00:47:55,720 by checking the CRC 1021 00:47:55,720 --> 00:47:56,920 of each loaded ASCII name 1022 00:47:56,920 --> 00:47:58,560 we don't send any ASCII names tomorrow 1023 00:47:58,560 --> 00:48:00,340 we're just sending the hash equivalents of them 1024 00:48:01,080 --> 00:48:02,920 makes our payload much smaller 1025 00:48:04,580 --> 00:48:06,200 so to talk about that for a moment 1026 00:48:06,200 --> 00:48:07,560 we have to know about the PE header 1027 00:48:07,560 --> 00:48:08,800 does everybody know what that is? 1028 00:48:10,000 --> 00:48:11,360 every executable under NT 1029 00:48:11,360 --> 00:48:13,000 or most are in this format 1030 00:48:13,000 --> 00:48:14,160 called portable executable 1031 00:48:14,820 --> 00:48:16,140 and inside of this format 1032 00:48:16,140 --> 00:48:18,940 is a table of all the functions that it loads 1033 00:48:19,960 --> 00:48:21,520 so we have to go find the information 1034 00:48:21,520 --> 00:48:23,000 so we go to this optional header 1035 00:48:23,580 --> 00:48:25,720 and then from there we can get the ASCII name 1036 00:48:25,720 --> 00:48:27,260 and the corresponding address 1037 00:48:27,820 --> 00:48:28,880 of that function 1038 00:48:29,440 --> 00:48:30,560 that's all we need to do 1039 00:48:31,540 --> 00:48:32,920 it's already there for us 1040 00:48:34,680 --> 00:48:35,740 so over here 1041 00:48:35,740 --> 00:48:36,740 on the right hand side 1042 00:48:36,740 --> 00:48:38,100 this is our payload 1043 00:48:39,040 --> 00:48:40,740 the yellow area down there is 1044 00:48:40,740 --> 00:48:43,580 the actual CRC's or the hashes 1045 00:48:43,580 --> 00:48:45,660 that we've made so we load one of those up 1046 00:48:46,300 --> 00:48:47,880 and then we go into the PE header 1047 00:48:47,880 --> 00:48:48,660 which is over here 1048 00:48:49,660 --> 00:48:50,760 and we actually in real time 1049 00:48:50,760 --> 00:48:52,300 hash every single ASCII name 1050 00:48:52,300 --> 00:48:53,100 these are ASCII names 1051 00:48:53,100 --> 00:48:55,840 we hash each one and match it against the CRC 1052 00:48:55,840 --> 00:48:57,200 if it matches 1053 00:48:57,940 --> 00:48:59,880 then we go find the function address 1054 00:48:59,880 --> 00:49:01,900 and then BOOM put it back 1055 00:49:02,680 --> 00:49:05,500 replacing the original CRC with a function address 1056 00:49:05,500 --> 00:49:06,680 it's nice and clean 1057 00:49:06,680 --> 00:49:09,060 if we want 10 functions 1058 00:49:09,060 --> 00:49:10,300 we start out with 10 hashes 1059 00:49:10,300 --> 00:49:12,900 and when we get done we have 10 function addresses in there 1060 00:49:12,900 --> 00:49:14,260 it doesn't change the size at all 1061 00:49:14,260 --> 00:49:15,040 it's nice and clean 1062 00:49:15,040 --> 00:49:17,100 so it's basically building another jump table 1063 00:49:19,660 --> 00:49:20,080 and so forth 1064 00:49:20,880 --> 00:49:22,260 ok so there's our jump table 1065 00:49:22,960 --> 00:49:24,020 much much cleaner 1066 00:49:26,220 --> 00:49:27,760 ok limited character sets 1067 00:49:27,760 --> 00:49:29,680 if you're MIME encoding, URL encoding, whatever 1068 00:49:29,680 --> 00:49:31,720 it's going to limit the number of characters 1069 00:49:31,720 --> 00:49:33,300 that you can send through say 1070 00:49:33,300 --> 00:49:34,800 the content filter to the application 1071 00:49:34,800 --> 00:49:37,060 what this really means is that we've limited 1072 00:49:37,060 --> 00:49:38,720 the number of instructions that we can use 1073 00:49:39,560 --> 00:49:40,440 it means that 1074 00:49:40,440 --> 00:49:42,780 the opcode values 1075 00:49:42,780 --> 00:49:45,100 that we're able to send is a limited set 1076 00:49:45,500 --> 00:49:46,640 so we have to work with that 1077 00:49:46,640 --> 00:49:48,340 now a couple of years ago 1078 00:49:49,660 --> 00:49:51,760 my friend Cesar and I had a party 1079 00:49:52,900 --> 00:49:54,320 came up with this solution 1080 00:49:54,320 --> 00:49:55,700 for a problem 1081 00:49:55,700 --> 00:49:56,860 the problem was MIME encoding 1082 00:49:56,860 --> 00:49:58,880 we only had a number of 1083 00:49:59,440 --> 00:50:00,760 instructions that we could work with 1084 00:50:00,760 --> 00:50:02,740 if we had to pass only ascii 1085 00:50:02,740 --> 00:50:04,140 or excuse me, alphanumeric information 1086 00:50:04,140 --> 00:50:05,480 we couldn't pass anything weird 1087 00:50:05,940 --> 00:50:07,440 we only had short jumps 1088 00:50:07,440 --> 00:50:08,860 push and pop and subtract 1089 00:50:09,680 --> 00:50:11,340 now the way this worked is 1090 00:50:11,340 --> 00:50:13,380 we came up with this idea that we could just simply 1091 00:50:14,900 --> 00:50:16,260 put a value on the stack 1092 00:50:16,260 --> 00:50:18,520 pop it, put it in a register like EAX 1093 00:50:19,660 --> 00:50:21,060 and then subtract on it over and over and over again 1094 00:50:21,060 --> 00:50:23,140 so it was the actual value we really needed 1095 00:50:23,140 --> 00:50:24,300 for the payload that we wanted 1096 00:50:24,300 --> 00:50:25,460 and we pushed it back on the stack 1097 00:50:25,460 --> 00:50:27,400 and we just did this over and over and over again 1098 00:50:27,400 --> 00:50:28,840 and we actually built our payload in real time 1099 00:50:29,500 --> 00:50:30,660 it looked like a dream 1100 00:50:32,900 --> 00:50:35,020 along with this technique we also had the bridge 1101 00:50:35,020 --> 00:50:35,980 since we couldn't jump 1102 00:50:35,980 --> 00:50:37,520 we had to avoid the jump instruction 1103 00:50:38,260 --> 00:50:39,960 so what we did is we had the stack 1104 00:50:39,960 --> 00:50:42,040 with the code on it that's building 1105 00:50:43,180 --> 00:50:44,200 our new payload 1106 00:50:44,200 --> 00:50:46,580 so it's popping stuff into EAX 1107 00:50:46,580 --> 00:50:48,920 it's subtracting until it's a real opcode that we want 1108 00:50:51,080 --> 00:50:52,860 and then when it pushes it back 1109 00:50:52,860 --> 00:50:53,920 it pushes it down on the bottom 1110 00:50:53,920 --> 00:50:55,540 and it grows up 1111 00:50:55,540 --> 00:50:57,160 so as we execute down 1112 00:50:57,800 --> 00:50:58,880 the other side 1113 00:50:59,400 --> 00:51:01,160 is growing up 1114 00:51:01,160 --> 00:51:02,300 as we push onto it 1115 00:51:02,300 --> 00:51:05,040 and what happened was we calculated the size exactly 1116 00:51:05,040 --> 00:51:06,220 no jump instruction required 1117 00:51:06,220 --> 00:51:08,500 so that as it's growing up 1118 00:51:08,500 --> 00:51:09,620 as soon as we got done 1119 00:51:09,620 --> 00:51:11,800 they met in the middle perfectly 1120 00:51:11,800 --> 00:51:14,500 and boom we just began executing real instructions 1121 00:51:14,500 --> 00:51:15,260 right off the bat 1122 00:51:15,860 --> 00:51:16,620 backwards bridge 1123 00:51:19,660 --> 00:51:21,440 okay so let's talk about loading a new DLL 1124 00:51:21,900 --> 00:51:23,140 same as get proc address 1125 00:51:23,140 --> 00:51:24,280 just call it load library 1126 00:51:24,800 --> 00:51:26,580 I actually stole the same slide 1127 00:51:28,640 --> 00:51:31,340 this is the name of the DLL we want to load 1128 00:51:31,340 --> 00:51:32,860 we call load library 1129 00:51:33,900 --> 00:51:35,620 and we end up passing 1130 00:51:35,620 --> 00:51:37,620 oh excuse me no this was the function address 1131 00:51:37,620 --> 00:51:38,300 of load library 1132 00:51:38,300 --> 00:51:41,620 and then we pass the ascii name of the DLL we want to load 1133 00:51:41,620 --> 00:51:43,800 and then boom suddenly our process space 1134 00:51:43,800 --> 00:51:45,480 becomes much larger because we just added 1135 00:51:45,480 --> 00:51:47,940 a whole new DLL full of functions that we can use 1136 00:51:48,420 --> 00:51:49,460 what's a good function 1137 00:51:49,660 --> 00:51:51,640 what's a good DLL to load 1138 00:51:53,220 --> 00:51:54,140 urlmon.dll 1139 00:51:54,140 --> 00:51:55,480 that sounds good 1140 00:51:55,480 --> 00:51:56,400 I don't know what it exports 1141 00:51:56,400 --> 00:51:57,420 but it definitely sounds good 1142 00:51:57,420 --> 00:51:58,800 urlmon.dll 1143 00:52:01,380 --> 00:52:02,300 oh okay 1144 00:52:02,880 --> 00:52:05,120 there's another one that actually I have on the slide next 1145 00:52:05,120 --> 00:52:06,180 which is called wininet 1146 00:52:06,180 --> 00:52:08,000 which does something similar as well 1147 00:52:10,640 --> 00:52:11,340 winsock stuff 1148 00:52:11,340 --> 00:52:13,360 is obviously good so you might want to load that as well 1149 00:52:13,920 --> 00:52:15,580 this is thanks to 1150 00:52:15,580 --> 00:52:16,880 dildog's paper that I read 1151 00:52:16,880 --> 00:52:18,820 he just mentioned the wininet DLL 1152 00:52:19,660 --> 00:52:21,620 explorer is really really useful for downloading files 1153 00:52:21,620 --> 00:52:23,220 off the internet with like 2 or 3 calls 1154 00:52:23,220 --> 00:52:25,600 so I load wininet DLL 1155 00:52:25,600 --> 00:52:27,060 and I use internet open url 1156 00:52:27,060 --> 00:52:29,220 and internet read file to download a file 1157 00:52:29,220 --> 00:52:30,520 from anywhere on the internet 1158 00:52:30,520 --> 00:52:33,000 takes 2 calls very simple no space 1159 00:52:33,600 --> 00:52:35,300 and it downloads it to the local system 1160 00:52:35,300 --> 00:52:36,620 at which point I can execute it 1161 00:52:36,620 --> 00:52:37,500 pretty scary 1162 00:52:38,260 --> 00:52:40,800 so wininet does all the hard work for me 1163 00:52:40,800 --> 00:52:42,380 it makes my payload smaller 1164 00:52:43,360 --> 00:52:44,800 and the best part is 1165 00:52:44,800 --> 00:52:47,000 I can store my file anonymously 1166 00:52:47,000 --> 00:52:48,020 on geocities somewhere 1167 00:52:49,660 --> 00:52:50,660 you wouldn't know who I was 1168 00:52:54,240 --> 00:52:55,240 just as for example 1169 00:52:55,920 --> 00:52:57,280 ws2 underscore 32 DLL 1170 00:52:57,280 --> 00:52:58,300 has all the winsock functionality 1171 00:52:58,840 --> 00:53:00,340 if I'm going to make a backdoor 1172 00:53:00,740 --> 00:53:02,720 or something like that I'm going to need to open a socket 1173 00:53:02,720 --> 00:53:04,600 so I could load this up and do that 1174 00:53:05,740 --> 00:53:07,240 another way to make calls on a system 1175 00:53:07,240 --> 00:53:08,860 is through the use of what's called an interrupt call 1176 00:53:10,320 --> 00:53:11,080 interrupt 2e 1177 00:53:11,080 --> 00:53:12,520 under windows and t 1178 00:53:12,520 --> 00:53:13,720 is the system call 1179 00:53:13,720 --> 00:53:16,560 and I can make a whole plethora of calls that way 1180 00:53:16,560 --> 00:53:18,760 and it takes like 2 bytes to make each one 1181 00:53:19,660 --> 00:53:20,700 I set up the registers to point to the 1182 00:53:21,220 --> 00:53:23,460 parameters for that call and then I call interrupt 2e 1183 00:53:23,460 --> 00:53:24,880 boom I just made a syscall 1184 00:53:24,880 --> 00:53:27,500 I can start processes that way open and close files 1185 00:53:27,500 --> 00:53:29,880 all of it available directly through the syscall interface 1186 00:53:29,880 --> 00:53:32,240 no monkeying around with DLLs 1187 00:53:32,240 --> 00:53:34,440 and these are always guaranteed to work 1188 00:53:34,440 --> 00:53:35,840 they don't change locations 1189 00:53:36,580 --> 00:53:38,120 and we'll make a caveat to that 1190 00:53:38,120 --> 00:53:40,180 windows and t4 to windows 2k 1191 00:53:40,180 --> 00:53:41,960 the syscall table changed slightly 1192 00:53:41,960 --> 00:53:44,340 so the syscall numbers slightly modified 1193 00:53:44,880 --> 00:53:45,880 that's important to know 1194 00:53:45,880 --> 00:53:47,280 same with linux 1195 00:53:47,280 --> 00:53:49,180 in fact I believe you can do most of a remote shell 1196 00:53:49,660 --> 00:53:50,480 using this method 1197 00:53:50,480 --> 00:53:53,060 under linux I believe it's interrupt 80 1198 00:53:53,500 --> 00:53:55,540 and under nt it's obviously interrupt 2e 1199 00:53:58,600 --> 00:53:59,980 responding to remote command shell 1200 00:53:59,980 --> 00:54:01,020 I can use create process 1201 00:54:01,660 --> 00:54:02,900 under nt 1202 00:54:02,900 --> 00:54:04,260 or a syscall 1203 00:54:04,260 --> 00:54:07,000 under linux 1204 00:54:07,000 --> 00:54:09,120 I can pipe the output through a socket 1205 00:54:09,120 --> 00:54:10,120 to attach to the process 1206 00:54:10,120 --> 00:54:13,180 and open up a tcp socket by loading the winsock DLL 1207 00:54:13,180 --> 00:54:15,000 on my side and have two way communications 1208 00:54:15,000 --> 00:54:16,680 I've just created an instant telnet server 1209 00:54:20,860 --> 00:54:22,300 if I want to get really crazy 1210 00:54:22,300 --> 00:54:23,760 I could not do it quite that way 1211 00:54:23,760 --> 00:54:25,000 I could make a covert channel 1212 00:54:25,560 --> 00:54:27,180 if I have access to the kernel 1213 00:54:27,180 --> 00:54:28,200 which most of the times I would 1214 00:54:28,200 --> 00:54:30,700 I could inject a TDI or indus layer hook 1215 00:54:30,700 --> 00:54:33,040 which enables me to sniff all network traffic 1216 00:54:33,040 --> 00:54:34,760 and send raw packets over the wire 1217 00:54:34,760 --> 00:54:36,820 I could watch icmp packets 1218 00:54:36,820 --> 00:54:39,840 and if there's a certain option in there 1219 00:54:39,840 --> 00:54:41,760 I could detect the next five characters 1220 00:54:41,760 --> 00:54:43,140 as a command like I was talking about earlier 1221 00:54:43,580 --> 00:54:45,020 it's covert you would never know 1222 00:54:45,020 --> 00:54:46,800 Arnie Wittstrom I don't know if you know him 1223 00:54:46,800 --> 00:54:48,720 but he has a site on the net where he distributes 1224 00:54:49,660 --> 00:54:49,980 a command server 1225 00:54:49,980 --> 00:54:51,720 it's another kind of interesting idea 1226 00:54:51,720 --> 00:54:53,280 it just sends act packets 1227 00:54:53,280 --> 00:54:54,260 there's no three way handshake 1228 00:54:54,260 --> 00:54:55,340 there's no real tcp session 1229 00:54:55,340 --> 00:54:57,000 it's just a bunch of act packets over port 80 1230 00:54:57,000 --> 00:54:57,560 going back and forth 1231 00:54:58,160 --> 00:55:00,220 but it looks just like a netcast session 1232 00:55:01,200 --> 00:55:02,780 it's actually open and working 1233 00:55:05,060 --> 00:55:06,660 IIS if I can't get into kernel mode 1234 00:55:06,660 --> 00:55:08,300 I can just patch something in the process I'm in 1235 00:55:08,300 --> 00:55:09,640 obviously it's accepting network input 1236 00:55:09,640 --> 00:55:10,800 or I wouldn't be there in the first place 1237 00:55:10,800 --> 00:55:12,900 so I obviously could patch the location 1238 00:55:12,900 --> 00:55:14,340 where that network input is processed 1239 00:55:19,660 --> 00:55:19,820 but it's a lot of stuff 1240 00:55:22,500 --> 00:55:22,860 worms 1241 00:55:23,520 --> 00:55:24,920 not going to go into detail on this 1242 00:55:24,920 --> 00:55:28,200 just know that mobile code is mobile code 1243 00:55:33,600 --> 00:55:34,260 lysine deficiency 1244 00:55:34,260 --> 00:55:36,040 I want to talk about this a little bit 1245 00:55:36,040 --> 00:55:36,740 in terms of worms 1246 00:55:36,740 --> 00:55:38,700 if you are playing with them in the lab 1247 00:55:39,060 --> 00:55:41,200 make sure you build a fail safe mechanism 1248 00:55:41,200 --> 00:55:43,560 so they don't get out of your lab by mistake 1249 00:55:44,040 --> 00:55:45,760 what we do in our lab is we make it 1250 00:55:45,760 --> 00:55:47,820 so you have to have a particular floppy disk in the drive 1251 00:55:49,660 --> 00:55:51,700 if it's not there the worm will not infect the machine 1252 00:55:51,700 --> 00:55:52,720 we call it lysine deficiency 1253 00:55:52,720 --> 00:55:54,900 and it's a very very important thing to do 1254 00:55:54,900 --> 00:55:56,600 if you are designing worm technology 1255 00:55:56,600 --> 00:55:57,860 to be responsible 1256 00:55:58,460 --> 00:56:00,740 especially if you are distributing it on a website somewhere 1257 00:56:00,740 --> 00:56:03,040 make sure the lysine deficiency exists 1258 00:56:03,040 --> 00:56:04,580 it could do a number of things 1259 00:56:04,580 --> 00:56:05,820 if you don't want to deal with floppies 1260 00:56:05,820 --> 00:56:08,040 you can just make sure it only works 1261 00:56:08,040 --> 00:56:10,420 if a particular machine responds to a ping 1262 00:56:10,420 --> 00:56:11,660 or something like that 1263 00:56:13,760 --> 00:56:15,260 ok so to recap all this 1264 00:56:15,260 --> 00:56:17,380 the injection part is not the same as the payload part 1265 00:56:17,380 --> 00:56:18,080 they can be separated 1266 00:56:18,920 --> 00:56:20,140 payloads can do all kinds of things 1267 00:56:20,140 --> 00:56:21,900 like DOS attacks, worm, remote shell 1268 00:56:21,900 --> 00:56:22,800 and solid rootkit 1269 00:56:24,120 --> 00:56:25,940 there's many challenges with the injection part 1270 00:56:25,940 --> 00:56:27,600 obviously the way the characters are encoded 1271 00:56:27,600 --> 00:56:29,480 null characters is obviously a good example of that 1272 00:56:29,480 --> 00:56:31,020 the stack size, dealing with that 1273 00:56:31,020 --> 00:56:32,220 highland and lowland address 1274 00:56:32,900 --> 00:56:34,240 and obviously the result 1275 00:56:34,240 --> 00:56:36,200 we could actually call through CPU registers 1276 00:56:36,200 --> 00:56:38,000 and what not to get back to the stack 1277 00:56:38,000 --> 00:56:39,200 if we can't use a lowland address 1278 00:56:40,580 --> 00:56:42,720 filters can limit what we can put in the payload 1279 00:56:42,720 --> 00:56:43,860 or in the injection vector 1280 00:56:43,860 --> 00:56:45,620 they can limit our opcode set 1281 00:56:48,080 --> 00:56:49,260 that's not a problem 1282 00:56:49,260 --> 00:56:50,200 we can work around those 1283 00:56:50,200 --> 00:56:51,680 and figure out how to make work encode 1284 00:56:53,580 --> 00:56:55,540 typically our payload is going to be encoded 1285 00:56:55,540 --> 00:56:56,840 XOR encoded some way 1286 00:56:56,840 --> 00:56:57,960 we can build jump tables 1287 00:56:57,960 --> 00:56:59,320 we can load any DOL 1288 00:56:59,320 --> 00:57:00,440 any function we want to 1289 00:57:00,440 --> 00:57:02,180 we can hardcode the addresses 1290 00:57:02,180 --> 00:57:03,620 or we can load them dynamically 1291 00:57:04,300 --> 00:57:07,020 and importantly also we should use lysine deficiency 1292 00:57:07,020 --> 00:57:08,760 if we're doing worm stuff 1293 00:57:09,340 --> 00:57:10,460 thank you very much 1294 00:57:18,080 --> 00:57:18,760 for watching