linu不同版本间驱动加载方法

上传人:博****1 文档编号:469173107 上传时间:2023-12-18 格式:DOC 页数:21 大小:84KB
返回 下载 相关 举报
linu不同版本间驱动加载方法_第1页
第1页 / 共21页
linu不同版本间驱动加载方法_第2页
第2页 / 共21页
linu不同版本间驱动加载方法_第3页
第3页 / 共21页
linu不同版本间驱动加载方法_第4页
第4页 / 共21页
linu不同版本间驱动加载方法_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《linu不同版本间驱动加载方法》由会员分享,可在线阅读,更多相关《linu不同版本间驱动加载方法(21页珍藏版)》请在金锄头文库上搜索。

1、WebZineIntroductionbyrootFlashsky访谈byflashskyStruts2框架安全缺陷bykxlzx重谈IP欺骗技术bypapayaFuzz客户端存储对象,寻找clientddosbywoyigui应用软件缺陷利用的一点心得(Webkit篇)bywushiBypassingLinuxkernelmoduleversioncheckbywztACS-ActiveContentSignaturesbyEduardoVelaNava卡巴虚拟机启发式查毒的绕过方法bydangdangdBypassingLinuxkernelmoduleversioncheckBywzt1

2、、为什么要突破模块验证2、内核是怎么实现的3、怎样去突破4、总结5、参考6、附录1、为什么要突破模块验证Linux内核版本很多,升级很快,2个小内核版本中内核函数的定义可能都不一样,为了确保不一致的驱动程序导致kerneloops,开发者加入了模块验证机制。它在加载内核模块的时候对模块进行校验,如果模块与主机的一些环境不一致,就会加载不成功。看下面一个例子,它简单的输岀当期系统中的模块列表:#include#include#include#include#include#includeMODULE_LICENSE(GPL);MODULE_AUTHOR(wzt);structmodule*m=&

3、_this_module;intprint_module_test(void)structmodule*mod;list_for_each_entry(mod,&m-list,list)printk(%sn,mod-name);returnNULL;staticintlist_print_init(void)printk(loadlist_printmodule.n);print_module_test();return0;staticvoidlist_print_exit(void)printk(unloadlist_printmodule.n);module_init(list_print

4、_init);module_exit(list_print_exit);我们在centos5.3环境中编译一下:#1SMPWedJan2110:44:23EST2009i686i686i386GNU/Linux然后拷贝到另一台主机centos5.1xen上:rootlocalhost#1SMPMonNov1203:26:12EST2007i686i686i386GNU/Linux用insmod加载:rootlocalhost#insmodlist.koinsmod:errorinsertinglist.ko:-1Invalidmoduleformat报错了,在看下dmesg的信息:rootlo

5、calhost#dmesg|tail-n1list:disagreesaboutversionofsymbolstruct_module先不管这是什么,总之我们的模块在另一台的主机中加载失败。通常的做法是要在主机中对源代码进行编译,然后才能加载成功,但是如果主机中缺少内核编译环境的话,我们的rootkit就不能编译,也不能安装在主机之中,这是多么尴尬的事情:)。没错,这就是linuxkernel开发的特点,你别指望像windows驱动一样,编译一个驱动,然后可以满世界去装a_a.些rootkit开发者抛弃了lkm类型rk的开发,转而去打kmem,mem的注意,像sk,moodnt这样的rk大家

6、都喜欢,可以在用户层下动态patch内核,不需要编译环境,wget下来,install即可。但是它也有很多缺点,比如很不稳定,而且在后内核已经取消了kmem这个设备,mem文件也做了映射和读写的限制。rk开发者没法继续sk的神话了。反过来,如果我们的lkm后门不需要编译环境,也可以达到直接insmod的目的,这是件多么美好的事情,而且lkm后门更加稳定,还不用像sk在内核中添加了很多自己的数据结构。2、内核是怎么实现的我们去看看内核在加载模块的时候都干了什么,或许我们可以发现点bug,然后做点手脚,欺骗过去:)grep下dmesg里的关键字,看看它在哪个文件中:rootlocalhostlin

7、ux-2.6.18#grep-r-idisagreesaboutkernel/kernel/module.c:printk(%s:disagreesaboutversionofsymbol%sn,2.6.18/kernel/module.c:insmod调用了sys_init_module这个系统调用,然后进入load_module这个主函数,它解析elf格式的ko文件,然后加载到内核中:/*Allocateandloadthemodule:notethatsizeofsection0isalwayszero,andwerelyonthisforoptionalsections.*/stati

8、cstructmodule*load_module(void_user*umod,unsignedlonglen,constchar_user*uargs)if(!check_modstruct_version(sechdrs,versindex,mod)err=-ENOEXEC;gotofree_hdr;modmagic=get_modinfo(sechdrs,infoindex,vermagic);/*Thisisallowed:modprobe-forcewillinvalidateit.*/if(!modmagic)add_taint(TAINT_FORCED_MODULE);prin

9、tk(KERN_WARNING%s:noversionmagic,taintingkernel.n,mod-name);elseif(!same_magic(modmagic,vermagic)printk(KERN_ERR%s:versionmagic%sshouldbe%sn,mod-name,modmagic,vermagic);err=-ENOEXEC;gotofree_hdr;check_modstruct_version就是用来计算模块符号的一些crc值,不相同就会出现我们在dmesg里看到的“disagreesaboutversionofsymbol”信息。get_modinfo

10、取得了内核本身的vermagic值,然后用same_magic函数和内核的vermagic去比较,不同也会使内核加载失败。所以在这里,我们看到内核对模块验证的时候采用了2层验证的方法:模块crc值和vermagic检查。继续跟踪check_modstruct_version,现在的内核默认的都开启了CONFIG_MODVERSIONS如果没有指定这个选项,函数为空,我们的目的是要在As,Centos下安装模块,redhat不是吃干饭的,当然开了MODVERSION选项。staticinlineintcheck_modstruct_version(Elf_Shdr*sechdrs,unsigne

11、dintversindex,structmodule*mod)constunsignedlong*crc;structmodule*owner;if(!_find_symbol(struct_module,&owner,&crc,1)BUG();returncheck_version(sechdrs,versindex,struct_module,mod,crc);去校验:_find_symbol找到了struct_module这个符号的crc值,然后调用check_versionstaticintcheck_version(Elf_Shdr*sechdrs,unsignedintversin

12、dex,constchar*symname,structmodule*mod,constunsignedlong*crc)unsignedinti,num_versions;structmodversion_info*versions;/*Exportingmoduledidntsupplycrcs?OK,werealreadytainted.*/if(!crc)versions=(void*)sechdrsversindex.sh_addr;num_versions=sechdrsversindex.sh_size/sizeof(structmodversion_info);for(i=0;

13、iname,symname);DEBUGP(Foundchecksum%lXvsmodule%lXn,*crc,versionsi.crc);return0;/*Notinmodulesversiontable.OK,butthattaintsthekernel.*/if(!(tainted&TAINT_FORCED_MODULE)printk(%s:noversionfor%sfound:kerneltainted.n,mod-name,symname);add_taint(TAINT_FORCED_MODULE);struct_module这个符号,?在看下编译后的生成它搜寻elf的ver

14、sions小节,循环遍历数组中的每个符号表,找到然后去比较crc的值。现在有个疑问,versions小节是怎么链接到模块的elf文件中去的呢文件,有一个rootlocalhostlist#catlist.mod.c#include#include#includeMODULE_INFO(vermagic,VERMAGIC_STRING);structmodule_this_module_attribute_(section(.gnu.linkonce.this_module)=.name=KBUILD_MODNAME,.init=init_module,#ifdefCONFIG_MODULE_UNLOAD.exit=cleanup_module,#endif;staticconststructmodversion_infoversions_attribute_used_attribute_(section(_versions)=0x89e24b9c,struct_module,0x1b7d4074,printk,;staticconstchar_module_depends_a

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号