SlideShare a Scribd company logo
1 of 121
Exploiting LOLDrivers (part1)
Physical Memory Mayhem
Russell Sanford
xort @ sploit.online
About me…
LOLDriver Exploitation
Physical Memory Mayhem
About me…
Russell Sanford
• 25 Years experience in writing exploits and reverse engineering
• Published exploit author with dozens of CVE’s in network security appliances
• 12+ years experience in penetration testing and red teaming
LOLDriver Exploitation
Physical Memory Mayhem
What are LOLDrivers ?
LOLDriver Exploitation
Physical Memory Mayhem
Living Off The Land (LOTL)
Living off the land (LOTL) is a fileless malware or LOLbins cyberattack
technique where the cybercriminal uses native, legitimate tools within
the victim’s system to sustain and advance an attack.
Living Off The Land Drivers (LOLDrivers) is a community-driven project
that provides a curated list of all Windows drivers that have been
found abused by adversaries to bypass security controls and execute
malicious code.
LOLDriver Exploitation
Physical Memory Mayhem
www.loldrivers.io
LOLDriver Exploitation
Physical Memory Mayhem
www.loldrivers.io
•List of multiple different versions of drivers known to be
vulnerable to attacks
•Information on Microsoft Blocked Driver Listing
•Hashes, Resource Links, YARA Rules, and Vulnerable API
used
LOLDriver Exploitation
Physical Memory Mayhem
Where/How this all began…
LOLDriver Exploitation
Physical Memory Mayhem
How I got started on this subject
• Microsoft finally got around to implementing mitigations to stop people from utilizing
Kdmapper
• Red Teaming friend asked me if I could look into writing a new replacement unsigned
driver mapper utilizing known LOLDrivers for testing EDR/XDR solutions
• I Quickly learned that there was only limited relevant and up-to-date information to be
learned from the Penetration Testing/Red Teaming communities
• Exploiting these types of vulnerabilities was largely pioneered by members of the gaming
communities
LOLDriver Exploitation
Physical Memory Mayhem
Let’s Begin… :D
LOLDriver Exploitation
Physical Memory Mayhem
Warning!
The exploitation tricks your going to see are not
being used in ANY public exploits I could find.
LOLDriver Exploitation
Physical Memory Mayhem
Getting Setup
LOLDriver Exploitation
Physical Memory Mayhem
Enabling DbgPrint Messages from the Windows Kernel
Go to path,
• “HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerDebug Print Filter”.
• If "Debug Print Filter" is not present then create it.
• Add value “DEFAULT” : REG_DWORD : 0xFFFFFFFF and then reboot.
LOLDriver Exploitation
Physical Memory Mayhem
Getting Setup For Visual Studio Driver Development
LOLDriver Exploitation
Physical Memory Mayhem
Getting Setup for Visual Studio Driver Development
LOLDriver Exploitation
Physical Memory Mayhem
Getting Setup for Visual Studio Driver Development
LOLDriver Exploitation
Physical Memory Mayhem
Setting up Windows Kernel Debugging over Serial
LOLDriver Exploitation
Physical Memory Mayhem
Setting Up VMWare – Adding a Serial Port for kernel debugging
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
Configuring WinDBG
VMWare
Serial Port
(Named
Pipe)
LOLDriver Exploitation
Physical Memory Mayhem
• Configuring VMware
Setting Up WinDBG for Remote Serial Debugging
LOLDriver Exploitation
Physical Memory Mayhem
How Communication with System Drivers works
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
• Communicating with SYSTEM Drivers – IOCTL calls
Userland (Ring3) <-> Kernel Land (Ring 0) communication - IOCTL
LOLDriver Exploitation
Physical Memory Mayhem
Userland (Ring3) <-> Kernel Land (Ring 0) communication – IOCTL
1) A handle is opened to
A device driver’s Symbolic
Name
2) IOCTL Request is made
With Input and Output
Buffers using handle
3) Kernel Driver returns
Response in Output buffer
4) When all communication has ended
Handle to driver is closed
LOLDriver Exploitation
Physical Memory Mayhem
Userland (Ring3) <-> Kernel Land (Ring 0) communication – IOCTL
Example:
HANDLE Handle = CreateFile(".IOCTL", ..., 0, NULL);
DWORD version, junk;
if (DeviceIoControl(Handle, IOCTL_GET_VERSION_BUFFERED,
NULL, 0, &version, sizeof(version), &junk, NULL))
printf("IOCTL.SYS version %d.%2dn", HIWORD(version),
LOWORD(version));
else
printf("Error %d in IOCTL_GET_VERSION_BUFFERED calln",
GetLastError());
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
Communicating with SYSTEM Drivers – IOCTL calls
1) A HANDLE is
opened to the
Driver
LOLDriver Exploitation
Physical Memory Mayhem
Communicating with SYSTEM Drivers – IOCTL calls
1) A HANDLE is
opened to
the Driver
2) A Request is
made to the
Driver using
an IOCTL call
LOLDriver Exploitation
Physical Memory Mayhem
Communicating with SYSTEM Drivers – IOCTL calls
1) A HANDLE is
opened to
the Driver
2) A Request is
made to the
Driver using
an IOCTL call
3) When all communications are done
The HANDLE to the Driver is closed.
LOLDriver Exploitation
Physical Memory Mayhem
Communicating with SYSTEM Drivers – IOCTL calls
INPUT Buffer / Buffer Size
Request from USERLAND to KERNELAND Driver
LOLDriver Exploitation
Physical Memory Mayhem
Communicating with SYSTEM Drivers – IOCTL calls
OUTPUT Buffer / Buffer Size
Response from KERNELAND Driver to USERLAND
Exploited Windows API Functions Providing
Access to Physical Memory
LOLDriver Exploitation
Physical Memory Mayhem
Common Vulnerable API
Access to Physical Memory PCI Device Access
MmMapIOSpace() HalGetBusDataByOffset()
ZwMapViewOfSection() HalSetBusDataByOffset()
<- in/out port communication ->
Physical Memory Address Resolving Memory Copying Operations
memcpy()
MSR Register Access memmove()
__readmsr()/__writemsr()
And Much More!
LOLDriver Exploitation
Physical Memory Mayhem
Common Vulnerable API
This presentation is my analysis of what could be done using the commonly
found API allowing for: Access to Physical Memory
• MmMapIOSpace()
• ZwMapViewOfSection()
* Note: There are several sub-variants of these functions that do/do-not allow
access to cached and/or locked operations
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
MmMapIoSpace()
LOLDriver Exploitation
Physical Memory Mayhem
MmMapIoSpace()
Note: Microsoft has blocked MmMapIoSpace() from being able to access page
tables directly. This can be circumvented by using MmMapIoSpace() in a provider-
>victim model in which shellcode is introduced into another driver fully capable of
accessing these blocked regions of code – staging 101.
LOLDriver Exploitation
Physical Memory Mayhem
ZwMapViewOfSection()
ZwMapViewOfSection()
LOLDriver Exploitation
Physical Memory Mayhem
Creates a “View” of a section
View can be mapped to ANY location in
memory
Can be READ only, READ|WRITE, or WRITE
only
Write operations will update address
pointed TO when WRITE is enabled
Some Drivers offer Phsical Addressing to Virtual Addressing or
vice-versa
IOCTL calls are sometime offered to implement:
• VA->PA ( calls MmGetPhysicalAddress() )
• VA->Pfn or VA-Pte (Page Frame Number / Page Table Entry)
LOLDriver Exploitation
Physical Memory Mayhem
Vulnerable Libraries Facilitating Exploitation
LOLDriver Exploitation
Physical Memory Mayhem
Known Vulnerable Libraries with Exploitation Primitives
• WinIO
• MAPMEM
• PHYMEM
• RWEverything
• WINRING0
LOLDriver Exploitation
Physical Memory Mayhem
WINIO was found to be the more popularly re-used
library and so the exploitation used/demonstrated in
this presentation will be focused on abusing it.
Culprit Drivers – ‘Providers’
Many of the vulnerable LOLDrivers fall into the tools that provide the following functionalities:
Bios flashing
Gaming Tuning
RGB Keyboard utilities
Core Temperature Controllers
Diagnostic Tools
Forensic Tools
GPU utilities
Performance Tools
Mimikatz
Rootkit Detection Utilities
Process Exploring Tools
LOLDriver Exploitation
Physical Memory Mayhem
Unsigned Driver Mappers Exploiting these APIs
LOLDriver Exploitation
Physical Memory Mayhem
Public Tools for unsigned driver loading
KDU (hfiref0x) GDRV-loader (alxbrn)
Voidmap (SamuelTulach) DSEFix (hfiref0x)
Kdmapper (TheCruz/z175) physmeme
TDL (hfiref0x)
Nasa mapper (xeroxz) many more….
Efi-mapper (SamuelTulach) http://www.unknowncheats.me
LOLDriver Exploitation
Physical Memory Mayhem
Resources:
LOLDrivers.com
Massive collection of
Drivers utilizing
Exploitable API
Gaming Forums!
Unknown Cheats
By far best source
Of information
On exploitation
Of LOLDrivers
LOLDriver Exploitation
Physical Memory Mayhem
https://www.unknowncheats.me/
Blacklisted Drivers
LOLDriver Exploitation
Physical Memory Mayhem
Dealing with revoked cert drivers…
We can disable the Driver Blocklist and
Run blocked drivers 
[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlCIConfig]
"VulnerableDriverBlocklistEnable"=dword:00000000
or
reg add HKLMSYSTEMCurrentControlSetCIConfig /v "VulnerableDriverBlocklistEnable" /t REG_DWORD /d 0
/f
LOLDriver Exploitation
Physical Memory Mayhem
Physical Memory vs Virtual Memory
LOLDriver Exploitation
Physical Memory Mayhem
Physical Memory vs Virtual Memory
LOLDriver Exploitation
Physical Memory Mayhem
Cached
Pages
Let’s start breaking down exploitation tactics…
LOLDriver Exploitation
Physical Memory Mayhem
The Kernel Pool
LOLDriver Exploitation
Physical Memory Mayhem
Welcome to the Pool Party – Kernel Pool Explained
LOLDriver Exploitation
Physical Memory Mayhem
Kernel Pool Allocation Functions:
ExAllocatePool()
ExAllocatePool2()
ExAllocatePool3()
ExAllocatePoolWithTag()
ExAllocatePoolWithQuotaTag()
ExAllocatePoolWithTagPriority()
+ more…
Kernel Pool Allocations are made with an associated ‘tag’ that is either provided
or generated depending on which API is utilized
LOLDriver Exploitation
Physical Memory Mayhem
Kernel Pool Allocation with ‘tags’:
Example Allocation with ‘abcd’ tag header:
LOLDriver Exploitation
Physical Memory Mayhem
Example Kernel Pool Allocation for Windows TOKEN with ‘tag’:
LOLDriver Exploitation
Physical Memory Mayhem
Note: There are tens of thousands of different Pool Tag’s for various Windows
Objects – Everything's got its own memory allocation tag type!
The Kernel Pool Exploitation
‘Proc’ Pool Scanning Technique
LOLDriver Exploitation
Physical Memory Mayhem
EPROCESS and the ‘Proc’ Pool Header
LOLDriver Exploitation
Physical Memory Mayhem
EPROCESS and the ‘Proc’ Pool Header – Preceeds EPROCESS structures
LOLDriver Exploitation
Physical Memory Mayhem
Kernel Memory Pools and the ‘Proc’ Pool Header…
• Pool Headers are allocated on 0x10 offsets
• The tag is located 4 bytes in
EPROCESS Structure Scanning Pseudocode:
For (i=0; I < 0x2000000; I += 0x10) {
if ( memcmp( (buffer+i+4), “Proc”) == 0 ) {
// found proc pool header – print info
}
}
LOLDriver Exploitation
Physical Memory Mayhem
Scanning for ‘Proc’ pool headers (EPROCESS structures)
LOLDriver Exploitation
Physical Memory Mayhem
DEMO!
PML4 Page Tables
LOLDriver Exploitation
Physical Memory Mayhem
Exploiting Windows Signed
Drivers for PrivEsc
LOLDriver Exploitation
Physical Memory Mayhem
4 Level Page Translation (4k page)
PML4E_Offset = (ADDR >>39) & 0x1FF
PDPE_Offset = ( ADDR >>30) & 0x1FF
PDE_Offset = (ADDR >>21) & 0x1FF
PT_OFFset (ADDR >>12) & 0x1FF
PysAddr_Offset = 0x1FFFFFFF
UINT64 PML4E = CR3 + (((address_to_lookup >> 39) & 0x1ff) * sizeof(DWORD64));
UINT64 PDPE = (read_UINT64_from_4k_page_phys_memory((PUINT64)PML4E) & 0x00FFFFFFFFFFF000) + (((address_to_lookup >> 30) & 0x1ff) *
sizeof(DWORD64));
UINT64 PDT = (read_UINT64_from_4k_page_phys_memory((PUINT64)PDPE) & 0x00FFFFFFFFFFF000) + (((address_to_lookup >> 21) & 0x1ff) *
sizeof(DWORD64));
UINT64 PT = (read_UINT64_from_4k_page_phys_memory((PUINT64)PDT) & 0x00FFFFFFFFFFF000) + (((address_to_lookup >> 12) & 0x1ff) *
sizeof(DWORD64));
final_addr_phys_ptr = (PT & 0x000FFFFFFFF00000) + (address_to_lookup & 0xFFFFF);
LOLDriver Exploitation
Physical Memory Mayhem
4 Level Page Translation (4k page)
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
HCVI / VBA Protections – Extended Page Tables
LOLDriver Exploitation
Physical Memory Mayhem
Finding Cr3’s value to walk tables
LOLDriver Exploitation
Physical Memory Mayhem
Finding Cr3 through ‘Proc’ (EPROCESS) pool scanning
LOLDriver Exploitation
Physical Memory Mayhem
Finding Cr3 through EPROCESS scanning…
• We can scan for ‘Proc’ pool headers which identify
EPROCESS structures
• The First Part of an EPROCESS structure is a KPROCESS structure
• The KPROCESS Structure contains DirectoryTableBase (CR3 register
value for process)
LOLDriver Exploitation
Physical Memory Mayhem
Finding Cr3 through the DOS “LOW STUB”
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
DEMO!
CR3 “Low Stub” trick courtesy of pcileech Direct
Memory Attack (DMA) software
Designed for cool hardware
hacking implant’s
like the PCI Squirrel
https://github.com/ufrisk/pcileech
LOLDriver Exploitation
Physical Memory Mayhem
typedef struct _PROCESSOR_START_BLOCK {
FAR_JMP_16 Jmp;
ULONG CompletionFlag;
PSEUDO_DESCRIPTOR_32 Gdt32;
PSEUDO_DESCRIPTOR_32 Idt32;
KGDTENTRY64 Gdt[PSB_GDT32_MAX + 1];
ULONG64 TiledCr3;
FAR_TARGET_32 PmTarget;
FAR_TARGET_32 LmIdentityTarget;
PVOID LmTarget;
PPROCESSOR_START_BLOCK SelfMap;
ULONG64 MsrPat;
ULONG64 MsrEFER;
KPROCESSOR_STATE ProcessorState;
} PROCESSOR_START_BLOCK;
CR3 “Low Stub” trick
The DOS “Low Stub” is the area of physical
memory between 0-0x20000
In this range, as the computer boots, a
structure called PROCESSOR_START_BLOCK
is stored in memory
It is used when resuming from ACPI Sleep
Vector amongst other things
LOLDriver Exploitation
Physical Memory Mayhem
CR3 “Low Stub” trick
The _PROCESSOR_START_BLOCK structure
has a structure named KSPECIAL_REGISTERS
KSPECIAL_REGISTERS contains the kernel’s
Cr3 value which points to the start of the
page tables
LOLDriver Exploitation
Physical Memory Mayhem
typedef struct _KPROCESSOR_STATE
{
CONTEXT ContextFrame;
KSPECIAL_REGISTERS SpecialRegisters;
} KPROCESSOR_STATE,
*PKPROCESSOR_STATE;
typedef struct _KSPECIAL_REGISTERS
{
ULONG Cr0;
ULONG Cr2;
ULONG Cr3;
ULONG Cr4;
ULONG KernelDr0;
ULONG KernelDr1;
ULONG KernelDr2;
ULONG KernelDr3;
ULONG KernelDr6;
ULONG KernelDr7;
DESCRIPTOR Gdtr;
DESCRIPTOR Idtr;
WORD Tr;
WORD Ldtr;
ULONG Reserved[6];
} KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
CR3 “Low Stub” trick
LOLDriver Exploitation
Physical Memory Mayhem
__try {
while (offset < 0x100000) {
offset += 0x1000;
if (0x00000001000600E9 != (0xffffffffffff00ff & 
*(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp
continue;
if (0xfffff80000000000 != (0xfffff80000000003 & 
*(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget))))
continue;
if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset))
continue;
PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset);
break;
} }
CR3 “Low Stub” trick
LOLDriver Exploitation
Physical Memory Mayhem
__try {
while (offset < 0x100000) {
offset += 0x1000;
if (0x00000001000600E9 != (0xffffffffffff00ff & 
*(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp
continue;
if (0xfffff80000000000 != (0xfffff80000000003 & 
*(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget))))
continue;
if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset))
continue;
PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset);
break;
} }
__try {
while (offset < 0x100000) {
offset += 0x1000;
if (0x00000001000600E9 != (0xffffffffffff00ff & 
*(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp
continue;
if (0xfffff80000000000 != (0xfffff80000000003 & 
*(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget))))
continue;
if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset))
continue;
PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset);
break;
} }
CR3 “Low Stub” trick
LOLDriver Exploitation
Physical Memory Mayhem
__try {
while (offset < 0x100000) {
offset += 0x1000;
if (0x00000001000600E9 != (0xffffffffffff00ff & 
*(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp
continue;
if (0xfffff80000000000 != (0xfffff80000000003 & 
*(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK,
LmTarget))))
continue;
if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset))
continue;
PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset);
break;
} }
CR3 “Low Stub” trick
LOLDriver Exploitation
Physical Memory Mayhem
CR3 “Low Stub” trick
LOLDriver Exploitation
Physical Memory Mayhem
__try {
while (offset < 0x100000) {
offset += 0x1000;
if (0x00000001000600E9 != (0xffffffffffff00ff & 
*(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp
continue;
if (0xfffff80000000000 != (0xfffff80000000003 & 
*(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget))))
continue;
if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset))
continue;
PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset);
break;
} }
CR3 “Low Stub” trick
LOLDriver Exploitation
Physical Memory Mayhem
__try {
while (offset < 0x100000) {
offset += 0x1000;
if (0x00000001000600E9 != (0xffffffffffff00ff & 
*(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp
continue;
if (0xfffff80000000000 != (0xfffff80000000003 & 
*(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget))))
continue;
if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset))
continue;
PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset);
break;
} }
Building Block API Functions for Exploitation
Building PA to VA translation functions
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
Walking the tables to PID 4 (SYSTEM EPROCSS structure)
LOLDriver Exploitation
Physical Memory Mayhem
DEMO!
Building Block API Functions for Exploitation
Building Pfn (Page Frame Numer) lookup
functions
LOLDriver Exploitation
Physical Memory Mayhem
MiGetPteAddress – Assembly contains Hardcoded Pte Base in Memory
1) We calculate the address of MiGetPteAddress in memory
LOLDriver Exploitation
Physical Memory Mayhem
MiGetPteAddress – Assembly contains Hardcoded Pte Base in Memory
2) We Extract the QWORD value of the PFN Table Base from the function
LOLDriver Exploitation
Physical Memory Mayhem
MiGetPteAddress() – decompiled to C
( Now we can write our own PFN Table lookup routine! )
LOLDriver Exploitation
Physical Memory Mayhem
Address we want to
find Page Frame
Number for
Note: PFN’s are multiplied by 0x1000 (4KB) to find the physical address of the next paging
structure.
HCVI/VBS
HVCI is a kernel hypervisor
Technology that extends page tables
Up additional levels so you have
5-layer page translation.
Here the kernel can request that the
Hypervisor make’s sure certain pages
are protected (Page Guard) and
Tricks like PTE overwrites can’t occur
(Priv Esc technique to make pages
executable)
LOLDriver Exploitation
Physical Memory Mayhem
HCVI/VBS
HVCI is employed through the Windows
Hypervisor’s usage of two abstract
Kernels known as VTL 0 and VTL 1 that
Operate above the running kernel.
This model offers many protections to
Prevent userland to kernel land
Privilege escalations
LOLDriver Exploitation
Physical Memory Mayhem
Exploitation – Token Theft Priv Esc (SYSTEM)
LOLDriver Exploitation
Physical Memory Mayhem
Locating SYSTEM’s EPROCESS structure from Userland
DHA_Userland_Find_SYSTEM_EPROCESS.exe explained… (c++)
STEP 1: Finding Windows Kernel Base
• The EnumDeviceDrivers() function will populate a list of loaded system modules
• The first entry [0] contains the loading address of ntosknrl.exe (windows kernel)
LOLDriver Exploitation
Physical Memory Mayhem
Locating SYSTEM’s EPROCESS structure from Userland
DHA_Userland_Find_SYSTEM_EPROCESS.exe explained… (c++)
STEP 2: Finding SYSTEM’s EPROCCESS structure offset
• We use LoadLibraryA() to load ntoskrnl.exe (Normally used for DLL’s – but .EXE, .SYS, and
.DLL are the same PE file format
• We use GetProcAddress() to find the export for PsInitialSystemProcess (EPROCESS pointer
offset)
( GetProcAddress() is normally used to look
up function addresses – but what it’s
ACTUALLY doing is looking up EXPORT
names/addresses  )
• We Add Kernelbase + PsInitialSystemProcess together for pointer to EPROCESS in memory
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
• Privilege Escalation via Token theft 1) We Copy
Token from
EPROCESS w/
PID #4
(SYSTEM)
LOLDriver Exploitation
Physical Memory Mayhem
• Privilege Escalation via Token theft 1) We Copy
Token from
EPROCESS w/
PID #4
(SYSTEM)
2) We Locate
our EPROCESS
PID #
LOLDriver Exploitation
Physical Memory Mayhem
• Privilege Escalation via Token theft 1) We Copy
Token from
EPROCESS w/
PID #4
(SYSTEM)
2) We Locate
our EPROCESS
PID #
3) We copy
SYSTEM Token
into our
EPROCESS
LOLDriver Exploitation
Physical Memory Mayhem
• Privilege Escalation via Token theft
Now running as
SYSTEM
LOLDriver Exploitation
Physical Memory Mayhem
• Privilege Escalation via Token theft
DEMO!
Exploitation – The Provider / Victim model
LOLDriver Exploitation
Physical Memory Mayhem
LOLDriver Exploitation
Physical Memory Mayhem
• How KDU Works… The Victim-Provider Model
LOLDriver Exploitation
Physical Memory Mayhem
• How KDU Works… The Victim-Provider Model
LOLDriver Exploitation
Physical Memory Mayhem
• How KDU Works… The Victim-Provider Model
LOLDriver Exploitation
Physical Memory Mayhem
• How KDU Works… The Victim-Provider Model
LOLDriver Exploitation
Physical Memory Mayhem
• How KDU Works… The Victim-Provider Model
LOLDriver Exploitation
Physical Memory Mayhem
typedef struct _KDU_PROVIDER {
struct {
provRegisterDriver RegisterDriver; //optional
provUnregisterDriver UnregisterDriver; //optional
provAllocateKernelVM AllocateKernelVM; //optional
provFreeKernelVM FreeKernelVM; //optional
provReadKernelVM ReadKernelVM;
provWriteKernelVM WriteKernelVM;
provVirtualToPhysical VirtualToPhysical; //optional
provReadControlRegister ReadControlRegister; //optional
provQueryPML4 QueryPML4Value; //optional
provReadPhysicalMemory ReadPhysicalMemory; //optional
provWritePhysicalMemory WritePhysicalMemory; //optional
} Callbacks;
} KDU_PROVIDER, * PKDU_PROVIDER;
KDU Provider BYOVD Model
LOLDriver Exploitation
Physical Memory Mayhem
Windows 11 – Working Providers
#1 – IQVM64.sys
#13 – AsIO2.sys
#15 – GmerDrv.sys
#20 – DBUtilDrv2.sys
#22 – AsIO3.sys
#26 – impoutx64.sys
#27 – DirectIo64.sys
#29 – ALSysIo64.sys
KDU Provider BYOVD Model
Win 11 (checked 07/11/23_
PROCEXP152.SYS – Process Explorer – KDU’s Victim Driver
It’s an old binary – so that means it was compiled without Code Integrity (CI) checks that
prevent shellcode/ROP (ROP Is dead for other Reasons – see: KVA Shadow Stack)
Set to have INIT section that is RWX – we can overwrite the IRP handlers for handlers such
as IRP_MJ_CREATE
IRP_MJ_CREATE is triggered when you open .PROCEXP152 with CreateFile (opening the
file)
This means we can write shellcode in there to do anything we want.
LOLDriver Exploitation
Physical Memory Mayhem
Exploitation – Large Page Drivers
LOLDriver Exploitation
Physical Memory Mayhem
Large Page Drivers
It was discovered that Drivers could be added to a special list designated in the windows registry for
system drivers known as ‘Large Page Drivers’
These Large Page Drivers – use large (2 MB) pages instead of the standard 4KB (0x1000 byte) pages.
In doing so – They combine the .TEXT (RX) and .DATA (RW) sections of an executable into a single
section
That is both RW and RX ( so RWX)
Example:
GitHub - VollRagm/lpmapper: A mapper that maps shellcode into loaded large page drivers
LOLDriver Exploitation
Physical Memory Mayhem
Large Page Drivers
LOLDriver Exploitation
Physical Memory Mayhem
Exploitation – Protected Process Lights (PPL)
LOLDriver Exploitation
Physical Memory Mayhem
• Protected Process Light (PPL) technology is used for controlling and protecting running processes and
protecting them from infection by malicious code and the potentially harmful effects of other processes.
These processes include:
• Shutdown
• Stream deployment
• Access to virtual memory
• Debugging
• Copying of descriptors
• Changing the memory working set
• Changing and receiving information about the current state of the thread
• Impersonation of threads (running process threads under a different account)
READ MORE HERE: https://spikysabra.gitbook.io/kernelcactus/pocs/ppl-toggling
LOLDriver Exploitation
Physical Memory Mayhem
PPL Elevation Since we can modify EPROCESS and its fields…
Note: Ounce we toggle a
process to be PPL
we can dump LSASS for
passwords!
Exploitation – Handle elevation
LOLDriver Exploitation
Physical Memory Mayhem
Handle elevation
Since we can modify EPROCESS and its fields…
• Each _EPROCESS structure holds within it a pointer to the _HANDLE_TABLE object, Named the
ObjectTable.
• This specific pointer, is to the head of the Handle Table, and contains a list of handles which appear
one after the other in the memory.
• Given read and write access to the _HANDLE_TABLE_ENTRY object itself, one can edit the
GrantedAccessBits
• handle created for SYNCHRONIZE, READ_CONTROL, QUERY_LIMITED_INFORMATION, can be
escalated to FULL_CONTROL
READ MORE HERE: https://spikysabra.gitbook.io/kernelcactus/pocs/handle-elevation
LOLDriver Exploitation
Physical Memory Mayhem
Next Talk:
Kernel Talks 0x04
BADUSB and the Gadget-FS filesystem
LOLDriver Exploitation
Physical Memory Mayhem
Thanks!
Russell Sanford
xort@sploit.online
LOLDriver Exploitation
Physical Memory Mayhem

More Related Content

What's hot

Hunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows InfrastructureHunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows InfrastructureSergey Soldatov
 
Not a Security Boundary
Not a Security BoundaryNot a Security Boundary
Not a Security BoundaryWill Schroeder
 
External to DA, the OS X Way
External to DA, the OS X WayExternal to DA, the OS X Way
External to DA, the OS X WayStephan Borosh
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!Affan Syed
 
Hunting for Privilege Escalation in Windows Environment
Hunting for Privilege Escalation in Windows EnvironmentHunting for Privilege Escalation in Windows Environment
Hunting for Privilege Escalation in Windows EnvironmentTeymur Kheirkhabarov
 
Overview of Vulnerability Scanning.pptx
Overview of Vulnerability Scanning.pptxOverview of Vulnerability Scanning.pptx
Overview of Vulnerability Scanning.pptxAjayKumar73315
 
(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory PwnagePetros Koutroumpis
 
DerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting RevisitedDerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting RevisitedWill Schroeder
 
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 EditionGoing Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 EditionSoroush Dalili
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Valeriy Kravchuk
 
PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)Will Schroeder
 
Windows privilege escalation by Dhruv Shah
Windows privilege escalation by Dhruv ShahWindows privilege escalation by Dhruv Shah
Windows privilege escalation by Dhruv ShahOWASP Delhi
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debuggingHao-Ran Liu
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)Brendan Gregg
 
How Functions Work
How Functions WorkHow Functions Work
How Functions WorkSaumil Shah
 
DNS exfiltration using sqlmap
DNS exfiltration using sqlmapDNS exfiltration using sqlmap
DNS exfiltration using sqlmapMiroslav Stampar
 
Building Better Backdoors with WMI - DerbyCon 2017
Building Better Backdoors with WMI - DerbyCon 2017Building Better Backdoors with WMI - DerbyCon 2017
Building Better Backdoors with WMI - DerbyCon 2017Alexander Polce Leary
 

What's hot (20)

Hunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows InfrastructureHunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows Infrastructure
 
Not a Security Boundary
Not a Security BoundaryNot a Security Boundary
Not a Security Boundary
 
I hunt sys admins 2.0
I hunt sys admins 2.0I hunt sys admins 2.0
I hunt sys admins 2.0
 
External to DA, the OS X Way
External to DA, the OS X WayExternal to DA, the OS X Way
External to DA, the OS X Way
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
Hunting for Privilege Escalation in Windows Environment
Hunting for Privilege Escalation in Windows EnvironmentHunting for Privilege Escalation in Windows Environment
Hunting for Privilege Escalation in Windows Environment
 
Xss (cross site scripting)
Xss (cross site scripting)Xss (cross site scripting)
Xss (cross site scripting)
 
Overview of Vulnerability Scanning.pptx
Overview of Vulnerability Scanning.pptxOverview of Vulnerability Scanning.pptx
Overview of Vulnerability Scanning.pptx
 
(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage
 
DerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting RevisitedDerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting Revisited
 
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 EditionGoing Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
 
PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)
 
RAT - Repurposing Adversarial Tradecraft
RAT - Repurposing Adversarial TradecraftRAT - Repurposing Adversarial Tradecraft
RAT - Repurposing Adversarial Tradecraft
 
Windows privilege escalation by Dhruv Shah
Windows privilege escalation by Dhruv ShahWindows privilege escalation by Dhruv Shah
Windows privilege escalation by Dhruv Shah
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
How Functions Work
How Functions WorkHow Functions Work
How Functions Work
 
DNS exfiltration using sqlmap
DNS exfiltration using sqlmapDNS exfiltration using sqlmap
DNS exfiltration using sqlmap
 
Building Better Backdoors with WMI - DerbyCon 2017
Building Better Backdoors with WMI - DerbyCon 2017Building Better Backdoors with WMI - DerbyCon 2017
Building Better Backdoors with WMI - DerbyCon 2017
 

Similar to 0x003 - Exploiting LOLDrivers - Physical Memory Mayhem

Reverse Engineering and Bug Hunting on KMDF Drivers - Enrique Nissim - 44CON ...
Reverse Engineering and Bug Hunting on KMDF Drivers - Enrique Nissim - 44CON ...Reverse Engineering and Bug Hunting on KMDF Drivers - Enrique Nissim - 44CON ...
Reverse Engineering and Bug Hunting on KMDF Drivers - Enrique Nissim - 44CON ...44CON
 
openioc_scan - IOC scanner for memory forensics
openioc_scan - IOC scanner for memory forensicsopenioc_scan - IOC scanner for memory forensics
openioc_scan - IOC scanner for memory forensicsTakahiro Haruyama
 
The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022lior mazor
 
DEF CON 27 - MICHAEL LEIBOWITZ and TOPHER TIMZEN - edr is coming hide yo sht
DEF CON 27 - MICHAEL LEIBOWITZ and TOPHER TIMZEN - edr is coming hide yo shtDEF CON 27 - MICHAEL LEIBOWITZ and TOPHER TIMZEN - edr is coming hide yo sht
DEF CON 27 - MICHAEL LEIBOWITZ and TOPHER TIMZEN - edr is coming hide yo shtFelipe Prado
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitDimitry Snezhkov
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...Felipe Prado
 
Defeating x64: Modern Trends of Kernel-Mode Rootkits
Defeating x64: Modern Trends of Kernel-Mode RootkitsDefeating x64: Modern Trends of Kernel-Mode Rootkits
Defeating x64: Modern Trends of Kernel-Mode RootkitsAlex Matrosov
 
0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlabNational Cheng Kung University
 
Learning AOSP - Building AOSP for Nexus 7
Learning AOSP - Building AOSP for Nexus 7Learning AOSP - Building AOSP for Nexus 7
Learning AOSP - Building AOSP for Nexus 7Nanik Tolaram
 
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012DefCamp
 
CEHv10 M0 Introduction.pptx
CEHv10 M0 Introduction.pptxCEHv10 M0 Introduction.pptx
CEHv10 M0 Introduction.pptxYasserOuda2
 
On non existent 0-days, stable binary exploits and
On non existent 0-days, stable binary exploits andOn non existent 0-days, stable binary exploits and
On non existent 0-days, stable binary exploits andAlisa Esage Шевченко
 
LJC-Unconference-2023-Keynote.pdf
LJC-Unconference-2023-Keynote.pdfLJC-Unconference-2023-Keynote.pdf
LJC-Unconference-2023-Keynote.pdfEmilyJiang23
 
Live Memory Forensics on Android devices
Live Memory Forensics on Android devicesLive Memory Forensics on Android devices
Live Memory Forensics on Android devicesNikos Gkogkos
 
Lateral Movement: How attackers quietly traverse your Network
Lateral Movement: How attackers quietly traverse your NetworkLateral Movement: How attackers quietly traverse your Network
Lateral Movement: How attackers quietly traverse your NetworkEC-Council
 
Lateral Movement - Hacker Halted 2016
Lateral Movement - Hacker Halted 2016Lateral Movement - Hacker Halted 2016
Lateral Movement - Hacker Halted 2016Xavier Ashe
 
OWASP Pune Chapter : Dive Into The Profound Web Attacks
OWASP Pune Chapter : Dive Into The Profound Web AttacksOWASP Pune Chapter : Dive Into The Profound Web Attacks
OWASP Pune Chapter : Dive Into The Profound Web AttacksNarendra Bhati
 

Similar to 0x003 - Exploiting LOLDrivers - Physical Memory Mayhem (20)

Reverse Engineering and Bug Hunting on KMDF Drivers - Enrique Nissim - 44CON ...
Reverse Engineering and Bug Hunting on KMDF Drivers - Enrique Nissim - 44CON ...Reverse Engineering and Bug Hunting on KMDF Drivers - Enrique Nissim - 44CON ...
Reverse Engineering and Bug Hunting on KMDF Drivers - Enrique Nissim - 44CON ...
 
openioc_scan - IOC scanner for memory forensics
openioc_scan - IOC scanner for memory forensicsopenioc_scan - IOC scanner for memory forensics
openioc_scan - IOC scanner for memory forensics
 
The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022
 
You suck at Memory Analysis
You suck at Memory AnalysisYou suck at Memory Analysis
You suck at Memory Analysis
 
DEF CON 27 - MICHAEL LEIBOWITZ and TOPHER TIMZEN - edr is coming hide yo sht
DEF CON 27 - MICHAEL LEIBOWITZ and TOPHER TIMZEN - edr is coming hide yo shtDEF CON 27 - MICHAEL LEIBOWITZ and TOPHER TIMZEN - edr is coming hide yo sht
DEF CON 27 - MICHAEL LEIBOWITZ and TOPHER TIMZEN - edr is coming hide yo sht
 
Faults inside System Software
Faults inside System SoftwareFaults inside System Software
Faults inside System Software
 
Improve Android System Component Performance
Improve Android System Component PerformanceImprove Android System Component Performance
Improve Android System Component Performance
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution Toolkit
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
 
Defeating x64: Modern Trends of Kernel-Mode Rootkits
Defeating x64: Modern Trends of Kernel-Mode RootkitsDefeating x64: Modern Trends of Kernel-Mode Rootkits
Defeating x64: Modern Trends of Kernel-Mode Rootkits
 
0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab
 
Learning AOSP - Building AOSP for Nexus 7
Learning AOSP - Building AOSP for Nexus 7Learning AOSP - Building AOSP for Nexus 7
Learning AOSP - Building AOSP for Nexus 7
 
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
 
CEHv10 M0 Introduction.pptx
CEHv10 M0 Introduction.pptxCEHv10 M0 Introduction.pptx
CEHv10 M0 Introduction.pptx
 
On non existent 0-days, stable binary exploits and
On non existent 0-days, stable binary exploits andOn non existent 0-days, stable binary exploits and
On non existent 0-days, stable binary exploits and
 
LJC-Unconference-2023-Keynote.pdf
LJC-Unconference-2023-Keynote.pdfLJC-Unconference-2023-Keynote.pdf
LJC-Unconference-2023-Keynote.pdf
 
Live Memory Forensics on Android devices
Live Memory Forensics on Android devicesLive Memory Forensics on Android devices
Live Memory Forensics on Android devices
 
Lateral Movement: How attackers quietly traverse your Network
Lateral Movement: How attackers quietly traverse your NetworkLateral Movement: How attackers quietly traverse your Network
Lateral Movement: How attackers quietly traverse your Network
 
Lateral Movement - Hacker Halted 2016
Lateral Movement - Hacker Halted 2016Lateral Movement - Hacker Halted 2016
Lateral Movement - Hacker Halted 2016
 
OWASP Pune Chapter : Dive Into The Profound Web Attacks
OWASP Pune Chapter : Dive Into The Profound Web AttacksOWASP Pune Chapter : Dive Into The Profound Web Attacks
OWASP Pune Chapter : Dive Into The Profound Web Attacks
 

Recently uploaded

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 

Recently uploaded (20)

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 

0x003 - Exploiting LOLDrivers - Physical Memory Mayhem

  • 1. Exploiting LOLDrivers (part1) Physical Memory Mayhem Russell Sanford xort @ sploit.online
  • 3. About me… Russell Sanford • 25 Years experience in writing exploits and reverse engineering • Published exploit author with dozens of CVE’s in network security appliances • 12+ years experience in penetration testing and red teaming LOLDriver Exploitation Physical Memory Mayhem
  • 4. What are LOLDrivers ? LOLDriver Exploitation Physical Memory Mayhem
  • 5. Living Off The Land (LOTL) Living off the land (LOTL) is a fileless malware or LOLbins cyberattack technique where the cybercriminal uses native, legitimate tools within the victim’s system to sustain and advance an attack. Living Off The Land Drivers (LOLDrivers) is a community-driven project that provides a curated list of all Windows drivers that have been found abused by adversaries to bypass security controls and execute malicious code. LOLDriver Exploitation Physical Memory Mayhem
  • 7. www.loldrivers.io •List of multiple different versions of drivers known to be vulnerable to attacks •Information on Microsoft Blocked Driver Listing •Hashes, Resource Links, YARA Rules, and Vulnerable API used LOLDriver Exploitation Physical Memory Mayhem
  • 8. Where/How this all began… LOLDriver Exploitation Physical Memory Mayhem
  • 9. How I got started on this subject • Microsoft finally got around to implementing mitigations to stop people from utilizing Kdmapper • Red Teaming friend asked me if I could look into writing a new replacement unsigned driver mapper utilizing known LOLDrivers for testing EDR/XDR solutions • I Quickly learned that there was only limited relevant and up-to-date information to be learned from the Penetration Testing/Red Teaming communities • Exploiting these types of vulnerabilities was largely pioneered by members of the gaming communities LOLDriver Exploitation Physical Memory Mayhem
  • 10. Let’s Begin… :D LOLDriver Exploitation Physical Memory Mayhem
  • 11. Warning! The exploitation tricks your going to see are not being used in ANY public exploits I could find. LOLDriver Exploitation Physical Memory Mayhem
  • 13. Enabling DbgPrint Messages from the Windows Kernel Go to path, • “HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerDebug Print Filter”. • If "Debug Print Filter" is not present then create it. • Add value “DEFAULT” : REG_DWORD : 0xFFFFFFFF and then reboot. LOLDriver Exploitation Physical Memory Mayhem
  • 14. Getting Setup For Visual Studio Driver Development LOLDriver Exploitation Physical Memory Mayhem
  • 15. Getting Setup for Visual Studio Driver Development LOLDriver Exploitation Physical Memory Mayhem
  • 16. Getting Setup for Visual Studio Driver Development LOLDriver Exploitation Physical Memory Mayhem
  • 17. Setting up Windows Kernel Debugging over Serial LOLDriver Exploitation Physical Memory Mayhem
  • 18. Setting Up VMWare – Adding a Serial Port for kernel debugging LOLDriver Exploitation Physical Memory Mayhem
  • 19. LOLDriver Exploitation Physical Memory Mayhem Configuring WinDBG VMWare Serial Port (Named Pipe)
  • 20. LOLDriver Exploitation Physical Memory Mayhem • Configuring VMware
  • 21. Setting Up WinDBG for Remote Serial Debugging LOLDriver Exploitation Physical Memory Mayhem
  • 22. How Communication with System Drivers works LOLDriver Exploitation Physical Memory Mayhem
  • 23. LOLDriver Exploitation Physical Memory Mayhem • Communicating with SYSTEM Drivers – IOCTL calls
  • 24. Userland (Ring3) <-> Kernel Land (Ring 0) communication - IOCTL LOLDriver Exploitation Physical Memory Mayhem
  • 25. Userland (Ring3) <-> Kernel Land (Ring 0) communication – IOCTL 1) A handle is opened to A device driver’s Symbolic Name 2) IOCTL Request is made With Input and Output Buffers using handle 3) Kernel Driver returns Response in Output buffer 4) When all communication has ended Handle to driver is closed LOLDriver Exploitation Physical Memory Mayhem
  • 26. Userland (Ring3) <-> Kernel Land (Ring 0) communication – IOCTL Example: HANDLE Handle = CreateFile(".IOCTL", ..., 0, NULL); DWORD version, junk; if (DeviceIoControl(Handle, IOCTL_GET_VERSION_BUFFERED, NULL, 0, &version, sizeof(version), &junk, NULL)) printf("IOCTL.SYS version %d.%2dn", HIWORD(version), LOWORD(version)); else printf("Error %d in IOCTL_GET_VERSION_BUFFERED calln", GetLastError()); LOLDriver Exploitation Physical Memory Mayhem
  • 28. LOLDriver Exploitation Physical Memory Mayhem Communicating with SYSTEM Drivers – IOCTL calls 1) A HANDLE is opened to the Driver
  • 29. LOLDriver Exploitation Physical Memory Mayhem Communicating with SYSTEM Drivers – IOCTL calls 1) A HANDLE is opened to the Driver 2) A Request is made to the Driver using an IOCTL call
  • 30. LOLDriver Exploitation Physical Memory Mayhem Communicating with SYSTEM Drivers – IOCTL calls 1) A HANDLE is opened to the Driver 2) A Request is made to the Driver using an IOCTL call 3) When all communications are done The HANDLE to the Driver is closed.
  • 31. LOLDriver Exploitation Physical Memory Mayhem Communicating with SYSTEM Drivers – IOCTL calls INPUT Buffer / Buffer Size Request from USERLAND to KERNELAND Driver
  • 32. LOLDriver Exploitation Physical Memory Mayhem Communicating with SYSTEM Drivers – IOCTL calls OUTPUT Buffer / Buffer Size Response from KERNELAND Driver to USERLAND
  • 33. Exploited Windows API Functions Providing Access to Physical Memory LOLDriver Exploitation Physical Memory Mayhem
  • 34. Common Vulnerable API Access to Physical Memory PCI Device Access MmMapIOSpace() HalGetBusDataByOffset() ZwMapViewOfSection() HalSetBusDataByOffset() <- in/out port communication -> Physical Memory Address Resolving Memory Copying Operations memcpy() MSR Register Access memmove() __readmsr()/__writemsr() And Much More! LOLDriver Exploitation Physical Memory Mayhem
  • 35. Common Vulnerable API This presentation is my analysis of what could be done using the commonly found API allowing for: Access to Physical Memory • MmMapIOSpace() • ZwMapViewOfSection() * Note: There are several sub-variants of these functions that do/do-not allow access to cached and/or locked operations LOLDriver Exploitation Physical Memory Mayhem
  • 36. LOLDriver Exploitation Physical Memory Mayhem MmMapIoSpace()
  • 37. LOLDriver Exploitation Physical Memory Mayhem MmMapIoSpace() Note: Microsoft has blocked MmMapIoSpace() from being able to access page tables directly. This can be circumvented by using MmMapIoSpace() in a provider- >victim model in which shellcode is introduced into another driver fully capable of accessing these blocked regions of code – staging 101.
  • 38. LOLDriver Exploitation Physical Memory Mayhem ZwMapViewOfSection()
  • 39. ZwMapViewOfSection() LOLDriver Exploitation Physical Memory Mayhem Creates a “View” of a section View can be mapped to ANY location in memory Can be READ only, READ|WRITE, or WRITE only Write operations will update address pointed TO when WRITE is enabled
  • 40. Some Drivers offer Phsical Addressing to Virtual Addressing or vice-versa IOCTL calls are sometime offered to implement: • VA->PA ( calls MmGetPhysicalAddress() ) • VA->Pfn or VA-Pte (Page Frame Number / Page Table Entry) LOLDriver Exploitation Physical Memory Mayhem
  • 41. Vulnerable Libraries Facilitating Exploitation LOLDriver Exploitation Physical Memory Mayhem
  • 42. Known Vulnerable Libraries with Exploitation Primitives • WinIO • MAPMEM • PHYMEM • RWEverything • WINRING0 LOLDriver Exploitation Physical Memory Mayhem WINIO was found to be the more popularly re-used library and so the exploitation used/demonstrated in this presentation will be focused on abusing it.
  • 43. Culprit Drivers – ‘Providers’ Many of the vulnerable LOLDrivers fall into the tools that provide the following functionalities: Bios flashing Gaming Tuning RGB Keyboard utilities Core Temperature Controllers Diagnostic Tools Forensic Tools GPU utilities Performance Tools Mimikatz Rootkit Detection Utilities Process Exploring Tools LOLDriver Exploitation Physical Memory Mayhem
  • 44. Unsigned Driver Mappers Exploiting these APIs LOLDriver Exploitation Physical Memory Mayhem
  • 45. Public Tools for unsigned driver loading KDU (hfiref0x) GDRV-loader (alxbrn) Voidmap (SamuelTulach) DSEFix (hfiref0x) Kdmapper (TheCruz/z175) physmeme TDL (hfiref0x) Nasa mapper (xeroxz) many more…. Efi-mapper (SamuelTulach) http://www.unknowncheats.me LOLDriver Exploitation Physical Memory Mayhem
  • 46. Resources: LOLDrivers.com Massive collection of Drivers utilizing Exploitable API Gaming Forums! Unknown Cheats By far best source Of information On exploitation Of LOLDrivers LOLDriver Exploitation Physical Memory Mayhem https://www.unknowncheats.me/
  • 48. Dealing with revoked cert drivers… We can disable the Driver Blocklist and Run blocked drivers  [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlCIConfig] "VulnerableDriverBlocklistEnable"=dword:00000000 or reg add HKLMSYSTEMCurrentControlSetCIConfig /v "VulnerableDriverBlocklistEnable" /t REG_DWORD /d 0 /f LOLDriver Exploitation Physical Memory Mayhem
  • 49. Physical Memory vs Virtual Memory LOLDriver Exploitation Physical Memory Mayhem
  • 50. Physical Memory vs Virtual Memory LOLDriver Exploitation Physical Memory Mayhem Cached Pages
  • 51. Let’s start breaking down exploitation tactics… LOLDriver Exploitation Physical Memory Mayhem
  • 52. The Kernel Pool LOLDriver Exploitation Physical Memory Mayhem
  • 53. Welcome to the Pool Party – Kernel Pool Explained LOLDriver Exploitation Physical Memory Mayhem
  • 54. Kernel Pool Allocation Functions: ExAllocatePool() ExAllocatePool2() ExAllocatePool3() ExAllocatePoolWithTag() ExAllocatePoolWithQuotaTag() ExAllocatePoolWithTagPriority() + more… Kernel Pool Allocations are made with an associated ‘tag’ that is either provided or generated depending on which API is utilized LOLDriver Exploitation Physical Memory Mayhem
  • 55. Kernel Pool Allocation with ‘tags’: Example Allocation with ‘abcd’ tag header: LOLDriver Exploitation Physical Memory Mayhem
  • 56. Example Kernel Pool Allocation for Windows TOKEN with ‘tag’: LOLDriver Exploitation Physical Memory Mayhem Note: There are tens of thousands of different Pool Tag’s for various Windows Objects – Everything's got its own memory allocation tag type!
  • 57. The Kernel Pool Exploitation ‘Proc’ Pool Scanning Technique LOLDriver Exploitation Physical Memory Mayhem
  • 58. EPROCESS and the ‘Proc’ Pool Header LOLDriver Exploitation Physical Memory Mayhem
  • 59. EPROCESS and the ‘Proc’ Pool Header – Preceeds EPROCESS structures LOLDriver Exploitation Physical Memory Mayhem
  • 60. Kernel Memory Pools and the ‘Proc’ Pool Header… • Pool Headers are allocated on 0x10 offsets • The tag is located 4 bytes in EPROCESS Structure Scanning Pseudocode: For (i=0; I < 0x2000000; I += 0x10) { if ( memcmp( (buffer+i+4), “Proc”) == 0 ) { // found proc pool header – print info } } LOLDriver Exploitation Physical Memory Mayhem
  • 61. Scanning for ‘Proc’ pool headers (EPROCESS structures) LOLDriver Exploitation Physical Memory Mayhem DEMO!
  • 62. PML4 Page Tables LOLDriver Exploitation Physical Memory Mayhem
  • 64. LOLDriver Exploitation Physical Memory Mayhem 4 Level Page Translation (4k page) PML4E_Offset = (ADDR >>39) & 0x1FF PDPE_Offset = ( ADDR >>30) & 0x1FF PDE_Offset = (ADDR >>21) & 0x1FF PT_OFFset (ADDR >>12) & 0x1FF PysAddr_Offset = 0x1FFFFFFF
  • 65. UINT64 PML4E = CR3 + (((address_to_lookup >> 39) & 0x1ff) * sizeof(DWORD64)); UINT64 PDPE = (read_UINT64_from_4k_page_phys_memory((PUINT64)PML4E) & 0x00FFFFFFFFFFF000) + (((address_to_lookup >> 30) & 0x1ff) * sizeof(DWORD64)); UINT64 PDT = (read_UINT64_from_4k_page_phys_memory((PUINT64)PDPE) & 0x00FFFFFFFFFFF000) + (((address_to_lookup >> 21) & 0x1ff) * sizeof(DWORD64)); UINT64 PT = (read_UINT64_from_4k_page_phys_memory((PUINT64)PDT) & 0x00FFFFFFFFFFF000) + (((address_to_lookup >> 12) & 0x1ff) * sizeof(DWORD64)); final_addr_phys_ptr = (PT & 0x000FFFFFFFF00000) + (address_to_lookup & 0xFFFFF); LOLDriver Exploitation Physical Memory Mayhem 4 Level Page Translation (4k page)
  • 68. HCVI / VBA Protections – Extended Page Tables LOLDriver Exploitation Physical Memory Mayhem
  • 69. Finding Cr3’s value to walk tables LOLDriver Exploitation Physical Memory Mayhem
  • 70. Finding Cr3 through ‘Proc’ (EPROCESS) pool scanning LOLDriver Exploitation Physical Memory Mayhem
  • 71. Finding Cr3 through EPROCESS scanning… • We can scan for ‘Proc’ pool headers which identify EPROCESS structures • The First Part of an EPROCESS structure is a KPROCESS structure • The KPROCESS Structure contains DirectoryTableBase (CR3 register value for process) LOLDriver Exploitation Physical Memory Mayhem
  • 72. Finding Cr3 through the DOS “LOW STUB” LOLDriver Exploitation Physical Memory Mayhem
  • 74. CR3 “Low Stub” trick courtesy of pcileech Direct Memory Attack (DMA) software Designed for cool hardware hacking implant’s like the PCI Squirrel https://github.com/ufrisk/pcileech LOLDriver Exploitation Physical Memory Mayhem
  • 75. typedef struct _PROCESSOR_START_BLOCK { FAR_JMP_16 Jmp; ULONG CompletionFlag; PSEUDO_DESCRIPTOR_32 Gdt32; PSEUDO_DESCRIPTOR_32 Idt32; KGDTENTRY64 Gdt[PSB_GDT32_MAX + 1]; ULONG64 TiledCr3; FAR_TARGET_32 PmTarget; FAR_TARGET_32 LmIdentityTarget; PVOID LmTarget; PPROCESSOR_START_BLOCK SelfMap; ULONG64 MsrPat; ULONG64 MsrEFER; KPROCESSOR_STATE ProcessorState; } PROCESSOR_START_BLOCK; CR3 “Low Stub” trick The DOS “Low Stub” is the area of physical memory between 0-0x20000 In this range, as the computer boots, a structure called PROCESSOR_START_BLOCK is stored in memory It is used when resuming from ACPI Sleep Vector amongst other things LOLDriver Exploitation Physical Memory Mayhem
  • 76. CR3 “Low Stub” trick The _PROCESSOR_START_BLOCK structure has a structure named KSPECIAL_REGISTERS KSPECIAL_REGISTERS contains the kernel’s Cr3 value which points to the start of the page tables LOLDriver Exploitation Physical Memory Mayhem typedef struct _KPROCESSOR_STATE { CONTEXT ContextFrame; KSPECIAL_REGISTERS SpecialRegisters; } KPROCESSOR_STATE, *PKPROCESSOR_STATE; typedef struct _KSPECIAL_REGISTERS { ULONG Cr0; ULONG Cr2; ULONG Cr3; ULONG Cr4; ULONG KernelDr0; ULONG KernelDr1; ULONG KernelDr2; ULONG KernelDr3; ULONG KernelDr6; ULONG KernelDr7; DESCRIPTOR Gdtr; DESCRIPTOR Idtr; WORD Tr; WORD Ldtr; ULONG Reserved[6]; } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  • 77. CR3 “Low Stub” trick LOLDriver Exploitation Physical Memory Mayhem __try { while (offset < 0x100000) { offset += 0x1000; if (0x00000001000600E9 != (0xffffffffffff00ff & *(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp continue; if (0xfffff80000000000 != (0xfffff80000000003 & *(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget)))) continue; if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset)) continue; PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset); break; } }
  • 78. CR3 “Low Stub” trick LOLDriver Exploitation Physical Memory Mayhem __try { while (offset < 0x100000) { offset += 0x1000; if (0x00000001000600E9 != (0xffffffffffff00ff & *(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp continue; if (0xfffff80000000000 != (0xfffff80000000003 & *(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget)))) continue; if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset)) continue; PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset); break; } }
  • 79. __try { while (offset < 0x100000) { offset += 0x1000; if (0x00000001000600E9 != (0xffffffffffff00ff & *(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp continue; if (0xfffff80000000000 != (0xfffff80000000003 & *(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget)))) continue; if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset)) continue; PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset); break; } } CR3 “Low Stub” trick LOLDriver Exploitation Physical Memory Mayhem
  • 80. __try { while (offset < 0x100000) { offset += 0x1000; if (0x00000001000600E9 != (0xffffffffffff00ff & *(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp continue; if (0xfffff80000000000 != (0xfffff80000000003 & *(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget)))) continue; if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset)) continue; PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset); break; } } CR3 “Low Stub” trick LOLDriver Exploitation Physical Memory Mayhem
  • 81. CR3 “Low Stub” trick LOLDriver Exploitation Physical Memory Mayhem __try { while (offset < 0x100000) { offset += 0x1000; if (0x00000001000600E9 != (0xffffffffffff00ff & *(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp continue; if (0xfffff80000000000 != (0xfffff80000000003 & *(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget)))) continue; if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset)) continue; PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset); break; } }
  • 82. CR3 “Low Stub” trick LOLDriver Exploitation Physical Memory Mayhem __try { while (offset < 0x100000) { offset += 0x1000; if (0x00000001000600E9 != (0xffffffffffff00ff & *(UINT64*)(pbLowStub1M + offset))) //PROCESSOR_START_BLOCK->Jmp continue; if (0xfffff80000000000 != (0xfffff80000000003 & *(UINT64*)(pbLowStub1M + offset + FIELD_OFFSET(PROCESSOR_START_BLOCK, LmTarget)))) continue; if (0xffffff0000000fff & *(UINT64*)(pbLowStub1M + offset + cr3_offset)) continue; PML4 = *(UINT64*)(pbLowStub1M + offset + cr3_offset); break; } }
  • 83. Building Block API Functions for Exploitation Building PA to VA translation functions LOLDriver Exploitation Physical Memory Mayhem
  • 89. Walking the tables to PID 4 (SYSTEM EPROCSS structure) LOLDriver Exploitation Physical Memory Mayhem DEMO!
  • 90. Building Block API Functions for Exploitation Building Pfn (Page Frame Numer) lookup functions LOLDriver Exploitation Physical Memory Mayhem
  • 91. MiGetPteAddress – Assembly contains Hardcoded Pte Base in Memory 1) We calculate the address of MiGetPteAddress in memory LOLDriver Exploitation Physical Memory Mayhem
  • 92. MiGetPteAddress – Assembly contains Hardcoded Pte Base in Memory 2) We Extract the QWORD value of the PFN Table Base from the function LOLDriver Exploitation Physical Memory Mayhem
  • 93. MiGetPteAddress() – decompiled to C ( Now we can write our own PFN Table lookup routine! ) LOLDriver Exploitation Physical Memory Mayhem Address we want to find Page Frame Number for Note: PFN’s are multiplied by 0x1000 (4KB) to find the physical address of the next paging structure.
  • 94. HCVI/VBS HVCI is a kernel hypervisor Technology that extends page tables Up additional levels so you have 5-layer page translation. Here the kernel can request that the Hypervisor make’s sure certain pages are protected (Page Guard) and Tricks like PTE overwrites can’t occur (Priv Esc technique to make pages executable) LOLDriver Exploitation Physical Memory Mayhem
  • 95. HCVI/VBS HVCI is employed through the Windows Hypervisor’s usage of two abstract Kernels known as VTL 0 and VTL 1 that Operate above the running kernel. This model offers many protections to Prevent userland to kernel land Privilege escalations LOLDriver Exploitation Physical Memory Mayhem
  • 96. Exploitation – Token Theft Priv Esc (SYSTEM) LOLDriver Exploitation Physical Memory Mayhem
  • 97. Locating SYSTEM’s EPROCESS structure from Userland DHA_Userland_Find_SYSTEM_EPROCESS.exe explained… (c++) STEP 1: Finding Windows Kernel Base • The EnumDeviceDrivers() function will populate a list of loaded system modules • The first entry [0] contains the loading address of ntosknrl.exe (windows kernel) LOLDriver Exploitation Physical Memory Mayhem
  • 98. Locating SYSTEM’s EPROCESS structure from Userland DHA_Userland_Find_SYSTEM_EPROCESS.exe explained… (c++) STEP 2: Finding SYSTEM’s EPROCCESS structure offset • We use LoadLibraryA() to load ntoskrnl.exe (Normally used for DLL’s – but .EXE, .SYS, and .DLL are the same PE file format • We use GetProcAddress() to find the export for PsInitialSystemProcess (EPROCESS pointer offset) ( GetProcAddress() is normally used to look up function addresses – but what it’s ACTUALLY doing is looking up EXPORT names/addresses  ) • We Add Kernelbase + PsInitialSystemProcess together for pointer to EPROCESS in memory LOLDriver Exploitation Physical Memory Mayhem
  • 99. LOLDriver Exploitation Physical Memory Mayhem • Privilege Escalation via Token theft 1) We Copy Token from EPROCESS w/ PID #4 (SYSTEM)
  • 100. LOLDriver Exploitation Physical Memory Mayhem • Privilege Escalation via Token theft 1) We Copy Token from EPROCESS w/ PID #4 (SYSTEM) 2) We Locate our EPROCESS PID #
  • 101. LOLDriver Exploitation Physical Memory Mayhem • Privilege Escalation via Token theft 1) We Copy Token from EPROCESS w/ PID #4 (SYSTEM) 2) We Locate our EPROCESS PID # 3) We copy SYSTEM Token into our EPROCESS
  • 102. LOLDriver Exploitation Physical Memory Mayhem • Privilege Escalation via Token theft Now running as SYSTEM
  • 103. LOLDriver Exploitation Physical Memory Mayhem • Privilege Escalation via Token theft DEMO!
  • 104. Exploitation – The Provider / Victim model LOLDriver Exploitation Physical Memory Mayhem
  • 105. LOLDriver Exploitation Physical Memory Mayhem • How KDU Works… The Victim-Provider Model
  • 106. LOLDriver Exploitation Physical Memory Mayhem • How KDU Works… The Victim-Provider Model
  • 107. LOLDriver Exploitation Physical Memory Mayhem • How KDU Works… The Victim-Provider Model
  • 108. LOLDriver Exploitation Physical Memory Mayhem • How KDU Works… The Victim-Provider Model
  • 109. LOLDriver Exploitation Physical Memory Mayhem • How KDU Works… The Victim-Provider Model
  • 110. LOLDriver Exploitation Physical Memory Mayhem typedef struct _KDU_PROVIDER { struct { provRegisterDriver RegisterDriver; //optional provUnregisterDriver UnregisterDriver; //optional provAllocateKernelVM AllocateKernelVM; //optional provFreeKernelVM FreeKernelVM; //optional provReadKernelVM ReadKernelVM; provWriteKernelVM WriteKernelVM; provVirtualToPhysical VirtualToPhysical; //optional provReadControlRegister ReadControlRegister; //optional provQueryPML4 QueryPML4Value; //optional provReadPhysicalMemory ReadPhysicalMemory; //optional provWritePhysicalMemory WritePhysicalMemory; //optional } Callbacks; } KDU_PROVIDER, * PKDU_PROVIDER; KDU Provider BYOVD Model
  • 111. LOLDriver Exploitation Physical Memory Mayhem Windows 11 – Working Providers #1 – IQVM64.sys #13 – AsIO2.sys #15 – GmerDrv.sys #20 – DBUtilDrv2.sys #22 – AsIO3.sys #26 – impoutx64.sys #27 – DirectIo64.sys #29 – ALSysIo64.sys KDU Provider BYOVD Model Win 11 (checked 07/11/23_
  • 112. PROCEXP152.SYS – Process Explorer – KDU’s Victim Driver It’s an old binary – so that means it was compiled without Code Integrity (CI) checks that prevent shellcode/ROP (ROP Is dead for other Reasons – see: KVA Shadow Stack) Set to have INIT section that is RWX – we can overwrite the IRP handlers for handlers such as IRP_MJ_CREATE IRP_MJ_CREATE is triggered when you open .PROCEXP152 with CreateFile (opening the file) This means we can write shellcode in there to do anything we want. LOLDriver Exploitation Physical Memory Mayhem
  • 113. Exploitation – Large Page Drivers LOLDriver Exploitation Physical Memory Mayhem
  • 114. Large Page Drivers It was discovered that Drivers could be added to a special list designated in the windows registry for system drivers known as ‘Large Page Drivers’ These Large Page Drivers – use large (2 MB) pages instead of the standard 4KB (0x1000 byte) pages. In doing so – They combine the .TEXT (RX) and .DATA (RW) sections of an executable into a single section That is both RW and RX ( so RWX) Example: GitHub - VollRagm/lpmapper: A mapper that maps shellcode into loaded large page drivers LOLDriver Exploitation Physical Memory Mayhem
  • 115. Large Page Drivers LOLDriver Exploitation Physical Memory Mayhem
  • 116. Exploitation – Protected Process Lights (PPL) LOLDriver Exploitation Physical Memory Mayhem
  • 117. • Protected Process Light (PPL) technology is used for controlling and protecting running processes and protecting them from infection by malicious code and the potentially harmful effects of other processes. These processes include: • Shutdown • Stream deployment • Access to virtual memory • Debugging • Copying of descriptors • Changing the memory working set • Changing and receiving information about the current state of the thread • Impersonation of threads (running process threads under a different account) READ MORE HERE: https://spikysabra.gitbook.io/kernelcactus/pocs/ppl-toggling LOLDriver Exploitation Physical Memory Mayhem PPL Elevation Since we can modify EPROCESS and its fields… Note: Ounce we toggle a process to be PPL we can dump LSASS for passwords!
  • 118. Exploitation – Handle elevation LOLDriver Exploitation Physical Memory Mayhem
  • 119. Handle elevation Since we can modify EPROCESS and its fields… • Each _EPROCESS structure holds within it a pointer to the _HANDLE_TABLE object, Named the ObjectTable. • This specific pointer, is to the head of the Handle Table, and contains a list of handles which appear one after the other in the memory. • Given read and write access to the _HANDLE_TABLE_ENTRY object itself, one can edit the GrantedAccessBits • handle created for SYNCHRONIZE, READ_CONTROL, QUERY_LIMITED_INFORMATION, can be escalated to FULL_CONTROL READ MORE HERE: https://spikysabra.gitbook.io/kernelcactus/pocs/handle-elevation LOLDriver Exploitation Physical Memory Mayhem
  • 120. Next Talk: Kernel Talks 0x04 BADUSB and the Gadget-FS filesystem LOLDriver Exploitation Physical Memory Mayhem