Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
bash aliases for shellcoding
# Some bash aliases for working with shellcode. i386-specific, no configuration etc.
# Probably of no use to professionals :)
# Thanks for the help, friends!
# outputs C array of shellcode from .s file, using s-proc (
function tocshellcode() { gcc -m32 "$@" -o tmp.elf -nostartfiles -nostdlib ; objcopy -O binary -j .text tmp.elf tmp.bin ; s-proc -p tmp.bin ; rm tmp.bin; rm tmp.elf; }
# Morphs the tocshellcode into a single string
function toshellcode() { echo `tocshellcode "$@" | tail -n+4 | tr -d '\n' | tr -d '\t' | tr -d '"' | tr -d ';'`; }
# Test .s in gdb
function testshellcode() { echo `tocshellcode "$@"` > testshellcode.c ; echo "int main(int argc, char* argv[]){int (*f)(); f = (int (*)()) shellcode; (int)(*f)();}" >> testshellcode.c ; gcc -m32 -z execstack -o testshellcode testshellcode.c; gdb ./testshellcode; }
# Disassemble shellcode string
function toasm() { perl -e 'print "'$@'" ' > tmp.bin ; objdump -D -b binary -mi386 tmp.bin; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment