27 lines
		
	
	
		
			893 B
		
	
	
	
		
			C
		
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			893 B
		
	
	
	
		
			C
		
	
	
	
| #include <stdio.h>
 | |
| #include <stdint.h>
 | |
| #include <unistd.h>
 | |
| #include <sys/mman.h>
 | |
| 
 | |
| // Define the shellcode
 | |
| 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";
 | |
| 
 | |
| // Declare a function pointer with no arguments and no return value
 | |
| typedef void (*ShellcodeFunc)();
 | |
| 
 | |
| int main() {
 | |
|     // Create a function pointer of the appropriate type and point it to the shellcode
 | |
|     ShellcodeFunc func = (ShellcodeFunc)code;
 | |
| 
 | |
|     // Make the memory containing the shellcode executable
 | |
|     // Using a reasonable default page size
 | |
|     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);
 | |
| 
 | |
|     // Call the shellcode
 | |
|     func();
 | |
| 
 | |
|     return 0;
 | |
| }
 |