This is a quick lab to explore the sequence of APIs, that can execute shellcode by invoking a callback function passed to CreateThreadpoolWait.
Technique Overview
CreateEvent is used to create an event object with a Signaled state
RWX memory for the shellcode is allocated with VirtualAlloc and the shellcode is written there
CreateThreadpoolWait is used to create a wait object. 1st argument of the function is a callback function, that will be called once the wait ends (immediately in our case, since our waitable event is in the Signaled state from the start). We will pass the address of our shellcode (allocated in step 2) as the callback function
SetThreadpoolWait is used to set wait object to the wait object created in step 3
WaitForSingleObject is used to wait for the waitable object to become Signaled, but since our event (waitable) object was created with a Signaled state in step 1, our callback function specified in step 3 is called and the shellcode is executed right away: