Arbitrary file "deletion" as SYSTEM with maintenance service
The Mozilla maintenance service, which runs with SYSTEM privileges, can be tricked by a standard user into overwriting arbitrary files with junk data. This effectively deletes the target file, for example locking Firefox to its current version by corrupting its updater executable.
Originally disclosed on Mozilla
- Fixed in 3 months
- Paid in 3 months
- Disclosed after 3 months
Created attachment 8833966
proof-of-concept
An unprivileged (standard) user can use the maintenance service to overwrite arbitrary files with junk data. There is no control over what is written to the target file, though the absence of the original data effectively "deletes" it.
For example, running the poc with clobber_file.rb "C:\Program Files (x86)\Mozilla Firefox\updater.exe" will lock firefox to the current installed version until an administrator repairs the installation because the existing updater.exe cannot be loaded to be verified.
The root cause seems to be that if GetTempFileNameW in WriteStatusFailure [0] is called with a path like '\\.\c:\foo\clobbered', instead of returning a temporary file like '\\.\c:\foo\clobbered\svc123.tmp', it just returns the input path. WriteStatusFailure then directly writes to the temporary path [1], truncating it's contents with the results of the updater.
WriteStatusFailure can be called with a user-supplied directory in a few places, the easiest way is to put the target in the first argument and not supply enough further arguments to cause GetInstallationDir in ExecuteServiceCommand to fail [2]. This is how the attached clobber_file.rb proof of concept works.
I haven't tested, but I think the calls in UpdaterIsValid would also be able to be purposely failed with an attacker controlled directory for update.status to get written into. Possibly some of the calls after that point as well, but it gets more difficult once the updater directory is verified as legitimate.
I also tested using hardlinks to redirect the update.status file while using a normal file path to trigger the overwrite - this does not seem to be possible as the maintenance service re-creates the file (which deletes the hardlink, rather than the file that is points to).
Tested on Windows 8.1 x64, Firefox 51.0.1 as well as mozilla-central.
[0] - https://dxr.mozilla.org/mozilla-central/rev/1d025ac534a6333a8170a59a95a8a3673d4028ee/toolkit/mozapps/update/common/updatehelper.cpp#276
[1] - https://dxr.mozilla.org/mozilla-central/rev/1d025ac534a6333a8170a59a95a8a3673d4028ee/toolkit/mozapps/update/common/updatehelper.cpp#288
[2] - https://dxr.mozilla.org/mozilla-central/rev/1d025ac534a6333a8170a59a95a8a3673d4028ee/toolkit/components/maintenanceservice/workmonitor.cpp#601
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 Windows API GetTempFileNameW returns the input path unchanged when given a device-style path, so WriteStatusFailure writes directly to an attacker-chosen file instead of a temporary file.
Impact
An unprivileged user could corrupt arbitrary files, for example locking Firefox to the installed version until an administrator repairs it; the report notes that hardlink redirection did not work because the service re-creates the file.
What the attacker needed
Local standard user account on Windows; Mozilla maintenance service installed
How it was found
- Run the proof-of-concept script with the target file path as the first argument.
- The script supplies too few further arguments so that GetInstallationDir in ExecuteServiceCommand fails.
- This causes WriteStatusFailure to be called with the attacker-supplied directory.
- WriteStatusFailure writes updater results directly to the target path, truncating its contents.
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.
A background helper program that runs with high privileges can be told by a normal user to write junk into any file on the computer. Because the original contents are destroyed, the file is effectively deleted, which can break or freeze installed software.
What is File upload?
An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.