Skip to content

Instantly share code, notes, and snippets.

@SiD3W4y
Created March 21, 2017 20:16
Show Gist options
  • Save SiD3W4y/df071a72056abb392bd93709686d9f7f to your computer and use it in GitHub Desktop.
Save SiD3W4y/df071a72056abb392bd93709686d9f7f to your computer and use it in GitHub Desktop.
Assembly to raw shellcode or runnable program
#!/usr/bin/zsh
ARCH="elf64"
TARGET=""
MODE="raw"
while getopts "a:f:e" arg; do
case $arg in
a)
echo "Setting arch to -> $OPTARG"
ARCH=$OPTARG
;;
f)
TARGET=$OPTARG
;;
e)
MODE="exec"
;;
esac
done
if [ -z "$TARGET" ];then
echo "Error : No file specified"
exit -1
fi
echo "Compiling $TARGET (arch $ARCH)"
nasm -f $ARCH $TARGET -o .tmp_sc
if [[ "$MODE" == "exec" ]];then
ld .tmp_sc -o payload.elf
else
objcopy -O binary -j .text .tmp_sc payload.bin
echo "Extracted shellcode of length -> $(wc -c payload.bin)"
fi
rm .tmp_sc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment