Windows Antimalware Scan Interface (AMSI) allows any program to communicate with the Anti-Virus that communicates on the machine. Essentially a bunch of functions that programs can call (amsi.dll). This allows programs to be like hey amsi scan this file, then amsi will be like or
Its built into PowerShell by default. So even though we're running scripts into memory, it's still getting passed through PowerShell which has AMSI so it stops the process from even happening.
AMSI Scan Buffer
With this technique, when amsi.dll gets loaded into memory we are going to find the location of the amsi scan buffer function and overwrite it in a way that makes it always return a clean file.
Test amsi
Invoke-Expression "AMSI Test Sample: 7e72c3ce-861b-4339-8740-0ac1484c1386"
Amsi.fail generates obfuscated PowerShell snippets that break or disable AMSI for the current process. So once your PowerShell process dies the AMSI bypass dies with it. This makes it better on real engagements because then you're not just disabling WIndows Defender