Windows kernel hacking framework, driver template, hypervisor and API written on C++

Overview

The Kernel-Bridge Framework

The "Kernel-Bridge" project is a C++20-ready Windows kernel driver template, development framework and kernel-mode API and wrappers.

Precompiled and signed binaries with the SecureBoot support

Capabilities:

  • Hypervisor (both Intel VT-x/EPT and AMD-V/RVI) with the Hyper-V support
  • Extremely fast hypervisor-based memory interceptions and hiding (+ support of Write-only pages), VT-x only
  • Support of HookLib and Zydis
  • IO-ports (+ 'in/out/cli/sti' usermode forwarding by IOPL)
  • System beeper
  • MSRs, CPUID, TSC and performance counters (RDPMC)
  • DMI/SMBIOS memory reading
  • Physical memory (allocations, RW, mappings)
  • Kernel memory management (allocations, mappings, transitions)
  • Usermode memory management (allocations in processes etc.)
  • Direct UM->KM and KM->UM memory transitions
  • Direct PTE-based memory management
  • Direct MDL management
  • Obtaining processes/threads handles from kernel
  • Reading and writing memory of another processes
  • Suspending/resuming/termination processes
  • Creating kernel and usermode threads
  • Memory mappings between usermode and kernel
  • Remote code execution (APCs delivery)
  • Execution of custom usermode shellcodes
  • Unsigned drivers mapping
  • Processes, threads, handles and modules usermode callbacks (ObRegisterCallbacks & PsSet***NotifyRoutine)
  • Minifilter with usermode callbacks
  • PDB parsing
  • Signatures and patterns scanning
  • Sections management (to map \\Device\PhysicalMemory and more)
  • Python binding

In development and plans:

  • Qt-based GUI for the kernel-hacking and memory researching framework
  • Kernel WinSock support
  • Extensions for the RTL: hooks, injections, disassembling
  • Kernel loadable modules with SEH support

Driver template has full support of C++ static and global initializers and all of C++20 features (without C++ exceptions). All of API modules are easy-to-use and have no external dependiencies, so you can include them to your own C++ drivers. All of API functions are grouped into a logical categories into namespaces, so you can quickly find all functions you want.

💦 Driver template has:

  • Support of METHOD_BUFFERED, METHOD_IN/OUT_DIRECT and METHOD_NEITHER
  • Minifilter loading and filtering routines templates
  • SAL-annotations and self-documented API
  • Ready-to-use IOCTLs handling routine
  • Out-of-box STL support
  • Static Driver Verifier tests passing

💨 Building and using:

Download Microsoft Visual Studio Community and Windows Driver Kit.
For driver testing use VMware Player.
For load an unsigned drivers you should to enable Test-mode of Windows and disable signs checkings:

- Disable signatures checkings (allow to install unsigned drivers):
bcdedit.exe /set loadoptions DISABLE_INTEGRITY_CHECKS
bcdedit.exe /set TESTSIGNING ON

- Enable signatures checkings (deny to install unsigned drivers):
bcdedit.exe /set loadoptions ENABLE_INTEGRITY_CHECKS
bcdedit.exe /set TESTSIGNING OFF

- Enable support of kernel debugger (WinDbg and Kernel Debugger from WDK):
bcdedit.exe /debug on   -  enable support of kernel debugging
bcdedit.exe /debug off  -  disable it

Communication with usermode apps:

For communication with usermode you should use "User-Bridge" wrappers as standalone *.cpp/*.h modules or as *.dll.
All required headers are WdkTypes.h, CtlTypes.h and User-Bridge.h. For using an extended features like minifilter callbacks, you should also use FltTypes.h, CommPort.h and Flt-Bridge.h. Some of ready-to-use RTL-functions (like an unsigned drivers mapping) you can find in Rtl-Bridge.h.

Files hierarchy:

/User-Bridge/API/ - usermode API and wrappers for all functions of KB
/Kernel-Bridge/API/ - standalone kernel API for using in C++ drivers
/Kernel-Bridge/Kernel-Bridge/ - driver template files
/SharedTypes/ - shared types headers required for UM and KM modules
/CommonTypes/ - common user- and kernelmode headers and types
/Python-Bridge/ - Python binding
/Kernel-Tests/ - unit-tests for UM and KM modules and common functions

Example (using of KbReadProcessMemory):

#include <Windows.h>

#include "WdkTypes.h"
#include "CtlTypes.h"
#include "User-Bridge.h"

using namespace Processes::MemoryManagement;

...

// Loading as minifilter (it allows to use extended features):
KbLoader::KbLoadAsFilter(L"N:\\Folder\\Kernel-Bridge.sys", L"260000");

constexpr int Size = 64;
UCHAR Buffer[Size] = {};
 
BOOL Status = KbReadProcessMemory(
    ProcessId,
    0x7FFF0000, // Desired address in context of ProcessId
    &Buffer,
    Size
);

KbLoader::KbUnload();
Comments
  • hardware ID for Kernel-Bridge.sys

    hardware ID for Kernel-Bridge.sys

    Hello, dear friends! I am new to the topic, so my question could be very naïve: I have successfully build the tool from sources using VS 2019, copied all necessary files to a remote computer, installed the certificate and now trying to install the driver itself there, using DEVCON. "devcon install Kernel-Bridge.inf hardware ID ?" What is hardware ID, which I need to use? Thanks a lot in advance! Your help is greatly appreciated!

    opened by PavelKotov1 10
  • ERROR_NOT_LOCKED error on KbReadProcessMemory

    ERROR_NOT_LOCKED error on KbReadProcessMemory

    Hey there,

    KbReadProcessMemory fails with 158 error (ERROR_NOT_LOCKED). Driver loads without any errors. For my project I use "User-Bridge" wrappers as standalone .cpp/.h modules. Driver version: v1.19

    BOOL status = KbReadProcessMemory(
    	GetPidByName(L"process.exe"),
    	Address,
    	&buf,
    	size
    );
    
    if (status == 0) {
    	cout << GetLastError() << endl;
    }
    

    Any ideas how could be this fixed?

    invalid 
    opened by klinyecviktor 7
  • How to fix KbLdrStatus::KbLdrImportNotResolved at MapDriverFile?

    How to fix KbLdrStatus::KbLdrImportNotResolved at MapDriverFile?

    Mapping any driver even the simplest.

    auto test = KbRtl::KbRtlMapDriverFile(L"C:\\dummy.sys", L"KBFM"); fmt::print("test {0} ", test);

    Produces KbLdrImportNotResolved can someone provide me a dummy driver example or explain to me what this error means and how to fix it?

    #include <ntddk.h>
    
    
    extern "C" DRIVER_INITIALIZE DriverEntry;
    
    
    namespace {
        UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\KBFM");
        UNICODE_STRING DeviceLink = RTL_CONSTANT_STRING(L"\\??\\KBFM");
        PDEVICE_OBJECT DeviceInstance = NULL;
    }
    
    #define IO_INCREMENT_VALUE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0001, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
    #define IO_RECEIVE_RANDOM_BUFFER CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0002, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
    EXTERN_C_START
    
    
    
    static NTSTATUS IoControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
    
    static NTSTATUS UnloadDriver(PDRIVER_OBJECT DriverObject);
    
    static NTSTATUS CreateCall(PDEVICE_OBJECT DeviceObject, PIRP irp);
    
    static NTSTATUS CloseCall(PDEVICE_OBJECT DeviceObject, PIRP irp);
    EXTERN_C_END
    
    extern "C" NTSTATUS NTAPI DriverEntry(
        _In_ PDRIVER_OBJECT DriverObject,
        _In_ PUNICODE_STRING RegistryPath
    ) {
        UNREFERENCED_PARAMETER(RegistryPath);
        NTSTATUS Status = IoCreateDevice(DriverObject, 0, &DeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &DeviceInstance);
    
        if (!NT_SUCCESS(Status)) {
            KdPrint(("[KBFM]: IoCreateDevice Error!\r\n"));
            return Status;
        }
    
        Status = IoCreateSymbolicLink(&DeviceLink, &DeviceName);
    
        if (!NT_SUCCESS(Status)) {
            KdPrint(("[KBFM]: IoCreateSymbolicLink Error!\r\n"));
            IoDeleteDevice(DeviceInstance);
            return Status;
        }
    
    
        DriverObject->MajorFunction[IRP_MJ_CREATE] = CreateCall;
        DriverObject->MajorFunction[IRP_MJ_CLOSE] = CloseCall;
        DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IoControl;
        DriverObject->DriverUnload = reinterpret_cast<PDRIVER_UNLOAD>(UnloadDriver);
    
    	
        return STATUS_SUCCESS;
    }
    
    
    
    static NTSTATUS UnloadDriver(PDRIVER_OBJECT DriverObject)
    {
        KdPrint(("[KBFM]: Unload routne called!\r\n"));
        IoDeleteSymbolicLink(&DeviceLink);
        IoDeleteDevice(DriverObject->DeviceObject);
        return STATUS_SUCCESS;
    }
    
    
    static NTSTATUS CreateCall(PDEVICE_OBJECT DeviceObject, PIRP irp)
    {
        UNREFERENCED_PARAMETER(DeviceObject);
        KdPrint(("[KBFM]: Create called!\r\n"));
        irp->IoStatus.Status = STATUS_SUCCESS;
        irp->IoStatus.Information = 0;
    
        IoCompleteRequest(irp, IO_NO_INCREMENT);
        return STATUS_SUCCESS;
    }
    
    static NTSTATUS CloseCall(PDEVICE_OBJECT DeviceObject, PIRP irp)
    {
        UNREFERENCED_PARAMETER(DeviceObject);
        KdPrint(("[KBFM]: Closecall called!\r\n"));
        irp->IoStatus.Status = STATUS_SUCCESS;
        irp->IoStatus.Information = 0;
    
        IoCompleteRequest(irp, IO_NO_INCREMENT);
        return STATUS_SUCCESS;
    }
    
    
    static NTSTATUS IoControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
    {
        UNREFERENCED_PARAMETER(DeviceObject);
        NTSTATUS Status = STATUS_INVALID_PARAMETER;
        ULONG BytesIO = 0;
    
        const IO_STACK_LOCATION stack = *IoGetCurrentIrpStackLocation(Irp);
        const ULONG ControlCode = stack.Parameters.DeviceIoControl.IoControlCode;
    
        if (ControlCode == IO_INCREMENT_VALUE)
        {
    
    
        }
        else if (ControlCode == IO_RECEIVE_RANDOM_BUFFER)
        {
    
        }
    
        // Complete the request
        Irp->IoStatus.Status = Status;
        Irp->IoStatus.Information = BytesIO;
        IoCompleteRequest(Irp, IO_NO_INCREMENT);
    
        return Status;
    }
    
    opened by vajos 5
  • C++ exception handling is not supported with /kernel

    C++ exception handling is not supported with /kernel

    Trying to include "CppSupport.h" from your project, but these errors occur:

    Severity	Code	Description	Project	File	Line	Suppression State
    Error	C2980	C++ exception handling is not supported with /kernel	MyDriver1	C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\km\crt\exception	72	
    Error	C2146	syntax error: missing ';' before identifier '_Raise_handler'	MyDriver1	C:\Sources\My\MyDriver1\MyDriver1\CppSupport.cpp	227	
    Error	C2980	C++ exception handling is not supported with /kernel	MyDriver1	C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\km\crt\exception	72	
    

    It shows and error at the following code:

    _Prhand _Raise_handler = &RaiseHandler;
    

    Could you help me, please, how to solve these errors?

    opened by AndyWatterman 4
  • building Reading process memory project

    building Reading process memory project

    3 errors preventing me from building Reading process memory

    #include <Windows.h> #include "WdkTypes.h" #include "CtlTypes.h" #include "User-Bridge.h" int main() { using namespace KbLoader; // Unloading previous loaded instance: KbUnload(); BOOL Status = KbLoadAsFilter( L"C:\Users\Admin\Downloads\Kernel-Bridge\x64\Release\Kernel-Bridge.sys", L"260000" // Altitude of minifilter ); if (!Status) return 0; // Unable to load driver! // Successfully loaded! // Now you can use the User-Bridge API! KbUnload(); return 0; }

    Error LNK2001 unresolved external symbol "int __cdecl KbLoader::KbLoadAsFilter(wchar_t const *,wchar_t const *)" ([email protected]@@[email protected]) MyProject C:\Users\Admin\Downloads\Kernel-Bridge-master\MyProject\MyProject.obj 1

    Error LNK2001 unresolved external symbol "int __cdecl KbLoader::KbUnload(void)" ([email protected]@@YAHXZ) MyProject C:\Users\Admin\Downloads\Kernel-Bridge-master\MyProject\MyProject.obj 1

    Error LNK1120 2 unresolved externals MyProject C:\Users\Admin\Downloads\Kernel-Bridge-master\x64\Release\MyProject.exe 1

    invalid 
    opened by qazxsw1597532018 3
  • how to find the process name or id which causes the VM EXIT in hypervisor mode

    how to find the process name or id which causes the VM EXIT in hypervisor mode

    Hello,

    I'm working on the hypervisor to add more functionality to it. I've now added a dynamic buffer to change the result of CPUID instruction in hypervisor mode. now I want to detect which process caused a VM EXIT regardless of the exit reason.

    psGetCurrentProcess() doesn't work;

    opened by danyhm 2
  • How to use the hypervisor to change the CPUID values?

    How to use the hypervisor to change the CPUID values?

    Hello,

    I've looked at the hypervisor API, however, It only starts and stops the virtualization. How is it possible to catch a CPUID instruction while the hypervisor is running and change the result values? is this possible with the API or source code change is needed?

    opened by danyhm 2
  • Unable to load driver!

    Unable to load driver!

    Hey,

    if I run the test I always get the message "Unable to load driver!". I adjusted the path for the kernel-bridge.sys but the issue still persists?

    Am I doing sth wrong?

    Best regards!

    opened by Johannes-Juengst 2
  • KbFindSignature Failing

    KbFindSignature Failing

    There are some memory regions where this function seems to fail (returns 0), whereas other memory regions seem to work fine. Any idea as to why this is happening or if there is a possible fix?

    The same memory regions that KbFindSignature fails on KbReadProcessMemory also fails.

    opened by SoftCrush 1
  • BSOD in DriverControl

    BSOD in DriverControl

    I tried to load the driver as a filter, and immediately got a blue screen, from some debugging, I found the bug in the DriverControl function, in line 311:

     IoCompleteRequest(Irp, IO_NO_INCREMENT);
     return Irp->IoStatus.Status;
    

    The Irp variable is used after IoCompleteRequest, which should not be done (according to google)

    opened by Eran-YT 1
  • Not initialized request variable

    Not initialized request variable

    https://github.com/HoShiMin/Kernel-Bridge/blob/master/User-Bridge/API/User-Bridge.cpp#L507 https://github.com/HoShiMin/Kernel-Bridge/blob/master/User-Bridge/API/User-Bridge.cpp#L565

    KbMapMdl and KbMapMemory funcs have UserRequestedAddress arg, but it is not passed to KB_MAP_MDL_IN Input struct.

    opened by boris768 1
  • how to intercept KUSER_SHARED_DATA using Hypervisor?

    how to intercept KUSER_SHARED_DATA using Hypervisor?

    Hello @HoShiMin Can you please guide me on how to intercept KUSER_SHARED_DATA using the hypervisor? I know it's possible using EPT but I just don't know how to do it using KbVmmInterceptPage Thanks

    opened by danyhm 0
  • Compiler crash in 'VMX.h'

    Compiler crash in 'VMX.h'

    This code crash compiler:

    enum VMCS_FIELD_ENCODING : decltype(VMCS_COMPONENT_ENCODING::Value) {
    

    with error:

    3>C:\Sources\Kernel-Bridge\CommonTypes\VMX.h(266,6): fatal  error C1001: Internal compiler error.
    3>(compiler file 'msc1.cpp', line 1576)
    3> To work around this problem, try simplifying or changing the program near the locations listed above.
    3>If possible please provide a repro here: https://developercommunity.visualstudio.com
    3>Please choose the Technical Support command on the Visual C++
    3> Help menu, or open the Technical Support help file for more information (compiling source file API\Hypervisor.cpp)
    3>INTERNAL COMPILER ERROR in 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX64\x64\CL.exe'
    3>    Please choose the Technical Support command on the Visual C++
    3>    Help menu, or open the Technical Support help file for more information
    3>KernelShells.cpp
    3>cl : command line  error D8040: error creating or communicating with child process
    3>Done building project "Kernel-Bridge.vcxproj" -- FAILED.
    

    Need to change:

    enum VMCS_FIELD_ENCODING : unsigned int {
    

    I use Visual Studio 2022, Windows SDK "10.0.22621.0" and appropriate WDK.

    opened by AndyWatterman 0
  • Fastest way to read process  memory

    Fastest way to read process memory

    While testing, I noticed reading a process memory using Kernel-Bridge is slower than a small driver I wrote. I checked and it seems KB is mapping MDLs and then copies the memory. While all I need is using a Method_Out_Direct to get a kernel-address space buffer and attach to target process stack, Copy memory and detach. I wonder if such a thing or something close is possible in KB?

    opened by behzad62 9
  • Windows on ARM, Support?

    Windows on ARM, Support?

    Please let us know when can we have an ARM64 version for Windows on ARM OS. We can help you test We have Windows on Rasberry Pi setup. Please pursue it we at Windows on Rasberry Pi community will be glad to extend support in testing your drivers and tools for ARM64.

    enhancement 
    opened by sidd-kishan 1
  • Winsock support help...

    Winsock support help...

    Hi , you can use https://github.com/wbenny/KSOCKET KSOCKET is windows kernel socket. Its very easy to use.You can implement it. But there is no usermode to use it.Its kernel only. Just needs some wrapper. Maybe you can do it in Kernel-Bridge

    Also checkout for Linux version: https://github.com/hbagdi/ksocket

    opened by eix128 1
Releases(v1.19.3)
Owner
Александр
Александр
The goal of arrowvctrs is to wrap the Arrow Data C API and Arrow Stream C API to provide lightweight Arrow support for R packages

The goal of arrowvctrs is to wrap the Arrow Data C API and Arrow Stream C API to provide lightweight Arrow support for R packages to consume and produce streams of data in Arrow format. Right now it’s just a fun way for me to learn about Arrow!

Dewey Dunnington 30 Aug 5, 2022
A simple Windows kernel rootkit.

Venom RootKit A simple windows rootkit that I have wrote, In order to explore a bit about the world of rootkits and windows kernel in general. The Ven

Amit Schendel 64 Oct 9, 2022
Sorting routine implementations in "template" C

sort.h Overview sort.h is an implementation of a ton of sorting algorithms in C with a user-defined type that is provided at include time. This means

Christopher Swenson 402 Nov 26, 2022
A Template Engine for Modern C++

Inja is a template engine for modern C++, loosely inspired by jinja for python. It has an easy and yet powerful template syntax with all variables, lo

pantor 1.2k Jan 8, 2023
A universal type for non-type template parameters for C++20 or later.

uninttp A universal type for non-type template parameters for C++20 or later. Installation: uninttp (Universal Non-Type Template Parameters) is a head

null 16 Dec 24, 2021
ARCHIVED - libbson has moved to https://github.com/mongodb/mongo-c-driver/tree/master/src/libbson

libbson ARCHIVED - libbson is now maintained in a subdirectory of the libmongoc project: https://github.com/mongodb/mongo-c-driver/tree/master/src/lib

mongodb 344 Nov 29, 2022
A LKM rootkit targeting 4.x and 5.x kernel versions which opens a backdoor that can be used to spawn a reverse shell to a remote host and more.

Umbra Umbra (/ˈʌmbrə/) is an experimental LKM rootkit for kernels 4.x and 5.x (up to 5.7) which opens a network backdoor that spawns reverse shells to

Marcos S. Bajo 93 Dec 10, 2022
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.

Microsoft 7.2k Jan 2, 2023
UClamp backports and custom tunings for different kernel versions/devices

Linux kernel ============ This file was moved to Documentation/admin-guide/README.rst Please notice that there are several guides for kernel develop

null 25 Jan 14, 2022
Unofficial C++ beta SDK for the top.gg API.

topgg-cpp-sdk (Beta) Unofficial C++11 beta SDK for the top.gg API. Please note that the library is currently not completed yet! Requirements: libcurl

7 Nov 16, 2021
The Sandboxed API project (SAPI) Generates sandboxes for C/C++ libraries automatically

The Sandboxed API project (SAPI) makes sandboxing of C/C++ libraries less burdensome: after initial setup of security policies and generation of library interfaces, a stub API is generated, transparently forwarding calls using a custom RPC layer to the real library running inside a sandboxed environment.

Google 1.6k Dec 28, 2022
A WIP "Vulnerable by Design" kext for iOS/macOS to play & learn *OS kernel exploitation

Vulnerable Kext A WIP (work-in progress) "Vulnerable by Design" kext for iOS/macOS to play/learn with *OS kernel exploitation Usage Documentation can

Chaithu 221 Dec 11, 2022
Linux Kernel module-less implant (backdoor)

0 KOPYCAT - Linux Kernel module-less implant (backdoor) Usage $ make $ sudo insmod kopycat.ko insmod: ERROR: could not insert module kopycat.ko: Inapp

Ilya V. Matveychikov 52 Dec 28, 2022
Quick check of NT kernel exported&unexported functions/global variable offset

NT内核导出以及未导出函数-全局变量偏移速查 Quick check of NT kernel exported&unexported functions/global variable offset System目录下有已经完成的偏移 可以在线速查 There are already comple

不想加班劉 71 Dec 29, 2022
Remote Download and Memory Execute for shellcode framework

RmExecute Remote Download and Memory Execute for shellcode framework 远程下载并内存加载的ShellCode框架,暂不支持X64 参(抄)考(袭)项目 windows下shellcode提取模板的实现 主要抄袭来源,直接使用这位大佬

null 52 Dec 25, 2022
Edf is an event-driven framework for embedded system (e.g. FreeRTOS) with state machine and subscriber-publisher pattern.

Edf means event-driven framework. Event-driven programming is a common pattern in embedded systems. However, if you develop software directly on top o

Arrow89 7 Oct 16, 2022
the checkra1n set of tools targeting bare metal, Linux and Windows

Universal toolchain Low-effort cross-compiling for the masses. What's Universal toolchain? It's a collection of sysroots and shell scripts in such a w

null 67 Jan 5, 2023
Orbit, the Open Runtime Binary Instrumentation Tool, is a standalone C/C++ profiler for Windows and Linux

Orbit, the Open Runtime Binary Instrumentation Tool, is a standalone C/C++ profiler for Windows and Linux. Its main purpose is to help developers visualize the execution flow of a complex application.

Google 3k Dec 30, 2022
AlleyWind is an advanced Win32-based and open-sourced utility that helps you to manage system's windows

AlleyWind AlleyWind is an advanced Win32-based and open-sourced utility that helps you to manage system's windows. AlleyWind could: Displays a graphic

KNSoft 22 Oct 20, 2022