Created
March 21, 2017 20:16
-
-
Save SiD3W4y/df071a72056abb392bd93709686d9f7f to your computer and use it in GitHub Desktop.
Assembly to raw shellcode or runnable program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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