Exploiting S3 bucket misconfiguration to dump users emails
This page has writeup about how misconfigured Amazon S3 bucket was found leaking several users email and other docs in public domain.
While pentesting an android application I came across an S3 bucket URL, which was storing user's documents. First thing came on my mind was to first check if this bucket is misconfigured. If it's misconfigured then I'll get complete access to users documents.
I won't be covering how I found this S3 bucket while pentesting the app because my main focus is on applications designed these days lacks security considerations and developers use insecure methods to store data.
Checking If bucket is misconfigured
I'll be using AWS cli because it provides better control over the commands while enumerating buckets and other AWS infra rather than depending on the tools.
Installing AWS cli
Verify Installation
Checking if bucket is accessible anonymously
To interact with bucket we first need bucket name which can be found from URL, which is usually in format
check if bucket is accessible publicly using aws cli
Bucket is publicly accessible!!
We can enumerate each by going through each and every directory, but in this writeup my focus will be on dumping only users email ids which is due to insecure applicaiton design.
We can also check if bucket is publicly accessible by simply visiting homepage of bucket but sometimes buckets are misconfigured with access to users with any AWS account so by using AWS cli we can make requests using our AWS account.
Enumerating Through Directories and Dumping File names
User can enumerate through each and every directory for juicy information, but since from android app pentest I know where I can find user's information. All user uploaded docs are stored in uploads/essay_submission/essay
directory of s3 bucket.
Now I'll be listing all the files inside uploads/essay_submission/essay and storing its output inside a text file.
Note /
in the end of essay, if you want to access contents of directory on bucket, its important to use forward slash /
at the end.
Let's tail data to understand how files are stored to analyze file names.
The design flaw exists in how are documents/images stored in bucket. All files name are in base64 encoded format allowing attacker to extract email ids from the file names which can be concluded after analyzing the output.
Extracting User Info from Dumped Data
Using awk and sed command line tools to extract only base64 encoded data
awk
is used to only print file names and sed
allows us to get rid of .jpeg
extension
Now let's extract all base64 encoded data and store it in another file base64data.txt
Decoding base64 Data Line by Line
I won't be using base64 command line utility to decode base64 data because I prefer python for doing such tasks and I can use that script again in future.
Running script decode_data.py
Some data will be printed on screen after script has been executed successfully
Now, we have all user emails those who have uploaded their docs.
How to mitigate issue and develop better applications
User data exposed to public due to misconfigured security bucket. Buckets shouldn't be publicly accessible. Use presigned URLs for limited amount of time for accessing bucket object.
It's not secure to use user's details, uniquely indentifiable id for storing user's data instead developers should use uuids or salted hashes to generate names for assets/objects.
Last updated