Good morning, DEF CON. Thank you for coming to see our session. Hopefully you'll enjoy it. Little bit about, a little bit about myself. My name is Dr. Bramwell Brizendine. I'm the former and founding director of the Verona Lab, which specializes in vulnerability and exploitation research. Uh, creator, creator of several different tools, the Shell Wasp, Chop Rocket, and Sharem. And I'm presently an assistant professor at UAH. Uh, I do have a PhD in cyber operations, which is a highly, uh, technical, uh, degree specializing in reverse engineering and exploitation. Um, just as a kind of a side note, I have kind of lost my voice a bit, but it has been improving, so I'll just try to do the best that I can. Uh, there is some contact information down below, so feel free to, uh, reach out to me if, uh, if you have questions or if you so desire. Uh, I'm joined by my graduate student, Shiva, and he is a master's of computer science student at UAH and he's interested in writing software, uh, web apps as well as block chain. Uh, he's got a lot of contact information there, so feel free- feel free to reach out with any, uh, opportunities for Shiva. So when we started this this research the, the goal, the idea was can we bring something fresh, something, something new to ROP because quite frankly it seemed to be getting a little bit kind of stale, kind of predictable. Uh, no doubt it w- w- the techniques that we used seemed to work very well but it's just a lot of the same types of things uh, over and over. Now there are a number of tools that can facilitate uh, getting uh, ROP gadgets. Uh, MONA, which of course has been around forever. ROP gadget, uh, ROPR, uh, as well as others. And additionally for jump oriented programming the Jop Rocket, which is actually a tool that uh, I created myself and presented at DEF CON in 2019. So again, um, the idea is to try to make it fresh, to try to make it exciting again. Uh, and part of this inspiration is because code reuse attacks in general should be inherently um, very free, very flexible. We shouldn't be confined by the shackles of what has been done before. But instead I'd rather see us embrace an openness, a desire to do something new, to something a little bit different. So part of my thinking is trying to kind of uh, think out of the box. So I spent a huge amount of time, uh, actually thousands of hours working with jump oriented programming. Now I didn't create it, but I did create the, the tool that helped to facilitate that. And a lot of uh, practical Jop just really had not been documented. And so I set about uh, providing that documentation uh, so that people actually wanted to do something significant with it. They'd have the capability of, of doing so. And there are a few different white papers out there that myself and Austin Babcock have, have written. So uh, by its very nature Jop is extraordinarily flexible. And I wanted to try to bring some of that to, to Rop and to introduce some new ideas. So uh, without further ado then, let's uh, see what some of these novel contributions may include. So the next generation state of the art uh, Rop gadget tool. Rop rocket is going to be uh, among these. Uh, and part of the, part of it is going to be uh, we'll have automatic Rop chain generation. So it will create the chains for these different techniques. Um, some of them are also in their own regard uh, novel approaches or novel techniques. So adapting Heaven's Gate to, to return oriented programming. Utilizing Windows Syscalls to bypass dep rather than the traditional Windows APIs. Uh, and then something that I like to call uh, shell codeless Rop, where, where instead of uh, trying to avoid data, uh, avoid uh, trying to bypass data execution prevention, we just simply uh, avoid it and invoke that shell code-like functionality directly by calling the, the appropriate Windows APIs. Uh, obfuscation of, of Rop gadgets which I'll get into uh, more later on. And then emulation of uh, Rop gadgets and as well as chains which does help us uh quite significantly. Okay so we're gonna start out here with uh Heaven's Gate and R.O.B. And I know that uh some of you are gonna be very familiar with Heaven's Gate for others it may be uh your first time encountering it so a little bit of history lesson. Now this is a traditional way in which we invoke it so uh if we're gonna go from x86 transition to 64 bit mode this is something that the the Windows operating system does continuously uh whenever we make use of an in in NTDLL function so it just happens automatically as part of uh making use of Windows sys calls. So the the the old kind of uh formula if you wanna call it that that you'll see it in malware or shell code is you'll do uh push 33 for the 33 uh CS selector which designates it going to 64 bit mode. And if you want to do that one step, if the fear of�� uk. That your computer is crashed and where 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 The reality is you don't have to have that return address or that destination address immediately after the red F. It could be anywhere in process memory. So that's a tremendous amount of flexibility that just isn't really being used. So of course we're not writing shell code. We are writing return oriented programming. So we need to find a new way to do that because we can't just simply write shell code. So we are introducing a couple new ways to do that that will um allow us to perform heaven's gate. And by doing this we can thereby expand the attack surface from uh wild 64 which means we're working in 32 bit. We're emulating a 32 bit application uh to 64 bit mode. Now you could do the opposite if you wanted. I don't really see much of a point but that that's fine. You can still do it. So uh our approach here is we're going to be utilizing the push add instruction. So if you're familiar with virtual alloc or virtual protect uh the types of change produced by something like mona is following the same idea and Shiva will be talking a little bit more about uh how this works. Um but these are the patterns for uh for heaven's gate. So we have 11 of them and I can actually increase it to to more than those uh 11. And uh so if one of these is not able to work then the tool will just simply try another one. Now these gadgets they're not exceedingly difficult to find. So very likely we will succeed. So let's take a look here at pattern 7. So we just simply load up the registers with the uh appropriate values. Uh and these values a lot a lot of them are very simple. They're ROPNOPs or uh in this case when we do the push add it's going to push them in a predefined order. So it'll go EDI ESI all the way to EAX. And so we'll have there that ret uh zero uh C and that's going to skip over the number a bunch of stuff. It'll it'll firstly execute the ROPNOP and ESI and then it'll skip over stuff until we get to that jump due to reference EBX. And then that will then cause us to go to EBX. What is EBX? Well that's the red F. And so then the red F will then uh cause that's gonna what's gonna initiate the heaven's gate. And then on the stack after that we'll have uh the destination address and the 33 selector. So everything will be perfectly set up and it should work. So let's take a look at the stack before and after. So uh DD ESP we can see we have our destination address and the 33 selector. And then after that red F uh they're gone. And you'll notice that the the address is now a Q word instead of a D word. It has expanded. And we have actually switched architectures. So uh we have that red F up above and then down below again everything we have Q words and then notice we have push uh R and then we have uh D words. Uh RBP instead of uh EBP. So we have switched to to 64 bit mode. Now just one little note for those who may not be aware, the only time you can actually view this is if you're in the 64 bit version of uh WinDebug. Any other debugger will not work or it will produce uh aberrant behavior. And there's no reason you can't uh open up a 13 bit application and then attach it with a 64 bit uh WinDebug. Let's take a look quickly here at pattern number 11. So this is a pattern number 11. Now this one is very very simple. So we have a couple rop nops. We have a pop EBP to consume the the the ESP which we just want to skip. Uh we have another rop nop and then the red F and everything is set up. We have the destination address and we have the 33 selector. So okay we've done the heaven's gate. Uh what is the advantage of this? Why do we want to do this? Good question. Wow. Excellent question. So uh by doing this we're able to find this. There could be many more registers. 64 bit registers. And the idea is maybe there's something that we're we want to do in 32 bit mode but we just don't have the right gadgets. But if we expand it to 64 bit mode maybe there are additional gadgets. Now um the reality is a lot of times however um there may not be some of these extra 64 bit gadgets. It's just because the bytes we're we're required to produce them may not be there. And so uh the um sometimes they will be purely by happenstance. And additionally there can be some very valuable structures that are accessible in x64 which you can access via the R2 R12 register. For instance the the tab 64. You get the tab 64 you can go to tab 32 and then pep 32 and pep 64 so it's actually immensely valuable. So if you can do that and then leak the R12 then that's very useful. 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 application. Uh technically you could call uh 64 bit NTDL functions. Uh that'd be very difficult. Uh it's not something that I personally would recommend uh trying to do. Uh people out out there have 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 would want to return back, back to, um, x86. Um, and so we have a forbidding gadget, unfortunately, so the push add simply doesn't exist. So if you try to do a push add, you'll see hex 60 and three question marks. How sad. So in this case, we're going to do a series of move dereferences and, uh, kind of like a snipe gadget. So we'll create an allocation of memory and we'll just set up what we want the stack to be and then we'll do a stack pivot and then everything should be, should be good and jolly. So we'll take a look at some of these, uh, different, uh, steps that we can, can take. So first thing we want to do, we want to get a pointer to memory. Let's make it easy and simple. We can do ESP. And then we're going to go move ahead 250 bytes and that's going to be our pointer reference. We're going to start building our different, uh, parameters, our, our, our, our, our, our, our, our, our, our, our, our, our, our, return address, et cetera. And we're not going to do every little thing here because it'll be a little bit tedious. We'll do, do a few of them. So, uh, we do want to write the, the retf, because remember that retf is going to be what's going to kick it off. It's that, that's a far ret. We only, we're not going to typically do that and, and ROP, but it does allow us to initiate the heaven's gate. So we'll get a, a retf. It doesn't matter which retf and we'll write that address there. And we do that with a move dereference. So it's move dword pointer RBX EAX. And it's not a Q word, uh, which some of you who are very observant may notice. Um, it's going to be a lot more common. You'll see the D words just because you're going from 32 bit to 64 bit. And, um, a lot of times when you do a move dereference technique, which is very, uh, effective, by the way, in traditional ROP, you'll do a series of four increments. Well, guess what? It's not going to work out too well, uh, with, with this because the, the byte to produce those increments, uh, will no longer produce increments. So the only increments you have will be created by happenstance. So instead we'll just do an add register, register, uh, and do a distance of four. It's a little bit more tedious, uh, but it's something that the tool can automate for us. So, we don't have to worry about it too much. Um, and then we also want to finish writing the address of the red F because remember we're 64 bit mode, so we're, we need to do a Q word rather than a D word and our move dereference gadget was a D word, so we're going to do, uh, XOR EAX, EAX, the result is zero. And we're going to write that there so we get a monstrously long, uh, uh, red F gadget address there. And then now we need to do the destination address and the 23 selector. So the 23 selector allows us to go back, uh, to the 64 bit mode. Um, and this is kind of where it's kind of a little weird, kind of funky. Um, we're 64 bit mode, we've been dealing with Q words, but now we're going to go back to, to D words. So we're going to represent the, the destination address and the 23 selector is D words. Hey, it makes our life a little bit easier so I'm not complaining. So, uh, I, I didn't show the steps for those, uh, but now what we want to do is do a stack pivot and of course there are many different ways to do a stack pivot. Um, but what we're going to do is we're going to get it, get it aligned so that, um, RAX, which is kind of where we've been building our gadgets, we want it to, to point to, to the red F. And so we're going to do, uh, a very long 16 digit number which is actually equal to negative 12. And then once we do that then, um, we can just take another before and after so do DDESP. We have the, the return address and the 23 selector and then after that, you'll notice that x86 is present and, um, we have succeeded. We've gone back to x86. So let's actually do a quick little demo here. Okay, it's all set up for us. So there's our push ad. 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 destination address, 33 selector. So now we are in x64. You can see the registers have indeed 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, we're at the red F. Go from x64 to x86. Let's look at the stack. We have the destination address and the 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. Okay, so this novel form of heaven's gate, again, this allows us to go back and forth, uh, between them. Obviously, a, a consideration is going to be the size of the payload. We want to be very, uh, we want to, 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, 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 just for the novelty of it. Uh, and again, this, this is potentially capable of expen-, expanding the attack surface. Um, and the, the technique or the approach that we've introduced is a little bit more complex and different from the, the standard approach that we showed you earlier. Okay, so we're going to segue into our, uh, next topic here, which is going to be, uh, Windows syscalls. So, very, uh, briefly, I'm going to speed through some of these, just as kind of a refresher, uh, for some people. So, what is a Windows syscall? Um, it's going to be something where you, you could call a kernel 32 function, 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. In order to do that, it will load into EAX, the appropriate SSN, syscall system number. And then, uh, you transition from user mode to kernel mode. And then after that, um, there's a bunch of stuff going on in kernel mode. It's really outside the scope of this. So, this is not something that's really intended for the average programmer, uh, to be doing. And the appeal of Windows syscalls is, um, it's much, much harder for it to be hooked by EDR. And to be, to, to prevent it from, from, from working, um, so that can definitely be very beneficial. Um, Melissa's Windows API is much easier to, to hook those, thereby preventing their, their usage. Uh, to my knowledge, I don't think this has been used in, uh, x86, uh, while 64. Again, that's the 32-bit. Um, now if you're doing syscalls in 64-bit mode, the, the technique is pretty much the same. You can approach, it's gonna be a little bit different. You can actually use an actual syscall instruction. 64-bit instruction, you're not gonna be using that. And, um, while 64, we'll be doing things in a different way. And one of the, the issues with syscalls is we have a, what we call a problem of portability. So, with Windows 10, for instance, um, that SSN potentially could change. You have more than 13 different OS builds. So, sometimes those SSNs will stay the same, but other times they will change. So, you could have, um, I think, uh, NT Protect Virtual Memory, I think for Windows 7 is hex 15 and I think for Windows 10 and 11 it's hex 18. So, um, those have changed. Others will change much more frequently, some less frequently. So, very briefly, let's, um, go over how we can reverse engineer 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. And, you can see we're loading into EAX, hex 15, um, so all that we can see is NT allocate virtual memory. 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 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 just need to get uh instructions that have FS in it and GS is gonna be the 64 bit equivalent. So there you see the you have a jump and you have a 33 selector and colon and then the address so that'll be switching to 64 bit mode so that'll be a form of Heaven's Gate in and of itself. And Windows 10 is a little bit different so uh we have hex 18 and to allocate virtual memory and the um set up is a little bit different but for our purposes we don't really care because we go to FSC zero it's gonna be pointing to that same address so we can still continue to use that FSC zero. In Windows 11 things are a little bit different again but again that Windows 7 way of invoking the syscalls is still able to to work so um uh as many of you are aware a lot of uh Windows 10 is a little bit different than Windows 10 for a while. So Windows-based ROP has gonna be focused on bypassing mitigations, one of the most prevalent mitigations is gonna be data execution prevention which says the memory should be readable and writable or executable but not both. That doesn't mean it can't be both, it can be but we need to use certain APIs or syscalls in order to make that happen. Virtual alloc we created a region of memory that has the desired permissions. Virtual protect we modified the permissions of existing memory allocations. So those are some of the are some very old, very uh simple ways of doing it and can be easily blocked. Uh there are alternative ways as well or ways to make them work. Um but Windows syscalls is gonna be something that is uh a little bit more low level, a little bit deeper way of of doing this. Um and again those syscall SSNs do change but the good news is for for Windows um 10 and 11 they're gonna stay the same for the two that we care about and Windows 7 is gonna be the same so um that works out uh very well for us. We don't, what this means practically speaking is we don't have to worry about um resolving the OS build like you would if you were using a traditional Windows syscall tool. We can just say okay I'm attacking Windows 10, doing Windows 11, I've done a little bit of reconnaissance, I know uh about my targets. So um we can dispense with that step. It's not necessary for these particular APIs. And I think it'd be a lot more challenging to uh to do that and um in ROP but uh maybe we'll do that later on. So how do we perform these uh the Windows syscall in Windows 10 and 11, particularly while 64? Well that can be a little bit challenging but ultimately as long as we follow the proper calling convention whether it be for the API or the syscall, it's gonna be a little bit more challenging. But ultimately as long as we follow the proper calling convention, whether it be for the API or the syscall, it's gonna be a little bit more challenging. But ultimately it's gonna work. So we just simply get the stack aligned properly uh with the return addresses and notice I didn't say return addresses, that's not a, I didn't misspeak there, it is indeed plural for for Windows syscalls. Um and then initiate things and it and it should work. So uh we'll see how that works here um shortly. So important Windows syscalls that are this tool utilizes is gonna be NT allocate virtual memory, the deeper version of virtual alloc. And NT protect virtual memory, which is the deeper version of a virtual protect. So we're gonna focus here on NT protect virtual memory from a ROP standpoint it's a little bit more challenging to set up. And one of the big things with Windows syscalls is instead of just using direct values like your Windows APIs, you'll have a lot of pointers. So a pointer is going to be, you go inside of the pointer and it has that value so we need to set it up on a somehow um create these pointers for for base address, number of bytes to protect and uh old access protection. And if we do that then um we should be in a good position. So we're using the move dereference approach rather than the push add approach and um so we want to get a pointer reference to memory. This is gonna be where we are going to build our parameters, our return addresses and we're gonna put uh a gadget there to invoke the Windows syscall which we'll talk about momentarily. So we'll just move uh ESP to EAX and then push it ahead 250 bytes. Uh now what this is gonna be something that'll be a little bit different for a lot of people is we need to set up a value for for a pointer. How do we do this uh in in ROP? And my solution is uh so you could either do increments or decrements. I've chose chosen to do uh decrements um for the automation and for this example. And so we're just gonna build the values for the pointers immediately after the parameters and then that just makes it easier for us to then move the pointers over to uh the parameters where where they where they need to be. So get base address value for pointer is what we're creating here and this may look a little weird if you're. scrutinizing it very closely. We moved ESP into EAX and now I'm moving that into EBX. So that doesn't really seem to make much sense, does it? Why am I not choosing a better one? Well, uh, I'll address that in a little bit. Um, and so then we then write that base address to, to memory with, uh, a move dereference and then we have a series of four decrements. So we then decrement to our next slot that we will then initialize with a next uh, value for another pointer. And this one is going to be number of bytes to protect. And if you look very closely, I'm putting one byte. I'm going to protect one byte. That's kind of bizarre. Um, I'll explain that again momentarily. It's kind of what I like to call a little trick just to, to save on gadgets. So we'll write that with a move dereference and four decrements. And I'm also going to, at this point, I'm going to save a point of reference to the number of bytes. Um, moving that into EDI. I'll be using that in a little bit. And I'm going to skip through some of these. I'm not going to go through the whole thing. There is going to be a white paper, so if you want to scrutinize the entire source code, you'll have that available as well as the tool itself. So then, uh, we've skipped a little bit here, but giving the pointer is a parameter. So we have the point of reference now in EDI. We're going to move EDI into EDI. And then we're going to move the pointer into EDI. And then we're going to BX and now we're going to increment EBX four times. So we're incrementing, not decrementing. And then we're going to write that to, uh, EAX. And that's going to be our number of bytes to protect, which again is just the value of one, which is odd. And so now I'm going to explain why I'm doing some of these kind of bizarre and odd type things. So the base address, um, what we're going to do is we're going to get it to, to round down to the, to the, the base address of that particular allocation. So I don't need to be precise here. A number of bytes, uh, because it's so low, it's just going to round up to the maximum size for that allocation. So in some of my examples, that allocation maximum size was 1000 bytes. So it'll be, uh, 1000 bytes. Uh, and that will just happen automatically for us. So we don't have to tediously try to put a particular value in there that's not necessary. So let's try to finish things up. And, uh, again, I, I alluded to the fact that we're going to have two return addresses. And so if you were trying to do this and you do one return address, it's never going to work because it's an insufficient number. So you would really only know this if you were going through and reverse engineering, um, very closely. Um, so in any case, uh, we go ahead and write that. And you'll notice a lot of these gadgets are repetitive, the same gadgets. That's just how a lot of these types of, type of things works. And then we do another one. So we're going to go ahead and write that. And you'll see the return address. In this case, it's just simply, uh, a ropnop, a ret. It doesn't really do anything. But we could also, um, make that something else if we wanted. So now we're going to write our Windows syscall, our method of invoking that to the stack. And so there are a number of ways in which to do that. The one that I prefer the most is going to be something like pushdword pointer fs, uh, and then edx. Um, and that edx, we can then change that to, to CZ. Now, a more desirable one would be like pushdword pointer, uh, fsc0. Uh, but something like that is going to be so obscure, it's not likely to be found. Uh, but we just simply write that address to the stack. And there are many other possibilities where the fs register is present. And we could select one of them. And we could manipu- manipulate things in such a fashion that they could be in the form of a pushret. Um, we don't have t- have time to talk about that, but there are a lot of other possibilities. Just as long as we can kind of leak that fs reg- register, then we're good. And if there is not a direct way, well, we actually could potentially find that from the R12 register via Heaven's Gate. It's a little bit more tedious to set that up. Uh, and the automation actually doesn't do that, uh, at least not at present. So we want to also specify anti-protect virtual memory. All we got to do is just load the appropriate SSN, so it's going to be hex 50 for Windows 10. And if you're doing Windows 7, there are going to be additional steps. So the ECX will need to be zero. And then EDI will then need to load the first parameter, uh, address or- or pointer. And there are a few different ways you can do that through 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 is not required. And then our final step here is, uh, do a stack pivot to- to the start of everything. So start of, um, uh, invoking the- the syscall. So let's look at our ESP. We have the pointer to, uh, the gadget to invoke the syscall. We have a return address, two of them, and then our anti-protect virtual memory addresses. Um, we can go ahead and do that. We have the- the push keyword pointer FSEBX. That then takes us to a far jump. And then after that call we can see our return addresses are still there. There is no stack cleanup. You're responsible for that yourself. So you might want to do a small little stack pivot, uh, with your return address, uh, or one of them. And, 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. Previously. And we can look at the VPROC, uh, permissions there. And it's 18. Are we at page execute, uh, read write? Um, into the allocate virtual memory. The setup is gonna be similar. Um, we're not gonna go into that just in the interest of time. We'll do a quick little demo here. Alright, so we are gonna get things set up. Right here we're doing that, uh, far jump. To invoke the, uh, this is messed up. Oh, let's just skip this demo. Alright, so we're gonna go into the deploy. Uh, with that we are going to change directions a bit. And we are going to, um, talk about shellcodeless-wrap and invite my co-speaker. Hey everyone. Um, the purpose of this exploit is to have three different Windows APIs working together collectively. This allows us to realize more advanced attack than just having just one API. We can implement the functionality of a shellcode directly without needing to bypass step and without actually having a shellcode. This one is relatively simple. Uh, we'll use the 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 runtime address of the system. And then system enables us to execute any command. Let's look at the 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 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 handle to the module now, which is the absolute requirement. Our return address, which is drop now, which will then take us to the next gadget. Get proc address allows us to take that handle and then we can provide the name of the function and then function gives us the runtime address of the system. Then there is return address as well. Finally, the most important API is going to be system, which allows us to execute system commands directly. In this case, we are doing proof of concept string calc.exe, but you can use any command you 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 automate the option generation, which enables us to do it on many different binaries. Next, we're gonna talk about finding patterns. How do we find patterns for a specific Windows API? First, determine the push add order. As you can see from the table, the EDI is in slot one, ranging all the way till EAX in slot eight. Push add puts the registers on the stack in predefined, predictable order. This push add order is helpful to create many patterns. This is one set of patterns that could be used. We have many that we are, we're gonna talk about later. Each 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, each register holds a value or a ROP gadget. For command, we have to provide the pointer to the command, and command will be part of the payload. This is one of the script that is generated by ROP Rocket. Each register has its own slot. It is usually not that difficult to load registers, but in the case of EAX, it is using a temporary register, EBX, to locate the string MSVCRT on the stack dynamically. I would have to calculate that value manually, but with emulation, ROP Rocket can do that for you. At the end of all the slots, we have push 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 RETI, which will execute the next one, and skip over the following two. Then there is load library pointer, and gem dereference to that load library, along with the return address and MSVCRT as the parameter. As you can see, the value of EAX is a base address of MSVCRT. This is the result for get proc address, as well as you can see the value is like runtime address of system. And finally, if all three ROP chain functions correctly, the command will be executed, which is just popping up a calculator at this point. This is a good demonstration of using shellcode-less ROM. We are able to execute shellcode-like functionality without needing to bypass DEP. But seriously, you can do a lot more than just popping up a boring calculator. The possibilities are endless. Throughout this research, I have created a lot of time to develop this pattern, trial and error, experimentally. So, let's see what happens after push add. Let's take a look at the presentation with debuggers, and these are some of the patterns I found. Here we have a dozen patterns for load library, and here I have like 11 patterns for get proc address, and finally 9 patterns for system. I created these patterns for ROP rocket. If it is not able to build a chain using one pattern, it can go and try the other one. Since we have a lot of patterns, it is likely to succeed. If one pattern fails due to lack of ROP gadgets, it will fail. So, let's see what happens after push add. Having multiple patterns can be really helpful. Let's take a look at the demo. Here is a script generated by ROP rocket, uh, and there is a payload at the bottom of the script. We have like three push adds. We're gonna stop at the third push add. And we have finally executed the push add. We'll get inside the system. We have jumped dereferencing to the system. We have like a Meine H ling of the system, and uh, and now we are inside the system, we're gonna step out of that, and here we go. Thank you very much Shiva. So, the purpose with this shellculist, um, ROP attack is to, again, automate the whole process so that we can have one of a multitude of pro- of possibilities and and then ROP rocket. If one doesn't work then there are many others that are available. Uh we have created other changes as well that are not currently part of the tool but will be included in the future such as uh get proc address at the library. Um URL download, download the file and create process A so you can download a file from the internet and then execute it. Okay so uh on to the next topic uh obfuscation of ROP gadgets. Now why do a lot of ROP gadgets fail? Uh sometimes it may be due to the recipe uh used to generate them. Um we may need particular gadgets that simply cannot be found or it could be bad bytes. So bad bytes could be something like you have uh push add but there are bad bytes there. We could also call some of these uh gadgets that have bad bytes uh forbidding gadgets. They're not supposed to be accessible because of uh the so-called bad bytes. But what if we were to to encode them or obfuscate them? Could we use them directly? So this is uh a script uh created by a student of mine, Bailey Belisario uh a few years back during the pandemic. And it was a challenging assignment and the the only push out available wasn't really something that could be easily done because of um bad bytes. And so he essentially uh encoded it and then decoded it in memory and then used that push ret to then cause it to be executed. So very clever and very uh elite if you will. And how he did that was an integer overflow. So that integer overflow will exceed the con- constraints of a D word and then be truncated producing the desired result. So he used a found add gadget to do that and then a push um EAX return. So for uh uh a push add return. So these are very common ways to encode a value all supported by ROP Rocket, XOR, NOT, NAG and uh integer overflow. So here's an example produced by ROP Rocket which gives us some lovely commentary. Uh the NAG gadget and it just automates that so you can specify hex 40, read write executable and it'll do the magic for you. So these are pretty simple other tool tools can do these. We have the NOT gadget there. Uh we have the XOR gadget so we can weaponize that. We have a couple pops and then a XOR giving us the desired result. And we also have a found XOR gadget so we can evaluate the something like XOR EAX 1 and figure out hey it needs uh 41 in order to create a hex 40. And then integer overflow with a found uh add gadget so we have add EAX and some large number. And the ROP Rocket will calculate exactly what it needs to be to produce hex 40. And then also integer overflow where we have two pops uh and then we do an add register register. And in this case we're doing hex 40 uh once again so you can input it at a desired value and the tool will just automatically do this on its own. So ROP Rocket is actually very special in terms of how it generates these uh integer overflows. Uh the ROP Rocket is it will have start out with 10 predetermined values. If those fail it will generate the it from the available character set. It'll keep on doing that using its own unique formula until it finds a set of two values that are free of bad bytes and produce the desired uh value. So uh let's get back to our example from from uh Bailey. Can we be elite? Uh sorry. And uh do you want an integer overflow to get our push add? And uh we're going to go back to our example from uh Bailey. Can we be elite? Uh sorry. And uh do you want an integer overflow to get our push add? And so um in this case we actually can. So it starts out with uh uh 8 e's, a ver- rather large number and then we add another uh value and that gives us an integer overflow producing 40, 1 8, 1 12 which is indeed push add. And so this is something that ROP Rocket can just uh automate and and do in you know less than a second. Makes our life a little bit easier. We can also do that with a found add gadget too. It's another option. And we get the same exact result. And so that push ex ret allows us to access that forbidden gadget. So highly effective as a way to obscure um or obfuscate ROP gadgets and so uh greatly expands the number of possibilities. Uh so the tool does have a remake function. So that remake function can allow us to if something doesn't work um because of bad bytes we can still use it and we can remake it by encoding it and then having it decoded on the fly and then do a push ret. So that really allows us to get a lot of data. So that really really expands the attack surface. So the tool is re- really fast. It does have parallelism to maximize available cores, persistence. So um if you've already evaluated a uh a binary it'll save um the gadgets found. And you can see some of what it looks like right there. Um and it also provides emulation. The emulation is done internally. Um so it can evaluate each and every gadget if it needs to. And then it also provides the ability to do a lot of things. So it can be a very short brief gadget like uh add EBX5 and then a less optimal one may have other uh intervening lines. But it might be okay. So um the emulation can allow us to find other possibilities. And this is not something you would see. It's just internal debugging output. And it also will uh emulate uh actual ROP chains. So sometimes we need to calculate the distance to a parameter cause we need a pointer. And so it can recursively uh do that. And how it will work is it will start with a guess and if it's wrong it probably will be wrong. It'll try again and it'll use the output to try to get it closer. And it'll keep doing that recursively until it is correct. 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. And there is a great deal of metadata to help facilitate that. So it has return addresses, this is a syscall, uh different parameters. And so it can check to see um you know if we've achieved a certain particular goal. And so calculating distances for certain types of syscalls uh or even some of the what what Shiva did is going to be nec- necessary for success. And so that emulation makes some of this possible. And so that emulation makes some of this possible. Without this emulation we couldn't do that. So uh it is immensely useful. 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 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. And if you have any feedback um be sure to let us know. Uh we are happy to meet down there and take any questions. I think we're about out of our time. So uh thank you very much for attending our session and hope you enjoy the rest of your DEF CON.