Understanding SeLoadDriverPrivilege Escalation: A Deep Dive

Oct 20, 2024    #windows   #active-directory   #seloaddriverprivilege   #capcom  

Introduction:

Among the various techniques employed by attackers, one particularly insidious method involves the exploitation of SeLoadDriverPrivilege. This Windows privilege, often overlooked, can serve as a powerful tool in the hands of malicious actors, enabling them to elevate their permissions and potentially gain complete control over a system.

Key Points:

Let’s dive into the world of SeLoadDriverPrivilege and explore how this seemingly innocuous privilege can become a significant security risk.

Understanding SeLoadDriverPrivilege:

At its core, SeLoadDriverPrivilege grants the ability to load kernel-mode drivers into the Windows operating system. While this might sound benign, it’s a capability that normally requires administrative permissions, and for good reason. Kernel-mode drivers operate at the highest level of the system, with unrestricted access to system resources. This level of access is precisely what makes SeLoadDriverPrivilege so attractive to attackers.

Typically, this privilege is assigned to administrative groups or specific users like Print Operators. It’s represented in the Windows API by the constant SE_LOAD_DRIVER_NAME. However, what makes it particularly dangerous is that it can sometimes be found enabled on accounts that aren’t full administrators, creating a potential security gap.

Key Points:

The Exploitation Process:

Overview & Diagram:

To better understand the flow of a SeLoadDriverPrivilege exploit, let’s look at a simplified diagram of the process:

+--------------------------------------------------+
|                                                  |
|  +--------------------------------------------+  |
|  |                                            |  |
|  |  1. Enable SeLoadDriverPrivilege           |  |
|  |     - OpenProcessToken()                   |  |
|  |     - LookupPrivilegeValue()               |  |
|  |     - AdjustTokenPrivileges()              |  |
|  |                                            |  |
|  +--------------------------------------------+  |
|                       |                          |
|                       v                          |
|  +--------------------------------------------+  |
|  |                                            |  |
|  |  2. Interact with Windows Registry         |  |
|  |     - Access HKLM\SYSTEM\CurrentControlSet |  |
|  |       \Services                            |  |
|  |                                            |  |
|  +--------------------------------------------+  |
|                       |                          |
|                       v                          |
|  +--------------------------------------------+  |
|  |                                            |  |
|  |  3. Load Vulnerable Driver                 |  |
|  |     - Register driver in registry          |  |
|  |     - Use NtLoadDriver() to load driver    |  |
|  |                                            |  |
|  +--------------------------------------------+  |
|                       |                          |
|                       v                          |
|  +--------------------------------------------+  |
|  |                                            |  |
|  |  4. Exploit Vulnerable Driver              |  |
|  |     - Execute arbitrary code in kernel     |  |
|  |       space                                |  |
|  |     - Gain SYSTEM privileges               |  |
|  |                                            |  |
|  +--------------------------------------------+  |
|                                                  |
+--------------------------------------------------+

This diagram outlines the four main steps an attacker would typically follow when exploiting SeLoadDriverPrivilege. Let’s dive deeper into each step.

Step 1: Enabling the SeLoadDriverPrivilege Privilege:

The first step involves activating the SeLoadDriverPrivilege. Windows uses a token-based system for managing user privileges, and SeLoadDriverPrivilege is usually disabled by default, even if it’s assigned to a user. Attackers can use Windows API functions like LookupPrivilegeValue() and AdjustTokenPrivileges() to enable this privilege on their token.

Step 2: Registry Interaction:

Step 3: Loading a Vulnerable Driver:

With the privilege activated and registry access established, the attacker can now load a driver of their choosing.

Step 4: Exploiting the Driver:

The final step involves exploiting the loaded driver. Attackers often choose to load known vulnerable drivers, such as the infamous Capcom.sys. (which is a Windows signed driver) These vulnerable drivers can be exploited to execute arbitrary code in kernel space, effectively giving the attacker complete control over the system.

Capcom.sys Driver Vulnerability: Arbitrary Code Execution with SYSTEM Privileges

Now that we’ve confirmed we have the necessary privilege and the system is vulnerable, let’s look at the specific vulnerability we’ll be exploiting.

Overview of the Capcom.sys Vulnerability:

Real-World Exploitation Example

To better understand how SeLoadDriverPrivilege exploitation works in practice, let’s walk through a real-world example. This demonstration will show each step of the process, from identifying the vulnerability to achieving system-level access.

Prerequisites:

Before we begin, ensure you have the following tools and environment set up:

Finding out we have the SeLoadDriverPrivilege privilege:

The first step in any privilege escalation attempt is to enumerate the current user’s privileges. In this case, we’re looking specifically for the SeLoadDriverPrivilege.

Checking the system is vulnerable to the exploit:

Not all systems are vulnerable to this exploit, even if the SeLoadDriverPrivilege is present. We need to check the Windows build number to ensure it’s below a certain threshold.

Executing the Attack

Now that we understand the vulnerability and have confirmed our system is susceptible, let’s walk through the actual attack process.

Download A Copy of the official Capcom.sys Signed Driver:

Compiling the EopLoadDriver tool to enable us to load the Capcom.sys driver:

The EopLoadDriver tool is a utility designed to leverage the SeLoadDriverPrivilege for loading a driver into the Windows kernel. It interacts with the Windows registry to register the driver and then uses the NtLoadDriver system call to load it. This tool is essential in our exploit chain as it allows us to load the vulnerable Capcom.sys driver, which we’ll subsequently exploit to gain SYSTEM privileges. By using EopLoadDriver, we’re able to bridge the gap between having the SeLoadDriverPrivilege and actually loading a driver of our choice into the kernel.

Compiling the ExploitCapcom exploit C++ project

The ExploitCapcom tool is the core component of our privilege escalation attack. It’s designed to exploit the vulnerability in the Capcom.sys driver that we’ve loaded using EopLoadDriver. This tool takes advantage of the driver’s ability to disable Supervisor Mode Execution Prevention (SMEP) and execute arbitrary code in kernel mode. By default, ExploitCapcom opens a new command prompt with SYSTEM privileges, but we’ll modify it to launch our custom payload instead. This tool effectively completes the privilege escalation chain, leveraging the loaded vulnerable driver to elevate our permissions to the highest level in the Windows operating system.

Modifying ExploitCapcom exploit to enable a reverse shell

To make our exploit more useful, we’ll modify it to give us a reverse shell instead of just opening a new command prompt.

Generating our reverse-shell payload using msfvenom:

Run the exploit chain on the victim:

Now that we have all our tools ready, let’s execute the attack:

  1. I Use evil-winrm to transfer all the files to the target:

    • upload [filename]
    • Use whatever method you prefer
  2. Load the driver Run Exploit:

    • .\EopLoadDriver.exe System\CurrentControlSet\Capcom C:\Users\svc-print\Documents\Capcom.sys
    • All 0’s is good as a response, means we are working.
  3. Setup Listener:

    • rlwrap -cAr nc -lnvp 443
  4. Trigger exploit:

    • .\ExploitCapcom.exe
  5. Catch the reverse shell and verify privileges:

Summary:

This real-world example demonstrates the entire process of exploiting the SeLoadDriverPrivilege, from initial enumeration to achieving SYSTEM-level access.

Defending Against SeLoadDriverPrivilege Attacks:

Given the potential for abuse, it’s crucial for system administrators to take steps to mitigate the risks associated with SeLoadDriverPrivilege. This includes:

  1. Restricting privilege assignment to only the most trusted accounts.
  2. Implementing rigorous driver integrity checks.
  3. Regularly auditing account privileges to detect any unauthorized changes.
  4. Using driver blocklists to prevent known vulnerable drivers from being loaded.
  5. Employing application control solutions like Windows Defender Application Control (WDAC) or AppLocker to restrict driver loading.

Detection is equally important. Monitoring Windows Event Logs for driver loading events (Event ID 6), configuring Sysmon to track driver loads, and implementing behavioral analysis to spot unusual patterns of driver loading can all help in identifying potential attacks.

It’s important to note that no single measure can provide complete protection against SeLoadDriverPrivilege exploitation. A defense-in-depth strategy, combining multiple layers of security controls, is crucial for comprehensive protection against this and other potential vulnerabilities.

Conclusion:

SeLoadDriverPrivilege serves as a stark reminder of the complexities involved in securing modern operating systems. What appears to be a benign administrative privilege can, in the wrong hands, become a powerful tool for system compromise. Mitigating such vulnerabilities will remain crucial in our ongoing efforts to protect our systems and data.

Further Reading:

For those interested in diving deeper into this topic, I recommend exploring:

Frequently Asked Questions:

Appendix:



Next: Understanding Azure AD Connect Exploitation & Privilege Escalation