Misconfigured AWS S3 Bucket (Information Disclosure & Subdomain Takeover)
A publicly readable S3 bucket exposed sample projects, and one project's JavaScript referenced a deleted S3 bucket. An attacker could register that bucket name and receive logs from the live site, enabling subdomain takeover.
Published on medium.com
Herkese merhaba, bu yazımda HackerOne platformuna bağlı private bir şirkette bulduğum güvenlik açığından bahsedip burada dikkat etmemiz gereken yerlere değinmeye çalışacağım. Yani bu makalede hem saldırı tarafını hem de savunma tarafını incelemiş olacağız.
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 write-up covers a finding made on a private company programme on HackerOne. The company is referred to throughout as XYZ, and its main domain as xyz.com. The scope added to the programme covered all subdomains of xyz.com, written as *.xyz.com.
The feature involved is not a single application but the company's subdomain estate as a whole. One of those subdomains, abc.xyz.com, was serving an AWS S3 bucket. The bucket was meant to hold sample projects, but its read permission was not restricted, so the contents were public. Inside one of those sample projects, a JavaScript file referenced a second bucket by name. That second bucket no longer existed, which turned an information disclosure into a subdomain takeover.
Setup
The researcher worked from the outside with no special access to the company's infrastructure. The tools used were:
- subfinder for subdomain enumeration.
- A Chrome extension that opens multiple URLs at once, used to review every discovered subdomain in a single pass.
- The AWS CLI, used to list bucket contents.
The programme scope included all subdomains of xyz.com, written as *.xyz.com.
Finding it
The first step was enumeration. Running subfinder against the scope produced roughly 250 subdomains. Rather than triaging them one by one, the researcher opened all of them at once with the multi-URL extension and reviewed the results.
One hostname stood out: abc.xyz.com was backed by an AWS S3 bucket. The read permission on that bucket had not been restricted, so the bucket was public. A public bucket that may hold sensitive material is worth inspecting immediately, so the next step was to confirm the exposure and list what was inside.
Exploitation
Step 1: confirm the bucket is public
The AWS CLI was used to list the bucket:
aws s3 ls abc.xyz.com
Running the command confirmed that the bucket was public. This is the information disclosure: anyone who knows the hostname can enumerate the objects.
Step 2: enumerate the samples directory
The bucket contained a samples prefix, which was listed next:
aws s3 ls abc.xyz.com/samples/
Under samples there were close to 20 sample test projects. These were different web applications that exercised login flows and tried out various tokens. Each project was reviewed in turn.
Step 3: find the second bucket name in JavaScript
While going through the projects, a block of code in the page source of one project's JavaScript caught the researcher's attention. The bucket contained a reference to another bucket. The developer had used that second bucket in the JavaScript and had left its name in the code. In the write-up the second bucket is called def.
Step 4: check whether the second bucket exists
Requesting the second bucket directly, at def.s3.amazonaws.com, returned an unexpected response:
The specified bucket does not exist
That response is the signal for a subdomain takeover: the bucket name is referenced by live code but the bucket itself has been deleted, so the name is free. Anyone who registers a bucket with that name takes control of whatever the code points at. The write-up points to can-i-take-over-xyz as the reference for which products are affected by this class of bug and under which conditions it can be exploited.
In itself, a bucket name left in code and then deleted is not obviously a vulnerability. The problem starts once the bucket is claimed. After registering the bucket, visiting the page whose code block referenced it caused logs to start arriving in the newly claimed bucket. Those logs contained IP addresses and information about HTTP requests. Because of what they contained, the researcher stopped there and the exploitation phase ended. The write-up notes that far more critical data could have flowed this way, for example to a backend API, or, as in this case, to the cloud, in an insecure manner.
The bounty for this finding was 1000 USD.
Root cause
Two separate mistakes combine here.
- The first bucket was public. Read permission on the S3 bucket behind
abc.xyz.comwas not restricted, so its contents, including the sample projects and their source, could be listed and read by anyone. The write-up does not say whether upload or delete were also open; it does say that in this case the upload function did not work, and that the impact would have been much greater if it had. - Live code referenced a bucket that no longer existed. The developer used a second bucket in the JavaScript and left its name in the code. The bucket was later deleted, but the code that referenced it stayed live. A deleted bucket name is claimable by anyone, so the reference became a takeover primitive. The write-up frames this as a general lesson: when an application is removed, no working code should be left behind, and old API versions, for example a v1 when a v3 exists, should not stay in use unless there is a reason.
Neither mistake is exotic. The public bucket made the second reference discoverable, and the dangling reference made the takeover possible.
Impact
The direct impact demonstrated was information disclosure: the contents of a public bucket, including close to 20 sample projects that exercised login and token handling, could be read by anyone. The second impact was a subdomain takeover: a bucket name referenced by the company's live code could be registered by an attacker, giving that attacker control over what the referencing page loaded or sent.
Once the bucket was claimed, requests to the page began depositing logs, including IP addresses and HTTP request details, into the attacker-controlled bucket. The researcher stopped at that point. The write-up is explicit that the effect could have been larger: sensitive data could have been sent insecurely to a backend API, or to the cloud as in this example.
Fix
The write-up does not describe which remediation the company applied. It closes with the points that should be observed:
- A storage area that may contain sensitive information must never be public.
- When applications are deleted, no working code should be left behind. If a third version of a REST API is written, v1 should not remain in use unless it is needed.
- When an S3 bucket is used, the read, upload and delete permissions must be configured properly. In this case upload did not work, but if it had, the impact could have been much greater.
- Sensitive information must not be hardcoded inside JavaScript.
Variants to test
- Public buckets behind subdomains. Enumerate subdomains, open them in bulk, and look for hosts that answer as S3. Run
aws s3 ls <bucket>against each. A positive result is a full object listing without credentials. - Bucket names in client-side code. Download the JavaScript of every application found in a public bucket and grep for S3 hostnames and bucket names. A positive result is a bucket name that is referenced by live code.
- Dangling bucket references. Request each discovered bucket name directly, for example at
<name>.s3.amazonaws.com. A positive result isThe specified bucket does not existon a name that live code still uses, which means the name can be registered. - Claim and observe. After registering a dangling bucket, load the referencing page and watch what arrives in the bucket. A positive result is logs arriving in the bucket. The researcher stopped once they contained IP addresses and HTTP request details.
Get the Medium app


What happened, in plain words
A security researcher was invited to test a private company on HackerOne, a platform where companies publish rules for what may be tested and pay for confirmed problems. The company is called XYZ in the write-up, and its main website is xyz.com. The rules said the researcher could look at every subdomain of xyz.com, written as *.xyz.com. A subdomain is a smaller address that sits in front of the main domain, for example shop.xyz.com or mail.xyz.com; companies use them to run separate services without buying a new domain name.
While looking through those subdomains, the researcher found one, abc.xyz.com, that was not a normal website. It was a storage area in the cloud, an AWS S3 bucket. S3 is Amazon's file storage service: you put files in a bucket, and the bucket can be made readable by everyone or restricted to certain people. This one had not been restricted, so anyone who knew the address could list and read what was inside.
Inside the bucket were sample projects, and in the code of one of them the researcher found the name of a second bucket. That second bucket had been deleted, but the code still pointed at it. Because the name was free, anyone could register a bucket with that name and start receiving whatever the company's page sent there. That is called a subdomain takeover: you take over an address the company still uses, without breaking into anything.
When the researcher registered the bucket to prove the point, the company's page started sending logs into it, including IP addresses and details of web requests. The researcher stopped there, and the company paid a 1000 USD bounty.
The setup
The researcher worked entirely from the outside, with no special access to the company's systems. Three tools were used:
- subfinder, a program that finds subdomains for a domain.
- A Chrome extension that opens many web addresses at once, so every subdomain could be looked at in one pass instead of one by one.
- The AWS CLI, Amazon's command-line tool: a program you run in a terminal window to talk to Amazon's cloud services, including S3.
The programme's scope included wildcard subdomains, so any hostname under *.xyz.com was fair game.
Finding it
Step 1: collect the subdomains
The first job was to find out which subdomains exist. Running subfinder against the scope produced roughly 250 subdomains. That is a lot to check by hand, so instead of opening them one at a time, the researcher used the multi-URL extension to open all of them together and then reviewed the results.
Why do this first? Because you cannot test what you cannot find. A company's public website is usually the least interesting part; the subdomains are where forgotten services, old projects and test systems tend to live.
Step 2: spot the storage bucket
One hostname stood out. abc.xyz.com was not serving a normal web page: it was backed by an AWS S3 bucket. The read permission on that bucket had not been restricted, which means the bucket was public. A public bucket that might hold sensitive material is worth inspecting straight away, so the next step was to confirm the exposure and see what was inside.
Step 3: confirm the bucket is public
The researcher used the AWS CLI to list the bucket:
aws s3 ls abc.xyz.com
Line by line:
awsis the name of the Amazon command-line program.s3tells it which Amazon service to talk to, here the file storage service.lsmeans "list", the same idea as thelscommand that lists files in a folder on Linux or macOS.abc.xyz.comis the name of the bucket being listed.
Running the command confirmed that the bucket was public. That is the information disclosure: information that should have been private can be read by anyone who knows the address. No password, no account, no trick.
Step 4: look inside the samples folder
Buckets can contain folders, which S3 calls prefixes. This one had a samples prefix, listed next:
aws s3 ls abc.xyz.com/samples/
This is the same command as before, with /samples/ added to the end to say "list only what is in this folder". Under samples there were close to 20 sample test projects. These were small web applications that exercised login flows and tried out various tokens. A token here is a short piece of text a website gives you after you log in, so it can recognise you on later requests without asking for your password again; it works like a wristband at an event, which proves you already showed your ticket at the door.
Each project was reviewed in turn, because sample code often contains the same mistakes as the real thing, only with less care taken.
Step 5: find a second bucket name in the JavaScript
While going through the projects, a block of code in the page source of one project's JavaScript caught the researcher's attention. JavaScript is the programming language that runs inside your browser and makes web pages interactive; it is delivered to your computer as text, so anyone can read it by choosing "view source" in the browser.
The bucket contained a reference to another bucket. The developer had used that second bucket in the JavaScript and had left its name in the code. In the write-up the second bucket is called def.
Why does this matter? Because the code that runs in visitors' browsers still points at that name. Whatever the page does with that bucket, it will do to whoever owns the name.
Step 6: check whether the second bucket exists
Requesting the second bucket directly, at def.s3.amazonaws.com, returned an unexpected response:
The specified bucket does not exist
This is Amazon's own message, meaning no bucket with that name is currently registered. That response is the signal for a subdomain takeover. The name is referenced by live code, but the bucket itself has been deleted, so the name is free. Anyone who registers a bucket with that name takes control of whatever the code points at. The write-up points to can-i-take-over-xyz as the reference for which products are affected by this class of bug and under which conditions it can be exploited.
A comparison: imagine a company prints business cards with a phone number it later cancels. Anyone who gets that number now answers calls meant for the company. The card is still in circulation, and the number is free to claim.
In itself, a bucket name left in code and then deleted is not obviously a vulnerability. The problem starts once the bucket is claimed. After registering the bucket, visiting the page whose code block referenced it caused logs to start arriving in the newly claimed bucket. A log is a record of something that happened, here an entry describing a request. Those logs contained IP addresses and information about HTTP requests. An IP address is the number that identifies a computer on the internet, a bit like a postal address for a device. Because of what the logs contained, the researcher stopped there and the exploitation phase ended. The write-up notes that far more critical data could have flowed this way, for example to a backend API, or, as in this case, to the cloud, in an insecure manner.
An API is the part of a service that other software talks to, rather than a person clicking buttons: a waiter taking orders between the kitchen and the tables. If a page sends data to an API through a bucket that an outsider controls, the outsider sees the data on the way.
The bounty for this finding was 1000 USD.
Why it worked
Two separate mistakes combine here.
- The first bucket was public. Read permission on the S3 bucket behind
abc.xyz.comwas not restricted, so its contents, including the sample projects and their source, could be listed and read by anyone. The write-up does not say whether upload or delete were also open; it does say that in this case the upload function did not work, and that the impact would have been much greater if it had. - Live code referenced a bucket that no longer existed. The developer used a second bucket in the JavaScript and left its name in the code. The bucket was later deleted, but the code that referenced it stayed live. A deleted bucket name is claimable by anyone, so the reference became a takeover primitive. The write-up frames this as a general lesson: when an application is removed, no working code should be left behind, and old API versions, for example a v1 when a v3 exists, should not stay in use unless there is a reason.
What the impact was
The direct impact demonstrated was information disclosure: the contents of a public bucket, including close to 20 sample projects that exercised login and token handling, could be read by anyone. The second impact was a subdomain takeover: a bucket name referenced by the company's live code could be registered by an attacker, giving that attacker control over what the referencing page loaded or sent.
Once the bucket was claimed, requests to the page began depositing logs, including IP addresses and HTTP request details, into the attacker-controlled bucket. The researcher stopped at that point. The write-up is explicit that the effect could have been larger: sensitive data could have been sent insecurely to a backend API, or to the cloud as in this example.
How to fix it
The write-up does not describe which remediation the company applied. It closes with the points that should be observed:
- A storage area that may contain sensitive information must never be public.
- When applications are deleted, no working code should be left behind. If a third version of a REST API is written, v1 should not remain in use unless it is needed.
- When an S3 bucket is used, the read, upload and delete permissions must be configured properly. In this case upload did not work, but if it had, the impact could have been much greater.
- Sensitive information must not be hardcoded inside JavaScript. Hardcoded means written directly into the code as a fixed value, so it ships to every visitor's browser.
Variants to test
If you want to look for the same pattern yourself, these are variations on it.
- Public buckets behind subdomains. Enumerate subdomains, open them in bulk, and look for hosts that answer as S3. Run
aws s3 ls <bucket>against each. A positive result is a full object listing without credentials. - Bucket names in client-side code. Download the JavaScript of every application found in a public bucket and grep for S3 hostnames and bucket names. A positive result is a bucket name that is referenced by live code.
- Dangling bucket references. Request each discovered bucket name directly, for example at
<name>.s3.amazonaws.com. A positive result isThe specified bucket does not existon a name that live code still uses, which means the name can be registered. - Claim and observe. After registering a dangling bucket, load the referencing page and watch what arrives in the bucket. A positive result is logs arriving in the bucket. The researcher stopped once they contained IP addresses and HTTP request details.
Get the Medium app


Glossary
- Subdomain: an address that sits in front of a main domain, such as
abc.xyz.comunderxyz.com, used to run separate services. - Wildcard scope: a testing rule that covers every subdomain of a domain, written
*.xyz.com. - HackerOne: a platform where companies publish testing rules and pay researchers for confirmed problems.
- Bounty: the money a company pays for a valid finding.
- AWS: Amazon Web Services, Amazon's cloud platform.
- S3 bucket: a storage area in Amazon's cloud that holds files; it can be public or restricted.
- AWS CLI: Amazon's command-line program for talking to its cloud services from a terminal.
- Prefix: S3's word for a folder inside a bucket.
- Public bucket: a bucket whose read permission is not restricted, so anyone can list and read it.
- Information disclosure: a flaw where information that should be private can be read by outsiders.
- JavaScript: the programming language that runs in the browser and makes pages interactive; its source is visible to visitors.
- Token: a short piece of text a site issues after login so it can recognise you on later requests.
- Log: a record of something that happened, such as a request to a server.
- IP address: the number that identifies a computer on the internet.
- HTTP request: the message a browser sends to a server to ask for a page or send data.
- API: the part of a service that other software talks to, rather than a person.
- Subdomain takeover: registering a name or service that a company's live code still points at but no longer owns, so you receive what that code sends.
- Dangling reference: a pointer in live code to something that has been deleted, such as a bucket name.
- Hardcoded: a fixed value written directly into code, so it ships to every visitor.
- REST API versioning: numbering API versions (v1, v3) so old and new can coexist; old ones should be retired.
- Severity: how serious a finding is, usually based on what an attacker could do with it.