Omer is now going to present Exploiting Windows, Exploit Mitigation for ROP Exploits. I knew exactly what I was doing there. Alright. Go ahead Omer. Have a good time dude. Okay. Hello everyone thank you for coming. Let me get sorted and we can start. Okay so first thing first. Doesn't work? Okay. So I bet your parents taught you well and taught you- told you don't listen to strangers so I'll- I will introduce myself. I'm Omer Yair. I manage the endpoint team at Javelin Networks. We are a small startup that uh decided to protect your endpoint on the enterprise from uh to protect your active directory from the endpoint. And Symantec uh believed in us and acquired us a few like mon- 9 months ago. Uh even though I'm still not sure how I'm supposed to pronounce the new title. I'm also a photographer and you can follow me on Twitter. So I want to start with the geist of this talk. It's a quote by Gilles Deleuze, a French philosopher and he said the concept is a brick. It can be used to build a courthouse of reason or it can be thrown through the window. And throughout this talk we- we will identify all those bricks that make up ROP exploits, Windows Mitigations, Windows Exploit Mitigation and we will see how we can use those to break Windows. So what's on that agenda? Yeah, we'll start talking about ROP uh 101. I will dumb down the things as much as possible, make it simple so everyone can understand. Then we'll talk about Windows Exploit Mitigations and we'll see how we can abuse them. Next about ROP Mitigations and we- we'll see how we can bypass them. And lastly there will be a demo where you will clap hands and if we will all- we will all behave yourself there will be a little surprise too. So let's start. We can't start talking about ROP exploit without mentioning the- smashing the stack for a few minutes. So uh, let's start with the stack overflow. This is a common term for funding and profit and is there anyone in the audience that ever heard the term for funding and profit? Please raise your hand. Yeah, it's quite common and I hope you all know where the source of this uh term came from. And it's an article by Allef One that he wrote on 96 about the mechanics of the stack overflow. And we can't talk about stack overflow without explaining how stack semantics works. So if you call a function in a 32 bit processor uh you first need to push the parameters the stack on my slides will grow upwards. And then when the call opcode is issued, the return address is pushed into the stack and the instruction pointer jumps to the function that you called. Now that function will allocate space for itself on the stack, do its stuff and eventually it will de-allocate the space and the red opcode will pop the return address from the stack. So how Stack Overflow works? Well let's take a hypothetical example, completely hypothet- hypothetical. Let's say you have a program that gets an input and looks for pa- for details about the user. So it first allocates its uh space for the stack, then it uses get test to receive a buffer from the user. Now a normal user will just fill up the few bytes of the buffer but a hacker will start overwriting the buffer until eventually the hacker overwrites the return address. So now, uh if you are a lead hacker you won't just write random bytes, you will write your shellcode instead and on the place that you write the return address, let's say hypothetical again, you know the address of the stack, you can just write the address of the stack where your shellcode starts. So now when the return code will be issued, the instruction pointer will jump to the shellcode on your stack and now you can run a shell. Now this is not a hypothetical at all, that was the exact source code and the exact buffer overflow, exact shellcode that was used on the Morris worm and that was 1988, almost a decade before LF1 published his article on uh stack overflow. So the security eye industry actually knew about stack overflow and the potential hazardous disasters that it can make, but still didn't do anything and it was so bad that it prompted the co- the formation of the self-coordination center. So again you would think that after LF1 published his article the security industry will wake up and start protecting everyone but no, on 2003 all you had to do to exploit the buffer overflow was to run the shellcode on your stack. So now you can run the shellcode on the stack, you can frustrated Because everything else there is- but what I on a Me nell was to run this simple HTML page and that's a CV but by Matt Miller and what happened behind the scene is that Internet Explorer just replaced the every slash character with an underline slash underline which caused to miscalculate the number of bytes that it needed to write. And then it caused you to write like the first buffer to the stack and you had the ability to override the return address and then you could write a shellcode. But now this is not, uh, uh, uh, an OS where you can guess the address of the, the stack. This is Windows, it's a modern OS. Well, yeah, then Matt Miller used a different theory, trick. He knew that the system DLLs were always loaded to the same address. So he looked in those DLLs and found the, an opcode which is jump ESP, which is, was always on the same address. So instead of writing the address of the stack, he wrote the address of that command. So now when the returning, uh, return opcode is issued, the instruction pointer jumps to the jump ESP and after it, uh, executes jump ESP, now the instruction pointer points to the stack and you can pop calc, if you want. Now you might ask yourself, well, how is it even possible to run code from the stack? Shouldn't it be just read write memory? Well, that was, uh, possible a long, long time ago. Until DEP came in, came in on Windows XP Service Pack 2. And DEP, or Data Execution Prevention, actually enforces the read write memory. So, uh, the, the, the, the, the, the read write or, more precisely, the not, non-execute code, uh, uh, in memory. Because Windows, throughout time, always marked that memory as only read write, but the CPU ignored that, uh, uh, CPU ignored that. And, uh, Windows had to add another bit, which is called the annex bit, which forces the CPU to actually not execute code on that, uh, area. And DEP was actually the cornerstone for ROP. It actually made ROP what it is today. And the reason why is now that, is because now, uh, the, the, the, the, the, the, the, the, the, the, the, the, the, the the, the, the, the, the, the, the, the, the, the, uh, that it is lifetimeечь. So we need a bridge between actually, uh, exploiting uh, software, and writing our shellcode to that, uh, memory. And running it. So ROP fills the, the, the bridge between those, uh, two things. Now, another thing you might ask yourself, what do you mean that all DLLs are loaded to the same address? Well, again, that was the reality back then, until ASLR, or other spaced layout randomization, came. And, with ASLR, every time you boot your machine, Windows randomized the base address of each intelligent load, and it happened across, you can watch, you can read, you can look at the失idal code. At Een you need to find it. Now it is effective mostly on remote uh exploits because if you can run code on your on the same machine let's say you're trying to exploit a privilege escalation bug well you can just run a benign program that loads the loads those DLLs and you know the address of those DLLs. So I want to take a little sped step back to help people that want to uh write exploits today to see some sped steps that we overlooked when we saw the stack the stack overflow because stack overflow looks very simple you just write bytes and you control the machine. So let's see what those are if you want to write exploits today. First you need to have a vulnerable software you need to have access to that software so you can run your code again and again and again until you perfect your exploit to make it uh running well. Next we had a way to uh to gather information so on the more so on case we knew the address of the stack. On the Matt Miller CVE we knew the system uh function addresses. Today you will need an arbitrary read vulnerability that will uh. allow you to leak those addresses uh when you run your exploit. Next you need a way to manipulate memory. So stack overflow obviously you write the stack so you have a way to uh to write into the memory. Uh you have other ways to write into memory like heap overflow or use after free which sometimes allows you to to do that. And if you want to write exploit today this kind of vulnerability is called arbitrary write. So if you have arbitrary read and arbitrary write you probably have a way to exploit the software. And then you have a way to exploit the last step which I which I think is the most important to understand is that you don't actually write code to the target uh process you are trying to exploit. When you hijack the code execution it's actually a uh byproduct of both writing memory into that process and the normal execution. So if you think about the red opcode that chim simply jumps into the shellcode from the uh Morris worm is the normal flow of execution of the program and we abuse that normal flow of execution to run our shellcode. So now we're ready to play. We're ready to run our shellcode. So let's talk about return orient oriented programming or ROP. And the term was coined by Chovav Shacham on his article the geometry of innocent flesh of on the bone which I think is one of the most amazing titles someone can give. And the main idea behind it is to reuse existing code in memory uh by leveraging the stack semantics. So let's understand how it works. In normal flow of execution when your program runs you the instruction pointer and the instructions control the the flow of uh the flow of execution. So every time you run an instruction is issued the instruction pointer automatically advances to the next instruction. So now you have the instru- instructions running one after the other. On ROP the the register that controls the execution is the stack pointer or the stack. So you are looking for set of instructions that end with a ret. So now the instructions are running and when the ret opcode is issued the next set of instruction will be fetched from the stack because that's the return address that over there. So now you're running another set of instructions that are followed by ret which fetches the next set of instructions. So now the stack pointer is controlling the execution or the stack. And luckily for us the stack is read and write uh memory which we can control if we have the proper uh vulnerability. Okay. So one of the most important terms on on uh ROP is gadgets. And a gadget is a sequence of instructions that usually ends with a ret that allows you to perform logit- logical operations. Let's say you can copy a value into memory, you can change the memory permission uh of uh the uh the memory area into executable, or load uh values into specific registers, and many more. Let's see an example. If you want to write uh an assembly code that uh write value into memory you will probably read write this uh this code. You will load the value into EAX, load the destination into ECX, and then use the move opcode to move the data from EAX into the destination of ECX. So we are working with the stack so we can replace the first two moves with props. Let's see how it will work in a in a ROP. So you have the stack on the middle and the memory and the code on the right and the uh registers on the left. So we will start with step- first set of instruction which is pop EAX. Now you pop dead beef into EAX and the ret opcode will take us to the next- next uh set of instructions which is pop ECX. So now we pop the address we want to write to, the six one two three zero, and now the ret opcode will take you to the next uh set of instructions which is the move EAX into ECX. So now we are writing the dead beef into the next set of instructions. the others we wanted. Ok so most of the talks on ROP only mentioned 32 bits but we are in 2019 it's about time we start talking about 64 bit ROPs. So the main difference between 32 and 64 bit ROPs is that when you pass the parameters for a function you need to load the first 4 parameters on RCX, RDX, R8, and R9. Next you need to allocate 32 bits on the stack you don't need to fill it with anything and lastly uh all the other parameters are passed uh similarly to 32 bits. How it uh how does it look like? Well if you want to call a 64 bit function that receive 5 parameters again it's a pseudo code you first push the first parameter to the stack now you load the first parameter into RCX the second into RDX the third into R8 and the fourth into R9. Next you need to allocate the 32 bit uh bits bytes and the code instruction works similar to uh 32 bit. Uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh and pushes the return address on the stack. So very similar to 32 bit and the example the example which we will see today will be 64 bit. So what do we do with a ROP? Usually you would what you would want to call either virtual protect or virtual alloc. Virtual protect allows you to change the uh protection of a memory address to into executable so if you have the shellcode already in memory you just need to change it into executable into and jump to that address or you can also allocate using virtual allocate virtual alloc and uh uh uh uh uh uh executable memory and copy your uh shellcode into that address and run it. Now because those two functions are the main uh targets of ROP the endpoint protection will actually monitor those functions and we will see later how they do it. So a lot of the time when you write ROP most of the time will be wasted looking for gadgets and I want to suggest you just look at in anti-DLL and there are a few reasons to do it. First anti-DLL is loaded into every process on the system. Uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh so you don't need to uh hope that the DLL you what you exploited before will be on that uh process because anti-DLL is always there. So if you find the gadgets on anti-DLL you might be able to uh use those gadgets on every other exploit you will use and another thing that contributes to that, is because anti-DLL is so close to the kernel, then a lot of the code on anti-DLL is handled at written assembly and if you ever wrote assembly you know that you write it once and you don't touch it, it just works so now if you find a a gadget that it's hand-reader assembly most of the chances that it works from the very early version of Windows sometimes even Windows Vista and uh gadgets I will show you works from at least Windows 7 if and that's a lot that's a lot of power if you can write your ROP once and use it on every other exploit you will ever need. So let's see some gadgets on NTDLL so the first is the function RTL copy LUID and that function even doesn't look if you are copying LUID it just copies 64 bytes from the destination you give into the from the source into the destination and how it looks like in uh assembly it will it simply loads the value from the source which is in RDX it's the second parameter into RIX and copy that value into RCX which is the destination that you gave it but because we are writing uh the stack we don't need to to write a return address to the beginning of that function we can skip three bytes directly into the second opcode and now we can we have the gadget that can move up and down and we can copy the RIX into the destination RCX now there is a similar gadget that exist throughout uh all versions of Windows the move RCX into the uh the others in RIX it's in the function RTL set extended feature mask and you can use it everywhere but now you'll need uh a way to load values into RIX and RCX so how you do it well modern compilers are aware of ROP and will not emit POP RIX threat or POP RCX threat in their code but what they do emit is the like add RSP 58 hex bytes which is just the allocating the stack for 58 hex bytes but apparently the byte 58 is POP RIX so if you skip three bytes into the middle of the opcode you get POP RIX threat and that opcode exist in a lot of time in NTDLL and very similarly if you're looking for POP RCX you have the multiply XMM zero with XMM three which allows you to skip two bytes and now you have POP RCX threat so now we have a way to copy uh uh uh uh uh any value we want in memory. Next I want to show you another great gadget uh which is uh on NTDLL check stack again handwritten assembly and I will soon explain to you why because it first load the top of the stack into R10 then the next value into R11 then it simply deallocates the stack that stack and returns and it's simply like writing POP R10 POP R11 RET and how do I know that this is handwritten assembly because only if you read the Intel manual back then when Windows wrote their POP R10 POP R11 RET and it's simply like writing code you know that this was more efficient way to write it so I didn't want to show you POP R10 but if you skip just one byte you have POP R uh EDX so now you can load both RCX and EDX so you have two parameters you can pass to functions so that's thing you can start working with. Another very important gadget well obviously not POP R12 it's the POP RSP and this gadget is called the stack pointer stack pivot because sometimes when you have exploit you can only write uh uh a POP R12 or a stack pointer. So you can also call on a stacked a stack pointer Pivot Pivot Rá because sometimes when you have exploit you can only write uh a stack Pivot a limited amount of bytes into the stack when you hijack the stack. And this gadget allows you to write the whole rope into the heap or a place where you can write a lot of code and simply pivot the stack into that address. So now you just need to write the return address into the stack pivot and you can have a rope as long as you want. Now one of the most powerful gadgets on NTDLL is actually a function. It's called anti-continue which gets two parameters and I can tell you that you can completely ignore the second parameter as it doesn't do anything. And context is a, uh, contains the processor specific register data which means you can actually replace all the values in all the registers of the currently running thread. So now you can control not only R6, RDX, R8, R10, uh, R9, you can also control the stack pointer and the instruction pointer. So that's a very powerful gadget that you can use. Now the last gadget I want to show is RTL Move Memory when you want to copy a large amount of data between memory. Now I like to make analogies because it better explains things and I want to compare gadgets to the art technique called the ready made. Okay, so the ready made technique was invented by a French artist called Marcel Duchamp and if you think the French people only contributed to the world by, uh, inventing, uh, I don't know, like croissant, baguette, democracy and mimikatz, then they do, they did some other stuff as well. So this is a, this hard piece called Fountain which is just urinal turned on its side and signed with his, uh, pseudonym, uh, Armut, which Marcel Duchamp did. And what he writes about it explains exactly, I think, what gadgets are all about. Whether Mr. Matt with his own hands made this, the fountain or not has no importance. He chose it. He took an ordinary article of life and placed it so that its useful significance disappeared under the new title and point of view created a new thought for that object. And if you think about it, that's exactly what we, we are doing with gadgets. And if you follow this train of thought, well, like the fountain is an art piece, our little gadgets are little pieces of virtual arts. Sorry? Uh, so if you follow this train of thought and our gadgets are little pieces of art, it actually makes NTDLL the public bathroom of Windows. Okay, so with that thought in mind, let's move on to Windows exploit mitigations. We'll stack with, we'll start with stackHancriz, and stackHancriz protect you against buffer overflow. It works by first generating a random base Canary value whenever a process is started and then writes a cookie into the stack using a calculation on that base value. Now, when the return opcode is issued before the return addcode is actually executed, it performs the reverse, uh, calculation and checks that the value we got is the base Canary value. So, we're going to use this function when the return So, now we can actually see if someone actually override, overridden the, the stack. Uh, and let's see a pseudocode, how it works. Uh, so it first loads the base canary value into ECX, then it stores the value with the stack pointer, so now it's not only, uh, as an attacker, you don't only need to guess the, the base canary value, you should also guess the current stack pointer, which is very hard, and then you push the value into the stack. Now before the return opcode, uh, let's say an attacker actually managed to override the stack, the, uh, opcode will pop the, the canary stack from, the canary value from the stack, will sort it again, and will, uh, call a function that verifies, uh, if the value was changed, and because it did, it will actually crash the process. Next, uh, mitigation I want to talk about is the Windows 8 ROP mitigation, which is a very big name, but it actually just detects, uh, stack pivots. So whenever you are calling, uh, memory functions on Windows, starting from Windows 8, it will actually check that the stack pointer points to a valid location on the stack. So if you used, uh, uh, stack pivot on your ROP, well, Windows will detect it and will crash the software. And now, it's very easy to guess how you can bypass it. You simply need to make sure that the stack pointer points to a valid location on the stack when you are calling, uh, Windows, uh, 32 API. So how can you, uh, fetch the stack pointer value? Well, you can do this by well, you can abuse canary, stack canaries. So for the first, I think, technique I will show you, I call it a little Bert told me, and we will see how we can abuse using a ROP, uh, stack canary to fetch the value of, uh, RSP. And, uh, main steps we will take is we will first prepare the registers, then we will call a benign function that uses stack canary. We will fetch that val- that cookie from the stack. You can treat it like a use or read after a free, uh, vulnerability. And then we will solve that value with a base canary value, right? So, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, and if you remember before, I told you that you need to have a memory read vulnerability. And if you have that memory read vulnerability, you can actually fetch that base value from the DLL you are calling. So we will assume that we have that value on the ROP already. So you have the code on the left, on the top right you have the registers, and on the bottom right you have the stack. So the stack is also split between the address on the left and the values on the right. So we will start with a pop gadget, which is a, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, which will pop the values that we want, we want to prepare the registers. The important registers we are preparing now are RCX and, and R9. RCX is a parameter for the function we are calling, and R9 you will see later what it is used for. And now the RET will take us to the next, uh, function, which is RTL is valid process trust label SID. What it does, I don't even care. The only thing I care about is that it uses stack canaries and it doesn't mess up with the, uh, uh, registers or the stack, or the stack itself. So, first this function allocates place on the stack. Next it fetches the base canary value into REX. You can see it over there. Now it will sort the value with the stack pointer. So this is the, uh, the stack canary cookie we are using. And later it saves that value into the stack. So you can see the same value on REX. We can find it now on the stack. Now because we passed the parameter to the function, we passed a bad parameter and the function will, uh, start to go into the ex- into the exit, uh, sequence. So now right before calling the RETOP code, we are going to call the RETOP code. It fetches the value, the stack, uh, cookie from the stack into RCX. Now it will solve it with the, the stack pointer. So now we have the base canary value and it called the functions that check the cookie. And because we are innocent, we didn't do anything wrong here, we're just calling a function. Well, that function will pass correctly. And now, before I execute this, I need to remind you the, the canary cookie is still on the stack. So we are de-allocating the stack, but actually the stack memory is like a memory in other, any other place on the computer. So if anyone, if no one re-written or overwritten that value, that value is still there. So now we will jump to a special, uh, gadget that will allow us to fetch that value. And that gadget is in RTLP execute handler for exception. Again, all the gadgets you are seeing here are from NTDLL and this is handwritten assembly. And you can guess it's used for exception handling, but this gadget actually allocates space on the stack. And now it calls, uh, you can see that, uh, now we have the cookie on the stack, on our, uh, on our stack, uh, value. And now it will call a pointer that is controlled by R9. So if you remember the first gadget we used, we popped R9 to control the value. So can you guess where we are going with this, uh, now? What gadget we will use? Well, we're going to the same, uh, pop gadget that we used before. So now we are popping values from the stack. And you can see that, uh, we are using R9. And the important thing is that now R9 will receive the canary, uh, cookie. So now we have the cookie on R9. All we need to do is to fetch the base canary value and XOR it. So now the retop code, you can see it will take us to the, to the next, uh, gadget, the pop RAX, you know that one. This will fetch the base canary value into RAX. And the retop code will take us to the last, uh, gadget, which is XOR R9 with RAX. And this is part of RTL decode system pointer, NTDLL. And now we have the stack pointer and we can pivot from here and continue our, uh, rope. Okay. So now for the next mitigation, we will talk about, uh, control, control flow guard, or CFG. And the idea behind it is to mitigate, uh, control flow hijacking of indirect calls. What are indirect calls? Let's say you are writing CPP code and, uh, compiler needs to fetch the address of the function from the virtual tie, table. Uh, as you can see, this is the So it will write, will emit code which look like this. It fetches the address uh of the pa- of the function into RAX then loads the parameter RCX, RDX and R9, R8 for like three parameters for this function and will call RAX. So CFG actually replaces uh RAX uh wait I'll take a step back. If you are an attacker you can actually hijack the value that will be saved into RAX and then you can call any function you want or any place in memory you want. So control flow guard actually replaces the control RAX with a call to guard dispatch uh I call FPTR. Uh sometimes it's just a check and there is another call to RAX uh RAX later. It depends on implementation. But actually this function will check that RAX is valid function and no one overwritten it. How it does it? It uses a huge uh bit field where every bit marks uh if a function starts at a specific address in memory. So it's uh coarse grained. Uh it's uh it doesn't know if those are the functions you actually wanted to call but uh if there is a function starting there and it doesn't matter what what DLL it is it will say that it's valid. What it gives us is that uh you won't be able to call in the middle of function and then uh mess with the stack uh the stack itself. So now comes the questions. How can we abuse CFG? Well we already did. Do you remember uh I told you that the uh CFG replaces the call with a call guard uh uh dispatch I call FPTR? Well actually that function translates into anti-DLL functions called LTE LTE L LDRP validate user call target. And that function checks the bit field you can see it and uh down below you can see that if it finds that there is no function over there it jumps into LDRP vali uh handle invalid user call target. And if this name sounds familiar because that's the pop gadget we just used. So thank you Microsoft for introducing one of the best gadgets for ops. Uh uh. Out there and making it available in every ad every goddamn process on the system. Uh now I need to ask sorry for all the people exploiting this because if Microsoft is watching this they probably take it away from us. But wait there is more. If you will look at them at the MSDN we'll see there is a uh a function called set process valid call targets and this function actually allows you to tell CFG what addresses are valid. So let's say if you can potentially exploit a CF uh uh indirect call twice you can first call set process valid call target set the target you want as a valid target then call it again. So what do you think? Do you think Microsoft actually protect a valid uh uh function that is published on MSDN? Well apparently they do. So nice one Microsoft but not that nice because if you look at set process valid call targets it's actually a wrapper around an anti-DLL function called anti-set information virtual memory. It's a set information virtual memory and you know what? Anti-set virtual uh set information virtual memory is actually valid call indirect call target. So you can call this function tell Windows that it's a valid target and then abuse the same uh exploit again to run whatever uh function you want or whatever others you want. It's actually like telling Windows those are not the exploits you're looking for and you know the force is powerful and the weak minded. Okay so let's talk about ROP mitigations. And we will talk about first about ROP guard which is the mitigation that is implemented by most endpoint security today or at least a variation of it. And it uses strategic hooks on a memory function like I told you before on the virtual protect virtual alloc uh all the matching anti-DLL functions and all functions that allow you to create processes. And what it does it fetches the return address from the stack and look at the opcode preceding it to see if there is a call uh to that uh function and if there is no call then it will not be able to call the function. So the call opcode before the return address then how did this return address go to the stack. Now it doesn't only check that there is a call it also checks that the call opcode actually uh calls the function that we are hooking. So that's the ROP guard in general it does have uh some more tricks uh to do but most of them simply checks that there is a call opcode. Now K-Bouncer is like uh ROP guard uh on steroids if you would like. It's actually utilizes uh a feature on the CPU called DAST branch records which saves the last indirect uh jumps or calls you had. So you have uh the source and the target address and you can actually perform similar checks to ROP guard on those addresses too. So if you can think about it ROP guard actually checks that the return address which is the future of execution. K-Bouncer also checks the past of the execution that was that already happened. Now I know that there are a few very few uh vendors that uh implemented K-Bouncer but most of them only implemented ROP guard. So you can actually check the ROP guard. Now another mitigation is uh ROP pecker which I haven't seen implemented anywhere. And uh the idea behind it is to use the same mechanism as uh DEP the data execution prevent-prevention to mark all the memory as non-executable except except for the current uh executing page and the next one. So now whenever the execution jumps outside of that uh area there will be exception phone and ROP pecker will catch this exception and will perform similar checks to uh, K-Bouncer. But uh, because it happens a lot, the heuristic that it uses are a lot weaker than uh, K-Bouncer. Now the last mitigation I want to mention is ShadowStack, which is uh, a collaboration between Microsoft and Intel. It was first proposed on 2016, but it was never implemented. Uh, they suggest to use two different stack. One, the regular stack that you have and will know about, and another matching kernel stack that only saves the return address. So whenever there is a call up code, the return address is pushed both to the user mode stack and the kernel stack, and when there is a ret, it will pop both addresses. And if the addresses are uh, incorrect, well, then you know that uh, someone overwritten the stack. Uh, the, but as I said before, uh, it was proposed in 2016, there is no implementation of it, and we all the time know of. And let's see how we can bypass it. So before I will tell you my method, I want to suggest you a paper to read or a black hat talk to, to watch, which is called The Beast is in Your Memory by Daniel Lehman and Achmed Rizaz-Degi. And they explain how you can bypass uh, Roppecker K-Bouncer uh, by abusing their heuristic. And if you think about it, when they say they're abusing their heuristic, they are actually uh, have an intention of being caught. And I don't like being caught. So this is why I invented uh, a new technique called Right of Passage, which allows you to bypass uh, the Rope Mitigation. Uh, the Rope Mitigation, which allows you to bypass the Rope Mitigation without even being caught or without going for any of the endpoint securities uh, hooks. So we collected a lot of bricks so far, and there is still one more brick we need to collect to understand how we can completely break Windows. And this one is the System Call. So, System Call is the way uh, you transition from user mode to kernel mode, and whenever you call uh, Virtual Protect or Virtual Alloc or any other Win32 uh, function, it usually translate into a System Call function. Uh, the system called Function is a function that is a function inside NTDLL. Again, handwritten assembly. So all of those functions will look very similar to uh, anti-allocate virtual memory. It first moves the first parameter from RCX and saves it into R10. Next, it loads the System Call parameter into EAX, and on the case of anti-allocate virtual memory, I think it's Windows 10, the value will be 18 hex. Uh, let's say for anti-virtual uh, anti-protect virtual memory, that will be 50 hex. So, uh, it will be, uh, the function called CCOL. So, every function has a different uh, number. Next, it issues the SYSCOLle uh, command and the SYSCOLle uh, actually, is actually the opcode to transition into kernel mode, but it always goes to the same function in kernel. So, how does this function know which function you want to run? Well, it looks at EAX. So now it knows that, because EAX is loaded with 18, it hacks. You want to run anti-allocate virtual memory. Now, when the function finishes in the kernel, it will return to uh, user mode, and the function will continue. function. So as I said before, all the endpoint protection usually hook those function. So now you have a hook on the function and if your rope goes for that uh function it will go through the endpoint hook. Some vendors even go as far as override the whole function so you will not even know that it's there. They don't know why they should do it. But you know what? They don't hook all functions. Let's say anti-yield execution which is actually a function uh that does nothing. It's like the insecure function of a program if you want. It just tells Windows well I don't know if I have anything important to do right now. Maybe you decide if I need to continue execution or someone else do the execution. It's a function that is no, has no interest to anyone. Maybe for us. But uh another thing that you can see how do I know that this is handwritten assembly or a macro that just copies the same values everywhere? It's because anti-yield execution doesn't get any power. It's a function that does nothing. It's a function that is a parameter. So why do you need to pass R6 into R10 if R6 holds no valuable data? Well that's handwritten assembly. But we can actually abuse anti-yield execution or any other function on int DLL which is not hooked for our cause. And how do we do it? Well we will start with a pop RAX uh RET gadget that loads the system call into RAX. Next we'll use another gadget that you've seen before that allows us to load R10. So we're going to load R10 into our R10. So now we can also prepare the first uh parameter. And next we will not call anti-yield execution we will jump 18 bytes directly into the system call. And now if you look at it we actually have a way to issue any system call we want using a ROP and because we don't pass through any of the endpoint protection hooks no one even know that our ROP was there and no one will ever catch us. So I wrote a little tool which I will publish on my git later. Uh it's called ROP injector injector which uh first allocates a read write memory into the target process. Uh it writes the shellcode into that process. Then it will create a new thread on that process and injects the ROP into that process using uh uh get process uh uh get process context and set thread get thread context and set thread context. And lastly the ROP will modify that ex that uh area into read write execute using either either a regular call to virtual or a write of passage call to anti-protect virtual memory. And lastly it will run the shellcode. So let's see how it works. Uh let's see how it works. Uh let's see how it works. Okay so. So I want to change things a bit. So I will not pop a calculator with my demo. I will actually inject a ROP into calc with in my demo. So you need to pass the process ID to the ROP injector. So now we will pass the process ID of the calculator. And we are injecting a regular ROP and you can see that our uh shellcode injected the the created a mutex called pawn so obviously it worked. Now I will tell you a little secret endpoint protection don't protect all process on your system. They usually protect only the vulnerable like Firefox. So now when you try to inject you can see that the endpoint protection caught the ROP. So now we will try to run Firefox again and we will use the write of passage ROP uh instead of the regular ROP. Uh let's see how it works. Okay. And then when the endpoint protection didn't even see it coming. Oh see it uh that it even happened. Okay. So let's see how it works. Uh let's see how it works. Let's see how it looks with the default. Here is what it looks like. Let me Okay so welcome to the mini talk exploiting a Windows exploit for mitigating right of passage exploit. So at the beginning I thought maybe I will show you like the blue pill and how to write uh hypervisor to protect against uh right of passage but last month there was a research by Nick Peterson he called it infinity hook which exploits uh the Windows event tracing mechanism to hook system calls on the kernel. So what Nick find out is that the there is a struct in the kernel that uh every uh event log saves which has a function pointer that needs to save the timing of the the event that occurred. And he found out that you can actually replace that function pointer with your function pointer uh to your function and now you have a way to get notification every time a system call was issued. So now we can hijack system calls. So obviously Microsoft responded that this is not a security boundary so I thought. Why not make it a security boundary? Yeah. So now every time there is a system call we can actually check what is the return address and check that the system call matches the same function that this uh function came from. And if it doesn't match then well we actually caught the right of passage uh bypass and it actually catches a lot of more kind of uh uh exploitations not only that. So you can find uh Nick's work on Github. And uh uh uh and okay so takeaways. First have fun. I mean even though Microsoft tries to make our life uh harder we can still enjoy it and do fun stuff with it. And we need to remember that ROP remains a viable threat even 30 years after its first uh its first incarnation. And as a security industry we need to respond faster to those uh threats. And I want to suggest we can utilize the brains on academy uh to do that. A lot of the research on ROP came from the academy. And also the research about how to bypass the ROP mitigations. And there are a lot of great minds there that we can use. So let's do that. And lastly break it to make it better. Okay. Thank you very much. So I think we have about 10 minutes for a Q&A. 5 minutes. Okay I can see 1. Yes. How much of the mitigations are transferable to. Okay so the question was how much of the mitigation are transferable to the Linux world. So first I will say I'm not a Linux guy I'm a Windows guy. Uh but I think uh ROP guard uh is transferable. KBouncer is also transferable. RobPecker I don't know how Linux manages the memory of the processes but I think it's also will be transferable and I think also shadow stack can be uh transferable too so maybe all of them it might need a little tweaks from the Linux side. Okay any more questions? Okay so thank you very much. Thank you very much.