Mozilla Maintenance Service buffer overflow allowing privilege escalation
Originally disclosed on Mozilla
- Fixed in 36 hours
- Paid in 5 days
- Disclosed after 36 hours
Created attachment 721765
Proof of Concept source code and executable
The Mozilla Maintenance Service is vulnerable to a stack-based buffer overflow, allowing an unprivileged user to escalate privileges to NT_AUTHORITY\SYSTEM.
The bug lies in workmonitor.cpp, in the ProcessSoftwareUpdateCommand function, at lines 307-308, where a fixed size array is passed to GetInstallationDir:
WCHAR installDir[MAX_PATH] = {L'\0'};
if (!GetInstallationDir(argc, argv, installDir)) {
GetInstallationDir, in turn, performs an unchecked copy of argv[2] into the destination buffer (here, installDir):
static BOOL
GetInstallationDir(int argcTmp, LPWSTR *argvTmp, WCHAR aResultDir[MAX_PATH])
{
if (argcTmp < 2) {
return FALSE;
}
wcscpy(aResultDir, argvTmp[2]);
Maintenanceservice.exe wrongly assumes that its arguments have a valid size. However, due to the way the maintenance service is configured, any unprivileged user can start it, with arbitrary arguments: this is why Firefox can use it to upgrade without triggering an UAC prompt.
In the ProcessSoftwareUpdateCommand stack layout, the installDir buffer is located 588 bytes before the security cookie used to protect against stack based buffer overflows. Therefore, an argv[2] greater than 588 bytes will trigger a process termination due to this protection, and an event will be added to the Windows' event log. The attached PoC triggers the bug with a 592 bytes long argv[2].
The event can later be viewed with Windows' event viewer, under the Windows logs > Application category:
Problem signature:
P1: maintenanceservice.exe => exe filename
P2: 19.0.0.4794 => exe version
P3: 511eba22 => exe timestamp
[...]
P7: 0000313b => faulting offset from ImageBase, this is the instruction right after __security_check_cookie in ProcessSoftwareUpdateCommand
P8: c0000409 => Exception type: Stack buffer overflow
Although it may look like the bug is not exploitable due to the stack overflow protection, it is indeed possible to exploit this bug:
-The service can be launched as many times as needed: the attacker gets as many tries as needed.
-The security cookie (stack overflow protection) is predictable (see below).
-ASLR and DEP are useless (see below).
Stack overflow protection:
The stack overflow protection works by generating a 32 bits integer which is called the security cookie. It is supposed to be random, however it is not. It is obtained by XORing the result of GetSystemTimeAsFileTime, GetTickCount, QueryPerformanceCounter, the process ID, and the thread ID:
-An attacker can call the 3 functions just before launching the service, and the results will be nearly identical, as they are all time-based. Even if there is a difference, it'll affect only the lowest bits of the security cookie.
-The process ID is predictable, as is the thread ID. Furthermore, they are low values, never superior to 1,000,000, and as such will affect only the lowest bits of the security cookie.
This makes the real entropy of the security cookie 16 bits, low enough to make an attack practical.
ASLR and DEP:
DEP is defeated with a ROP payload.
ASLR is useless because the base addresses of some DLLs like ntdll and kernel32 are randomized at boot time, and don't change until next reboot. An attacker running can just call GetModuleHandle to get their base addresses, and adapt the payload.
This was tested on Windows 7 64 bits, and it should work on all versions of Windows.
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 8 March 2013 as CVE-2013-0799.
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.