Analyzing Javascript Files
Analyzing Javascript Files
Developers have used this over the years to make static websites a bit more
interactive and beautiful with things like javascript image carrousels but also XHR
requests and AJAX requests to the backend server to automatically fill in a page.
Javascript can do many things and for this reason it's of interest to us.
We can either analyze a javascript file statically (not running it) and dynamically
(debugging or running it). We will mostly focus on static analysis here.
New endpoints, one time i found a whole list of endpoints in the comments
Hidden parameters
Secrets/passwords
Attack strategy
For our attack stragey we first need to gather all the javascript files from a
website. We have several options to do this automatically for us or we can look in
the HTML source code manually but this will not catch all the JS files as some files
might be called nested (a JS file called from inside another JS file), these would
not show up in our initial manual scan.
Open burp
Click on the "Script" checkbox and make sure it's the only one active under
"Mime type"
Under "Filter by file extension" , click "Show only" and fill in JS in the box
go get github.com/tomnomnom/waybackurls
JS Obfuscation
This is where developers will make it intenionally hard to read the code for
humans but machines don't have any problem reading this code. This is
harder to decipher but with some dilligence it can be done.
https://stackoverflow.com/questions/194397/how-can-i-obfuscate-
protect-javascript
JS Chunking
This is where the developers chops up the JS into little pieces that all
reference eachother. Very annoying to get arround and it's just hard work
puzzling together the code
If we are trying to defeat these mechanisms it might help to set up a replica of you
targets environment and to run the code statically.
Analysing JS files
So now that we have a ton of JS files, we can analyse them manually or we can
run some tools on them. The cool thing is that these tools don't always need to
have the JS files downloaded. It is possible for tools like linkfinder to crawl a
domain for JS files.
We basically have a few tools in our toolbelt but today i want to focus on linkfinder
and secretfinder.
Linkfinder
https://github.com/GerbenJavado/LinkFinder
The results will consist a TON of new links that we can investigate and either dig
deeper into manually or automatically scan them if the target allows it.
Secretfinder
Secretfinder builds on linkfinder but focusses on analyzing the JS for things like
API keys.
https://github.com/GerbenJavado/LinkFinder
The results will consist of a list of sensitive data. The nature of this sensitive data
can vary from API keys to litteral passwords. It's highly situational on how we can
use these and sometimes they don't even have a use at all or are supposed to be
public so judge carefully.