Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6333

getting system module export

$
0
0

I am programming a windows kernel mode driver and have been unable to find the issue with this code for the past three days. Basically the CallKernelFunc() function calls the get_system_module_export()function which always returns null. This means that there is either an issue with get_system_module_export() or get_system_module_base()

PVOID get_system_module_base(const char * module_name){    ULONG bytes = 0;    NTSTATUS status = ZwQuerySystemInformation(11, NULL, bytes, &bytes);    if (!bytes)    {        return NULL;    }    PRTL_PROCESS_MODULES modules = (PRTL_PROCESS_MODULES)ExAllocatePoolWithTag(NonPagedPool, bytes, 0x4e554c4c);    if (!NT_SUCCESS(status))        return NULL;    PRTL_PROCESS_MODULE_INFORMATION module = modules->Modules;    PVOID module_base = 0, module_size = 0;    for (ULONG i = 0; i < modules->NumberOfMods; i++)    {        if (strcmp((char*)module[i].FullPathName, module_name) == 0)        {            module_base = module[i].ImageBase;            module_size = (PVOID)module[i].ImageSize;            break;        }    }    if (modules)        ExFreePoolWithTag(modules, NULL);    if (module_base <= NULL)        return NULL;    return module_base;}PVOID get_system_module_export(const char * module_name, LPCSTR routine_name){    PVOID lpModule = get_system_module_base(module_name);    if (!lpModule) // this is where my issue is. I have been unsuccessful at fixing this as it is always triggered        return NULL;    return RtlFindExportedRoutineByName(lpModule, routine_name);}bool CallKernelFunc(void * KernelFuncAddy){    if (!KernelFuncAddy)        return false;    PVOID* function = reinterpret_cast<PVOID*> (get_system_module_export("\\SystemRoot\\System32\\drivers\\dxgkrnl.sys", "NtQueryCompositionSurfaceStatistics"));    if (!function)        return false; // this if statement is always triggered    BYTE orig[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ,0x00, 0x00, 0x00, 0x00 };     BYTE shell_code[] = { 0x48, 0xB8 }; // mov rax, xxx    BYTE shell_code_end[] = { 0xFF, 0xE0 }; // jmp rax    RtlSecureZeroMemory(&orig, sizeof(orig));    memcpy((PVOID)((ULONG_PTR)orig), &shell_code, sizeof(shell_code));    uintptr_t hook_address = reinterpret_cast<uintptr_t>(KernelFuncAddy);    memcpy((PVOID)((ULONG_PTR)orig + sizeof(shell_code)), &hook_address, sizeof(void*));    memcpy((PVOID)((ULONG_PTR)orig + sizeof(shell_code) + sizeof(void*)), &shell_code_end,     sizeof(shell_code_end));    write_to_read_only_memory(function, &orig, sizeof(orig));    return true;}

Viewing all articles
Browse latest Browse all 6333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>