XXE Lab: Read Server Files Through an XML Upload

✨ AI Summary
DocParse accepts XML documents and shows you what it parsed. XML has an old feature called entities, a way to define a shortcut that expands into other text. Some entities can point at a file, and the parser will fetch it. Define one that points at a system file, use it in your document, and the parser pastes that file into its output for you.
Lab at a glance: Intermediate · 100 XP · about 15 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

XML External Entity injection (XXE) abuses the document type definition (DTD) part of XML. A DTD can declare an entity whose value comes from an external source such as a file path or URL. If the parser processes external entities, which many older parsers did by default, an attacker can read local files or make the server send requests.

How DocParse handles XML

DocParse parses uploaded XML with external entity loading switched on, then echoes the parsed values back. The lab is solved when the contents of the system password file, /etc/passwd, appear in the output.

The attack approach

  • Submit a small valid XML document first and see which element values are echoed back.
  • Add a DOCTYPE declaration at the top of the document. This is where entities are defined.
  • Declare an external entity whose system identifier is a file:// URL for the target file.
  • Use that entity inside an element that gets echoed, so its expanded value is shown to you.

Full walkthrough (spoiler)

Stuck after a few attempts? Open the steps below. Solving it yourself first is worth more XP, and more learning.

Show the step-by-step solution
  1. Start with a simple document that has a root element and a child element such as a name.
  2. Above the root, add a DOCTYPE that declares one entity, marked SYSTEM, pointing at the file URL for /etc/passwd.
  3. Put a reference to that entity (an ampersand, its name, then a semicolon) inside the name element.
  4. Submit. The parser expands the entity by reading the file and places its contents in the echoed output. The lab marks you solved.

Why it works

The parser is doing exactly what the XML specification describes: when it meets an entity reference, it replaces it with the entity’s value, fetching it if the value is external. The application never needed DTDs or external entities, but the parser had them switched on, so it read a local file because the document asked it to.

Core principleDisable DTDs and external entities in every XML parser that handles untrusted input.

Where this happens in the real world

XXE had its own category in the OWASP Top 10 in 2017 (A4) and was folded into Security Misconfiguration in 2021. It shows up wherever XML is accepted, often in places people forget: SOAP APIs, SAML single sign-on, and file formats built on XML such as DOCX, XLSX and SVG. Beyond file reading, XXE can be used for SSRF and, with the “billion laughs” trick, for denial of service.

How to defend against it

  • Turn off DTD processing entirely if you do not need it, which is almost always.
  • Disable external entity resolution explicitly in your parser’s settings; do not rely on defaults.
  • Keep XML libraries updated. Modern versions are safer by default, but old code paths are not.
  • Prefer simpler formats such as JSON when you control the API.
  • Remember XML in disguise: office documents, SVG uploads and SAML responses all need the same care.
Mr Elite tip: If a target accepts JSON, try sending the same data as XML with the content type changed. Some frameworks quietly accept both, and the XML path is often the forgotten one.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is XXE?
XML External Entity injection is a vulnerability where an XML parser processes attacker-defined external entities, letting the attacker read server files, make the server send requests, or exhaust its resources.
What is the billion laughs attack?
A denial-of-service attack that uses nested XML entities which expand exponentially, so a tiny document consumes huge amounts of memory when parsed.
How do I prevent XXE?
Disable DTD processing and external entity resolution in your XML parser, and keep XML libraries up to date.
Where else can XXE appear?
Anywhere XML is parsed, including SOAP and SAML endpoints and XML-based file formats such as DOCX, XLSX and SVG.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *