Repository navigation
Expand file tree
/
Copy pathclient.c
More file actions
105 lines (90 loc) · 2.41 KB
/
Copy pathclient.c
File metadata and controls
105 lines (90 loc) · 2.41 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#define SIG_PROC_PROT 70
#define SIG_PROC_UNPROT 71
#define IOCTL_ARGP_SIZE 128
#define IOCTL_PROC_PROT 0xDEAD0001
#define IOCTL_PROC_UNPROT 0xDEAD0002
int sample_kill(char * arg) {
int fd = 0, r;
pid_t pid = atoi(arg);
char cmd[512];
/* find the process (`sleep 2000 &`) */
printf("current process list\n");
sprintf(cmd, "ps aux | grep %d | grep -v grep", pid);
r = system(cmd);
sleep(5);
/* enable the protection */
printf("protect the process\n");
kill(pid, SIG_PROC_PROT);
r = system(cmd);
printf("you can not kill the process\n");
sleep(5);
kill(pid, SIGKILL);
r = system(cmd);
sleep(5);
/* disable the protection */
printf("unprotect the process\n");
kill(pid, SIG_PROC_UNPROT);
r = system(cmd);
printf("now you can kill the process\n");
sleep(5);
kill(pid, SIGKILL);
r = system(cmd);
return 0;
}
int sample_ioctl(char * arg) {
int fd = 0, r;
pid_t pid = atoi(arg);
char cmd[512];
/* find the process (`sleep 2000 &`) */
printf("current process list\n");
sprintf(cmd, "ps aux | grep %d | grep -v grep", pid);
r = system(cmd);
sleep(5);
/* enable the protection */
printf("protect the process\n");
if (ioctl(fd, IOCTL_PROC_PROT, arg) != 0) {
printf("IOCTL_PROC_PROT error\n");
return -1;
}
r = system(cmd);
printf("you can not kill the process\n");
sleep(5);
kill(pid, SIGKILL);
r = system(cmd);
sleep(5);
/* disable the protection */
printf("unprotect the process\n");
if (ioctl(fd, IOCTL_PROC_UNPROT, arg) != 0) {
printf("IOCTL_PROC_UNPROT error\n");
return -1;
}
r = system(cmd);
printf("now you can kill the process\n");
sleep(5);
kill(pid, SIGKILL);
r = system(cmd);
return 0;
}
int main(int argc, char *argv[]) {
if (argc == 3) {
char * argp = (char *) malloc(IOCTL_ARGP_SIZE);
memset(argp, 0, IOCTL_ARGP_SIZE);
strcpy(argp, argv[2]);
if (strcmp("kill", argv[1])) {
sample_kill(argp);
return 0;
} else if (strcmp("ioctl", argv[1])) {
sample_ioctl(argp);
return 0;
}
}
printf("usage: %s [$pid] [kill|ioctl]\n", argv[0]);
return -1;
}