Article View: borland.public.cppbuilder.nativeapi
Article #1873Re: How to detect dll injection and hook installers on a Windows system
From: Remy Lebeau (TeamB)
Date: Mon, 28 May 2007 21:32
Date: Mon, 28 May 2007 21:32
34 lines
2488 bytes
2488 bytes
"Mark Jacobs" <www.jacobsm.com/mjmsg.htm?Borland Newsgroup> wrote in message news:465b45cb$1@newsgroups.borland.com... > I need some information on how an application can raise an alert > if another process on the system attempts to perform DLL code > injection. The only way I know of would be to install your own hook that redirects the VirtualAllocEx(), LoadLibrary/Ex(), and/or CreateRemoteThread() functions of every running process, such as with madCodeHook (http://www.madshi.net), which incidently also has DLL injection capabilities of its own implemented. You can then detect whenever those functions are called by any process you hook. On NT-based systems at least, DLL injection is commonly done by calling VirtualAllocEx() to create a block of memory in the context of the target process, then filling that memory with the desired DLL filename, and then calling CreateRemoteThread() to run a new thread in the target process that calls LoadLibrary/Ex(), passing it the memory block that was allocated. So in theory, you could keep track of whenever VirtualAllocEx() is used to allocate memory in a different process than the one calling VirtualAllocEx(), and then detect when that same memory address is being passed as a parameter to CreateRemoteThread(), as well as when LoadLibrary/Ex() is being passed as the starting address of the new thread procedure. I am sure that there are other ways to inject a DLL into a process, but this will get you started. Gambit
Technical Details
Message-ID:
<465b4aa3$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<465b45cb$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1b1d8084f8b63121 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <465b45cb$1@newsgroups.borland.com> Subject: Re: How to detect dll injection and hook installers on a Windows system Date: Mon, 28 May 2007 14:32:26 -0700 Lines: 36 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.82.252.126 Message-ID: <465b4aa3$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1180388003 75.82.252.126 (28 May 2007 14:33:23 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail