Originally Posted by
jonmcc
does anyone have .NET injection that can get clean into .net v4??
I don't target games so much but you guys seem to be on the front lines
THK if you do
IF NOT-
a small second request: I'm injecting .NET with .NET
I am currently Bootstrapping C++ and unpacking .NET and would like to inject pure .NET and not have to go C++ DLLMain then unpack C# from that

so anyone have "the best" way to do this from .NET to bring my injected .NET-DLL to life? -> code
sorry to load this down but a third request:
I need to hop AppDomains, this is all good in .NET pre v4 and in v4 they changed objects to do this, anyone have .NET (or c/c++) code to do this?
my help in return is you can make infected Visual Studio Projects that runs code on viewing a form in the project
This is done by putting code into a user control's constructor, then drop that on a form, also check what happens if you don't rebuild but you remove the code

It is on my list to make a project cleaner to stop/hunt this
anyway if you help with this I will owe you one
This is what I'm using atm.
I run this from my loader.exe, using blackmagic.
Code:
static bool Inject(string bootstrapDll, string cSharpDll)
{
string path = Application.StartupPath;
string dllPath = path + "\\" + bootstrapDll;
string moduleName = "StartTheDotNetRuntime";
uint args = 0, hModule, farProc;
IntPtr moduleOffset, injectedDllAddress;
try
{
if ((hModule = (uint) LoadLibrary(bootstrapDll)) == 0)
{
return false;
}
if ((farProc = (uint) Imports.GetProcAddress((UIntPtr)hModule, moduleName)) == 0)
{
return false;
}
moduleOffset = (IntPtr)(farProc - hModule);
FreeLibrary((IntPtr)hModule);
if (!File.Exists(dllPath))
{
MessageBox.Show("Unable to find " + dllPath);
return false;
}
if ((injectedDllAddress = (IntPtr)wow.InjectDllCreateThread(dllPath)) == IntPtr.Zero)
{
MessageBox.Show("Failed attempt to inject " + bootstrapDll);
return false;
}
dllPath = path + "\\" + cSharpDll;
if (!File.Exists(dllPath))
{
MessageBox.Show("Unable to find " + dllPath);
return false;
}
if ((args = wow.AllocateMemory(dllPath.Length + 1)) == 0)
{
MessageBox.Show("memory allocation error");
return false;
}
wow.WriteUnicodeString(args, dllPath);
if (!(wow.WriteUnicodeString(args, dllPath)))
{
MessageBox.Show("memory writing error");
return false;
}
IntPtr threadHandle = wow.CreateRemoteThread((uint)injectedDllAddress + (uint)moduleOffset, args);
Imports.WaitForSingleObject((IntPtr)threadHandle, 5000);
Imports.TerminateThread(threadHandle, 0);
Imports.CloseHandle(threadHandle);
return true;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return false;
}
finally
{
wow.FreeMemory(args);
}
}
and this is the bootstrap dll.
Code:
#include "stdafx.h"
#include <string>
#include <MSCorEE.h>
#include <MetaHost.h>
extern "C" __declspec(dllexport) void StartTheDotNetRuntime(wchar_t *dllPath)
{
ICLRMetaHost* MetaHost = NULL;
ICLRRuntimeInfo* Info = NULL;
ICLRRuntimeHost* Host = NULL;
DWORD *curAppID = NULL;
HRESULT hr;
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost,(PVOID*)&MetaHost);
DWORD dwRet = 0;
hr = MetaHost->GetRuntime(TEXT("v4.0.30319"), IID_ICLRRuntimeInfo, (PVOID*)&Info);
hr = Info->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (PVOID*)&Host);
if (Host == NULL)
return;
hr = Host->Start();
hr = Host->ExecuteInDefaultAppDomain(dllPath, L"Trons.Trons",
L"InitModule", L"", (DWORD*)&dwRet);
Host->Release();
return;
}
and InitModule in my c# dll is defines like this.
Code:
public static int InitModule(String pwzArgument)
{
EndScene.InstallEndSceneHook();
return 0;
}