Remote code execution by hijacking an unclaimed S3 bucket in Rocket.Chat's installation script.
The Rocket.Chat installation script downloaded a file from an unclaimed S3 bucket, allowing anyone who registered that bucket to serve malicious code. An attacker could execute arbitrary code on any user's machine when they ran the script.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 3 days
- Disclosed after 4 days
Hi team,
When I downloaded the latest release of Rocket.Chat to test the fix for my previous report I spotted an install.sh script. Inside that installation script I noticed the following line:
#!/bin/bash
set -x
set -euvo pipefail
IFS=$'\n\t'
ROOTPATH=/var/www/rocket.chat
PM2FILE=pm2.json
if [ "$1" == "development" ]; then
ROOTPATH=/var/www/rocket.chat.dev
PM2FILE=pm2.dev.json
fi
cd $ROOTPATH
+ curl -fSL "https://s3.amazonaws.com/rocketchatbuild/rocket.chat-develop.tgz" -o rocket.chat.tgz
tar zxf rocket.chat.tgz && rm rocket.chat.tgz
cd $ROOTPATH/bundle/programs/server
npm install
pm2 startOrRestart $ROOTPATH/current/$PM2FILE
So I decided to see if I could access the contents of that S3 bucket. To my surprise, I got the following error message:
$ aws s3 ls s3://rocketchatbuild
An error occurred (NoSuchBucket) when calling the ListObjects operation: The specified bucket does not exist
That is when I realised that you were requesting a file from an unclaimed S3 bucket. I created a bucket with that name and I am currently serving my own rocket.chat-develop.tgz file that your script now fetches. The script then executes my code on any user's machine. Please note that I do not want to cause any harm to Rocket.Chat users so all I did was upload a text file with my username in it and will happily remove the file as soon as you have seen this report.
~ λ curl -fSL "https://s3.amazonaws.com/rocketchatbuild/rocket.chat-develop.tgz" -o rocket.chat.tgz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 100 179 100 179 0 0 250 0 --:--:-- --:--:-- --:--:-- 250
~ λ tar -xvzf rocket.chat.tgz
frogs-find-bugs/
frogs-find-bugs/hehehe
~ λ cat frogs-find-bugs/hehehe
EdOverflow :D
Please let me know how you would like to proceed with this report and I will try my best to help you out wherever I can.
- Ed
Impact
An adversary or, at the very least, I can execute arbitrary code whenever someone runs install.sh.
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 installation script downloaded and executed a file from an S3 bucket that was not registered, allowing anyone to claim it and serve arbitrary content.
Impact
An attacker could execute arbitrary code on any user's machine when they run the installation script.
What the attacker needed
Victim runs install.sh
How it was found
- Download the latest Rocket.Chat release and inspect the install.sh script.
- Notice the script downloads a file from an S3 bucket.
- Check if the S3 bucket exists and find it does not.
- Create a bucket with that name and upload a file.
- Fetch the file via curl to confirm it returns the attacker's content.
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.
An installation script is a set of commands that sets up software. This script fetched a file from a cloud storage location (an S3 bucket) that nobody owned. The researcher claimed that bucket and put their own file there, so anyone running the script would download and run the researcher's code instead of the real software.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.