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.

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

According to specifications, tags should appear within <strong>the</strong> <br />

section of <strong>the</strong> HTML page. However, some browsers, including Firefox, accept<br />

tags appearing anywhere in <strong>the</strong> page, considerably widening <strong>the</strong> scope<br />

of this attack.<br />

Space Following <strong>the</strong> Tag Name<br />

Several characters can replace <strong>the</strong> space between <strong>the</strong> tag name and <strong>the</strong> first<br />

attribute name:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Note that even where an attack does not require any tag attributes, you should<br />

always try adding some superfluous content after <strong>the</strong> tag name, because this<br />

bypasses some simple filters:<br />

alert(1)<br />

Attribute Names<br />

Within <strong>the</strong> attribute name, you can use <strong>the</strong> same NULL byte trick described<br />

earlier. This bypasses many simple filters that try to block event handlers by<br />

blocking attribute names starting with on:<br />

<br />

Attribute Delimiters<br />

In <strong>the</strong> original example, attribute values were not delimited, requiring some<br />

whitespace after <strong>the</strong> attribute value to indicate that it has ended before ano<strong>the</strong>r<br />

attribute can be introduced. Attributes can optionally be delimited with double<br />

or single quotes or, on IE, with backticks:<br />

<br />

<br />

<br />

Switching around <strong>the</strong> attributes in <strong>the</strong> preceding example provides a fur<strong>the</strong>r<br />

way to bypass some filters that check for attribute names starting with on. If<br />

<strong>the</strong> filter is unaware that backticks work as attribute delimiters, it treats <strong>the</strong><br />

following example as containing a single attribute, whose name is not that of<br />

an event handler:<br />

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

Saved successfully!

Ooh no, something went wrong!