Skip to content

Instantly share code, notes, and snippets.

@aczid
Created October 4, 2011 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aczid/1263176 to your computer and use it in GitHub Desktop.
Save aczid/1263176 to your computer and use it in GitHub Desktop.
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 (http://www.safemode.org/files/zillion/shellcode/tools/s-proc.c)
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