Skip to content

Instantly share code, notes, and snippets.

@P1kachu
Last active March 22, 2022 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save P1kachu/a1bf1afa2ecfc7c557be to your computer and use it in GitHub Desktop.
Save P1kachu/a1bf1afa2ecfc7c557be to your computer and use it in GitHub Desktop.
Hexdump to shellcode
#!/bin/bash
# Translate hexdump output to ready_to_send shellcode
# C'EST PAS OPTI
# MAIS JE M'EN FOUS
to_shellcode()
{
hexdump -x $1
counter=0
echo -n "TO CORRECT ENDIAN --> "
echo -n "\""
IFS=$'\n' # Split for each line
for line in `hexdump $1`; do # For each line in hexdump
IFS=" " # Split for each space
for byte in $(echo "$line" | cut -c 9-); do # For each byte pair in line
echo -n "\x"
echo -n $byte | cut -c 3- | awk '{printf $0}' # Print the seconde one
echo -n "\x"
echo -n $byte | cut -c -2 | awk '{printf $0}' # Print the first one
counter=$((counter + 2)) # MIGHT COUNT THE LAST NULL
# BYTE IF ODD NUMBER OF BYTES
done
IFS='\n'
done
echo "\""
echo "Length: $counter"
}
if [ $# -le 0 ]
then
echo "Usage: $0 NASM_FILE"
exit 1
fi
to_shellcode $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment