1 00:00:00,000 --> 00:00:04,340 Hi, my name is Paul Haas, and this is my talk on advanced format string attacks. 2 00:00:04,780 --> 00:00:05,320 Go, Paulie. 3 00:00:06,880 --> 00:00:08,680 A little bit of background. 4 00:00:10,640 --> 00:00:13,360 Contents of this are going to be a little bit of background on me, 5 00:00:14,140 --> 00:00:17,980 an abstract of what format strings are, how you exploit them, 6 00:00:18,400 --> 00:00:25,460 a definition of sort of the way in which C functions are made vulnerable to it, 7 00:00:26,180 --> 00:00:30,740 context in terms of old, current, and new attacks. 8 00:00:32,100 --> 00:00:36,500 I'm going to show you my new techniques for exploiting them 9 00:00:36,500 --> 00:00:38,500 and actually go through a couple of demos 10 00:00:39,760 --> 00:00:43,400 before actually showing you a couple of full exploits, 11 00:00:44,080 --> 00:00:46,960 popping root shells without doing any work. 12 00:00:48,340 --> 00:00:50,740 Then I'm going to show you my tools, how I do it, 13 00:00:50,820 --> 00:00:53,900 finally leading to a conclusion and Q&A. 14 00:00:56,500 --> 00:01:03,040 So I work for Redspin Incorporated as the lead web application security engineer. 15 00:01:03,360 --> 00:01:05,480 This talk isn't associated with that at all. 16 00:01:05,560 --> 00:01:09,860 It's just for fun because I like doing some binary analysis type of stuff. 17 00:01:11,340 --> 00:01:14,320 I'm a former CTF champion here at DEF CON, 18 00:01:14,620 --> 00:01:17,480 so hopefully I know what I'm talking about. 19 00:01:18,080 --> 00:01:19,680 You guys will make the decision for me. 20 00:01:19,980 --> 00:01:22,980 And for those of you who don't play Mario Kart, apparently, 21 00:01:23,530 --> 00:01:24,820 it's all about robot and tank. 22 00:01:25,460 --> 00:01:26,360 I'm going to put some money into it. 23 00:01:28,080 --> 00:01:28,680 I've made a lot to do. 24 00:01:28,680 --> 00:01:33,640 So the purpose of this talk is to take a vulnerable program 25 00:01:33,640 --> 00:01:38,480 like this, get a shell, without doing any of this. 26 00:01:42,960 --> 00:01:47,140 So a little bit of brief background, format string attacks, 27 00:01:47,540 --> 00:01:51,360 for those who don't know, vulnerability and a type 28 00:01:51,360 --> 00:01:55,220 of C function, printf type functions that basically can lead 29 00:01:55,220 --> 00:02:02,120 to shellcode executed. Even though it's been sort of resolved, ignorance and 30 00:02:02,120 --> 00:02:06,980 vulnerability still exist, otherwise I wouldn't be talking about it. It's 31 00:02:06,980 --> 00:02:14,020 especially common in academic exercises, CTFs, a lot of legacy pen tests. The 32 00:02:14,020 --> 00:02:17,740 reason I brought this up is actually because one of our clients had this 33 00:02:17,740 --> 00:02:21,740 issue and I didn't feel like doing any additional work on it, so I created a 34 00:02:21,740 --> 00:02:27,760 tool to exploit it for me. This name of the talk is Advanced Format String 35 00:02:27,760 --> 00:02:31,000 Attacks, so I assume you know a little bit about what format string attacks 36 00:02:31,000 --> 00:02:36,200 actually do and how they work. Thankfully the tools I'm going to be talking about 37 00:02:36,200 --> 00:02:40,160 don't require any knowledge, they're pretty much point-and-click as you're 38 00:02:40,160 --> 00:02:46,080 seeing. Brief history, format string attacks have been around for about 20 39 00:02:46,080 --> 00:02:51,640 years, sort of reaching the apex around 2000 for being popular 40 00:02:51,740 --> 00:02:57,920 being really well-known. The last format string attack that I've 41 00:02:58,260 --> 00:03:04,600 seen has been in 2010, so they still are around, as you can 42 00:03:05,400 --> 00:03:13,760 see. The old technique used to be really kind of a pain to create, it required a 43 00:03:13,760 --> 00:03:21,580 long string of doing these manual popping using %x, %p, in order 44 00:03:21,740 --> 00:03:24,340 to sort of get to your interesting data on the stack. 45 00:03:26,060 --> 00:03:28,280 Often when you want to actually create the exploit 46 00:03:28,280 --> 00:03:30,020 you have to use a variety of other tools. 47 00:03:30,920 --> 00:03:35,800 You know, look for shellcode in your core after a seg fault. 48 00:03:38,480 --> 00:03:41,500 Basically, you know, it's a lot of having to, you know, 49 00:03:41,520 --> 00:03:44,920 read the manual, you know, consult the document, you know. 50 00:03:45,000 --> 00:03:47,280 And then once you wrote it for one, you know, program, 51 00:03:47,560 --> 00:03:49,820 you couldn't take that work and then bring it anywhere else. 52 00:03:49,820 --> 00:03:54,580 So, you know, the current has improved a little bit 53 00:03:54,580 --> 00:03:55,780 on this, but not much. 54 00:03:56,200 --> 00:03:58,020 It's still sort of the same technique. 55 00:03:58,660 --> 00:04:00,900 You know, some of the advances have been 56 00:04:00,900 --> 00:04:02,100 direct parameter access. 57 00:04:03,080 --> 00:04:07,420 So rather than having to pop, say, 10 things off the stack, 58 00:04:07,620 --> 00:04:09,980 you can just reference the 10th parameter directly. 59 00:04:11,440 --> 00:04:14,780 But again, you still needed to sort of use external tools 60 00:04:14,780 --> 00:04:18,560 to access, you know, where you want to actually 61 00:04:18,560 --> 00:04:19,560 overwrite your code for. 62 00:04:28,080 --> 00:04:29,200 So that's the first step. 63 00:04:29,200 --> 00:04:33,020 The technique that I've been working on basically utilizes 64 00:04:33,020 --> 00:04:35,820 the information that because you're dumping the stack 65 00:04:36,200 --> 00:04:38,980 and the stack of most programs, C programs, 66 00:04:39,380 --> 00:04:42,420 has interesting information in it, you can use this 67 00:04:42,420 --> 00:04:45,620 information to basically leverage piece by piece of exploit 68 00:04:45,620 --> 00:04:48,900 leading to eventual, you know, compromise of the application. 69 00:04:49,820 --> 00:04:53,760 For example, most stacks contain data, code addresses, 70 00:04:54,000 --> 00:04:57,480 you know, addresses that point to code, as well addresses 71 00:04:57,480 --> 00:04:59,760 that point to other information on the stack, such as, 72 00:04:59,820 --> 00:05:01,480 you know, data pointers or code pointers. 73 00:05:02,880 --> 00:05:05,920 And what's also interesting is that the string that we pass 74 00:05:05,920 --> 00:05:08,500 for a format string attack is also on the stack. 75 00:05:08,720 --> 00:05:14,080 So we can locate that as well as its offset. 76 00:05:14,920 --> 00:05:17,480 And with this information, we basically can locate 77 00:05:17,480 --> 00:05:19,160 the address of anything on the stack. 78 00:05:19,820 --> 00:05:22,120 Which is useful, for example, if we find a code pointer 79 00:05:22,120 --> 00:05:23,840 that we want to overwrite on the stack. 80 00:05:24,420 --> 00:05:27,540 We can now find out the address of that pointer 81 00:05:27,540 --> 00:05:29,680 and then overwrite it with our format string attack. 82 00:05:32,580 --> 00:05:34,860 So here's the vulnerable code that I've been using. 83 00:05:36,460 --> 00:05:38,500 Obviously, it's not going to work in secure environments, 84 00:05:38,860 --> 00:05:43,200 but, you know, you still see a lot of this, you know, 85 00:05:43,280 --> 00:05:44,900 bits and pieces here and there. 86 00:05:45,040 --> 00:05:48,540 So, you know, I wouldn't be expected, you know, I would be 87 00:05:48,540 --> 00:05:51,480 pretty expected to see it in, you know, a couple pen tests 88 00:05:51,480 --> 00:05:53,300 that I've been doing for legacy applications. 89 00:05:56,000 --> 00:05:59,060 Let's talk a little bit about the exploit steps 90 00:05:59,060 --> 00:06:00,500 for my new method. 91 00:06:01,900 --> 00:06:05,680 I first dump the stack using, you know, an exploit string 92 00:06:05,680 --> 00:06:08,280 until I find that exploit string on the stack. 93 00:06:09,560 --> 00:06:14,180 I then find the address of that format string address 94 00:06:14,180 --> 00:06:14,860 on the stack. 95 00:06:15,380 --> 00:06:18,300 Then by finding the physical location and the pointer 96 00:06:18,300 --> 00:06:21,760 to that location, I basically can calculate the address 97 00:06:21,760 --> 00:06:25,660 of any other stack pointer or stack, you know, data 98 00:06:26,240 --> 00:06:27,480 that's present in my dump. 99 00:06:28,820 --> 00:06:31,200 This basically allows me, if I find any, you know, 100 00:06:31,300 --> 00:06:34,820 code pointers, return addresses, to say I can overwrite 101 00:06:34,820 --> 00:06:37,200 that address to point back to my shell code, 102 00:06:37,440 --> 00:06:39,060 which is also on the stack. 103 00:06:40,700 --> 00:06:43,900 One note with this is, because I'm sort of leveraging 104 00:06:43,900 --> 00:06:47,380 multiple executions of a program to drive this information, 105 00:06:49,400 --> 00:06:52,880 it's really helpful to keep the format string length constant 106 00:06:53,480 --> 00:06:57,220 because if you change it around, so do stack values 107 00:06:57,220 --> 00:07:00,400 and stack addresses, and since you need that information 108 00:07:00,400 --> 00:07:03,680 to be relatively constant, it helps to basically 109 00:07:03,680 --> 00:07:06,580 just keep the same format string length across 110 00:07:06,580 --> 00:07:08,180 all these different runs as I'll show you. 111 00:07:10,560 --> 00:07:14,420 The first thing you have to do, stack dumps, two methods. 112 00:07:14,940 --> 00:07:18,280 One, you just dump, you know, the whole stack, you know, 113 00:07:18,300 --> 00:07:21,880 the whole stack at once using, you know, a bunch of percent p's 114 00:07:21,880 --> 00:07:22,760 or percent x's. 115 00:07:24,860 --> 00:07:27,500 Second method is to execute a loop with, you know, 116 00:07:27,560 --> 00:07:28,380 incrementing values. 117 00:07:30,560 --> 00:07:33,860 In this case, I have here just a little bash script. 118 00:07:34,700 --> 00:07:38,000 I'll show you a demo of this that does it and makes it 119 00:07:38,000 --> 00:07:39,760 really convenient to show what's on the data 120 00:07:39,760 --> 00:07:40,700 or what's on the stack. 121 00:07:42,260 --> 00:07:46,520 You then take this stack information, which is based on 122 00:07:46,520 --> 00:07:48,160 percent p or percent x's. 123 00:07:48,300 --> 00:07:49,360 It's gonna be code pointers. 124 00:07:49,720 --> 00:07:52,300 And you actually wanna convert it to the, you know, 125 00:07:53,260 --> 00:07:55,260 string representation of that data. 126 00:07:55,480 --> 00:07:59,360 By doing that, you basically can find the actual string 127 00:07:59,360 --> 00:08:01,140 that's located through those pointers. 128 00:08:02,440 --> 00:08:04,740 And then by doing that, you can find the offset 129 00:08:05,380 --> 00:08:08,400 of that string from the stack dump. 130 00:08:16,340 --> 00:08:18,180 So right here I have a, you know, 131 00:08:18,180 --> 00:08:21,180 a decently long one-liner for bash. 132 00:08:22,600 --> 00:08:26,920 This is basically running our vulnerable print f function. 133 00:08:28,720 --> 00:08:29,040 Let's see. 134 00:08:32,880 --> 00:08:36,480 So basically this function, when you pass it, 135 00:08:38,160 --> 00:08:41,680 a string basically just prints it to the command line. 136 00:08:43,440 --> 00:08:47,180 And you can see it's actually vulnerable to, you know, 137 00:08:47,220 --> 00:08:47,940 a trivial format. 138 00:08:47,940 --> 00:08:49,080 It's a format string attack, basically. 139 00:08:49,960 --> 00:08:51,100 Oops, sorry about that. 140 00:09:03,780 --> 00:09:06,160 So this one-liner basically is gonna loop through 141 00:09:06,160 --> 00:09:09,080 the print f, you know, sending incremental values 142 00:09:09,080 --> 00:09:12,140 on the stack in order to see what's there, basically. 143 00:09:23,800 --> 00:09:26,840 So what this is, this is the offset that I'm passing. 144 00:09:27,380 --> 00:09:30,080 This happens to be the string that I'm passing to print f. 145 00:09:31,040 --> 00:09:34,860 This is what print f returns to me, a code or stack pointer. 146 00:09:35,720 --> 00:09:38,840 And this is actually what that resolves to in terms of a string. 147 00:09:40,480 --> 00:09:41,660 So scrolling up. 148 00:09:44,360 --> 00:09:46,260 Let's see if I can find where I'm looking for. 149 00:09:46,940 --> 00:09:47,920 You see that I've got a string that I'm passing to print f. 150 00:09:47,920 --> 00:09:53,520 At about offset 138, sort of divided between offset 137 to 139, 151 00:09:53,700 --> 00:09:58,240 we have percentage 138 dollar sign, which happens to be 152 00:09:58,240 --> 00:10:00,640 what I passed on the command line to print f. 153 00:10:00,800 --> 00:10:05,380 So here we've used knowledge of the exploit to basically 154 00:10:05,380 --> 00:10:10,140 find our string at offset 130, 137, 138. 155 00:10:10,420 --> 00:10:13,300 So we use that in a future step to sort of help 156 00:10:13,300 --> 00:10:14,160 exploit the program. 157 00:10:20,260 --> 00:10:23,780 The next thing we have to do, format string address. 158 00:10:25,080 --> 00:10:27,520 Now that we have the physical location on the stack, 159 00:10:27,760 --> 00:10:31,220 we want to find the pointer to that string. 160 00:10:32,960 --> 00:10:36,180 Two ways to do this as well, a sequential loop 161 00:10:36,180 --> 00:10:40,780 as we did before, which will cause segfaults in the case 162 00:10:40,780 --> 00:10:43,340 of if the pointer at the given offset 163 00:10:43,340 --> 00:10:45,680 isn't actually a pointer but some data value, 164 00:10:45,840 --> 00:10:46,680 it's going to segfault. 165 00:10:48,640 --> 00:10:50,640 Which might not be good in certain environments, 166 00:10:50,820 --> 00:10:54,740 for example, on a pen test if there's aggressive IDS systems. 167 00:10:55,900 --> 00:10:58,480 The other way to do it, the more sneaky way is, 168 00:10:59,140 --> 00:11:01,640 given the stack dump, since we already have all that list, 169 00:11:01,820 --> 00:11:03,800 since we have a list of pointers already, 170 00:11:04,360 --> 00:11:06,780 we can parse that list for values that actually are 171 00:11:06,780 --> 00:11:10,260 on the stack and then just obtain the offsets 172 00:11:10,260 --> 00:11:11,240 from those values only. 173 00:11:11,920 --> 00:11:15,320 This avoids segfaults, it's a little bit more elegant 174 00:11:15,800 --> 00:11:17,280 and can get bought. 175 00:11:17,280 --> 00:11:19,320 It allows us to basically dump all strings 176 00:11:19,320 --> 00:11:22,320 in just one run of the program, basically. 177 00:11:27,700 --> 00:11:32,140 So let me show you the first brute force method. 178 00:11:34,460 --> 00:11:36,420 Because it's a little bit more easy to run on the command line. 179 00:11:43,440 --> 00:11:44,160 How's it going, guys? 180 00:11:44,800 --> 00:11:45,280 Pretty good. 181 00:11:45,540 --> 00:11:46,100 We're tied. 182 00:11:46,340 --> 00:11:46,700 Yeah. 183 00:11:47,280 --> 00:11:47,840 Very good. 184 00:11:49,280 --> 00:11:50,460 We do all the hard work. 185 00:11:50,660 --> 00:11:53,740 So same thing, a loop here, basically. 186 00:11:54,440 --> 00:11:57,240 One liner that's going to basically pass a bunch of things 187 00:11:57,240 --> 00:12:00,060 to the same printf function and try 188 00:12:00,060 --> 00:12:05,200 to get both the value as a pointer of the location 189 00:12:05,200 --> 00:12:06,220 as well as a string. 190 00:12:10,320 --> 00:12:12,880 So you can see here that, again, it's dumping offsets, 191 00:12:12,880 --> 00:12:16,280 showing, for example, what's the value, 192 00:12:16,280 --> 00:12:19,980 the pointer value, as well as the string that that pointer 193 00:12:19,980 --> 00:12:20,680 resolves to. 194 00:12:21,720 --> 00:12:24,520 So going back up a little bit, let's see if we can find it. 195 00:12:30,900 --> 00:12:36,440 So at offset 38, pointer that ends with 608 actually 196 00:12:36,440 --> 00:12:42,540 references itself, telling us that that pointer value actually 197 00:12:42,540 --> 00:12:44,200 resolves to our pass argument. 198 00:12:47,120 --> 00:12:47,680 And so we can see it's going to be 100. 199 00:12:47,680 --> 00:12:50,000 This is the second step of the attack, basically. 200 00:12:55,660 --> 00:12:59,200 So given this offset that we found in the first stack dump 201 00:12:59,200 --> 00:13:01,000 and the address that we found in the second, 202 00:13:01,300 --> 00:13:05,920 we basically have a method to allow arbitrary win on the stack. 203 00:13:08,100 --> 00:13:16,220 We know that, since offset 100 is at, for example, stack pointer, BFFFF, 100, 204 00:13:16,220 --> 00:13:22,560 And we know that a pointer is four bytes. We know for example that offset one is going to be 205 00:13:23,240 --> 00:13:23,960 minus 400 206 00:13:24,580 --> 00:13:26,980 values from that offset basically 207 00:13:27,780 --> 00:13:30,720 So we have a return address at offset 10 208 00:13:31,340 --> 00:13:36,880 we can calculate the return or the stack offset of that and then when we're attempting our 209 00:13:37,520 --> 00:13:39,400 Exploit we don't have to get 210 00:13:40,140 --> 00:13:45,400 You know, for example detours a program program link table or some other overwrite location 211 00:13:45,400 --> 00:13:48,120 We can just overwrite this location on the stack 212 00:13:48,700 --> 00:13:51,340 Which we've already found from a previous step 213 00:13:55,580 --> 00:14:01,140 Even though it's possible for example in advanced format string attacks to sort of extract this information 214 00:14:01,860 --> 00:14:04,820 We want to be sort of lazy and just have you know this 215 00:14:05,380 --> 00:14:08,200 Operations from previous steps do our work for us 216 00:14:09,900 --> 00:14:11,680 Now two methods to do this as well 217 00:14:12,540 --> 00:14:14,940 If we know what a return address looks like 218 00:14:15,400 --> 00:14:17,160 They're pretty common on most 219 00:14:17,640 --> 00:14:20,700 You know Linux systems we can use those 220 00:14:21,320 --> 00:14:27,720 Or you can also guess them using sort of an algorithm that matches values that are close to each other that aren't data and aren't strings 221 00:14:28,600 --> 00:14:35,760 Or we can also be lazy and just brute-force everything on the stack until you know, our exploit succeeds basically 222 00:14:36,580 --> 00:14:39,580 Which is a lot easier to do basically 223 00:14:41,200 --> 00:14:44,920 Some issues with this new technique as I mentioned 224 00:14:45,400 --> 00:14:49,280 If we change the length of our format string, it's basically an effect 225 00:14:50,720 --> 00:14:58,340 Addresses on the stack since our format string basically as it grows so does so do stack values grow in addition to it 226 00:14:58,940 --> 00:15:05,540 The easy way to resolve this is basically to keep all format strings, you know during the technique the same size 227 00:15:05,540 --> 00:15:07,460 You know just pattern with you know 228 00:15:07,460 --> 00:15:15,020 No characters or useless characters so that when we actually attempt our exploit and append shell code to the format string 229 00:15:15,400 --> 00:15:18,720 You know that will happen to be the same length as all our previous 230 00:15:19,380 --> 00:15:20,380 executions of the program 231 00:15:23,120 --> 00:15:26,060 The result of this is you know given two 232 00:15:26,600 --> 00:15:33,320 Executions of a program one to dump the stack and two if you're being really clever and just dumping all the string addresses 233 00:15:33,900 --> 00:15:37,360 You basically get all the information you need to exploit that 234 00:15:38,280 --> 00:15:41,700 Function basically no brute-forcing just a little bit of math 235 00:15:43,980 --> 00:15:44,780 It's also 236 00:15:44,780 --> 00:15:48,620 nice because the way this current technique works 237 00:15:48,620 --> 00:15:55,580 You can shrink the length of the format string so that you can fit both the format string and the shell code and 238 00:15:55,580 --> 00:16:02,840 Say less than a hundred bytes, which is usually pretty, you know, really reasonable for you know, any user input field basically 239 00:16:04,640 --> 00:16:11,400 However, if you don't brute force the brute force the override address or if you don't do some math you still have to derive 240 00:16:12,160 --> 00:16:14,760 derive it from some other source such as you know 241 00:16:14,780 --> 00:16:20,300 A core dump or you know a known location like a program link table or the detours 242 00:16:21,840 --> 00:16:24,700 So demo is a good the good heart of the talk 243 00:16:26,760 --> 00:16:32,840 The first tool which should be on your DEF CON CD is a proof of concept tool in Python 244 00:16:33,780 --> 00:16:36,600 I have instructions for running on backtrack for 245 00:16:38,300 --> 00:16:42,920 Basically is a nice little suite for demonstrating sort of the way the attack works 246 00:16:43,980 --> 00:16:48,460 You know multiple options about where you want to overwrite where you want to put your shell code 247 00:16:50,180 --> 00:16:56,480 Again since the proof of concept is missing some useful things, but you know those can be really easily added 248 00:16:56,480 --> 00:16:59,900 You know, hopefully by anyone who has an understanding of this talk 249 00:17:01,600 --> 00:17:03,540 So I'll demo that tool right now 250 00:17:04,900 --> 00:17:11,900 You know taking our same printf function that's we know to be vulnerable to format string attack 251 00:17:13,520 --> 00:17:17,340 And you know just for the sake of vulnerability sync will make it 252 00:17:17,940 --> 00:17:23,420 Ownable and then exit executable by root so you know anyone will inherit those permissions 253 00:17:25,580 --> 00:17:26,100 I 254 00:17:27,660 --> 00:17:30,800 Have a dummy account right now that doesn't have that has limited permissions 255 00:17:32,100 --> 00:17:39,240 Obviously I want to exploit this printf function, you know gain root access. I don't have to actually have to do it to myself. So 256 00:17:40,240 --> 00:17:40,760 I 257 00:17:44,320 --> 00:17:45,880 I'm gonna basically use my tool 258 00:17:48,740 --> 00:17:52,800 So that's a little hard to read but basically it's just going over the options about 259 00:17:53,260 --> 00:17:57,360 You know where you want the exploit to override and where you want the shell code to be 260 00:17:59,660 --> 00:18:04,900 But the nice thing is you don't really have to read any of that because you can just you know, click it with the 261 00:18:07,140 --> 00:18:07,940 binary and 262 00:18:07,940 --> 00:18:09,000 You're in basically 263 00:18:18,460 --> 00:18:19,100 So 264 00:18:19,100 --> 00:18:21,060 So and 265 00:18:21,060 --> 00:18:27,780 The nice thing is this technique works on any, you know any similar similar exploiting, you know type of vulnerability basically 266 00:18:39,520 --> 00:18:42,900 The question was would this work on a syslog thing? 267 00:18:42,920 --> 00:18:44,600 Where are the outputs going somewhere else? 268 00:18:46,100 --> 00:18:54,040 This attack basically works as long as you can read the output from formal former vulnerabilities and use those and new vulnerabilities 269 00:18:54,040 --> 00:18:55,620 It's gonna work basically 270 00:18:58,380 --> 00:19:04,740 The next next code I developed specially for DEF CON designed to be as loud and invasive as possible 271 00:19:06,680 --> 00:19:12,900 Has been completely automated so I sort of removed that reference to having to get an overwrite location 272 00:19:12,900 --> 00:19:16,960 I'm using basically brute-forcing through the stack 273 00:19:18,720 --> 00:19:22,740 Ported both the Python and Ruby under hundred lines of code. So 274 00:19:23,560 --> 00:19:27,000 You know, hopefully if I haven't have time I'll go through it right now and 275 00:19:27,000 --> 00:19:29,420 You know talk about it a little bit 276 00:19:30,900 --> 00:19:36,160 Basically does the same thing except, you know using a brute force attack. So let me show you that as well 277 00:19:44,860 --> 00:19:45,240 So 278 00:19:45,620 --> 00:19:46,960 So again same printf function 279 00:19:49,660 --> 00:19:50,920 Same dummy user 280 00:19:53,920 --> 00:19:56,160 Different different binary 281 00:19:59,700 --> 00:20:04,720 So again you just pass it at the vulnerable function as a parameter and 282 00:20:06,380 --> 00:20:07,620 You get a root shell 283 00:20:09,720 --> 00:20:10,480 So 284 00:20:10,480 --> 00:20:10,680 I'm 285 00:20:12,440 --> 00:20:19,400 Even though you can't see it right now, for example, if I exit you see right now, it's it's actually brute-forcing a bunch of you know 286 00:20:19,400 --> 00:20:23,920 Spaces trying to go through all the stack values until it finds it 287 00:20:25,400 --> 00:20:25,840 so 288 00:20:26,440 --> 00:20:30,220 You know if as long as you know, as long as it's there somewhere you're gonna get in 289 00:20:30,220 --> 00:20:33,240 So if that's all that matters you can be invasive as possible 290 00:20:35,160 --> 00:20:36,060 I'll show the 291 00:20:37,260 --> 00:20:39,480 Ruby version does the same thing but 292 00:20:40,480 --> 00:20:41,500 For those who like Ruby better 293 00:20:42,460 --> 00:20:43,760 You also can get a shell 294 00:20:51,180 --> 00:20:53,720 Finally the sort of the meat of this talk 295 00:20:54,420 --> 00:20:59,880 You know if you're gonna have this sweet program, she might as well put where someone can use it 296 00:21:00,480 --> 00:21:03,200 In this case, I decided to move it to meta exploit 297 00:21:04,100 --> 00:21:06,720 Add it for the capability for remote exploit 298 00:21:08,880 --> 00:21:10,460 the bill the usefulness of the troisième of power access teaching is thosemetrosumpl measurements between the individual data統 of the ones in water is 3d. 299 00:21:10,460 --> 00:21:17,360 of this is that you can use an arbitrary payload, anything from Metasploit. The code is there 300 00:21:17,360 --> 00:21:23,000 in Metasploit in a known location, so if you want to extend your functions for another 301 00:21:23,000 --> 00:21:29,420 vulnerability, you can just use Metasploit for it. And for this, I created a sample vulnerable 302 00:21:29,420 --> 00:21:34,940 server that basically does the same thing as our printf vulnerable function, except 303 00:21:34,940 --> 00:21:49,100 through a TCP connection. So let me demo that right now. So I'm not going to go through 304 00:21:49,100 --> 00:21:57,920 this too much, but basically it opens a port on 4546, forks a process for connections, 305 00:22:00,840 --> 00:22:04,420 and then it basically sends smprintf vulnerability 306 00:22:04,420 --> 00:22:15,980 right here back to that socket that you connected to. So let me make this and go ahead and run 307 00:22:15,980 --> 00:22:24,180 it. So this is running on my VMware. I'm going to try to exploit it from my local machine. 308 00:22:37,860 --> 00:22:39,180 Metasploit is taking a while, don't worry. 309 00:22:55,720 --> 00:23:00,940 That's correct. This assumes, you know, this is for kind of legacy environments where a 310 00:23:00,940 --> 00:23:03,600 lot of those protections are nonexistent. 311 00:23:07,520 --> 00:23:12,120 So while Metasploit is loading right now, I'll go ahead and just show you that it indeed 312 00:23:12,120 --> 00:23:18,660 basically just, you know, by piping something through netcat to that server and to that 313 00:23:18,660 --> 00:23:23,480 port, it basically does the same thing. You know, it gives sort of this, you know, data 314 00:23:23,480 --> 00:23:23,800 disclosure. 315 00:23:32,680 --> 00:23:33,420 How's it going, guys? 316 00:23:33,900 --> 00:23:34,400 It's great. 317 00:23:34,980 --> 00:23:35,660 Very good. 318 00:23:39,720 --> 00:23:45,860 These are my co-workers from Redspin, so they're here to play Mario Kart with me, basically. 319 00:23:47,400 --> 00:23:49,820 They don't have any relation to the talk whatsoever. 320 00:23:52,360 --> 00:23:53,140 Okay, there we go. 321 00:24:03,440 --> 00:24:04,400 All right. 322 00:24:07,000 --> 00:24:12,480 So right now I'm going to load my custom Metasploit module. 323 00:24:16,080 --> 00:24:17,800 Show payloads, let's see. 324 00:24:20,780 --> 00:24:22,620 What do I want to exploit today? 325 00:24:29,100 --> 00:24:33,660 I'm going to just use a reverse TCP bind shell. 326 00:24:44,160 --> 00:24:46,040 Let's see, are my options for this? 327 00:24:47,160 --> 00:24:54,800 Looks like it accepts remote host, remote port, local host, so I'm going to go ahead 328 00:24:54,800 --> 00:24:55,260 and set those. 329 00:24:57,940 --> 00:24:58,420 Okay. 330 00:25:03,160 --> 00:25:03,640 All right. 331 00:25:03,640 --> 00:25:06,040 One third in this case is my VMware machine. 332 00:25:13,620 --> 00:25:15,880 And 58.1 is my local machine. 333 00:25:18,380 --> 00:25:21,760 And hopefully this will work. 334 00:25:29,740 --> 00:25:33,480 So the nice thing is, since we're brute forcing the stack. 335 00:25:34,200 --> 00:25:37,620 You know, any return address on that stack is going to give us a shell. 336 00:25:38,180 --> 00:25:46,240 In this case it happens to be, you know, six, six, you know, overwrite return addresses 337 00:25:46,240 --> 00:25:47,840 on the other program. 338 00:25:48,040 --> 00:25:52,420 So now you can share a shell with your friends and family if you would so choose to. 339 00:25:54,620 --> 00:25:59,640 And we can verify that by, you know, listing the sessions. 340 00:26:03,640 --> 00:26:05,120 And then say the command to them. 341 00:26:09,020 --> 00:26:13,300 So you can see that, you know, I compromised this application six times. 342 00:26:13,580 --> 00:26:16,120 And you know, got a root access on all of them. 343 00:26:18,300 --> 00:26:18,740 Okay. 344 00:26:29,920 --> 00:26:31,900 Looks like I'm doing really well on time. 345 00:26:32,100 --> 00:26:36,920 So I'm going to go through, you know, my brute forcing code in Python. 346 00:26:38,820 --> 00:26:41,000 Hopefully you guys will get something out of it. 347 00:26:41,080 --> 00:26:42,640 It's only about 100 lines of code. 348 00:26:43,340 --> 00:26:44,040 Four steps. 349 00:26:45,560 --> 00:26:49,420 So first thing I do, basically, is just, you know, standard. 350 00:26:50,780 --> 00:26:51,620 Actually, wrong one. 351 00:26:53,020 --> 00:26:59,180 I basically just have, you know, initialization, you know, setting up my variables, defining 352 00:26:59,180 --> 00:26:59,960 some functions. 353 00:27:02,300 --> 00:27:06,960 Second step, I basically go through that stack dump process as I showed you before. 354 00:27:08,860 --> 00:27:15,280 You know, I use this data, basically, to find, you know, an offset address of the found 355 00:27:15,280 --> 00:27:16,180 format string. 356 00:27:18,220 --> 00:27:21,900 The next step after that, basically, is, you know, I'm looking for that. 357 00:27:21,900 --> 00:27:22,340 There. 358 00:27:22,420 --> 00:27:24,220 You know, the address of that format string. 359 00:27:25,180 --> 00:27:29,000 So basically, I run another loop to find that address. 360 00:27:31,100 --> 00:27:35,580 And finally, when I'm actually exploiting, all I do is create the exploit string and 361 00:27:35,580 --> 00:27:37,560 then run through this brute forcing technique. 362 00:27:37,960 --> 00:27:40,540 So you know, 68 lines of code. 363 00:27:40,800 --> 00:27:43,020 You know, hopefully pretty extendable. 364 00:27:44,780 --> 00:27:47,180 Used on a variety of, you know, similar instances. 365 00:27:47,480 --> 00:27:49,420 So hopefully you guys will find some use out of it. 366 00:27:50,700 --> 00:27:51,140 Okay. 367 00:27:53,660 --> 00:27:54,140 Next slide. 368 00:27:54,360 --> 00:28:00,280 In conclusion, you know, format string output gives you everything you need to actually 369 00:28:00,280 --> 00:28:02,600 go from discovery to compromise. 370 00:28:04,220 --> 00:28:06,820 You know, it can be completely automated as I've shown. 371 00:28:07,980 --> 00:28:09,800 You know, they have been easy to fix. 372 00:28:09,940 --> 00:28:11,380 Now they're easy to exploit. 373 00:28:13,180 --> 00:28:17,000 You know, for those who are interested in finding some of them, a good suggestion, 374 00:28:17,260 --> 00:28:18,000 Google code. 375 00:28:18,560 --> 00:28:20,240 A good dork to look for. 376 00:28:20,240 --> 00:28:23,600 You know, this type of thing is shown there. 377 00:28:24,300 --> 00:28:29,380 This basically look for a C language print type function. 378 00:28:29,400 --> 00:28:34,500 Print app type function that doesn't begin with something like a constant. 379 00:28:34,740 --> 00:28:40,500 Something that doesn't begin with something like STDIN or STDER or something that begins 380 00:28:40,500 --> 00:28:41,240 with a parenthesis. 381 00:28:41,460 --> 00:28:45,640 So hopefully something that is actually using, you know, a buffer. 382 00:28:47,320 --> 00:28:48,500 You know, a non. 383 00:28:51,080 --> 00:28:52,700 Non command line. 384 00:28:53,440 --> 00:28:57,560 Something that uses something that the user is providing in terms of a buffer basically. 385 00:29:00,280 --> 00:29:01,320 So thanks. 386 00:29:02,320 --> 00:29:07,280 Hopefully the tools that aren't on your CD will be put on Redspin and DEF CON shortly 387 00:29:07,280 --> 00:29:08,800 Monday I'm hoping. 388 00:29:09,900 --> 00:29:15,360 I'm hoping that the Metasploit module will also be there as soon as I talk to those responsible 389 00:29:15,360 --> 00:29:18,480 for weird autofilters. 390 00:29:18,480 --> 00:29:19,140 For more Supreme stuff. 391 00:29:20,340 --> 00:29:21,740 You can contact me. 392 00:29:22,140 --> 00:29:28,640 Otherwise, you know, shout out to all the people at Shellfish and the people playing 393 00:29:28,640 --> 00:29:29,520 mother cart with me. 394 00:29:33,580 --> 00:29:35,120 questions, Mario cart. 395 00:29:35,500 --> 00:29:40,840 Hopefully look like we have plenty of time, but hopefully we'll be in another room. 396 00:29:40,900 --> 00:29:41,740 If you don't have any right now. 397 00:29:41,900 --> 00:29:42,320 So... 398 00:29:51,240 --> 00:29:53,680 Can you, can you repeat that one more time, please? 399 00:30:05,060 --> 00:30:12,480 So the question was, does my proof of concept assume that there's direct parameter access 400 00:30:13,100 --> 00:30:14,020 to exploit it? 401 00:30:14,120 --> 00:30:15,080 And the answer is yes. 402 00:30:15,080 --> 00:30:21,660 So, I basically assume that, you know, most modern versions, or most versions that I've 403 00:30:21,660 --> 00:30:23,700 seen have used that direct parameter access. 404 00:30:25,520 --> 00:30:27,440 Again, the technique can still be modified. 405 00:30:28,220 --> 00:30:29,320 You just have to do it yourself. 406 00:30:32,840 --> 00:30:36,800 How hard do you think it would be to modify this to actually work with, like, 407 00:30:36,800 --> 00:30:38,720 X-based layout recognizations or no? 408 00:30:40,460 --> 00:30:41,100 I don't know. 409 00:30:41,140 --> 00:30:44,860 I think it would be a good exercise, but, you know, I wouldn't be surprised if you could 410 00:30:44,860 --> 00:30:45,260 do it. 411 00:30:45,940 --> 00:30:50,020 You know, because if you dump the stack enough times, you're still going to have a general 412 00:30:50,020 --> 00:30:54,860 idea about where stuff is relative to everything else on the stack, so, you know, you still 413 00:30:54,860 --> 00:30:59,920 could do some sort of permutation attacks, and if you're brute force in any way, you 414 00:30:59,920 --> 00:31:00,980 know, it's only a matter of time. 415 00:31:08,400 --> 00:31:09,760 Okay, guys, thanks a whole bunch. 416 00:31:14,860 --> 00:31:14,880 Bye. 417 00:31:14,940 --> 00:31:14,960 Bye. 418 00:31:14,980 --> 00:31:15,020 Bye.