-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdemo.c
executable file
·76 lines (62 loc) · 1.7 KB
/
demo.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <seccomp.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/prctl.h>
#include <linux/filter.h>
#include <seccomp.h>
#include <stddef.h>
#include<sys/socket.h>
#include<arpa/inet.h>
struct sock_filter filter[] = {
BPF_STMT(BPF_LD + BPF_W + BPF_ABS, (offsetof(struct seccomp_data, nr))),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __NR_read, 1, 0),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __NR_write, 0, 1),
BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW),
BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_KILL),
};
struct sock_fprog prog = {
.len = (unsigned short)(sizeof(filter) / sizeof(filter[0])),
.filter = filter,
};
struct sockaddr_in server = {
.sin_family = AF_INET,
.sin_addr.s_addr = INADDR_ANY,
.sin_port = 14597,
};
int main() {
void* region = mmap(NULL,
0x1000,
PROT_WRITE | PROT_EXEC | PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE,
-1,
0);
int socket_desc , client_sock , c;
struct sockaddr_in client;
//Create socket
socket_desc = socket(AF_INET , SOCK_STREAM , 0);
if (socket_desc == -1)
{
return 1;
}
//Bind
if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
{
return 1;
}
listen(socket_desc , 3);
c = sizeof(struct sockaddr_in);
client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
int recv_len = recv(client_sock, region, 0x1000, 0);
printf("Received %d bytes!\n", recv_len);
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
return 1;
}
if (prctl(PR_SET_SECCOMP, 2, &prog)) {
return 1;
}
((int(*)())region)();
return 0;
}