Skip to content
XXE Write-up Advanced

Exploiting Out-of-Band XXE in the Wild

An XML parser on a non-standard port was vulnerable to out-of-band XXE, allowing an attacker to make the server request external DTDs and exfiltrate local files. The attacker could read single-line files and later multi-line files like /etc/passwd via error messages.

Mahmoud Youssef Follow

Published on 0xmahmoudjo0.medium.com

Hello all, I hope you’re fine! Our story today is about one of the most interesting bugs I found, actually, it’s my first time finding this bug in a BB Program, and some problems faced me while making a PoC to retrieve local files, so I decided to share it!

Mahmoud Youssef, on 0xmahmoudjo0.medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This write-up covers an out-of-band XML External Entity (XXE) vulnerability that the author found in a bug bounty program. The target is referred to only as redacted.com. The vulnerable service was an IP address with port 9180 open, which served content that used XML. The author does not name the product or describe what the service normally does beyond the fact that it accepts XML input.

The report walks through a failed attempt to read local files directly, a successful SSRF, a port scan through the SSRF, and finally a working OOB XXE that read /etc/passwd. The author notes that the SSRF alone was a P4, the port scan a P3, and the OOB XXE was accepted as a P1.

Setup

The author used the following tools and preconditions:

  • Shodan to enumerate IP addresses related to the target.
  • Rustscan for a full port scan (the author mentions naabu as an alternative).
  • An HTTP probe against the discovered IPs, checking unusual ports such as 8443, 8080, 8888, 9180 and 9000.
  • Burp Suite to intercept and replay requests, including Burp Collaborator for out-of-band interaction and Burp Comparer for comparing responses.
  • A listener on port 1337 and an HTTP server on port 8080 for the OOB XXE stage.

No accounts or roles are mentioned. The only precondition is network access to the IP and port 9180.

Finding it

After enumerating IPs from Shodan and running a full port scan, the author probed the discovered hosts over HTTP and looked at unusual ports. One IP had port 9180 open and served content that used XML. The author sent a POST request with Content-Type: application/xml and received errors back. That response prompted the author to test for XXE.

Exploitation

Step 1: Direct file read attempt

The author first tried the payload used to detect the vulnerability, but the response contained only errors. The author then tried the classic payload to retrieve local files directly:

The report does not reproduce the payload text itself. The result was nothing: the response still contained only errors.

From the original on 0xmahmoudjo0.medium.com

The author then tried other payloads and modified some of them, comparing response differences. Some responses had different content lengths, but every response contained errors and the author could not interpret the differences.

Step 2: SSRF attempt with the initial payload

The author concluded that direct file retrieval was not working and tried to make the server issue an HTTP request to a Burp Collaborator instance (SSRF). The payload used for this attempt is not reproduced in the report text.

From the original on 0xmahmoudjo0.medium.com

The result was the same: no interaction. The author tried several more SSRF payloads with no success.

Step 3: Switching to the PUBLIC entity

After reading older write-ups, the author came across a payload that worked. The report does not reproduce the payload text, but notes that SYSTEM can be used as well, since the two are almost synonymous. The author decided to use PUBLIC.

From the original on 0xmahmoudjo0.medium.com

With this payload the author got an HTTP interaction in Burp Collaborator. At this point the finding was an SSRF, which the author describes as a P4 submission on its own.

Step 4: Escalating SSRF to a port scan

To raise the severity, the author used the SSRF to probe local ports. A request was sent to http://[redacted]:9180, a port known to be open, and another to a random port, http://[redacted]:333. The two responses were compared in Burp Comparer.

From the original on 0xmahmoudjo0.medium.com

As expected, port 333 returned Connection refused. The author notes that 333 is an uncommon port that was assumed to be closed.

From the original on 0xmahmoudjo0.medium.com

The author then ran a simple port scan against the top 10000 ports and filtered responses containing Connection refused, which revealed several open ports.

Filter responses that contain Connection refused From the original on 0xmahmoudjo0.medium.com

Filter responses that contain Connection refused

From the original on 0xmahmoudjo0.medium.com

This produced what the author calls a P3 in a paid bug bounty program. Before reporting, the author decided to try once more for the XXE, which would be a P1.

Step 5: Reasoning about OOB XXE

The author reasoned that the XXE might be out-of-band, which would make /etc/passwd impossible to read because it is a multi-line file, while /etc/hostname would work because it is a single line. The plan was to host a malicious DTD file and use the SSRF to force the server to request it.

https://www.synack.com/blog/a-deep-dive-into-xxe-injection/ From the original on 0xmahmoudjo0.medium.com

https://www.synack.com/blog/a-deep-dive-into-xxe-injection/

The author describes the OOB XXE flow as follows:

  1. The site requests the malicious DTD file.
  2. The malicious DTD requests /etc/hostname and sends it to the author's IP on port 1337.
  3. The listener receives a request containing the /etc/hostname content.

The malicious DTD and the HTTP server on port 8080 are shown in the report but their contents are not reproduced in the text.

From the original on 0xmahmoudjo0.medium.com

Step 6: Successful OOB XXE

The listener received the hostname, confirming the OOB XXE.

From the original on 0xmahmoudjo0.medium.com

At this point the author could read single-line files but not multi-line files such as /etc/passwd or /etc/hosts. The author was concerned that this limitation might reduce the severity to P2 or lower, and decided to try to read large files.

Step 7: Reading large files via error messages

The author tried the usual techniques for large files in OOB XXE, including base64 encoding, FTP, and tools that exfiltrate data over FTP, but all failed. The remaining approach was to leak file contents through error messages.

The technique works as follows:

  1. Host a malicious DTD file that does two things:
    • defines an XML parameter entity containing the content of /etc/passwd;
    • defines an XML parameter entity containing a dynamic declaration of another XML parameter entity, which is evaluated by loading a nonexistent file whose name contains the first entity, which in turn contains the /etc/passwd content.
  2. When the site requests the DTD file, it tries to load the nonexistent file. The error message about the nonexistent file includes the file name, which includes the /etc/passwd content.

To demonstrate the mechanism, the author hosted a DTD that requested a nonexistent file and used a payload to show that the value of the XML parameter entity %secret is reflected in the response.

From the original on 0xmahmoudjo0.medium.com

The response contained the value of %secret. The author then changed the %secret value to /etc/passwd so that the file content would be reflected in the response.

From the original on 0xmahmoudjo0.medium.com

The response contained the contents of /etc/passwd. The author reported the finding and it was accepted as a P1.

Root cause

The report does not describe the server-side code or configuration. The behaviour is consistent with an XML parser that resolves external entities, including parameter entities in external DTDs, and that returns parser error messages to the client. The author does not state which parser or library was in use, or whether any entity resolution was disabled. The fact that direct in-band entity expansion returned only errors, while external DTD loading and error-based reflection worked, suggests that the parser was configured in a way that allowed external entity resolution but did not allow the entity value to be expanded inline in the response. This is an inference from the observed behaviour, not something the report states.

Impact

Under the conditions observed, an attacker who can reach the XML endpoint could:

  • make the server issue HTTP requests to arbitrary hosts (SSRF), including internal addresses;
  • use that SSRF to scan internal ports and identify open services;
  • read local files, including multi-line files such as /etc/passwd, through error-based exfiltration.

The author notes that the SSRF alone was rated P4, the port scan P3, and the OOB XXE was accepted as P1. The report does not describe what other files or services were reachable, or what privileges the vulnerable service ran with.

Fix

The standard remediation for this class of issue is to disable external entity and external DTD resolution in the XML parser, and to avoid returning raw parser error messages to clients.

Variants to test

  • Direct in-band entity expansion: send an XML body with a DOCTYPE that defines an entity pointing to a local file. A positive result is the file content appearing in the response.
  • SSRF via external entity: define an entity pointing to an attacker-controlled URL and watch for an interaction. A positive result is an HTTP request from the target to the listener.
  • SSRF port scan: use the SSRF to request http://[redacted]:<port> for a range of ports and compare responses. A positive result is a response that differs from Connection refused.
  • OOB XXE with external DTD: host a DTD that reads a single-line file and sends it to a listener. A positive result is the file content arriving at the listener.
  • Error-based exfiltration: host a DTD that defines a parameter entity containing a file's content and a second parameter entity that loads a nonexistent file whose name includes the first entity. A positive result is the file content appearing in the parser error message.
  • SYSTEM versus PUBLIC: if one keyword fails, try the other, since the report notes they are almost synonymous.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 12 min read.

What happened, in plain words

A security researcher was hunting for bugs in a company's systems as part of a bug bounty programme. In a bug bounty programme, a company invites outside people to look for security weaknesses in its systems and pays them for reporting what they find. The bigger the impact of the bug, the higher the reward, and the platform sorts findings into priority levels: P1 is the most serious, P4 the least.

The researcher found a web service that accepted XML, a way of formatting data that computers exchange with each other. That service turned out to be vulnerable to a class of bug called XXE, short for XML External Entity. An "entity" in XML is a placeholder that the parser (the program that reads the XML) replaces with something else, and an "external entity" is a placeholder that points at a file or a URL outside the document. If the parser is allowed to fetch those external things, an attacker can make the server read files from its own disk or send requests to other machines.

Getting there took several attempts. The first tries to read files directly failed. Then the researcher managed to make the server send a request to a machine the researcher controlled, which is a bug called SSRF (Server-Side Request Forgery). Using that, the researcher scanned the server's internal network for open ports. Finally, by hosting a small file on the internet and making the server fetch it, the researcher got the server to read /etc/passwd, a file on Linux systems that lists user accounts, and to reflect its contents in an error response. That last step was accepted as a P1.

From the original on 0xmahmoudjo0.medium.com

Phase 1: Recon

Recon, short for reconnaissance, is the information-gathering stage. Before touching anything, you work out which machines belong to the target and what they are running.

The researcher likes Shodan, a search engine that indexes devices connected to the internet. Instead of searching web pages, Shodan lets you search for servers, ports and services. From Shodan the researcher collected a list of IP addresses related to the target, which is referred to only as redacted.com. An IP address is the numeric address of a machine on a network, like a postal address for computers.

Next came a full port scan with rustscan. A port is a numbered doorway on a machine; a single server can run many services, each listening on its own port. A port scan means trying every doorway to see which ones answer. The researcher mentions naabu as an alternative tool for the same job.

After the scan, the researcher sent an HTTP probe to the discovered IPs. HTTP is the protocol browsers use to talk to web servers, and a probe is just a simple request to see whether something answers. The researcher paid attention to unusual ports such as 8443, 8080, 8888, 9180 and 9000, The researcher paid attention to unusual ports such as 8443, 8080, 8888, 9180 and 9000..

All requests were passed through Burp Suite, a tool that sits between your browser and the server so you can see, edit and replay every request. One IP had port 9180 open, and the content it served used XML. The researcher sent a POST request with Content-Type: application/xml. A POST request is one that sends data to the server, and the Content-Type header tells the server what kind of data it is. The server replied with errors. That reaction, an XML service that complains about XML, is exactly the kind of thing that makes a tester think of XXE, so the researcher decided to test for it.

Phase 2: Analysis

The researcher first tried the payload normally used to detect the vulnerability. A payload is the piece of malicious input you send to trigger a bug. The response contained only errors. Then the researcher tried to retrieve local files directly with the classic payload:

The report does not reproduce the payload text itself. The result was nothing: the response still contained only errors.

From the original on 0xmahmoudjo0.medium.com

After that, the researcher tried other payloads and modified some of them, comparing how the responses differed. Some responses had different content lengths, but every response contained errors, and the researcher could not make sense of the differences. This is a common experience: the server is clearly reacting to your input, but the reaction is buried in error noise.

Phase 3: SSRF

The researcher concluded that reading files directly was not going to work, so changed approach: make the server send an HTTP request to a Burp Collaborator instance. Burp Collaborator is a service that gives you a unique address on the internet and tells you when anything contacts it. If the target server reaches out to that address, you know your payload made the server make a request. That is SSRF: the server is tricked into fetching a URL of the attacker's choosing, which is dangerous because the server can often reach internal machines that outsiders cannot.

The payload used for this attempt is not reproduced in the report text.

From the original on 0xmahmoudjo0.medium.com

The result was the same: no interaction. The researcher tried several more SSRF payloads with no success.

After reading older write-ups, the researcher came across a payload that worked. The report does not reproduce the payload text, but notes that SYSTEM can be used as well, since the two are almost synonymous. In XML, SYSTEM and PUBLIC are keywords used when declaring an external entity; they tell the parser where the external resource lives. The researcher decided to use PUBLIC.

From the original on 0xmahmoudjo0.medium.com

With this payload the researcher got an HTTP interaction in Burp Collaborator. At this point the finding was an SSRF, which the author describes as a P4 submission on its own.

Phase 4: Escalating SSRF to a port scan

To raise the severity, the researcher used the SSRF to probe local ports. The idea is simple: if you can make the server request http://[redacted]:<port>, you can ask it about its own internal doorways. [redacted] is the loopback address, meaning "this machine itself". A request was sent to http://[redacted]:9180, a port known to be open, and another to a random port, http://[redacted]:333. The two responses were compared in Burp Comparer, a tool that shows two responses side by side and highlights the differences.

From the original on 0xmahmoudjo0.medium.com

As expected, port 333 returned Connection refused. That message means nothing is listening on that port. The researcher notes that 333 is an uncommon port that was assumed to be closed.

From the original on 0xmahmoudjo0.medium.com

The researcher then ran a simple port scan against the top 10000 ports and filtered responses containing Connection refused, which revealed several open ports. Filtering means looking only at the responses that match a pattern; anything that does not say Connection refused is worth a closer look.

Filter responses that contain Connection refused From the original on 0xmahmoudjo0.medium.com

Filter responses that contain Connection refused

From the original on 0xmahmoudjo0.medium.com

This produced what the researcher calls a P3 in a paid bug bounty programme. Before reporting, the researcher decided to try once more for the XXE, which would be a P1.

Phase 5: Reasoning about OOB XXE

OOB stands for out-of-band. In a normal, in-band attack, the result comes back in the response you are looking at. In an out-of-band attack, the result travels by a different route, for example the server contacts a machine you control. That is useful when the response itself gives you nothing.

The researcher reasoned that the XXE might be out-of-band, which would make /etc/passwd impossible to read because it is a multi-line file, while /etc/hostname would work because it is a single line. /etc/hostname is a small file containing the machine's name. The plan was to host a malicious DTD file and use the SSRF to force the server to request it. A DTD, or Document Type Definition, is a file that describes the structure of an XML document, including the entities it may use. If you can make the server load a DTD you wrote, you control the entities it will resolve.

https://www.synack.com/blog/a-deep-dive-into-xxe-injection/ From the original on 0xmahmoudjo0.medium.com

https://www.synack.com/blog/a-deep-dive-into-xxe-injection/

The researcher describes the OOB XXE flow as follows:

  1. The site requests the malicious DTD file.
  2. The malicious DTD requests /etc/hostname and sends it to the researcher's IP on port 1337.
  3. The listener receives a request containing the /etc/hostname content.

A listener is a small program that waits for incoming connections and prints what it receives. The malicious DTD and the HTTP server on port 8080 are shown in the report but their contents are not reproduced in the text.

From the original on 0xmahmoudjo0.medium.com

Phase 6: Successful OOB XXE

The listener received the hostname, confirming the OOB XXE.

From the original on 0xmahmoudjo0.medium.com

At this point the researcher could read single-line files but not multi-line files such as /etc/passwd or /etc/hosts. The researcher was concerned that this limitation might reduce the severity to P2 or lower, and decided to try to read large files.

Phase 7: Reading large files via error messages

The researcher tried the usual techniques for large files in OOB XXE, including base64 encoding, FTP, and tools that exfiltrate data over FTP, but all failed. Base64 is a way of turning binary data into plain text so it can travel safely through systems that only expect text. FTP is an older file transfer protocol. Exfiltration means getting data out of a system without permission.

The remaining approach was to leak file contents through error messages. The technique works as follows:

  1. Host a malicious DTD file that does two things:
    • defines an XML parameter entity containing the content of /etc/passwd;
    • defines an XML parameter entity containing a dynamic declaration of another XML parameter entity, which is evaluated by loading a nonexistent file whose name contains the first entity, which in turn contains the /etc/passwd content.
  2. When the site requests the DTD file, it tries to load the nonexistent file. The error message about the nonexistent file includes the file name, which includes the /etc/passwd content.

A parameter entity is an entity used inside a DTD rather than inside the document body. The trick is that the parser builds an error message that quotes the name of the file it could not find, and that name has been constructed to contain the secret data.

To demonstrate the mechanism, the researcher hosted a DTD that requested a nonexistent file and used a payload to show that the value of the XML parameter entity %secret is reflected in the response.

From the original on 0xmahmoudjo0.medium.com

The response contained the value of %secret. The researcher then changed the %secret value to /etc/passwd so that the file content would be reflected in the response.

From the original on 0xmahmoudjo0.medium.com

The response contained the contents of /etc/passwd. The researcher reported the finding and it was accepted as a P1.

Root cause

The report does not describe the server-side code or configuration. The behaviour is consistent with an XML parser that resolves external entities, including parameter entities in external DTDs, and that returns parser error messages to the client. The researcher does not state which parser or library was in use, or whether any entity resolution was disabled. The fact that direct in-band entity expansion returned only errors, while external DTD loading and error-based reflection worked, suggests that the parser was configured in a way that allowed external entity resolution but did not allow the entity value to be expanded inline in the response. This is an inference from the observed behaviour, not something the report states.

Impact

Under the conditions observed, an attacker who can reach the XML endpoint could:

  • make the server issue HTTP requests to arbitrary hosts (SSRF), including internal addresses;
  • use that SSRF to scan internal ports and identify open services;
  • read local files, including multi-line files such as /etc/passwd, through error-based exfiltration.

The researcher notes that the SSRF alone was rated P4, the port scan P3, and the OOB XXE was accepted as P1.

Fix

The standard remediation for this class of issue is to disable external entity and external DTD resolution in the XML parser, and to avoid returning raw parser error messages to clients.

Variants to test

  • Direct in-band entity expansion: send an XML body with a DOCTYPE that defines an entity pointing to a local file. A positive result is the file content appearing in the response.
  • SSRF via external entity: define an entity pointing to an attacker-controlled URL and watch for an interaction. A positive result is an HTTP request from the target to the listener.
  • SSRF port scan: use the SSRF to request http://[redacted]:<port> for a range of ports and compare responses. A positive result is a response that differs from Connection refused.
  • OOB XXE with external DTD: host a DTD that reads a single-line file and sends it to a listener. A positive result is the file content arriving at the listener.
  • Error-based exfiltration: host a DTD that defines a parameter entity containing a file's content and a second parameter entity that loads a nonexistent file whose name includes the first entity. A positive result is the file content appearing in the parser error message.
  • SYSTEM versus PUBLIC: if one keyword fails, try the other, since the report notes they are almost synonymous.

Glossary

  • Bug bounty programme: a scheme where a company pays outside researchers for reporting security weaknesses in its systems.
  • P1, P2, P3, P4: priority levels used by bug bounty platforms, where P1 is the most serious and P4 the least.
  • XML: a text format for structuring data so that computers can exchange it.
  • XML parser: the program that reads XML and turns it into data the application can use.
  • Entity: a placeholder in XML that the parser replaces with something else.
  • External entity: an entity that points at a file or URL outside the document.
  • XXE (XML External Entity): a bug where an XML parser is tricked into fetching external entities, letting an attacker read files or make requests.
  • SSRF (Server-Side Request Forgery): a bug where an attacker makes a server send requests to addresses of the attacker's choosing.
  • OOB (out-of-band): a technique where the result of an attack travels by a different route than the normal response, for example to a server the attacker controls.
  • Recon: the information-gathering stage of a security test.
  • Shodan: a search engine that indexes devices and services connected to the internet.
  • IP address: the numeric address of a machine on a network.
  • Port: a numbered doorway on a machine through which a service listens.
  • Port scan: trying many ports on a machine to see which ones answer.
  • HTTP: the protocol browsers and servers use to exchange requests and responses.
  • HTTP probe: a simple request sent to check whether a service answers.
  • Burp Suite: a tool that intercepts, inspects, edits and replays HTTP requests.
  • Burp Collaborator: a service that gives you a unique address and reports when anything contacts it.
  • Burp Comparer: a tool that shows two responses side by side and highlights differences.
  • POST request: an HTTP request that sends data to the server.
  • Content-Type header: a header that tells the server what kind of data a request contains.
  • Payload: the piece of input crafted to trigger a bug.
  • SYSTEM and PUBLIC: XML keywords used when declaring an external entity, telling the parser where the resource lives.
  • [redacted]: the loopback address, meaning the machine itself.
  • Connection refused: the message returned when nothing is listening on a port.
  • DTD (Document Type Definition): a file that describes the structure of an XML document, including its entities.
  • Parameter entity: an entity used inside a DTD rather than in the document body.
  • Listener: a small program that waits for incoming connections and prints what it receives.
  • Base64: a way of turning binary data into plain text.
  • FTP: an older protocol for transferring files.
  • Exfiltration: getting data out of a system without permission.
  • /etc/passwd: a file on Linux systems that lists user accounts.
  • /etc/hostname: a small file on Linux systems containing the machine's name.
  • /etc/hosts: a file on Linux systems that maps host names to IP addresses.
  • Remediation: the fix applied to close a vulnerability.

More by Mahmoud Youssef

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

XML external entities (XXE)

The lesson behind this report.

An XML parser resolves entities the attacker defines, reading local files or making the server send requests.