In this section we will use the Create a tool that will load a DLL and Inject it to the current process.

First Let’s Create Our DLL.

// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include <stdio.h>
#include <Windows.h>

void callmsgbox()
{
    MessageBoxA(NULL, "Evasion Basics", "Hell !", MB_OK | MB_ICONINFORMATION);
}

BOOL APIENTRY DllMain( HMODULE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        callmsgbox();
        break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

image.png

Let’s Create a DLL Loader

#include <stdio.h>
#include <Windows.h>
#include <wincrypt.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        printf("[!] Usage: Loader.exe <dllname>\\n");
    }

    printf("[+] Injecting DLL To Current Process...\\n");

    if (LoadLibraryA(argv[1]) == NULL)
    {
        printf("[-] Faild To Load The DLL To Current Process :(\\n");
        return EXIT_FAILURE;
    }
    printf("[+] Successfully Loaded %s To Current Process", argv[1]);

    return EXIT_SUCCESS;
}

image.png

Now let’s run the Loader and see it it injects the DLL in the Current Process Or Not.

image.png

Please Notice that our executable self injected the DLL to it so that the Message Box is Loaded!