woody-woodpacker/shellcode_test.c

18 lines
582 B
C

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/mman.h>
char code[] = "\x31\xc0\x99\xb2\x0a\xff\xc0\x89\xc7\x48\x8d\x35\x12\x00\x00\x00\x0f\x05\xb2\x2a\x31\xc0\xff\xc0\xf6\xe2\x89\xc7\x31\xc0\xb0\x3c\x0f\x05\x2e\x2e\x57\x4f\x4f\x44\x59\x2e\x2e\x0a";
typedef void (*ShellcodeFunc)();
int main() {
ShellcodeFunc func = (ShellcodeFunc)code;
size_t pagesize = 4096; // 4KB, a common page size
uintptr_t page_start = (uintptr_t)code & ~(pagesize - 1);
mprotect((void *)page_start, pagesize, PROT_READ | PROT_EXEC);
func();
return 0;
}