The Markdown parser in Rocket.Chat Desktop fails to properly escape link attributes, allowing an attacker to inject JavaScript event handlers. This can lead to remote code execution by abusing the Electron shell.openExternal function to open local files or network shares.
From this point the goal is to get the application to call shell.openExternal(href); with a URL we control. Thats because:
"open 'file://localhost/Volumes/Macintosh HD/foo.txt'" opens the document
in the default application for its type (as determined by LaunchSer-
vices).
Note: For this demo I point to file:///Applications/Calculator.app however if you point to a public NFS or SMB server on windows this executable can be controlled by the attacker. (example at: file:///net/192.241.239.91/var/nfs/general/hack2.app)
Normally preload javascript is an "isolated scope" in this case however the code is directly attached to the user controlled DOM as the "window.onload" handler. This means we can overload some global objects and methods including the RegExp.prototype.test method. Now we can bypass the file:\/\/ check send our application path to openExternal.
The markdown parser needs a little love to prevent the initial xss.
I believe you should be able to use something like window.addEventListener("load", .. to execute the checks in the proper scope.
The original report as published on HackerOne, by mattaustin. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
An attacker could get the app to open a local application or an attacker-controlled executable on a network share via shell.openExternal.
What the attacker needed
Victim uses Rocket.Chat Desktop; attacker can send a message in a channel
The fix
The Markdown parser should be fixed to prevent attribute injection, and the link checks should be moved to a proper scope using window.addEventListener("load", ...).
How it was found
Create a new channel to test in.
Send the malicious markdown snippet.
Move your mouse over the link you just sent.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
The chat app's Markdown parser, which turns text into formatted messages, didn't properly sanitise links. An attacker could craft a special link that, when hovered over, runs malicious code. This code could then trick the desktop app into opening harmful files or programs on the victim's computer.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.