Skip to content
Misconfiguration Write-up Beginner

Misconfigured s3 bucket leads to Sensitive Data exposure(No super controls )

An S3 bucket belonging to a subsidiary was misconfigured so that its contents could be listed and read without authentication. The author found an old server code file and a users.htpasswd authentication file, exposing credentials.

Virdoexhunter Follow

Published on virdoexhunter.medium.com

Bounty$400 View original

Amazon S3 (Simple Storage Service) is one of the popular and widely used storage services. Many companies are using S3 buckets to store their assets such as user profile pictures, static resources, and anything as per their business logic and needs.

Virdoexhunter, on virdoexhunter.medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 3 min read.

Context

Amazon S3 (Simple Storage Service) is a widely used object storage service. Companies use S3 buckets to hold assets such as user profile pictures, static resources and other files that fit their business logic. When a bucket is misconfigured or left unclaimed, an attacker may be able to carry out actions such as S3 bucket takeover or S3 content takeover.

This write-up covers a misconfigured S3 bucket that exposed old server code together with an authentication file, users.htpasswd. The application under test had a medium scope, and the finding belonged to one of the program's subsidiaries, referred to here as target.com. The program is identified as RDP, and the bounty was 400 USD.

Setup

The work started from subdomain enumeration. The researcher resolved unique subdomains with the following command:

Bash
Subfinder -d target.com | httpx | tee -a alive.txt

subfinder enumerates subdomains for the domain, httpx probes which of them are alive, and tee -a alive.txt writes the results to a file while also showing them. The output was the set of alive subdomains, each of which was then opened in a browser.

Finding it

Opening an alive host, called site.com in the write-up, and appending /%C0 to the URL produced a Cloudflare error:

Text
https://site.com/%C0
XML
<Error>
<Code>InvalidURI</Code>
<Message>Couldn't parse the specified URI.</Message>
<URI>/%C0</URI>

The %C0 sequence is not a valid UTF-8 encoding, so the request URI could not be parsed and the edge returned an InvalidURI error.

Exploitation

Step 1: Check for an S3 bucket behind the host

The target domain was appended with .s3.amazonaws.com:

Text
https;//target.com.s3.amazonaws.com/

This returned the bucket name. Sometimes the response said no such bucket. In that case the researcher ran dig against the host:

Bash
$ dig site.com

dig returns the DNS records for the name, including the CNAME of the pointed domain.

Step 2: Test what the bucket allows

A referenced article on S3 bucket misconfigured access controls describes testing CRUD operations, but on this bucket those operations returned access denied. The next step was to check what could be done at all, using the AWS CLI to list the bucket:

Bash
aws s3 ls s3://target-bucketname

The response contained a prefix:

Text
PRE Server/

PRE marks a common prefix in the listing, so a Server/ prefix existed in the bucket.

Step 3: Read the exposed files

Looking inside that prefix revealed server.js and users.httpasswd. The researcher was able to read the old server code (the env one) and the authentication file with the users.

From the original on virdoexhunter.medium.com

Root cause

The bucket allowed listing and reading objects under the Server/ prefix, while CRUD operations returned access denied. Old server code and an authentication file had been left in the bucket and were reachable through those permissions.

Impact

An attacker who can list and read the bucket obtains the old server code and the users.htpasswd authentication file. The write-up does not describe what those credentials protect or whether they were still valid, so the practical reach of the exposure depends on whether the old code and credentials are reused anywhere live.

Fix

The write-up does not describe a remediation. The measure implied by the finding is to remove public list and read access from the bucket and to delete old server code and authentication files that are no longer needed.

Variants to test

  1. Request a host with an invalid percent-encoded byte such as /%C0 and look for an InvalidURI error from the edge. A positive result is an InvalidURI error response that names the URI.
  2. Append .s3.amazonaws.com to the target domain and request it. A positive result is a response that reveals the bucket name; a "no such bucket" response means moving on to DNS.
  3. Run dig on the host and inspect the CNAME. A positive result is a CNAME record returned for the host.
  4. Run aws s3 ls s3://bucketname without credentials. A positive result is a listing, including PRE prefixes, rather than access denied.
  5. List each prefix found and look for source code, configuration or authentication files. A positive result is readable objects such as server.js or users.htpasswd.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

A security researcher was testing a company's website. While poking at one of its subdomains, he found an Amazon S3 bucket. which is a kind of online filing cabinet that companies rent from Amazon to store files. That bucket allowed listing and reading of the files inside it. Inside, the company had left old server code and a file called users.htpasswd, which is a file that stores usernames and scrambled passwords for protecting a part of a website. The researcher reported it and was paid a bounty of 400 USD. The program is identified as RDP, and the finding belonged to one of the program's subsidiaries, which the write-up calls target.com.

This article walks through the same steps the researcher took, explaining each idea from scratch. You only need a browser and a computer to follow along; the command-line tools are explained as they appear.

Background: what S3 is and why misconfiguration matters

Amazon S3 (Simple Storage Service) is one of the most popular storage services on the internet. Companies use S3 buckets to store assets such as user profile pictures, static resources, and anything else their business logic needs. Think of a bucket as a shared folder in the cloud: you put files in it, and you can give other people permission to list the folder and to read or write files inside it.

When a bucket is not configured properly, or is left unclaimed, an attacker may be able to perform actions such as S3 bucket takeover or S3 content takeover. A bucket takeover means someone else claims a bucket name that a company still points to, so traffic meant for the company ends up at the attacker's files. A content takeover means an attacker can replace or add files that the company's website serves to its users. Both are serious because visitors trust the site's own domain name.

This write-up is about a misconfigured S3 bucket that exposed old server code together with an authentication file, users.htpasswd. The application under test had a medium scope, meaning the bug bounty program allowed testing of a defined, middle-sized set of its systems, and the finding belonged to one of the program's subsidiaries.

Step 1: Finding subdomains

The work started with subdomain enumeration. A subdomain is a name that sits in front of a main domain, like shop.example.com next to example.com. Companies often have many of them, and each one can be a separate system with its own mistakes. Enumerating them means making a list of all the subdomains that exist, so you can look at each one.

The researcher resolved unique subdomains with the following command:

Bash
Subfinder -d target.com | httpx | tee -a alive.txt

Line by line, in plain words:

  • Subfinder -d target.com runs a tool called Subfinder against the domain target.com. The -d flag means "domain", so the tool goes looking for subdomains of that domain and prints the ones it finds.
  • The vertical bar | is a pipe. It takes whatever the first command printed and hands it to the next command as input, like passing a list from one person to the next.
  • httpx takes that list of names and checks which of them actually respond on the web. A name can exist in DNS but have nothing running behind it, so this step filters out the dead ones. The result is the set of "alive" subdomains.
  • tee -a alive.txt does two things at once: it shows the results on screen and appends them to a file called alive.txt. The -a means append, so if the file already exists, new results are added rather than overwriting it.

The output was the set of alive subdomains, each of which was then opened in a browser. Opening each one by hand is how the researcher got a feel for what each host was and how it behaved.

Step 2: The odd error that started the trail

One of the alive hosts is called site.com in the write-up. The researcher opened it in the browser and then appended /%C0 to the URL:

Text
https://site.com/%C0

In a URL, a percent sign followed by two characters is an escape sequence that stands for a single byte. %C0 is a byte value that is not a valid UTF-8 encoding on its own. UTF-8 is the standard way text is encoded on the web, and some byte values are only valid as part of a longer sequence. Sending %C0 alone is therefore malformed input, and the server or the layer in front of it cannot make sense of the request URI.

The response was a Cloudflare error:

XML
<Error>
<Code>InvalidURI</Code>
<Message>Couldn't parse the specified URI.</Message>
<URI>/%C0</URI>
</Error>

Line by line:

  • <Error> opens an error document. The whole reply is a small XML document, which is a structured text format made of tags in angle brackets.
  • <Code>InvalidURI</Code> gives the error's short name: the URI (the address part of the request) was invalid.
  • <Message>Couldn't parse the specified URI.</Message> is the human-readable explanation: the system could not parse, meaning could not understand, the address it was given.
  • <URI>/%C0</URI> echoes back the part of the address that caused the problem.
  • </Error> closes the document.

Cloudflare is a service that sits in front of many websites and filters or caches traffic before it reaches the company's own servers.

Step 3: Checking for an S3 bucket behind the host

Next, the target domain was appended with .s3.amazonaws.com:

Text
https;//target.com.s3.amazonaws.com/

This is the address pattern Amazon uses for buckets: the bucket name comes first, then .s3.amazonaws.com. The write-up notes that this returned the bucket name. Sometimes the response said no such bucket, meaning no bucket with that name existed at that address. In that case the researcher ran dig against the host:

Bash
$ dig site.com

dig is a command-line tool that asks the Domain Name System (DNS) for information about a name. DNS is the internet's address book: it translates names like site.com into the addresses of the machines that serve them. dig returns the DNS records for the name, including the CNAME of the pointed domain. A CNAME (canonical name) record is an alias: it says "this name is really another name". The CNAME of the pointed domain is returned by dig.

Step 4: Testing what the bucket allows

The researcher then read a referenced article on S3 bucket misconfigured access controls. That article describes testing CRUD operations. CRUD stands for Create, Read, Update and Delete: the four basic things you can do with stored data. On this bucket, those operations returned access denied.

The next step was to check what could be done at all, using the AWS CLI to list the bucket:

Bash
aws s3 ls s3://target-bucketname

Line by line:

  • aws is the command-line program for Amazon Web Services, Amazon's cloud platform. The AWS CLI is the tool you use to talk to AWS services from a terminal.
  • s3 selects the S3 service, so the command is about storage buckets.
  • ls means list. It asks S3 to show what is inside the bucket, like listing the contents of a folder.
  • s3://target-bucketname is the address of the bucket, in the form s3:// followed by the bucket's name.

The response contained a prefix:

Text
PRE Server/

PRE marks a common prefix in the listing. A prefix is the beginning of a file path, and S3 groups objects by these beginnings the way a folder groups files. So a Server/ prefix existed in the bucket, and its contents could be listed. The bucket allowed listing and reading, which is how the files were found.

Step 5: Reading the exposed files

Looking inside that prefix revealed server.js and users.httpasswd. The researcher was able to read the old server code (the env one) and the authentication file with the users.

server.js is a file of JavaScript code that runs on a server, so it is the program that handles requests for a website. The write-up calls it the old server code (the env one). users.htpasswd is an authentication file: .htpasswd files store usernames and hashed passwords, and a web server checks them to decide who may access a protected area. Hashed means the password has been scrambled with a one-way function, so the file does not contain the plain password, but it can still be attacked offline by guessing passwords and comparing the results.

From the original on virdoexhunter.medium.com

Why this matters

The bucket allowed listing and reading objects under the Server/ prefix, while CRUD operations returned access denied. Old server code and an authentication file had been left in the bucket and were reachable through those permissions.

An attacker who can list and read the bucket obtains the old server code and the users.htpasswd authentication file. The write-up does not describe what those credentials protect or whether they were still valid, so the practical reach of the exposure depends on whether the old code and credentials are reused anywhere live.

How to fix it

The write-up does not describe a remediation. The measure implied by the finding is to remove public list and read access from the bucket and to delete old server code and authentication files that are no longer needed. In everyday terms: lock the filing cabinet, and throw away the old keys and documents you no longer use instead of leaving them in a drawer anyone can open.

Things to try yourself

  1. Request a host with an invalid percent-encoded byte such as /%C0 and look for an InvalidURI error from the edge. A positive result is an InvalidURI error response that names the URI.
  2. Append .s3.amazonaws.com to the target domain and request it. A positive result is a response that reveals the bucket name; a "no such bucket" response means moving on to DNS.
  3. Run dig on the host and inspect the CNAME. A positive result is a CNAME record returned for the host.
  4. Run aws s3 ls s3://bucketname without credentials. A positive result is a listing, including PRE prefixes, rather than access denied.
  5. List each prefix found and look for source code, configuration or authentication files. A positive result is readable objects such as server.js or users.htpasswd.

Glossary

  • S3 (Simple Storage Service): Amazon's cloud service for storing files, organised into containers called buckets.
  • Bucket: a container in S3 that holds files, similar to a folder.
  • Object: a single file stored in a bucket.
  • Bucket takeover: an attacker claims a bucket name that a company still points to, so traffic meant for the company reaches the attacker's files.
  • Content takeover: an attacker replaces or adds files that a company's website serves to its users.
  • Misconfiguration: a setting left in a state that exposes more than intended, often by accident.
  • Subdomain: a name in front of a main domain, such as shop.example.com next to example.com.
  • Subdomain enumeration: making a list of the subdomains that exist for a domain.
  • Pipe (|): a shell symbol that passes the output of one command as input to the next.
  • Subfinder: a tool that finds subdomains for a domain.
  • httpx: a tool that checks which hostnames respond on the web.
  • tee: a command that shows output on screen and also writes it to a file; -a appends instead of overwriting.
  • URL: the address of a resource on the web.
  • Percent encoding: writing a byte in a URL as a percent sign followed by two characters, such as %C0.
  • UTF-8: the standard encoding that turns text into bytes on the web.
  • URI: the address part of a request; in practice, the URL path being requested.
  • XML: a structured text format made of tags in angle brackets.
  • Cloudflare: a service that sits in front of websites and filters or caches traffic before it reaches the company's servers.
  • DNS (Domain Name System): the internet's address book, translating names into machine addresses.
  • CNAME: a DNS record that says one name is an alias for another.
  • dig: a command-line tool that queries DNS records for a name.
  • CRUD: Create, Read, Update, Delete, the four basic operations on stored data.
  • AWS CLI: the command-line program for talking to Amazon Web Services.
  • Prefix: the beginning of a file path; S3 groups objects by prefixes the way folders group files.
  • PRE: a marker in an S3 listing that indicates a common prefix, that is, a folder-like group.
  • server.js: a file of JavaScript code that runs on a server and handles requests for a website.
  • Environment: a particular deployment setup, such as a staging or production copy of a system.
  • .htpasswd: an authentication file that stores usernames and hashed passwords for protecting part of a website.
  • Hash: the scrambled result of a one-way function applied to a password, so the original is not stored directly.
  • Access denied: the response when a service refuses an operation because the requester lacks permission.
  • Bounty: a reward paid by a bug bounty program for a valid security report.
  • Scope: the set of systems a bug bounty program allows you to test.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.