Kernel-mode multi-surface state introspection and emulation architecture for Windows x64 platforms.
Hardware and operating system integrity validation mechanisms verify UEFI Secure Boot state across multiple disconnected kernel and user-accessible boundaries. Simplistic emulation approaches that modify solely the system registry succeed under cursory inspections but fail when subjected to cross-validation via Windows Management Instrumentation (WMI), PowerShell hardware cmdlets (Confirm-SecureBootUEFI), or direct runtime EFI environment variable queries. Discrepancies between these layers immediately expose state inconsistencies.
This framework implements an atomic four-surface state synchronization model within the Windows kernel (ntoskrnl.exe), aligning all independent query interfaces without triggering Kernel Patch Protection (PatchGuard) or leaving persistent driver objects in system telemetry tables.
- Target Architecture: x86_64
- Operating Systems: Windows 10 / 11 (NT Kernel builds 10.0.19041 through 10.0.22631+)
- Execution Context: Kernel Ring 0 (Designed for manual mapping via signed vulnerable driver loaders, e.g.,
kdmapper) - Key Subsystems:
- Configuration Manager Registry Subsystem (
ZwSetValueKey) - Shared User Data Aperture (
KUSER_SHARED_DATAat0xFFFFF78000000000) - System Information Dispatcher (
ExpQuerySystemInformation/SeSecureBootQueryInformation) - Firmware Environment Variable Service (
NtQuerySystemEnvironmentValueEx)
- Configuration Manager Registry Subsystem (
+-----------------------+--------------------------+-----------------------+------------------------------------------+
| Subsystem Surface | Memory Location / Path | Type / Size | Emulated Value / Target State |
+-----------------------+--------------------------+-----------------------+------------------------------------------+
| Registry State | HKLM\...\SecureBoot\State| REG_DWORD (4 Bytes) | UEFISecureBootEnabled = 1 |
| | | REG_DWORD (4 Bytes) | SecureBootCapable = 1 |
| KUSER_SHARED_DATA | 0xFFFFF780000002EC | BOOLEAN (1 Byte) | DbgSecureBootEnabled = 1 |
| System Information | RIP-relative .data ptr | UINT32 (4 Bytes) | Bit 0 (Enabled) = 1, Bit 3 (Capable) = 1 |
| EFI Variable: SecureBoot| NtQuerySysEnvValEx Detour| UINT8 (1 Byte) | 0x01 (EFI_GLOBAL_VARIABLE_GUID) |
| EFI Variable: SetupMode | NtQuerySysEnvValEx Detour| UINT8 (1 Byte) | 0x00 (User Mode / PK Enrolled) |
| EFI Variable: AuditMode | NtQuerySysEnvValEx Detour| UINT8 (1 Byte) | 0x00 (Audit Mode Inactive) |
| EFI Variable: DeployedMode| NtQuerySysEnvValEx Detour| UINT8 (1 Byte) | 0x01 (Deployed State Active) |
| EFI Variable: CustomEnable| NtQuerySysEnvValEx Detour| UINT8 (1 Byte) | 0x01 (Vendor-Specific Enable Active) |
+-----------------------+--------------------------+-----------------------+------------------------------------------+
Registry validation is enforced under:
\Registry\Machine\SYSTEM\CurrentControlSet\Control\SecureBoot\State
Values written:
UEFISecureBootEnabled(REG_DWORD= 1)SecureBootCapable(REG_DWORD= 1)
Modifications are executed directly via ZwCreateKey and ZwSetValueKey during driver initialization. The implementation avoids registering registry callback routines (CmRegisterCallbackEx), preventing forensic enumeration of filter driver tracking structures.
User-mode processes can inspect the Secure Boot debugging flag without executing a system call by directly reading 0x7FFE02EC (PKUSER_SHARED_DATA->DbgSecureBootEnabled).
Because user-mode access to this page is marked read-only, write access is performed via the permanent kernel-mode read/write alias mapped by the memory manager at:
0xFFFFF780000002EC
Writing directly to this kernel virtual address synchronizes the state across all process contexts with zero overhead.
Administrative query utilities, including the PowerShell Confirm-SecureBootUEFI cmdlet and WMI providers (Win32_SecureBoot), query NtQuerySystemInformation with information class 145 (SystemSecureBootInformation).
Execution flow:
ExpQuerySystemInformationdispatches class 145 toSeSecureBootQueryInformation.SeSecureBootQueryInformationaccesses an unexported kernel global variable (e.g.,dword_140C5467Cin representative 22H2 builds).- Bit 0 controls
SecureBootEnabled; Bit 3 controlsSecureBootCapable. - The memory address of this global is resolved at runtime via a RIP-relative pattern scan of
SeSecureBootQueryInformation. - An atomic bitwise OR (
InterlockedOr) sets bits 0 and 3 (0x09). Because this variable resides in the.datasection ofntoskrnl.exe, modifications do not trigger Kernel Patch Protection (PatchGuard).
Low-level anti-cheat engines and hardware profiling utilities circumvent high-level system APIs by issuing direct queries against UEFI runtime variables.
NtQuerySystemEnvironmentValueEx is unexported in the ntoskrnl.exe export table (MmGetSystemRoutineAddress returns NULL). The routine is located using a multi-version prologue signature and hooked using an MDL-backed 12-byte absolute detour:
mov rax, TargetHookAddress ; 48 B8 [64-bit absolute address]
jmp rax ; FF E0
The hook handles five critical variables via table-driven matching:
SecureBoot(EFI_GLOBAL_VARIABLE_GUID): Returns1.SetupMode(EFI_GLOBAL_VARIABLE_GUID): Returns0. When Secure Boot is disabled in physical firmware, UEFI defaults to Setup Mode (Platform Key not enrolled) whereSetupModereturns1. Anti-cheat engines querySetupModeimmediately afterSecureBoot; returning1for both creates an immediate logical contradiction. EmulatingSetupMode = 0guarantees consistency.AuditMode(EFI_GLOBAL_VARIABLE_GUID): Returns0.DeployedMode(EFI_GLOBAL_VARIABLE_GUID): Returns1.SecureBootEnable(EFI_CUSTOM_SECURE_BOOT_GUID): Returns1.
All unhandled variable queries are redirected to an allocated executable trampoline preserving the original prologue instructions and jumping back to the target function offset.
Repeated driver injection without an intermediate system reboot risks corrupting the inline hook chain. If mapped a second time:
- The signature scanner locates the target function.
- The prologue already contains bytes
0x48 0xB8from the previous detour. - The newly generated trampoline saves the previous detour bytes instead of original kernel instructions, causing cyclic branch faults or
KMODE_EXCEPTION_NOT_HANDLEDbugchecks.
To eliminate this condition, the initialization sequence incorporates a dual-phase guard:
- Guard 1: Checks if bits 0 and 3 are already active in the Class 145 global variable.
- Guard 2: Checks whether bytes 0-1 of
NtQuerySystemEnvironmentValueExequal0x48 0xB8.
If either guard detects previous instrumentation, the driver gracefully bypasses detour installation and exits safely.
Queries for SystemCodeIntegrityInformation (information class 103) resolve to internal code integrity flags inside ci.dll via a Control Flow Guard (CFG) protected dispatch routine. Under standard manual mapping environments where the operating system has not enabled test-signing (bcdedit /set testsigning on) or connected a kernel debugger, Code Integrity flags already reflect fully validated production status (CODEINTEGRITY_OPTION_ENABLED). Consequently, patching class 103 is non-essential and deliberately omitted to minimize memory footprint.
.
├── include/
│ ├── common.h # Logging macros, status helpers, and driver tag
│ ├── efi_variable.h # EFI GUIDs, variable attributes, and hook definitions
│ ├── memory.h # MDL page remapping, relative resolution, and scanning
│ ├── ntdef.h # Undocumented NT structures and system information classes
│ ├── registry.h # Kernel registry manipulation interfaces
│ ├── secureboot_emulation.h # High-level orchestrator interface
│ └── sysinfo.h # SystemSecureBootInformation class 145 contracts
├── src/
│ ├── driver_entry.c # DriverEntry and orchestration dispatch
│ ├── efi_variable.c # Signature lookup, MDL detour, and table emulation
│ ├── memory.c # Pattern search and MDL-backed safe memory write
│ ├── registry.c # ZwSetValueKey state synchronization
│ ├── shared_data.c # KUSER_SHARED_DATA kernel alias manipulation
│ └── sysinfo.c # Class 145 signature resolution and atomic bitwise patch
├── .gitignore # WDK / Visual Studio build artifact exclusions
├── LICENSE # MIT License (Adam 2026)
├── README.md # Technical specifications and architecture documentation
├── SecureBoot.sln # Visual Studio 2022 solution
├── SecureBoot.vcxproj # WDK driver project definition
└── SecureBoot.vcxproj.filters # Solution filter hierarchy
- Compiler: Visual Studio 2022 (MSVC v143) with Windows Driver Kit (WDK) 10.0.22621+
- Platform: x64 (Native 64-bit)
- Configuration: Release (
/O2optimization,/GS-buffer security checks disabled where appropriate for manual mapping)
# Build driver via MSBuild
msbuild SecureBoot.sln /p:Configuration=Release /p:Platform=x64This repository is published strictly for educational, security research, and operating system reverse-engineering purposes. It demonstrates kernel-mode memory manipulation, MDL-backed instruction modification, and system integrity verification architecture on the Windows operating system.