Asynchronous Procedure Call (APC) queuing to execute shellcode within the context of a thread. It uses key Windows APIs VirtualAlloc
, QueueUserAPC
, OpenThread
, and GetCurrentThreadId
to allocate memory, inject shellcode, and execute it by queuing an APC.
powershell -File sc_loader.ps1 -b64EncSc "<Base64EncodedXORedShellcode>" -scXorKey <Byte>
-b64EncSc
: The Base64 encoded XORed shellcode to be injected.-scXorKey
: XOR key to decrypt the shellcode.
-
Decryption of Shellcode:
- The provided shellcode is Base64 decoded and XOR decrypted using the specified key.
-
Dynamic Function Importing:
- The script dynamically imports critical Windows APIs (
VirtualAlloc
,QueueUserAPC
, etc.) using .NET reflection and DllImport.
- The script dynamically imports critical Windows APIs (
-
Memory Allocation:
- Allocates memory with
VirtualAlloc
to hold the decrypted shellcode with execution permissions (0x40
).
- Allocates memory with
-
APC Queuing:
- The current thread is opened with
OpenThread
using0x1F03FF
permissions, granting full control. - The shellcode address is queued as an APC to the thread using
QueueUserAPC
.
- The current thread is opened with
-
Triggering APC:
- The thread is put into an alertable state using
SleepEx
to execute the APC and run the shellcode.
- The thread is put into an alertable state using
-
Execution of Shellcode: The script demonstrates how to execute arbitrary code within a legitimate thread, a common technique in malware post-exploitation.
-
APC Queuing: APC injection is a stealthy method of running code in the context of another thread, bypassing common detection mechanisms.
-
Dynamic Imports: Dynamically resolving API functions at runtime complicates static analysis and signature-based detection.
-
Usage of
OpenThread
with0x1F03FF
permissions provides full access, potentially enabling malicious control over any thread. -
The use of APCs can evade user-mode hooks, making it effective in bypassing endpoint security solutions.
-
Memory permissions set with
0x40
allow both read and execute, a typical indicator for malicious shellcode injection.