-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidt_check.c
117 lines (91 loc) · 2.83 KB
/
idt_check.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
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
/*
** ~ Informations:
*/
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("[ EpiTek4 ] Strasbourg");
/*
** ~ Initializations:
*/
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;
unsigned long ptr_idt_table;
unsigned long pdt_gdt_table;
unsigned long old_interrupt;
static int hookIDT_init(void)
{
printk(KERN_ALERT "[MSG] deadlands h00k IDT - module init\n");
//ptr_idt_table = get_idt_addr();
//epiHook(INT_0, &my_handler);
//printk(KERN_ALERT "[MSG] deadlands h00k SYS - interrupt powned!\n");
return (0);
}
static void hookIDT_exit(void)
{
printk(KERN_ALERT "[MSG] deadlands h00k IDT - module exit\n");
// epiHook1(INT_0);
printk(KERN_ALERT "[MSG] deadlands h00k IDT - interrupt restored!\n");
}
/*
** ~ Functions:
*/
unsigned long get_idt_addr(void)
{
//unsigned char idtr[6];
//unsigned long idt;
//__asm__ volatile ("sidt %0" : "=m" (idtr));
//idt = *((unsigned long *)&idtr[2]);
//return (idt);
asm("sidt %0":"=m" (idtr));
printk(KERN_ALERT "IDT Base Address: %p\n", idtr.base);
//memcpy(&idt, (void *)(idtr.base + 16 * 0x80), sizeof(idt));
}
int epiHook(int nINT, void *new_interrupt)
{
struct s_descriptorIDT *idt;
unsigned long addr;
addr = (unsigned long)new_interrupt;
idt = (struct s_descriptorIDT *)ptr_idt_table;
old_interrupt = (unsigned long)get_interrupt_from_idt(nINT);
//idt[nINT].offset_hi = (unsigned short)(addr >> 16);
//idt[nINT].offset_lo = (unsigned short)(addr & 0x0000FFFF);
return (0);
}
int epiHook1(int nINT)
{
struct s_descriptorIDT *idt;
idt = (struct s_descriptorIDT *)ptr_idt_table;
idt[nINT].offset_hi = (unsigned short)(old_interrupt >> 16);
idt[nINT].offset_lo = (unsigned short)(old_interrupt & 0x0000FFFF);
return (0);
}
void *get_interrupt_from_idt(int nINT)
{
struct s_descriptorIDT *idt;
void *addr;
idt = &((struct s_descriptorIDT *)ptr_idt_table)[nINT];
printk(KERN_ALERT"idt_address = %lx", (unsigned long) idt);
printk(KERN_ALERT"idt_address_pointer = %p", (void *) idt);
printk(KERN_ALERT"idt member offset low address = %d", (idt -> offset_lo));
printk(KERN_ALERT"idt member offset high address = %d", (idt -> offset_hi));
addr = (void *)(((unsigned long)0xFFFFFFFF00000000) + (((unsigned long)idt->offset_hi) << 16) + ((unsigned long)(idt->offset_lo)));
return (addr);
}
asmlinkage void my_handler(struct pt_regs * regs, long err_code)
{
void (*old_int_handler)(struct pt_regs *, long) = (void *)old_interrupt;
printk(KERN_ALERT "[MSG] deadlands h00k IDT - INTERCEPT IDT^^\n");
(*old_int_handler)(regs, err_code);
}
module_init(hookIDT_init);
module_exit(hookIDT_exit);