CN108491237B - 一种隐蔽的Dll文件注入方法 - Google Patents
一种隐蔽的Dll文件注入方法 Download PDFInfo
- Publication number
- CN108491237B CN108491237B CN201810269225.5A CN201810269225A CN108491237B CN 108491237 B CN108491237 B CN 108491237B CN 201810269225 A CN201810269225 A CN 201810269225A CN 108491237 B CN108491237 B CN 108491237B
- Authority
- CN
- China
- Prior art keywords
- import table
- function
- file
- dll
- import
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000002347 injection Methods 0.000 title claims abstract description 20
- 239000007924 injection Substances 0.000 title claims abstract description 20
- 238000000034 method Methods 0.000 title claims abstract description 14
- 230000008676 import Effects 0.000 claims abstract description 72
- 230000006870 function Effects 0.000 claims abstract description 38
- 239000008186 active pharmaceutical agent Substances 0.000 claims description 8
- 230000000694 effects Effects 0.000 abstract description 7
- 230000004048 modification Effects 0.000 description 8
- 238000012986 modification Methods 0.000 description 8
- 238000005516 engineering process Methods 0.000 description 4
- 238000001514 detection method Methods 0.000 description 3
- 230000006399 behavior Effects 0.000 description 2
- 238000012550 audit Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000002474 experimental method Methods 0.000 description 1
- 230000007774 longterm Effects 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44521—Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
Abstract
一种隐蔽的Dll文件注入方法,包括如下步骤:a)设定回调函数;b)在exe文件被加载且执行入口函数前,系统调用OnLoadImage回调函数;c)读取lpImportTable地址里的原始导入表备份到缓冲区lpBackTable中;d)完成导入表的备份;e)读取lpImportTable中的导入表后依次将lpImportTable中的导入表拷贝至lpNewTable中;f)exe文件按照lpNewTable中的导入表加载Dll文件;g)替换DllMain函数中gdsection区段内的导入表,完成导入表还原。还原后的导入表与原始导入表无任何区别,因此无法通过PeTools类似软件查看到注入的Dll,理论上也无法通过对比内存导入表与PE文件导入表区分出注入的Dll,从而达到更好的Dll注入和隐藏效果。
Description
技术领域
本发明涉及计算机操作系统Dll文件领域,具体涉及一种隐蔽的Dll文件注入方法。
背景技术
通过内核层注入dll可以通过多种技术方式来实现,其中一种方式就是通过内核层驱动修改导入表来实现。调用windows API PsSetLoadImageNotifyRoutine注册一个镜像回调通知,当模块被加载时回调函数将被操作系统内核层调用,在此回调函数内将要注入的a.dll插入到导入表并替换原有导入表。函数返回,系统将按照新的导入表依次加载dll,第一个要加载的便是我们注入的a.dll,从而完成注入。现有实现方式下,注入的a.dll使用PeTools等工具可以在内存中查看到,理论上也可以通过对比原始PE文件的导入表与内存导入表区分出所注入的dll。
发明内容
本发明为了克服以上技术的不足,提供了一种实现保护和隐藏Dll文件,使PeTools以及同原理类软件(基于导入表检测技术)无法查看到注入的Dll的隐蔽的Dll文件注入方法。
本发明克服其技术问题所采用的技术方案是:
一种隐蔽的Dll文件注入方法,包括如下步骤:
a)windows系统驱动调用PsSetLoadImageNotifyRoutine的API函数,并通过API设定回调函数,回调函数的名称为OnLoadImage;
b)当用户双击exe文件时,在exe文件被加载且执行入口函数前,系统调用OnLoadImage回调函数,在OnLoadImage函数内部通过参数IMAGE_INFO类型的ImageBase成员变量获取到导入表地址lpImportTable中;
c) windows系统遍历读取lpImportTable地址里的原始导入表备份到缓冲区lpBackTable中;
d)在exe文件中建立新的区段为gdsection,将缓冲区lpBackTable中的内容拷贝到gdsection区段中,完成导入表的备份;
e) windows系统建立新的导入表内存为lpNewTable,将需要注入的Dll文件加入到导入表内存中,windows系统读取lpImportTable中的导入表后依次将lpImportTable中的导入表拷贝至lpNewTable中;
f)回调函数OnLoadImage执行返回,exe文件按照lpNewTable中的导入表加载Dll文件;
g)加载Dll文件后进入Dll文件的DllMain函数,在DllMain函数内读取gdsection区段,将步骤d)中备份的lpBackTable的导入表取出,替换DllMain函数中gdsection区段内的导入表,完成导入表还原。
进一步的,步骤e)中需要注入的Dll文件加入到导入表内存中并放在在内存数组中第一个元素位置。
本发明的有益效果是:在确保同样注入效果的前提下,通过导入表备份还原技术,实现保护和隐藏注入Dll效果。还原后的导入表与原始导入表无任何区别,因此无法通过PeTools类似软件查看到注入的Dll,理论上也无法通过对比内存导入表与PE文件导入表区分出注入的Dll,从而达到更好的Dll注入和隐藏效果。
具体实施方式
下面对本发明做进一步说明。
一种隐蔽的Dll文件注入方法,包括如下步骤:
a) 在内核层,Windows提供了一个API函PsSetLoadImageNotifyRoutine,该函数用来设定镜像模块加载通知回调。windows系统驱动调用PsSetLoadImageNotifyRoutine的API函数,并通过API设定回调函数,回调函数的名称为OnLoadImage。
b)当用户双击exe文件时,在exe文件被加载且执行入口函数前,系统调用OnLoadImage回调函数,在OnLoadImage函数内部通过参数IMAGE_INFO类型的ImageBase成员变量获取到导入表地址lpImportTable中。
c) windows系统遍历读取lpImportTable地址里的原始导入表备份到缓冲区lpBackTable中;
d)在exe文件中建立新的区段为gdsection,将缓冲区lpBackTable中的内容拷贝到gdsection区段中,完成导入表的备份。
e) windows系统建立新的导入表内存为lpNewTable,将需要注入的Dll文件加入到导入表内存中,windows系统读取lpImportTable中的导入表后依次将lpImportTable中的导入表拷贝至lpNewTable中,保证原有Dll的正常加载,使用构建完成的新导入表替换旧导入表完成导入表修改工作。
f)回调函数OnLoadImage执行返回,exe文件按照lpNewTable中的导入表加载Dll文件。
g)加载Dll文件后进入Dll文件的DllMain函数,在DllMain函数内读取gdsection区段,将步骤d)中备份的lpBackTable的导入表取出,替换DllMain函数中gdsection区段内的导入表,完成导入表还原。
还原完成后,再次对还原后的导入表以及原始导入表做校验,确认还原后的导入表与修改前的导入表一致,这时被注入目标程序检测模块便无法再检测到修改,同样原理的导入表修改检测工具也无法检测出修改,例如上面提及的Pe Tools工具。从而实现了“更为隐蔽”的Dll注入效果。
作为安全厂商,经常需要将Dll注入到一些第三方应用程序然后Hook关键Api进行拦截和审计。下面以一个实际应用场景为例说下该专利能达到的效果:
某产品Client.exe是一款第三方应用,但是并无Client.exe源代码,现需要审计该程序行为,必须将Dll注入到目标程序。然而经试验,常规的应用层远程线程注入技术、全局钩子等方式均无法稳定注入或者注入后就立即又被该程序的保护模块卸载。经过研究其原理,该应用程序采用了导入表比对技术来对抗常规DLL注入。采用本方案后,由于注入后立即还原了导入表的修改,且还原动作在检测动作之前,因此对抗代码无法检测到导入表的修改,也就没有将其卸载,此后再进行行为审计、拦截等动作均可顺利进行,从而达到了隐蔽的注入效果。由于该技术基于PE文件进行,从技术原理上具有通用性。另经过长期的用户验证,该方案也兼具稳定性的特点。
进一步的,步骤e)中需要注入的Dll文件加入到导入表内存中并放在在内存数组中第一个元素位置。从而确保Dll文件加载的优先性确保其可以被正常加载。
Claims (2)
1.一种隐蔽的Dll文件注入方法,其特征在于,包括如下步骤:
a)windows系统驱动调用PsSetLoadImageNotifyRoutine的API函数,并通过sSetLoadImageNotifyRoutine的API设定回调函数,回调函数的名称为OnLoadImage;
b)当用户双击exe文件时,在exe文件被加载且执行入口函数前,系统调用OnLoadImage回调函数,在OnLoadImage函数内部通过参数IMAGE_INFO类型的ImageBase获取成员变量,将获取的成员变量导入表地址lpImportTable中;
c) windows系统遍历读取lpImportTable地址里的原始导入表备份到缓冲区lpBackTable中;
d)在exe文件中建立新的区段为gdsection,将缓冲区lpBackTable中的内容拷贝到gdsection区段中,完成导入表的备份;
e) windows系统建立新的导入表内存为lpNewTable,将需要注入的Dll文件加入到导入表内存中,windows系统读取lpImportTable中的导入表后依次将lpImportTable中的导入表拷贝至lpNewTable中;
f)回调函数OnLoadImage执行返回,exe文件按照lpNewTable中的导入表加载Dll文件;
g)加载Dll文件后进入Dll文件的DllMain函数,在DllMain函数内读取gdsection区段,将步骤d)中备份的lpBackTable的导入表取出,替换DllMain函数中gdsection区段内的导入表,完成导入表还原。
2.根据权利要求1所述的隐蔽的Dll文件注入方法,其特征在于:步骤e)中需要注入的Dll文件加入到导入表内存中并放在在内存数组中第一个元素位置。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810269225.5A CN108491237B (zh) | 2018-03-29 | 2018-03-29 | 一种隐蔽的Dll文件注入方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810269225.5A CN108491237B (zh) | 2018-03-29 | 2018-03-29 | 一种隐蔽的Dll文件注入方法 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108491237A CN108491237A (zh) | 2018-09-04 |
CN108491237B true CN108491237B (zh) | 2020-11-27 |
Family
ID=63317305
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810269225.5A Active CN108491237B (zh) | 2018-03-29 | 2018-03-29 | 一种隐蔽的Dll文件注入方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108491237B (zh) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111506437A (zh) * | 2020-03-31 | 2020-08-07 | 北京安码科技有限公司 | 基于windows原始调用接口的靶场应用程序调用方法、系统、电子设备及存储介质 |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101908119A (zh) * | 2010-08-12 | 2010-12-08 | 浙江中控软件技术有限公司 | 一种动态链接库dll文件的处理方法和装置 |
CN105955762A (zh) * | 2016-04-19 | 2016-09-21 | 北京金山安全软件有限公司 | 一种注入动态链接库文件的方法、装置及电子设备 |
CN106203069A (zh) * | 2016-06-27 | 2016-12-07 | 北京金山安全软件有限公司 | 一种动态链接库文件的拦截方法、装置及终端设备 |
CN105512548B (zh) * | 2015-12-02 | 2018-03-30 | 湘潭大学 | 基于隐藏可执行镜像并注入dll保护镜像代码的方法 |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6874139B2 (en) * | 2000-05-15 | 2005-03-29 | Interfuse Technology Corporation | Method and system for seamless integration of preprocessing and postprocessing functions with an existing application program |
-
2018
- 2018-03-29 CN CN201810269225.5A patent/CN108491237B/zh active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101908119A (zh) * | 2010-08-12 | 2010-12-08 | 浙江中控软件技术有限公司 | 一种动态链接库dll文件的处理方法和装置 |
CN105512548B (zh) * | 2015-12-02 | 2018-03-30 | 湘潭大学 | 基于隐藏可执行镜像并注入dll保护镜像代码的方法 |
CN105955762A (zh) * | 2016-04-19 | 2016-09-21 | 北京金山安全软件有限公司 | 一种注入动态链接库文件的方法、装置及电子设备 |
CN106203069A (zh) * | 2016-06-27 | 2016-12-07 | 北京金山安全软件有限公司 | 一种动态链接库文件的拦截方法、装置及终端设备 |
Non-Patent Citations (1)
Title |
---|
一种隐藏注入模块的新方法;吴建 等;《计算机工程与科学》;20150831;第1472-1478页 * |
Also Published As
Publication number | Publication date |
---|---|
CN108491237A (zh) | 2018-09-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP3568791B1 (en) | Early runtime detection and prevention of ransomware | |
US7337291B2 (en) | Software memory access control | |
CA2831369C (en) | Method of securing non-native code | |
US9141787B2 (en) | Interlocked binary protection using whitebox cryptography | |
Berdajs et al. | Extending applications using an advanced approach to dll injection and api hooking | |
US20080148399A1 (en) | Protection against stack buffer overrun exploitation | |
WO2016078130A1 (zh) | 一种防逆向apk文件的动态加载方法 | |
CN102737188A (zh) | 检测恶意网页的方法及装置 | |
US10783041B2 (en) | Backup and recovery of data files using hard links | |
CN102651060A (zh) | 一种漏洞检测的方法和系统 | |
US20170255775A1 (en) | Software verification systems with multiple verification paths | |
CN107908958B (zh) | SELinux安全标识符防篡改检测方法及系统 | |
CN106648749B (zh) | 一种可执行程序动态调用方法及系统 | |
CN105512548A (zh) | 基于隐藏可执行镜像并注入dll保护镜像代码的方法 | |
CN108491237B (zh) | 一种隐蔽的Dll文件注入方法 | |
CN111368299A (zh) | 动态链接库文件劫持检测方法、设备及存储介质 | |
CN114556336A (zh) | 保卫软件例程 | |
Kruegel | Evasive malware exposed and deconstructed | |
US20190080111A1 (en) | Method for protecting unauthorized data access from a memory | |
US8572742B1 (en) | Detecting and repairing master boot record infections | |
US10867032B2 (en) | Generating and executing protected items of software | |
US7409713B2 (en) | Method of protecting software code | |
KR102310766B1 (ko) | 어플리케이션의 무결성 검사방법 | |
US9280666B2 (en) | Method and electronic device for protecting data | |
Leitch | IAT hooking revisited |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
PP01 | Preservation of patent right | ||
PP01 | Preservation of patent right |
Effective date of registration: 20231113 Granted publication date: 20201127 |