Skip to content

Instantly share code, notes, and snippets.

@erayarslan
Created July 17, 2014 10:36
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 erayarslan/9dee06f361a03a05122b to your computer and use it in GitHub Desktop.
Save erayarslan/9dee06f361a03a05122b to your computer and use it in GitHub Desktop.
Run Your Shellcode with mman on Linux
// ( segmentation fault – core dumped problem solver )
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
int (*shellcode)();
char code[] = "\xeb\x19\x31\xc0\x31\xdb\x31\xd2\x31\xc9\xb0\x04\xb3\x01\x59\xb2\x05\xcd"\
"\x80\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xe2\xff\xff\xff\x68\x65\x6c\x6c\x6f";
int main(int argc, char **argv) {
void *p = mmap(0, sizeof(code), PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANON | MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) { perror("mmap"); exit(-1); }
memcpy(p, code, sizeof(code));
shellcode = p;
shellcode();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment