使用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]。
设为首页 - 加入收藏 - 关于我们 - 广告合作 - 友情链接 - 投稿与建议 - 版权申明 - 帮助中心
Copyright©2004--2007 www.ithov.com IT坊资讯网版权所有
网站客服QQ群 ①群15569476 ②群19439244 ③群20730522 ④群31220781 ⑤群7190232
未经授权禁止转载、摘编、复制、盗链或建立镜像.如有违反,追究法律责任.
鄂ICP备05000249号
本站提供的所有资源均来自互联网,下载纯属学习交流之用,如侵犯您的版权请与我们联系,我们会尽快改正!请在下载24小时后删除