Jsluice
Jsluice
Presented by: Tom Hudson, Senior Security Engineer, Bishop Fox | Date: 2023-06-24
1
JSLUICE
Hello, BSides :)
✦ I’m Tom(NomNom)
✦ It’s been a while! Hello! 👋
✦ I make open-source tools (gron, anew, meg, fff, unfurl, gf, waybackurls, httprobe, assetfinder, qsrepla…
✦ I like questions, so have ‘em ready!
✦ I do security tooling R&D stuff at Bishop Fox
⎻ That means this slide-deck is branded and in light-mode
⎻ …and also lacks legally-questionable use of watermarked stock photography
The retu
rn of
light-mo
de
sheepy (:
A guestb
ook is lik
commen ea
ts sectio
for your n, but
whole sit
e
felt kind of
Honestly,
not hear
magical to
"click"
the reload
a page
every time
changed
✦ One way to deal with JavaScript is to use a (headless) browser – a sort of dynamic analysis
⎻ It’s kinda slow and resource intensive
⎻ You only find out about things that are actually executed
✦ To do static analysis you could use regular expressions
⎻ Something something, then you have two problems…
fetch('/api/v2/guestbook', { 'fetch' is a
mode
alternative rn
to
method: "POST", XMLHttpR
equest
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({msg: "..."})
})
© Bishop Fox. All rights reserved worldwide. 5
JSLUICE
Irregularly Regular
one from
I stole this
, but it's a
somewhere finding
for
real regex
(?:"|'|\s)(((https?://[A-Za-z0-9_\-\.]+(:\d{1,5})?)+([\.]{1,2})?/[A-Za-z0-9/\-_\.\\%]+([\?|#][^"']+)?)|((\.{1,2}/)?[a-
vaScript!
URLs in Ja
zA-Z0-9\-_/\\%]+\.(aspx?|js(on|p)?|html|php5?|html|action|do)([\?|#][^"']+)?)|((\.{0,2}/)[a-zA-Z0-9\-_/\\%]+(/|\\)[a-
zA-Z0-9\-_]{3,}([\?|#][^"|']+)?)|((\.{0,2})[a-zA-Z0-9\-_/\\%]{3,}/))(?:"|'|\s)
fetch('/api/v2/guestbook', {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({msg: "..."})
})
Sitting In A Tree: P, A, R, S, I, N, G
✦ Raw JavaScript source code is difficult to understand for humans, doubly so for programs
✦ Tree-sitter parses JavaScript (and dozens of other languages) into syntax trees
⎻ It's meant for tasks like syntax highlighting so it's tolerant of minor errors <3
✦ jsluice can show you the syntax tree for any JavaScript file
$ cat hello.js
console.log("Hello, world!")
😍
{
"url": "/api/v2/guestbook",
jslui
JSON ce outputs "method": "POST",
Lin
want t es; you mig
o pipe h "headers": {
it to jq t
:)
"Content-Type": "application/json"
},
"type": "fetch"
}
© Bishop Fox. All rights reserved worldwide. 9
JSLUICE
XMLHttpRequest is tricksy
{
function callAPI(method, callback){
"url": "/api/EXPR?format=json",
var xhr = new XMLHttpRequest();
"queryParams": ["format"],
xhr.onreadystatechange = callback;
"method": "GET",
xhr.open('GET', '/api/' + method + '?format=json');
"headers": {
xhr.setRequestHeader('Accept', 'application/json');
"Accept": "application/json",
"X-Env": "staging"
if (window.env != 'prod'){
},
xhr.setRequestHeader('X-Env', 'staging')
"type": "XMLHttpRequest.open"
}
}
xhr.send();
} 'EXPR' is
the default
placeholde
r, but you
can chang
e it with
--placeho
lder
Secret Sauce
✦ Modern web apps talk to lots of APIs, run in The Cloud™, and need secrets for stuff like that
✦ Sometimes those secrets end up in JavaScript files
✦ You can find secrets with jsluice too!
🤫
"awsKey": "AKIAIOSFODNN7EXAMPLE",
"awsSecret": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"bucket": "examplebucket",
"server": "someserver.example.com"
} Look at tha
t sweet co
} that was e ntext
xtracte d!
© Bishop Fox. All rights reserved worldwide. 11
JSLUICE
Custom Secrets
✦ There are built-in matchers for AWS, GCP, GitHub, and a few other types of secrets
✦ The internet is awash with different secrets types, and your target might use an obscure vendor
✦ You can provide your own patterns in a JSON file :)
Queries
✦ Tree-sitter is super cool, it has its own query language for querying syntax trees
✦ The query mode lets you run queries, and massages the results into valid JSON
✦ Use the tree mode we saw earlier to help you write queries
⎻ Also the docs: https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax
...
✦ The command-line tool is nice, and you can use it for automation in shell scripts
✦ But if you want to get serious, use the Go package…
analyzer := jsluice.NewAnalyzer(sourceCode)
analyzer.AddURLMatcher(
jsluice.URLMatcher{"string", func(n *jsluice.Node) *jsluice.URL {
val := n.DecodedString()
if !strings.HasPrefix(val, "mailto:") {
custom
n make return nil
You ca using the full
rs
matche Tree-sitter :) }
r of
powe
$ find . -type f -exec file {} \; | # Find files and check what type they are
grep 'HTML document' | # Take just the HTML files
cut -d: -f1 | # Remove everything after the filename
while read htmlfile; do # Loop over each filename
# Use htmlq to extract inline JavaScript
jsluice secrets <(htmlq -f $htmlfile script --text)
done ative get n
e jslu ice will s soon :)
Mayb ML file
t for HT
suppor
Presented by: Tom Hudson, Senior Security Engineer, Bishop Fox | Date: 2023-06-24
17