Skip to content

Instantly share code, notes, and snippets.

@fervagar
Last active June 18, 2021 11:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fervagar/45341ee012533721b0e8 to your computer and use it in GitHub Desktop.
Save fervagar/45341ee012533721b0e8 to your computer and use it in GitHub Desktop.
Bash script that prints out the shellcode of a binary in C string format (using objdump)
#!/bin/bash
## Prints the shellcode in little endian
RAW=$(objdump -d "$1" | grep "^ "|awk -F"[\t]" '{print $2}')
SHELLCODE=""
COUNT=0
for word in $RAW
do
SHELLCODE=${SHELLCODE}${word:6:2}${word:4:2}${word:2:2}${word:0:2}
((COUNT++))
done
echo $SHELLCODE | sed 's/ //g'| sed 's/.\{2\}/\\x&/g'|paste -d '' -s
echo "Shellcode size: ${COUNT} bytes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment