Open In App

Dynamic Winapi Resolution

Dynamic winapi resolution is a technique used to modify the structure of the winapi call stack without physically altering the code. WinAPI functions are exported from the kernel32 and ntdll libraries, which Windows loads in memory at startup. Dynamic changes require a re-initialization of Windows API functions; however, when this happens is undefined, so this technique should not be used in production code.

Dynamic Winapi Resolution with GetProcAddress():

For dynamic winapi resolution with GetProcAddress(), a cost function is used to intelligently search through the exports of each exported function by trial and error until the targeted function is found. A callback function is then used to query the RegQueryValueExW function from kernel32.dll, which is called with a parameter that specifies an arbitrary base pointer in the process space where the targeted function should be resolved. If GetProcAddress() finds a matching DLL, it returns a pointer to an address in that DLL.



However, this would require a memory copy of the entire DLL, which will be very inefficient when many functions are being searched through. Instead, GetProcAddress() only searches within each individual exported function for one of its exports. When the targeted function is found and its address is passed in as an argument to GetProcAddress(), that address is returned and put into a code buffer.

Countermeasures: 

Conclusion:

WinAPI Resolution Techniques are used to resolve the Windows API functions at runtime. WinAPI functions are pushed into the stack by calling LoadLibrary() with a DLL name argument and then pushing the exported function addresses onto the stack by calling GetProcAddress(). This can be done manually, or by using a table look-up which also creates an evasion scenario where no code is executable in memory. WinAPI resolution is performed as part of code injection in a malicious process, as a method of reflective loading or as an evasion technique to avoid detection.



Article Tags :