Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C# Programming › Prevent classic DLL Injection

Prevent classic DLL Injection

Posts 1–12 of 12 · Page 1 of 1
SA
Sam...
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/
http://virusscan.jotti.org/en/scanre...e7154f23a02985

Download dll:
AntiDLLInject_mpgh.net.zip
#1 · edited 11y ago · 11y ago
SA
Sam...
Fixed rare crash bug caused by multiple hooks, updated the dll.
#2 · 11y ago
Hero
[MPGH]Hero
Please upload two scans of the .RAR file. One scan from VirusTotal and Jotti's malware scan for a total of two scans.
#3 · 11y ago
GodsAngel
GodsAngel
Wow I am lookin forward to this o_O
#4 · 11y ago
TH
TheTrigger
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?
#5 · 11y ago
SA
Sam...
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...");
}
#6 · edited 11y ago · 11y ago
TH
TheTrigger
Nice Work :)
#7 · 11y ago
Jason
Jason
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?
#8 · edited 11y ago · 11y ago
SA
Sam...
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.
#9 · 11y ago
Jason
Jason
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.
#10 · 11y ago
SA
Sam...
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.
#11 · 11y ago
OF
ofrist123
Source
any chance for the source?
#12 · 6y ago
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

  • DLL injection FailledBy aynal in WarRock - International Hacks
    1Last post 20y ago
  • Crash at Dll injectBy CyberStriker in WarRock - International Hacks
    1Last post 18y ago
  • [Help!] CA crash on dll injectBy CyberStriker in Combat Arms Hacks & Cheats
    9Last post 18y ago
  • [HELP] - DLL InjectionBy pelonzudo in C++/C Programming
    1Last post 18y ago
  • DLL injectionBy Lynie in C++/C Programming
    3Last post 17y ago

Tags for this Thread

None