0x00 前言
最近,来自SensePost的Chris Le Roy开源了一款工具:Rattler,可用来自动识别DLL是否存在预加载漏洞(也可以理解为DLL劫持漏洞,文中该名词均采用DLL劫持漏洞)。虽然DLL劫持漏洞已不再是新技术,可追溯到2010年,但是我对自动化很是感兴趣,于是对此做了进一步研究。
本文将理清DLL劫持漏洞原理,实例分析,测试自动化工具Rattler,分享心得,并测试一个存在该漏洞的软件——Explorer Suite安装包
注:
Explorer Suite安装包内包含CFF Explorer,免费,常用来编辑PE文件格式,最后更新于2012年11月18日,是比较小众的一款工具。对于分析PE文件格式,建议使用作者另一款更专业的工具:Cerbero Profiler
Chris Le Roy介绍Rattler的博客地址:
https://sensepost.com/blog/2016/rattleridentifying-and-exploiting-dll-preloading-vulnerabilities/
Chris Le Roy在BSides Cape Town上也介绍了Rattler,简介如下:
http://www.bsidescapetown.co.za/speaker/chris-le-roy/
0x01 简介DLL劫持漏洞根源
程序在调用DLL时未指明DLL的完整路径
SafeDllSearchMode
从WindowsXPSP2开始,SafeDllSearchMode默认开启,SafeDllSearchMode的存在是为了阻止在XP时代存在的DLL劫持漏洞
注:
强制关闭SafeDllSearchMode的方法:创建注册表项HKEY_LOCAL_MACHINESystemCurrentControlSetControlSession ManagerSafeDllSearchMode值设为0
程序在调用DLL时,如果未指明DLL的完整路径,那么系统会按照一套固定的搜索顺序寻找DLL
如果SafeDllSearchMode开启,程序会依次从以下位置查找DLL文件:
The directory from which the application loaded
The system directory
The 16-bit system directory
The Windows directory
The current directory
The directories that are listed in the PATH environment variable
如果关闭,则从以下位置查找DLL文件:
The directory from which the application loaded
The current directory
The system directory
The 16-bit system directory
The Windows directory
The directories that are listed in the PATH environment variable
详细内容见:
https://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx
KnownDLLs
注册表位置:
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerKnownDLLs
KnownDLLs注册表项下包含一系列常见的系统dll,如usp10.dll、lpk.dll、shell3