forked from H4ckF0rFun/elf_to_shellcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_shellcode.c
39 lines (30 loc) · 966 Bytes
/
run_shellcode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/syscall.h> /* For SYS_xxx definitions */
void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);
int munmap(void *addr, size_t length);
long syscall(long number, ...);
int main(int argc,char * argv[]){
if (argc != 2){
printf("Usage : %s <shellcode>\n",argv[0]);
exit(1);
}
FILE * fp = fopen(argv[1],"rb");
if(!fp){
return -1;
}
fseek(fp,0,SEEK_END);
int len = ftell(fp);
void * shellcode = mmap(0,len,PROT_READ|PROT_EXEC|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0);
if(shellcode == MAP_FAILED){
perror("mmap failed");
return -1;
}
fseek(fp,0,SEEK_SET);
fread(shellcode,1,len,fp);
__clear_cache(shellcode,len + (char*)shellcode);
((void (*)()) shellcode)();
return 0;
}