3.-XML-external-entity-xxe-injection
Introduction to XXE
Definition: XXE vulnerabilities occur when a web application parses XML input from a user without proper sanitization, allowing attackers to inject malicious XML entities.
Impact: Can lead to:
Sensitive file disclosure (e.g., reading
/etc/passwd
)Server-side request forgery (SSRF)
Denial-of-service (DoS)
Remote code execution (RCE)
OWASP Top 10: XXE is considered a significant web security risk.
XML Basics
XML Structure:
XML documents consist of elements, attributes, entities, and declarations.
DTD (Document Type Definition): Defines the structure of an XML document and can be internal or external.
XML Entities: Variables within XML documents, including internal and external entities.
External entities can reference local or remote files.
Exploitation Techniques
1. Local File Disclosure
Identification: Look for web pages that accept XML input.
Exploitation: Define external entities to reference local files.
Command:
2. Source Code Disclosure (PHP Filter)
Command:
3. Remote Code Execution (RCE) with Expect
Command:
4. CDATA Exfiltration via External DTD
Create xxe.dtd
:
Host the DTD file:
Send the XML payload:
Command:
5. Error-Based XXE with External DTD
Create xxe.dtd
:
Host the DTD file:
Send the XML payload:
Command:
6. Out-of-Band (OOB) Exfiltration with External DTD
Create xxe.dtd
:
Host a PHP server:
Send the XML payload:
7. Automated XXE Exploitation with XXEinjector
Clone the tool:
Create request.txt
:
Run the exploit:
Set up listeners:
Capture DNS requests:
XXE Prevention
Disable DTDs: Configure XML parsers to disable DTD processing.
Input Validation: Sanitize and validate XML input.
Use Safe Parsing Libraries: Use XML parsers that are not vulnerable to XXE.
Update Components: Keep XML libraries and related components up to date.
Least Privilege: Run applications with minimal privileges.
Web Application Firewall (WAF): Implement a WAF to filter malicious XML input.
Key Takeaways
Understand XML Entities: Internal vs. external entities.
Advanced XXE Attacks: OOB exfiltration, error-based XXE, and parameter entities.
Use Automated Tools: XXEinjector helps automate XXE attacks.
Always test legally: Conduct security tests only on systems where you have explicit permission.
Regular Updates and Fixes: Patch and monitor applications to prevent XXE vulnerabilities.
Last updated