Local DTD reuse (error-based, no OOB)
Local DTD reuse XXE lets you exfiltrate data when the server has no outbound network at all: instead of hosting your own external DTD, you reference a DTD file that already exists on the target (such as a GNOME or Linux docs DTD) and redefine one of its parameter entities to run the error-based chain entirely locally.
- Target formats
- Plain XMLSOAP
- Affected parsers
- Java XercesPHP libxmlPython lxml
- Impact
- Blind file disclosure without outbound network
How it works
Blind and error-based XXE normally fetch an external DTD from the attacker's server, which fails if outbound traffic is blocked. Local DTD reuse removes that requirement: you load a DTD that is already present on the filesystem, then redefine one of the parameter entities it declares.
XML lets an earlier parameter-entity definition win, so by predefining the entity with your malicious value before including the local DTD, you hijack it to build the error-based exfiltration chain — no attacker-hosted DTD, no outbound connection.
Which parser configuration makes it work
Requires a known DTD file path on the target OS and a parser that loads it and surfaces errors. It is the technique of choice when the server resolves entities but is fully egress-filtered.
Representative payloads
Replace callback hosts and target paths with your own authorized test values.
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY % local_dtd SYSTEM "file:///usr/share/yelp/dtd/docbookx.dtd">
<!ENTITY % ISOamso '
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file;'>">
%eval;
%error;
'>
%local_dtd;
]>
<foo>trigger</foo>ISOamso is a parameter entity defined inside docbookx.dtd; redefining it before %local_dtd; hijacks the parse.
Variants
Windows / .NET DTD paths
On Windows targets, DTDs shipped with .NET or office tooling can be reused the same way; the method is identical, only the file path and the hijacked entity name change.
Detection
As a tester, enumerate likely DTD paths for the target platform and look for the file contents in the parse error. As a defender, this technique proves that egress filtering alone is not a fix: watch for DOCTYPE bodies that reference local file:// DTD paths and for parse errors leaking file fragments, and remember that a blocked internet connection does not stop it.
- SYSTEM entities pointing at local .dtd file paths
- Redefinition of well-known parameter entities (ISOamso, etc.)
- File-content fragments appearing in returned parse errors
Remediation
Disable DOCTYPE processing at the parser — because this attack needs the internal DTD subset, rejecting DOCTYPE stops it even though it uses no outbound network. Do not treat egress filtering as the control: local DTD reuse works offline. Also suppress parser errors to the client. If DTDs must be allowed, disable external parameter entities and external DTD loading so neither the local DTD nor a redefined entity can be loaded.
Fix checklist
- Reject DOCTYPE declarations (primary fix; works even when egress is blocked)
- Do not rely on blocking outbound network as the only defence
- Suppress parser errors returned to the client
- Disable external parameter entities and external DTD loading