邪恶八进制信息安全团队技术讨论组's Archiver

EvilOctal 2005-12-2 04:48

[转载]DOM Based Cross Site Scripting or XSS of the Third Kind

文章作者:Amit Klein ( aksecurity (at) hotpop (dot) com )<BR><BR>
<H3>Summary</H3>
<P>We all know what Cross Site Scripting (XSS) is, right? It’s that vulnerability wherein one sends malicious data (typically HTML stuff with java script code in it) that is echoed back later by the application in an HTML context of some sort, and the java script code gets executed. Well, wrong. There’s a kind of XSS which does not match this description, at least not in some fundamental properties. The XSS attacks described above are either “non-persistent”/“reflected” (i.e. the malicious data is embedded in the page that is returned to the browser immediately following the request) or “persistent”/“stored” (in which case the malicious data is returned at some later time). But there’s also a third kind of XSS attacks - the ones that do not rely on sending the malicious data to the server in the first place! While this seems almost contradictory to the definition or to common sense, there are, in fact, two well described examples for such attacks. This technical note discusses the third kind of XSS, dubbed “DOM Based XSS”. No claim is made to novelty in the attacks themselves, of course, but rather, the innovation in this write-up is about noticing that these belong to a different flavor, and that flavor is interesting and important. </P>
<P>Application developers and owners need to understand DOM Based XSS, as it represents a threat to the web application, which has different preconditions than standard XSS. As such, there are many web applications on the Internet that are vulnerable to DOM Based XSS, yet when tested for (standard) XSS, are demonstrated to be “not vulnerable”. Developers and site maintainers (and auditors) need to familiarize themselves with techniques to detect DOM Based XSS vulnerabilities, as well as with techniques to defend against them, both therewhich are different than the ones applicable for standard XSS.</P><BR>
<H3>Introduction</H3>
<P>The reader is assumed to possess basic knowledge of XSS (<A href="http://www.webappsec.org/projects/articles/071105.shtml#r1">[1]</A>, <A href="http://www.webappsec.org/projects/articles/071105.shtml#r2">[2]</A>, <A href="http://www.webappsec.org/projects/articles/071105.shtml#r3">[3]</A>, <A href="http://www.webappsec.org/projects/articles/071105.shtml#r4">[4]</A>, <A href="http://www.webappsec.org/projects/articles/071105.shtml#r8">[8]</A>). XSS is typically categorized into “non-persistent” and “persistent” (<A href="http://www.webappsec.org/projects/articles/071105.shtml#r3">[3]</A>, “reflected” and “stored” accordingly, as defined in <A href="http://www.webappsec.org/projects/articles/071105.shtml#r4">[4]</A>). “Non-persistent” means that the malicious (java script) payload is echoed by the server in an immediate response to an HTTP request from the victim. “Persistent” means that the payload is stored by the system, and may later be embedded by the vulnerable system in an HTML page provided to a victim. As mentioned in the summary, this categorization assumes that a fundamental property of XSS is having the malicious payload move from the browser to the server and back to the same (in non-persistent XSS) or any (in persistent XSS) browser. This paper points out that this is a misconception. While there are not many counterexamples in the wild, the mere existence of XSS attacks which do not rely on the payload embedded by the server in some response page, is of importance as it has a significant impact on detection and protection methods. This is discussed in the document.</P><BR>
<H3>Example and Discussion</H3>
<P>Before describing the basic scenario, it is important to stress that the techniques outlined here were already demonstrated in public (e.g. <A href="http://www.webappsec.org/projects/articles/071105.shtml#r5">[5]</A>, <A href="http://www.webappsec.org/projects/articles/071105.shtml#r6">[6]</A> and <A href="http://www.webappsec.org/projects/articles/071105.shtml#r7">[7]</A>). As such, it is not claimed that the below are new techniques (although perhaps some of the evasion techniques are).</P>
<P>The prerequisite is for the vulnerable site to have an HTML page that uses data from the <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location</SPAN> or <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.URL</SPAN> or <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.referrer</SPAN> (or any various other objects which the attacker can influence) in an insecure manner.</P>
<P>NOTE for readers unfamiliar with those java script objects: when java script is executed at the browser, the browser provides the java script code with several objects that represent the DOM (Document Object Model). The <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document</SPAN> object is chief among those objects, and it represents most of the page’s properties, as experienced by the browser. This <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document</SPAN> object contains many sub-objects, such as <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">location</SPAN>, <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">URL</SPAN> and <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">referrer</SPAN>. These are populated by the browser according to the browser’s point of view (this is significant, as we’ll see later with the fragments). So, <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.URL</SPAN> and <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location</SPAN> are populated with the URL of the page, as the browser understands it. Notice that these objects are not extracted of the HTML body - they do not appear in the page data. The <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document</SPAN> object does contain a <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">body</SPAN> object that is a representation of the parsed HTML.</P>
<P>It is not uncommon to find an application HTML page containing java script code that parses the URL line (by accessing <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.URL</SPAN> or <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location</SPAN>) and performs some client side logic according to it. The below is an example to such logic.</P>
<P>In analogy to the example in <A href="http://www.webappsec.org/projects/articles/071105.shtml#r2">[2]</A> (and as an essentially identical scenario to the one in <A href="http://www.webappsec.org/projects/articles/071105.shtml#r7">[7]</A>), consider, for example, the following HTML page (let’s say this is the content of <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">[url]http://www.vulnerable.site/welcome.html[/url]</SPAN>): <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><BR><BR><HTML><BR><TITLE>Welcome!</TITLE><BR>Hi<BR><SCRIPT><BR>var pos=document.URL.indexOf("name=")+5;<BR>document.write(document.URL.substring(pos,document.URL.length));<BR></SCRIPT><BR><BR><BR>Welcome to our system<BR>…<BR></HTML><BR><BR></SPAN></P>Normally, this HTML page would be used for welcoming the user, e.g.:<BR><BR> [url]http://www.vulnerable.site/welcome.html?name=Joe[/url]<BR><BR>However, a request such as:<BR><BR> [url]http://www.vulnerable.site/welcome.html?name=[/url]<BR> <script>alert(document.cookie)</script> <BR><BR>
<P>would result in an XSS condition. Let’s see why: the victim’s browser receives this link, sends an HTTP request to <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">www.vulnerable.site</SPAN>, and receives the above (static!) HTML page. The victim’s browser then starts parsing this HTML into DOM. The DOM contains an object called document, which contains a property called URL, and this property is populated with the URL of the current page, as part of DOM creation. When the parser arrives to the java script code, it executes it and it modifies the raw HTML of the page. In this case, the code references <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.URL</SPAN>, and so, a part of this string is embedded at parsing time in the HTML, which is then immediately parsed and the java script code found (<SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">alert(…)</SPAN>) is executed in the context of the same page, hence the XSS condition. </P><BR>
<P>Notes:<BR>1. The malicious payload was not embedded in the raw HTML page at any time (unlike the other flavors of XSS).</P>
<P>2. This exploit only works if the browser does not modify the URL characters. Mozilla automatically encodes <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><</SPAN> and <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">></SPAN> (into <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">%3C</SPAN> and <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">%3E</SPAN>, respectively) in the <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.URL</SPAN> when the URL is not directly typed at the address bar, and therefore it is not vulnerable to the attack as shown in the example. It is vulnerable to attacks if <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><</SPAN> and <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">></SPAN> are not needed (in raw form). Microsoft Internet Explorer 6.0 does not encode <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><</SPAN> and <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">></SPAN>, and is therefore vulnerable to the attack as-is.</P>
<P>Of course, embedding in the HTML directly is just one attack mount point, there are various scenarios that do not require <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><</SPAN> and <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">></SPAN>, and therefore Mozilla in general is not immune from this attack.</P><BR>
<H3>Evading standard detection and prevention technologies</H3>
<P>In the above example, it may be argued that still, the payload did arrive to the server (in the query part of the HTTP request), and so it can be detected just like any other XSS attack. But even that can be taken care of. Consider the following attack: <BR><BR>[url]http://www.vulnerable.site/welcome.html#name=<script>alert[/url](document.cookie)<script> <BR><BR>Notice the number sign (<SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">#</SPAN>) right after the file name. It tells the browser that everything beyond it is a fragment, i.e. not part of the query. Microsoft Internet Explorer (6.0) and Mozilla do not send the fragment to the server, and therefore, the server would see the equivalent of <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">[url]http://www.vulnerable.site/welcome.html[/url]</SPAN>, so the payload would not even be seen by the server. We see, therefore, that this evasion technique causes the major browsers not to send the malicious payload to the server.</P>
<P>Sometimes, it’s impossible to completely hide the payload: in <A href="http://www.webappsec.org/projects/articles/071105.shtml#r5">[5]</A> and <A href="http://www.webappsec.org/projects/articles/071105.shtml#r6">[6]</A>, the malicious payload is part of the username, in a URL that looks like <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">[url]http://username@host/[/url]</SPAN>. The browser, in such case, sends a request with Authorization header containing the username (the malicious payload), and thus, the payload does arrive to the server (Base64 encoded - so IDS/IPS would need to decode this data first in order to observe the attack). Still, the server is not required to embed this payload in order for the XSS condition to occur.</P>
<P>Obviously, in situations where the payload can be completely hidden, online detection (IDS) and prevention (IPS, web application firewalls) products cannot fully defend against this attack, assuming the vulnerable script can indeed be invoked from a known location. Even if the payload has to be sent to the server, in many cases it can be crafted in such way to avoid being detected, e.g. if a specific parameter is protected (e.g. the name parameter in the above example), then a slight variation of the attack may succeed: <BR><BR> [url]http://www.vulnerable.site/welcome.html?notname=<script>[/url](document.cookie)</script><BR><BR>A more strict security policy would require that the name parameter be sent (to avoid the above tricks with names and number sign). We can therefore send this:<BR><BR> [url]http://www.vulnerable.site/welcome.html?notname=[/url]<BR> <script>alert(document.cookie)<script>&name=Joe<BR><BR>If the policy restricts the additional parameter name (e.g. to <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">foobar</SPAN>), then the following variant would succeed:<BR><BR> [url]http://www.vulnerable.site/welcome.html?foobar=[/url]<BR> name=<script>alert(document.cookie)<script>&name=Joe<BR><BR>Note that the ignored parameter (<SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">foobar</SPAN>) must come first, and it contains the payload in its value.</P>
<P>The scenario in <A href="http://www.webappsec.org/projects/articles/071105.shtml#r7">[7]</A> is even better from the attacker’s perspective, since the full <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location</SPAN> is written to the HTML page (the java script code does not scan for a specific parameter name). Therefore, the attacker can completely hide the payload e.g. by sending:<BR><BR> /attachment.cgi?id=&action=<BR> foobar#<script>alert(document.cookie)</script><BR><BR>Even if the payload is inspected by the server, protection can be guaranteed only if the request in its fullness is denied, or if the response is replaced with some error text. Consider <A href="http://www.webappsec.org/projects/articles/071105.shtml#r5">[5]</A> and <A href="http://www.webappsec.org/projects/articles/071105.shtml#r6">[6]</A> again, if the Authorization header is simply removed by an intermediate protection system, it has no effect as long as the original page is returned. Likewise, any attempt to sanitize the data on the server, either by removing the offending characters or by encoding them, is ineffective against this attack.</P>
<P>In the case of <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.referrer</SPAN> , the payload is sent to the server through the Referer header. However, if the user’s browser, or an intermediate device eliminates this header, then there’s no trace of the attack - it may go completely unnoticed. <BR><BR>To generalize, traditional methods of:<BR> 1. HTML encoding output data at the server side<BR> 2. Removing/encoding offending input data at the server side<BR>Do not work well against DOM Based XSS. <BR></P>
<P>Regarding automatic vulnerability assessment by way of fault injection (sometimes called fuzzing) won’t work, since products that use this technology typically evaluate the results according to whether the injected data is present in the response page or not (rather than execute the client side code in a browser context and observe the runtime effects). However, if a product is able to statically analyze a java script found in a page, then it may point out suspicious patterns (see below). And of course, if the product can execute the java script (and correctly populating the DOM objects), or simulate such execution, then it can detect this attack.</P>
<P>Manual vulnerability assessment using a browser would work because the browser would execute the client side (java script) code. Of course, a vulnerability assessment product may adopt this kind of technology and execute client side code to inspect the runtime effects.</P><BR>
<H3>Effective defenses</H3>
<P>1. Avoiding client side document rewriting, redirection, or other sensitive actions, using client side data. Most of these effects can be achieved by using dynamic pages (server side).</P>
<P>2. Analyzing and hardening the client side (java script) code. Reference to DOM objects that may be influenced by the user (attacker) should be inspected, including (but not limited to):</P>
<UL style="MARGIN-TOP: 0in">
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.URL</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.URLUnencoded</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location (and many of its properties)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.referrer</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.location (and many of its properties)</SPAN> </LI></UL>
<P>Note that a document object property or a window object property may be referenced syntactically in many ways - explicitly (e.g. <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.location</SPAN>), implicitly (e.g. <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">location</SPAN>), or via obtaining a handle to a window and using it (e.g. <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">handle_to_some_window.location</SPAN>).</P>
<P>Special attention should be given to scenarios wherein the DOM is modified, either explicitly or potentially, either via raw access to the HTML or via access to the DOM itself, e.g. (by no means an exhaustive list, there are probably various browser extensions):</P>
<UL style="MARGIN-TOP: 0in">
<LI>Write raw HTML, e.g.:
<UL style="MARGIN-TOP: 0in">
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.write(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.writeln(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.body.innerHtml=…</SPAN> </LI></UL>
<LI>Directly modifying the DOM (including DHTML events), e.g.:
<UL style="MARGIN-TOP: 0in">
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.forms[0].action=… </SPAN>(and various other collections)
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.attachEvent(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.create…(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.execCommand(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.body. … </SPAN>(accessing the DOM through the body object)
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.attachEvent(…)</SPAN> </LI></UL>
<LI>Replacing the document URL, e.g.:
<UL style="MARGIN-TOP: 0in">
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location=… </SPAN>(and assigning to location’s href, host and hostname)
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location.hostname=…</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location.replace(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.location.assign(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.URL=…</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.navigate(…)</SPAN> </LI></UL>
<LI>Opening/modifying a window, e.g.:
<UL style="MARGIN-TOP: 0in">
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">document.open(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.open(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.location.href=… </SPAN>(and assigning to location’s href, host and hostname) </LI></UL>
<LI>Directly executing script, e.g.:
<UL style="MARGIN-TOP: 0in">
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">eval(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.execScript(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.setInterval(…)</SPAN>
<LI><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">window.setTimeout(…)</SPAN> </LI></UL></LI></UL>
<P>To continue the above example, an effective defense can be replacing the original script part with the following code, which verifies that the string written to the HTML page consists of alphanumeric characters only: <BR><BR> <SCRIPT><BR> var pos=document.URL.indexOf("name=")+5;<BR> var name=document.URL.substring(pos,document.URL.length);<BR> if (name.match(/^[a-zA-Z0-9]$/))<BR> {<BR> document.write(name);<BR> }<BR> else<BR> {<BR> window.alert("Security error");<BR> }<BR> </SCRIPT><BR>
<P>Such functionality can (and perhaps should) be provided through a generic library for sanitation of data (i.e. a set of java script functions that perform input validation and/or sanitation). The downside is that the security logic is exposed to the attackers - it is embedded in the HTML code. This makes it easier to understand and to attack it. While in the above example, the situation is very simple, in more complex scenarios wherein the security checks are less than perfect, this may come to play.</P>
<P>3. Employing a very strict IPS policy in which, for example, page welcome.html is expected to receive a one only parameter named “name”, whose content is inspected, and any irregularity (including excessive parameters or no parameters) results in not serving the original page, likewise with any other violation (such as an Authorization header or Referer header containing problematic data), the original content must not be served. And in some cases, even this cannot guarantee that an attack will be thwarted. </P><BR>
<H3>A note about redirection vulnerabilities</H3>
<P>The above discussion is on XSS, yet in many cases, merely using a client side script to (insecurely) redirect the browser to another location is considered vulnerability in itself. In such cases, the above techniques and observations still apply.</P><BR>
<H3>Conclusion</H3>
<P>While most XSS attacks described in public do indeed depend on the server physically embedding user data into the response HTML pages, there are XSS attacks that do not rely on server side embedding of the data. This has material significance when discussing ways to detect and prevent XSS. To date, almost all detection and prevention techniques discussed in public assume that XSS implies that the server receives malicious user input and embeds it in an HTML page. Since this assumption doesn’t hold (or only very partially holds) for the XSS attacks described in this paper, many of the techniques fail to detect and prevent this kind of attacks.</P>
<P>The XSS attacks that rely on server side embedding of user data are categorized into “non-persistent” (or “reflected”) and “persistent” (or “stored”). It is thus suggested that the third kind of XSS, the one that does not rely on server side embedding, be named “DOM Based XSS”. <BR><BR>Here is a comparison between standard XSS and DOM Based XSS: </P>
<TABLE class=MsoTableGrid style="BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-COLLAPSE: collapse; BORDER-BOTTOM-STYLE: none" cellSpacing=0 cellPadding=0 border=1>
<TBODY>
<TR>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P></P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; BORDER-LEFT-WIDTH: 1pt; BORDER-LEFT-COLOR: windowtext; PADDING-BOTTOM: 0in; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P>Standard XSS</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; BORDER-LEFT-WIDTH: 1pt; BORDER-LEFT-COLOR: windowtext; PADDING-BOTTOM: 0in; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P>DOM Based XSS</P></TD></TR>
<TR>
<TD style="BORDER-TOP-WIDTH: 1pt; BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 2.05in; BORDER-TOP-COLOR: windowtext; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P>Root cause</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<P>Insecure embedding of client input in HTML outbound page</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<P>Insecure reference and use (in a client side code) of DOM objects that are not fully controlled by the server provided page</P></TD></TR>
<TR>
<TD style="BORDER-TOP-WIDTH: 1pt; BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 2.05in; BORDER-TOP-COLOR: windowtext; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P>Owner</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<P>Web developer (CGI)</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<P>Web developer (HTML)</P></TD></TR>
<TR>
<TD style="BORDER-TOP-WIDTH: 1pt; BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 2.05in; BORDER-TOP-COLOR: windowtext; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P>Page nature</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<P>Dynamic only (CGI script)</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<P>Typically static (HTML), but not necessarily.</P></TD></TR>
<TR>
<TD style="BORDER-TOP-WIDTH: 1pt; BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 2.05in; BORDER-TOP-COLOR: windowtext; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P>Vulnerability Detection</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<UL style="MARGIN-TOP: 0in">
<LI>Manual Fault injection
<LI>Automatic Fault Injection
<LI>Code Review (need access to the page source) </LI></UL></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<UL style="MARGIN-TOP: 0in">
<LI>Manual Fault Injection
<LI>Code Review (can be done remotely!) </LI></UL></TD></TR>
<TR>
<TD style="BORDER-TOP-WIDTH: 1pt; BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 2.05in; BORDER-TOP-COLOR: windowtext; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P>Attack detection</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<UL style="MARGIN-TOP: 0in">
<LI>Web server logs
<LI>Online attack detection tools (IDS, IPS, web application firewalls) </LI></UL></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<P>If evasion techniques are applicable and used - no server side detection is possible</P></TD></TR>
<TR>
<TD style="BORDER-TOP-WIDTH: 1pt; BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 2.05in; BORDER-TOP-COLOR: windowtext; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid" vAlign=top>
<P>Effective defense</P></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<UL style="MARGIN-TOP: 0in">
<LI>Data validation at the server side
<LI>Attack prevention utilities/tools (IPS, application firewalls) </LI></UL></TD>
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; WIDTH: 2.05in; BORDER-TOP-STYLE: none; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT-STYLE: none" vAlign=top>
<UL style="MARGIN-TOP: 0in">
<LI>Data validation at the client side (in java script)
<LI>Alternative server side logic </LI></UL></TD></TR></TBODY></TABLE><BR>
<H3>References</H3>
<P>Note: the URLs below are up to date at the time of writing (July 4<SUP>th</SUP>, 2005). Some of these materials are live documents, and as such may be updated to reflect the insights of this paper.</P>
<P id=r1>[1] “CERT Advisory CA-2000-02 - Malicious HTML Tags Embedded in Client Web Requests”, CERT, February 2<SUP>nd</SUP>, 2000</P>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.cert.org/advisories/CA-2000-02.html">[url]http://www.cert.org/advisories/CA-2000-02.html[/url]</A></SPAN></P>
<P id=r2>[2] “Cross Site Scripting Explained”, Amit Klein, June 2002</P>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://crypto.stanford.edu/cs155/CSS.pdf">[url]http://crypto.stanford.edu/cs155/CSS.pdf[/url]</A></SPAN></P>
<P id=r3>[3] “Cross-Site Scripting”, Web Application Security Consortium, February 23<SUP>rd</SUP>, 2004</P>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.webappsec.org/projects/threat/classes/cross-site_scripting.shtml">[url]http://www.webappsec.org/projects/threat/classes/cross-site_scripting.shtml[/url]</A></SPAN></P>
<P id=r4>[4] “Cross Site Scripting (XSS) Flaws”, The OWASP Foundation, updated 2004 <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.owasp.org/documentation/topten/a4.html">[url]http://www.owasp.org/documentation/topten/a4.html[/url]</A></SPAN></P>
<P id=r5>[5] “Thor Larholm security advisory TL#001 (IIS allows universal CrossSiteScripting)”, Thor Larholm, April 10<SUP>th</SUP>, 2002</P>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.cgisecurity.com/archive/webservers/iis_xss_4_5_and_5.1.txt">[url]http://www.cgisecurity.com/archive/webservers/iis_xss_4_5_and_5.1.txt[/url]</A></SPAN></P>
<P>(see also Microsoft Security Bulletin MS02-018 <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.microsoft.com/technet/security/bulletin/MS02-018.mspx">[url]http://www.microsoft.com/technet/security/bulletin/MS02-018.mspx[/url]</A></SPAN>)</P>
<P id=r6>[6] “ISA Server Error Page Cross Site Scripting”, Brett Moore, July 16<SUP>th</SUP>, 2003 <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.security-assessment.com/Advisories/ISA%20XSS%20Advisory.pdf">[url]http://www.security-assessment.com/Advisories/ISA%20XSS%20Advisory.pdf[/url]</A></SPAN></P>
<P>(see also Microsoft Security Bulletin MS03-028 <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.microsoft.com/technet/security/bulletin/MS03-028.mspx">[url]http://www.microsoft.com/technet/security/bulletin/MS03-028.mspx[/url]</A> </SPAN>and a more elaborate description in “Microsoft ISA Server HTTP error handler XSS”, Thor Larholm, July 16<SUP>th</SUP>, 2003 <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.securityfocus.com/archive/1/329273">[url]http://www.securityfocus.com/archive/1/329273[/url]</A></SPAN>)</P>
<P id=r7>[7] “Bugzilla Bug 272620 - XSS vulnerability in internal error messages”<SPAN lang=EN>, reported by Michael Krax, </SPAN><SPAN lang=EN>December 23<SUP>rd</SUP>, 2004</SPAN></P>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="https://bugzilla.mozilla.org/show_bug.cgi?id=272620">[url]https://bugzilla.mozilla.org/show_bug.cgi?id=272620[/url]</A></SPAN></P>
<P id=r8>[8] “The Cross Site Scripting FAQ”, Robert Auger, May 2002 (revised August 2003)</P>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"><A href="http://www.cgisecurity.com/articles/xss-faq.shtml">[url]http://www.cgisecurity.com/articles/xss-faq.shtml[/url]</A></SPAN></P><BR>
<H3>About the author</H3>
<P>Amit Klein is a renowned web application security researcher. Mr. Klein has written many research papers on various web application technologies--from HTTP to XML, SOAP and web services--and covered many topics--HTTP request smuggling, insecure indexing, blind XPath injection, HTTP response splitting, securing .NET web applications, cross site scripting, cookie poisoning and more. His works have been published in Dr. Dobb's Journal, SC Magazine, ISSA journal, and IT Audit journal; have been presented at SANS and CERT conferences; and are used and referenced in many academic syllabi. <BR><BR>Mr. Klein is a WASC (Web Application Security Consortium) member. <BR></P>The current copy of this document can be here:<BR><A href="http://www.webappsec.org/articles/">[url]http://www.webappsec.org/articles/[/url]</A><BR><BR>Information on the Web Application Security Consortium's Article Guidelines can be found here:<BR><A href="http://www.webappsec.org/projects/articles/guidelines.shtml">[url]http://www.webappsec.org/projects/articles/guidelines.shtml[/url]</A><BR><BR>A copy of the <STRONG>license</STRONG> for this document can be found here:<BR><A href="http://www.webappsec.org/projects/articles/license.shtml">[url]http://www.webappsec.org/projects/articles/license.shtml[/url]</A>

页: [1]
© 1999-2008 EvilOctal Security Team