#include "kdmapper.hpp" HANDLE iqvw64edevicehandle; LONG WINAPI…
- User
#include "kdmapper.hpp"
HANDLE iqvw64e_device_handle;
LONG WINAPI SimplestCrashHandler(EXCEPTION_POINTERS* ExceptionInfo) { if (ExceptionInfo && ExceptionInfo->ExceptionRecord) Log(L"[!!] Crash at addr 0x" << ExceptionInfo->ExceptionRecord->ExceptionAddress << L" by 0x" << std::hex << ExceptionInfo->ExceptionRecord->ExceptionCode << std::endl); else Log(L"[!!] Crash" << std::endl);
if (iqvw64e_device_handle) intel_driver::Unload(iqvw64e_device_handle); return EXCEPTION_EXECUTE_HANDLER;}
int paramExists(const int argc, wchar_t** argv, const wchar_t* param) { size_t plen = wcslen(param); for (int i = 1; i < argc; i++) { if (wcslen(argv[i]) == plen + 1ull && _wcsicmp(&argv[i][1], param) == 0 && argv[i][0] == '/') { // with slash return i; } else if (wcslen(argv[i]) == plen + 2ull && _wcsicmp(&argv[i][2], param) == 0 && argv[i][0] == '-' && argv[i][1] == '-') { // with double dash return i; } } return -1; }
void help() { Log(L"\r\n\r\n[!] Incorrect Usage!" << std::endl); Log(L"[+] Usage: kdmapper.exe [--free][--mdl][--PassAllocationPtr] driver" << std::endl); }
bool callbackExample(ULONG64* param1, ULONG64* param2, ULONG64 allocationPtr, ULONG64 allocationSize, ULONG64 mdlptr) { UNREFERENCED_PARAMETER(param1); UNREFERENCED_PARAMETER(param2); UNREFERENCED_PARAMETER(allocationPtr); UNREFERENCED_PARAMETER(allocationSize); UNREFERENCED_PARAMETER(mdlptr); Log("[+] Callback example called" << std::endl);
/* This callback occurs before call driver entry and can be usefull to pass more customized params in the last step of the mapping procedure since you know now the mapping address and other things */ return true;}
int wmain(const int argc, wchar_t** argv) { SetUnhandledExceptionFilter(SimplestCrashHandler);
bool free = paramExists(argc, argv, L"free") > 0; bool mdlMode = paramExists(argc, argv, L"mdl") > 0; bool passAllocationPtr = paramExists(argc, argv, L"PassAllocationPtr") > 0; if (free) { Log(L"[+] Free pool memory after usage enabled" << std::endl); } if (mdlMode) { Log(L"[+] Mdl memory usage enabled" << std::endl); } if (passAllocationPtr) { Log(L"[+] Pass Allocation Ptr as first param enabled" << std::endl); } int drvIndex = -1; for (int i = 1; i < argc; i++) { if (std::filesystem::path(argv[i]).extension().string().compare(".sys") == 0) { drvIndex = i; break; } } if (drvIndex <= 0) { help(); return -1; } const std::wstring driver_path = argv[drvIndex]; if (!std::filesystem::exists(driver_path)) { Log(L"[-] File " << driver_path << L" doesn't exist" << std::endl); return -1; } iqvw64e_device_handle = intel_driver::Load(); if (iqvw64e_device_handle == INVALID_HANDLE_VALUE) return -1; std::vector<uint8_t> raw_image = { 0 }; if (!utils::ReadFileToMemory(driver_path, &raw_image)) { Log(L"[-] Failed to read image to memory" << std::endl); intel_driver::Unload(iqvw64e_device_handle); return -1; } NTSTATUS exitCode = 0; if (!kdmapper::MapDriver(iqvw64e_device_handle, raw_image.data(), 0, 0, free, true, mdlMode, passAllocationPtr, callbackExample, &exitCode)) { Log(L"[-] Failed to map " << driver_path << std::endl); intel_driver::Unload(iqvw64e_device_handle); return -1; } if (!intel_driver::Unload(iqvw64e_device_handle)) { Log(L"[-] Warning failed to fully unload vulnerable driver " << std::endl); } Log(L"[+] success" << std::endl);}
make it wait for me to close it
- Assistant
To make the program wait for user input before closing, you can simply add a
std::cin.get()call at the end of thewmainfunction, like this:// ... if (!intel_driver::Unload(iqvw64e_device_handle)) { Log(L"[-] Warning failed to fully unload vulnerable driver " << std::endl); } Log(L"[+] success" << std::endl); std::wcout << L"Press enter to exit..." << std::endl; std::cin.get(); return 0; }This will wait for the user to press enter before exiting the program.
- User
why is it auto closing
- Assistant
The program may be auto-closing because it is reaching the end of the
mainfunction and terminating before you have a chance to see any output on the console.By adding
std::cin.get()at the end of themainfunction, you are forcing the program to wait for user input before terminating. This gives you a chance to see any output on the console before the program exits. - User
'kdmapper.exe' (Win32): Loaded 'C:\Users\loris\OneDrive\Documents\testing\x64\Debug\kdmapper.exe'. Symbols loaded. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140_1d.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. 'kdmapper.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. The thread 0x4d5c has exited with code 4294967295 (0xffffffff). The thread 0x4344 has exited with code 4294967295 (0xffffffff). The thread 0x36cc has exited with code 4294967295 (0xffffffff). The program '[248] kdmapper.exe' has exited with code 4294967295 (0xffffffff).
- Assistant
It seems like the program is still terminating before anything useful is printed to the console.
One possible reason could be an issue with the
Logfunction. Make sure that it properly flushes the output stream after writing to it, so that the text is immediately visible on the console.Another possible reason could be an issue with the
kdmapperlibrary itself. You could try adding somestd::coutcalls throughout the code to see where the program is getting stuck or terminating early. This way, you can narrow down the issue and fix it accordingly. - User
do it for me
- Assistant
Sure, here's an updated version of
mainthat includes some additional debugging output:int wmain(const int argc, wchar_t** argv) { SetUnhandledExceptionFilter(SimplestCrashHandler); bool free = paramExists(argc, argv, L"free") > 0; bool mdlMode = paramExists(argc, argv, L"mdl") > 0; bool passAllocationPtr = paramExists(argc, argv, L"PassAllocationPtr") > 0; if (free) { Log(L"[+] Free pool memory after usage enabled" << std::endl); } if (mdlMode) { Log(L"[+] Mdl memory usage enabled" << std::endl); } if (passAllocationPtr) { Log(L"[+] Pass Allocation Ptr as first param enabled" << std::endl); } int drvIndex = -1; for (int i = 1; i < argc; i++) { if (std::filesystem::path(argv[i]).extension().string().compare(".sys") == 0) { drvIndex = i; break; } } if (drvIndex <= 0) { help(); return -1; } const std::wstring driver_path = argv[drvIndex]; if (!std::filesystem::exists(driver_path)) { Log(L"[-] File " << driver_path << L" doesn't exist" << std::endl); return -1; } iqvw64e_device_handle = intel_driver::Load(); if (iqvw64e_device_handle == INVALID_HANDLE_VALUE) return -1; std::vector<uint8_t> raw_image = { 0 }; if (!utils::ReadFileToMemory(driver_path, &raw_image)) { Log(L"[-] Failed to read image to memory" << std::endl); intel_driver::Unload(iqvw64e_device_handle); return -1; } Log(L"[+] Attempting to map driver: " << driver_path << std::endl); NTSTATUS exitCode = 0; if (!kdmapper::MapDriver(iqvw64e_device_handle, raw_image.data(), 0, 0, free, true, mdlMode, passAllocationPtr, callbackExample, &exitCode)) { Log(L"[-] Failed to map " << driver_path << std::endl); intel_driver::Unload(iqvw64e_device_handle); return -1; } if (!intel_driver::Unload(iqvw64e_device_handle)) { Log(L"[-] Warning failed to fully unload vulnerable driver " << std::endl); } Log(L"[+] Success" << std::endl); std::wcout << L"Press enter to exit..." << std::endl; std::cin.get(); return 0; }This version prints out the driver path before attempting to map it, as well as a success message after mapping is complete.
It also includes a
std::cin.get()call at the end to keep the console window open after the program terminates. - User
i get error exited with code 4294967295 on windows 10
- Assistant
The error code
4294967295usually indicates an unhandled exception or a crash in the program.Here are some things you can try to resolve the issue:
-
Check your exception handling code: Make sure that your crash handler is properly catching any exceptions that are thrown by the program, and that it is logging them to the console or a log file. If your crash handler is not working as expected, the program may be terminating before you have a chance to see any helpful output.
-
Use a debugger: Try running the program under a debugger like Visual Studio or WinDbg. This will allow you to attach to the process and see where it is crashing, and get more detailed information about the error.
-
Check your code for memory leaks or buffer overflows: Use a memory profiling tool like valgrind or the Visual Studio Debugger to check your code for memory leaks or buffer overflows. These types of errors can cause unpredictable behavior and crashes in your program.
-
Verify driver compatibility: Make sure that the driver you are attempting to map is compatible with your version of Windows. Drivers compiled for an older version of Windows may not work correctly on a newer version of Windows, and can cause crashes or other issues.
-
Check your anti-virus software: Some anti-virus software may interfere with the operation of your program. Try temporarily disabling any anti-virus software on your system and see if the program runs correctly without it. If it does, you may need to configure your anti-virus software to allow your program to run.
-