Okay, thank you all for coming to my presentation. For those who I haven't met before, my name is Andrew Case. I am a core developer on the Volatility Memory Analysis Project and also the Director of Research at Vellect City. At Vellect City, we do a significant amount of incident response and malware analysis. And as part of our research workflow and being on the research team there, we make sure that for all the malware techniques that we see during our attacks and that we see other vendors reporting about, any type of malware technique, any attacker toolkit that's really being used in the wild, we want to make sure that we have a complete understanding of it and also that we can automatically detect it during our investigations. To ensure that we meet that goal and meet that reality, we very often perform very targeted, very specific deep dives on specific techniques that we see the malware using, that we see attackers using. And then we make sure that we document all the different techniques, all the different tools that use it, whether they're private tools from threat groups, whether it's some open source tool that has implemented it. And then we make infected machines with it. So we make our infected virtual machines. We make sure all the techniques are active. We do the deepest memory forensics research we know how to do, which we have most of the volatility developers at Vellect City, so that's pretty deep. And then we do talks like this where we publish it. For one of the latest research projects that we did, that's what I'm going to be talking to you about today, we looked at all the ways that EDRs were being evaded by real malware. Because what we noticed in our investigations is that we're working in enterprises, they're trying to do security correctly, they have EDRs, they have them configured, they're listed as active on these machines, but over and over again, as we were doing memory forensics, we were finding very potent malware in the same processes where the EDRs supposedly were. So obviously we wanted to figure out why that disconnect was happening, and through our memory forensics work, we wanted to be able to detect it automatically as well. Because as you'll see as we go through the slides, normally when malware bypasses EDRs, it's not every process. It's just the process or the two processes where the malware is running out of directly or where it's injected code into, so if you detect the EDR evasion, then you also directly detect the malware. And so this has allowed us to do very scalable work. And at Vilexity, where we're dealing in many investigations with dozens, hundreds, thousands of memory samples, we don't have time, and it would obviously not be very time efficient, to manually look at anything to start. So we want a set of techniques that will at least say, hey, out of these hundred memory samples, these are the five you really need to focus on. And that's where we target our research. We don't want a lot of false positives. We don't want algorithms that take forever to run. We just want to find the malware so that we can deep dive it. And then, as you can probably guess by the title and the fact that all this research was done with volatility, we're going to be looking for that malware in memory. If you haven't seen memory forensics before, or maybe you've never looked at a memory sample yourself, the reason why there's this whole industry now around memory forensics and why it's so vital to incorporate it in your investigations is that when you look at the real attacks in the wild, when you look at the malware that's going to be used in environments where the attackers don't want to get caught, where the EDRs are, where there's actually security teams, that malware is going to be memory only. It's not going to touch the file system. Anything that traverses the network is going to be encrypted. So if you don't get a memory sample, then you just threw all the evidence away. If you walk up to that compromised machine and you turn it off, as soon as that machine shuts down, the evidence is gone forever. And what I have highlighted here on the slide is just an interesting report from Microsoft. There's hundreds of reports like this that companies have published. But I like this one because in two sentences it really summarizes why we spend so much time doing memory. This was Microsoft. It was really interesting. It was basically a spyware company out of Australia that was being used to target some high-level people. And Microsoft burned the whole company to the ground in one report. They burned every piece of malware that company had, all the capabilities. And as I have highlighted in red here with the screenshot, over and over again, Microsoft made the point to say that where the evasion is, where the real payloads are, are in memory. And if you look at what these payloads are capable of, it's key logging, it's screenshots, it's recording the microphone, it's recording the webcam, exfiltrating files, everything that allowed this spyware to operate against politicians, journalists, all these people, it was memory only. So traditional disk forensics isn't going to get you anywhere. And you need to know how to efficiently do memory forensics to even make sense of the data and detect the malware in the first place. So as part of our research project, when we first broke down how EDRs are monitoring system activity, the first three have been around a while. Kernel callbacks is where EDRs or antivirus inside the kernel, so from their driver, they can register to say that that callback will be notified every time a process starts or a thread starts or a DLL gets loaded. EDRs will also monitor activity through two of the newer interfaces, so ETW and AMSI. ETW is where kernel drivers can receive a wide range of system activity from processes, also other parts of the kernel. And then AMSI, if you go to other DEF CON talks, Black Hat talks, it gets mentioned a lot because at this point, what AMSI does is it lets Defender, so Windows Defender, as well as all the AVs and EDRs, they get to register to say before a PowerShell script runs, before a macro runs, before all these scripting languages where traditional reversing doesn't work and there's a lot of obfuscation, those antivirus engines and the EDR engines get to scan the scripts. If they say they are malicious, then the scripts get blocked. And then what we'll really be focusing on with this talk is the last one, which is system call monitoring. And we'll have some pictures for that to make sure everyone is on the same page. And so when we broke down the bypasses, even, not even just like your really sophisticated threat groups, every ransomware family at this point, the half-decent ones, the first thing they do is load a kernel driver through Bring Your Own Vulnerable Driver, and they disable all the EDR callbacks and the AV callbacks. At that point, the ransomware can inject code, start new processes, and those systems are blind. For event tracing and AMSI, there are dozens and dozens of papers on how to disable these, and it's essentially a modern part of what you see in real investigations. But what we noticed, and as we'll see here on the next slide, is when we get to system call monitoring, we had no way to detect this. So before this research effort, with memory forensics, with volatility, you could very quickly determine that callbacks had been unregistered, that ETW had been tampered with, that AMSI had been tampered with. Again, these are going to point you right to the malware. But the system call monitoring that EDRs use, and it's one of the best ways they get visibility on the system, there was no way to detect this. And so in our investigations, we were having to do a lot of manual work to find it, to unravel it, and that just doesn't work for the scale that we operate at. We need automated ways. And the reason that the system calls are so critical to EDRs is the idea with system calls is this is your boundary from process memory to the kernel. So this diagram here, the Windows internals book, you have your processes running, your web browser, your office application, whatever it is that the process is running in user land or user mode, it's all the same thing. Besides manipulating their own memory, whenever they want to access a resource on the system, so they want to read or write a file, they want to read or write a network packet, anything beyond manipulating their own memory, they have to ask the operating system to do it. Because obviously you don't want your random notepad process writing directly to the hard drive. Or you don't want notepad writing directly to the ring buffer of your network driver. So, for processes that want to talk to network devices and request those operations, reading a file, writing a file, interacting with the network, it has to go through a system call. And that system call is going to change the execution context into the kernel, which is obviously the most privileged part. It has full access to the operating system itself, to other drivers, to other hardware. What you're seeing on the right side of this slide is the arrow that breaks down between process memory and the kernel where the system calls happen. You're seeing a stack trace of that here. When you look at a stack trace, you want to start at the bottom to make sense of it. So in the beginning, what these lines or these rows here with the U, this is in user land, or again, process memory. You can see that the Edge browser is running. It eventually gets to this call, ZW create file. Your system calls will, in almost all cases, start with ZW. And then you can see this is sysinternals monitoring the call stack. It eventually, when the system call is made, it jumps into the kernel file. And this K means we're in kernel memory. So this last call, the ZW, whatever that particular system call is, that is the last boundary before we jump in the kernel. And the reason we're focusing on this background so much is this is where your EDRs live. Because if you look at this slide, what we're seeing, I'll explain in more detail in a second, but on the left is the normal system call handler. So this is what you get with Windows by default. In this case, the slide is showing ZW protect virtual memory, so another system call on Windows. On the left is the normal flow that's going to reach the kernel. On the right is an EDR that has hooked it. So EDRs that want to monitor what processes are doing on the machine by injecting code into every process, hooking the system call functions of interest, it has complete control over what that process is doing right before it makes the system call. So if it wants to look for suspicious parameters, if it wants to log out what files are being read, what parts of the registry are being interacted with, by hooking that lowest level function, the EDR has full visibility. And so as we'll see here in a second, what malware wants to do is make its system calls without EDRs interfering or detecting it. But some background real quick while we're on a nice slide with a picture. What we're seeing here, again on the left, is the normal system call handler that jumped. We're going to go back. So what we see on the left is the normal system call handler. And there's a few things to keep in mind. First off, when you have the NT version of a function and then the ZW prefix version, it's the same exact function, but one's in user land, one's in the kernel. So we're seeing that here. The second thing is, from regular C code or C++ code, when you call a function, the parameters are sent in certain registers. We're going to focus on 64-bit machines. And besides RCX and R10, they're exactly the same. The weird thing is, with Windows, when you make a system call, your second parameter needs to be an R10 instead of RCX. So this has to get updated in those paths. And then EAX or REX has to hold the system call number. So for all the hundreds of system calls that Windows has for a particular version, each system call has its own number. And if you look at these handlers, they all look exactly like this, except this number changes, because that is the index into the system call table at runtime. And then we have a quick check to see what system call path is supported. And then to make that transition to kernel mode, we're either going to use the system call instruction, or if we're on an older processor, older version of Windows, we're going to make the int2e call. So again, this is, on the left, is what we would expect on a regular machine where you don't have EDRs. And then if you look on the right here, instead of all this code, eventually calling system call, we just have a jump out to an unknown region, which is going to be the EDR. And then when malware calls something like protect virtual memory here, or create file on the previous slide, the EDR has full control of that. It's going to kill the ransomware before it can launch any payloads. It's going to kill all the code injection techniques. And so if you have a decent EDR and it's not being tampered with, it's going to stop all these regular malware techniques from functioning. But like I said, we constantly do investigations where there's very potent malware on the machine, there's supposedly EDR on the machine, but when we dig into the infected processes, the EDR has been nullified. So what we're going to do for the rest of the talk is look at all of the bypasses that we found. Like I said, in our own investigations, there's a bunch of open source tools that do it as well. And then how we can detect them. The first one goes by a couple different names. Module unhooking, system call unhooking, API unhooking. The basic idea here is the malware is going to unhook the system call handlers. And the end goal is when malware starts running and they're in a process that EDRs have all the system calls in this hooked form, it wants to get it back to the original form so that the EDR is blind to what's going on. The way this works, and this PowerPoint keeps jumping a lot, the way this works, this is a screenshot from a very recent report from a very recent report maybe two or three months ago of malware that did this to then spread across a huge network. The basic idea is where system calls are implemented in memory is NTDLL. So the first DLL that loads in every process is NTDLL that has all of those system call handlers, one per system call. And that's what the EDRs hook. They put the jump instruction, it goes directly to the EDR code and then like I said, the EDR can evaluate the parameters before the system call is made. So you can see it in the steps here, this report was really nice. What this malware did is it read the clean copy of NTDLL from disk so that copy on disk is what Microsoft published that does not have any EDR hooks present. So it reads NTDLL from disk, it finds where those system call handlers are in their clean state on disk and it just overwrites all the EDRs hooks. And now the malware can call any system call at once with whatever malicious parameters it wants, any malicious end goal that it has, and even though the EDR is technically loaded in that process, its code is never going to be activated. And so when we look at ransomware and we're like, how can it inject code? How's it encrypting all the files? How's it elevating privileges? It's because the EDR has no idea what's going on, and this is one of the many ways that we'll talk about how it happens. So again, you go from the state where every process on the machine has their system calls hooked, the malicious code, the malware is going to run in its own process, or it's going to inject code into a victim process, and in that victim process, or the malware's own process, the system call handlers will be reverted back to where they were on disk, but all the other processes will have the hooked form. So what we realized is instead of trying to figure out the 50 different variations for module unhooking, we could just use data in memory to tell us where the malware is. So what our new volatility plugin does is it enumerates every process, it reads the bytes of all the system call handlers that the malware often targets, and then we just compare the implementations. And as you'll see here in a couple slides, what we can do is say, you have 100 processes running, 99 of them have one implementation, and this one process on its own has a different implementation. The 99 are the ones where the EDR is still active, and that one kind of outlier process is the one that the malware is unhooked. And so we like, when we do this type of research, we like to make experiments that can be repeated by anyone else. Obviously not everyone works at Velocity and has access to our infected samples from the wild, so we come up with experiments using open source tools where you can recreate this on your own and you can test it in your own environment. So a very nice tool for testing EDR, a very nice open source tool for testing EDR bypasses is called SilentStrike. So this is an open source EDR, and it was actually developed just to test these bypasses and then see if you could detect them. The way SilentStrike works is it hooks NT protect virtual memory. This is one of the main functions that malware needs to perform code injection and also to try to keep that code injection stealthy. And so what this open source EDR does is it hooks that function if it gets called where the region is going to become readable, writable, and executable the EDR says you can't do that, and that stops a lot of different code injection techniques. So for our experiment what we did is we took a base Windows 10 install, so no EDR. With SilentStrike you can tell it to create individual processes that it will then treat as an EDR and protect. So we started a notepad and we started a wordpad. At this point they have SilentStrike active in it which is your EDR. We then took a memory sample. After that we ran R77 which is an open source rootkit that does this module unhooking and we unhooked the notepad process. And then we took a second memory sample. So we have the state before and after the malware ran and with our new plugin, so unhook system calls to volatility 3 what it's saying here is what we do is we enumerate all the functions the slide is cut, there's probably like 50 functions we actually check. But the idea is we're saying for these processes down here, there's no distinct implementations. So every process inside of that memory sample had the same version of the function and then the two that we started under SilentStrike, their NT protect virtual memory, had the EDR's view. This is before we ran R77. We then ran the R77 rootkit on the machine. We unhooked notepad and you can see it removes from distinct implementations it's been reverted back to the base form. So then we took this plugin ran it across the many hundreds of memory samples that we have to test our code on and the only place this plugin fired was either traditional API hooking or EDR unhooks. So there's no false positives with this if the EDR's hooked every process it doesn't make sense that it would skip one or that one should be reverted. This directly tells you where the malware is running. We then started looking into other ways to read NTDLL. So you saw it in the screenshot before from that malware report and I walked you through where to, for unhooking to work, the malware needs access to a clean copy of NTDLL which normally you can just read from disk but there were several EDR vendors that started detecting that because why would some random process need to read NTDLL as a file and like parse the section? The only reason to do that is to unhook the EDR out of memory. So this made it harder for that malware to operate it can't read NTDLL from disk or it's going to get caught. So we saw some malware samples and some open source tools that abused suspended processes to get the clean copy. If you've ever investigated process hollowing, whether you were writing code for it or you were trying to detect it, creating suspended processes is the first step of every process hollowing technique. So we'll see that we catch some of those as well as kind of a side effect. But the idea for EDR bypasses is the malware will create a suspended process. The idea with a suspended process is that the only thing that's going to load is the application executable and NTDLL. It's kind of like a half created process at that point. Once the EXE and NTDLL are mapped into the process then at that point the parent process, the one who created the process, gets control back. So then what the malware does is it just reads from its child process, the clean NTDLL out of memory. The EDR doesn't see a suspended process until it actually starts running. So this puts a clean copy of NTDLL in memory. The malware doesn't have to go read it from disk. And so obviously we want it to be able to detect this as well. So we did some reverse engineering and read some pre-existing reports on what happens with suspended processes. Like I said, we see it a lot because you have to do this if you want to create a hollowed process. But what you have in kernel memory is for every process you have an E-process structure. For every thread you have an E-thread or a K-thread structure. When that process gets created in the suspended state every process starts with one thread. And when you create the thread suspended, its suspense count goes to one, which tells the operating system not to run it. Normally if you just create a process in the normal way or you double click it on your desktop, the suspend count is going to be zero. And as soon as that process can get scheduled, its threads are going to run. But what we saw in every piece of malware that we had and every open source tool we had access to that did this, when they create the suspended process just to read the clean NTDLL, they're never going to run that child process. They are just getting that into memory to get access to the clean system call handlers. So this was pretty easy. We wrote a plugin. Volatility could already enumerate every thread of every process. And then we just added an extra step to say does that thread have a suspend count greater than zero. Running it across our large data set of memory samples, the only false positive we had, which was pretty random, is this work folder shell DLL inside of edge makes suspended threads. We don't know why. So we just added that to the list of ones we don't print out. And besides that, we didn't have a single false positive. And then like I said, at Vlexity, we have hundreds and hundreds of memory samples in different states that we test these things on. And quite a few of the samples that we know have process hollowing in them, they were detected too, because if you're familiar with that technique, the idea is you create a process in a suspended state, you overwrite the code, and then you let that new process run. And so not only is this plugin picking up all the EDR bypasses, we caught a bunch of different... we generically caught a bunch of different process hollowing techniques as well. At Blackhat Europe, maybe two years ago now, three years ago, there was a really cool white paper and talk on a project called Dirty Vanity. The idea was they tested against basically every commercial EDR they could get their hands on. And the idea is they wanted to be able to do code injection into a victim process without the EDRs catching them. And if you're familiar with this, to do code injection, there's five or six APIs you have to call to make that work. And if you call all those in a row and you're injecting, the end result is you're going to inject into your victim process, any half-decent EDR, any enterprise-level EDR is going to catch that. So what was really interesting about Dirty Vanity is they instead created clone processes, or a forked process if you're more familiar with Linux. So the idea with a clone or a forked process is your process is running, you create a clone of your own process, so that child process you created has your same exact state. So then what Dirty Vanity did is they called the first couple APIs from the parent and then they create the clone, which has the same exact state as the parent and they called the final set of APIs from the child. So the end result is they're still injecting code into the victim process, but none of the EDRs that they tested were able to detect the calls going across the process boundary. So obviously we wanted to be able to detect this from a memory forensic standpoint. So while we were looking into what it means to clone a process in Windows, the real internal state, we saw that what Windows does when it's setting up that clone is it makes a suspended thread. So that child that's being cloned into has its first thread suspended and with Dirty Vanity it never restarted the child process or the initial thread of the child process. So the plugin that we had detected it right away. And if you're interested in this I have it cited here at the bottom. We found this thing called the Definitive Guide to Process Cloning on Windows. It's like 40 pages of APIs and data structures and background, but it pretty much told us exactly what we needed to know on top of what we saw with reversing. We made a memory sample that was infected with Dirty Vanity and as you can see we're running our suspended threads plugin. It's telling us that inside of the fake EXE process, which is what Dirty Vanity calls itself if you just compile it straight from GitHub and then it's saying that this process ID, 6752 this thread, it is suspended or suspend count is greater than zero. And then if you look at PSTree in Volatility so this is drawing out the parent child relationship of processes you can see that the original fake EXE has a child called fake EXE so this is that process that was created through cloning. So this is the parent, this is where Dirty Vanity will call the first couple APIs it then forks or clones off a child process where it will call the remaining APIs bypassing the EDR, but what you can see Volatility picking up on is the child's always going to have it's main thread suspended. And so we pick up on that right away, you would then run PSTree would probably be the next thing if this was a real investigation, you would figure out the parent that created the suspended process. And then you can see here what it does in demo mode, so if you don't have an EDR you're targeting Dirty Vanity will run command shell with some shell code that makes a pop up on the screen or prints it to the terminal. So you see that here as well, that child process. But through the new plugin you see exactly which process is malicious, you can then do your normal memory forensics workflow. As you've been seeing in the slides, the previous techniques that we looked into for bypassing the system call handlers relied on overwriting code. And you might have been thinking, especially if you've done debugging before or low level programming before, the idea that you're going to overwrite NTDLL the entire thing or certain functions at run time is a bit unsafe. Because you can imagine if you're overwriting 30 or 40 functions code in memory, if any other thread is using that function or a system call was just made and you're waiting for user land to return again, you just blew away the code that was technically running on the CPU. So malware does it, it generally works, but it's a bit unsafe. And then the other thing you could imagine is EDR could just check for its hooks. If it hooked 40 or 50 system call handlers and then it checks whatever frequency later and its handlers are overwritten, it knows that there's malware inside of that process. So this led to what was some really interesting research on the open source side, and like I said, we saw it in private malware as well. So there were alternative methods developed where the code is not overwritten. The malware, as you'll see, can still make its malicious system calls, it can still do any system calls at once with any parameters, but we're not overwriting code. So inside of NTDLL, in that EDR protected process, the original implementation that the EDR gave is the same, the hooks are present, the EDR would get control if the real system call was used, but malware is just going to avoid those code paths. So we'll look at the different ways they do that and the ways we can detect it. The first one we looked at were direct system calls. So the malware authors realized that why do I need to call the system call handler inside of NTDLL? You saw that a system call handler is only 5 or 6 instructions, why don't I just do that myself? So rather than going through NTDLL, which the EDR is hooked, I'm just going to set up the registers that are needed and I'm going to make the syscall instruction on my own. And again, the EDRs that are trying to catch you through system call hooks, they are blind to you because you're not going through their hooked code. The problem with this, and there was a very interesting series of posts by Elastic that I have cited at the end, this is where they started doing call stack examination, Elastic does this really well, there's some open source implementations of it also, but the idea is, if you were making a system call instruction, or you're calling a system call instruction outside of NTDLL, so you're in some random DLL that you've injected, or you're in a shellcode region, your EDR in kernel mode can see that. And then it's going to say, why is a system call being made from a random shellcode region that wouldn't normally happen on a running machine? And then the other downside to this, as we'll see, is you have to know where the system call indexes are. So like I said, there's hundreds of system calls per release of Windows, and the indexes change almost every time. The indexes are not guaranteed. If you're writing normal legitimate code, you shouldn't care about the indexes, you just call the higher level API, and the operating system does the work for you. But in this case, where you want to make the system call yourself, and you don't want to use the normal APIs because the EDR has hooked them, you have to be able to get that index value to put into EAX. So if we look at the way that this has evolved over time, the first tool that made this popular is called dumpERT. It's an open source tool, it's still on GitHub, has a very nice companion blog post, and as you can see, for every system call it wants to make available to the malware, it has to put that little stub itself. It has to update R10, update EAX with the very specific index for the very specific system call, then it can call system call in return, and at this point you can make those, but if you look at the code, this is hard-coded to one version of Windows 7, one release under Service Pack 1, this is not something you could use in generic malware. So instead what we want to be able to have is where that is very loud, instead we want to make it where system calls can be resolved dynamically. So instead of your malware having what would literally be hundreds of hard-coded system call tables for different versions of Windows, we want to find those indexes dynamically. The first implementation of this is called Hell's Gate. Almost every technique has gate in the name, which makes it kind of annoying to remember. So the first one is Hell's Gate. In this case, what it did is it parsed NTDLL on disk. Kind of like we talked about before, but instead of overwriting pre-existing code or the EDR's code, it's just parsing NTDLL on disk and then it's dynamically resolving the numbers. Because, for example, let's say in this case it wants to call a ZW open process. Instead of having to know beforehand that on Windows 7 Service Pack 1 the index is 23 hex, it can just load NTDLL, it can call get proc address for ZW open process, it can do some automated disassembly on the code, and it can read out the index dynamically. So this was Hell's Gate. You can see the code here on the right. Instead of being hard-coded to a certain number, it has a little API wrapper that you use as a programmer. You prep the system call, that's going to fill in this global variable, and then when it comes time to make the system call, it will fill in the number correctly for you. The problem with this, like I said, is most decent EDRs, I'm not going to say certain vendors, but most decent EDRs, if random code is reading NTDLL and parsing the P header and all of that, the EDR is going to flag on it because it's just not something legitimate code would do. So this led to even more gates. There is Tataris Gate, which initially, there was some detections and some YARA rules that were put out to detect this code pattern that's very hard-coded and this code pattern that's very hard-coded. All it did was make it a little more difficult to where those naive patterns would break. It put some no-op instructions, it put some other instructions that didn't have a side effect. But remember, you're in the system call handler path, so you can't add a bunch of junk instructions or you will kill performance on the machine. In a real process, you're going to have thousands and thousands of system calls running. You cannot have where you put in a bunch of junk code just to throw off a YARA rule. So even adding a few extra instructions will have a real impact on the system. So like I said, Tataris Gate is just trying to make it where if all you have is a kind of brittle, basic YARA rule, you will not catch those code patterns. There was then Halos Gate, which was an interesting twist on reading NTDLL from disk. So they wanted to, these malware authors wanted to get away from reading NTDLL from disk. So instead what they do is they kind of rely on the fact that the EDRs aren't going to hook every system call. They're just going to, the malware is only going to unhook this, sorry, the EDR is only going to hook the system calls that it wants to monitor. So what Halos Gate does is it dynamically goes through all the other system calls that the EDR is not hooking and then it just does some math. It says, OK, I know the system call before it and the system call after it are this number, so the one in the middle, it can dynamically figure it out. Again, this avoids reading NTDLL from disk. And then there's a really cool technique called address sorting. One of the authors of this open source project realized that all the system calls are put in order alphabetically. So if you just read the addresses of where they all are, it's kind of the same idea. You alphabetically sort them. If they're the one that you're trying to use as hooked, you just look at the one before it and you add one and now you know the index that you need. And then even dealing with all of that previously was kind of difficult. There's a lot of assembly, a lot of low level C code. So there's this really nice project called Sys Whisperers 2. And the 2 is important because the first version was not very good, but the second version is very powerful. This integrates with Visual Studio. You call directly through this and it does all the nasty work in the background for you to dynamically resolve those system call indexes. So if you want to write code that bypasses EDRs, you want to be able to make whatever system call you want without being detected, all you have to do is import the Sys Whispers 2 into your Visual Studio project, write your malware freely and it does all the hard work in the background for you. So with all these different techniques that make EDRs blind to what's happening, we wanted to be able to detect this. So we kind of already knew this before going into it, but we did a large sweep across all of our Windows memory samples and for every version of Windows going back to XP through the latest Windows 11, there's only 3 DLLs that legitimately implement system calls. There's the NTDLL that I talked about, Wow64 for 32-bit processes and then Win32 is for the GUI, so what you're seeing here on the screen with Explorer and PowerPoint. So the idea is through memory forensics, if we find the instructions needed to make a system call instruction and set the parameters and it's not in one of those 3 DLLs, this is malware trying to bypass the system. And then like I mentioned, it's some very, very cool low-level work. I threw this screenshot in literally last second, like right before I sent these slides to DEF CON, because there was a talk by a security vendor as I was making the slides, right as I was about to upload it and I took this screenshot and threw it in last second, because it was talking about malware that was just used recently in the last 1 or 2 months in real attacks and it, the malware was called Dodgebox and it's talking about how in every phase of the malware, every component the malware had, it did call stack spoofing, so bypassing the EDRs to make it appear where those system calls, so it's doing direct system calls, making it appear where it came from the trusted binary, so the ones we saw in the last slide, instead of the malware itself. And so it's this constant back and forth between EDRs and malware, trying to figure out that system calls are being made from the wrong spot but quite honestly the EDRs are in a tough spot and usually the malware wins. We don't have these problems with memory forensics, we don't have to detect the system call the second it's made, we're trying to find proof of code that can do that or does that through memory forensics, and so what we did is we wrote, we used Capstone, which is a very flexible disassembly library, has Python support so you can use it directly in volatility and what we do is look for blocks of code, so block code pattern blocks where EAX gets updated, that's your system call index, where R10 gets updated, where one of the system call instruction happens and where there's a return. We did a bunch of work so that simple things like Tataris gate with this noops wouldn't bypass our code, we're not doing pattern matching, we're doing actual automated static disassembly and when we tested this on every implementation that we had of this technique, our new plug-in direct system calls detected it. In this case, just to make it fit on a slide nicer, this is Hell's Descent from Hell's Gate, so this is where it's calling the system call instruction on its own, and then the plug-in saying, hey, inside of this process, executable with this PID, and it shows you right in memory where that system call handler is. So it's as simple as running this plug-in across your potentially infected samples, and it tells you right where the malware is. And then with the indirect system calls, the idea is, instead of having that code pattern where you're making syscall or int2e directly from your malware code or your shell code, which, again, you have to do a bunch of call stack spoofing and things, or the EDRs will see you, the idea is you find the address of the syscall instruction in ntdll, but instead of calling the function of that, you find where the syscall instruction is, and you jump to it. So you set the registers yourself, you do all the prereqs yourself, you jump to the syscall instruction, it looks like it's coming from ntdll, and then depending on which EDR you have, that EDR is going to think it's the real system call, and then you've bypassed it. So we wanted to be able to detect that as well, and something that also gets used with this technique are the exception handlers and the debug registers, which is the last thing we cover in this talk. So the idea is debug registers have been abused forever by malware, there was a frack article in 2008 that's the first, considered the first public documentation of it, and the idea is by abusing debug registers, you can get your exception handler called at any point in time, and then from your exception handler, you're going to make the system call instruction, and EDRs do not follow this well as, at all. They don't expect malware to be running inside of exception handlers. So a cool open source project for this, if you want to see it yourself, is called MutationGate, it is on GitHub, and you can see what it's doing, it's adding a vectored exception handler, so it's saying it wants to handle exceptions in its process, this is the function that's going to be called, and then on its own, it sets a breakpoint at this innocuous system call, NTDrawText, that has nothing to do with code injection or malware, so the idea is, this malware, this code injection, uh, this EDR bypass technique, will get called whenever a breakpoint is set, and then it explicitly sets a breakpoint on where the system call instruction is inside of this innocuous function. So then, in the implementation of it, what it does, is every time the malware wants to make a malicious system call, it just calls NTDrawText, which again, you can't do anything malicious with that, and then the malware, the MutationGate, it updates RAX right before the system call instruction to be the real system call. So your EDR is going to think, hey, this malicious code's calling DrawText, it's going to write something on the screen, but in reality, it's all the prereqs you need for code injection. So we wanted to detect this, we didn't even have to do any major reversing for this, there was two very nice blog posts on the topic that we have referenced here, and the only downside to this is legitimate software uses uh, exception handlers, you don't want your software having an unhandled exception and then like crashing the machine, so by having an exception handler, you make it where your code gets to handle the exception and then you can cleanly exit. So what we did is we, instead of just listing them all out like some plugins do, we applied very similar static disassembly to the function handlers, we looked at all the malicious techniques, we saw which registers they interacted with, which per- which actions they performed, and so instead of just listing out every vector exception handler, we apply the static disassembly, and then we only list out the malicious ones. And as you can see here, with our new plugin, we're catching mutation gate generically right away, because of how it interacts with it. There was also a cool project by Marcus Hutchins, where he wanted to bypass EDRs in the same way, instead of the vector exception handler, he used the higher level one, the unhandled exception filter. In this case, this is going to be the address of where he has his exception handler called, and then he's calling setThreadContext on what's an invalid address. So this is going to trigger the exception handler. So what we did here was very similar. We enumerate all the handlers, and then we make it- this keeps jumping a lot. We enumerate all the handlers, we apply our static disassembly, and then in this case we find his malicious process generically, because the exception handler is doing things that you would need to bypass an EDR. And then with the debug registers, the last thing we really show here, if you're familiar with AMSI bypasses, one of the things you need to do is, one of the functions you're probably going to tamper with is the scanBuffer1. In this case, they set a breakpoint on it, and they make it where that function doesn't get- anytime that function returns, it returns that the code is okay. So you can send whatever malicious PowerShell you want through, whatever malicious macros that you have, and with this code present, all of your EDRs are forced to say, hey yeah, this is clean, and then it gets to execute on the system. And you can see that here with our new plugin. So with the vector exception handler, we're catching it right away. The project that implements what you're seeing on these slides is called Patchless AMSI. So we're not only catching its vector exception handler, we're also catching its abuse of the debug registers so that it can be called whenever the code is going to get scanned by the AMSI subsystem. So the end result of our project is we documented and went through every single way that EDRs get bypassed in user land, and then we wrote a bunch of volatility plugins to automatically detect it. Two quick things before I break. We wrote a 19-page white paper about this. It should be on the DEF CON website by like now or tomorrow. Feel free to email me if not. Also, the slides. Don't try to take pictures of the next couple slides. These are all the references that you were seeing with the numbers at the top of the slides. We have like 45 references. It was a huge research effort. The slides are on the DEF CON website as well, or email me if you can't find them. But if you really want to understand in great detail, read the paper, and then read all the references as well. And again, thank you for coming to the talk. Thank you.