19.09.2017 Views

the-web-application-hackers-handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

If <strong>the</strong> <strong>application</strong> blocks <strong>the</strong> uploaded file, try to use various file extensions,<br />

including .txt and .jpg. If <strong>the</strong> <strong>application</strong> accepts a file containing HTML when<br />

you use a different extension, it may still be vulnerable, depending on exactly<br />

how <strong>the</strong> file is delivered during download. Web mail <strong>application</strong>s are often<br />

vulnerable in this way. An attacker can send e-mails containing a seductivesounding<br />

image attachment that in fact compromises <strong>the</strong> session of any user<br />

who views it.<br />

Even if <strong>the</strong> <strong>application</strong> returns a Content-Type header specifying that <strong>the</strong><br />

downloaded file is an image, some browsers may still process its contents as<br />

HTML if this is what <strong>the</strong> file actually contains. For example:<br />

HTTP/1.1 200 OK<br />

Content-Length: 25<br />

Content-Type: image/jpeg<br />

alert(1)<br />

Older versions of Internet Explorer behaved in this way. If a user requested a<br />

.jpg file directly (not via an embedded tag), and <strong>the</strong> preceding response<br />

was received, IE would actually process its contents as HTML. Although this<br />

behavior has since been modified, it is possible that o<strong>the</strong>r browsers may behave<br />

this way in <strong>the</strong> future.<br />

Hybrid File Attacks<br />

Often, to defend against <strong>the</strong> attacks described so far, <strong>application</strong>s perform<br />

some validation of <strong>the</strong> uploaded file’s contents to verify that it actually contains<br />

data in <strong>the</strong> expected format, such as an image. These <strong>application</strong>s may<br />

still be vulnerable, using “hybrid files” that combine two different formats<br />

within <strong>the</strong> same file.<br />

One example of a hybrid file is a GIFAR file, devised by Billy Rios. A GIFAR<br />

file contains data in both GIF image format and JAR (Java archive) format and<br />

is actually a valid instance of both formats. This is possible because <strong>the</strong> file<br />

metadata relating to <strong>the</strong> GIF format is at <strong>the</strong> start of <strong>the</strong> file, and <strong>the</strong> metadata<br />

relating to <strong>the</strong> JAR format is at <strong>the</strong> end of <strong>the</strong> file. Because of this, <strong>application</strong>s<br />

that validate <strong>the</strong> contents of uploaded files, and that allow files containing GIF<br />

data, accept GIFAR files as valid.<br />

An uploaded file attack using a GIFAR file typically involves <strong>the</strong> following<br />

steps:<br />

n The attacker finds an <strong>application</strong> function in which GIF files that are<br />

uploaded by one user can be downloaded by o<strong>the</strong>r users, such as a user’s<br />

profile picture in a social networking <strong>application</strong>.<br />

n The attacker constructs a GIFAR file containing Java code that hijacks <strong>the</strong><br />

session of any user who executes it.

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

Saved successfully!

Ooh no, something went wrong!