avatarHuy Phu

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1150

Abstract

">email</span> [ <span class="hljs-meta"><!ENTITY <span class="hljs-keyword">test</span> <span class="hljs-string">"This is a test Payload."</span>></span> ]></span></pre></div><figure id="4bf4"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*DVHfotxqb-qBHN4aex8PUw.png"><figcaption></figcaption></figure><p id="5f65">From the above image, <code>(1)</code> is the declaration of the entity named test, whose value is the string “This is a test Payload.” <code>(2)</code> is where we refer the <code>test entity</code> using <code>&</code> and <code>;</code>. <code>(3)</code> is where the entity <code>test</code> is displayed. This is a clear indicator that the application is vulnerable to XXE Injection.</p><h1 id="fbe5">Exploiting the vulnerability</h1><h2 id="a270">Local File Disclosure with XXE</h2><p id="e2f9">In a regular Local File Disclosure attack, when we want to read a file, we use <code>file://</code> filter. As the first instinct, we try <code>file:///etc/passwd</code></p><p id="ef83">However, this does not work as the file is not in XML format, which will eventually break the application. To wo

Options

rk around, we use wrapper <code>php://filter</code> with <code>convert.base64-encode</code> function to encoded the content of the file we want to read. By doing this, the server will response a string, which does not break the application.</p><figure id="9bf8"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*MPhJILmedDUJyRDVkmoVVA.png"><figcaption></figcaption></figure><p id="9b4e">As seen in the above screenshot, <code>(1)</code> is where we inject our payload using <code>php://filter</code> wrapper. <code>(2)</code> is the response from the server, which is the base64-encoded string of the file <code>index.php</code> that we requested. Finally, on the right hand side, <code>(3)</code> shows the decoded/original version of <code>index.php</code> file.</p><p id="3b2f">Using the same technique, we can read the content of <code>connection.php</code>, which contains the flag for this challenge.</p><figure id="8a3e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*aWC6cPGXp3DRQHzkeQdUrw.png"><figcaption></figcaption></figure><p id="74aa"><i>UTM1NjM0MmRzJ2dmcTIzND0wMXJnZXdmc2RmCg</i></p></article></body>

HackTheBox — Web Attacks: From XXE Injection to Local File Disclosure

Identifying the vulnerability

We need to find a web page that parses XML format. From the target machine, fill out the form and submit it. Intercept the request with Burp Suite.

Continue with the request in Burp Suite, we see that the response displays user’s email. Now wqe know that we should inject our payload into the email field.

Try creating a new XML entity and try to put it in the email field to check if the application displays the injected entity.

<!DOCTYPE email [
  <!ENTITY test "This is a test Payload.">
]>

From the above image, (1) is the declaration of the entity named test, whose value is the string “This is a test Payload.” (2) is where we refer the test entity using & and ;. (3) is where the entity test is displayed. This is a clear indicator that the application is vulnerable to XXE Injection.

Exploiting the vulnerability

Local File Disclosure with XXE

In a regular Local File Disclosure attack, when we want to read a file, we use file:// filter. As the first instinct, we try file:///etc/passwd

However, this does not work as the file is not in XML format, which will eventually break the application. To work around, we use wrapper php://filter with convert.base64-encode function to encoded the content of the file we want to read. By doing this, the server will response a string, which does not break the application.

As seen in the above screenshot, (1) is where we inject our payload using php://filter wrapper. (2) is the response from the server, which is the base64-encoded string of the file index.php that we requested. Finally, on the right hand side, (3) shows the decoded/original version of index.php file.

Using the same technique, we can read the content of connection.php, which contains the flag for this challenge.

UTM1NjM0MmRzJ2dmcTIzND0wMXJnZXdmc2RmCg

Hackthebox
Xxe Attack
Web Security
Owasp Top 10
Local File Inclusion
Recommended from ReadMedium