1 00:00:05,140 --> 00:00:11,060 Good morning, DEF CON. Thank you for coming to see our session. Hopefully you'll enjoy it. 2 00:00:11,380 --> 00:00:15,600 Little bit about, a little bit about myself. My name is Dr. Bramwell Brizendine. I'm the 3 00:00:15,600 --> 00:00:20,060 former and founding director of the Verona Lab, which specializes in vulnerability and 4 00:00:20,060 --> 00:00:25,700 exploitation research. Uh, creator, creator of several different tools, the Shell Wasp, 5 00:00:25,700 --> 00:00:32,840 Chop Rocket, and Sharem. And I'm presently an assistant professor at UAH. Uh, I do have a 6 00:00:32,840 --> 00:00:39,020 PhD in cyber operations, which is a highly, uh, technical, uh, degree specializing in 7 00:00:39,020 --> 00:00:45,600 reverse engineering and exploitation. Um, just as a kind of a side note, I have kind of lost my 8 00:00:45,600 --> 00:00:50,700 voice a bit, but it has been improving, so I'll just try to do the best that I can. Uh, there is 9 00:00:50,700 --> 00:00:55,680 some contact information down below, so feel free to, uh, reach out to me if, uh, if you have 10 00:00:55,700 --> 00:01:03,140 questions or if you so desire. Uh, I'm joined by my graduate student, Shiva, and he is a 11 00:01:03,140 --> 00:01:08,500 master's of computer science student at UAH and he's interested in writing software, uh, web 12 00:01:08,500 --> 00:01:14,620 apps as well as block chain. Uh, he's got a lot of contact information there, so feel free- 13 00:01:14,620 --> 00:01:22,340 feel free to reach out with any, uh, opportunities for Shiva. So when we started this 14 00:01:22,340 --> 00:01:28,160 this research the, the goal, the idea was can we bring something fresh, something, something 15 00:01:28,160 --> 00:01:33,300 new to ROP because quite frankly it seemed to be getting a little bit kind of stale, kind of 16 00:01:33,300 --> 00:01:39,120 predictable. Uh, no doubt it w- w- the techniques that we used seemed to work very well but 17 00:01:39,120 --> 00:01:45,760 it's just a lot of the same types of things uh, over and over. Now there are a number of tools 18 00:01:45,760 --> 00:01:51,480 that can facilitate uh, getting uh, ROP gadgets. Uh, MONA, which of course has been around 19 00:01:51,480 --> 00:01:58,720 forever. ROP gadget, uh, ROPR, uh, as well as others. And additionally for jump oriented 20 00:01:58,720 --> 00:02:03,720 programming the Jop Rocket, which is actually a tool that uh, I created myself and presented at 21 00:02:03,720 --> 00:02:13,040 DEF CON in 2019. So again, um, the idea is to try to make it fresh, to try to make it exciting 22 00:02:13,040 --> 00:02:20,280 again. Uh, and part of this inspiration is because code reuse attacks in general should be 23 00:02:20,280 --> 00:02:29,320 inherently um, very free, very flexible. We shouldn't be confined by the shackles of what has 24 00:02:29,320 --> 00:02:36,260 been done before. But instead I'd rather see us embrace an openness, a desire to do something new, 25 00:02:36,320 --> 00:02:43,460 to something a little bit different. So part of my thinking is trying to kind of uh, think out of 26 00:02:43,460 --> 00:02:48,100 the box. So I spent a huge amount of time, uh, actually thousands of hours working with jump 27 00:02:48,100 --> 00:02:52,280 oriented programming. Now I didn't create it, but I did create the, the tool that helped to 28 00:02:52,280 --> 00:02:59,120 facilitate that. And a lot of uh, practical Jop just really had not been documented. And so I 29 00:02:59,120 --> 00:03:04,180 set about uh, providing that documentation uh, so that people actually wanted to do something 30 00:03:04,180 --> 00:03:09,080 significant with it. They'd have the capability of, of doing so. And there are a few different 31 00:03:09,080 --> 00:03:14,940 white papers out there that myself and Austin Babcock have, have written. So uh, by its very nature 32 00:03:14,940 --> 00:03:21,780 Jop is extraordinarily flexible. And I wanted to try to bring some of that to, to Rop and to 33 00:03:21,780 --> 00:03:28,580 introduce some new ideas. So uh, without further ado then, let's uh, see what some of these novel 34 00:03:29,240 --> 00:03:36,900 contributions may include. So the next generation state of the art uh, Rop gadget tool. Rop 35 00:03:36,900 --> 00:03:43,780 rocket is going to be uh, among these. Uh, and part of the, part of it is going to be uh, 36 00:03:44,940 --> 00:03:49,460 we'll have automatic Rop chain generation. So it will create the chains for these different 37 00:03:49,460 --> 00:03:56,960 techniques. Um, some of them are also in their own regard uh, novel approaches or novel 38 00:03:56,960 --> 00:04:03,020 techniques. So adapting Heaven's Gate to, to return oriented programming. Utilizing Windows 39 00:04:03,020 --> 00:04:09,620 Syscalls to bypass dep rather than the traditional Windows APIs. Uh, and then something that I 40 00:04:09,620 --> 00:04:16,580 like to call uh, shell codeless Rop, where, where instead of uh, trying to avoid data, uh, 41 00:04:16,860 --> 00:04:24,400 avoid uh, trying to bypass data execution prevention, we just simply uh, avoid it and invoke 42 00:04:24,400 --> 00:04:30,860 that shell code-like functionality directly by calling the, the appropriate Windows APIs. Uh, 43 00:04:30,960 --> 00:04:38,720 obfuscation of, of Rop gadgets which I'll get into uh, more later on. And then emulation of uh, Rop 44 00:04:38,720 --> 00:04:45,480 gadgets and as well as chains which does help us uh quite significantly. Okay so we're gonna 45 00:04:45,480 --> 00:04:50,940 start out here with uh Heaven's Gate and R.O.B. And I know that uh some of you are gonna be 46 00:04:50,940 --> 00:04:56,100 very familiar with Heaven's Gate for others it may be uh your first time encountering it so a 47 00:04:56,100 --> 00:05:01,520 little bit of history lesson. Now this is a traditional way in which we invoke it so uh if 48 00:05:01,520 --> 00:05:07,920 we're gonna go from x86 transition to 64 bit mode this is something that the the Windows 49 00:05:07,920 --> 00:05:15,080 operating system does continuously uh whenever we make use of an in in NTDLL function so it 50 00:05:15,080 --> 00:05:22,940 just happens automatically as part of uh making use of Windows sys calls. So the the the old 51 00:05:22,940 --> 00:05:27,400 kind of uh formula if you wanna call it that that you'll see it in malware or shell code is 52 00:05:27,400 --> 00:05:37,900 you'll do uh push 33 for the 33 uh CS selector which designates it going to 64 bit mode. And 53 00:05:37,900 --> 00:05:38,300 if you want to do that one step, if the fear of�� uk. That your computer is crashed and 54 00:05:38,300 --> 00:06:03,300 you have a device and uh all of the 신기 cœur. So yup now we've gone past that and now it's gonna will be a function for Geoện Hotfile and next action. So that's how you might do it if you just까요. weaving Nuke into another file. Call Next Red F Re록ion, which is just an address so the compiler would then produce that address and then we're going to then at that particular location. We're 55 00:06:03,300 --> 00:06:07,140 The reality is you don't have to have that return address or that destination address 56 00:06:08,040 --> 00:06:12,560 immediately after the red F. It could be anywhere in process memory. So that's a tremendous 57 00:06:12,560 --> 00:06:19,180 amount of flexibility that just isn't really being used. So of course we're not writing shell 58 00:06:19,180 --> 00:06:25,180 code. We are writing return oriented programming. So we need to find a new way to do that 59 00:06:25,180 --> 00:06:31,000 because we can't just simply write shell code. So we are introducing a couple new ways to do 60 00:06:31,000 --> 00:06:37,320 that that will um allow us to perform heaven's gate. And by doing this we can thereby expand 61 00:06:37,320 --> 00:06:42,920 the attack surface from uh wild 64 which means we're working in 32 bit. We're emulating a 62 00:06:42,920 --> 00:06:50,200 32 bit application uh to 64 bit mode. Now you could do the opposite if you wanted. I don't 63 00:06:50,200 --> 00:06:57,440 really see much of a point but that that's fine. You can still do it. So uh our approach here 64 00:06:57,440 --> 00:07:00,900 is we're going to be utilizing the push add instruction. So if you're familiar 65 00:07:00,900 --> 00:07:05,920 with virtual alloc or virtual protect uh the types of change produced by something like 66 00:07:05,920 --> 00:07:11,440 mona is following the same idea and Shiva will be talking a little bit more about uh how this 67 00:07:11,440 --> 00:07:18,820 works. Um but these are the patterns for uh for heaven's gate. So we have 11 of them and I 68 00:07:18,820 --> 00:07:26,680 can actually increase it to to more than those uh 11. And uh so if one of these is not able to 69 00:07:26,680 --> 00:07:30,600 work then the tool will just simply try another one. Now these gadgets they're not 70 00:07:30,600 --> 00:07:36,660 exceedingly difficult to find. So very likely we will succeed. So let's take a look here at 71 00:07:36,660 --> 00:07:43,080 pattern 7. So we just simply load up the registers with the uh appropriate values. Uh and 72 00:07:43,080 --> 00:07:47,940 these values a lot a lot of them are very simple. They're ROPNOPs or uh in this case when we 73 00:07:47,940 --> 00:07:53,160 do the push add it's going to push them in a predefined order. So it'll go EDI ESI all the 74 00:07:53,160 --> 00:08:00,580 way to EAX. And so we'll have there that ret uh zero uh C and that's going to skip over the 75 00:08:00,600 --> 00:08:05,340 number a bunch of stuff. It'll it'll firstly execute the ROPNOP and ESI and then it'll skip 76 00:08:05,340 --> 00:08:10,720 over stuff until we get to that jump due to reference EBX. And then that will then cause us to 77 00:08:10,720 --> 00:08:17,240 go to EBX. What is EBX? Well that's the red F. And so then the red F will then uh cause 78 00:08:17,240 --> 00:08:22,880 that's gonna what's gonna initiate the heaven's gate. And then on the stack after that we'll 79 00:08:22,880 --> 00:08:29,360 have uh the destination address and the 33 selector. So everything will be perfectly set up and 80 00:08:29,360 --> 00:08:29,900 it should work. 81 00:08:30,600 --> 00:08:36,260 So let's take a look at the stack before and after. So uh DD ESP we can see we have our 82 00:08:36,820 --> 00:08:44,320 destination address and the 33 selector. And then after that red F uh they're gone. And you'll 83 00:08:44,320 --> 00:08:51,140 notice that the the address is now a Q word instead of a D word. It has expanded. And we have 84 00:08:51,140 --> 00:08:57,080 actually switched architectures. So uh we have that red F up above and then down below again 85 00:08:57,080 --> 00:09:00,580 everything we have Q words and then notice we have push uh R and then we have uh D words. Uh 86 00:09:00,580 --> 00:09:08,160 RBP instead of uh EBP. So we have switched to to 64 bit mode. Now just one little note for 87 00:09:08,160 --> 00:09:13,020 those who may not be aware, the only time you can actually view this is if you're in the 64 bit 88 00:09:13,020 --> 00:09:19,260 version of uh WinDebug. Any other debugger will not work or it will produce uh aberrant 89 00:09:19,260 --> 00:09:25,220 behavior. And there's no reason you can't uh open up a 13 bit application and then attach it 90 00:09:25,220 --> 00:09:30,560 with a 64 bit uh WinDebug. Let's take a look quickly here at pattern number 11. So this is a 91 00:09:30,560 --> 00:09:35,360 pattern number 11. Now this one is very very simple. So we have a couple rop nops. We have a 92 00:09:35,360 --> 00:09:42,060 pop EBP to consume the the the ESP which we just want to skip. Uh we have another rop nop and 93 00:09:42,060 --> 00:09:47,500 then the red F and everything is set up. We have the destination address and we have the 33 94 00:09:47,500 --> 00:09:54,880 selector. So okay we've done the heaven's gate. Uh what is the advantage of this? Why do we 95 00:09:54,880 --> 00:10:00,540 want to do this? Good question. Wow. Excellent question. So uh by doing this we're able to 96 00:10:00,560 --> 00:10:06,840 find this. There could be many more registers. 64 bit registers. And the idea is maybe 97 00:10:06,840 --> 00:10:12,020 there's something that we're we want to do in 32 bit mode but we just don't have the right 98 00:10:12,020 --> 00:10:18,060 gadgets. But if we expand it to 64 bit mode maybe there are additional gadgets. Now um the 99 00:10:18,060 --> 00:10:24,580 reality is a lot of times however um there may not be some of these extra 64 bit gadgets. It's 100 00:10:24,580 --> 00:10:30,540 just because the bytes we're we're required to produce them may not be there. And so uh the 101 00:10:30,540 --> 00:10:36,540 um sometimes they will be purely by happenstance. And additionally there can be some very 102 00:10:36,540 --> 00:10:44,400 valuable structures that are accessible in x64 which you can access via the R2 R12 register. For 103 00:10:44,400 --> 00:10:51,960 instance the the tab 64. You get the tab 64 you can go to tab 32 and then pep 32 and pep 64 so 104 00:10:52,580 --> 00:10:59,340 it's actually immensely valuable. So if you can do that and then leak the R12 then that's very useful. 105 00:11:00,540 --> 00:11:08,420 Ok so we've done uh x86 we want to go back to x64 because otherwise you're in 64 bit mode for a 32 bit 106 00:11:08,420 --> 00:11:16,420 application. Uh technically you could call uh 64 bit NTDL functions. Uh that'd be very difficult. Uh it's 107 00:11:16,420 --> 00:11:21,520 not something that I personally would recommend uh trying to do. Uh people out out there have 108 00:11:21,520 --> 00:11:30,460 done that uh in terms of um malware development but I don't think it's too terribly realistic for a for a return on to programming. So at this stage we would 109 00:11:30,460 --> 00:11:39,240 would want to return back, back to, um, x86. Um, and so we have a forbidding gadget, 110 00:11:39,400 --> 00:11:44,340 unfortunately, so the push add simply doesn't exist. So if you try to do a push add, you'll 111 00:11:44,340 --> 00:11:50,840 see hex 60 and three question marks. How sad. So in this case, we're going to do a series of 112 00:11:50,840 --> 00:11:57,120 move dereferences and, uh, kind of like a snipe gadget. So we'll create an allocation of 113 00:11:57,120 --> 00:12:02,300 memory and we'll just set up what we want the stack to be and then we'll do a stack pivot and 114 00:12:02,300 --> 00:12:07,820 then everything should be, should be good and jolly. So we'll take a look at some of these, 115 00:12:07,880 --> 00:12:13,540 uh, different, uh, steps that we can, can take. So first thing we want to do, we want to get a 116 00:12:13,540 --> 00:12:18,560 pointer to memory. Let's make it easy and simple. We can do ESP. And then we're going to go move 117 00:12:18,560 --> 00:12:25,120 ahead 250 bytes and that's going to be our pointer reference. We're going to start building our 118 00:12:25,120 --> 00:12:27,100 different, uh, parameters, our, our, our, our, our, our, our, our, our, our, our, our, our, our, 119 00:12:27,120 --> 00:12:31,800 return address, et cetera. And we're not going to do every little thing here because it'll be a 120 00:12:31,800 --> 00:12:37,280 little bit tedious. We'll do, do a few of them. So, uh, we do want to write the, the retf, 121 00:12:37,440 --> 00:12:40,480 because remember that retf is going to be what's going to kick it off. It's that, that's a 122 00:12:40,480 --> 00:12:45,740 far ret. We only, we're not going to typically do that and, and ROP, but it does allow us to 123 00:12:45,740 --> 00:12:50,540 initiate the heaven's gate. So we'll get a, a retf. It doesn't matter which retf and we'll 124 00:12:50,540 --> 00:12:56,360 write that address there. And we do that with a move dereference. So it's move dword pointer RBX 125 00:12:56,360 --> 00:13:03,460 EAX. And it's not a Q word, uh, which some of you who are very observant may notice. Um, 126 00:13:04,080 --> 00:13:08,160 it's going to be a lot more common. You'll see the D words just because you're going from 32 bit 127 00:13:08,160 --> 00:13:15,820 to 64 bit. And, um, a lot of times when you do a move dereference technique, which is very, uh, 128 00:13:15,920 --> 00:13:20,780 effective, by the way, in traditional ROP, you'll do a series of four increments. Well, guess 129 00:13:20,780 --> 00:13:26,180 what? It's not going to work out too well, uh, with, with this because the, the byte to 130 00:13:26,180 --> 00:13:30,560 produce those increments, uh, will no longer produce increments. So the only increments you 131 00:13:30,560 --> 00:13:38,280 have will be created by happenstance. So instead we'll just do an add register, register, uh, and 132 00:13:38,280 --> 00:13:42,840 do a distance of four. It's a little bit more tedious, uh, but it's something that the tool can 133 00:13:42,840 --> 00:13:49,000 automate for us. So, we don't have to worry about it too much. Um, and then we also want to 134 00:13:49,000 --> 00:13:53,840 finish writing the address of the red F because remember we're 64 bit mode, so we're, we need to do 135 00:13:53,840 --> 00:13:59,520 a Q word rather than a D word and our move dereference gadget was a D word, so we're going to 136 00:13:59,520 --> 00:14:05,320 do, uh, XOR EAX, EAX, the result is zero. And we're going to write that there so we get a 137 00:14:05,320 --> 00:14:11,920 monstrously long, uh, uh, red F gadget address there. And then now we need to do the 138 00:14:11,920 --> 00:14:18,980 destination address and the 23 selector. So the 23 selector allows us to go back, uh, to the 139 00:14:19,000 --> 00:14:25,720 64 bit mode. Um, and this is kind of where it's kind of a little weird, kind of funky. Um, 140 00:14:25,960 --> 00:14:31,100 we're 64 bit mode, we've been dealing with Q words, but now we're going to go back to, to D 141 00:14:31,100 --> 00:14:35,740 words. So we're going to represent the, the destination address and the 23 selector is D 142 00:14:35,740 --> 00:14:41,800 words. Hey, it makes our life a little bit easier so I'm not complaining. So, uh, I, I didn't 143 00:14:41,800 --> 00:14:47,020 show the steps for those, uh, but now what we want to do is do a stack pivot and of course 144 00:14:47,020 --> 00:14:48,720 there are many different ways to do a stack pivot. 145 00:14:49,000 --> 00:14:57,180 Um, but what we're going to do is we're going to get it, get it aligned so that, um, RAX, 146 00:14:57,320 --> 00:15:02,600 which is kind of where we've been building our gadgets, we want it to, to point to, to the red 147 00:15:02,600 --> 00:15:09,120 F. And so we're going to do, uh, a very long 16 digit number which is actually equal to 148 00:15:09,120 --> 00:15:16,940 negative 12. And then once we do that then, um, we can just take another before and after so 149 00:15:16,940 --> 00:15:22,940 do DDESP. We have the, the return address and the 23 selector and then after that, you'll 150 00:15:22,940 --> 00:15:30,040 notice that x86 is present and, um, we have succeeded. We've gone back to x86. So let's 151 00:15:30,040 --> 00:15:37,280 actually do a quick little demo here. Okay, it's all set up for us. So there's our push ad. 152 00:15:39,640 --> 00:15:46,920 And, uh, we can do that red F right there. So it's going to be the first red F. We're going to go from x86 to x64. We have a 153 00:15:46,940 --> 00:15:52,620 destination address, 33 selector. So now we are in x64. You can see the registers have indeed 154 00:15:52,620 --> 00:16:03,100 changed. That's awesome. And we're going to skip ahead a little bit to not be too tedious. And we are going to, uh, 155 00:16:03,580 --> 00:16:09,620 we're at the red F. Go from x64 to x86. Let's look at the stack. We have the destination address and the 156 00:16:09,620 --> 00:16:16,260 23 selector. And now we're back at x86. So we did it. We did two heaven's gates, uh, right there in that little demo. 157 00:16:25,640 --> 00:16:31,060 Okay, so this novel form of heaven's gate, again, this allows us to go back and forth, uh, between them. 158 00:16:31,560 --> 00:16:36,900 Obviously, a, a consideration is going to be the size of the payload. We want to be very, uh, we want to, 159 00:16:37,100 --> 00:16:45,700 we definitely want to be aware of that. And it's really designed for, uh, for WoW 64 or 32 bit, uh, applications. I mean, you, 160 00:16:45,700 --> 00:16:51,260 there's no reason you can, can't do it in the 64 bit mode. I just can't really think of a good reason why, except maybe 161 00:16:51,260 --> 00:17:00,280 just for the novelty of it. Uh, and again, this, this is potentially capable of expen-, expanding the attack surface. 162 00:17:02,600 --> 00:17:08,020 Um, and the, the technique or the approach that we've introduced is a little bit more complex and 163 00:17:08,020 --> 00:17:15,680 different from the, the standard approach that we showed you earlier. Okay, so we're going to segue into our, uh, 164 00:17:15,700 --> 00:17:19,660 next topic here, which is going to be, uh, Windows syscalls. 165 00:17:24,480 --> 00:17:29,600 So, very, uh, briefly, I'm going to speed through some of these, just as kind of a refresher, uh, for some people. 166 00:17:29,760 --> 00:17:34,860 So, what is a Windows syscall? Um, it's going to be something where you, you could call a kernel 32 function, 167 00:17:35,260 --> 00:17:45,680 like virtual alloc. That will call an NTDL function, such as NT allocate virtual memory. And then that, uh, NTDL function will then call a Windows syscall. 168 00:17:45,700 --> 00:17:51,200 In order to do that, it will load into EAX, the appropriate SSN, syscall system number. 169 00:17:51,780 --> 00:17:57,800 And then, uh, you transition from user mode to kernel mode. And then after that, 170 00:17:57,980 --> 00:18:01,620 um, there's a bunch of stuff going on in kernel mode. It's really outside the scope of this. 171 00:18:01,820 --> 00:18:06,680 So, this is not something that's really intended for the average programmer, uh, to be doing. 172 00:18:07,480 --> 00:18:15,120 And the appeal of Windows syscalls is, um, it's much, much harder for it to be hooked by EDR. 173 00:18:15,700 --> 00:18:24,860 And to be, to, to prevent it from, from, from working, um, so that can definitely be very beneficial. 174 00:18:25,180 --> 00:18:31,440 Um, Melissa's Windows API is much easier to, to hook those, thereby preventing their, their usage. 175 00:18:32,600 --> 00:18:41,040 Uh, to my knowledge, I don't think this has been used in, uh, x86, uh, while 64. Again, that's the 32-bit. 176 00:18:41,220 --> 00:18:45,680 Um, now if you're doing syscalls in 64-bit mode, the, the technique is pretty much the same. 177 00:18:45,700 --> 00:18:49,440 You can approach, it's gonna be a little bit different. You can actually use an actual syscall instruction. 178 00:18:50,300 --> 00:18:55,660 64-bit instruction, you're not gonna be using that. And, um, while 64, we'll be doing things in a 179 00:18:55,660 --> 00:19:01,540 different way. And one of the, the issues with syscalls is we have a, what we call a problem of portability. 180 00:19:01,820 --> 00:19:08,860 So, with Windows 10, for instance, um, that SSN potentially could change. You have more than 13 181 00:19:08,860 --> 00:19:15,160 different OS builds. So, sometimes those SSNs will stay the same, but other times they will change. So, 182 00:19:15,700 --> 00:19:24,720 you could have, um, I think, uh, NT Protect Virtual Memory, I think for Windows 7 is hex 15 and I think 183 00:19:24,720 --> 00:19:31,840 for Windows 10 and 11 it's hex 18. So, um, those have changed. Others will change much more 184 00:19:31,840 --> 00:19:37,600 frequently, some less frequently. So, very briefly, let's, um, go over how we can reverse engineer 185 00:19:37,600 --> 00:19:45,620 them. So, Windows 7, what we're gonna be looking for is that call D word FSC zero that will point to a special address, which will be a far jump. 186 00:19:45,700 --> 00:19:53,000 And, you can see we're loading into EAX, hex 15, um, so all that we can see is NT allocate virtual memory. 187 00:19:53,340 --> 00:20:04,240 It's off there. And, uh, the FS register is gonna be pointing to the, the thread environment block. Um, so what we can do is we can 188 00:20:04,240 --> 00:20:15,680 weaponize that, we can utilize that, that knob, that FSC zero is gonna be a reliable, uh, way for us to interface with that. And the FSC is actually a register, so, it's gonna always be there. So, we don't have to worry about anything. So, here 189 00:20:15,700 --> 00:20:21,760 just need to get uh instructions that have FS in it and GS is gonna be the 64 bit equivalent. 190 00:20:22,460 --> 00:20:26,920 So there you see the you have a jump and you have a 33 selector and colon and then the 191 00:20:26,920 --> 00:20:32,780 address so that'll be switching to 64 bit mode so that'll be a form of Heaven's Gate in and 192 00:20:32,780 --> 00:20:39,640 of itself. And Windows 10 is a little bit different so uh we have hex 18 and to allocate 193 00:20:39,640 --> 00:20:47,740 virtual memory and the um set up is a little bit different but for our purposes we don't 194 00:20:47,740 --> 00:20:52,420 really care because we go to FSC zero it's gonna be pointing to that same address so we can 195 00:20:52,420 --> 00:21:00,340 still continue to use that FSC zero. In Windows 11 things are a little bit different again 196 00:21:00,340 --> 00:21:07,920 but again that Windows 7 way of invoking the syscalls is still able to to work so um uh as 197 00:21:07,920 --> 00:21:09,620 many of you are aware a lot of uh Windows 10 is a little bit different than Windows 10 198 00:21:09,620 --> 00:21:12,620 for a while. So Windows-based ROP has gonna be focused on bypassing mitigations, one of the 199 00:21:12,620 --> 00:21:16,220 most prevalent mitigations is gonna be data execution prevention which says the memory 200 00:21:16,220 --> 00:21:22,740 should be readable and writable or executable but not both. That doesn't mean it can't be 201 00:21:22,740 --> 00:21:28,680 both, it can be but we need to use certain APIs or syscalls in order to make that happen. 202 00:21:28,800 --> 00:21:33,400 Virtual alloc we created a region of memory that has the desired permissions. Virtual 203 00:21:33,400 --> 00:21:39,600 protect we modified the permissions of existing memory allocations. So those are some of the 204 00:21:39,620 --> 00:21:45,300 are some very old, very uh simple ways of doing it and can be easily blocked. Uh there are 205 00:21:45,300 --> 00:21:52,360 alternative ways as well or ways to make them work. Um but Windows syscalls is gonna be 206 00:21:52,360 --> 00:21:58,700 something that is uh a little bit more low level, a little bit deeper way of of doing this. 207 00:21:59,000 --> 00:22:06,960 Um and again those syscall SSNs do change but the good news is for for Windows um 10 and 11 208 00:22:06,960 --> 00:22:12,780 they're gonna stay the same for the two that we care about and Windows 7 is gonna be the same 209 00:22:12,780 --> 00:22:19,640 so um that works out uh very well for us. We don't, what this means practically speaking is 210 00:22:19,640 --> 00:22:27,060 we don't have to worry about um resolving the OS build like you would if you were using a 211 00:22:27,060 --> 00:22:32,200 traditional Windows syscall tool. We can just say okay I'm attacking Windows 10, doing Windows 212 00:22:32,200 --> 00:22:36,700 11, I've done a little bit of reconnaissance, I know uh about my targets. 213 00:22:36,960 --> 00:22:45,340 So um we can dispense with that step. It's not necessary for these particular APIs. And I 214 00:22:45,340 --> 00:22:52,040 think it'd be a lot more challenging to uh to do that and um in ROP but uh maybe we'll do that 215 00:22:52,040 --> 00:22:57,120 later on. So how do we perform these uh the Windows syscall in Windows 10 and 11, 216 00:22:57,320 --> 00:23:02,200 particularly while 64? Well that can be a little bit challenging but ultimately as long as we 217 00:23:02,200 --> 00:23:06,500 follow the proper calling convention whether it be for the API or the syscall, it's gonna be a 218 00:23:06,500 --> 00:23:06,780 little bit more challenging. But ultimately as long as we follow the proper calling convention, 219 00:23:06,780 --> 00:23:06,940 whether it be for the API or the syscall, it's gonna be a little bit more challenging. But ultimately 220 00:23:06,960 --> 00:23:12,020 it's gonna work. So we just simply get the stack aligned properly uh with the return 221 00:23:12,020 --> 00:23:16,400 addresses and notice I didn't say return addresses, that's not a, I didn't misspeak there, 222 00:23:16,540 --> 00:23:24,700 it is indeed plural for for Windows syscalls. Um and then initiate things and it and it should 223 00:23:24,700 --> 00:23:32,320 work. So uh we'll see how that works here um shortly. So important Windows syscalls that 224 00:23:32,320 --> 00:23:36,700 are this tool utilizes is gonna be NT allocate virtual memory, the deeper version of virtual 225 00:23:36,700 --> 00:23:44,100 alloc. And NT protect virtual memory, which is the deeper version of a virtual protect. So 226 00:23:44,100 --> 00:23:48,720 we're gonna focus here on NT protect virtual memory from a ROP standpoint it's a little bit 227 00:23:48,720 --> 00:23:55,540 more challenging to set up. And one of the big things with Windows syscalls is instead of just 228 00:23:55,540 --> 00:24:01,760 using direct values like your Windows APIs, you'll have a lot of pointers. So a pointer is 229 00:24:01,760 --> 00:24:06,680 going to be, you go inside of the pointer and it has that value so we need to set it up on a 230 00:24:06,680 --> 00:24:13,360 somehow um create these pointers for for base address, number of bytes to protect and uh 231 00:24:13,360 --> 00:24:23,400 old access protection. And if we do that then um we should be in a good position. So we're using 232 00:24:23,400 --> 00:24:29,280 the move dereference approach rather than the push add approach and um so we want to get a 233 00:24:29,280 --> 00:24:34,400 pointer reference to memory. This is gonna be where we are going to build our parameters, our 234 00:24:34,400 --> 00:24:41,240 return addresses and we're gonna put uh a gadget there to invoke the Windows syscall which we'll 235 00:24:41,240 --> 00:24:50,140 talk about momentarily. So we'll just move uh ESP to EAX and then push it ahead 250 bytes. Uh 236 00:24:50,140 --> 00:24:54,080 now what this is gonna be something that'll be a little bit different for a lot of people is we 237 00:24:54,080 --> 00:25:01,180 need to set up a value for for a pointer. How do we do this uh in in ROP? And my solution is uh 238 00:25:01,180 --> 00:25:04,260 so you could either do increments or decrements. I've 239 00:25:04,260 --> 00:25:11,620 chose chosen to do uh decrements um for the automation and for this example. And so we're just 240 00:25:11,620 --> 00:25:17,140 gonna build the values for the pointers immediately after the parameters and then that just 241 00:25:17,140 --> 00:25:25,140 makes it easier for us to then move the pointers over to uh the parameters where where they where 242 00:25:25,140 --> 00:25:32,360 they need to be. So get base address value for pointer is what we're creating here and this may 243 00:25:32,360 --> 00:25:33,660 look a little weird if you're. 244 00:25:34,260 --> 00:25:39,840 scrutinizing it very closely. We moved ESP into EAX and now I'm moving that into EBX. So 245 00:25:39,840 --> 00:25:44,220 that doesn't really seem to make much sense, does it? Why am I not choosing a better one? 246 00:25:45,080 --> 00:25:52,260 Well, uh, I'll address that in a little bit. Um, and so then we then write that base 247 00:25:52,260 --> 00:25:56,520 address to, to memory with, uh, a move dereference and then we have a series of four 248 00:25:56,520 --> 00:26:04,240 decrements. So we then decrement to our next slot that we will then initialize with a next 249 00:26:04,260 --> 00:26:09,920 uh, value for another pointer. And this one is going to be number of bytes to protect. And 250 00:26:09,920 --> 00:26:15,000 if you look very closely, I'm putting one byte. I'm going to protect one byte. That's kind 251 00:26:15,000 --> 00:26:22,540 of bizarre. Um, I'll explain that again momentarily. It's kind of what I like to call a 252 00:26:22,540 --> 00:26:28,000 little trick just to, to save on gadgets. So we'll write that with a move dereference and 253 00:26:28,000 --> 00:26:32,920 four decrements. And I'm also going to, at this point, I'm going to save a point of reference 254 00:26:32,920 --> 00:26:41,380 to the number of bytes. Um, moving that into EDI. I'll be using that in a little bit. And 255 00:26:41,380 --> 00:26:44,320 I'm going to skip through some of these. I'm not going to go through the whole thing. There is 256 00:26:44,320 --> 00:26:48,380 going to be a white paper, so if you want to scrutinize the entire source code, you'll have 257 00:26:48,380 --> 00:26:55,180 that available as well as the tool itself. So then, uh, we've skipped a little bit here, but 258 00:26:55,180 --> 00:27:01,580 giving the pointer is a parameter. So we have the point of reference now in EDI. We're going to 259 00:27:01,580 --> 00:27:02,900 move EDI into EDI. And then we're going to move the pointer into EDI. And then we're going to 260 00:27:02,920 --> 00:27:07,780 BX and now we're going to increment EBX four times. So we're incrementing, not decrementing. And 261 00:27:07,780 --> 00:27:14,020 then we're going to write that to, uh, EAX. And that's going to be our number of bytes to 262 00:27:14,020 --> 00:27:20,480 protect, which again is just the value of one, which is odd. And so now I'm going to explain 263 00:27:20,480 --> 00:27:27,160 why I'm doing some of these kind of bizarre and odd type things. So the base address, um, what 264 00:27:27,160 --> 00:27:31,560 we're going to do is we're going to get it to, to round down to the, to the, the base address of 265 00:27:31,560 --> 00:27:37,380 that particular allocation. So I don't need to be precise here. A number of bytes, uh, because 266 00:27:37,380 --> 00:27:42,740 it's so low, it's just going to round up to the maximum size for that allocation. So in some of my 267 00:27:42,740 --> 00:27:49,580 examples, that allocation maximum size was 1000 bytes. So it'll be, uh, 1000 bytes. Uh, and 268 00:27:49,580 --> 00:27:54,080 that will just happen automatically for us. So we don't have to tediously try to put a particular 269 00:27:54,080 --> 00:28:01,440 value in there that's not necessary. So let's try to finish things up. And, uh, again, I, I alluded 270 00:28:01,560 --> 00:28:05,580 to the fact that we're going to have two return addresses. And so if you were trying to do 271 00:28:05,580 --> 00:28:11,420 this and you do one return address, it's never going to work because it's an insufficient number. 272 00:28:11,560 --> 00:28:17,060 So you would really only know this if you were going through and reverse engineering, um, very 273 00:28:17,060 --> 00:28:24,180 closely. Um, so in any case, uh, we go ahead and write that. And you'll notice a lot of these 274 00:28:24,180 --> 00:28:29,440 gadgets are repetitive, the same gadgets. That's just how a lot of these types of, type of 275 00:28:29,440 --> 00:28:31,540 things works. And then we do another one. So we're going to go ahead and write that. And you'll 276 00:28:31,560 --> 00:28:36,280 see the return address. In this case, it's just simply, uh, a ropnop, a ret. It doesn't really do 277 00:28:36,280 --> 00:28:43,160 anything. But we could also, um, make that something else if we wanted. So now we're going to 278 00:28:43,160 --> 00:28:48,740 write our Windows syscall, our method of invoking that to the stack. And so there are a 279 00:28:48,740 --> 00:28:52,440 number of ways in which to do that. The one that I prefer the most is going to be something like 280 00:28:52,440 --> 00:29:01,540 pushdword pointer fs, uh, and then edx. Um, and that edx, we can then change that to, to CZ. 281 00:29:01,560 --> 00:29:08,840 Now, a more desirable one would be like pushdword pointer, uh, fsc0. Uh, but something 282 00:29:08,840 --> 00:29:13,600 like that is going to be so obscure, it's not likely to be found. Uh, but we just simply write 283 00:29:13,600 --> 00:29:21,000 that address to the stack. And there are many other possibilities where the fs register is 284 00:29:21,000 --> 00:29:26,560 present. And we could select one of them. And we could manipu- manipulate things in such a 285 00:29:26,560 --> 00:29:31,540 fashion that they could be in the form of a pushret. Um, we don't have t- have time to 286 00:29:31,560 --> 00:29:35,560 talk about that, but there are a lot of other possibilities. Just as long as we can kind of leak 287 00:29:35,560 --> 00:29:42,920 that fs reg- register, then we're good. And if there is not a direct way, well, we actually could 288 00:29:42,920 --> 00:29:48,840 potentially find that from the R12 register via Heaven's Gate. It's a little bit more tedious to 289 00:29:48,840 --> 00:29:55,660 set that up. Uh, and the automation actually doesn't do that, uh, at least not at present. So we 290 00:29:55,660 --> 00:30:00,620 want to also specify anti-protect virtual memory. All we got to do is just load the appropriate SSN, 291 00:30:00,760 --> 00:30:06,120 so it's going to be hex 50 for Windows 10. And if you're doing Windows 7, there are going to be 292 00:30:06,120 --> 00:30:12,360 additional steps. So the ECX will need to be zero. And then EDI will then need to load the first 293 00:30:12,360 --> 00:30:18,240 parameter, uh, address or- or pointer. And there are a few different ways you can do that through 294 00:30:18,240 --> 00:30:25,640 ROP and the- the white paper will go into some more detail. Uh, you can do this with Windows 10. It doesn't hurt any- hurt anything, it just does- it's just a little bit more 295 00:30:25,640 --> 00:30:32,120 is not required. And then our final step here is, uh, do a stack pivot to- to the start of 296 00:30:32,120 --> 00:30:40,940 everything. So start of, um, uh, invoking the- the syscall. So let's look at our ESP. We have the 297 00:30:40,940 --> 00:30:46,820 pointer to, uh, the gadget to invoke the syscall. We have a return address, two of them, and then our 298 00:30:46,820 --> 00:30:55,620 anti-protect virtual memory addresses. Um, we can go ahead and do that. We have the- the 299 00:30:55,640 --> 00:31:04,640 push keyword pointer FSEBX. That then takes us to a far jump. And then after that call we can see our 300 00:31:04,640 --> 00:31:09,280 return addresses are still there. There is no stack cleanup. You're responsible for that 301 00:31:09,280 --> 00:31:16,660 yourself. So you might want to do a small little stack pivot, uh, with your return address, uh, or one of them. And, 302 00:31:16,800 --> 00:31:25,480 um, you can see the size has been upgraded to a thousand bytes and the base address has been provided rather than the address that we had inputed. 303 00:31:25,640 --> 00:31:32,040 Previously. And we can look at the VPROC, uh, permissions there. And it's 18. 304 00:31:33,320 --> 00:31:40,880 Are we at page execute, uh, read write? Um, into the allocate virtual memory. The setup is gonna be similar. 305 00:31:41,460 --> 00:31:46,120 Um, we're not gonna go into that just in the interest of time. We'll do a quick little demo here. 306 00:31:58,320 --> 00:32:05,740 Alright, so we are gonna get things set up. Right here we're doing that, uh, far jump. To invoke 307 00:32:09,420 --> 00:32:25,620 the, uh, this is messed up. Oh, let's just skip this demo. Alright, so we're gonna go into the 308 00:32:25,640 --> 00:32:32,940 deploy. Uh, with that we are going to change directions a bit. And we are going to, um, talk about 309 00:32:32,940 --> 00:32:35,300 shellcodeless-wrap and invite my co-speaker. 310 00:32:44,440 --> 00:32:55,300 Hey everyone. Um, the purpose of this exploit is to have three different Windows APIs working together collectively. This allows us to 311 00:32:55,640 --> 00:33:03,680 realize more advanced attack than just having just one API. We can implement the functionality of a shellcode directly 312 00:33:03,680 --> 00:33:11,000 without needing to bypass step and without actually having a shellcode. This one is relatively simple. Uh, we'll use the 313 00:33:11,000 --> 00:33:18,160 load library to get the handle to the module, also known as H module. And then pass it to get proc address, um, to get the 314 00:33:18,160 --> 00:33:25,620 runtime address of the system. And then system enables us to execute any command. Let's look at the 315 00:33:25,640 --> 00:33:32,580 shellcode. Let's talk briefly about some of these APIs. Load library. The purpose here is to load a DLL or a module, or if it is 316 00:33:32,580 --> 00:33:39,280 already loaded, which is in, in a lot of times, we simply return the address of it. That is the H module. We have the 317 00:33:39,280 --> 00:33:44,680 handle to the module now, which is the absolute requirement. Our return address, which is 318 00:33:44,680 --> 00:33:53,020 drop now, which will then take us to the next gadget. Get proc address allows us to take that handle and then we can 319 00:33:53,020 --> 00:33:59,000 provide the name of the function and then function gives us the runtime address of the system. Then there is 320 00:33:59,000 --> 00:34:07,380 return address as well. Finally, the most important API is going to be system, which allows us to execute system 321 00:34:07,380 --> 00:34:14,540 commands directly. In this case, we are doing proof of concept string calc.exe, but you can use any command you 322 00:34:14,540 --> 00:34:22,260 want to execute. Our point with this is not just to call this one time, but in essence is to create a recipe so that we can 323 00:34:22,260 --> 00:34:30,080 automate the option generation, which enables us to do it on many different binaries. Next, we're gonna talk 324 00:34:30,080 --> 00:34:35,920 about finding patterns. How do we find patterns for a specific Windows API? First, determine the push 325 00:34:35,920 --> 00:34:42,840 add order. As you can see from the table, the EDI is in slot one, ranging all the way till EAX in slot 326 00:34:42,840 --> 00:34:50,080 eight. Push add puts the registers on the stack in predefined, predictable order. This push add order is 327 00:34:50,080 --> 00:34:51,660 helpful to create many patterns. 328 00:34:53,500 --> 00:35:00,100 This is one set of patterns that could be used. We have many that we are, we're gonna talk about later. Each 329 00:35:00,100 --> 00:35:08,140 register holds a value, but in the case of ESP, we'll always skip over it. This is a pattern for system. As you can see, 330 00:35:08,200 --> 00:35:14,460 each register holds a value or a ROP gadget. For command, we have to provide the pointer to the command, and command 331 00:35:14,460 --> 00:35:22,240 will be part of the payload. This is one of the script that is generated by ROP Rocket. Each register has its own 332 00:35:22,260 --> 00:35:29,180 slot. It is usually not that difficult to load registers, but in the case of EAX, it is using a temporary 333 00:35:29,180 --> 00:35:36,360 register, EBX, to locate the string MSVCRT on the stack dynamically. I would have to calculate that value 334 00:35:36,360 --> 00:35:42,160 manually, but with emulation, ROP Rocket can do that for you. At the end of all the slots, we have push 335 00:35:42,160 --> 00:35:52,240 add. Let's see what happens after push add. Let's take a look at the stack values. The ROP knob is in EDI, and the 336 00:35:52,260 --> 00:35:59,380 RETI, which will execute the next one, and skip over the following two. Then there is load library pointer, and 337 00:35:59,380 --> 00:36:06,640 gem dereference to that load library, along with the return address and MSVCRT as the parameter. As you can see, 338 00:36:07,320 --> 00:36:16,020 the value of EAX is a base address of MSVCRT. This is the result for get proc address, as well as you can see 339 00:36:16,020 --> 00:36:22,100 the value is like runtime address of system. And finally, if all three ROP chain functions correctly, 340 00:36:22,260 --> 00:36:29,100 the command will be executed, which is just popping up a calculator at this point. This is a good 341 00:36:29,100 --> 00:36:34,820 demonstration of using shellcode-less ROM. We are able to execute shellcode-like functionality without 342 00:36:34,820 --> 00:36:41,640 needing to bypass DEP. But seriously, you can do a lot more than just popping up a boring calculator. 343 00:36:42,000 --> 00:36:50,480 The possibilities are endless. Throughout this research, I have created a lot of time to develop this 344 00:36:50,480 --> 00:36:52,240 pattern, trial and error, experimentally. So, let's see what happens after push add. Let's take a look at the 345 00:36:52,260 --> 00:36:57,320 presentation with debuggers, and these are some of the patterns I found. Here we have a dozen 346 00:36:57,320 --> 00:37:06,260 patterns for load library, and here I have like 11 patterns for get proc address, and finally 9 347 00:37:06,260 --> 00:37:11,960 patterns for system. I created these patterns for ROP rocket. If it is not able to build a chain using 348 00:37:11,960 --> 00:37:18,660 one pattern, it can go and try the other one. Since we have a lot of patterns, it is likely to succeed. 349 00:37:19,020 --> 00:37:22,240 If one pattern fails due to lack of ROP gadgets, it will fail. So, let's see what happens after push add. 350 00:37:22,240 --> 00:37:34,980 Having multiple patterns can be really helpful. Let's take a look at the demo. Here is a script 351 00:37:34,980 --> 00:37:40,980 generated by ROP rocket, uh, and there is a payload at the bottom of the script. We have like 352 00:37:40,980 --> 00:37:47,480 three push adds. We're gonna stop at the third push add. And we have finally executed the push add. 353 00:37:47,620 --> 00:37:52,220 We'll get inside the system. We have jumped dereferencing to the system. We have like a 354 00:37:53,200 --> 00:37:56,560 Meine H ling of the system, and uh, and now we are inside the system, we're gonna step out of that, 355 00:37:58,060 --> 00:37:59,280 and here we go. 356 00:38:08,380 --> 00:38:15,620 Thank you very much Shiva. So, the purpose with this shellculist, um, ROP attack is to, again, 357 00:38:15,720 --> 00:38:22,220 automate the whole process so that we can have one of a multitude of pro- of possibilities and 358 00:38:22,240 --> 00:38:28,580 and then ROP rocket. If one doesn't work then there are many others that are available. Uh we 359 00:38:28,580 --> 00:38:33,140 have created other changes as well that are not currently part of the tool but will be included 360 00:38:33,140 --> 00:38:39,680 in the future such as uh get proc address at the library. Um URL download, download the 361 00:38:39,680 --> 00:38:44,020 file and create process A so you can download a file from the internet and then execute it. 362 00:38:44,820 --> 00:38:50,440 Okay so uh on to the next topic uh obfuscation of ROP gadgets. Now why do a lot of ROP 363 00:38:50,440 --> 00:39:00,660 gadgets fail? Uh sometimes it may be due to the recipe uh used to generate them. Um we may 364 00:39:00,660 --> 00:39:05,480 need particular gadgets that simply cannot be found or it could be bad bytes. So bad bytes 365 00:39:05,480 --> 00:39:14,260 could be something like you have uh push add but there are bad bytes there. We could also call 366 00:39:14,260 --> 00:39:19,560 some of these uh gadgets that have bad bytes uh forbidding gadgets. They're not supposed to be 367 00:39:19,560 --> 00:39:25,200 accessible because of uh the so-called bad bytes. But what if we were to to encode them or 368 00:39:25,200 --> 00:39:30,900 obfuscate them? Could we use them directly? So this is uh a script uh created by a student of 369 00:39:30,900 --> 00:39:36,920 mine, Bailey Belisario uh a few years back during the pandemic. And it was a challenging 370 00:39:36,920 --> 00:39:41,600 assignment and the the only push out available wasn't really something that could be easily 371 00:39:41,600 --> 00:39:49,540 done because of um bad bytes. And so he essentially uh encoded it and then decoded it in memory and 372 00:39:49,560 --> 00:39:57,200 then used that push ret to then cause it to be executed. So very clever and very uh elite if 373 00:39:57,200 --> 00:40:03,480 you will. And how he did that was an integer overflow. So that integer overflow will exceed 374 00:40:03,480 --> 00:40:11,760 the con- constraints of a D word and then be truncated producing the desired result. So he 375 00:40:11,760 --> 00:40:19,540 used a found add gadget to do that and then a push um EAX return. So for uh uh a push add 376 00:40:19,560 --> 00:40:23,620 return. So these are very common ways to encode a value all supported by ROP Rocket, XOR, 377 00:40:23,860 --> 00:40:31,460 NOT, NAG and uh integer overflow. So here's an example produced by ROP Rocket which gives us some 378 00:40:31,460 --> 00:40:38,840 lovely commentary. Uh the NAG gadget and it just automates that so you can specify hex 40, read 379 00:40:38,840 --> 00:40:45,700 write executable and it'll do the magic for you. So these are pretty simple other tool tools can do 380 00:40:45,700 --> 00:40:51,900 these. We have the NOT gadget there. Uh we have the XOR gadget so we can weaponize that. We 381 00:40:51,900 --> 00:40:57,960 have a couple pops and then a XOR giving us the desired result. And we also have a found XOR 382 00:40:57,960 --> 00:41:05,700 gadget so we can evaluate the something like XOR EAX 1 and figure out hey it needs uh 41 in 383 00:41:05,700 --> 00:41:13,360 order to create a hex 40. And then integer overflow with a found uh add gadget so we have add EAX 384 00:41:13,360 --> 00:41:18,500 and some large number. And the ROP Rocket will calculate exactly what it needs to be to 385 00:41:18,900 --> 00:41:25,800 produce hex 40. And then also integer overflow where we have two pops uh and then we do an add 386 00:41:25,800 --> 00:41:31,740 register register. And in this case we're doing hex 40 uh once again so you can input it at a 387 00:41:31,740 --> 00:41:38,860 desired value and the tool will just automatically do this on its own. So ROP Rocket is 388 00:41:38,860 --> 00:41:43,340 actually very special in terms of how it generates these uh integer overflows. Uh the ROP Rocket is 389 00:41:43,360 --> 00:41:48,760 it will have start out with 10 predetermined values. If those fail it will generate the it 390 00:41:48,760 --> 00:41:54,560 from the available character set. It'll keep on doing that using its own unique formula until it 391 00:41:54,560 --> 00:42:02,720 finds a set of two values that are free of bad bytes and produce the desired uh value. So uh 392 00:42:02,720 --> 00:42:09,660 let's get back to our example from from uh Bailey. Can we be elite? Uh sorry. And uh do you 393 00:42:09,660 --> 00:42:12,940 want an integer overflow to get our push add? And uh we're going to go back to our example from uh 394 00:42:12,940 --> 00:42:13,280 Bailey. Can we be elite? Uh sorry. And uh do you want an integer overflow to get our push add? And 395 00:42:13,360 --> 00:42:21,320 so um in this case we actually can. So it starts out with uh uh 8 e's, a ver- rather large 396 00:42:21,320 --> 00:42:26,540 number and then we add another uh value and that gives us an integer overflow producing 40, 397 00:42:26,580 --> 00:42:31,220 1 8, 1 12 which is indeed push add. And so this is something that ROP Rocket can just uh 398 00:42:31,220 --> 00:42:36,820 automate and and do in you know less than a second. Makes our life a little bit easier. We 399 00:42:36,820 --> 00:42:42,500 can also do that with a found add gadget too. It's another option. And we get the same exact result. 400 00:42:42,500 --> 00:42:48,540 And so that push ex ret allows us to access that forbidden gadget. So highly effective as a way to 401 00:42:48,540 --> 00:42:57,000 obscure um or obfuscate ROP gadgets and so uh greatly expands the number of possibilities. Uh 402 00:42:57,000 --> 00:43:01,900 so the tool does have a remake function. So that remake function can allow us to if something 403 00:43:01,900 --> 00:43:08,740 doesn't work um because of bad bytes we can still use it and we can remake it by encoding it and 404 00:43:08,740 --> 00:43:12,480 then having it decoded on the fly and then do a push ret. So that really allows us to get a lot of 405 00:43:12,480 --> 00:43:18,040 data. So that really really expands the attack surface. So the tool is re- really fast. It does 406 00:43:18,040 --> 00:43:24,700 have parallelism to maximize available cores, persistence. So um if you've already evaluated a 407 00:43:24,700 --> 00:43:31,900 uh a binary it'll save um the gadgets found. And you can see some of what it looks like right 408 00:43:31,900 --> 00:43:39,900 there. Um and it also provides emulation. The emulation is done internally. Um so it can 409 00:43:39,900 --> 00:43:42,460 evaluate each and every gadget if it needs to. And then it also provides the ability to do a lot of 410 00:43:42,460 --> 00:43:53,580 things. So it can be a very short brief gadget like uh add EBX5 and then a less optimal one may 411 00:43:53,580 --> 00:44:00,980 have other uh intervening lines. But it might be okay. So um the emulation can allow us to find 412 00:44:00,980 --> 00:44:04,800 other possibilities. And this is not something you would see. It's just internal debugging 413 00:44:04,800 --> 00:44:12,100 output. And it also will uh emulate uh actual ROP chains. So sometimes we need to calculate the distance 414 00:44:12,460 --> 00:44:22,620 to a parameter cause we need a pointer. And so it can recursively uh do that. And how it will work 415 00:44:22,620 --> 00:44:28,500 is it will start with a guess and if it's wrong it probably will be wrong. It'll try again and it'll 416 00:44:28,500 --> 00:44:34,040 use the output to try to get it closer. And it'll keep doing that recursively until it is correct. 417 00:44:34,200 --> 00:44:42,060 And it's smart enough that it knows when it has actually achieved its goal. And so that's some more internal debugging information there. 418 00:44:42,460 --> 00:44:48,840 And there is a great deal of metadata to help facilitate that. So it has return addresses, this is a syscall, 419 00:44:49,160 --> 00:44:56,620 uh different parameters. And so it can check to see um you know if we've achieved a certain particular goal. 420 00:44:57,400 --> 00:45:06,520 And so calculating distances for certain types of syscalls uh or even some of the what what Shiva did is going to be 421 00:45:06,520 --> 00:45:12,440 nec- necessary for success. And so that emulation makes some of this possible. And so that emulation 422 00:45:12,460 --> 00:45:18,200 makes some of this possible. Without this emulation we couldn't do that. So uh it is immensely useful. 423 00:45:18,740 --> 00:45:25,820 Uh we are we have come to the conclusion of our talk. Uh the tool is not up right now but it should be up 424 00:45:25,820 --> 00:45:33,980 about sometime in the next week or so. Uh so go ahead and take a a picture of that if you like and um be sure to check it out. 425 00:45:34,100 --> 00:45:42,320 And if you have any feedback um be sure to let us know. Uh we are happy to meet down there and take 426 00:45:42,460 --> 00:45:46,840 any questions. I think we're about out of our time. So uh thank you very much for attending our 427 00:45:46,840 --> 00:45:49,100 session and hope you enjoy the rest of your DEF CON.