当前位置: 首页 > 图文教程 > 服务器 > Linux服务器 > 在linux操作系统中如何截获系统调用
使用LinuxKernelModule的一般目的就是扩展系统的功能,或者给某些特殊的设备提供驱动等等。其实利用Linux内核模块我们还可以做一些比较“黑客”的事情,例如用来拦截系统调用,然后自己处理。嘿嘿,有意思的说。
下面给出一个简单的例子,说明了其基本的工作过程。
| 以下为引用的内容: #defineMODULE #define__KERNEL__ #include<linux/module.h> #include<linux/kernel.h> #include<asm/unistd.h> #include<sys/syscall.h> #include<linux/types.h> #include<linux/dirent.h> #include<linux/string.h> #include<linux/fs.h> #include<linux/malloc.h> externvoid*sys_call_table[];/*sys_call_tableisexported,sowecanaccessit*/ int(*orig_mkdir)(constchar*path);/*theoriginalsystemcall*/ inthacked_mkdir(constchar*path) { return0;/*everythingisok,buthenewsystemcall doesnothing*/ } intinit_module(void)/*modulesetup*/ { orig_mkdir=sys_call_table[SYS_mkdir]; sys_call_table[SYS_mkdir]=hacked_mkdir; return0; } voidcleanup_module(void)/*moduleshutdown*/ { sys_call_table[SYS_mkdir]=orig_mkdir;/*setmkdirsyscalltotheorigal one*/ } |
1、查找出感兴趣的系统调用在系统内核数组中的入口位置。可以参看include/sys/syscall.h文件。
2、将内核中原来的调用函数对应的指针sys_call_table[X]保留下来。
3、将我们新的伪造的系统函数指针给sys_call_table[X]。
评论 (0) All