Malware

Banshee – A Foray Into Kernel-Level Power With Rootkit Techniques

Learning about Windows rootkits lately, so here is my own implementation of some techniques. For an overview, see Features below.

Banshee is meant to be used with kdmapper or a similar driver mapper.

I am just learning about kernel driver development, so this is for educational purposes mainly.

Usage

You can integrate Banshee into your tooling, by including the Banshee.hpp file in your project, e.g.:

Banshee banshee = Banshee();
banshee.Initialize();

int targetPid = GetDefenderPID(); // this would be your implementation
banshee.KillProcess(targetPid);   // instruct banshee to kill the targetprocess

An example implementation of all the features in a command line client is found in ./BansheeClient/BansheeClient.cpp:

Features

Get in everyone, we’re going to Kernel Land!

Kill Processes

ZwTerminateProcess is simply called from kernel land to terminate any process.

Change Protection Levels

This is done by modifying the EPROCESS structure, which is an kernel object that describes a processes attributes. It also holds a value that specifies the protection level of the process.

We can directly modify this value (aka Direct Kernel Object Modification or DKOM), since we are operating in Ring 0.

Elevate Any Process Token To SYSTEM

EPROCESS also holds a pointer to the current access token, so we can just make it point to e.g. the token of process 4 (SYSTEM) to elevate any process to SYSTEM.

Enumerating And Erasing Kernel callbacks

For now, only Process- and Thread-Creation kernel callbacks are enumerated, by parsing the PsSetCreateNotifyProcess/ThreadRoutine routine to reach the private Psp* routine and then parsing the address of the array, where kernel callbacks are stored. With erase, callbacks can be erased by overwriting the function pointer to point to an empty function in Banshee instead.

Protecting The Driver File

By hooking the NTFS filesystem’s IRP_MJ_CREATE handler, we can block any process from opening a handle to our driver file (This will probably change to a filter driver concept soon).

Keylogging From The Kernel

Using the undocumented gafAsyncKeyState function we can parse keystrokes from a session without using any API calls besides reading memory.

Misc

Communication Over SharedMemory

Banshee does not communicate over IOCTLs as most drivers do, but rather over shared memory. This way no DriverObject needs to be registered, which would point to our unbacked memory region (if mapped to memory) and would lead anti-rootkit software directly onto us. We can still get clapped with NMI callbacks, but hopefully, a custom mapper I have planned should solve that (WIP).

Patchguard Triggering Features

These should only be used with a patchguard bypass or in a lab environment as they trigger BSOD.

Hide Process By PID

Again, EPROCESS comes to help here – it contains a LIST_ENTRY of a doubly linked list called ActiveProcessLink which is queried by Windows to enumerate running processes. If we simply unlink an entry here, we can hide our process from tools like Process Monitor or Task Manager.

  • This can cause Bluescreens, e.g. when the process is closed while being hidden or due to patchguard scanning the kernel memory. While the former can be fixed by not being so lazy when programming, the latter can not be as easily bypassed from within the driver.

Testing And Debugging The Driver

I recommend to enable debugging for the kernel. Run the following from an administrative prompt and reboot afterwards:

bcdedit /debug on

Afterwards load the driver with kdmapper.

You can then run the client, after compiling the solution, with e.g.:

.\x64\Debug\BansheeClient.exe

Run this in a VM, debug this VM with WinDbg and create a snapshot before. You will probably Bluescreen a lot when developing.

Varshini

Tamil has a great interest in the fields of Cyber Security, OSINT, and CTF projects. Currently, he is deeply involved in researching and publishing various security tools with Kali Linux Tutorials, which is quite fascinating.

Recent Posts

Kali Linux 2024.4 Released, What’s New?

Kali Linux 2024.4, the final release of 2024, brings a wide range of updates and…

22 hours ago

Lifetime-Amsi-EtwPatch : Disabling PowerShell’s AMSI And ETW Protections

This Go program applies a lifetime patch to PowerShell to disable ETW (Event Tracing for…

22 hours ago

GPOHunter – Active Directory Group Policy Security Analyzer

GPOHunter is a comprehensive tool designed to analyze and identify security misconfigurations in Active Directory…

3 days ago

2024 MITRE ATT&CK Evaluation Results – Cynet Became a Leader With 100% Detection & Protection

Across small-to-medium enterprises (SMEs) and managed service providers (MSPs), the top priority for cybersecurity leaders…

5 days ago

SecHub : Streamlining Security Across Software Development Lifecycles

The free and open-source security platform SecHub, provides a central API to test software with…

1 week ago

Hawker : The Comprehensive OSINT Toolkit For Cybersecurity Professionals

Don't worry if there are any bugs in the tool, we will try to fix…

1 week ago