New processes not being injected

c++ / delphi package - dll injection and api hooking
Kino
Posts: 4
Joined: Thu Jan 19, 2006 5:55 am
Contact:

New processes not being injected

Post by Kino »

When I inject the DLL (ALL_SESSIONS | SYSTEM_PROCESSES) all current process are injected and the hooks work well. But new processes that are started do not get automatically injected. Can you think of any reason for this?

I assume the new processes are not being injected because the hook works for the current processes, but not on any new processes.

Details below:
-----------------
Static lib build (commercial)
DLL to inject is in applications root directory
Calling InjectLibrary()/UninjectLibrary() from an NT service
WinXP Pro
Visual Studio .NET 2003
Windows Server 2003 SDK

Brian Young
KinoCode, Inc.
www.kinocode.com
iconic
Site Admin
Posts: 1065
Joined: Wed Jun 08, 2005 5:08 am

Post by iconic »

I assume the new processes are not being injected because the hook works for the current processes, but not on any new processes.
Nope, the flags you specified ensure that newly created processes (processes created AFTER you inject also load your library) otherwise, what good is an injection system which only injects into current process, that would defeat the whole purpose of "SYSTEM WIDE" injection.

--Iconic
iconic
Site Admin
Posts: 1065
Joined: Wed Jun 08, 2005 5:08 am

Post by iconic »

I missed this line (didn't read it until now)
Calling InjectLibrary()/UninjectLibrary() from an NT service
Maybe that has something to do with it, i wouldn't know because i've never used it in a service.

--Iconic
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Can you please use the ProcessExplorer from sysinternals to check whether the hook dll is loaded or not loaded into newly created processes - just to be sure?

Also please reboot your PC and try the precompiled demos shipping with madCodeHook (without running any of your software after the reboot). Do these demos work or do they show the same problem?
Kino
Posts: 4
Joined: Thu Jan 19, 2006 5:55 am
Contact:

Results

Post by Kino »

This problem was completely my fault. I ended up deleting the InitializeMadCHook() call in a code merge. It created some interesting results though.

If program ran first that called the InitializeMadCHook(), such as one of the precompiled demos, then my hook worked properly even with the lack of this call in my code. But, if my program ran first, without the InitializeMadCHook() call, then the demo would also have the same problem hooking new processes.

Sorry to waste your time iconic and madshi and thank you very much for the quick help with my problem!
iconic
Site Admin
Posts: 1065
Joined: Wed Jun 08, 2005 5:08 am

Post by iconic »

no problem, glad it is working for you. :D cheers!

--Iconic
linden
Posts: 36
Joined: Tue Mar 08, 2005 9:17 am
Location: Japan

Post by linden »

I just wonder...
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

linden wrote:I just wonder...
Hi linden,

I'm sorry, but while you're right, I don't want information about how to "disable" madCodeHook being published on my forum. Virus writers could misuse this information to work around security software which is based on madCodeHook.
linden
Posts: 36
Joined: Tue Mar 08, 2005 9:17 am
Location: Japan

Post by linden »

Oh! Sorry about that :-x
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

No problem... :)
ren
Posts: 3
Joined: Sat Dec 31, 2005 9:53 am

Post by ren »

iconic wrote:the flags you specified ensure that newly created processes (processes created AFTER you inject also load your library)
Hmm... by the way, I am using:
(ALL_SESSIONS) and (not CURRENT_PROCESS)
to avoid wasting time with system processes (I only need to hook user applications). Sometimes, on some machines, the hooking doesn't seem to work at all :? I was wondering if this may be the culprit...?
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

ren wrote:I was wondering if this may be the culprit...?
I don't think so.
iconic
Site Admin
Posts: 1065
Joined: Wed Jun 08, 2005 5:08 am

Post by iconic »

@ren,
The ALL_SESSIONS flag does exactly what it says, if your hook code conforms to that of madshi's hooking rules then you shouldn't have any problems.

--Iconic
denisb
Posts: 33
Joined: Tue Dec 07, 2004 3:48 pm

Post by denisb »

HOLD THE PHONE!!!!

Madshi...are you saying that if someone manages to prevent InitializeMadCHook() from running then this kewl code hooking technique can be rendered useless?
then maybe we're gonna have to make sure InitializeMadCHook is ran as soon as possible...even in a system driver loaded at boot time...btw is this possible? to run MadCode Hook from a system driver?

i'm kinda planning on moving to driver development since i saw that in user realm there are many ways to bypass any security software...

so i was wondering if you, madshi, ever tried hooking let's say the ndis driver from a kernel mode driver...donnow if it makes lots of sense yet
madshi
Site Admin
Posts: 10766
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

denisb wrote:HOLD THE PHONE!!!!

Madshi...are you saying that if someone manages to prevent InitializeMadCHook() from running then this kewl code hooking technique can be rendered useless?
Well, if someone manages to prevent HookAPI or InjectLibrary from running, then madCodeHook won't work correctly, either. No big surprise here.
denisb wrote:then maybe we're gonna have to make sure InitializeMadCHook is ran as soon as possible...even in a system driver loaded at boot time...
InitializeMadCHook is needed to be called for each hook dll which was compiled with MSVC++ and is using the static lib. InitializeMadCHook doesn't even exist when using Delphi and it's not as important when using the dynamic MSVC++ lib.
denisb wrote:btw is this possible? to run MadCode Hook from a system driver?
No. madCodeHook is strictly user land only - and it will stay that way.
Post Reply