-
Notifications
You must be signed in to change notification settings - Fork 495
Open
Labels
Description
Environment: Win10 1709
DLL: C:\Windows\SysWOW64\user32.dll
- I firstly use command
python Python\ConvertToShellcode.py user32.dllconvert user32.dll to user32.bin. - Then I change the code in Native\Loader.cpp to call API MessageBoxA after loading the user32.dll and compile the Native project using Visual Studio 2015 Debug x86.
// Only set the first page to RWX
// This is should sufficiently cover the sRDI shellcode up top
if (VirtualProtect(finalShellcode, sysInfo.dwPageSize, PAGE_EXECUTE_READWRITE, &dwOldProtect1)) {
RDI rdi = (RDI)(finalShellcode);
printf("[+] Executing RDI\n");
UINT_PTR hLoadedDLL = rdi(); // Excute DLL
free(finalShellcode); // Free the RDI blob. We no longer need it.
/*Function exportedFunction = (Function)GetProcAddressR(hLoadedDLL, "SayGoodbye");
if (exportedFunction) {
printf("[+] Calling exported functon\n");
exportedFunction();
}*/
MyMessageBoxA exportedFunction = (MyMessageBoxA)GetProcAddressR(hLoadedDLL, "MessageBoxA");
if (exportedFunction) {
printf("[+] Calling exported functon\n");
exportedFunction(0, "Hello", "user32.dll message", 1);
}
}
----
typedef int (WINAPI *MyMessageBoxA)(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType);
- Then use command
Native.exe user32.binto load the shellcode.
The exe crashed and report a error :
0x7774CCC5 (ntdll.dll) (located at Native.exe) Exception: 0xC0000005: Access violation reading location 0x00000008.
I ensure that the GetProcAddressR return the correct address of MessageBoxA.
I found that the 0x7774CCC5 belongs to ntdll.dll!RtlAllocateHeap function:

Do you have comments that which possible cause this problem? My conclusion is that reflective loading a DLL written by ourselves works fine but loading a system dll(ntdll, user32..) will not work. It seems that there is something the loader doesn't handle when load the system dll into memory.