Welcome Vegas! Woohoo! Let's go guys! Ladies and gentlemen, LVO. Thank you guys to be here. It is amazing experience to be here for my first time. And let's talk about EDR, XDR, bypassing. First of all, our agenda. Uh, a little bit who I am. Uh, a little bit what is hookchain and what is not hookchain is. And these research limitations. And after that, let's talk about the basics to understand how does hookchain works. And after, look through rootchains. And who I am. My name is Elvio Junior Aka Mabarik. Uh, my undergraduation school, uh, I did a airplane pilot. So yes, I am a pilot. And I was the first in America Latina to learn OSCE3. Uh, and I studied, or maybe studied too, OSCE. This research, uh, that I have here. Uh, I studied OSCE3. Uh, I have no much time to study OSCE. And what I like, I like low level exploitation, buffer overflow, shell coding, malware, and so on. And also, I am CEO of SecForUs, a company, a Brazilian company that, uh, provide training and research and consulting and so on. What is the motivation of this talk and this research? Many people believes that I, I have solution X, that I talk of the Gartner, and I am a hundred percent protected. No, there is no silver bullet. And when I doing, uh, pentesting or red team exercise, I just need to bypass the red team exercise. Your environment. I don't need to bypass everything, just your environment. So, and full undetectable. Sometimes it happens. And what is hookchain? Hookchain is a technique. It is not a tool. I'm not pretending to launch a tool. Yeah, obviously, I need to do some programming. I need to, to create a code to prove the concept, but it is a technique. Okay? And what is the focus of hookchain? Do hook, do bypassing of monitoring of EDRs and XDRs inside of NET DLL. In other words, a hundred percent user land. Nothing about kernel land. Okay? So, what is hookchain? And limitation. As I said, it is, uh, 64 bits programming and limited just to NT DLL. User land hooks. And I'm not pretending here to classify the EDR vendors, XDR vendors as his effectivity. I'm just launching a new technique. Okay? I need to do some tests, but I'm focused just in one point, not entire ecosystem. So, I'm not pretending to classify EDRs. It must be clear for, for all guys. During this study, I, I did, uh, public call for vendors to work together with me to get early access to this code, to this technique, and no one answered. When I published it, some bypass in LinkedIn, I received some calls, not too happy calls sometimes, but I received just three years, three weeks ago, some calls in order to test this. Okay? And let's go to the technical things. First of all, we have almost two layers in order to protect and split the time during inside of our operational test. Ring zero, kernel land, and ring three, user land. To transition between user land to kernel land, in a few words, we have just one way to do this. Using a gate calling system call, or system dispatcher and so on, that I can transit from user mode to the kernel mode. In general, we have this picture where we have user process, system services, and so on. Doesn't matter what is the, his level is, it is a system level, a certain level, or a simple non-privileged user process. Every time I need to do this transition. In general, this, this is a responsibility to NTDLL to do this for me. So, this is a common stack call where I have one common application for, that must be, that need to be, for example, need to execute first a virtual lock to locate a, a memory. And the common stack call, the application will call this from kernel 32 DLL and the kernel 32 will call another uh, API inside of NTDLL and the NTDLL will prepare stack call parameters, register parameters, and will execute uh, assembly instruction called sys call that will transit from user mode to the kernel mode. This is just another image to explain that. So, I have the user mode application and the important here, system service number. There's a table called system service descriptor table where I have uh, indexes from zero to, I have no idea how much, more than 400, uh, numbers that match each ID from a pointer to a kernel function. So, when I need to uh, to transit from the user mode to kernel mode, I put the system service number inside of register RAL. Sorry about the noise. But uh, I put this number in this register and I execute the system call instruction. And system call will come to the kernel uh, address space and this function will match inside of this table and get the pointer to the real kernel function. And the real kernel function will be executed and return to the user mode space with the return of the executed function. Doesn't matter uh, what this means. This is another uh, uh, image to illustrate that. System service call, system service dispatcher, the table with the indexes and uh, the pointers to the function and the real code from, through the function. Okay? And when I execute some proxies uh, un-executed or uh, when I load uh, DLL inside of another proxies, when I initiate uh, a proxies, several actions are, have been done behind the scenes. One of the most important that uh, uh, to this talk is related to import address table. Import address table in a few words is a table that have uh, the name of the function that I want to execute. For example, uh, create proxies and the name of the function and the uh, ID representing, ID representing inside of this table and the function that when I run this, when I run the, the application, the operational system, the, the loading of the operational system will look through uh, all loaded DLLs and fill this table with the address, the real address of this function in the operational system. Virtual address, of course, but the virtual address. So when I try to execute these proxies, my application will comes uh, to the import address table and request, import address table, what is the real virtual address to this function? And put this, for example, in a history and after that call the address of this hazards, history in order to call the uh, real uh, function code. And another things that image loader do is uh, look through the, the loaded DLLs if this DLLs uh, uh, was already loaded, the recursive loading and so on and fill this, this function pointer. There is another image to, to illustrate this, this same thing that I have the name of DLLs and the functions that I imported in my application by default and the, the, the name and the code of the application inside the, the uh, the target DLL. Let's start talking about the techniques. Uh, when I, when I saw this, this kind of hooking, uh, we need to say, we must say that the techniques that we use to attack, it's the same techniques that the EDR vendors are using to protect. The first time that uh, someone published uh, uh, something related with this techniques in, in Windows 95. So uh, a few, few years ago. Uh, and what is hook? Like a interception of the stack call. When I try to execute some function, this function uh, I, I'm not executing the real function. I, I will be uh, intercepted and redirected to another function. Like a man in the middle. In this case it will be a function in the middle. But it's the same concept. Okay? The, the most common techniques to do that is using instruction jump or call. Or I can use uh, uh, uh, import address table hooking. How can I do that? Let's see. Uh, talking about jumping. This is a strategy that I, I'm uh, that we can see here. It's the most common strategy uh, used by EDR and XDR vendors. That is when I run a, an application uh, NTDLL is the first DLL uh, that is, is attached to my process. And after that the EDR DLL will be uh, attached and the DLL from EDR will patch or change in memory uh, the instructions of the NTDLL. So, when I try to execute for example this function, this function is uh, uh, changes to jump to address space of EDR uh, code. In order the, the, the EDR can uh, check our parameters and response and so on. This is uh, an example of original execution flow where when I get the address of the, the, the, the function, the target function, we will receive the real address. But if after the EDR changes or after our change in the target function, that, because we will change this table, uh, after that, instead of receive the address of the real function, the original function, we will receive an address to a hooked function or to a uh, function in the middle in this case. Okay? So we will receive a malicious function or uh, when I EDR doing that, the fu- the, the address of the EDR function. So, when I, when I call this address, we will call the, receive the function. In this case, uh, arbitrary code from EDR or from our perspective, and it is a decision if we will or not execute the real function. In uh, talking about EDR infrastructure, the EDR will uh, analyze the parameters and decide, yes, uh, LV is a good guy, I can allow this. Oh no, LV is a bad guy, let's drop this. And uh, uh, pop, pop up alert and uh, send this to, to SOC and so on. Uh, this is a, that I am talking, this is a, uh, when I EDR load, EDR puts an, another DLL and it will be redirected and decide, yes, no, execute or no, and do if, yeah, LV is a good guy, let's uh, permit this execution, so do system call in kernel land. It's everything as usual and after that, come back to the user land process. Okay, I can see here an unhooked API, okay, so I can see this typically uh, instructions where uh, there is a, a, a moving from R-C-X to R10 and after that there is a, an ID here in hexadecimal uh, where I put this ID in uh, E-A-X or R-A-X, doesn't matter. And after that there is a system call. This is a typical uh, uh, code from NTDLL's uh, uh, functions that will transmit from user land to kernel land. And here we can see a hooked API where he is unhooked and he is a hooked API. As you can see, there is no this typical code. There is a jump code where I'm doing a, a jumping or a interception to the API or to the EDR uh, code. Okay, said that the most common bypasses is remapping NTDLL but to do that we need to load the NTDLL from the disk or from the another uh, memory area. It seems to be malicious in most of case. Uh, another technique, it's direct syscall. When instead of goes through NTDLL, I get the system service number and do uh, and execute the system call inside of my, my process. This sounds malicious again because the system call was not coming back from NTDLL memory address space. It's coming from my application address space. Okay, and EDR catch this. I direct syscall, it's uh, similar to direct syscall but instead of uh, do uh, system call instruction inside of my application, I will jump it to address inside of NTDLL that exists just system call instruction. So, who will execute NTDLL? So, sounds less malicious. But in this case, the stack trace will be broken because I'm executing directly from my code inside of NTDLL. In general, the application doesn't do that. The application in general calls system 32 DLL, kernel base DLLs, GDI DLL and so on. And DLL will call NTDLL and, and et cetera. So, sounds malicious. Then, there are amazing guys uh, without this research, this talk today was not possible. So, this is amazing guys uh, created uh, uh, Heaven Gate technique, Hell's Gate technique and the Hell's Gate technique. So, uh, for this research, I used the part of Hell's Gate technique in order to uh, resolve dynamically uh, the system service numbers. Okay? So, let's understand a little bit better about Hell's Gate, this part of Hell's Gate. In general, in Hell's Gate, locate the current address of the uh, target function that, the function that I want to execute. For example, uh, create a virtual memory or um, create processor and look that uh, that code that we, we saw, the, the typically code and check if the typically code uh, match with these uh, uh, these instructions. If yes, okay, this function was not hooked. If no, the function is hooked. Okay? So, we can uh, see that and how can I uh, get the system service number? If, if the function is hooked, the real code uh, does not exist more there. How, how can I see this? Let's, let, let's see uh, uh, another screen here. We can see that the functions are linear. So, we can see here, for example, the system service number six, system service number seven, this function is hooked. So, in general, I have no idea what's the, the, the system service ID of this function. And the next function will be nine and we, the next function will be ten. In other words, we can see the neighborhood uh, functions before and after our uh, uh, uh, desired function in order to calculate. If this function is six, that function is seven. My function will be eight. So, we can dynamically check this. This is hollows gate technique, ok? And uh, before this, this research, this study, uh, in a sunny day, uh, playing with my two uh, boys, my two kids, I have an idea. Whoa! The major part of EDRs are hooking in an NTDLL. If the function is high, step above and try to catch or try to do a, a, a function in the middle, uh, changing the flow before NTDLL. Ok, because, because some uh, uh, several EDRs are checking if we are changing NTDLL. So, because they are changing there, the EDR are checking if we also change there and flag us as malicious. So, if EDR are checking there, and what if I did or I do this in a step above? So, to check the uh, viability of this technique, I, I create a code in order to check the EDRs hookings. So, nine percent of the EDRs are hooking just in NTDLL. So, the technique can be viable. Ok, and I created the new technique called hook chain. What is hook chain? Hook chain, the first step I will uh, resolve system service number. After that, create a table where I store the system service number and uh, another address of my custom stub function. In other words, the function that will be executed instead of original function. EDR do this, whoa, I can do this also. And implant or change the import address table from our proxies to our custom stub function. And after that, continue as usual. With this, I have in more details the hook chain implant flow. First one, uh, I resolve dynamically, map some critical functions because in this, in this phase, uh, I have no, uh, I had no bypass at EDR yet. So, I need to use some functions, not uh, monitor it by EDR in order to change some memory address and change some uh, memory areas and so on. Read and etc. Uh, so I map statically these main functions that I call it here critical functions. And after that, I create a table. We will see the structure of this table, uh, later on. Uh, we create a table that holds system service number that I already mapped. The function address, the real function address inside of NTDLL and uh, the, the closest uh, address that holds a system call instruction inside of NTDLL. And after that, I loaded, I preloaded some functions. For example, uh, if we will run uh, MetaExploit payload or Havoc payload, uh, payload and uh, I have no idea. Uh, there are another uh, DLLs that must be called before the execution of this payload. Because a simple uh, a simple executable for example, has no access to the uh, URL uh, APIs or uh, critical functions. So, we must preload this DLL in order to change the import address table of this DLL. So, here we preloaded these DLLs and after that do the magics. Change the import address table of all needed DLLs. In this time I, I, I need to say that that is not a good idea to change the import address table of all loaded DLLs. I tried that and I lose my hair trying that and that's not a good idea. Believe me, believe me. So, I, I, I created like a, a blacklist DLLs where I put inside of the application and uh, do this preloading and after that changing that. This is the typical flow after hookchain planting. The simplified version. So, my application must call virtual unlock for example to create uh, uh, malicious error in order to put there a meta exploit shellcode for example. And I need to create this. I will call kernel to 32 DLL. Instead of call direct NT DLL, this function as I hook it, as I did the uh, the, the function in the middle, I will, this, this flow will be redirected to my application stub code. This application stub code will, will check several things and create a stack frame, a stack call, create uh, uh, put the, the, the, the, uh, the information inside the registers and after that do an indirect syscall in order to execute. And kernel mode as usual. Here, this uh, I can present you the, the first struct that I, that I, uh, I will use. I will use here uh, a list, okay, with this system call information and each entry of this list uh, has a system service number, real address from the real function, okay, uh, the, the address of the function or the address that holds the system call instruction and the address of my stub function that will be redirected to. And uh, a hash use it to bypass uh, static analysis instead of the name of the functions and the, and so on, okay. And this is the entire flow where the same, my application want to execute some function will call kernel 32 DLL and that call kernel base DLL and after that I will check in a import address table. When I check in import address table instead of receive the original address I will receive my stub function. So, the application will be, will redirect to my stub function inside of this function. Uh, I can check the system call list, the list that I saw, and the list there are several items in order to check, get the parameters that were the real function, syscall uh, uh, address and so on. Create the stack call frame and put everything that we, we need in the registers and after that do indirect syscall. Okay? What are the advantages of that? How this works? Why? Uh, reduction of probability to identification for several reasons. The first one, total time of execution. As I have several times similar to the regular execution, the DDR cannot flag us because the total time of execution, the telemetry of total time of execution will be okay. Will be uh, seems to be uh, valid. And stack, stack framing. Talking about stack frame, I'm flowing, I'm uh, uh, uh, executing as usual. Came in for a kernel 32 for example, kernel base and so on. So, I, I'm not stepping steps. Yeah, I'm not skipping steps. Okay? And the most important, I did not or I uh, uh, I, I didn't need to change the code of the original application. For example, if I want to execute Mimikatz for example, I uh, uh, I don't need to touch the code. I just execute the hookchain in order to implant and execute Mimikatz. That's it. Because the hookchain implanted uh, uh, uh, everything that we need. The function in the middle. Let's see the first demo where we will execute and uh, command and control using Havoc. Okay, this is uh, flag as malicious as usual. And let's see this first one. Here we can see uh, Bit Defender updated with uh, advanced threat protection. Full enable and in the left side we can see our uh, console where uh, we will have, let me see, uh, let's stop here. Just uh, let me put here together in order to, okay. Okay, no problem. Uh, first time I will implant hookchain. After that, download remotely from HTTP the malicious payload and after that execute this malicious payload. So, we are using Havoc to do that. And uh, let's see and here we go. Executed our first, first command control. We can interact with that without any identification. Thank you guys. You are amazing. It's just a starting one. Let's go. Let's go back to the presentation. Whoa. Here it is. Looking in the browser, we can see details. We have the first step is mapping everything that we need. So, in this operational system we have four, four hundred seventy two NTDLL functions where we can map and these functions are hooked or I need this as a critical function. And after that, I create this table, okay. This is the, the, the showing of this table. And after that, I do the import address table hooking. So, I can see here the output of this, this hookings in kernel two thirty two, kernel base user thirty two and so on. Let's talk about the real environment. The first of all, thank you for all friends, all Brazilian community that there are most, most guys here. Uh, that share with me, uh, your environment license and help me and support me in order to make this research works. Uh, without you guys, nothing will be possible. Uh, thank you. Thank, thank you so much. Uh, because obviously some EDR vendors are not too happy and not sharing their license or their environment in order that I test. So, uh, there are a lot of friends, uh, sharing his environment with me in order to, to make this test, okay. So, we did this in a closed environment. As the focus, the focus of this research is talk about, uh, EDR protections, uh, and we will touch here else, else us. Uh, I disabled the run as prepare and coordination guard inside of the windows because the, the, the, the target the full focus, it is not the windows, it is not the EDR and the XDR products. So, let's execute the second DEM for you guys. The same as again, we have the antivirals, EDR working with advanced threat protection and we will execute, uh, as usual, Mimikatz. I downloaded from GitHub, put on my server, as you can see, and execute this guy in a protected environment. And let's see this working. Woo! So, uh, this is a, this is a, this is a demo. It's not all. Execute and show a coffee, it, it's a easy part. Let's dump the creds. Without creds, we have nothing. So, yeah, we can touch the else us without any identification with regular Mimikatz guys. Woo! Coming to the end, uh, we are able to test with 66, uh, percent of the products, uh, present in Gartner and in additional four other products. And this is the result table. Okay? We tested remote process injection, Meterpreter, and Havoc as non-privileged user, and Meterpreter loading QE model, Mimikatz, ProcDump, and a custom, a hundred percent developed by me, a hundred percent assembled by me, uh, assembly, else us dump. Okay? I created this in order to do this test. And this is the result table, okay? This is the products that I, I was able to test. And as you can see, uh, we, we have, uh, a lot of effectivity in order to, to doing this little things. Uh, as I told you guys, uh, three weeks ago, two vendors, uh, reached me in order to, to test, uh, again. The Sentinel one was the first and the second one was the trench. This results that I'm showing you, uh, the Sentinel one was able to, uh, stop hookchain. They did some patches in his product and, uh, uh, I was able to, to test this and stop it at all. Okay? Deadline, end line. Uh, and the trench, uh, is still working on this, this, uh, uh, identification. And they tried some behaviors but, but not at all. Okay? The other vendors, non-contact. Okay? I love it this, uh, this phrase of Sif Hawking. I'm just, uh, a child asking who, how and why. Occasionally I found the answer. Thank you guys. This is my contact, full white paper, source code, reference and feel free to contact me, feel free to reach me by, uh, LinkedIn. My LinkedIn, it's my name, just Elvio Junior and that's it. Now it's your time, time to ask questions. Thank you.