Permissions overwrite via folder symlink TOCTOU by Maintenance Service
A race condition exists in the Windows Mozilla Maintenance Service's fix-update-directory-perms command between checking a directory for symlinks and changing permissions on its contents. An attacker could replace a valid directory with a symlink to a target directory, causing the service to grant Full Control to the Users group on all files in that target, potentially leading to arbitrary code execution as SYSTEM.
Originally disclosed on Mozilla
- Fixed in 3 months
- Paid in 3 months
- Disclosed after 3 months
Created attachment 9065440
proof-of-concept.zip
When running the Windows Mozilla Maintenace Service's fix-update-directory-perms command there is a race condition between the time when a directories attributes are checked for symlinks/junctions [0] to when the permissions on the file contents of the directory are actually changed [1].
By replacing a valid directory after the call to GetFileAttributesW() with a symlink to a target directory before the recursive call into SetPermissionsOfContent() the maintenance service will be tricked into granting Full Control for the Users group to all files/folders in the target directory.
If we use this to overwrite the permissions of the files in C:\Program Files (x86)\Mozilla Maintenance Service\ folder, we can replace the maintenance service itself with a binary we control and achieve arbitrary code execution as the SYSTEM user.
I've attached a proof of concept + binary which takes a folder path to overwrite the contents' permissions. It's pretty unreliable, but I did have success around the 350ms mark while also running a stress testing tool like Prime95 to slow the system down a bit. I tested this on version 68.0.0.7074 of the maintenanceservice.exe.
[0] - https://dxr.mozilla.org/mozilla-central/rev/cb5734727c0a9d88e3e236a3e4a741a051509e0e/toolkit/mozapps/update/common/commonupdatedir.cpp#1040
[1] - https://dxr.mozilla.org/mozilla-central/rev/cb5734727c0a9d88e3e236a3e4a741a051509e0e/toolkit/mozapps/update/common/commonupdatedir.cpp#1071
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 a time-of-check to time-of-use (TOCTOU) race condition: the directory's attributes are checked for symlinks/junctions, but the check and the subsequent permission change are not atomic, allowing a symlink to be substituted in between.
Impact
An attacker could achieve arbitrary code execution as the SYSTEM user, though the exploit is described as unreliable and required stress testing to succeed.
What the attacker needed
Windows system with Mozilla Maintenance Service; Ability to create symlinks/junctions; Timing the race condition
How it was found
- Run the maintenance service's fix-update-directory-perms command.
- Replace a valid directory with a symlink to a target directory after the GetFileAttributesW() check but before SetPermissionsOfContent() is called.
- The service grants Full Control for the Users group to all files/folders in the target directory.
- Use this to overwrite permissions of files in the Mozilla Maintenance Service folder.
- Replace the maintenance service binary with a controlled binary to achieve arbitrary code execution 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 maintenance service checks if a folder is safe, but then later changes permissions on whatever is in that folder. An attacker can quickly swap the folder for a shortcut (symlink) to a sensitive location, so the service ends up giving normal users full control over important files. This can let the attacker replace the service's own program with a malicious one and run code as the highest-privileged system user.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.