Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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