Results 1 to 12 of 12
  1. #1
    Sam...'s Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    57
    Reputation
    15
    Thanks
    27
    My Mood
    Tired

    Prevent classic DLL Injection

    Today i made a dll to prevent the classic dll injection based on LoadLibrary functions of kernel32.dll, this is how to use it

    Code:
    [DllImport("AntiDLLInject.dll", CallingConvention = CallingConvention.Cdecl)]
    private static extern void Activate();
    
    static void Main(string[] args)
    {
        Activate();
        //etc...
    }
    You just need to put the dll in the same location of the exe or in some subfolder like .\\FolderName\\AntiDLLInject.dll

    Result trying to inject with CE:


    Antivirus scans:
    https://www.virustotal.com/it/file/5...is/1411229492/
    https://virusscan.jotti.org/en/scanre...e7154f23a02985

    Download dll:
    <b>Downloadable Files</b> Downloadable Files
    Last edited by Sam...; 09-20-2014 at 10:13 AM.

  2. The Following 8 Users Say Thank You to Sam... For This Useful Post:

    anjuyoung (10-05-2014),avacompute (01-21-2019),geyfeggot (10-03-2014),k-k-krusty (04-08-2015),mohammadomid87 (10-17-2020),NikolasKrai (10-04-2014),Shadowlord01 (06-03-2022),sifenks55 (12-31-2014)

  3. #2
    Sam...'s Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    57
    Reputation
    15
    Thanks
    27
    My Mood
    Tired
    Fixed rare crash bug caused by multiple hooks, updated the dll.

  4. #3
    Hero's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Location
    memes
    Posts
    40,134
    Reputation
    4764
    Thanks
    9,674
    Please upload two scans of the .RAR file. One scan from VirusTotal and Jotti's malware scan for a total of two scans.
    [ • ] [ • ] [ • ] [ • ][ • ]

    Editor from 06•14•2011 • 2014
    Donator since 09•16•2011
    Minion from 10•10•2011 • 01•06•2011
    Minion+ from 01•06•2012 • 08•08•2012
    Moderator from 08•08•2012 • 10•06•2012
    Global Moderator from 10•06•2012 • 12•05•2017
    Staff Administrator from 12•05•2017 • 05•01•2019
    Trusted Member since 07•13•2019
    Global Moderator since 09•11•2020




  5. #4
    GodsAngel's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    location
    Posts
    57
    Reputation
    10
    Thanks
    2,292
    My Mood
    Happy
    Wow I am lookin forward to this o_O

  6. #5
    TheTrigger's Avatar
    Join Date
    Sep 2012
    Gender
    male
    Posts
    4
    Reputation
    10
    Thanks
    4
    If i create a new (empty) dll with a same function name (that does nothing, ofc), i could avoid your protection..
    This library should be integrated into the program then.
    or i'm wrong?

  7. #6
    Sam...'s Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    57
    Reputation
    15
    Thanks
    27
    My Mood
    Tired
    Quote Originally Posted by TheTrigger View Post
    If i create a new (empty) dll with a same function name (that does nothing, ofc), i could avoid your protection..
    This library should be integrated into the program then.
    or i'm wrong?
    To prevent a dll override you could do a checksum of the file using any hash type like md5 or sha1...example:

    Code:
    static class AntiDllInjection
    {
        [DllImport("AntiDLLInject.dll", CallingConvention = CallingConvention.Cdecl)]
        private static extern void Activate();
    
        private static MD5 hasher = MD5.Create();
        private static readonly string md5checksum = "6E7E31653A365CC66D5CF977B2A9B473";
    
        public static void Protect()
        {
            if (string.Concat(hasher.ComputeHash(File.ReadAllBytes("AntiDLLInject.dll"))
                .Select(x => x.ToString("X2"))) == md5checksum)
                Activate();
            else
                throw new Exception();
        }
    }
    Code:
    try
    {
        AntiDllInjection.Protect();
    }
    catch (Exception)
    {
        Console.WriteLine("Can't load protection...");
    }
    Last edited by Sam...; 09-26-2014 at 01:37 PM.

  8. The Following 2 Users Say Thank You to Sam... For This Useful Post:

    [MPGH]Mayion (09-29-2014),TheTrigger (09-29-2014)

  9. #7
    TheTrigger's Avatar
    Join Date
    Sep 2012
    Gender
    male
    Posts
    4
    Reputation
    10
    Thanks
    4
    Nice Work :)

  10. #8
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Sam View Post
    To prevent a dll override you could do a checksum of the file using any hash type like md5 or sha1...example:

    Code:
    static class AntiDllInjection
    {
        [DllImport("AntiDLLInject.dll", CallingConvention = CallingConvention.Cdecl)]
        private static extern void Activate();
    
        private static MD5 hasher = MD5.Create();
        private static readonly string md5checksum = "6E7E31653A365CC66D5CF977B2A9B473";
    
        public static void Protect()
        {
            if (string.Concat(hasher.ComputeHash(File.ReadAllBytes("AntiDLLInject.dll"))
                .Select(x => x.ToString("X2"))) == md5checksum)
                Activate();
            else
                throw new Exception();
        }
    }
    Code:
    try
    {
        AntiDllInjection.Protect();
    }
    catch (Exception)
    {
        Console.WriteLine("Can't load protection...");
    }
    It's fairly trivial to change one hardcoded hash to another using any decent hex editor / decompiler, though.

    What would happen if a legitimate DLL was loaded into the process, would your protection prevent it? Take DllImport as an example:

    From the MSDN docs:
    Quote Originally Posted by msdn
    Locating and loading the DLL, and locating the address of the function in memory occur only on the first call to the function.
    This means that any external libraries will only be loaded when the PInvoke'd function is first called. If I was to call "Activate()" prior to any of my other PInvoke'd functions, would the program fail to load the libraries into memory?
    Last edited by Jason; 10-03-2014 at 01:21 AM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  11. #9
    Sam...'s Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    57
    Reputation
    15
    Thanks
    27
    My Mood
    Tired
    Quote Originally Posted by Jason View Post

    It's fairly trivial to change one hardcoded hash to another using any decent hex editor / decompiler, though.
    The developer need to improve it, i just brought him an example.

    Quote Originally Posted by Jason View Post

    What would happen if a legitimate DLL was loaded into the process, would your protection prevent it? Take DllImport as an example:

    ....

    This means that any external libraries will only be loaded when the PInvoke'd function is first called. If I was to call "Activate()" prior to any of my other PInvoke'd functions, would the program fail to load the libraries into memory?
    Since kernel32.dll is always loaded into .net apps DllImport will just use LoadLibrary of the current dll, most of dll injectors create a remote thread using an external address so when the thread will start they will get the hooked function instead of LoadLibrary.

  12. #10
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Sam View Post
    Since kernel32.dll is always loaded into .net apps DllImport will just use LoadLibrary of the current dll, most of dll injectors create a remote thread using an external address so when the thread will start they will get the hooked function instead of LoadLibrary.
    That doesn't make any sense.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  13. #11
    Sam...'s Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    57
    Reputation
    15
    Thanks
    27
    My Mood
    Tired
    Quote Originally Posted by Jason View Post


    That doesn't make any sense.
    Try yourself , the dll just handle native injection do not affects the .net app.

  14. #12
    ofrist123's Avatar
    Join Date
    Nov 2017
    Gender
    male
    Posts
    1
    Reputation
    10
    Thanks
    0

    Source

    any chance for the source?

Similar Threads

  1. DLL injection
    By Lynie in forum C++/C Programming
    Replies: 3
    Last Post: 10-30-2008, 11:44 AM
  2. [HELP] - DLL Injection
    By pelonzudo in forum C++/C Programming
    Replies: 1
    Last Post: 09-10-2008, 02:27 AM
  3. Crash at Dll inject
    By CyberStriker in forum WarRock - International Hacks
    Replies: 1
    Last Post: 08-13-2008, 06:51 AM
  4. [Help!] CA crash on dll inject
    By CyberStriker in forum Combat Arms Hacks & Cheats
    Replies: 9
    Last Post: 08-12-2008, 09:23 PM
  5. DLL injection Failled
    By aynal in forum WarRock - International Hacks
    Replies: 1
    Last Post: 01-15-2006, 09:41 PM