-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.c
84 lines (48 loc) · 1.37 KB
/
module.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
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kallsyms.h>
#include <linux/utsname.h>
#include <linux/slab.h>
#include "mantis.h"
#include "hijack.h"
MODULE_LICENSE("GPL");
ksym_hook_t* hook_uname;
void hexdump(unsigned char *mem, unsigned int length) {
int i;
printk(KERN_INFO "printing %d bytes from addr 0x%16lX\n", length, (unsigned long)mem);
for (i=0; i < length; i++) {
if ((i+1) % 8) {
printk("%02x ", mem[i]);
} else {
printk("%02x\n", mem[i]);
}
}
printk("\n");
}
asmlinkage long sys_newuname(struct new_utsname __user *name) {
long ret;
long (*call)(struct new_utsname __user*);
call = (long (*)(struct new_utsname __user*))hook_uname->addr;
ksym_unhook(hook_uname);
ret = call(name);
strncpy(name->sysname, "hoooked!", 8);
ksym_hook(hook_uname);
return ret;
}
static int __init bd_init(void) {
void *addr_uname;
addr_uname = (void*)kallsyms_lookup_name("sys_newuname");
if (!addr_uname) {
printk(KERN_INFO "Could not find uname...\n");
return -1;
}
hook_uname = ksym_hook_init(addr_uname, (void*)sys_newuname);
ksym_hook(hook_uname);
return 0;
}
static void __exit bd_release(void) {
ksym_unhook(hook_uname);
kfree(hook_uname);
}
module_init(bd_init);
module_exit(bd_release);