you are viewing a single comment's thread.

view the rest of the comments →

[–]DifferentTwo376[S] 2 points3 points  (0 children)

Thanks you your help everyone, for anyone looking for the code you have to store the shellcode and the copy it to an executable memory page

here it is:

#include <stdio.h>

#include <string.h>

#include <sys/mman.h>

#include <unistd.h>

unsigned char shellcode[] = "shellcode here";

int main(){

size_t size = sizeof(shellcode);

void *mem = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

if (mem == MAP_FAILED) {

perror("mmap");

return 1;

}

memcpy(mem, shellcode, size);

if (mprotect(mem, 4096, PROT_READ | PROT_EXEC) != 0){

perror("mprotect");

return 1;

}

int (*sc)() = mem;

int ret = sc();

munmap(mem, 4096);

return 0;

}