<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Joe Walker - csrf tag</title>
  <link>http://directwebremoting.org/blog/joe/tags/csrf/</link>
  <description>Thoughts on Web Development</description>
  <language>en</language>
  <copyright>Joe Walker</copyright>
  <lastBuildDate>Wed, 23 Jul 2008 11:00:41 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Fixing browser security: SameRefererOnly</title>
    <link>http://directwebremoting.org/blog/joe/2007/08/07/fixing_browser_security_samerefereronly.html</link>
    
      
        <description>
          &lt;p&gt;Web security is horribly broken, and lot has been said about CSRF, XSS, DNS-Pinning, etc, but not enough about what we can do to fix the mess.&lt;/p&gt;

&lt;p&gt;I think we could adapt an idea like HttpOnly to tackle CSRF - I&#039;d like to see a &amp;quot;&lt;em&gt;SameRefererOnly&lt;/em&gt;&amp;quot; marker for cookies.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SameRefererOnly&lt;/em&gt; is an indication that a cookie should &lt;strong&gt;only&lt;/strong&gt; be sent to a Site when the referring domain matches the destination domain.&lt;/p&gt;

&lt;p&gt;A number of people have commented that you could use server based referer checking to fix CSRF, however that doesn&#039;t work for 2 reasons, firstly sometimes referers are not sent, and secondly using old versions of Flash, you can forge referer headers anyway.&lt;/p&gt;

&lt;p&gt;However if we move the checking into the browser, then we should be able to instruct browsers to be more careful what they do without our cookies.&lt;/p&gt;

&lt;p&gt;The official spec for Set-Cookie is RFC
&lt;a style=&#034;text-decoration: line-through&#034; href=&#034;http://www.ietf.org/rfc/rfc2109.txt&#034;&gt;2109&lt;/a&gt;/&lt;a href=&#034;http://www.ietf.org/rfc/rfc2965.txt&#034;&gt;2965&lt;/a&gt; 
which says this:&lt;/p&gt;

&lt;pre&gt;Set-Cookie: &amp;lt;name&amp;gt;=&amp;lt;value&amp;gt;[; &amp;lt;name&amp;gt;=&amp;lt;value&amp;gt;][; expires=&amp;lt;date&amp;gt;] \
            [; domain=&amp;lt;domain_name&amp;gt;][; path=&amp;lt;some_path&amp;gt;][; secure]&lt;/pre&gt;

&lt;p&gt;Microsoft&#039;s &lt;a href=&#034;http://msdn2.microsoft.com/en-us/library/ms533046.aspx&#034;&gt;HttpOnly spec&lt;/a&gt; adds this to the end:&lt;/p&gt;

&lt;pre&gt;            [; HttpOnly]&lt;/pre&gt;

&lt;p&gt;I propose that we further add this:&lt;/p&gt;

&lt;pre&gt;            [; SameRefererOnly]&lt;/pre&gt;

&lt;p&gt;Any cookie marked &lt;em&gt;SameRefererOnly&lt;/em&gt; MUST &lt;strong&gt;only&lt;/strong&gt; be sent to servers when the domain of the cookie matches the referring domain. The cookie MUST NOT be sent when there is no referring domain (this might help to prevent CSRF / Phishing mash-ups).&lt;/p&gt;

&lt;p&gt;It&#039;s worth noting that this protection breaks in the presence of XSS flaws in a site, because XSSed commands come from the compromised domain, however that does not make this protection useless.&lt;/p&gt;

&lt;p&gt;Plug-ins like Java and Flash that have their own HTTP pipelines generally don&#039;t send cookies so these systems probably do not need to be patched.&lt;/p&gt;

&lt;p&gt;This proposal has 3 places where it can come in handy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As an additional defence-in-depth layer of protection for a site that already has other CSRF protection.&lt;/li&gt;
&lt;li&gt;On an Intranet site where access through browsers that implement SameRefererOnly can be mandated&lt;/li&gt;
&lt;li&gt;In a future world where enough browsers implement this, that other browsers can be excluded.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note on spelling: The pedant might note that this should be spelt SameRefe&lt;strong&gt;rr&lt;/strong&gt;erOnly - i.e. with a double &#039;r&#039;, and the pedant would normally be correct however this misspelling is so common that
&lt;a href=&#034;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36&#034;&gt;the 
HTTP spec makes it&lt;/a&gt;, and hence
&lt;a href=&#034;http://en.wikipedia.org/wiki/Referrer&#034;&gt;we all follow unquestioningly&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I&#039;m sure there must be some holes in this suggestion, but I make it anyway so someone can move the discussion on.&lt;/p&gt;

        </description>
      
      
    
    
    
    <comments>http://directwebremoting.org/blog/joe/2007/08/07/fixing_browser_security_samerefereronly.html#comments</comments>
    <guid isPermaLink="true">http://directwebremoting.org/blog/joe/2007/08/07/fixing_browser_security_samerefereronly.html</guid>
    <pubDate>Tue, 07 Aug 2007 12:33:55 GMT</pubDate>
  </item>
  
  <item>
    <title>CSRF, Anti-DNS Pinning and NTLM</title>
    <link>http://directwebremoting.org/blog/joe/2007/04/18/csrf_anti_dns_pinning_and_ntlm.html</link>
    
      
        <description>
          &lt;p&gt;Mark Goodwin has written a &lt;a href=&#034;/blog/mark/2007/04/16/integrated_windows_authentication.html&#034;&gt;neat discussion of the extra problems that CSRF causes&lt;/a&gt; when used alongside DNS pinning attacks and against intranets that use NTLM authentication (AKA Integrated Windows Auth)&lt;/p&gt;

&lt;p&gt;The short version is that you might be able to use CSRF and anti-DNS pinning attacks to steal resources from an intranet, including those that need auth NTML authentication.&lt;/p&gt;

&lt;p&gt;Getahead predates DWR by quite a while, and Mark has worked with me on a few projects. For the past few years he&#039;s been a serious security head, and he&#039;s just &lt;a href=&#034;/blog/mark&#034;&gt;started blogging&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I&#039;m not going to link to all his posts, so if you are interested in security; &lt;a href=&#034;/blog/mark/atom.xml&#034;&gt;subscribe&lt;/a&gt;, and I&#039;ll get on with the Ajax and Java stuff.&lt;/p&gt;

        </description>
      
      
    
    
    
    <comments>http://directwebremoting.org/blog/joe/2007/04/18/csrf_anti_dns_pinning_and_ntlm.html#comments</comments>
    <guid isPermaLink="true">http://directwebremoting.org/blog/joe/2007/04/18/csrf_anti_dns_pinning_and_ntlm.html</guid>
    <pubDate>Wed, 18 Apr 2007 09:22:26 GMT</pubDate>
  </item>
  
  <item>
    <title>How to Protect a JSON or Javascript Service</title>
    <link>http://directwebremoting.org/blog/joe/2007/04/04/how_to_protect_a_json_or_javascript_service.html</link>
    
      
        <description>
          &lt;p&gt;There have been lots of explanations recently of the dangers of JSON or JavaScript remoting. This post is about what you can do to protect your scripts.&lt;/p&gt;

&lt;h2&gt;The Problem&lt;/h2&gt;

&lt;p&gt;The issues have been explained before, so I&#039;m going to assume some knowledge of the problem. If you&#039;re not sure, some stuff to read:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I blogged that &lt;a href=&#034;/blog/joe/2007/03/05/json_is_not_as_safe_as_people_think_it_is.html&#034;&gt;JSON is not as safe as people think it is&lt;/a&gt;, and updated it with &lt;a href=&#034;/blog/joe/2007/03/06/json_is_not_as_safe_as_people_think_it_is_part_2.html&#034;&gt;more issues the next day&lt;/a&gt;. I&#039;ve also written &lt;a href=&#034;/blog/joe/2007/01/01/csrf_attacks_or_how_to_avoid_exposing_your_gmail_contacts.html&#034;&gt;about CSRF too&lt;/a&gt;.&lt;/li&gt;

&lt;li&gt;Dan Morrill has written an &lt;a href=&#034;http://groups.google.com/group/Google-Web-Toolkit/web/security-for-gwt-applications&#034;&gt;excellent and lengthy summary&lt;/a&gt;. The fixes are focused on GWT, but the issues are the same for everyone.&lt;/li&gt;

&lt;li&gt;Brent Ashley has just published on developerWorks, about  the &lt;a href=&#034;http://www-128.ibm.com/developerworks/library/x-securemashups/&#034;&gt;future of cross-domain requests&lt;/a&gt;. The article is tangentially relevant, but there is a particularly good set of linked articles.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;The Solutions&lt;/h2&gt;

&lt;p&gt;So what are the solutions? I think there are 3 options. Each has their pros and cons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use a Secret in the Request&lt;/li&gt;
&lt;li&gt;Force pre-eval() Processing&lt;/li&gt;
&lt;li&gt;Force POST requests&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This post is a shortened version of the &lt;a href=&#034;/dwr/security/script-tag-protection&#034;&gt;detailed description of what DWR does&lt;a/&gt; If you are interested in the options &lt;a href=&#034;/dwr&#034;&gt;DWR&lt;/a&gt; takes and how you can configure it, you should read page.

&lt;h2&gt;1. Use a Secret in the Request&lt;/h2&gt;

&lt;p&gt;If you can only support one of these protections, this is the one to chose. Including a secret in the request allows the server to reject the request as invalid before any actions take place. It is common to include the secret in the URL, however this is a slightly vulnerable position for a secret since it is likely to turn up in web server log files and so on.&lt;/p&gt;

&lt;p&gt;It is possible to use cookie values like PHPSESSIONID or JSESSIONID read using Javascript as the secret. The browsers cross-domain rules should prevent attackers from discovering this cookie. However this method will stop working as people begin to switch to using &lt;a href=&#034;http://msdn.microsoft.com/workshop/author/dhtml/httponly_cookies.asp&#034;&gt;HttpOnly&lt;/a&gt; cookies. So it is better to start with a separate secret.&lt;/p&gt;

&lt;h2&gt;2. Force pre-eval() Processing&lt;/h2&gt;

&lt;p&gt;Since &amp;lt;script&amp;gt; tag remoting does not allow you to process the JSON or Javascript before it is eval()ed you can protect your JSON by forcing it to be manipulated before eval(). All 3 of these techniques will prevent your request from being pure JSON, however you may rank security above purity. There are 3 ways to do this:&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;Wrap the JSON in a comment. For example, &lt;code&gt;/* { &#039;data&#039;:&#039;protected&#039; } */&lt;/code&gt;. When this is eval()ed, there will be no result, however if you have fetched the data using XHR or iframe, you can do some string manipulation before eval() to remove the leading /* and trailing */.
&lt;br/&gt;
This method is good for plain JSON, however if you are using Javascript which could contain /* comments */, then you should not use this technique because comments in Javascript do not nest.&lt;/li&gt;

&lt;li&gt;Prefix the script with &#039;&lt;code&gt;while(1);&lt;/code&gt;&#039; Since this is an infinite loop, if causes browsers to hang, and maybe give an error message. Either way the script does not get executed.
&lt;br/&gt;
There is a potential vulnerability that some browser may allow you to override the action of while using something like this: &#039;&lt;code&gt;function while() {}&lt;/code&gt;&#039;. However I don&#039;t know of any such browser.
&lt;br/&gt;
Google use this method to protect data in GMail. &#039;&lt;code&gt;while(1);&lt;/code&gt;&#039; is possibly better than &#039;&lt;code&gt;while(true);&lt;/code&gt;&#039; in case there are any browsers that allow you to redefine truth.&lt;/li&gt;

&lt;li&gt;Prefix the script with &#039;&lt;code&gt;throw new Error(&#034;message&#034;);&lt;/code&gt;&#039;. This is a neat solution in that it allows you to explain what is wrong to users that get the message by mistake. DWR uses this method.
&lt;br/&gt;
It is potentially vulnerable to some browser allowing an attacker to redefine the Error or String constructors to prevent the throw from happening, however this does not work on any browser that I know of, and it&#039;s hard to see how it could happen.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;3. Force POST Requests&lt;/h2&gt;

&lt;p&gt;Since browsers use GET to process &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags, you can prevent &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags from working by denying GET requests for some JavaScript resource. This is the most common solution, however it is also perhaps the weakest.&lt;/p&gt;

&lt;p&gt;Firstly XHR-POST doesn&#039;t work with older versions of Safari, so some support for GET is often useful.&lt;/p&gt;

&lt;p&gt;More importantly future versions of Firefox are touted to include cross-domain XHR support. While we don&#039;t have exact knowledge of how this will happen, it would be foolish to base your security plans on this technique holding up.&lt;/p&gt;

&lt;p&gt;Finally, we&#039;re working in an environment where new possibilities are popping up every day - betting your security on a system that works more by fluke than design isn&#039;t a great idea in my opinion.&lt;/p&gt;

&lt;p&gt;By default DWR denies POST requests for belt and braces security, however this is customizable to allow support for older versions of Safari.&lt;/p&gt;

        </description>
      
      
    
    
    
    <comments>http://directwebremoting.org/blog/joe/2007/04/04/how_to_protect_a_json_or_javascript_service.html#comments</comments>
    <guid isPermaLink="true">http://directwebremoting.org/blog/joe/2007/04/04/how_to_protect_a_json_or_javascript_service.html</guid>
    <pubDate>Wed, 04 Apr 2007 08:32:14 GMT</pubDate>
  </item>
  
  <item>
    <title>JSON is not as safe as people think it is</title>
    <link>http://directwebremoting.org/blog/joe/2007/03/05/json_is_not_as_safe_as_people_think_it_is.html</link>
    
      
        <description>
          &lt;p&gt;I saw some &lt;a href=&#034;http://robubu.com/?p=24&#034;&gt;discussion recently&lt;/a&gt; about using JSON for secured data, and I&#039;m not sure that everyone understands the risks.&lt;/p&gt;

&lt;p&gt;I believe that JSON is unsafe for anything but public data unless you are using unpredictable URLs.&lt;/p&gt;

&lt;p&gt;There are 2 problems. CSRF (Cross Site Request Fogery) allows attackers to bypass cookie based authentication. &lt;a href=&#034;http://getahead.org/blog/joe/2007/01/01/csrf_attacks_or_how_to_avoid_exposing_your_gmail_contacts.html&#034;&gt;I blogged about it&lt;/a&gt; a while ago. &lt;a href=&#034;http://en.wikipedia.org/wiki/Cross-site_request_forgery&#034;&gt;Wikipedia&lt;/a&gt; talks about it. CSRF allows you to invoke cookie protected actions on a remote server. It allows Mr. Evil to trick Mrs. Innocent into transferring money from her bank account into his.&lt;/p&gt;

&lt;p&gt;Far less known perhaps, is the JSON/Array hack that allows a user to steal JSON data on Mozilla and any other platform with a modern JavaScript interpreter.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Update:&lt;/b&gt; It&#039;s not just Arrays - it you can &lt;a href=&#039;http://getahead.org/blog/joe/2007/03/06/json_is_not_as_safe_as_people_think_it_is_part_2.html&#039;&gt;steal data from objects&lt;/a&gt; too.&lt;/p&gt;

&lt;p&gt;There are many ways to fetch data from a server, but the interesting cases here are: XHR, iframe and script-tags. Without knowledge of the JSON/Array hack it&#039;s easy to reason like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;XHR: Browser cross-domain rules prevent the attacker from making the request in the first place.&lt;/li&gt;

&lt;li&gt;iframe: The attacker can embed an iframe that points at some remote server (the bank in the above example) and ask to be sent some JSON, but browser cross-domain rules prevent scripts from the attackers domain from reading the reply, so the JSON is safe because it will never be &lt;code&gt;eval()ed&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;Script-Tags: The attacker can embed a script tag pointing at a remote server and the browser will effectively &lt;code&gt;eval()&lt;/code&gt; the reply for you, however it throws away the response and since JSON is all response, you&#039;re safe.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It&#039;s the last of these arguments that is suspect. The dynamic nature of JavaScript will let you redefine how the browser evaluates the JSON.&lt;/p&gt;

&lt;p&gt;Here&#039;s how it works, and you can follow along with any JavaScript console: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Redefine the Array constructor:&lt;br /&gt;
&lt;pre&gt;function Array() { alert(&amp;quot;hi&amp;quot;); }&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Verify that this constructor is called when arrays are created:&lt;br /&gt;
&lt;pre&gt;var a = [ 43 ];&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Use the new feature to manipulate the array:&lt;br /&gt;
&lt;pre&gt;
function Array() {
  this[1] = 50;
}
var a = [40];
alert(a[0] + a[1]); // Gives 90
&lt;/pre&gt;
&lt;/ol&gt;

&lt;p&gt;So we can call secure JSON data using CSRF with a script tag to by-pass the cookie authentication, and then use the JSON/Array hack to steal the JavaScript data from the browser as it processes the script-tag.&lt;/p&gt;

&lt;p&gt;So we&#039;ve redefined the Array constructor, how do we actually get the data out? The syntax below works in current versions of Firefox, although from my reading of the spec proposals, it&#039;s not a part of &lt;a href=&#039;http://developer.mozilla.org/es4/spec/spec.html&#039;&gt;Javascript 2&lt;/a&gt;, and it appears to fail in IE/Safari/Opera.&lt;/p&gt;

&lt;p&gt;Create a web page at evil.com, with a couple of script tags like this:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;script type=&amp;#39;text/javascript&amp;#39;&amp;gt;
function Array() {
  var obj = this;
  var ind = 0;
  var getNext = function(x) {
    obj[ind++] setter = getNext;
    if (x) alert(Data stolen from array: &#034; + x.toString());
  };
  this[ind++] setter = getNext;
}
&amp;lt;/script&amp;gt;
&amp;lt;script type=&amp;#39;text/javascript&amp;#39; src=&amp;#39;http://bank.com/jsonservice&amp;#39;&amp;gt; &amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;!--
&lt;Xscript type=&#034;text/javascript&#034;&gt;
function Array() {
  var obj = this;
  var ind = 0;
  var getNext = function(x) {
    obj[ind++] setter = getNext;
    if (x) alert(&#034;Data stolen from array: &#034; + x.toString());
   };
   this[ind++] setter = getNext;
}
&lt;/Xscript&gt;
--&gt;

&lt;p&gt;As a demo, I&#039;ve redefined the Array constructor in this page, so if you&#039;re on Firefox, you should get an alert dialog from the following script: &lt;button disabled=&#034;disabled&#034; onclick=&#039;var hack = [ 42 ];&#039;&gt;var hack = [ 42 ];&lt;/button&gt;. &lt;strong&gt;Update:&lt;/strong&gt; This was killing Google Analytics, which we added later, so I&#039;ve removed the array hack script from this page.&lt;/p&gt;

&lt;p&gt;(If you&#039;re reading this in a blog aggregator, then the script above should have been stripped out, so it won&#039;t work. You need to try it on &lt;a href=&#034;http://getahead.org/blog/joe/2007/03/05/json_is_not_as_safe_as_people_think_it_is.html&#034;&gt;this page&lt;/a&gt;. If the script has not been stripped, get a new aggregator - your current one has a horrible security flaw.)&lt;/p&gt;

&lt;p&gt;The long and short is that JSON is not safe in any system that uses cookies for authentication.&lt;/p&gt;

&lt;p&gt;With &lt;a href=&#034;http://getahead.org/dwr/&#034;&gt;DWR&lt;/a&gt; we use full JavaScript which is as vulnerable as JSON, however DWR&#039;s CSRF protection automatically uses the doubly-submitted cookie pattern to provide extra safety.&lt;/p&gt;

&lt;p&gt;I&#039;m by no means the first person to think of this; Jeremiah Grossman &lt;a href=&#039;http://jeremiahgrossman.blogspot.com/2006/01/advanced-web-attack-techniques-using.html&#039;&gt;used it to break GMail&lt;/a&gt; over a year ago.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; If you are doing JSON 100% properly, then you will only have objects at the top level. Arrays, Strings, Numbers, etc will all be wrapped. A JSON object will then fail to eval() because the JavaScript interpreter will think it&#039;s looking at a block rather than an object. This goes a long way to protecting against these attacks, however it&#039;s still best to protect your secure data with un-predictable URLs.&lt;/p&gt;

        </description>
      
      
    
    
    
    <comments>http://directwebremoting.org/blog/joe/2007/03/05/json_is_not_as_safe_as_people_think_it_is.html#comments</comments>
    <guid isPermaLink="true">http://directwebremoting.org/blog/joe/2007/03/05/json_is_not_as_safe_as_people_think_it_is.html</guid>
    <pubDate>Mon, 05 Mar 2007 19:31:52 GMT</pubDate>
  </item>
  
  <item>
    <title>CSRF Pharming</title>
    <link>http://directwebremoting.org/blog/joe/2007/02/08/csrf_pharming.html</link>
    
      
        <description>
          &lt;p&gt;In short: If you still have the default password on your router then go and change it now. Don&#039;t stop to read this post before you change it.&lt;/p&gt;

&lt;p&gt;This post describes an attack that combines &lt;a href=&#034;http://getahead.ltd.uk/blog/joe/2007/01/01/csrf_attacks_or_how_to_avoid_exposing_your_gmail_contacts.html&#034;&gt;CSRF&lt;/a&gt; with an older technique - &lt;a href=&#034;http://en.wikipedia.org/wiki/Pharming&#034;&gt;Pharming&lt;/a&gt; (see particularly the section on &#034;Pharming vulnerability at home&#034;).&lt;/p&gt;

&lt;p&gt;CSRF allows an attacker to script an attack on a foreign website, this could potentially be used against a user&#039;s home router to change DNS settings, and affect a pharming attack by DNS poisoning. Having altered the DNS settings for a victim, they are at heightened risk of man-in-the-middle attacks, phishing and cookie theft.&lt;/p&gt;

&lt;p&gt;CSRF Pharming makes use of the fact that a large number of home routers have the default passwords unchanged. However default passwords are easy to find. There are several lists of default passwords in home routers published on the internet. &lt;a href=&#034;http://www.google.com/search?q=default+passwords&#034;&gt;Google ranks one at phenoelit.de highly&lt;/a&gt;. My guess is that something like 25% of home users have default passwords set on their routers.&lt;/p&gt;

&lt;h2&gt;Exploiting the Flaw&lt;/h2&gt;

&lt;p&gt;The victim of a CSRF Pharming attack visits a web page that has been created or manipulated by an attacker to include some Javascript that uses CSRF to pass the default admin username and password to the default IP address of a number of common home routers. Sometimes the attack is simple enough that Javascript is not required and a single iframe resource is all that is needed.&lt;/p&gt;

&lt;p&gt;Having altered the DNS settings to query an alternative DNS server, the attacker can provide accurate IP addresses for most queries, but fake IP addresses for banking and other important services. The users are then at heightened risk of man-in-the-middle attacks, phishing and cookie theft.&lt;/p&gt;

&lt;p&gt;The attacker can use a number of CSS based techniques to detect routers or it can simply cycle through all known vulnerable routers since each attack is fairly quick.&lt;/p&gt;

&lt;p&gt;There are 2 methods of authentication used in most home routers: http-auth and form/cookie.&lt;/p&gt;

&lt;h3&gt;http-auth&lt;/h3&gt;

&lt;p&gt;Routers using http-auth are vulnerable to attacks from older browsers that allow URLs with the following style: &lt;code&gt;http://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@&amp;lt;address&amp;gt;/&lt;/code&gt; This allows scripted access to http-auth protected resources.&lt;/p&gt;
&lt;p&gt;Routers from the following manufacturers use http-auth: DLink, Modern Netgear and Linksys.&lt;/p&gt;

&lt;p&gt;For some routers a single line of HTML is all that is required:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;iframe src=&amp;quot;http://admin:@192.168.0.1/cgi-bin/prim?attack-params-here&amp;quot;&amp;gt;&amp;lt;/iframe&amp;gt;
&lt;/pre&gt;

&lt;h3&gt;form/cookie&lt;/h3&gt;

&lt;p&gt;Using CSRF it is possible to script a sequence of URLs, although it is not possible to read the responses. Routers using form/cookie authentication are susceptible attacks from almost any web browser with Javascript enabled.&lt;/p&gt;

&lt;p&gt;Routers from the following manufacturers use form/cookie authentication: Belkin, Buffalo, SMC, Asante, Zyxel and reportedly Older Netgear and Linksys routers.&lt;/p&gt;

&lt;h2&gt;Issues for the Attacker&lt;/h2&gt;

&lt;p&gt;An attacker wishing to exploit this problem must discover a URL sequence which affects each model of home router. Frequently sets of routers from a manufacturer will use similar firmware, so often an attack will work across a large number of router models. Knowledge of the attack URL sequences can be easily shared.&lt;/p&gt;

&lt;p&gt;An attacker must also persuade a user to view some attack HTML. There are a number of mechanisms by which this may happen. Spyware vendors have had significant success placing spyware in many websites around the internet. Since this attack does not require the website to host binaries it may also be possible to host the attack-HTML on bulletin boards.&lt;/p&gt;

&lt;h2&gt;Protection&lt;/h2&gt;

&lt;p&gt;The only side effect of the attack is altered DNS settings in the router, so detecting the attack is hard. Detection probably involves making assumptions about the correct IP settings and comparing with those found from a lookup.&lt;/p&gt;

&lt;p&gt;Patching home routers to protect them from CSRF attacks is unlikely to be successful since it is generally too complex a task for many users.&lt;/p&gt;

&lt;p&gt;Altering browsers to not allow URL based http-auth will not protect against all CSRF attacks, and has been done in most common browsers.&lt;/p&gt;

&lt;p&gt;The best current solution is for users is to change the password on their router. Since many users will know less about their routers than their attackers, this is still tricky.&lt;/p&gt;

&lt;p&gt;It may be possible for trusted websites to detect default passwords on vulnerable routers by attempting to read a protected resource like an image, using Javascript and CSS to read image attributes like &#039;clientWidth&#039;, and then using the reported values to infer if the image read was successful. A trusted website could then re-direct the user to a page with instructions on how to change the router password. This technique, whist technically possible does come with some legal challenges - could this be classed as &#039;hacking&#039;?&lt;/p&gt;

&lt;p&gt;Website owners can provide &lt;em&gt;some&lt;/em&gt; extra protection by using HTTPS. An attacker may be able to redirect web traffic using this attack, however they are theoretically not able to provide SSL certificates to match the spoofed URL. This protection does rely on user&#039;s ability to recognize correct HTTPS connections. This would be a shaky reliance.&lt;/p&gt;

&lt;p&gt;The credit for applying these techniques to pharming should really go to &lt;a href=&#034;http://getahead.ltd.uk/mark&#034;&gt;Mark Goodwin&lt;/a&gt; who had the original idea, although Jeremiah Grossman wrote about &lt;a href=&#034;http://www.whitehatsec.com/home/resources/presentations/files/javascript_malware.pdf&#034;&gt;using CSRF against network devices first&lt;/a&gt;; he comes very close to it in this paper without actually mentioning it specifically.&lt;/p&gt;

        </description>
      
      
    
    
    
    <comments>http://directwebremoting.org/blog/joe/2007/02/08/csrf_pharming.html#comments</comments>
    <guid isPermaLink="true">http://directwebremoting.org/blog/joe/2007/02/08/csrf_pharming.html</guid>
    <pubDate>Thu, 08 Feb 2007 09:14:56 GMT</pubDate>
  </item>
  
  </channel>
</rss>
