I'm trying to call a process function in C# by creating an array of bytes, allocating memory, writing to allocated memory, then Creating Remote thread. As far as I know it's the usual way to execute shellcode through a process.
void WalkFunc()
{
byte[] asm = new byte[]
{
0x6A, 0x01, //PUSH 1
0x31, 0xC9, //XOR ECX, ECX
0xBA, 0x10, 0x00, 0x10, 0x00, //MOV EDX,00+10+00+10
0xA1, 0xB0, 0x01, 0x83, 0x00, //MOV EAX,DWORD PTR DS:[8301B0]
0xE8, 0x??, 0x??, 0x??, 0x??, //CALL 0x005378E4
0xC3 //RETN
};
Process proc = Process.GetProcessesByName("process")[0];
IntPtr hHandle = OpenProcess((int)ProcessAccessFlags.All, false, proc.Id);
IntPtr hAlloc = VirtualAllocEx(hHandle, IntPtr.Zero, (uint)asm.Length, AllocationType.Commit, MemoryProtection.ExecuteReadWrite);
UIntPtr bytesWritten = UIntPtr.Zero;
WriteProcessMemory(hHandle, hAlloc, asm, (uint) asm.Length, out bytesWritten);
uint iThreadId = 0;
IntPtr hThread = CreateRemoteThread(hHandle, IntPtr.Zero, 0, hAlloc, IntPtr.Zero, 0, out iThreadId);
}
As you can see, I'm unable to find the call offset. Indeed, after reading information, I got that call has no static offset so I have to calculate the jump address which is, if I'm not wrong, CALL . In my opinio, my TO is 0x005378E4. But I don't get how to find my FROM knowing that
VirtualAllocEx is assigning an address I can not predict at run time.
Thanks