Skip to content
RCE Disclosed report Advanced CVE-2017-7766

Arbitrary code execution as SYSTEM using Updater to overwrite updater.ini

The Firefox Updater can be tricked into executing an arbitrary PostUpdate file via a crafted updater.ini, and a separate bug allows overwriting any file as SYSTEM with partially controlled data. By combining these, an unprivileged user can overwrite updater.ini to install Firefox into an attacker-controlled directory and execute arbitrary code as SYSTEM.

Seb Patane Follow

Originally disclosed on Mozilla

  • Fixed in 2 months
  • Paid in 2 months
  • Disclosed after 2 months

Created attachment 8841306 poc + source.zip

An unprivileged, standard, Windows user can execute arbitrary code as SYSTEM using the Firefox Updater (via the Maintenance Service).

This is possible by combining two bugs. The first is that the Updater can be tricked into executing an arbitrary PostUpdate file by the updater.ini file after a successful action is performed. The second allows overwrite of any file as SYSTEM with partially attacker controlled data.

We use the overwrite bug to write a new updater.ini, which triggers an install of Firefox into an attacker controlled directory which allows arbitrary code execution via the maintenanceservice_installer.exe binary.

Reproduction

I've attached a poc + source, to run it you'll need the full update.mar for the current installed version of Firefox [0] (or higher), as well as a full firefox installer [1]. The poc can be run as follows:

firefox_poc.exe payload.exe firefox-51.0.1.complete.mar "Firefox Setup 51.0.1.exe" C:\Program Files (x86)\Mozilla Firefox

The payload.exe is the file to be executed as SYSTEM. The final argument needs to be a legitimate Firefox installation directory, and will default to C:\Program Files(x86)\Mozilla Firefox if not supplied. One of the bugs relies on a small race condition, which has always executed in less than a minute for me but let me know if you have any problems. It will continue trying until it succeeds or you use ctrl+c to kill it.

The included payload.exe just runs "whoami > /foo.txt", which should create a foo.txt file in your drive root with the contents "nt authority\system".

ExeRelPath in updater.ini allows execution of arbitrary Mozilla binaries using absolute paths

The ExeRelPath entry in the C:\Program Files (x86)\Mozilla Firefox\updater.ini file is executed by the updater after a successful action is made. There are allowances made to prevent directory traversal using '..', however if an absolute file path is provided instead of a filename then PathAppendSafe [2] (which uses PathAppendW) will return the absolute file path instead.

Eg. PathAppendW("C:\Program Files (x86)\Mozilla Firefox", "C:\some\mozilla.exe") => "C:\some\mozilla.exe"

The updater will happily execute this file, as long as it is signed by Mozilla with a current certificate. We can use then use these binaries in ways never intended to gain arbitrary code execution.

The avenue used in this proof of concept is to use the Firefox setup.exe to install Firefox into an attacker controlled directory [3], which then executes whatever is in the maintenanceservice_installer.exe file on post-install (in fairness, this would have no practical chance of being intercepted otherwise). I imagine there are similar avenues in other Mozilla signed binaries, however I have not investigated them.

Arbitrary file overwrite with partial content injection

Soon after the updater starts, updater.cpp [4] calls LogInit, which calls GetTempFileNameW with the attacker-supplied patch directory to get a temp filename for the log file. By providing a file which starts with \., GetTempFileNameW will just copy the input into the output buffer instead of providing a valid temp directory.

Eg. GetTempFileNameW("\.\c:\target\file.txt", L"log", 0, mTmpFilePath) => mTmpFilePath = "\.\c:\target\file.txt"

Since it is essentially a normal file path, the log file will happily truncate and write to this file.

We can insert up to 260 characters at some point in the file using the fact that the working directory argument gets logged in updater.cpp [5]. The resulting file ends up looking something like the following (ABC's are user supplied):

Performing a replace request
PATCH DIRECTORY \\.\C:\target\file.txt
INSTALLATION DIRECTORY C:\Program Files (x86)\Mozilla Firefox
WORKING DIRECTORY AAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCC

The apply-to directory must be the same as or a child of the installation directory! Exiting.

In order to reach the line of code which logs the working directory argument, we need to first avoid a failure of WriteStatusFile [6], otherwise the updater will exit early and we will only truncate the file without our content written. The reason WriteStatusFile fails is that it tries to move a file to <patch-dir>/update.status, which in this case is \.\c:\target\file.txt\update.status, which is not possible because file.txt is a file.

However, if we create a directory junction in an attacker controlled directory, eg. c:\exploit\junction\ pointing to c:\target, then we can supply that to the updater instead. Now after the updater has opened a file descriptor to file.txt, we race it to switch the junction out with a directory named file.txt before it has attempted the status file move. If we win the race, the updater creates c:\exploit\junction\file.txt\update.status and execution continues.

Arbitrary code execution

Because GetPrivateProfileStringW [7] isn't very picky about the formatting of the updater.ini, we can use the arbitrary file overwrite to replace the C:\Program Files (x86)\Mozilla Firefox\updater.ini with one which looks like this:

Performing a replace request
PATCH DIRECTORY \\.\C:\temp\ff-exploit\overwrite-target\updater.ini
INSTALLATION DIRECTORY C:\Program Files (x86)\Mozilla Firefox
WORKING DIRECTORY 

[PostUpdateWin]
ExeRelPath=C:\temp\ff-exploit\setup-dir\ff_setup.exe
ExeArg=/INI=C:\temp\ff-exploit\setup-dir\ff_setup.ini

The apply-to directory must be the same as or a child of the installation directory! Exiting.

The ff_setup.ini has the InstallDirectoryPath entry set to an attacker controlled directory, eg. c:\temp\ff-exploit\new-firefox\ and the MaintenanceService entry set to true. The attacker just needs to copy their payload.exe into c:\temp\ff-exploit-new-firefox\maintenanceservice_installer.exe and keep it locked for shared reads (so it can't be overwritten on install, but can be executed).

Then, we trigger some action which will succeed, like staging an upate.mar file -> which will execute the PostUpdateWin command -> which will install a new copy of firefox into the attacker controlled c:\temp\ff-exploit\new-firefox\ directory -> which will then run the maintenanceservice_install.exe payload as SYSTEM

Let me know if you need any more information. I tested on Windows 8.1 x64, Firefox 51.0.1

[0] - http://archive.mozilla.org/pub/firefox/releases/51.0.1/update/win32/en-US/firefox-51.0.1.complete.mar [1] - http://archive.mozilla.org/pub/firefox/releases/51.0.1/win32/en-US/Firefox%20Setup%2051.0.1.exe

[2] - https://dxr.mozilla.org/mozilla-central/rev/f36062d04d165f6f6e781cf0633ffcbbebe6c273/toolkit/mozapps/update/updater/updater.cpp#2029 [3] - https://wiki.mozilla.org/Installer:Command_Line_Arguments

[4] - https://dxr.mozilla.org/mozilla-central/rev/f36062d04d165f6f6e781cf0633ffcbbebe6c273/toolkit/mozapps/update/updater/updater.cpp#2937 [5] - https://dxr.mozilla.org/mozilla-central/rev/f36062d04d165f6f6e781cf0633ffcbbebe6c273/toolkit/mozapps/update/updater/updater.cpp#2958 [6] - https://dxr.mozilla.org/mozilla-central/rev/f36062d04d165f6f6e781cf0633ffcbbebe6c273/toolkit/mozapps/update/updater/updater.cpp#2939

[7] - https://dxr.mozilla.org/mozilla-central/rev/f36062d04d165f6f6e781cf0633ffcbbebe6c273/toolkit/mozapps/update/updater/updater.cpp#2005

The original report as published on Mozilla's Bugzilla, by Seb Patane. 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 updater trusts the updater.ini file and allows absolute paths in ExeRelPath, and a path handling flaw in GetTempFileNameW allows arbitrary file overwrite with partial content injection.

Impact

An unprivileged user can execute arbitrary code as SYSTEM, but the exploit relies on a race condition that may not always succeed.

What the attacker needed

Windows user account; Ability to create directory junctions; Full update.mar file for installed Firefox; Full Firefox installer

How it was found

  1. Create a directory junction in an attacker-controlled directory pointing to the target directory.
  2. Run the updater with the junction path as the patch directory to trigger the log file write to the target file.
  3. Race to replace the junction with a directory named file.txt before the updater moves the status file.
  4. Use the overwrite to replace updater.ini with a malicious version containing a PostUpdateWin section.
  5. Place a payload as maintenanceservice_installer.exe in the attacker-controlled install directory and lock it.
  6. Trigger a successful update action to execute the PostUpdateWin command, installing Firefox and running the payload as SYSTEM.

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.

The Firefox updater runs with high privileges (SYSTEM) to install updates. The report shows two mistakes: the updater can be made to run any program listed in a configuration file, and it can be tricked into overwriting that configuration file with new content. Together, a normal user can make the updater run their own program with SYSTEM rights.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Seb Patane

View all

10 more disclosed reports, 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.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.