DLL unhooking is a methodology employed to circumvent detection by endpoint detection and response (EDR) systems. EDRs employ hooks within DLLs that contain Windows API functions to monitor for malicious activity. A comprehensive catalog of EDR hooks is readily accessible at Mr-Un1k0d3rs Github.
Usage
std::string dllName = "ntdll.dll"
int pid = [Code to get process ID of any function]
remoteunhook(dllName, int pid)
POC
Open x64dbg.exe and attach it to the target process (ex. procexp64.exe)
Identify a hooked function, I will search for "ZwMapViewOfSection":
Find ZwMapViewOfSection
E9? Hooked
E9 indicates ZwMapViewOfSection is hooked. Unhooked ntdll functions are expected to return have BX.
Detach x64dbg.exe and execute the remote dll unhooking tool against the remote process.
Re-attach x64dbg.exe and return to the ZwMapViewOfSection
If successful, there will be a BX value instead of E9
B8!
NOTE
The code below will only work with NTDLL.DLL, according to the research where I got the main base of this code from, ntdll doesn't need image base relocations. I have experimental code I have been working on at the bottom of this article but it has no been tested as I am still learning as I go!
Code
UNTESTED CODE:
I don't fully understand everything about PE files yet. This is code that I developed with a lot of research and asking ChatGPT what was wrong with my code LOL. USE AT OWN RISK.