Skip to content
Write-up

Finding Basic Authtoken in JAVASCRIPT file BY Full Automation

Santosh Kumar Sha Follow

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 to Find the production and staging access token leaked by android application and takeover the whole infrastructure .

Santosh Kumar Sha (@killmongar1996), on notifybugme.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. 6 min read.

Context

Santosh Kumar Sha (@killmongar1996) describes a workflow for finding leaked credentials in JavaScript files, and reports that with it he found production and staging access tokens leaked by an Android application and was able to take over the whole infrastructure. The article is written as a general method rather than a single-endpoint walkthrough: the target is referred to only as example.com, with all subdomains and wildcards in scope.

The weakness class is information disclosure: secrets that should never have been shipped to a client end up inside JavaScript bundles served to anyone who asks for them. The article's stated motivation is scale. Reading every JavaScript file by hand, when a single file can run past a thousand lines, is not feasible, so the collection and the search are automated.

Setup

The researcher lists the following tools:

  1. gf (tomnomnom) - https://github.com/tomnomnom/gf
  2. grep
  3. wget
  4. gau (Corben) - https://github.com/lc/gau
  5. waybackurls (tomnomnom) - https://github.com/tomnomnom/waybackurls
  6. subjs (Corben) - https://github.com/lc/subjs

Several commands in the article also use subfinder, httpx and anew, which are not in that list. The only precondition stated is scope: the target domain is example.com and all subdomains and wildcards are in scope, written as *.example.com. No account, role or authentication is needed for the collection or the search steps.

Finding it

The idea is that JavaScript files are a place to look for secrets, because the researcher found access tokens leaked by an Android application in them. Rather than guessing URLs, the researcher harvests JavaScript file URLs from passive sources (the Wayback Machine, via gau and waybackurls), from live hosts (via subjs), and from Burp by spidering the host and copying every JavaScript link out of it. The Burp step is called out explicitly so that no JavaScript file is missed.

Once the list exists, it is deduplicated and filtered down to URLs that actually resolve, so that dead links do not waste the later requests.

Exploitation

Step 1: Collecting all the JS files from the Wayback Machine

Three collection commands feed the same file:

Bash
gau -subs example.com | grep “.js$” >> jsfile.txt
Bash
subfinder -d example.com -silent | waybackurls | grep “.js$” >> jsfile.txt
Bash
subfinder -d example.com -silent | httpx -silent | subjs >> jsfile.txt

The first pulls known URLs for the domain and its subdomains with gau and keeps those ending in .js. The second enumerates subdomains with subfinder, feeds them to waybackurls, and again keeps .js URLs. The third enumerates subdomains, probes which are alive with httpx, and extracts the JavaScript files each live host references with subjs. All three append to jsfile.txt.

The researcher also notes that the host should be spidered in Burp and every JavaScript link copied from Burp into jsfile.txt, so that nothing is missed.

Step 2: Sorting and removing dead links

The combined list is deduplicated and filtered to resolving URLs:

Bash
cat jsfile.txt | sort -u | anew | httpx -silent >> jsfile_totest.txt

sort -u removes duplicates, anew appends only new lines, and httpx -silent keeps the URLs that respond, writing the result to jsfile_totest.txt. This is the list used by both automation cases below.

Step 3: Case 1, automation with curl and grep

The researcher deliberately avoids complex tooling or custom scripts. The whole search is one pipeline:

Bash
cat jsfile_totest.txt | xargs -I % -P 10 curl -sk “%” | grep -E -i -w -n ‘BASIC[\\-|_|A-Z0–9]*(\’|\”)?(:|=)(\’|\”)?[\\-|_|A-Z0–9]{10}’ — color

xargs -I % -P 10 runs up to ten curl fetches in parallel, one per URL. curl -sk fetches each file silently and ignores TLS certificate errors, so hosts with bad or self-signed certificates still get checked. The output of all fetches is piped into grep -E -i -w -n, an extended, case-insensitive, whole-word, line-numbered search. The pattern looks for the word BASIC, followed by any run of characters from the class [\-|_|A-Z0–9], an optional quote, a : or =, another optional quote, and then ten characters from the same class. In other words it hunts for a Basic authentication value assigned or paired with a colon or equals sign, with a ten-character token after it. --color highlights the matches.

Step 4: Case 2, automation with wget and grep

The second case exists so that the files are also available locally for white box testing. First the files are downloaded recursively:

Bash
mkdir localpathjs; cd localpathjs
Bash
cat jsfile_totest.txt | xargs -I % -P 10 wget -r “%”

Again ten parallel downloads, this time with wget -r so that each URL is mirrored into the local directory tree. The researcher then moves into the download directory (his own is localpathjs) and runs the same pattern as a recursive search over the local files:

Bash
cd localpathjs
Bash
root@kali:~/localpathjs# grep -E -i -w -n -r -H ‘BASIC[\\-|_|A-Z0–9]*(\’|\”)?(:|=)(\’|\”)?[\\-|_|A-Z0–9]{10}’ — color

The added flags are -r for recursive search and -H to print the filename with each hit, so a match points back to the file it came from. The prompt shows the search running from a Kali shell inside the download directory.

Result

Using this process the researcher reports finding production and staging access tokens leaked by an Android application, and states that this allowed takeover of the whole infrastructure. The article does not show the matched lines, the endpoints, the token values or the responses, so the exact form of the leak is not documented beyond the pattern above.

Root cause

Secrets that belong on the server were embedded in JavaScript delivered to clients. Because JavaScript is fetched by the browser or extracted from the Android application, anyone can read it, and a token in it is effectively public. The article frames the problem as one of scale on the defender's side too: with files running past a thousand lines, nobody reviews them by hand, so leaked credentials sit unnoticed. The researcher does not describe any specific defence that failed; the implication is that the tokens were simply present in shipped code.

Impact

The researcher reports finding production and staging access tokens leaked by an Android application and taking over the whole infrastructure. That is his account of the outcome on his target; the article gives no further detail on what the tokens authorised or what was accessed. In general terms, a leaked token in client-side code is readable by anyone who fetches the file, and no special access is needed to obtain it.

Fix

The article does not describe a fix or a remediation carried out by the target.

Variants to test

  1. Run the same collection against other scopes: gau -subs, waybackurls over subfinder output, and subjs over httpx output, plus a Burp spider. A positive result is a jsfile_totest.txt that includes JavaScript from hosts you did not know about, especially staging or internal-sounding subdomains.
  2. Change the grep pattern to other credential shapes, for example api[_-]?key, secret, token, Authorization or Bearer, keeping the same curl -sk pipeline. A positive result is a line in a JavaScript file pairing the keyword with a value.
  3. Run the wget variant and grep the local mirror with -r -H, so hits carry a filename. A positive result is a hit in a downloaded file that you can open and read in context.
  4. Look for staging and production tokens, since the researcher's finding involved both. A positive result is a token in a file from either environment.
  5. Repeat the search on JavaScript associated with an Android application, as the researcher's finding involved one. A positive result is a token in a JavaScript file.

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. 12 min read.

What happened, in plain words

Santosh Kumar Sha, a security researcher from Assam in India, wrote up a method for finding secrets that have been left inside JavaScript files. JavaScript is the programming language that web pages and mobile apps use to run code on your own computer or phone. When you open a website, your browser downloads JavaScript files and runs them. Anyone can download those same files, because they are sent to every visitor. If a developer accidentally puts a password, a token or an API key inside one of those files, it is no longer secret: it is sitting on your machine, readable by anyone who looks.

Using this method, Santosh reports that he found production and staging access tokens leaked by an Android application and took over the whole infrastructure. The article does not show the matched lines, the addresses involved, the token values or any server responses, so the exact shape of the leak is not documented beyond the search pattern he gives.

The article is written as a general recipe rather than a walkthrough of one specific website. The target is only ever called example.com, and the scope is every subdomain and wildcard, written *.example.com. A subdomain is a prefix on a domain name, like shop.example.com or staging.example.com; a wildcard means all of them are fair game.

The kind of problem here is called information disclosure: something that should have stayed private is handed out to anyone who asks. The reason for automating the search is scale. A single JavaScript file can run past a thousand lines, and a site can have thousands of files, so reading them by hand is not realistic.

The tools

The researcher lists six tools. Each one is a small command-line program, meaning you type its name in a terminal window and it does one job.

  1. gf (tomnomnom) - https://github.com/tomnomnom/gf
  2. grep
  3. wget
  4. gau (Corben) - https://github.com/lc/gau
  5. waybackurls (tomnomnom) - https://github.com/tomnomnom/waybackurls
  6. subjs (Corben) - https://github.com/lc/subjs

Several commands in the article also use subfinder, httpx and anew, which are not in that list. Here is what each one does in plain terms:

  • gau asks the Wayback Machine, an archive that has been saving copies of web pages for years, for every URL it has ever recorded for a domain. It is like asking a library for every page it ever photocopied from a magazine.
  • waybackurls does a similar job: given a list of domains, it prints URLs the archive knows about.
  • subfinder finds subdomains of a domain, the way you might list every room in a building.
  • httpx takes a list of addresses and checks which ones actually answer, like knocking on doors to see which ones open.
  • subjs takes a web page and lists the JavaScript files that page loads.
  • grep searches text for a pattern and prints the lines that match. It is the heart of the whole method.
  • wget downloads files, and with the right option can copy a whole site's file tree to your computer.
  • curl fetches a single URL and prints what comes back.
  • anew adds only lines that are not already in a file, so you do not get duplicates.
  • gf is a helper for storing and reusing grep patterns.

The only precondition stated is scope: the target is example.com and all subdomains and wildcards are in scope. No account, login or special permission is needed for the collection or the search steps, because all of it works on files the site serves publicly.

Finding it

The reasoning is simple. JavaScript files are a good place to look for secrets because front-end code and mobile code often carry tokens that were meant to stay on the server. Instead of guessing addresses, the researcher gathers JavaScript file addresses from three kinds of source: passive archives (the Wayback Machine, through gau and waybackurls), live hosts (through subjs), and Burp. Burp is a tool that sits between your browser and a website and records every request; the researcher spiders the host with it, meaning he lets it crawl the site automatically, and copies every JavaScript link out of it. That step is called out explicitly so that no JavaScript file is missed.

Once the list exists, it is deduplicated and filtered down to addresses that actually respond, so dead links do not waste the later requests.

Step 1: Collecting all the JS files from the Wayback Machine

Three collection commands all feed the same file:

Bash
gau -subs example.com | grep “.js$” >> jsfile.txt

Line by line: gau -subs example.com asks the archive for known URLs for example.com and its subdomains. The vertical bar | means "take the output of the left command and feed it to the right one", like a pipe carrying water from one tank to the next. grep “.js$” keeps only the lines that end in .js, because $ means "end of line". >> jsfile.txt appends the result to a file called jsfile.txt without erasing what is already there.

Bash
subfinder -d example.com -silent | waybackurls | grep “.js$” >> jsfile.txt

Here subfinder -d example.com -silent lists subdomains of example.com quietly, without extra chatter. Those subdomains are piped into waybackurls, which prints archived URLs for each of them. grep “.js$” again keeps only JavaScript files, and the result is appended to the same jsfile.txt.

Bash
subfinder -d example.com -silent | httpx -silent | subjs >> jsfile.txt

This time the subdomains go to httpx -silent, which keeps only the ones that are alive and answering. Those live hosts go to subjs, which lists the JavaScript files each live page loads. Again the output is appended to jsfile.txt.

The researcher also notes that the host should be spidered in Burp and every JavaScript link copied from Burp into jsfile.txt, so that nothing is missed.

Step 2: Sorting and removing dead links

The combined list is deduplicated and filtered to addresses that respond:

Bash
cat jsfile.txt | sort -u | anew | httpx -silent >> jsfile_totest.txt

cat jsfile.txt prints the whole file. sort -u sorts the lines and removes duplicates, so the same address appearing five times becomes one line. anew appends only lines that are new. httpx -silent keeps the addresses that actually answer, dropping dead links. The result is written to jsfile_totest.txt, and that is the list both automation cases below use.

Step 3: Case 1, automation with curl and grep

The researcher deliberately avoids complex tooling or custom scripts. The whole search is one pipeline:

Bash
cat jsfile_totest.txt | xargs -I % -P 10 curl -sk “%” | grep -E -i -w -n ‘BASIC[\\-|_|A-Z0–9]*(\’|\”)?(:|=)(\’|\”)?[\\-|_|A-Z0–9]{10}’ — color

Line by line: cat jsfile_totest.txt prints the list of addresses. xargs -I % -P 10 takes that list and runs the next command once per line, where % stands for the current line, and -P 10 means up to ten of them run at the same time, like ten people each fetching one file instead of one person fetching all of them. curl -sk “%” fetches each address: -s means silent, no progress noise, and -k means ignore TLS certificate errors, so hosts with bad or self-signed certificates still get checked. A TLS certificate is the padlock proof a website shows that it is who it claims to be; ignoring errors here just means the researcher does not want a broken padlock to stop the download.

The output of all those fetches is piped into grep -E -i -w -n. -E means extended regular expressions, a richer pattern language. -i means ignore case, so basic and BASIC both match. -w means whole word, so the pattern must sit on word boundaries. -n prints the line number of each match. --color highlights the matching text so it stands out.

The pattern itself looks for the word BASIC, followed by any run of characters from the class [\-|_|A-Z0–9] (letters, digits, hyphen and underscore), an optional quote, a : or =, another optional quote, and then ten characters from the same class. In other words it hunts for a Basic authentication value paired with a colon or an equals sign, with a ten-character token after it. A Basic authentication token is a short string a client sends to prove who it is; if it is in a public file, anyone can send it too.

Step 4: Case 2, automation with wget and grep

The second case exists so that the files are also available locally for white box testing. White box testing means you can read the code itself, not just poke at the running site from outside.

Bash
mkdir localpathjs; cd localpathjs

mkdir localpathjs creates a folder called localpathjs. The semicolon separates commands, so cd localpathjs then moves you into that folder. It is like making a new drawer and opening it.

Bash
cat jsfile_totest.txt | xargs -I % -P 10 wget -r “%”

Again ten parallel downloads, this time with wget -r, where -r means recursive: wget follows links and mirrors the file tree into your local folder rather than saving one flat file.

The researcher then moves into the download directory (his own is localpathjs) and runs the same pattern as a recursive search over the local files:

Bash
cd localpathjs
Bash
root@kali:~/localpathjs# grep -E -i -w -n -r -H ‘BASIC[\\-|_|A-Z0–9]*(\’|\”)?(:|=)(\’|\”)?[\\-|_|A-Z0–9]{10}’ — color

The prompt root@kali:~/localpathjs# shows the search running from a Kali shell inside the download directory. Kali is a Linux distribution that ships with security tools. The flags are the same as before, with two additions: -r means search recursively through every file in the folder and its subfolders, and -H prints the filename with each hit, so a match points back to the file it came from.

Result

Using this process the researcher reports finding production and staging access tokens leaked by an Android application, and states that this allowed takeover of the whole infrastructure. Production means the live system real users touch; staging means the copy used for testing before release. A token is a short string that acts like a key: whoever holds it is treated as the person it was issued to. The article does not show the matched lines, the addresses, the token values or the responses, so the exact form of the leak is not documented beyond the pattern above.

Root cause

Secrets that belong on the server were embedded in JavaScript delivered to clients. Because JavaScript is fetched by the browser or extracted from the Android application, anyone can read it, and a token in it is effectively public. The article frames the problem as one of scale on the defender's side too: with files running past a thousand lines, nobody reviews them by hand, so leaked credentials sit unnoticed. The researcher does not describe any specific defence that failed; the implication is that the tokens were simply present in shipped code.

Impact

The researcher reports finding production and staging access tokens leaked by an Android application and taking over the whole infrastructure. That is his account of the outcome on his target; the article gives no further detail on what the tokens authorised or what was accessed. In general terms, a leaked token in client-side code is readable by anyone who fetches the file, and no special access is needed to obtain it.

Fix

The article does not describe a fix or a remediation carried out by the target. Rotating means issuing a new token and cancelling the old one, the way you change a lock after losing a key.

Variants to test

  1. Run the same collection against other scopes: gau -subs, waybackurls over subfinder output, and subjs over httpx output, plus a Burp spider. A positive result is a jsfile_totest.txt that includes JavaScript from hosts you did not know about, especially staging or internal-sounding subdomains.
  2. Change the grep pattern to other credential shapes, for example api[_-]?key, secret, token, Authorization or Bearer, keeping the same curl -sk pipeline. A positive result is a line in a JavaScript file pairing the keyword with a value.
  3. Run the wget variant and grep the local mirror with -r -H, so hits carry a filename. A positive result is a hit in a downloaded file that you can open and read in context.
  4. Look for staging and production tokens, since the researcher's finding involved both. A positive result is a token in a file from either environment.
  5. Repeat the search on JavaScript associated with an Android application, as the researcher's finding involved one. A positive result is a token in a JavaScript file.

Glossary

  • JavaScript: the programming language that web pages and mobile apps use to run code on the visitor's own device.
  • JavaScript file: a file ending in .js that a page loads and runs; anyone can download it.
  • Information disclosure: a weakness where something meant to stay private is handed out to anyone who asks.
  • Token: a short string that acts like a key; whoever holds it is treated as the person it was issued to.
  • Access token: a token that grants access to a service or API.
  • API: a way for one program to talk to another, like a service counter where you hand over a request and get an answer.
  • Basic authentication: a simple login scheme where the client sends a short encoded string to prove who it is.
  • Production: the live system that real users use.
  • Staging: a copy of the system used for testing before release.
  • Subdomain: a prefix on a domain name, such as shop.example.com.
  • Wildcard: a notation like *.example.com meaning every subdomain is included.
  • Scope: the set of targets a researcher is allowed to test.
  • Wayback Machine: an archive that has saved copies of web pages and their addresses for years.
  • Spider: to let a tool crawl a site automatically, following links and recording what it finds.
  • Burp: a tool that sits between your browser and a website and records every request.
  • Terminal: a window where you type commands instead of clicking.
  • Command line: the text interface where commands are typed.
  • Pipeline: a chain of commands where the output of one is fed to the next, written with |.
  • grep: a program that searches text for a pattern and prints matching lines.
  • Regular expression: a pattern language for describing text to search for.
  • curl: a program that fetches a URL and prints the response.
  • wget: a program that downloads files, optionally mirroring a whole site.
  • Recursive: following links and subfolders rather than stopping at one level.
  • TLS certificate: the padlock proof a website shows that it is who it claims to be.
  • White box testing: testing where you can read the code itself, not just poke at the running site.
  • Kali: a Linux distribution that ships with security tools.
  • Rotate: to issue a new secret and cancel the old one.
  • Credential: any secret used to prove identity, such as a password or token.
  • Deduplicate: to remove repeated copies of the same line.
  • Dead link: an address that no longer responds.

More by Santosh Kumar Sha

View all

16 more disclosed reports, best first.

Similar reports

Same bug class and techniques, clearest first.