Skip to content

Instantly share code, notes, and snippets.

@kkirsche
Last active July 10, 2018 18:32
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 kkirsche/ceb6f613f0cc8d53370752a7ebac3841 to your computer and use it in GitHub Desktop.
Save kkirsche/ceb6f613f0cc8d53370752a7ebac3841 to your computer and use it in GitHub Desktop.
Shellcode C Harness
#!/bin/bash
if [ $# -ne 1 ]; then
echo "{$0} <program to dump as shellcode>"
exit 1
fi
# https://www.commandlinefu.com/commands/view/6051/get-all-shellcode-on-binary-file-from-objdump
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'
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
unsigned char code[] = \
"SHELLCODE: ";
int main() {
printf("Shellcode Length: %d\n", strlen(code));
int (*ret)() = (int(*)())code;
ret()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment