- 论坛徽章:
- 0
|
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fdtable.h>
#include <linux/binfmts.h>
#include <linux/syscalls.h>
#include <linux/dirent.h>
#include <linux/dcache.h>
#include <linux/mount.h>
#include <linux/fs_struct.h>
#include <asm/unistd_32.h>
static unsigned long sys_call_tab =0x0000000000000000;
module_param(sys_call_tab, ulong, S_IRUGO);
typedef asmlinkage long (*SYS_EXECVE)(const char __user *filename,
const char __user *const __user *argv,
const char __user *const __user *envp,
struct pt_regs *regs);
SYS_EXECVE old_sys_execve;
static long clear_and_return_cr0(void)
{
unsigned long cr0 = 0;
unsigned long ret = 0;
asm volatile ("movl %%cr0, %%eax":"=a"(cr0));
ret = cr0;
cr0 &=0xfffeffff;
asm volatile ("movl %%eax, %%cr0"
:
: "a"(cr0));
return ret;
}
void setback_cr0(unsigned int val)
{
asm volatile ("movl %%eax, %%cr0"
:
: "a"(val));
}
asmlinkage long new_sys_execve(const char __user *filename,
const char __user *const __user *argv,
const char __user *const __user *envp,
struct pt_regs *regs)
{
return old_sys_execve(filename , argv, envp, regs);
}
int __init monitor_init(void)
{
unsigned int orig_cr0 = 0;
unsigned long* sys_call_table = sys_call_tab;
old_sys_execve = (SYS_EXECVE)sys_call_table[__NR_execve];
orig_cr0 = clear_and_return_cr0();
sys_call_table[__NR_execve] = new_sys_execve;
setback_cr0(orig_cr0);
printk("sys_execve : %p , syscall : %p __NR_execve : %d\n", old_sys_execve, sys_call_table, __NR_execve);
return 0;
}
void __exit monitor_exit(void)
{
unsigned int orig_cr0 = 0;
unsigned long* sys_call_table = sys_call_tab;
orig_cr0 = clear_and_return_cr0();
sys_call_table[__NR_execve] = old_sys_execve;
setback_cr0(orig_cr0);
return;
}
module_init(monitor_init);
module_exit(monitor_exit);
MODULE_LICENSE("GPL"); |
|