> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/web/xxe/xxe-via-malicious-image-upload.md).

# XXE via Malicious Image Upload

XXE via Malicious Image Upload notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Exploiting XXE via Image File Upload

Exploiting a XXE vulnerability by sending a malicious image (SVG) which, during processing by the Apache Batik library, reveals the content of a local file. The exercise requires to upload an SVG avatar displaying `/etc/hostname` content and then submit the host name as a solution.

The site offers a form to add d的avatar for comments. By intercepting the d

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b6c50bc60b50f0a6601edc7d2e993c688fcce39a%2F%7B5916D6B8-BF3F-4B83-81A1-7939B73F35DF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-deb2d7e349fb839b8cfa7bc609d06c54d4c367d0%2F%7BDC74CA07-F8EC-417A-8DF2-5749BFA83626%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Create a SVG file containing a `<!DOCTYPE>` statement that defines an external entity pointing to `file:///etc/hostname` and then insert that entity into the SVG text so that, once rendered/processed, the contents of the file are injected into the displayed image.

```svg
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:///etc/hostname" > ]>
<svg width="128px" height="128px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
   <text font-size="16" x="0" y="16">&xxe;</text>
</svg>
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a343b3264d357cef21e140b4f35c0a4beda7e57b%2F%7B5AC5DB1F-C391-431C-9982-BD190FA54C67%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

After upload, the display of the avatar in the comments section shows that the server interpreted the SVG and returned the entity value — the content of `/etc/hostname` appears in the image, allowing to retrieve the host name and submit the solution.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e2d53d5c99fede0707e750fa8d06ef7d64984257%2F%7BAC47938B-9598-40B7-851B-A27A65E30360%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/web/xxe/xxe-via-malicious-image-upload.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
