04 Evasion Funcion Call Obf
04 Evasion Funcion Call Obf
In this example we will study function call obfuscation. So what is this? Why malware developers and
red teamers need to learn it?
CreateThread
...
...
VirtualAlloc
VirtualProtect
...
So let’s create a global variable called VirtualAlloc, but it has to be a pointer pVirtualAlloc this
PROFESSEUR : M.DA ROS BTS SIO BORDEAUX - LYCÉE GUSTAVE EIFFEL
✦2/7✦
variable will store the address to VirtualAlloc:
And now we need to get this address via GetProcAddress, and we need to change the call
VirtualAlloc to pVirtualAlloc:
So no VirtualAlloc in import address table. Looks good. But, there is a caveat. When we try to
extract all the strings from the our binary we will see that VirtualAlloc string is still there. Let's do
it. run:
stings -n 8 hack2.exe
For that we will need encryption key and some string. And let's say string as cVirtualAlloc and
modify our code:
unsigned char cVirtualAlloc[] = { 0x25, 0xc, 0x11, 0x6, 0x10, 0x15,
0x1f, 0x24, 0xf, 0x1e, 0xa, 0x17 };
//...
pVirtualAlloc = (LPVOID(WINAPI *)(LPVOID, SIZE_T, DWORD,
DWORD))GetProcAddress(kernel, (LPCSTR)cVirtualAlloc);
python3 xor.py
strings -n 8 hack2.exe
and as you can see no VirtualAlloc in strings check. This is how you can actually obfuscate any
function in your code. It can be VirtualProtect or RtlMoveMemory, etc.
Checking correctness:
.\hack2.exe