19.09.2017 Views

the-web-application-hackers-handbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

484 Chapter 12 n Attacking Users: Cross-Site Scripting<br />

The following is an example of a raw e-mail file. As well as testing various<br />

XSS payloads and filter bypasses in <strong>the</strong> message body, you can also try specifying<br />

a different Content-Type and charset:<br />

MIME-Version: 1.0<br />

From: test@example.org<br />

Content-Type: text/html; charset=us-ascii<br />

Content-Transfer-Encoding: 7bit<br />

Subject: XSS test<br />

<br />

<br />

<br />

<br />

<br />

.<br />

Testing for XSS in Uploaded Files<br />

One common, but frequently overlooked, source of stored XSS vulnerabilities<br />

arises where an <strong>application</strong> allows users to upload files that can be downloaded<br />

and viewed by o<strong>the</strong>r users. This kind of functionality arises frequently in today’s<br />

<strong>application</strong>s. In addition to traditional work flow functions designed for file<br />

sharing, files can be sent as e-mail attachments to <strong>web</strong> mail users. Image files<br />

can be attached to blog entries and can be used as custom profile pictures or<br />

shared via photo albums.<br />

Various factors may affect whe<strong>the</strong>r an <strong>application</strong> is vulnerable to uploaded<br />

file attacks:<br />

n During file upload, <strong>the</strong> <strong>application</strong> may restrict <strong>the</strong> file extensions that<br />

can be used.<br />

n During file upload, <strong>the</strong> <strong>application</strong> may inspect <strong>the</strong> file’s contents to confirm<br />

that this complies with an expected format, such as JPEG.<br />

n During file download, <strong>the</strong> <strong>application</strong> may return a Content-Type header<br />

specifying <strong>the</strong> type of content that <strong>the</strong> <strong>application</strong> believes <strong>the</strong> file contains,<br />

such as image/jpeg.<br />

n During file download, <strong>the</strong> <strong>application</strong> may return a Content-Disposition<br />

header that specifies <strong>the</strong> browser should save <strong>the</strong> file to disk. O<strong>the</strong>rwise,<br />

for relevant content types, <strong>the</strong> <strong>application</strong> processes and renders <strong>the</strong> file<br />

within <strong>the</strong> user’s browser.<br />

When examining this functionality, <strong>the</strong> first thing you should do is try to<br />

upload a simple HTML file containing a proof-of-concept script. If <strong>the</strong> file is<br />

accepted, try to download <strong>the</strong> file in <strong>the</strong> usual way. If <strong>the</strong> original file is returned<br />

unmodified, and your script executes, <strong>the</strong> <strong>application</strong> is certainly vulnerable.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!