How to delete all company progress by one “rm” command in AWS s3 Buckets
An AWS S3 bucket allowed public listing and, despite write access being denied, permitted file copy, move and delete operations. An attacker could delete or move files, potentially destroying company data.
Published on medium.com
{{media:0}}
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This is a story about an AWS S3 bucket used by a company that makes a native application for electric skateboards. The bucket held application updates, including versions of unstable updates, together with developer comments warning that a given update could be dangerous. The bucket was also used for ordinary static content such as logos, pictures and text.
The author, Valeriy Shevchenko (@Krevetk0Valeriy), had read a write-up by Sriram titled "How i pwned a million dollar company" and wanted to test the ideas in practice. He had already tried them on an office project, where access levels were set up correctly and nothing interesting turned up. The target here was a different project, found while researching applications written by various electric skate companies.

Setup
The work was done from the command line, using the cp, mv and rm commands against S3 paths. No accounts, roles or credentials are described in the report.
One practical precondition mattered: S3 buckets live in different regions, and to refer to a particular bucket you need both the exact bucket name and the region prefix. The author solved this by guessing the region, working from the list of regions published at:
http://docs.aws.amazon.com/general/latest/gr/rande.html
He recovered the bucket name he was interested in from his old logs, then went from there.
Finding it
The bucket was available for listing, so anyone could walk through the directories and see the contents. On its own, listing is not necessarily dangerous when a bucket holds static data for an application or web page. What made it look wrong here was the content: versions of unstable updates for a high-speed vehicle, published publicly, with developer comments stating that an update could be dangerous.

Exploitation
Step 1: Confirm listing and read the contents
With the bucket name from the old logs and a guessed region, the author could list the bucket and browse its directories. This confirmed that the contents, including the update files and their developer comments, were publicly readable.
Step 2: Try to write
He tried to write a new test file into the project directory with the cp command. The response was a 403 Forbidden:
Access denied.
So writing new objects was blocked.
Step 3: Copy a file between directories
He then tried to move a file between directories. He did this with the cp command, and notes that mv also worked. The test subject was a regular file, Readme.txt, that he had found in one of the folders.
After the copy there were two Readme.txt files in different folders. At that point it was already possible to create chaos and confusion by moving and copying files, even though creating a brand new object had been refused.
Step 4: Delete a file
Finally he tried the remove command, rm:
It worked. Readme.txt was deleted.

Root cause
The report does not describe the bucket policy or ACL that produced this behaviour, so the exact configuration is not stated. What the behaviour shows is that the permission check treated a copy or move of an existing object differently from the creation of a new one: a fresh write was refused with 403, while copying an existing object to another prefix and deleting an object both succeeded. The report does not explain why copying and deleting succeeded while a new write was refused.
Impact
Anyone who knew or guessed the bucket name and region could list the contents, copy files around inside the bucket and delete files. In this case that meant a third party could instantly take and destroy the company's work with a few commands.

Fix
Variants to test
- On a bucket that returns
403for a new object, try copying an existing object to another prefix withcpand withmv. A positive result is a second copy of the file appearing under the new prefix. - Try
rmon a harmless existing object. A positive result is the object disappearing from the listing. - Try the same operations against a bucket whose name you recovered from logs or application traffic, iterating over region prefixes from the published region list until listing succeeds.
- Look at what the listing exposes: update files, developer comments and internal notes. A positive result is content that reveals unreleased or unstable builds and warnings about them.
Clap your hands if you like this story :)
What happened, in plain words
A company that makes an app for electric skateboards kept its files in an online storage service called Amazon S3. Think of S3 as a very large shared filing cabinet in the cloud: each company rents a drawer, called a bucket, and puts files (called objects) inside folders. The company's bucket held the app's updates, including early test versions of updates, plus ordinary things like logos, pictures and text.
The bucket was set up so that anyone on the internet could open it and look through the folders. That alone is not always a disaster: many companies deliberately leave pictures and logos public so their website can show them. But here the public could also see unstable update files, and those files carried comments from the developers warning that a particular update might be dangerous.
The author, Valeriy Shevchenko (@Krevetk0Valeriy), had read another person's story about a similar problem and wanted to try the same ideas himself. He had already tested them on a project at his office, where the permissions were set correctly and nothing interesting happened. This time he looked at a different project, one he found while researching apps made by various electric skateboard companies.
What he found was worse than just being able to look. He could not create a brand new file, but he could copy an existing file into another folder, and he could delete a file. In other words, a stranger could rearrange and destroy the company's work with a few typed commands.

The tools and the setup
The work was done from a command line: a text window where you type instructions instead of clicking buttons. The commands used were cp (copy), mv (move) and rm (remove). It offers commands such as cp (copy), mv (move) and rm (remove), which work on S3 paths much like they work on files on your own computer.
One practical detail mattered. S3 buckets are stored in different regions, which are physical parts of the world where Amazon runs its data centres. To reach a particular bucket you need both its exact name and the region it lives in. The author did not know the region, so he simply guessed, working through the published list of regions:
http://docs.aws.amazon.com/general/latest/gr/rande.html
This is a web address for Amazon's own documentation page that lists every region. The author took the region names from it and guessed the region for reading the contents. He had recovered the bucket name he was interested in from his old logs, records of earlier activity he had kept, and started from there.
Finding the bucket
The bucket allowed listing: anyone could walk through its folders and see what was inside, the way you can browse a public folder on a website. On its own, listing is not necessarily dangerous when a bucket only holds static content, meaning files that never change, such as logos, pictures and text for an app or a web page.
What made it look wrong here was the content itself. The bucket held versions of unstable updates for a high-speed vehicle, published where anyone could read them, and the developer comments said plainly that an update could be dangerous. Publishing unfinished software and warnings about it is not something you would expect a company to do openly.

Trying things out, step by step
Step 1: Confirm you can look inside
With the bucket name from his old logs and a guessed region, the author could list the bucket and browse its folders. This confirmed that the update files and their developer comments were readable by anyone.
Step 2: Try to add a new file
He tried to write a new test file into the project folder with the cp command. The service answered with a 403 Forbidden:
Access denied.
A 403 Forbidden is the standard web response for "I understood your request, but you are not allowed to do this". So creating a brand new file was blocked. At this point everything looked normal.
Step 3: Copy a file between folders
He then tried to move a file from one folder to another. He did this with the cp command, and notes that mv also worked. The test subject was an ordinary file, Readme.txt, that he had found in one of the folders.
This is the copy command on its own, as the report shows it. In normal use you would give it a source and a destination, for example a file in one folder and a path in another, and it would place a copy of the file at the destination. The point of the step was to see whether the service would treat copying an existing file differently from creating a new one.
After the copy there were two Readme.txt files in different folders. That already meant someone could create chaos and confusion by moving and copying files around, even though creating a brand new file had been refused. The protection was inconsistent: the front door was locked, but a side door was open.
Step 4: Delete a file
Finally he tried the remove command, rm:
This is the delete command, again shown on its own as in the report. In normal use you point it at a file and the file is removed. The step was taken to see whether deletion was protected in the same way that creating a new file was.
It worked. Readme.txt was deleted.

Why this was possible
The report does not describe the bucket policy or the access control list (the rules that say who may do what) that produced this behaviour, so the exact configuration is not stated. What the behaviour shows is that the permission check treated a copy or a move of an existing file differently from the creation of a new one. A fresh write was refused with 403, while copying an existing file to another folder and deleting a file both succeeded.
The report does not explain why copying and deleting succeeded while a new file was refused. Either way, the read-only intention of the bucket was not enforced for cp, mv and rm.
What the impact was
Anyone who knew or guessed the bucket name and its region could list the contents, copy files around inside the bucket and delete files. In this case that meant a third party could instantly take and destroy the company's work with a few commands. The author notes that it took a lot of effort to find someone who would take note of the information, and that there was no question of a reward.

What a fix would look like
Things worth testing on other buckets
- On a bucket that returns
403for a new file, try copying an existing file to another folder withcpand withmv. A positive result is a second copy of the file appearing under the new folder. - Try
rmon a harmless existing file. A positive result is the file disappearing from the listing. - Try the same operations against a bucket whose name you recovered from logs or application traffic, trying region prefixes from the published region list until listing succeeds.
- Look at what the listing exposes: update files, developer comments and internal notes. A positive result is content that reveals unreleased or unstable builds and warnings about them.
Clap your hands if you like this story :)
Glossary
- AWS (Amazon Web Services): Amazon's collection of cloud services, including storage, computing and databases, rented over the internet.
- S3 (Simple Storage Service): Amazon's file storage service in the cloud, organised into buckets and objects.
- Bucket: a container in S3, like a top-level folder, that holds files and subfolders.
- Object: a single file stored in an S3 bucket.
- Region: a physical location where Amazon runs data centres; each bucket lives in one region, and you need the region to reach it.
- AWS CLI: Amazon's command line program for controlling AWS services by typing commands.
- Command line: a text window where you type instructions instead of clicking buttons.
cp: the copy command; it duplicates a file, here from one S3 folder to another.mv: the move command; it relocates a file, here between S3 folders.rm: the remove command; it deletes a file.- Listing: the ability to browse the folders of a bucket and see what files it contains.
- Static content: files that do not change, such as logos, pictures and text used by an app or web page.
- 403 Forbidden: the standard web response meaning the server understood the request but refuses to allow it.
- Bucket policy: the set of rules attached to a bucket that says who may read, write, copy or delete what.
- Access control list (ACL): a list attached to a resource that names who is allowed to do what with it.
- Permission check: the step where the service decides whether the person making a request is allowed to do it.
- Anonymous user: someone making requests without logging in or proving who they are.
- Principal: the identity, such as a user or account, that a permission rule applies to.
- Prefix: the folder-like part of a path inside a bucket, used to group files.
- Root cause: the underlying reason a problem exists, as opposed to its visible symptoms.
- Impact: the harm that results from a problem, such as data being read, changed or destroyed.
- Vulnerability: a weakness in how something is set up or built that lets someone do what they should not be able to do.
- Misconfiguration: a setting that was left in a state that is unsafe, usually by mistake.