linux系统调用替换的简单实现
/*==================================
LKM study
gcc -c open_sys.c
insmod open_sys.o
kernel verion 2.4.7.10 redhat7.2
===================================*/
#define MODULE
#define __KERNEL__
#ifdef MODVERSIONS
#include
#endif
#include
#include
#include
/* you can read entity.S*/
#define __NR_open 5
#define __NR_getuid 201
int uid;
asmlinkage int (*original_call)(const char *, int, int);
asmlinkage int (*getuid_call)();
asmlinkage int our_sys_open(const char *filename,
int flags,
int mode)
{
char ch;
if (uid == getuid_call()) {
printk("Opened file by %d: ", uid);
do {
get_user(ch, filename+i);
printk("%c", ch);
} while (ch != 0);
printk("\n");
}
return original_call(filename, flags, mode);
}
extern void *sys_call_table[];
asmlinkage int sys_newsyscall(int n){
printk("newsyscall: %d\n", n);
return 0;
}
int init_module(){
original_call = sys_call_table[__NR_open];
sys_call_table[__NR_open] = our_sys_open;
printk("Spying on UID:%d\n", uid);
getuid_call = sys_call_table[__NR_getuid];
return 0;
}
int cleanup_module(){
if (sys_call_table[__NR_open] != our_sys_open) {
printk("Aha,kernel hacking ");
}
sys_call_table[__NR_open] = original_call;
return 0;
}
阅读(768) | 评论(0) | 转发(0) |