openat函数系统劫持
openat函数系统劫持,通过cat /boot/System-map-3.8.13 | grep 查看sys_call_table 和sys_openat地址。劫持后函数做些操作,再调用原来函数。结果发现系统的sys_openat函数定义是四个。我调用需要传入7个!!! 本帖最后由 我爱你我的菜 于 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;
mm_segment_t old_fs;
/////////////////////////////////////////////////////////////////
// 钩子操作
clear_cr0();
orig_sys_openat = (unsigned long*)(orig_sys_call_table);
orig_sys_call_table = (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 = (void *)orig_sys_openat;
orig_sys_call_table = (void *)orig_sys_open;
orig_sys_call_table = (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);
这个是include/linux/syscalls.h里函数声明:asmlinkage long sys_openat(int dfd, const char __user *filename, int flags,
umode_t mode); @Godbach 各位解决了,谢谢 回复 5# 我爱你我的菜
欢迎分享原因。
回复 6# Godbach
内核中声明的函数加了asmlinkage,而用户自己通过地址定义的函数那没加,所以有冲突,具体原因没深究
页:
[1]