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
| PVOID GetSSDTEntryByNtdll(IN PCSTR name) { HANDLE hFile = NULL; HANDLE hSection = NULL; PVOID DllBase = NULL; SIZE_T ViewSize = 0; NTSTATUS Status = STATUS_SUCCESS; IO_STATUS_BLOCK IoStatus = { 0 }; OBJECT_ATTRIBUTES ObjAttrib = { 0 }; UNICODE_STRING NtDllName = { 0 }; PUCHAR FuncAddr = NULL; ULONG Index = 0; PVOID KernelAddr = NULL; PSYSTEM_SERVICE_TABLE SSDTAddr = NULL; #ifdef AMD64 RtlInitUnicodeString(&NtDllName, L"\\SystemRoot\\SysWOW64\\ntdll.dll"); #else RtlInitUnicodeString(&NtDllName, L"\\SystemRoot\\System32\\ntdll.dll"); #endif InitializeObjectAttributes(&ObjAttrib, &NtDllName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); Status = ZwOpenFile(&hFile, FILE_GENERIC_READ, &ObjAttrib, &IoStatus, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT); if (!NT_SUCCESS(Status)) return NULL; InitializeObjectAttributes(&ObjAttrib, NULL, OBJ_KERNEL_HANDLE, NULL, NULL); Status = ZwCreateSection(&hSection, SECTION_MAP_READ, &ObjAttrib, 0, PAGE_READONLY, 0x01000000, hFile); if (!NT_SUCCESS(Status)) { ZwClose(hFile); return NULL; } Status = ZwMapViewOfSection(hSection, ZwCurrentProcess(), &DllBase, 0, 0, 0, &ViewSize, ViewShare, MEM_TOP_DOWN, PAGE_READONLY); if (!NT_SUCCESS(Status)) { ZwClose(hSection); ZwClose(hFile); return NULL; } FuncAddr = GetExportFuncAddr(DllBase, name); if (!FuncAddr) { ZwUnmapViewOfSection(ZwCurrentProcess(), DllBase); ZwClose(hSection); ZwClose(hFile); return NULL; } Index = *(PULONG)(FuncAddr + 1); ZwUnmapViewOfSection(ZwCurrentProcess(), DllBase); ZwClose(hSection); ZwClose(hFile); KernelAddr = GetKernelAddress(); SSDTAddr = GetSSDTAddress(); if (KernelAddr && SSDTAddr) { if (Index > SSDTAddr->NumberOfServices) return NULL; return (PVOID)((PUCHAR)SSDTAddr->ServiceTableBase + (((PLONG)SSDTAddr->ServiceTableBase)[Index] >> 4)); } return NULL; }
|