Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Manually mapping a .NET executable.

So pretty much I've been working on a Manual Mapper, works like a charm with native executables but if I try to map a .NET executable (or anything that has .NET dependencies), it fails throwing this error:

[Image: Mzn2o.png]

I know that this can be fixed by using a compiler flag (/clr), but that's a bad solution because, while it'll allow .NET applications to be manually loaded, it will also require VC++ to be installed on the victim's machine (all of this is for a crypter's stub I am making, so I want zero dependencies whatsoever). So I manually load .NET assemblies with this code snippet:

Code
ICLRRuntimeHost* LoadNETRuntimeStatic()
{
    DLL_DEBUG("Loading .NET Runtime...\n");

    HRESULT hr;
    ICLRMetaHost* pMetaHost = NULL;
    ICLRRuntimeInfo* pRuntimeInfo = NULL;
    ICLRRuntimeHost* pRuntimeHost = NULL;

    hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&pMetaHost));

    if (FAILED(hr))
    {
        DLL_DEBUG("Could not create CLR instance.\n");
        return 0;
    }

    hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_PPV_ARGS(&pRuntimeInfo));

    if (FAILED(hr))
    {
        DLL_DEBUG("Could not get .NET runtime.\n");
        return 0;
    }

    hr = pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_PPV_ARGS(&pRuntimeHost));

    if (FAILED(hr))
    {
        DLL_DEBUG("Could not get .NET interface.\n");
        return 0;
    }

    hr = pRuntimeHost->Start();
}

Indeed .NET assemblies get correctly loaded inside the executable, but the latter still won't run.
[Image: VkJO9.png]

So before I tell what I want to achieve, let's gloss over some rules.
1. No dependencies, aka no usage of the /clr flag.
2. The executable is inside the stub (duh.), so no dropping files on disk, everything is done in memory.

My manual mapper does every required step, remapping to memory, base relocation, fixing imports etc etc, although .NET assemblies might require some sort of extra step since their PE structure is different.

Am I missing something? Is the /clr flag the only way out of this?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by _redbaron_Jun 14, 2024 04:56 PM 16 669 Jun 14, 2024 04:56 PM
Last Post: secret_code
[Python] by Beginner1234Nov 11, 2021 03:54 AM 2 141 Nov 11, 2021 03:54 AM
Last Post: 3phase
[Java] by ChukozyOct 2, 2020 11:55 AM 4 216 Oct 2, 2020 11:55 AM
Last Post: G.P.D.