作者selph
前言
窥探Ring0漏洞世界:未初始化堆变量漏洞
哪怕是类似原理的都用,在利用方式上也总能带来很多新鲜感,每次都有新的长见识,不断的感叹和震撼
实验环境:
•虚拟机:Windows 7 x86
•物理机:Windows 10 x64
•软件:IDA,Windbg,VS2022
漏洞分析
老样子,先IDA找到该漏洞的触发函数TriggerUninitializedMemoryPagedPool,分析函数是如何存在漏洞的:
首先依然是申请内存0xf0字节
然后接着取用户参数地址的值,不是魔数就跳转,是魔数就向下走,填充魔数和固定的回调到结构里,然后填充申请内存的多余部分
最后,判断值,如果输入的地址的值是0,则调用偏移4的回调函数:
查看一下漏洞函数源码:
///
/// Trigger the uninitialized memory in PagedPool Vulnerability
///
///The pointer to user mode buffer /// NTSTATUS NTSTATUS TriggerUninitializedMemoryPagedPool( _In_ PVOID UserBuffer ) { ULONG_PTR UserValue = 0; ULONG_PTR MagicValue = 0xBAD0B0B0; NTSTATUS Status = STATUS_SUCCESS; PUNINITIALIZED_MEMORY_POOL UninitializedMemory = NULL; PAGED_CODE(); __try { // // Verify if the buffer resides in user mode // ProbeForRead(UserBuffer, sizeof(UNINITIALIZED_MEMORY_POOL), (ULONG)__alignof(UCHAR)); // // Allocate Pool chunk // UninitializedMemory = (PUNINITIALIZED_MEMORY_POOL)ExAllocatePoolWithTag( PagedPool, sizeof(UNINITIALIZED_MEMORY_POOL), (ULONG)POOL_TAG ); if (!UninitializedMemory) { // // Unable to allocate Pool chunk // DbgPrint("[-] Unable to allocate Pool chunkn"); Status = STATUS_NO_MEMORY; return Status; } else { DbgPrint("[ ] Pool Tag: %sn", STRINGIFY(POOL_TAG)); DbgPrint("[ ] Pool Type: %sn", STRINGIFY(PagedPool)); DbgPrint("[ ] Pool Size: 0x%zXn", sizeof(UNINITIALIZED_MEMORY_POOL)); DbgPrint("[ ] Pool Chunk: 0x%pn", UninitializedMemory); } // // Get the value from user mode // UserValue = *(PULONG_PTR)UserBuffer; DbgPrint("[ ] UserValue: 0x%pn", UserValue); DbgPrint("[ ] UninitializedMemory Address: 0x%pn", &UninitializedMemory); // // Validate the magic value // if (UserValue == MagicValue) { UninitializedMemory->Value = UserValue; UninitializedMemory->Callback = &UninitializedMemoryPagedPoolObjectCallback; // // Fill the buffer with ASCII 'A' // RtlFillMemory( (PVOID)UninitializedMemory->Buffer, sizeof(UninitializedMemory->Buffer), 0x41 ); // // Null terminate the char buffer // UninitializedMemory->Buffer[(sizeof(UninitializedMemory->Buffer) / sizeof(ULONG_PTR)) - 1] = '