Mozilla maintenance service arbitrary file overwrite allowing privilege escalation
Originally disclosed on Mozilla
- Fixed in 4 months
- Paid in 30 days
- Disclosed after 4 months
Created attachment 8704556
Exploit source code
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
Build ID: 20151223140742
Steps to reproduce:
A combination of vulnerabilities in updater.cpp allows to overwrite arbitrary files, including protected files in protected folders (such as c:\windows), allowing privilege escalation (for example, by overwriting one of the many executables that are scheduled to run periodically with SYSTEM privileges).
The main vulnerability is that files extracted by ArchiveReader are not locked for writing and can be overwritten while the update is running.
Since a software-update command can be run in any location by unprivileged users, an attacker can choose to run it from a controlled location and overwrite files extracted by updater.exe. By overwriting files as they are being extracted, the attacker can force updater.exe to overwrite any file. I explain the procedure below (after "Steps to reproduce").
The updater will only accept to overwrite files that are in the update location and its subfolders (the updater rejects any path that is not relative, or that contains ".."). But it doesn't check if the path contains junctions, allowing to circumvent this protection. Unlike symlinks, junctions can be created by unprivileged users.
Using a combination of both these vulnerabilities allow to overwrite any file in any protected location.
This is all theoretical, so I wrote an exploit in order to prove the seriousness of this vulnerability. This has been tested successfully on Windows 7 and Windows 10 (both 64 bits) with Firefox 43.0.2 and 43.0.3 (32 bits).
Steps to reproduce:
* Download the FirefoxExploit.zip project and unzip it.
* If necessary, modify any of the configuration parameters in main.cpp (junctionName, fileToOverwrite, and defaultMarPatchFileToOverwrite). In the next steps I'll assume you're using the default values.
* Compile the project (I used VS2013, any recent version should be alright). You get FirefoxExploit.exe.
* From a privileged account, create a file in c:\windows named exploitpoc.txt and put some text in it (e.g. "Original content"). This is the file that will be overwritten as a proof of concept.
* Download the latest mar file (firefox-43.0.2-43.0.3.partial.mar: http://releases.mozilla.org/pub/firefox/releases/43.0.3/update/win32/en-US/firefox-43.0.2-43.0.3.partial.mar , replace en-US by the correct language).
* Optionally, create a limited user account on the computer you are going to run the exploit on (this is to prove the privilege escalation) and log in with it.
* Place FirefoxExploit.exe and the mar file in a directory. I'll assume it's c:\firefox_pe in the next steps.
* Create a file named exploitpocnew.txt in c:\firefox_pe. Put any content in it (e.g. "Exploit successful"); it will replace c:\windows\exploitpoc.txt after the exploit is successful.
* Open a cmd shell. Go to c:\firefox_pe.
* Create a junction named "exploit" which points to c:\windows : mklink /J exploit c:\windows
* Execute the exploit: FirefoxExploit.exe exploitpocnew.txt
* Open c:\windows\exploitpoc.txt . It now contains "Exploit successful".
Below is an explanation of how the exploit works. For complete details, refer to the source code (mainly main.cpp).
The exploit will first prepare some things:
* Detect the Firefox installation directory, copy updater.exe from it into c:\firefox_pe (so that the maintenance service accepts to run the update from this location).
* Open the mar file, make sure the version is correct (downgrade is refused), make sure it contains the files needed.
* Read the updatev3.manifest and the original patch from the mar file, so that it can detect later when updater.exe has decompressed enough data from them.
* Generate (using bsdiff) the rogue patch file that will overwrite the legitimate patch.
Then, it will start the update by launching the maintenance service with the appropriate parameters. As soon as it is launched, it will continually monitor the c:\firefox_pe\updating directory, where updater.exe puts files extracted from the mar archive.
The first step of the exploit is to continually check for the presence of update.manifest (extracted by updater.exe). As soon as it is here, it is continually read until enough data is written to it. It is then overwritten with our rogue manifest, which contains a single PatchFile action with the file we want to overwrite as a destination.
The second step is to continually check for the presence of 0.patch (this is updater.exe extracting the legitimate patch file from the mar). Again, as soon as enough data is written to it, it is overwritten with our rogue patch. At this point, it is still being written to by updater.exe, so it is repeatedly truncated to the size of our rogue patch.
Then, updater.exe will apply our rogue patch to the file we want to overwrite. The exploit is successful; you can check that c:\windows\exploitpoc.txt contains the content of exploitpocnew.txt ("Exploit successful").
I'll be happy to provide any help needed to run the exploit successfully. I strongly advise to run the exploit on a multi-core machine; the race condition is much more likely to succeed if it can run concurrently to updater.exe since it has busy loops.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity access control bug in Application Update. Mozilla made it public on 12 May 2016 as CVE-2016-2826.
About Access control
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.