A malicious program such as rootkit can load a kernel driver to run the code in kernel mode. Once it's running in the kernel space, it has access to the internal operating system code and it can monitor system events, evade detection by modifying the internal data structures, hook functions, and modify the call tables. A kernel mode driver typically has an extension of .sys and it resides in %windir%\system32\drivers. A kernel driver is normally loaded by creating a service of type Kernel Driver Service (as described in Chapter 7, Malware Functionalities and Persistence, in the Service section).
Windows has implemented various security mechanisms that are designed to prevent the execution of unauthorized code in the kernel space. This makes it difficult for a rootkit to install the kernel drivers. On 64-bit Windows, Microsoft implemented Kernel-Mode Code Signing (KMCS), which requires the kernel mode drivers to be digitally signed in order to be loaded into memory. Another security mechanism is Kernel Patch Protection (KPP), also known as PatchGuard, which prevents modifications to core system components, data structures, and call tables (such as SSDT, IDT, and so on). These security mechanisms are effective against most rootkits, but at the same time, this has forced the attackers to come up with advanced techniques that allow them to install unsigned drivers and to bypass these security mechanisms. One method is to install a Bootkit. A Bootkit infects the early stages of the system startup process, even before the operating system is fully loaded. Another method is to exploit vulnerabilities in the kernel or third-party driver to install an unsigned driver. For the rest of this chapter, we will assume that an attacker has managed to install the kernel mode driver (using Bootkit or by exploiting a kernel-level vulnerability), and we will focus on kernel memory forensics, which involves identifying the malicious driver.
On a clean windows system, you will find hundreds of kernel modules, so finding the malicious kernel module requires some work. In the following sections, we will look at some of the common techniques to locate and extract malicious kernel modules. We will start by listing the kernel modules.