Handle2Self
Get a handle from current process and creating a new thread
Last updated
Was this helpful?
Get a handle from current process and creating a new thread
Last updated
Was this helpful?
I first saw this in a public loader on GitHub called "GregsBestFriend":
In this technique, we use two well-known Windows APIs for process injection, VirtualAllocEx
and CreateRemoteThread
. using these APIs in remote process injection makes the loader look very suspicious and will be detected by most AVs. but interestingly enough, if we use the same set of APIs to allocate memory in local process space and then creating a new local thread, it goes unnoticed even by some of the best AV/EDR products out there (at least it used to be like that the last time i checked). so we are using the same APIs but instead of passing the handle of a remote process, we use the handle of current process.
Execution Flow:
Get a handle to local process using OpenProcess
Allocate memory using VirtualAllocEx
Write shellcode to allocated memoey with WriteProcessMemory
Create new local thread using CreateRemoteThread
using current process handle
Release the allocated memory and close the local thread handle
Code: