Skip to content

Instantly share code, notes, and snippets.

@maugern
Last active July 31, 2019 11:49
Show Gist options
  • Save maugern/5a3acb8aee769ac0c78a81c9ceae6496 to your computer and use it in GitHub Desktop.
Save maugern/5a3acb8aee769ac0c78a81c9ceae6496 to your computer and use it in GitHub Desktop.
ELF to shellcode
#!/bin/bash
# Usage: elf2shell.sh a.out
GREEN='\033[1;32m'
RED='\033[1;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
SHELLCODE=$(objdump -d $1 | grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\\\x/g'|paste -d '' -s |sed 's/^/\"/'|sed 's/$/\"/g' | sed 's/\\\\/\\/g')
if [[ $SHELLCODE =~ ^\"(\\x[0-9a-fA-F]{2})+\"$ ]]; then
if [[ $SHELLCODE == *"x00"* ]]; then
echo -e "${YELLOW}WARNING:${NC} shellcode contain null byte."
fi
else
echo -e "${RED}ERROR:${NC} Bad shellcode format"
fi
echo -e "Shellcode lenght: ${GREEN}$(awk -F"x" '{print NF-1}' <<< "${SHELLCODE}")${NC}"
echo "$SHELLCODE"
#!/usr/bin/env python3
# Usage: python3 str2push.py "/bin/nc -lvp 4444"
import sys
s = sys.argv[1]
print ('\033[32;1mString length\033[00m: ' + str(len(s)))
stringList = [s[i:i+4] for i in range(0, len(s), 4)]
for item in stringList[::-1]:
print ('push\t' + '0x' + item[::-1].encode("ascii").hex() + '\t; ' + '\033[33;1m' + item[::-1] + '\033[00m')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment