elegant method to inject a dll to processes BEFORE they start

こ雲淡風輕ζ 提交于 2019-12-05 16:01:40

You could abuse the Image File Execution Options and register your modification DLL as the 'debugger' (see How to: Launch the Debugger Automatically for details).

The procedure is simple:

  1. Add a key with the name of your target process (e.g. victim.exe) under the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options key.
  2. Under this key, add a new String Value with name debugger.
  3. Set the value to the path name of your modification binary. This must be either the fully qualified path name, or the image location must be in your PATH environment variable.

Whenever victim.exe is launched your modification binary is launched after victim.exe (and its dependencies) have been loaded, but before execution begins. This will happen regardless of how victim.exe is launched.

Note also that on a 64-bit OS the key is reflected in the Wow6432Node as well, so your modification binary will be launched for both 32-bit as well as 64-bit versions of victim.exe.

Another way to have your DLL loaded into each and every executable (at least those that link against user32.dll) is to abuse the AppInit_DLLs registry key (which also goes by the name Deadlock_Or_Crash_Randomly_DLLs). This is even messier than registering a random executable as a debugger, but still one hack that any self-respecting malware author absolutely needs to be familiar with. Note also, that this - uhm - feature may become unavailable in future versions of Windows. Windows Vista, Windows 7 and Windows Server 2008 R2 must be prepared for AppInit_DLLs to work.

What you want to achieve is called DLL Hooking, libraries to do that can be easily found.

You can try Microsoft Detours for that but it must be purchased depending on your usage (Detours Express is free for 32-bit and non-commercial usage). Alternatives include EasyHook, madCodeHook, ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!