
1. Introduction
XML External Entity (XXE) attacks occur when an application parses XML input containing a reference to an external entity without proper configuration or sanitization.
This vulnerability can lead to file disclosure, server-side request forgery (SSRF), remote code execution (RCE), and even denial of service (DoS).
Why XXE is still dangerous in 2025:
- Legacy XML parsers are still in production in enterprise systems.
- Modern APIs, SAML-based authentication, and SOAP services often process XML.
- Many developers focus on input validation but overlook parser hardening.
2. How XXE Works
When XML parsers support Document Type Definitions (DTDs) and entity expansion, attackers can define malicious entities to retrieve sensitive files or make network requests.
Example Malicious XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<foo>&xxe;</foo>
Attack Flow:
- Application accepts XML input.
- XML parser processes the DTD and expands the entity.
- Contents of
/etc/passwdare returned in the application response or sent to attacker-controlled systems.
3. Types of XXE Attacks
3.1 File Disclosure
Reading sensitive files like /etc/passwd or configuration files.
3.2 SSRF via XXE
Using external entities to make HTTP requests to internal or cloud metadata endpoints:
<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">
3.3 Blind XXE
Exfiltrating data to an attacker-controlled server when the response is not returned directly.
3.4 Denial of Service (Billion Laughs Attack)
Recursive entity expansion to exhaust memory:
<!ENTITY lol "lol">
<!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
...
4. Real-World Incidents
- Facebook (2013) – XXE in a developer tool allowed access to internal services.
- Drupal (2014) – XML parsing flaw allowed SSRF and file disclosure.
- Multiple SAP Services – XXE in SOAP APIs exposed business-critical data.
5. MITRE ATT&CK Mapping
- T1005 – Data from Local System
- T1083 – File and Directory Discovery
- T1213 – Data from Information Repositories
- T1190 – Exploit Public-Facing Application
6. Advanced XXE Techniques in 2025
| Technique | Description | Impact |
|---|---|---|
| Polyglot Payloads | Embedding XXE in formats like DOCX, SVG, or SOAP envelopes. | Stealthy exploitation. |
| Protocol Abuse | Using gopher://, ftp://, or file:// in entity definitions. | SSRF & data exfiltration. |
| Out-of-Band XXE | Using DNS or HTTP callbacks for data extraction. | Evades inline detection. |
| XXE Chaining | Combining XXE with path traversal or insecure deserialization. | Full environment compromise. |
7. Detection & Prevention Strategies
A. Disable External Entity Processing
- For Java:
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
- For .NET, Python, PHP – use parser options to disable DTDs.
B. Use Safe XML Libraries
- Prefer parsers that do not support DTDs by default.
C. Input Validation & Content-Type Restrictions
- Reject unexpected XML where not needed.
- Validate content type and enforce strict schema.
D. Network Egress Controls
- Prevent the XML parser host from making arbitrary outbound requests.
E. Threat Modeling
- Include XXE scenarios in design reviews for XML-handling services.
8. Threat Hunting Tips
- Monitor application logs for
<!DOCTYPEin incoming requests. - Detect unusual outbound traffic from XML parsing systems.
- Search for large, repetitive XML entity expansions.
9. CyberDudeBivash Recommendations
- Red Team: Test all XML endpoints (SOAP, SAML, file upload parsers) for XXE.
- Blue Team: Deploy WAF signatures for
<!ENTITYand monitor outbound parser requests. - DevSecOps: Enforce safe XML parser settings in code review checklists.
Conclusion
XXE attacks are a low-effort, high-impact exploit vector for attackers targeting legacy or poorly configured XML parsers. Disabling external entity resolution at the parser level is your single most effective defense.
Bottom line: If you don’t need DTDs, disable them entirely. And if you must process XML, harden your parser like your data depends on it — because it does.
🔗 Powered by CyberDudeBivash – Global Threat Intel, Incident Analysis, and Cybersecurity Engineering.
#XXE #CyberSecurity #OWASP #AppSec #XML #CyberDudeBivash
Leave a comment