- 论坛徽章:
- 11
|
本帖最后由 我爱你我的菜 于 2016-04-13 15:02 编辑
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h> // current, struct task_struct
#include <linux/slab.h> // kmalloc, kfree
#include <linux/fs.h> // SEEK_CUR, SEEK_SET, SEEK_END
#include <linux/stat.h>
#include <linux/fdtable.h> // struct fdtable, struct files_fdtable
#include <linux/fs_struct.h> // struct fs_struct, current->fs
#include <linux/file.h> // struct file, fget,fput
#include <linux/dirent.h> // struct linux_dirent64
#include <linux/syscalls.h>
#include <linux/kallsyms.h> // kallsyms_lookup_name
#include <asm/uaccess.h> // copy_*_user, VERIFY_WRITE, VERIFY_READ
#include <linux/socket.h>
MODULE_LICENSE("GPL");
static unsigned orig_cr0 = 0;
static void clear_cr0(void)
{
unsigned int cr0 = 0;
asm volatile("movl %%cr0, %%eax"
:"=a"(cr0));
orig_cr0 = cr0;
cr0 &= 0xfffeffff;
asm volatile ("movl %%eax, %%cr0"
:
:"a"(cr0));
}
static void reset_cr0(void)
{
asm volatile ("movl %%eax, %%cr0"
:
:"a"(orig_cr0));
}
static unsigned long**orig_sys_call_table = (unsigned long**)0xc1623060;
static int zf_hook_sys_openat(int index, int allmode, char *allptr, //
int dfd, const char __user *filename, int flags, umode_t mode)
{
printk("%s,%d => %d:%d:%p = %d,%s,%08x,%04o\n",
__FUNCTION__, __LINE__, index, allmode, allptr, dfd, filename, flags, mode);
return orig_sys_openat(/*index, allmode, allptr,*/ dfd, filename, flags, mode); //这里需要传入4个参数(系统调用头文件里是4个,传入四个劫持不成功),所以zf_hook_sys_openat也为7个参数
}
static int __init zf_kernel_hook_open_init(void)
{
int fd = 0;
char name[128];
mm_segment_t old_fs;
/////////////////////////////////////////////////////////////////
// 钩子操作
clear_cr0();
orig_sys_openat = (unsigned long*)(orig_sys_call_table[295]);
orig_sys_call_table[295] = (unsigned long*)zf_hook_sys_openat;
printk("%s,%d => %p 2 %p\n", __FUNCTION__, __LINE__, orig_sys_openat, zf_hook_sys_openat);
reset_cr0();
return 0;
}
static void __exit zf_kernel_hook_open_cleanup(void)
{
clear_cr0();
orig_sys_call_table[295] = (void *)orig_sys_openat;
orig_sys_call_table[5] = (void *)orig_sys_open;
orig_sys_call_table[39] = (void *)orig_sys_mkdir;
reset_cr0();
printk("%s,%d => removed\n", __FUNCTION__, __LINE__);
}
module_init(zf_kernel_hook_open_init);
module_exit(zf_kernel_hook_open_cleanup);
|
|