1 00:00:27,960 --> 00:00:29,980 Thank you for watching, and I'll see you next time. 2 00:00:30,000 --> 00:00:35,040 We'll be right back. 3 00:01:11,940 --> 00:01:12,660 We'll be right back. 4 00:01:53,500 --> 00:01:58,740 We'll be right back. 5 00:02:00,000 --> 00:02:13,880 As you can see, this is the first presentation, and I'm going to present and discuss some issues for designing buffer overflow exploits, mainly focusing on small payloads. 6 00:02:16,000 --> 00:02:23,340 My name is Anders Ingeborn. I'm from Sweden, and just before I begin, I'd like to give away some free stuff. 7 00:02:59,000 --> 00:02:59,980 My name is Anders Ingeborn, and I'd like to give away some free stuff. 8 00:03:25,600 --> 00:03:29,980 My name is Anders Ingeborn. I'm from Sweden, and just before I begin, I'd like to give away some free stuff. 9 00:03:30,000 --> 00:03:50,380 My name is Anders Ingeborn. I'm from Sweden, and just before I begin, I'd like to give away some free stuff. 10 00:04:07,300 --> 00:04:12,360 Okay, I better get home. 11 00:04:16,520 --> 00:04:19,520 As you can see, I tend to lose them quite quickly. 12 00:04:21,960 --> 00:04:25,360 Okay, anyway, why would anyone be interested in buffer overflows? 13 00:04:25,920 --> 00:04:27,060 I can see two reasons. 14 00:04:27,060 --> 00:04:29,100 These attacks are very effective. 15 00:04:29,940 --> 00:04:32,120 They're very flexible and very useful. 16 00:04:32,360 --> 00:04:34,720 You can run your own code on the target system. 17 00:04:35,000 --> 00:04:38,220 You can run basically whatever you want if you manage to exploit an application. 18 00:04:39,480 --> 00:04:44,480 If you exploit an application that uses an allowed protocol, it will go through a firewall, 19 00:04:44,740 --> 00:04:53,140 let's say HTTP or FTP or something that's allowed to pass the firewalls and IDSs. 20 00:04:54,800 --> 00:04:55,920 That's the first reason. 21 00:04:55,920 --> 00:04:58,380 Effective and flexible attacks, really cool stuff. 22 00:04:58,780 --> 00:05:04,440 Then the second reason why anyone would be interested in buffer overflows is that they 23 00:05:04,440 --> 00:05:05,240 are very common. 24 00:05:05,620 --> 00:05:06,760 I read this report. 25 00:05:07,700 --> 00:05:13,880 It's two years old now, but from the Oregon Institute of Science and Technology, I think. 26 00:05:14,120 --> 00:05:21,580 They stated that buffer overflow has been the single most common computer security flaw 27 00:05:21,580 --> 00:05:23,260 or problem for 10 years. 28 00:05:23,980 --> 00:05:25,900 That's another reason to be interested in this. 29 00:05:25,900 --> 00:05:45,000 If you have any questions, please contact me to provide answers at aclu.com or aclu.org. 30 00:05:45,000 --> 00:05:45,060 I'll see you next time. 31 00:05:45,060 --> 00:05:45,780 Bye-bye. 32 00:05:45,780 --> 00:05:46,180 Bye. 33 00:05:47,400 --> 00:05:48,600 Bye. 34 00:05:49,280 --> 00:05:50,480 Bye. 35 00:05:50,700 --> 00:05:51,900 Bye. 36 00:05:54,640 --> 00:05:55,240 Bye. 37 00:05:55,900 --> 00:06:01,700 nodes, I think that you can add to the number of possible applications to exploit. 38 00:06:03,400 --> 00:06:10,300 As a benefit, it turns out that these suggestions and these design issues that I present will 39 00:06:11,400 --> 00:06:17,680 make it possible to evade some intrusion detection systems, both network-based and host-based. 40 00:06:17,680 --> 00:06:27,120 And I'll get back to that later, of course. First, how many of you are perfectly sure 41 00:06:27,120 --> 00:06:31,880 about buffer overflows, and how many need a little reminder? How many need a reminder? 42 00:06:32,720 --> 00:06:36,260 Yeah, at least one. You won't get a t-shirt this time. 43 00:06:37,020 --> 00:06:41,960 Okay, let's say an application does a string copy operation without a bounce check. 44 00:06:42,220 --> 00:06:47,660 Then that will mean that the function will copy data from one method. 45 00:06:47,660 --> 00:06:54,000 One place in memory until another, and go on until it reaches a null byte. 46 00:06:54,680 --> 00:07:00,800 If it doesn't reach it, it will go on copying and overwrite memory, and write outside the 47 00:07:00,800 --> 00:07:07,500 memory that has been reserved for that variable, which means that you will overwrite your stored 48 00:07:07,500 --> 00:07:10,600 instruction pointer, and you may jump into your own code. 49 00:07:12,140 --> 00:07:12,780 Excuse me? 50 00:07:13,140 --> 00:07:13,660 Yes. 51 00:07:14,100 --> 00:07:14,700 Speak louder. 52 00:07:15,180 --> 00:07:16,280 Speak louder. 53 00:07:16,580 --> 00:07:16,780 Speak louder. 54 00:07:17,120 --> 00:07:17,640 Speak louder. 55 00:07:18,840 --> 00:07:19,280 Speak louder. 56 00:07:19,280 --> 00:07:20,260 There's no volume, but I... 57 00:07:20,260 --> 00:07:20,600 Okay. 58 00:07:23,020 --> 00:07:27,020 Okay, here's a picture of it. Let's say I do a function call, then you store your original 59 00:07:27,020 --> 00:07:31,380 instruction pointer on the stack memory. You reserve space for some local variable, 60 00:07:31,540 --> 00:07:35,740 and then you perform a string copy. Without a bounce check, you will overwrite the instruction 61 00:07:35,740 --> 00:07:41,320 pointer, and then you may jump back into your own code, or jump wherever you want in memory. 62 00:07:42,660 --> 00:07:44,140 So this is pretty cool. 63 00:07:46,000 --> 00:07:47,340 But let's say some... 64 00:07:47,340 --> 00:07:52,480 Some vulnerable server performs a bounce check. Let's say it receives data over a network 65 00:07:52,480 --> 00:07:59,020 connection and implements some sort of bounce check on the receive call, but then not on 66 00:07:59,020 --> 00:08:04,420 internal copy functions or such. Then we have a restriction. Then we have a bounce 67 00:08:04,420 --> 00:08:08,020 check that we have to somewhat get around to exploit this application. 68 00:08:10,460 --> 00:08:17,000 I see two possible ways of doing this. Either we can write a simple, small exploit code, 69 00:08:17,000 --> 00:08:27,600 where the exploit itself is small enough to fit into this restricted memory and still 70 00:08:27,600 --> 00:08:32,940 do what kind of exploit we want to do. It's a little naive, but it's okay, and that's 71 00:08:32,940 --> 00:08:39,960 what we did in our last winter. Another approach which might be better is to change the design 72 00:08:39,960 --> 00:08:45,360 concept somewhat and make a double injection, and that is basically what I'm going to present 73 00:08:45,360 --> 00:08:46,200 here today. 74 00:08:47,000 --> 00:08:55,160 But first, let's have a small look at the straightforward, simple, small exploits. 75 00:08:57,840 --> 00:09:04,000 It will imply at least two functional requirements for the exploit itself. It has to be able 76 00:09:04,000 --> 00:09:08,600 to listen for requests over a network and execute those at system commands. That's basically 77 00:09:08,600 --> 00:09:15,140 what we want to do when we exploit an application. And we also have a requirement to keep the 78 00:09:15,140 --> 00:09:16,680 number of bytes as low as possible. 79 00:09:20,760 --> 00:09:26,460 Last time we did it, we came up with an example that was just above 250 bytes. We used two 80 00:09:26,460 --> 00:09:31,320 libraries, Windows sockets and kernel 32. We used a datagram socket instead of a stream 81 00:09:31,320 --> 00:09:37,300 socket because UDP don't need to do, because with UDP you don't need to do any listen 82 00:09:37,300 --> 00:09:42,560 or accept calls, and you save a few bytes. And then we went into a loop doing receive 83 00:09:42,560 --> 00:09:46,720 and executing with WinExec from kernel 32. 84 00:09:47,540 --> 00:09:53,100 If you want to have a look at this one, you can download it from SecurityFocus. It's about 85 00:09:53,100 --> 00:09:54,080 half year old. 86 00:09:55,260 --> 00:10:01,240 Now, for the second approach that I think is much more cool is to change the design 87 00:10:01,240 --> 00:10:06,880 concept and do a double injection. And of course, I will explain that on the next slide. 88 00:10:10,560 --> 00:10:16,040 Besides changing the design concept, we can also try to use the existing network connection 89 00:10:17,000 --> 00:10:21,880 and try to reuse the already loaded libraries to further minimize and optimize our code 90 00:10:21,880 --> 00:10:22,960 to get even smaller. 91 00:10:23,380 --> 00:10:26,860 So that's two parts, change the concept and optimize. 92 00:10:27,960 --> 00:10:33,900 So what do I mean by double injection? Let's say you have a server process in the middle 93 00:10:34,400 --> 00:10:39,360 that listens for connection over the network, and when it receives a request from a client, 94 00:10:39,440 --> 00:10:46,980 it calls an internal parse and execute function to, yeah, well, to parse and execute. So, 95 00:10:48,880 --> 00:10:54,100 it looks like this. And the server is running. Let's say we are at this place in the server 96 00:10:54,100 --> 00:11:02,120 code, and some client over the network calls the server. Then when the server receives 97 00:11:02,120 --> 00:11:08,000 the first call, the first command or request or whatever, the server will call the parse 98 00:11:08,000 --> 00:11:12,640 and execute function and store the current instruction pointer onto the stack memory 99 00:11:12,640 --> 00:11:14,260 on top of its stack frame. 100 00:11:14,600 --> 00:11:16,980 Stack frame number one belongs to the server. 101 00:11:17,000 --> 00:11:21,820 The server process and call jump into the instructions of the parse and execute function. 102 00:11:22,120 --> 00:11:26,560 The parse and execute function will receive a stack frame of its own, which is being placed 103 00:11:26,560 --> 00:11:33,300 above the service stack frame onto the stack memory. And then the parse and execute performs 104 00:11:33,300 --> 00:11:40,940 a string copy call. So, let's say we have a restriction on the number of bytes for the 105 00:11:40,940 --> 00:11:45,720 first call from the client to the server. But let's say we have no bounce check within 106 00:11:45,720 --> 00:11:46,980 the parse and execute function. 107 00:11:47,000 --> 00:11:48,760 That means the array of functions calls to string copy. 108 00:11:49,920 --> 00:11:54,820 Then the first payload we send through the first call will overwrite down the second 109 00:11:54,820 --> 00:11:56,860 stack frame and overwrite the instruction pointer. 110 00:11:59,620 --> 00:12:00,300 . 111 00:12:01,860 --> 00:12:02,720 Excuse me? 112 00:12:03,140 --> 00:12:03,680 . 113 00:12:04,880 --> 00:12:15,940 Yes. Yes. So, the stack grows upwards, and variables are written downwards on the stack. 114 00:12:16,080 --> 00:12:16,480 . 115 00:12:16,480 --> 00:12:16,980 . 116 00:12:21,260 --> 00:12:26,540 On the next few couple of slides, I have written memory addresses to us so you can see them, 117 00:12:27,580 --> 00:12:30,420 but not in this very fine animation. 118 00:12:31,620 --> 00:12:34,000 The first time I made a PowerPoint animation. 119 00:12:34,640 --> 00:12:43,760 Well, anyway, okay, the second part of the double injection is when the first payload 120 00:12:43,760 --> 00:12:49,280 executes and listens for a second injection or a second call from the client, it reads 121 00:12:49,280 --> 00:12:54,840 the second payload and stores it higher up on the stack where we have free memory, lower 122 00:12:54,840 --> 00:12:55,220 address. 123 00:12:56,760 --> 00:13:03,400 Then the first payload when it has received the entire second payload, it jumps up to 124 00:13:03,400 --> 00:13:05,540 it and continues to execute the second payload. 125 00:13:06,580 --> 00:13:08,160 We're still executing on the stack. 126 00:13:08,360 --> 00:13:13,740 Then the second payload can perform the actual exploit and by that I mean open a shell and 127 00:13:13,740 --> 00:13:19,740 or add an account or whatever that we want to do to exploit this host server. 128 00:13:24,400 --> 00:13:28,580 The benefits of doing this is, of course, that we get lower memory requirements for 129 00:13:28,580 --> 00:13:33,240 the first payload. And it's basically only the first payload 130 00:13:33,240 --> 00:13:39,220 in this approach that is interesting, because if the first payload is small enough, then 131 00:13:39,220 --> 00:13:42,940 the first stack frame, that one that belonged to the server, will be preserved. 132 00:13:43,280 --> 00:13:48,060 And if it's preserved, then we might be able to do a clean return to the calling function. 133 00:13:48,500 --> 00:13:52,620 And if we can do this clean return, the server function will not crash. 134 00:13:52,940 --> 00:13:57,900 And if it doesn't crash, we'll get no log entry on the system. 135 00:13:58,220 --> 00:14:03,920 And if we'll get no log entry, we will evade some host-based intrusion detection systems, 136 00:14:04,120 --> 00:14:07,180 mainly those that just parse these log files. 137 00:14:09,440 --> 00:14:14,460 Okay, part number two, or trick number two, is to use the existing connection. 138 00:14:15,000 --> 00:14:20,500 And that means that we let the server open a new socket and receives the first payload. 139 00:14:21,040 --> 00:14:25,860 And then we manage to get the first payload to receive the second payload over the same 140 00:14:26,380 --> 00:14:36,440 session by using the same socket. Benefits of doing this is that we do not need 141 00:14:36,440 --> 00:14:37,160 to set up any new files. We don't need to set up any new files. 142 00:14:37,160 --> 00:14:43,680 We don't need to set up any new connection. And if we don't need to set up any new connection, 143 00:14:43,860 --> 00:14:49,560 we will, or we might, evade some intrusion detection systems, some network-based intrusion 144 00:14:49,560 --> 00:14:56,340 detection system that looks for TCP handshakes or that looks for unrecognized elite ports 145 00:14:56,340 --> 00:15:00,540 over the network. But we're using the same still-allowed protocol, 146 00:15:01,260 --> 00:15:05,380 the same still-allowed port number. It's the same session. 147 00:15:05,560 --> 00:15:06,120 Okay. 148 00:15:06,840 --> 00:15:07,140 Okay. 149 00:15:07,160 --> 00:15:10,460 And that will make it harder for network-based intrusion detection to see it. 150 00:15:11,380 --> 00:15:16,180 Of course, we will also get even lower memory requirements for the first payload, and that's 151 00:15:16,180 --> 00:15:16,820 a benefit too. 152 00:15:20,200 --> 00:15:26,920 Okay. I hope this sounds cool. But how can we do it? I have made a small proof-of-concept 153 00:15:26,920 --> 00:15:31,820 implementation that I'm giving away after this speech or after DEF CON. I think I will 154 00:15:31,820 --> 00:15:36,180 put it up on the post-DEF CON pages together with my slides if you want it, where I have 155 00:15:36,180 --> 00:15:42,480 implemented a small vulnerable server that accepts connection, receives commands with 156 00:15:42,480 --> 00:15:51,000 this restriction, calls this vulnerable parse and execute function, and is possible to exploit. 157 00:15:51,260 --> 00:15:57,080 And also I will provide, of course, a remote client with these exploits. And they cannot 158 00:15:57,080 --> 00:16:00,020 be used on anything but this particular server, of course. 159 00:16:00,980 --> 00:16:01,540 Okay. 160 00:16:05,600 --> 00:16:06,160 Okay. 161 00:16:09,660 --> 00:16:15,160 So I'm a little surprised that you didn't ask this before I got to the slide. But isn't 162 00:16:15,160 --> 00:16:18,460 it interesting how we will manage to use the existing connection? 163 00:16:19,880 --> 00:16:27,760 I say we have to find the socket descriptor and use it. And how to find it is by finding 164 00:16:27,760 --> 00:16:36,160 the accept call. The accept call can be found by disassembling the server and the main 165 00:16:36,160 --> 00:16:42,660 one. And maybe look for an error message or something. And then set a break point at 166 00:16:42,660 --> 00:16:47,800 that address in the code and debug the program. And then look where the return value from 167 00:16:47,800 --> 00:16:53,640 the accept call is being stored in memory because the accept call returns the socket 168 00:16:53,640 --> 00:16:57,240 descriptor for the session socket. 169 00:16:58,480 --> 00:17:04,180 There's a plenty of disassemblers available on the internet. And that's just one example. 170 00:17:04,660 --> 00:17:05,600 This one's free. 171 00:17:08,600 --> 00:17:13,940 If you run a disassembler on the server that I'm providing, you will get this. And if 172 00:17:13,940 --> 00:17:20,380 you look through the disassembled code, you will find an error message that is quite useful. 173 00:17:21,500 --> 00:17:27,320 It shows us that the accept function is probably that one. And then we know that we can set 174 00:17:27,320 --> 00:17:33,700 our break point at this address. Then we debug the program. And we get this. We see where 175 00:17:33,700 --> 00:17:36,140 the session socket is. 176 00:17:36,140 --> 00:17:36,940 The socket is being stored. 177 00:17:43,360 --> 00:17:52,240 Okay, so we have found it. And then to use it, we need to know that the socket's position 178 00:17:52,240 --> 00:17:58,660 within the stack frame does not change. While the stack frame itself might change. The stack 179 00:17:58,660 --> 00:18:05,300 frame's position might change, that is, so if we now a fixed position within the stack 180 00:18:05,300 --> 00:18:06,120 frame. So if we know a fixed position within the stack frame, we can then re-suce it. So, 181 00:18:06,120 --> 00:18:12,900 calculate where the socket is being stored and reuse it. So this is second 182 00:18:12,900 --> 00:18:19,120 animation and it shows what the first payload is basically doing. When the 183 00:18:19,120 --> 00:18:21,840 first payload starts the base pointer has been overwritten and the stack 184 00:18:21,840 --> 00:18:27,260 pointer points towards the end of the first payload. First I do is to change 185 00:18:27,260 --> 00:18:33,120 the base pointer and move the stack pointer upwards against free 186 00:18:33,120 --> 00:18:40,740 memory. Then I add some arguments for the receive function. I set a pointer to 187 00:18:40,740 --> 00:18:45,220 the buffer where we want to store the second payload in free 188 00:18:45,220 --> 00:18:54,560 memory and then the socket. Because I know that the distance from 189 00:18:54,560 --> 00:18:58,400 the base pointer to the socket will always be the same and the base pointer 190 00:18:58,400 --> 00:19:02,980 will be set during runtime. So I can always find the socket description 191 00:19:02,980 --> 00:19:03,100 here. 192 00:19:06,660 --> 00:19:18,840 So that's using the socket. To further minimize and optimize the code of the 193 00:19:18,840 --> 00:19:24,780 first payload I suggest to use those functions that have already been loaded 194 00:19:24,780 --> 00:19:29,620 by the server. And of course the server needs to use some functions from the 195 00:19:29,620 --> 00:19:32,760 Windows socket library. I mean it receives the first 196 00:19:32,760 --> 00:19:40,360 payload. And the addresses to this function are being stored at known places 197 00:19:40,360 --> 00:19:45,500 within the instructions of the server process as long as it hasn't been 198 00:19:45,500 --> 00:19:50,800 relocated. While the library may be stored wherever in memory. Not wherever 199 00:19:50,800 --> 00:19:58,500 but at an unknown place. So this is what happens when the server calls a function 200 00:19:58,500 --> 00:20:00,220 within the Windows socket library. 201 00:20:05,940 --> 00:20:15,400 The server uses its jump table. And if we disassemble the server code one more time 202 00:20:15,400 --> 00:20:21,960 we find this. This is the jump table. And by just reading the code or by debugging we can 203 00:20:23,280 --> 00:20:30,720 deduce that these addresses correspond to these functions. So if we want to do a receive function 204 00:20:32,120 --> 00:20:35,300 or if we want to call the receive function we can do it like this. 205 00:20:44,840 --> 00:20:45,520 Are you following? 206 00:20:49,060 --> 00:20:52,440 This is just a picture of the first payload in Memorand. As you can see the addresses 207 00:20:52,440 --> 00:20:59,700 are printed to the left. And this is the code itself. As you can see I'll start by 208 00:21:01,360 --> 00:21:06,020 subtracting at least at least as much 209 00:21:11,420 --> 00:21:14,400 amount of memory from the stack pointer that I 210 00:21:14,400 --> 00:21:20,560 need to store the second payload. Then I push the arguments to the receive 211 00:21:20,560 --> 00:21:25,200 function onto the stack. The new stack frame. And then I basically call the 212 00:21:26,460 --> 00:21:29,680 receive function through the jump table within the server. 213 00:21:29,700 --> 00:21:36,380 and then I jump to the second payload you have any questions on this first 214 00:21:36,380 --> 00:21:46,620 payload I have some pens anyway okay so what's to send the second time I mean 215 00:21:46,620 --> 00:21:52,360 you can send whatever you can send your code of choice you do not need to to 216 00:21:52,360 --> 00:21:57,520 feel any restrictions for the size of the code to send the second time you can 217 00:21:57,520 --> 00:22:03,960 send code that opens a shell and performs or performs whatever action you 218 00:22:03,960 --> 00:22:07,840 want to do to exploit this server and remember you may still use the same 219 00:22:07,840 --> 00:22:12,000 socket you may still use the jump table for the functions that has already been 220 00:22:12,000 --> 00:22:18,280 loaded as well as you might might try to load your own libraries and look up new 221 00:22:18,280 --> 00:22:25,880 functions another important thing concerning the second payload is that we 222 00:22:25,880 --> 00:22:27,500 do not need to XOR place 223 00:22:27,500 --> 00:22:32,420 protect the second payload because it's being sent to the stack is being written 224 00:22:32,420 --> 00:22:37,500 to the stack as raw data over a socket the first payload is written to the 225 00:22:37,500 --> 00:22:42,700 stack by a string copy operation and as you probably know we cannot have any 226 00:22:42,700 --> 00:22:47,200 nulls within that because then the string copy function will stop so we 227 00:22:47,200 --> 00:22:50,460 need to XOR protect them but for the second payload we do not need to bother 228 00:22:50,460 --> 00:22:57,280 to XOR protect the data the proof of concept implementation that I have made 229 00:22:57,500 --> 00:23:03,120 it's it does not exploit this server in any particular way it just confirms its 230 00:23:03,120 --> 00:23:06,020 success by sending a short message back to the client 231 00:23:19,580 --> 00:23:26,280 ok so this isn't picture of what to say second payload does when the second 232 00:23:26,280 --> 00:23:27,260 payload starts running 233 00:23:27,500 --> 00:23:31,680 the base pointer still points to the base of the first payload and the stack 234 00:23:31,680 --> 00:23:37,200 pointer points to the to the top of the second payload the instruction pointer is 235 00:23:37,200 --> 00:23:41,700 of course at the top of the second payload because we have made a jump I 236 00:23:41,700 --> 00:23:46,560 call the sync send function I add I push this the arguments for the send 237 00:23:46,560 --> 00:23:50,900 function to the stack and I call the stack and I call the send function sorry 238 00:23:52,660 --> 00:23:54,520 and then I'm finishing up 239 00:23:57,500 --> 00:23:57,780 thank you 240 00:23:57,780 --> 00:24:02,860 when I'm finishing up I want to do a clean return because as you remember if 241 00:24:02,860 --> 00:24:08,680 I do a clean return I won't get an area entry to the system log and I will I 242 00:24:08,680 --> 00:24:15,560 can use that to possibly evade and host based intrusion detection system so to 243 00:24:15,560 --> 00:24:20,080 To be able to do a clean return, I need to reset the base pointer and the stack pointer 244 00:24:20,720 --> 00:24:27,440 to their originally intended positions with respect to the first stack frame, the stack 245 00:24:27,440 --> 00:24:31,220 frame of the calling function, and I need to reset the instruction pointer to point 246 00:24:31,220 --> 00:24:40,660 back into the service instruction codes. Of course, if the parse and execute function 247 00:24:40,660 --> 00:24:45,000 is supposed to return anything special, I have to set that up as well. 248 00:24:48,940 --> 00:24:54,720 Since I haven't changed the base pointer throughout the execution of the second payload, and I 249 00:24:54,720 --> 00:25:05,120 remember that the base pointer did point to the stack pointer before I started, I can 250 00:25:05,120 --> 00:25:10,260 simply set them back. And since I know that the stack frame of the calling function is 251 00:25:10,260 --> 00:25:10,540 always 252 00:25:10,540 --> 00:25:15,340 of the same size, I can calculate what to set the base pointer to. 253 00:25:21,020 --> 00:25:27,120 I mean, all of these stack frames, their position in memory may change, and I do not know that 254 00:25:27,120 --> 00:25:32,040 until runtime. But what I do know is that the size of the stack frame is always the same, 255 00:25:33,980 --> 00:25:40,280 and thereby I can calculate what to set the base pointer to. And then I can do a clean return. 256 00:25:41,900 --> 00:25:49,300 Back to the server. Back to the service or original instructions. With both the stack pointer and the base 257 00:25:49,300 --> 00:25:54,680 pointer reset to its original values, and the stack frame of the calling function not disrupted in any 258 00:25:54,680 --> 00:26:04,900 way. Do you have any questions? Yeah. You want the pen before? Nah, sorry. 259 00:26:15,880 --> 00:26:21,880 Let's say you just have a... Okay, the question was, can you do this without having the source code for the server? 260 00:26:22,120 --> 00:26:32,460 And the answer is, yes, if you manage to read only the disassembly. If you have the binary, you can still disassemble it. 261 00:26:36,620 --> 00:26:40,440 Okay, if it's only a remote situation. 262 00:26:40,540 --> 00:26:50,280 No, you need to disassemble the server. But since you're only supposed to evaluate your own programs, 263 00:26:50,480 --> 00:26:56,040 you will probably have access to the binary, right? You want a black one or a purple one? 264 00:26:56,960 --> 00:27:09,660 Okay. Cool. Any more questions? Yeah. 265 00:27:18,980 --> 00:27:38,240 The first payload overwrites the original return address. Yes. Yeah. Yeah. Okay, how do I know what to set the instruction 266 00:27:38,240 --> 00:27:39,680 pointer to do a clean return? 267 00:27:42,400 --> 00:27:47,660 I get it from the disassembly code, and it will be the same... Excuse me? 268 00:27:51,500 --> 00:27:52,040 Excuse me? 269 00:28:08,320 --> 00:28:10,260 I don't know if I got it right, but... 270 00:28:11,480 --> 00:28:15,280 Let's try to answer something and see if it fits. 271 00:28:16,300 --> 00:28:22,960 When I disassemble the server, I can find the address for the call, and I know that 272 00:28:22,960 --> 00:28:27,300 the return, supposed return address is the address next, the next address. 273 00:28:27,660 --> 00:28:32,640 And as long as the server hasn't been relocated in memory, this address will be the same because 274 00:28:32,640 --> 00:28:46,580 as long as the server hasn't been relocated through anything, its base address will always 275 00:28:46,580 --> 00:28:50,460 be this 0040, 0000. 276 00:28:51,040 --> 00:28:54,780 You can set that when you compile your binary. 277 00:28:55,160 --> 00:28:57,500 And you will see it when you disassemble your binary, too. 278 00:28:58,560 --> 00:29:00,120 You want a purple or a black one? 279 00:29:01,660 --> 00:29:02,560 You don't want any. 280 00:29:04,160 --> 00:29:05,460 Okay. 281 00:29:05,820 --> 00:29:06,760 . 282 00:29:16,820 --> 00:29:18,380 Yes, Steven. 283 00:29:19,520 --> 00:29:20,820 . 284 00:29:33,160 --> 00:29:33,860 . 285 00:29:33,860 --> 00:29:34,820 . 286 00:30:03,400 --> 00:30:04,800 . 287 00:30:04,800 --> 00:30:05,020 . 288 00:30:05,020 --> 00:30:11,400 cannot overwrite the it cannot be allowed to disrupt the first stack frame 289 00:30:12,120 --> 00:30:16,160 and that that might be true that might be possible or that might not be 290 00:30:16,160 --> 00:30:21,580 possible there are some other conditions that has to be met too but I think the 291 00:30:21,580 --> 00:30:27,280 concept the idea it will be able to do on other servers as well yes you 292 00:30:36,460 --> 00:30:41,060 okay the question was how effective is a non-executable stack frame I would say 293 00:30:41,060 --> 00:30:52,000 it's quite effective but let's say one possible way to get around it might be 294 00:30:52,000 --> 00:30:59,980 to to jump to maybe an argument that is being stored on the heap or something 295 00:30:59,980 --> 00:31:00,340 instead 296 00:31:03,840 --> 00:31:04,800 basically I 297 00:31:04,800 --> 00:31:05,000 basically I 298 00:31:05,020 --> 00:31:10,740 basically I'm kind of amazed that stack frames aren't being protected from 299 00:31:10,740 --> 00:31:29,260 execution you want the last time sorry okay so I ran out of pants or ran out of 300 00:31:29,260 --> 00:31:34,020 free stuff and I'm basically running out of slides too so I'm going to finish off 301 00:31:34,020 --> 00:31:34,440 and 302 00:31:34,440 --> 00:31:41,540 and so this is just the payloads in memory and as you can see I just send a 303 00:31:41,540 --> 00:31:47,040 simple stupid message back from the second payload to the calling client this 304 00:31:47,040 --> 00:31:54,140 is the code for the second payload as you can see it's basically just a number 305 00:31:54,140 --> 00:31:59,280 of push operations to push the arguments to the send function and then call the 306 00:31:59,280 --> 00:32:03,240 same some function through the jump table of the server and then reset the 307 00:32:03,240 --> 00:32:13,760 the stack pointers and return so the return address in this example is hard coded into the second payload because on this second last line 308 00:32:13,760 --> 00:32:14,300 right 309 00:32:15,620 --> 00:32:21,040 to summarize this I've 자막 고민 Finan party 310 00:32:21,040 --> 00:32:23,020 discussed a double injection and by a 311 00:32:23,020 --> 00:32:24,940 double injection I mean that we have we 312 00:32:24,940 --> 00:32:26,700 offend us that first page wasn't one 313 00:32:26,700 --> 00:32:29,400 payload that uploads a second payload 314 00:32:29,400 --> 00:32:30,600 sollten payload and then jumps to the 315 00:32:30,600 --> 00:32:32,080 second payload and that the second 316 00:32:32,080 --> 00:32:32,420 payload 317 00:32:32,420 --> 00:32:40,200 execute the actual exploit like the shell or something I've suggested to try 318 00:32:40,200 --> 00:32:46,360 to use an existing network connection by finding and supplying an existing socket 319 00:32:46,360 --> 00:32:50,360 descriptor to the receive and send functions and I have also suggested to 320 00:32:50,360 --> 00:32:54,340 try to use the existing functions the preloaded ones through the jump table of 321 00:32:54,340 --> 00:33:01,360 the original program by doing this it might be possible to evade a network 322 00:33:01,360 --> 00:33:06,780 based intrusion detection system there are no elite ports and no TCP handshakes 323 00:33:06,780 --> 00:33:14,460 since we are sorry using the existing network connections there are not as 324 00:33:14,460 --> 00:33:18,860 long as for the first payload there are no large amount of amounts of data being 325 00:33:18,860 --> 00:33:29,180 sent and it this by doing this we force and network-based intrusion detection 326 00:33:29,180 --> 00:33:31,260 system into interpreting the 327 00:33:31,260 --> 00:33:31,340 application system and the process to perform the network based intrusion detection system into interpreting the actual 328 00:33:31,340 --> 00:33:38,860 application protocol to see and detect the changes of my payloads from an 329 00:33:38,860 --> 00:33:46,960 original yeah application protocol and that into interpretation will probably 330 00:33:47,920 --> 00:33:52,240 it will definitely increase the complexity of the ideas and it will 331 00:33:52,240 --> 00:34:00,920 probably decrease the capacity and slow down analysis have you read through 332 00:34:00,920 --> 00:34:09,960 Caesars ASCII encoding paper that can also be used as a counter if if 333 00:34:10,680 --> 00:34:13,960 application protocol interpretation by the network-based intrusion detection 334 00:34:13,960 --> 00:34:18,300 system is a countermeasure against this attack Caesars ASCII encoding can be 335 00:34:18,300 --> 00:34:26,260 seen as a counter counter measure so you can continue this by not setting up any 336 00:34:26,260 --> 00:34:30,820 new connections and by returning cleanly without the crash there will be no log 337 00:34:30,820 --> 00:34:30,900 error 338 00:34:30,920 --> 00:34:38,320 entry and that will force and host based intrusion detection system to kind of 339 00:34:38,320 --> 00:34:42,380 get some strange behavior awareness because the server won't function 340 00:34:42,380 --> 00:34:48,080 properly but it won't crash either and true to be able to recognize the 341 00:34:48,080 --> 00:34:54,540 difference between those two you need well some kind of abnormal behavior 342 00:34:54,540 --> 00:34:57,560 detection and that will add complexity to 343 00:35:01,880 --> 00:35:08,820 almost finished I really recommend you to read this the first one is a chapter 344 00:35:08,820 --> 00:35:12,560 in the book called hack proofing your network by Greg Haglund it's really good 345 00:35:12,560 --> 00:35:18,160 and the second paper I really recommend you to read is about windows buffer 346 00:35:18,160 --> 00:35:26,780 overflows from frac by Barnaby Jack also known as the dark spirit is any of you 347 00:35:26,780 --> 00:35:27,140 guys here 348 00:35:29,460 --> 00:35:29,900 no 349 00:35:31,340 --> 00:35:36,500 I give you credit anyway if you have any questions about this if you want more 350 00:35:36,500 --> 00:35:39,860 information if you want to see a demonstration if you want to have a copy 351 00:35:39,860 --> 00:35:43,780 of the code or the slides you can probably get them from the post defcon 352 00:35:43,780 --> 00:35:48,780 pages or you can try to catch me here during the day I will be here all day 353 00:35:48,780 --> 00:35:53,160 and all night probably and I'll leave back home for Sweden tomorrow morning or 354 00:35:53,160 --> 00:36:00,740 you can also drop me an email at this email address any last question 355 00:36:01,960 --> 00:36:02,680 yeah 356 00:36:19,240 --> 00:36:24,500 with TCP and UDP but I think the concept is possible for 357 00:36:26,980 --> 00:36:27,700 yeah 358 00:36:27,700 --> 00:36:28,060 yeah 359 00:36:32,380 --> 00:36:37,360 okay thank you very much for attending and please stay for the Cisco routers as 360 00:36:37,360 --> 00:36:38,280 well thank you