Asynchronous Procedure Calls (APCs) are Windows operating system mechanism that enables programs to execute tasks asynchronously while continuing to run other tasks.
Introduction
APC Injection is a more stealthy and advanced form of process injection, it is a well known technique with many variations. Heres a fiew:
QueueUserAPC APC Injection (Most common)
NtQueueApcThread APC Injection
Early Bird Injection
AtomBombimg
Reflective DLL Injection - Can be used in conjunction with APC.
Alertable State
Not all threads can run a queued APC function, only threads in an alterable state can do so.
QueueUserAPC Injection
Here is the most basic example of APC Injection utilizing the QueueUserAPC Win32 Function & CreateRemoteThreadEx. It works by allocating memory in an external process (VirtualAllocEx), copying the payload to the allocated memory, and executing it with QueueUserAPC. We use Sleep() as our basic function of choice to put the thread in an alertable state.
NOTE: Obviously this is unpractical as it's the most basic example. Thread hijacking, obfuscations, deletion, amongst other anti analysis techniques are all things that are required in modern malware development.