简体   繁体   English

“安全” DLL注入

[英]'Safe' DLL Injection

Not a terribly good question, sorry. 对不起,这不是一个非常好的问题。

I have a program that needs to be alerted when a file is opened from explorer (ie ShellExecute(A/W) is called). 我有一个程序,从资源管理器打开文件时需要提醒(即,调用ShellExecute(A / W))。

Unfortunately, Microsoft removed the COM interface (IShellExecuteHook) that allows you to hook these events in Vista and up, supposedly because older code could cause a crash due to changes. 不幸的是,Microsoft删除了COM接口(IShellExecuteHook),该接口允许您在Vista和更高版本中挂接这些事件,这可能是因为较旧的代码可能会因更改而导致崩溃。 There was a work-around to re-enable this feature, but it no longer works. 有一种变通办法可以重新启用此功能,但是它不再起作用。

I've done some research and it looks like the only way to catch calls to ShellExecute is to re-route the call to shell32.dll. 我已经做过一些研究,看来捕捉到ShellExecute调用的唯一方法是将调用重新路由到shell32.dll。 At the moment, I'm looking at injecting my own DLL into the explorer process, then copying the IAT entry for ShellExecute to some address allocation in my DLL, and finally modifying the IAT entry for ShellExecute to point to my function, which will notify the program that a file was opened and jump to the original ShellExecute function, whose address we stored earlier. 目前,我正在考虑将自己的DLL注入资源管理器进程,然后将ShellExecute的IAT条目复制到DLL中的某些地址分配中,最后修改ShellExecute的IAT条目以指向我的函数,这将通知打开文件并跳到原始ShellExecute函数的程序,该函数的地址我们之前存储了。

My biggest concern here is antiviruses. 我在这里最大的担心是防病毒。 Will they care that I'm injecting into explorer? 他们会在乎我正在注入资源管理器吗? Will they care that I'm modifying the IAT? 他们会关心我正在修改IAT吗?

Another concern is whether this is safe; 另一个问题是这是否安全; is it possible (or rather likely) for explorer's security priveleges to not allow injection via CreateRemoteThread? 资源管理器的安全特权是否有可能(或相当可能)不允许通过CreateRemoteThread进行注入? If so, is there a better way to do this injection? 如果是这样,是否有更好的方法进行注射?

Is there a better way to do this in general? 总的来说,有更好的方法吗?

EDIT: For anyone who comes across this in the future, explorer.exe has no IAT for shell32.dll; 编辑:对于以后遇到此问题的任何人,explorer.exe都没有shell32.dll的IAT; it has a header, but the thunk is full of junk values, so there's no way (as far as I can tell) to retrieve the entry for any imported functions. 它有一个标头,但是thunk充满了垃圾值,因此(就我所知)无法检索任何导入函数的条目。
Looks like code tunneling is the only way to hook this. 看起来代码隧道是挂钩此问题的唯一方法。

Most good antivirus heuristics should pick up on import table patching as being a red flag for a trojan. 大多数优秀的防病毒试探法都应该在导入表修补程序中作为木马的危险信号而使用。

The online documentation for madcodehook has some extended articles on various code injection techniques, their benefits/drawbacks, and the API provides some options for specifying "safe" hooking: http://www.madshi.net/madCodeHookDescription.htm madcodehook的在线文档提供了有关各种代码注入技术,其优点/缺点的扩展文章,并且API提供了一些用于指定“安全”钩子的选项: http : //www.madshi.net/madCodeHookDescription.htm

The Detours library: 绕行库:

http://research.microsoft.com/en-us/projects/detours/ http://research.microsoft.com/en-us/projects/detours/

From Microsoft Research allows arbitrary hooking of functions. 来自Microsoft Research的功能允许任意挂钩。 You might give that a shot. 您可能会尝试一下。

Some more resources on API hooking: 有关API挂钩的更多资源:

Easy hook: http://www.codeplex.com/easyhook 简易钩子: http : //www.codeplex.com/easyhook

Deviare: http://www.nektra.com/products/deviare-api-hook-windows/ Deviare: http//www.nektra.com/products/deviare-api-hook-windows/

An interesting post: http://www.codeproject.com/KB/system/hooksys.aspx 有趣的帖子: http : //www.codeproject.com/KB/system/hooksys.aspx

When doing API hooking it is very important to asses in which environments you need to run. 进行API挂钩时,评估您需要在哪个环境中运行非常重要。 Not all libraries support x86/x64 for example. 例如,并非所有库都支持x86 / x64。

Detours only supports x64 in the licensed (payed) version. Detours仅在许可(付费)版本中支持x64。 Easy hook supports x86 and x64. 简易挂钩支持x86和x64。

Windows Explorer in Windows Vista and Windows 7 doesn't even call ShellExecuteA or ShellExecuteW. Windows Vista和Windows 7中的Windows资源管理器甚至都不调用ShellExecuteA或ShellExecuteW。

No point bother. 没有一点麻烦。 Lol :-) 大声笑 :-)

AND, if i may add, i have tested by hooking both functions with both 32 bit and 64 bit inline hooks. 而且,如果我可以添加的话,我已经通过32位和64位内联钩子同时钩住这两个函数进行了测试。

Sorry. 抱歉。 Lol :-) 大声笑 :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM