WEBVTT

00:08.380 --> 00:10.020
Thank you, everyone, for coming.

00:10.280 --> 00:12.620
It was said this is going to be big data.

00:12.620 --> 00:14.220
Well, press code, sorry.

00:14.220 --> 00:16.780
Big data approach to understanding the content security policy.

00:18.020 --> 00:21.920
At the end of the talk I would like to share with you eight bypasses.

00:21.920 --> 00:24.420
Six of them I think that they are not so well known.

00:24.460 --> 00:32.100
Two of them I think that maybe would be a bit known, but nevertheless I would like to popularise them because I think they are really interesting.

00:32.520 --> 00:36.720
Okay, starting with that, I would like everyone here to imagine a big red button.

00:37.300 --> 00:49.820
Next to this big red button, there is a note that says, if you push this button, you are going to get rid of every SQL injection in your life for every application that you ever develop.

00:49.820 --> 00:51.200
Would you push that button?

00:51.200 --> 00:51.720
Wouldn't you?

00:51.720 --> 00:52.420
Yes, no?

00:52.780 --> 00:54.060
Me included?

00:54.060 --> 00:54.880
Everyone here?

00:54.880 --> 00:57.120
I guess that would do the same.

00:57.120 --> 01:07.160
But interestingly, we are not doing the same for other impactful vulnerabilities like cross-site scripting, which could have a really high impact on your users.

01:07.680 --> 01:15.820
I will come back to that later and explain why I do not think that we are pushing that button for this kind of data injection vulnerabilities.

01:16.420 --> 01:18.820
But before that, I would like to introduce myself.

01:18.820 --> 01:20.200
I'm Felipe Molina.

01:20.240 --> 01:25.280
I've been working with Orange Cyber Defence SensePost team for four years and something more.

01:25.320 --> 01:28.720
Ten years in the information security industry.

01:29.080 --> 01:31.880
Proud dad, Futurama and Simpson fan, of course.

01:32.060 --> 01:36.020
You can find me on Twitter, if you want to chat with me about Futurama.

01:36.600 --> 01:40.160
Anyway, I have divided this talk in three different blocks.

01:40.160 --> 01:43.480
The first one is going to be the context with a bit of history, brief.

01:43.720 --> 01:46.420
The aim of CSP, the content security policy.

01:46.600 --> 02:01.720
The second part is going to be the big data part, with little stars there, where I explain the architecture that I came up with to scan one million sites of internet to understand the content health security, the content health status of content security policy.

02:02.020 --> 02:06.620
The third block is going to be the bypasses themselves, with a bit of demo, if we have enough time.

02:07.200 --> 02:09.960
Okay, I want to clarify what the dress code name.

02:09.960 --> 02:12.020
It comes from UI redressing attacks.

02:12.020 --> 02:19.500
UI redressing attacks, as you may know, it comes from different kind of injection, JavaScript injection in your pages.

02:19.600 --> 02:28.640
So I was here last year with a web application assessment that I got with one of our clients that called iterative assessment with us.

02:28.640 --> 02:34.960
So I was reading that they have this cross-site scripting, store one, in many places of their web pages.

02:34.960 --> 02:36.960
And I said, okay, let's try it.

02:37.080 --> 02:44.680
I saw that it wasn't possible to exploit them anymore because the client implemented that very strict CSP policy, content security policy.

02:44.680 --> 02:48.560
I said, damn, I'm not going to be able to exploit them again.

02:48.560 --> 02:53.060
They didn't care about the base code of the application, but instead implemented the CSP.

02:53.060 --> 02:54.400
So what happened?

02:54.520 --> 03:00.340
As a hacker, you think that you have to bypass that and resurface the cross-site scripting.

03:00.640 --> 03:08.820
So yeah, what I did is that, found a bypass on CSP policy and resurrected the old cross-site scripting.

03:08.860 --> 03:12.160
The client was a bit sad, I was a bit happy, sorry for that.

03:12.780 --> 03:16.260
But the thing is that it made sense at that point.

03:16.480 --> 03:34.340
I was also able to use this cross-site scripting and bypass to carry out a UI redressing attack to exfiltrate data to some kind of phishing and exfiltrate the data to Google Analytics site, because it was very strict and you could only connect and send that data out to Google Analytics.

03:34.460 --> 03:35.400
So yeah, nice.

03:35.400 --> 03:35.800
Okay.

03:35.800 --> 03:37.300
This is the context.

03:37.540 --> 03:43.320
After that assessment, I thought to myself, okay, this is like, I want to know more about CSP.

03:43.320 --> 03:50.140
So I decided to understand how CSP works for real, how prevalent it is across internet, how well configured.

03:50.140 --> 03:58.720
And ideally, I would like to find new bypasses to keep in my toolbox for future assessment or whatever, if you want to keep them for your bug bounties or whatever.

03:58.860 --> 04:01.660
So let's start with what is CSP?

04:01.660 --> 04:04.440
Define Verbatim from Mozilla.org site.

04:04.440 --> 04:11.640
It's another layer of security to detect and mitigate injection attacks.

04:12.240 --> 04:15.340
More so if it's cross-site scripting.

04:15.340 --> 04:28.680
So now that we know what it is, this was the aim of CSP, to tackle and to prevent cross-site scripting, quick-jacking, data injection, many other that are not listed here.

04:29.240 --> 04:35.620
And this could result in very ugly impacts, such as data theft, site displacement, malware distribution.

04:35.920 --> 04:40.060
Very, very bad things could happen if you don't protect against that.

04:40.060 --> 04:44.040
So it looks like CSP has a really good end.

04:44.220 --> 04:46.380
It's really good to implement in that.

04:46.380 --> 04:53.640
But yet, even knowing how good could be implementing CSP, most of us are not pushing that button.

04:53.640 --> 04:59.180
Only 10% of the sites that I scan were implementing CSP.

04:59.180 --> 05:06.440
This is a chart that indicates how many of those 1 million sites that I scan were implementing CSP headers.

05:06.600 --> 05:10.880
These top 1 million sites were pulled from a database .

05:11.060 --> 05:13.180
Well, the source was Majestic Million.

05:13.180 --> 05:20.420
It's a list of popular sites on the internet constructed by a company called Majestic.

05:20.420 --> 05:22.320
They do SEO, so they know their stuff.

05:22.320 --> 05:25.740
So yeah, I target that 1 million site list.

05:26.160 --> 05:28.380
And it was a concerning outcome.

05:29.180 --> 05:32.960
So we are implementing only 10% of the sites are implementing this.

05:32.960 --> 05:41.840
So this is similar to the situation, to the commercial where we have the 9 out of 10 dentists recommending you to brush your teeth, but completely opposite.

05:41.840 --> 05:43.800
We are just doing completely opposite.

05:43.800 --> 05:48.060
The dentists being us, the security and the developers here, we are not doing the right thing.

05:48.060 --> 05:50.520
We are just not brushing our teeth.

05:50.720 --> 05:54.780
So with that in mind, I was a bit disappointed.

05:54.780 --> 05:57.320
And I thought, OK, but maybe this is a modern technology.

05:57.320 --> 05:58.060
No, it is not.

05:58.060 --> 05:59.800
It has been a long time with us.

05:59.800 --> 06:03.000
It started as an idea with a snake in 2004.

06:03.300 --> 06:12.700
And then in 2009, he published this in hacker.org saying that Mozilla was going to implement a content security policy, which was a good new.

06:12.700 --> 06:15.960
In 2012, it was issued as a standard.

06:15.960 --> 06:28.140
And nowadays, in 2023, we have this developing this working draft policy level 3, which is a bit sad from my perspective, because it has been with us more than 10 years, and we are still not doing it.

06:28.600 --> 06:38.860
How does it look like if you go to a site that has content security policy enabled, you would find this header in the response, content security followed by the policy itself.

06:38.940 --> 06:44.940
The policy would be separated in different directives, each directive separated by a semicolon.

06:45.080 --> 06:50.760
And each directive would have a directive name separated by a space with one, sorry, zero or more values.

06:50.760 --> 06:52.740
So this is the structure that it has.

06:52.780 --> 06:57.880
When you go to a random site of internet, you find this is the answer in the response.

06:57.880 --> 07:05.200
And if we structure this by separating it by semicolons and by spaces later, this is how it would look like.

07:05.380 --> 07:09.460
The first line, for example, well, I must say that this is just three examples.

07:09.500 --> 07:16.580
Content security policy has a lot of other directive names, which can have a lot of other purposes here.

07:16.760 --> 07:18.780
But those are just three examples.

07:19.100 --> 07:24.720
Script source is indicating the agent or the browser what scripts are allowed to be running on your page.

07:24.720 --> 07:31.820
Okay, this first value is telling the agent that scripts that contain these nouns are allowed to be executed.

07:31.940 --> 07:34.660
This or any other randomly generated nouns.

07:34.660 --> 07:36.440
The following one is a strict dynamic.

07:36.440 --> 07:47.640
This is a value that says to the agent that these scripts that are allowed, they can transitively create or add new scripts to the page.

07:47.680 --> 07:56.740
That would be allowed in turn to be executed itself, means that also the self page, the same domain, is allowed to be executing their own scripts.

07:56.740 --> 08:05.640
And the fourth one means that all scripts coming from HTTP source, this is the protocol handle HTTPS, are also allowed to be executed.

08:05.680 --> 08:10.080
Okay, then we have two additional ones that I want to put a bit of more attention in.

08:10.080 --> 08:11.320
Connect source and default source.

08:11.320 --> 08:20.640
Connect source is telling the agent what pages are being allowed to be connected out from the page.

08:20.840 --> 08:32.100
And default source directive is telling the agent what directives or what set of rules to look at in case that there are no other specific rules in the policy.

08:32.100 --> 08:39.780
Okay, now that we know how it looks like, I wanted to see how prevalent was CSP and how well implemented was in Internet.

08:39.780 --> 08:44.980
So I'm not a developer myself, so this is me, the dog, not knowing what how to program.

08:45.220 --> 08:50.480
But I wanted to do something scalable and something that could be finished in my own lifetime.

08:50.480 --> 08:54.700
So I did it, I wanted to do something that was fast.

08:54.700 --> 08:56.660
So to scan this one million sites.

08:56.660 --> 09:08.560
So I did this approach with asynchronous programming paradigm, instead of doing a loop with a fork and requesting every site, one million sites in turn, I would do this asynchronous paradigm.

09:08.560 --> 09:22.960
So yeah, this is a heads up that the project is going to be released in this repo, address code of SensePost, and you could use it yourself to scan your own sites or to use it for your own purposes.

09:23.060 --> 09:26.240
So anyway, this is the solution that I came with.

09:26.240 --> 09:36.110
This is a scanner using the libraries asyncio and aio-http, pmongo for managing the data with the backend database, and pandas to managing the big set of data.

09:36.230 --> 09:47.570
The backend would be mongodatabase, and to tap into this information and retrieve useful data, I would use a dashboard using a program with Dash and Plotly Express for the nice charts.

09:48.030 --> 09:49.630
Okay, the process would be simple.

09:49.670 --> 09:54.530
Collecting the headers with a scanner, two different sources are used, Majestic Million and Cisco Umbrella.

09:54.630 --> 09:58.470
Both of them gave me the same results, 10% of the sites using it.

09:58.570 --> 10:09.710
Then parse the CSP headers from the headers that I retrieved, and assign a country or continent, first by country code TLD, then by IP address geolocation, and then by whois record.

10:10.190 --> 10:15.670
Then I would scan everything there, spot weaknesses and bypasses that you can take for profit.

10:15.690 --> 10:24.590
So you want to say that for your next assessment, or for your next bug bounty program, or whatever you want to use it for.

10:25.170 --> 10:27.670
Okay, this is how the data looks like in the database.

10:27.670 --> 10:33.090
So you start by with an ID, URL, and final URL, because you can be redirected multiple times.

10:33.090 --> 10:43.330
The headers that I gather, the vulnerabilities that I detected, in this case, no CSP was defined, and whois host, IPv4, country, continent, and global rank of the site you are looking at.

10:44.130 --> 10:49.030
Now I'm going to show you a brief view of how the dashboard is.

10:49.030 --> 10:53.670
I'm not going to delve into details of this dashboard, it's just for you to get an idea.

10:53.750 --> 11:01.690
So the top bar that you see there is telling the application how many sites to pull from the database, 35% or etc, etc.

11:01.690 --> 11:08.890
Now you get down there, the pie chart that shows you how many sites are using CSP at that moment.

11:08.890 --> 11:21.050
Then we have this line here, where you can, for example, explore weaknesses, the status, reverse IP to sites, header names, for example, the one that I'm going to show, and CSP directives.

11:21.050 --> 11:26.210
This is a frequency chart showing the most frequent directives that I will show you later.

11:26.210 --> 11:30.150
I'm not going to delve too much into this, this is just to give you an idea of how it looks like.

11:30.390 --> 11:33.350
The results of this chart would be shown here.

11:33.450 --> 11:36.290
So this is the CSP directive sort by frequency.

11:36.290 --> 11:38.470
We can take a look at the first ones there.

11:38.730 --> 11:43.810
The most frequent ones and the most used are upgrading secure requests and frame ancestors.

11:43.810 --> 11:49.890
Upgrading secure requests are used in 46% of the site that define a content security policy.

11:49.890 --> 11:52.910
Frame ancestors are used similarly in the 46%.

11:53.590 --> 11:55.490
Could be better, but it's okay.

11:55.490 --> 11:59.350
Those make sense that they are most used because they are easiest one to implement.

11:59.350 --> 12:06.890
So it looks like when it comes to maintaining an allow list, we get a bit tired and we stop implementing.

12:06.890 --> 12:09.790
So we just decide those are enough for our policy.

12:11.110 --> 12:18.910
For example, defining script sources, there is only 20% of the sites that are defining what scripts can be executed in our page.

12:18.910 --> 12:20.110
The rest are not defining.

12:20.110 --> 12:22.290
So it's not the best configuration.

12:23.490 --> 12:26.730
Then we see that those are the less popular ones.

12:26.730 --> 12:29.850
Base URI, report URI from action manifest.

12:29.850 --> 12:32.430
And I think that this is because we don't know what they are doing.

12:32.430 --> 12:34.510
There is not much popularity of those.

12:34.510 --> 12:36.410
They are not being very widely used.

12:36.410 --> 12:46.510
For example, this one, base URI, it's allowing you to prevent you against cross-site scripting that injects, for example, a base tag on your site.

12:46.510 --> 12:56.310
This base tag is telling to the agent that all the relative paths of scripts are going to be pulled from that base domain.

12:56.310 --> 13:05.770
In case an attacker injects a base tag in your web, all the scripts of your page are going to be pulled from this attacker site, from this attacker domain.

13:05.770 --> 13:09.790
So it's pretty serious, but still we're not using it enough.

13:09.790 --> 13:18.150
Okay , so you can also take a look in this dashboard to the allowed sources for different values.

13:18.150 --> 13:26.830
In this case, as an example, I took script source and the most allowed source for script source were unsafe-inline and unsafe-able.

13:26.830 --> 13:37.910
This makes me a bit sad because 20% of the sites and 21% of the sites are defining scripts source are okay with unsafe-inline and unsafe-able.

13:37.910 --> 13:40.010
It's quite popular, this configuration.

13:40.010 --> 13:49.530
So not only this guy that is the only one that is recommending you to brush your teeth is doing it, but he's only doing it 80% of the time.

13:49.530 --> 13:52.530
The other 20% of the time he's not brushing his teeth.

13:52.930 --> 13:59.450
Anyway, I had this other map there in the dashboard where you can see the current status across the globe.

13:59.450 --> 14:01.510
No, we are doing it equally wrong.

14:02.210 --> 14:10.810
This light green color here means that no more than 10% per country of the sites are implementing CSP.

14:10.810 --> 14:13.410
There are some outliers here in Africa.

14:13.450 --> 14:17.950
I can think that those are because we don't have enough sample data from them.

14:18.110 --> 14:24.010
If we have a couple or three sites there, it gets rigorous, a lot of sites.

14:24.010 --> 14:27.030
But I haven't studied them very deeply.

14:27.090 --> 14:31.890
So then we can take a look to the weaknesses.

14:32.110 --> 14:34.090
This is a way to classify the weaknesses.

14:34.090 --> 14:37.170
For example, this is the the most frequent weakness that I found.

14:37.170 --> 14:39.490
No one is using report2.

14:39.490 --> 14:48.330
This report2 directive indicates the agent where all those errors can be reported.

14:48.330 --> 15:01.330
So you can have if you implement this report2 directive on your site, you would have real-time feedback from all the servers that your clients or your user are having in your site.

15:01.330 --> 15:03.450
No one is also using base URI.

15:03.990 --> 15:05.790
So yeah, it looks like there.

15:05.790 --> 15:08.790
Yeah, it's pretty common not having those.

15:08.790 --> 15:14.850
So remember if you've come across... make a wish if you come across a policy that contains the both of them, okay?

15:16.970 --> 15:22.750
So the least frequent weaknesses are... yeah, and safeinline and safehabit, they are there.

15:22.750 --> 15:26.530
But those are the two ones that get me more worried.

15:26.530 --> 15:34.250
For example, 9% of the sites that define a content security policy, they can be abused by third parties domains.

15:34.610 --> 15:36.910
I will get back to that later.

15:37.730 --> 15:53.610
And lenient scheme, that means that every site... sorry, 7% of the sites are allowing HTTP handles, for example, to execute scripts on your... anything that comes from HTTPS, for example, they are okay in executing as a script.

15:53.610 --> 15:55.470
So yeah, it's a bit worrying as well.

15:56.350 --> 15:59.330
There are other parts in the dashboard that you can take a look at.

15:59.330 --> 16:04.390
There are some tables that lets you to explore some weaknesses of the sites that I gather.

16:04.570 --> 16:09.630
This is, for example, third-party orphan domains, no-csp-defined and safehavel and safeinline.

16:09.630 --> 16:10.490
So many others.

16:10.490 --> 16:12.770
Many vulnerabilities that you can take a look at.

16:12.910 --> 16:17.770
This is how it would look like if you visit this part of the dashboard.

16:17.790 --> 16:20.790
The orphan domains is the one that we are looking at now.

16:20.790 --> 16:22.890
The first column is the affected domain.

16:23.190 --> 16:30.910
And the description column tells you what are the domains that are orphan, that means not registered right now.

16:31.050 --> 16:39.710
So at the first line, for example, you see that the domain bosh-tools-results-page.com is present in the script source directive, but it's not registered.

16:39.710 --> 16:49.350
So it's sitting there for you to register and execute scripts on that page, provided that you find another cross-site scripting in that site.

16:50.110 --> 16:54.270
Now, for example, another example would be to look at the third-party abuse.

16:54.270 --> 16:58.290
In this case, the first column is the affected domain as well.

16:58.450 --> 17:04.190
And the description is telling me, for example, the third-party abuse that I can take advantage of.

17:04.190 --> 17:13.330
The second line, for example, is telling me that the directive-connect-source contains asterisk-at-hotjar.com, so I can use that to exfiltrate data.

17:13.410 --> 17:17.150
So it's at least that you can take advantage of, if you want to say that.

17:17.410 --> 17:18.050
Now what?

17:18.050 --> 17:19.790
What do we do with this information?

17:19.790 --> 17:22.210
It comes the fun part, the exploitation part.

17:23.410 --> 17:25.930
I wanted to find new bypasses.

17:26.350 --> 17:31.310
I found, just ahead, I wanted to find new vectors.

17:31.310 --> 17:42.730
I found a lot of information on the internet about how to bypass CSP using JSON with padding and AngularJS outdated libraries of AngularJS.

17:43.250 --> 17:49.350
I wanted to find different vectors, so I just forgot about them for a moment and found different ways.

17:49.730 --> 17:51.550
I came up with this list.

17:51.550 --> 17:54.530
That does not mean that this is the only list that exists out there.

17:54.530 --> 17:55.870
Probably there are others.

17:56.390 --> 17:59.690
Due to time restriction, I will only focus on this first one.

18:00.110 --> 18:07.690
I will explain a bit more the following three ones, and this last will just be mentioned by passing.

18:08.070 --> 18:14.330
But if you want to know more information about them, take a look to our blog post in sensepost.com.

18:14.750 --> 18:16.910
Details will be published soon.

18:17.810 --> 18:21.330
So yeah, to demonstrate the bypasses, I created a lab.

18:21.330 --> 18:35.070
This lab contains a private part where you can see the secret ingredient for the KFC recipe, and there is also a part here where you can change your own password and your security question, etc.

18:35.070 --> 18:38.350
So this is the lab where I want to test everything.

18:38.810 --> 18:49.350
The objectives for me to demonstrate the CSP bypasses would be first one to exfiltrate the security question and answer, second one to exfiltrate the secret ingredient, and third one to change the user password, victim password.

18:49.990 --> 18:52.970
For that, I created two different vulnerabilities on the lab.

18:52.970 --> 18:59.710
This vulnerability, just it's easier I guess to understand, gets a message parameter, no?

18:59.710 --> 19:05.170
And directly introduce the string into this JavaScript code down there.

19:05.350 --> 19:16.250
So you would get, if you visit the following page, secret.php, etc., msg, this is an error, and semicolon, you get the following JavaScript generated, which of course is a nice cross-site scripting.

19:16.250 --> 19:34.290
And the second vulnerability would be something similar, but in this case what we have is a loud script with a nonce, etc., and gets the parameter source, okay, from URL params, and the source gets introduced as the source of a script.

19:34.290 --> 19:37.410
This script is going to be appended in the head of the document, okay?

19:37.410 --> 19:42.450
So those are the two vulnerabilities that I will be using to demonstrate the CSP bypasses.

19:42.490 --> 19:50.550
So if you visit this source, you would get the script pointing to this code, script execution.js.

19:50.870 --> 19:52.090
So, showtime.

19:52.470 --> 19:57.130
The first one with Hotjar that I mentioned, I found 2050 sites in MyDB.

19:57.210 --> 20:01.310
This is a 2% of the sites that I have that are implementing CSP.

20:01.310 --> 20:04.630
It's not big, but it's not small, relatively, okay?

20:04.630 --> 20:14.530
Symptoms would be, oops, sorry, symptoms would be finding asterisk hotjar.com and askhotjar.io in the content security policy, and can be used to exfiltrate data.

20:14.790 --> 20:17.530
This is how it would look like when you go to the site.

20:17.690 --> 20:26.490
This is a content security policy, allowing default askhotjar.io, but for exfiltration purposes, you can use it as well for connect source, okay?

20:26.490 --> 20:27.770
This is the payload.

20:27.770 --> 20:30.350
Now, don't pay much attention to the mumbo-jumbo.

20:30.350 --> 20:36.450
It's just focus on those part, security question and answer, getting exfiltrated to the attacker.local domain.

20:36.450 --> 20:48.230
But, of course, due to the content policy that has been implemented, if we try this, to fetch this, and send out this information, you would get the following error, thanks to the CSP, which is good, no?

20:48.230 --> 20:52.610
But you, as an attacker, you know that they are low in Hotjar here, okay?

20:52.610 --> 20:59.310
So now what we do, as an attacker, you open yourself an account in Hotjar, you create a poll, no?

20:59.310 --> 21:12.970
You insert that poll in your own website, you sniff this traffic, you sniff the traffic of answering that poll in your own website, and then you mimic this answer, but in this case, from the victim website, or from the victim browser.

21:13.130 --> 21:23.090
So, if we take a look in BARP, for example, or your proxy of choice, we can see that the site, this is what you will see when you answer the poll in Hotjar.

21:23.190 --> 21:27.390
askhotjar.io is the host where we are exfiltrating this information to.

21:27.390 --> 21:34.810
This is a response content parameter, which contains, within the comment, we get the answer of the poll, no?

21:34.810 --> 21:39.290
So we are going to take advantage of it by introducing that in our previous proof of concept.

21:39.290 --> 21:51.270
We get now, again, the security question and answers exfiltrated from the profile of the user, we introduce them in the comment, and then fetch, post this information to askhotjar.io, etc.

21:51.270 --> 21:55.390
So we take all this JavaScript and encode it in Base64.

21:55.390 --> 21:59.230
Sorry for the red color, it doesn't look very bright here.

21:59.690 --> 22:08.410
But yeah, and you use it, and you introduce it as in the cross-site description that we saw in the first vulnerability here, append an extra message.

22:08.970 --> 22:16.470
By the way, this is a callout that you would need if you are going to use this eval, you need unsafe eval also allowed in the script source.

22:16.870 --> 22:24.830
But anyway, you shorten this to look less suspicious and deliver this script, sorry, this link to the victim, no?

22:24.830 --> 22:30.950
The victim clicks, and when the victim clicks, you get the following on your Hotjar attacker's account.

22:31.010 --> 22:33.230
I'm going to show you a video to demonstrate that.

22:33.230 --> 22:36.510
At the left side of the screen is the page.

22:36.890 --> 22:38.230
The victim is now logging in.

22:38.230 --> 22:40.510
On the right side is the attacker's perspective.

22:40.510 --> 22:42.350
It's a Hotjar account.

22:43.590 --> 22:45.210
The victim is logging in right now.

22:45.210 --> 22:50.370
There is the secret ingredient there and the profile with your password and the security answer and whatnot.

22:50.570 --> 22:55.370
Okay, so now the victim is going to click on the link, the malicious link.

22:55.370 --> 23:00.030
It gets redirected now to the cross-site scripting.

23:00.030 --> 23:01.790
We get that it was a success.

23:01.790 --> 23:11.630
And as attacker, we update our dashboard and get the following exfiltrated from the page, okay?

23:12.150 --> 23:15.710
The favorite word is the word.

23:15.790 --> 23:19.510
Anyway, so Facebook.

23:21.930 --> 23:23.230
Thank you.

23:24.890 --> 23:36.110
I found this was a bit more popular in this case, 2,750 sites in my database, just 2% of the site, 2.6% of the site implementing CSP.

23:36.110 --> 23:41.510
They're allowing facebook.com or facebook.net to be used to exfiltrate data, okay?

23:41.510 --> 23:49.750
So you can, as an attacker, go and create yourself a developer account in Facebook and exfiltrate data there.

23:49.750 --> 23:50.910
I will show that later.

23:50.910 --> 23:53.950
So this is the content security policy that you would face.

23:54.010 --> 23:57.150
This or this other configuration to exfiltrate data, okay?

23:57.650 --> 23:59.310
This is going to be shorter.

23:59.310 --> 24:03.770
In this case, we are taking advantage of the Facebook framework, the tracking pixel.

24:04.050 --> 24:10.210
The first line is just initiating the tracking pixel of Facebook to point to the attacker account ID.

24:10.250 --> 24:14.730
And the second line is just creating a fake event, a fake custom event.

24:14.730 --> 24:20.090
This fake custom event is going to exfiltrate within the data, the secret ingredient in this case, okay?

24:20.430 --> 24:28.970
So this is what you would look like, what you would see as an attacker if you get your victim clicking on that link, okay?

24:28.970 --> 24:34.190
The secret ingredient has been exfiltrated to your Facebook account, to your Facebook developer account dashboard.

24:34.690 --> 24:35.330
Okay.

24:35.330 --> 24:37.690
Demo three is with jsdeliver.

24:37.690 --> 24:43.930
I found that this was a bit more known around, but nevertheless, I think it's interesting to know.

24:43.990 --> 24:54.270
Found 1,550 sites in my database, symptoms, cdnjsdeliver allowed, and asterisk jsdeliver allowed.

24:54.270 --> 24:58.310
Can be used in this case to execute code instead of exfiltrating code, okay?

24:58.590 --> 25:00.230
That one is straightforward.

25:00.230 --> 25:05.270
You just host your code in your account, GitHub account or npm, okay?

25:05.390 --> 25:10.970
And politely ask jsdeliver cdn to cache that code, no?

25:10.970 --> 25:13.230
By using a specific URL.

25:13.230 --> 25:22.430
This URL is telling jsdeliver to go to GitHub, to the username felmoltor, to the repo name bunchofjs, and to the path exec.

25:22.430 --> 25:27.350
And it would politely get all your code and get it cached there.

25:27.350 --> 25:33.390
So now you only need to exploit the second vulnerability, the one with the source parameter here.

25:33.390 --> 25:37.590
You just need to send or deliver this script, sorry, this link to the victim.

25:37.590 --> 25:42.590
The victim clicks and gets the password changing and security question, et cetera, et cetera.

25:43.670 --> 25:46.770
Now, this is a bit more elaborate, but interesting as well.

25:46.970 --> 25:49.970
Not many sites, but relatively high.

25:50.210 --> 25:55.290
550 sites in my DB, amazonaws.com, asterisk, okay?

25:55.290 --> 25:59.310
Can be used to exfiltrate, but I'm pretty positive that you can use it to execute code as well.

25:59.610 --> 26:02.930
So you need to define two different components here.

26:03.370 --> 26:06.770
A lambda function and an API gateway.

26:07.350 --> 26:09.670
This is the content of the lambda function.

26:09.670 --> 26:10.550
It is easy.

26:10.550 --> 26:24.730
You just get the data parameter, decode it, and print it in the console, which this console logs is going to be visible for you as an attacker in your CloudWatch logs, okay?

26:24.910 --> 26:30.430
And this is the script that you need to execute in the victim side, the code that you need to execute in the victim side.

26:30.890 --> 26:45.330
You just have your API gateway hosted here as a subdomain of amazonaws.com, and the data contains just the base64 encoded data that you want to exfiltrate, okay?

26:45.330 --> 26:53.050
And then just append this script, and you would get the following on your CloudWatch logs, okay?

26:53.510 --> 26:55.570
The secret ingredient.

26:55.570 --> 26:58.550
Okay, now this is just passing by.

26:58.550 --> 27:05.670
I found other four different vulnerabilities, sorry, CSP bypasses with Amazon CloudFront, Azure Web Applications.

27:05.670 --> 27:08.170
Similarly, 100 sites, 100 sites.

27:08.170 --> 27:13.830
First one would be the content security policy allowing asterisk cloudfront.com.

27:13.870 --> 27:18.450
The following one would be azurewebsites.net and azurestaticapps.net.

27:18.450 --> 27:22.370
Both can be used to execute and exfiltrate data, and the proof of concept would be similar.

27:22.370 --> 27:26.230
To exploit the second vulnerability, you just send to the victim.

27:26.230 --> 27:32.530
You get the information or the script executed on the victim side.

27:32.970 --> 27:38.670
Heroku, Firebase, those are not very popular, but you never know when they're going to be useful for your next bug bounty.

27:38.790 --> 27:43.250
So asteriskherokuapps.com and firebaseapp.com.

27:43.290 --> 27:50.370
Similarly, you open your account in each of those and host your code, and it could be executed by the victim.

27:50.370 --> 27:52.210
Anyway, not going to delve too much.

27:52.210 --> 27:58.390
So now that we know how many ways they can bypass this CSP, what do we do as defenders?

27:59.330 --> 28:04.790
First of all, push the big red button and encourage other people to do so, please.

28:05.110 --> 28:08.930
Do not be the dentists that are not brushing their teeth.

28:09.110 --> 28:16.470
So if you're doing that, if you're implementing CSP, do that in conjunction with self-resource integrity.

28:16.470 --> 28:28.230
So if one of your third parties get popped and one of the JavaScripts get changed, please, if you're using self-resource integrity, you won't get that code executed on your website.

28:28.230 --> 28:30.430
I know some personal stories of that.

28:30.850 --> 28:35.330
So then if you're using your CSP, don't use anything that says unsafe.

28:35.330 --> 28:39.490
Unsafe for the ones that do not know English is very bad word, okay?

28:39.490 --> 28:43.050
And use instead nonces and hashes.

28:44.570 --> 28:46.790
You can use a strict dynamic, okay?

28:46.790 --> 28:53.410
You can use a strict dynamic to reduce the operational load transitive property that I mentioned before, but be aware of the risk.

28:53.410 --> 28:56.230
That means that you have to really trust those other third parties.

28:57.090 --> 29:03.310
Then reduce the number of third parties on your content security policy, reduce it to a minimum.

29:03.310 --> 29:06.770
I'm not saying not use them, but reduce them to a minimum.

29:06.770 --> 29:18.190
And if possible, instead of opening pokes and poking holes on your CSP, to allow third parties, just host the libraries on your own domain, so you don't have to poke a hole in your CSP.

29:18.350 --> 29:23.750
Do not include, of course, if you have to do that, do not include third party domains with wildcards, such as this one.

29:23.750 --> 29:31.470
You're allowing everyone that has an Amazon AWS domain.com API gateway to execute or retrieve code from your site, no?

29:31.530 --> 29:33.930
Then use report two and report sample.

29:33.970 --> 29:42.410
This is going to be noisy, but it's giving you superpowers and you are going to be able to see what is happening in real time with your users, no?

29:42.410 --> 29:46.450
What code is being executed on your client's or user's side.

29:46.470 --> 29:51.230
And then finally, consider available commercial solutions to monitor client-side JavaScript.

29:51.230 --> 30:01.870
These solutions, you can search for them, they are going to tell you, they're going to highlight and alert, tell you, hey, this script has been executed in one of your user browser and it's not useful.

30:01.890 --> 30:03.850
So take a look to it.

30:04.430 --> 30:06.390
With all of that, thank you, everyone.

30:06.390 --> 30:08.370
Thank you for all my colleagues.

30:17.780 --> 30:28.800
You didn't let me thanks to my colleagues in SensePost and Orange Cyber Defense, especially Simon and Leon and John and everyone else and you guys for being here.

30:28.800 --> 30:29.800
Thank you, everyone.

