CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    May 2008
    Posts
    15

    DLL Injection Detection

    Hi there, so here's the deal. First off let me start by telling you why:

    Basically it's a game security feature, to prevent cheating.

    Anywhere here's the deal, I've been given the task of making a function to find all injected and loaded DLL's in a specific process at run time. Here's an example: They launch the game, this program will dump the target game's memory into a buffer or a file or something, and try and find all the DLL's loaded in that game's memory/process/address space.

    I'm just wondering what an efficient way to do this would be. I'm uncertain how to find all DLL's loaded in a certain process's address space, or how I could really access this memory to begin with. I'm not asking to be spoon fed here (unless you really feel like it haha) I would just like to have some suggestions on how I can accomplish this task, and what I will need to know/be able to do.

    I've done a bit of googling and I found a method commonly used to 'hide' these DLLs from injection detection techniques, here's the link/source code:

    Found at: http://www.battleforums.com/forums/d...akdll-cpp.html
    Source code: http://www.privatepaste.com/b31hpsgNJt

    I'm also aware that I may be able to use notification hooks to monitor access of OpenGL.dll or the Direct 3D DLL, but I'm uncertain if this will be an affective method to counter the 'hide' code used, or even if it's an affective method overall.

    Thanks a lot!

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: DLL Injection Detection

    A dll is a module. So the task must look like enumerating a process modules. The task could be performed several ways, and to begin with something I would suggest to create a toolhelp32 snapshot and enumerate process modules. That would be the very first spoon.
    Best regards,
    Igor

  3. #3
    Join Date
    May 2008
    Posts
    15

    Re: DLL Injection Detection

    OK I'll be sure to do that. Anyone else want to chime in, maybe with some ideas on how I can accomplish my task?

  4. #4
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    77

    Re: DLL Injection Detection

    if you really want to prevent DLL injection.

    - set your program security descriptor
    - prevent apps from getting your process handle.
    - scan for dll modules (without winapi) nt internals
    - re-fix import table

    this is how far any pro game security goes.

    cannot give you specific details on how todo that, good luck

  5. #5
    Join Date
    May 2008
    Posts
    15

    Re: DLL Injection Detection

    Well, I mainly just want to know if a DLL has been injected, not necessarily PREVENT them from being injected. Because if a DLL HAS been injected, I want to alert the server admin that cheats have been detected, or I want to kick/ban them from the server. So I don't necessarily need to prevent it, I just need to know if it's happening.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: DLL Injection Detection

    One point to remember: an injected dll is not necessarily a cheat tool. For example: contemporary dictionary applications inject global hook dlls into processes. Last year I made the one for one well-known respectable dictionary.
    Best regards,
    Igor

  7. #7
    Join Date
    May 2008
    Posts
    15

    Re: DLL Injection Detection

    Quote Originally Posted by Igor Vartanov View Post
    One point to remember: an injected dll is not necessarily a cheat tool. For example: contemporary dictionary applications inject global hook dlls into processes. Last year I made the one for one well-known respectable dictionary.
    That may be true, but in my case most if not all injected DLLs will be cheats. And if there is any that aren't, I should be able to distinguish them depending on their name or some other way. But as far as I know there is no legit reason for there to be injected DLLs into this specific game.

  8. #8
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    Re: DLL Injection Detection

    What you are trying to do is swim against the stream, that is the problem all game developers
    have since day 1.
    cj-wijtmans post is maybe the best advice, not using any win api calls (any function you call for detection could be hooked already).

    It's maybe a good idea to use EncodePointer and DecodePointer at startup of your application.

    Just scanning for injected dll's can be done by using toolhelp32 as Igor Vartanov already mentioned, but again, several applications inject dlls into other processes for any reason, so it's probably not a good idea to bust an user because of those results.

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: DLL Injection Detection

    Quote Originally Posted by pobri19 View Post
    But as far as I know there is no legit reason for there to be injected DLLs into this specific game.
    As far as I know, a global hook dll is injected into each and every windowed process that runs along with the hooking process... Okay, I'm gonna stop bothering you with my suggestions, have a good hunt.
    Best regards,
    Igor

  10. #10
    Join Date
    May 2008
    Posts
    15

    Re: DLL Injection Detection

    Quote Originally Posted by Igor Vartanov View Post
    As far as I know, a global hook dll is injected into each and every windowed process that runs along with the hooking process... Okay, I'm gonna stop bothering you with my suggestions, have a good hunt.
    My bad hehe, but that won't necessarily be a problem if I can get the names of the injected dlls. I could probably have a blacklist of known cheats or something, and run the names against the blacklist, or possibly attempt to see what the injected modules are trying to do, and if they're doing something suspect (like trying to hook OpenGL) I will know if it's being used for cheating. Anyways, sorry if I came across wrong, but what I just stated was what I was trying to get across =)

  11. #11
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    77

    Re: DLL Injection Detection

    better to check DLL's for CRC hash

  12. #12
    Join Date
    Mar 2013
    Posts
    5

    Re: DLL Injection Detection

    Igor Vartanov

    A dll is a module. So the task must look like enumerating a process modules. The task could be performed several ways, and to begin with something I would suggest to create a toolhelp32 snapshot and enumerate process modules. That would be the very first spoon.

    can you give me c# source code how to detect because i want to close my application when dll inject into my process.........help me to give c# source code.i remain thankfull to you

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: DLL Injection Detection

    Quote Originally Posted by Qasim Qadri View Post
    can you give me c# source code how to detect because i want to close my application when dll inject into my process.........help me to give c# source code.
    But why do you ask about a c# code in a C++ and WinAPI Forum?
    Victor Nijegorodov

  14. #14
    Join Date
    Mar 2013
    Posts
    5

    Re: DLL Injection Detection

    because i know c# and i make dll injector my self in c# now i want to detect.i did alots searching but tired to find solution.may be i not have much experience.i ask queston c# forum.i not get answer yet..may be i dnt know why they not provide me.i ask microsoft forum and stackflow.i just want when dll is injected in my process any event fire runtime or wat .dat i can detect it.then i will close my application. i hope codeguru team member will help me.

  15. #15
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: DLL Injection Detection

    Fact: You have no realistic means to stop all methods of client side "hacking". At best you can raise the bar and make it harder for the novice hacker or you can stop a couple common generic hacking tools dead in their tracks (or at least detect their use server side). There are simply put way too many ways you can:
    - inject dll's into code
    - inject code that isn't even in a dll
    - execute code that influences a running program without even ever running any code in the addres space of your game.

    Fact 2: It takes considerably more effort AND expertise to devise ways against a hack than it is to make a hack. If you aren't experienced at how "hacking a game" works in practice, you have zero chance of achieving anything.

    Fact 3: Nomatter how good you are, there are a lot of hackers out there that are either a lot smarter than you, or a lot more creative than you, or a lot more devious/evil than your are.

    Fact 4: A hacker will go to extremes in effort for even minimal gains. They will gladly spend weeks/months of effort on their cheat apps. Either because the minimal gains are significant enough to make a difference, or even just because it's a challenge to succeed at what they do. Even if you have a lot of paying customers, you cannot possibly match every hacker with an appropriately matching investment in time/effort/money to stop them.

    ----

    Listing all the DLL's is easy enough. This is achieved with EnumProcessModules(). This returns handles, you can know which dll it is with GetModuleName or GetModuleBaseName. note that a LOT of dll's can get loaded in your application process space for a wide assortment of reasons, these can be perfectly legitimate and blocking them could be anything from mildly annoying to the user, to potentially harmfull (as in preventing the PC from operation properly and even destroying data and preventing it from booting anymore).

    Listing all the memory that is marked as executable is also easy enough. Just use VirtualQueryEx to walk over the entire memory range and obtain the Access flag to see if it's executable.
    You can then match this up with the loaded modules (dll's) and pick out any sections of code that are marked executable but aren't part of a DLL's image. This could be suspect, but it's also used in legitimate ways by for example JIT compilers, scripts, and even some Windows DLL's use this for code-overrides on specific hardware, or for obfuscating some security related code.


    -----

    What you can do are:

    1) for local games. don't bother, the player is only hurting himself by using cheats. Cheat prevention is only a real issue for online/multiplayer games.

    1) Don't send ANY data to the client that it can't know about (such as sending it information about what opponents are doing). This was abused in a cheat for a RTS game. The clients got information about buildings opponents were doing, so a cheat could be devised that basically removed the "fog of war" and you could perfectly see at all time what your opponent was doing and building.
    In a "patch" this was fixed, but they were still sending information about how much resources everyone had gathered. By watching changes to the resources a cheat could infer what buildings/units were being built.

    2) Don't allow the client to send/submit any information that isn't verifiable on the server.
    If a user has X resources. and 2 seconds later he has Y. Then the server should have a means to verify that the transition from X to Y was indeed possible. The simplest way to do that is of course to do all resource management server side, but that isn't always fully feasible.

    3) Even with the above 2 in place there's still plenty ways to cheat.
    Autotargetters in FPS games. Any sort of automated play could be an issue. Detecting those is harder, this boils down to detecting 'unhuman' behavioural playing patterns.


    GL. you have a very ungrateful job ahead of you. But it has it's rewards

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured