I'm trying to Execute a binary from Memory ( Without touching disk ) Here is some code that i tried but it's failed with error. This is what i've tried:
import(
"fmt"
"io/ioutil"
"syscall"
"time"
"unsafe"
)
const (
mfdCloexec = 0x0001
memfdCreate = 319
AbsPathOfExecutable = "Path\\To\\Executable\\File"
NameOfExecutable = "ProcessName"
)
func main() {
fdName := ""
fd, _, _ := syscall.Syscall(memfdCreate, uintptr(unsafe.Pointer(&fdName)), uintptr(mfdCloexec), 1,0)
buffer, _ := ioutil.ReadFile(AbsPathOfExecutable)
_, _ = syscall.Write(syscall.Handle(fd), buffer)
fdPath := fmt.Sprintf("/proc/self/fd/%d", fd)
_ = syscall.Exec(fdPath, []string{NameOfExecutable}, nil)
time.Sleep(25 * time.Second)
fmt.Println("Done...")
time.Sleep(3*time.Second)
}
This code will failure with error:
fatal error: unexpected signal during runtime execution
[signal 0x80000003 code=0x0 addr=0x0 pc=0x6a612e]
Go Version:
go version go1.15.5 windows/amd64
If anyone can help me to figure out what's wrong with this code or give some references that could help me to execute a binary from memory in windows, it would be very nice and help full.
User contributions licensed under CC BY-SA 3.0