The pingsender executable dynamically loads libcurl, using dlopen and hardcoded library list. [Mac/Linux]
The pingsender helper binary loads libcurl by bare library name via dlopen, so the dynamic loader searches user-writable locations such as the home lib directory before system paths. An attacker who can place a malicious library there gets code execution each time telemetry is sent.
Originally disclosed on Mozilla
- Fixed in 6 days
- Paid in 20 days
- Disclosed after 6 days
Created attachment 8909974
poc.c
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
Steps to reproduce:
Introduction:
The pingsender executable dynamically loads libcurl, using dlopen and hardcoded library list.
According to the manpages, the order of execution for dlopen will be:
When path does not contain a slash character (i.e. it is just a leaf name), dlopen() searches the following until it finds a compatible Mach-O file:
$LD_LIBRARY_PATH, $DYLD_LIBRARY_PATH, current working directory, $DYLD_FALLBACK_LIBRARY_PATH.
Further:
Note: If DYLD_FALLBACK_LIBRARY_PATH is not set, dlopen operates as if DYLD_FALLBACK_LIBRARY_PATH was set to $HOME/lib:/usr/local/lib:/usr/lib.
The vulnerable file is located on: https://dxr.mozilla.org/mozilla-central/source/toolkit/components/telemetry/pingsender/pingsender_unix_common.cpp
The offending dlopen code dlopen is in line 105
mLib = dlopen(libname, RTLD_NOW);
And in line 84 through 101:
const char* libcurlNames[] = {
"libcurl.so",
"libcurl.so.4",
// Debian gives libcurl a different name when it is built against GnuTLS
"libcurl-gnutls.so.4",
// Older libcurl if we can't find anything better
"libcurl.so.3",
#ifndef HAVE_64BIT_BUILD
// 32-bit versions on 64-bit hosts
"/usr/lib32/libcurl.so",
"/usr/lib32/libcurl.so.4",
"/usr/lib32/libcurl-gnutls.so.4",
"/usr/lib32/libcurl.so.3",
#endif
// macOS
"libcurl.dylib",
"libcurl.4.dylib",
"libcurl.3.dylib"
};
By writing a malicious dylib, in ~/lib, an attacker can attain local execution privileges.
Further - on every subsequent telemetry request, the code will be executed.
Instruction to reproduce:
Save the C file and compile to generate a dyilib:
gcc -c poc.c
gcc -dynamiclib -current_version 1.0 poc.o -o libcurl.dylib
Ensure that Enable Firefox Health Report is enabled On Firefox -> Preferences -> Advanced -> Data Choices
Open and close Firefox.
This is a bad security practice, you can read more about it (although on a Windows world) on:
http://blog.opensecurityresearch.com/2014/01/unsafe-dll-loading-vulnerabilities.html
Actual results:
Code was executed (Calculator was opened)
Expected results:
A list with the known paths should had been provided.
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 code passes a bare library name to dlopen instead of an absolute path, so the loader's search order includes user-controlled directories.
Impact
An attacker with the ability to write to a searched directory could run arbitrary code locally, and it would run again on every subsequent telemetry request.
What the attacker needed
Ability to write to a searched directory; Health Report telemetry enabled; Firefox opened or closed to trigger pingsender
The fix
The code should load the library from a known absolute path rather than relying on the loader's search order.
How it was found
- Compile the proof-of-concept source into a dynamic library named like libcurl.
- Make sure the Firefox Health Report data choice is enabled.
- Open and close Firefox so pingsender runs.
- Observe that the attacker's code executes.
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.
When a program needs a shared library, it can ask the operating system to find it by name. If only a short name is given, the system looks in several folders, including some the user can write to. An attacker who drops a fake library with the right name into one of those folders gets their code run by the program.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.