[00:08.380 --> 00:13.300] Thank you, everyone, for coming. It was said this is going to be big data. Well, press [00:13.300 --> 00:18.800] code, sorry. Big data approach to understanding the content security policy. At the end of [00:18.800 --> 00:23.260] the talk I would like to share with you eight bypasses. Six of them I think that they are [00:23.260 --> 00:28.060] not so well known. Two of them I think that maybe would be a bit known, but nevertheless [00:28.060 --> 00:32.100] I would like to popularise them because I think they are really interesting. [00:32.520 --> 00:37.820] Okay, starting with that, I would like everyone here to imagine a big red button. Next to [00:37.820 --> 00:43.980] this big red button, there is a note that says, if you push this button, you are going [00:43.980 --> 00:49.820] to get rid of every SQL injection in your life for every application that you ever develop. [00:49.820 --> 00:55.260] Would you push that button? Wouldn't you? Yes, no? Me included? Everyone here? I guess [00:55.260 --> 01:01.200] that would do the same. But interestingly, we are not doing the same for other impactful [01:01.200 --> 01:06.480] vulnerabilities like cross-site scripting, which could have a really high impact on your [01:06.480 --> 01:12.380] users. I will come back to that later and explain why I do not think that we are pushing [01:12.380 --> 01:15.820] that button for this kind of data injection vulnerabilities. [01:16.420 --> 01:20.900] But before that, I would like to introduce myself. I'm Felipe Molina. I've been working [01:20.900 --> 01:26.020] with Orange Cyber Defence SensePost team for four years and something more. Ten years in [01:26.020 --> 01:32.520] the information security industry. Proud dad, Futurama and Simpson fan, of course. You can [01:32.520 --> 01:38.340] find me on Twitter, if you want to chat with me about Futurama. Anyway, I have divided [01:38.340 --> 01:42.080] this talk in three different blocks. The first one is going to be the context with a bit [01:42.080 --> 01:47.580] of history, brief. The aim of CSP, the content security policy. The second part is going [01:47.580 --> 01:52.240] to be the big data part, with little stars there, where I explain the architecture that [01:52.240 --> 01:57.320] I came up with to scan one million sites of internet to understand the content health [01:57.320 --> 02:03.380] security, the content health status of content security policy. The third block is going [02:03.380 --> 02:06.620] to be the bypasses themselves, with a bit of demo, if we have enough time. [02:07.200 --> 02:12.020] Okay, I want to clarify what the dress code name. It comes from UI redressing attacks. [02:12.020 --> 02:17.600] UI redressing attacks, as you may know, it comes from different kind of injection, JavaScript [02:17.600 --> 02:23.120] injection in your pages. So I was here last year with a web application assessment that [02:23.120 --> 02:29.340] I got with one of our clients that called iterative assessment with us. So I was reading [02:29.340 --> 02:34.960] that they have this cross-site scripting, store one, in many places of their web pages. [02:34.960 --> 02:39.620] And I said, okay, let's try it. I saw that it wasn't possible to exploit them anymore [02:39.620 --> 02:45.120] because the client implemented that very strict CSP policy, content security policy. I said, [02:45.120 --> 02:49.840] damn, I'm not going to be able to exploit them again. They didn't care about the base [02:49.840 --> 02:56.140] code of the application, but instead implemented the CSP. So what happened? As a hacker, you [02:56.140 --> 03:01.940] think that you have to bypass that and resurface the cross-site scripting. So yeah, what I [03:01.940 --> 03:08.820] did is that, found a bypass on CSP policy and resurrected the old cross-site scripting. [03:08.860 --> 03:15.600] The client was a bit sad, I was a bit happy, sorry for that. But the thing is that it made [03:15.600 --> 03:21.460] sense at that point. I was also able to use this cross-site scripting and bypass to carry [03:21.460 --> 03:26.420] out a UI redressing attack to exfiltrate data to some kind of phishing and exfiltrate the [03:26.420 --> 03:30.700] data to Google Analytics site, because it was very strict and you could only connect [03:30.700 --> 03:37.300] and send that data out to Google Analytics. So yeah, nice. Okay. This is the context. [03:37.540 --> 03:42.640] After that assessment, I thought to myself, okay, this is like, I want to know more about [03:42.640 --> 03:48.220] CSP. So I decided to understand how CSP works for real, how prevalent it is across [03:48.220 --> 03:53.580] internet, how well configured. And ideally, I would like to find new bypasses to keep in my [03:53.580 --> 03:57.940] toolbox for future assessment or whatever, if you want to keep them for your bug bounties or [03:57.940 --> 04:05.300] whatever. So let's start with what is CSP? Define Verbatim from Mozilla.org site. It's another [04:05.300 --> 04:14.540] layer of security to detect and mitigate injection attacks. More so if it's cross-site [04:14.540 --> 04:23.340] scripting. So now that we know what it is, this was the aim of CSP, to tackle and to prevent [04:23.340 --> 04:28.680] cross-site scripting, quick-jacking, data injection, many other that are not listed here. [04:29.240 --> 04:34.740] And this could result in very ugly impacts, such as data theft, site displacement, malware [04:34.740 --> 04:40.600] distribution. Very, very bad things could happen if you don't protect against that. So it looks [04:40.600 --> 04:48.460] like CSP has a really good end. It's really good to implement in that. But yet, even knowing how [04:48.460 --> 04:55.120] good could be implementing CSP, most of us are not pushing that button. Only 10% of the sites [04:55.120 --> 05:03.080] that I scan were implementing CSP. This is a chart that indicates how many of those 1 million [05:03.080 --> 05:10.360] sites that I scan were implementing CSP headers. These top 1 million sites were pulled from a [05:10.360 --> 05:17.560] database. Well, the source was Majestic Million. It's a list of popular sites on the internet [05:18.060 --> 05:23.520] constructed by a company called Majestic. They do SEO, so they know their stuff. So yeah, I target [05:23.520 --> 05:32.020] that 1 million site list. And it was a concerning outcome. So we are implementing only 10% of the [05:32.020 --> 05:36.140] sites are implementing this. So this is similar to the situation, to the commercial where we have [05:36.140 --> 05:42.740] the 9 out of 10 dentists recommending you to brush your teeth, but completely opposite. We are just [05:42.740 --> 05:47.100] doing completely opposite. The dentists being us, the security and the developers here, we are not [05:47.100 --> 05:54.080] doing the right thing. We are just not brushing our teeth. So with that in mind, I was a bit [05:54.080 --> 05:58.540] disappointed. And I thought, OK, but maybe this is a modern technology. No, it is not. It has been [05:58.540 --> 06:05.360] a long time with us. It started as an idea with a snake in 2004. And then in 2009, he published [06:05.360 --> 06:11.720] this in hacker.org saying that Mozilla was going to implement a content security policy, which was [06:11.840 --> 06:19.320] a good new. In 2012, it was issued as a standard. And nowadays, in 2023, we have this developing [06:19.320 --> 06:25.260] this working draft policy level 3, which is a bit sad from my perspective, because it has been [06:25.260 --> 06:31.000] with us more than 10 years, and we are still not doing it. How does it look like if you go to a [06:31.000 --> 06:37.080] site that has content security policy enabled, you would find this header in the response, content [06:37.080 --> 06:41.760] security followed by the policy itself. The policy would be separated in different directives, each [06:41.760 --> 06:47.620] directive separated by a semicolon. And each directive would have a directive name separated [06:47.740 --> 06:53.480] by a space with one, sorry, zero or more values. So this is the structure that it has. When you go [06:53.480 --> 06:59.540] to a random site of internet, you find this is the answer in the response. And if we structure this [06:59.540 --> 07:06.160] by separating it by semicolons and by spaces later, this is how it would look like. The first line, [07:06.160 --> 07:10.900] for example, well, I must say that this is just three examples. Content security policy has a lot [07:10.900 --> 07:17.980] of other directive names, which can have a lot of other purposes here. But those are just three [07:17.980 --> 07:23.380] examples. Script source is indicating the agent or the browser what scripts are allowed to be [07:23.380 --> 07:29.440] running on your page. Okay, this first value is telling the agent that scripts that contain these [07:29.440 --> 07:35.960] nouns are allowed to be executed. This or any other randomly generated nouns. The following one is a [07:35.960 --> 07:41.660] strict dynamic. This is a value that says to the agent that these scripts that are allowed, they [07:41.660 --> 07:49.700] can transitively create or add new scripts to the page. That would be allowed in turn to be [07:49.700 --> 07:55.820] executed itself, means that also the self page, the same domain, is allowed to be executing their own [07:55.820 --> 08:02.420] scripts. And the fourth one means that all scripts coming from HTTP source, this is the protocol [08:02.420 --> 08:07.860] handle HTTPS, are also allowed to be executed. Okay, then we have two additional ones that I want [08:07.860 --> 08:12.640] to put a bit of more attention in. Connect source and default source. Connect source is telling the [08:12.640 --> 08:22.960] agent what pages are being allowed to be connected out from the page. And default source directive is [08:22.960 --> 08:29.460] telling the agent what directives or what set of rules to look at in case that there are no other [08:29.460 --> 08:36.040] specific rules in the policy. Okay, now that we know how it looks like, I wanted to see how [08:36.040 --> 08:41.860] prevalent was CSP and how well implemented was in Internet. So I'm not a developer myself, so this is [08:41.860 --> 08:47.540] me, the dog, not knowing what how to program. But I wanted to do something scalable and something [08:47.540 --> 08:55.340] that could be finished in my own lifetime. So I did it, I wanted to do something that was fast. So to [08:55.340 --> 09:01.300] scan this one million sites. So I did this approach with asynchronous programming paradigm, instead of [09:01.300 --> 09:07.400] doing a loop with a fork and requesting every site, one million sites in turn, I would do this [09:07.400 --> 09:13.320] asynchronous paradigm. So yeah, this is a heads up that the project is going to be released in this [09:13.320 --> 09:19.500] repo, address code of SensePost, and you could use it yourself to scan your own sites or to [09:21.280 --> 09:26.730] use it for your own purposes. So anyway, this is the solution that I came with. This is a [09:26.730 --> 09:32.770] scanner using the libraries asyncio and aio-http, pmongo for managing the data with the backend [09:32.770 --> 09:39.050] database, and pandas to managing the big set of data. The backend would be mongodatabase, and to [09:39.050 --> 09:44.770] tap into this information and retrieve useful data, I would use a dashboard using a program with [09:44.770 --> 09:50.270] Dash and Plotly Express for the nice charts. Okay, the process would be simple. Collecting the [09:50.270 --> 09:55.190] headers with a scanner, two different sources are used, Majestic Million and Cisco Umbrella. Both of [09:55.190 --> 10:00.710] them gave me the same results, 10% of the sites using it. Then parse the CSP headers from the [10:00.710 --> 10:07.050] headers that I retrieved, and assign a country or continent, first by country code TLD, then by IP [10:07.050 --> 10:12.570] address geolocation, and then by whois record. Then I would scan everything there, spot [10:12.570 --> 10:19.790] weaknesses and bypasses that you can take for profit. So you want to say that for your next [10:19.790 --> 10:25.890] assessment, or for your next bug bounty program, or whatever you want to use it for. Okay, this is how [10:25.890 --> 10:31.290] the data looks like in the database. So you start by with an ID, URL, and final URL, because you can [10:31.290 --> 10:36.110] be redirected multiple times. The headers that I gather, the vulnerabilities that I detected, in [10:36.110 --> 10:41.730] this case, no CSP was defined, and whois host, IPv4, country, continent, and global rank of the [10:41.730 --> 10:49.330] site you are looking at. Now I'm going to show you a brief view of how the dashboard is. I'm not [10:49.330 --> 10:54.970] going to delve into details of this dashboard, it's just for you to get an idea. So the top bar [10:54.970 --> 11:00.950] that you see there is telling the application how many sites to pull from the database, 35% or [11:00.950 --> 11:08.190] etc, etc. Now you get down there, the pie chart that shows you how many sites are using CSP at [11:08.190 --> 11:13.510] that moment. Then we have this line here, where you can, for example, explore weaknesses, the [11:13.510 --> 11:20.590] status, reverse IP to sites, header names, for example, the one that I'm going to show, and CSP [11:20.590 --> 11:25.810] directives. This is a frequency chart showing the most frequent directives that I will show you [11:25.810 --> 11:29.590] later. I'm not going to delve too much into this, this is just to give you an idea of how it looks [11:29.590 --> 11:35.590] like. The results of this chart would be shown here. So this is the CSP directive sort by [11:35.590 --> 11:40.910] frequency. We can take a look at the first ones there. The most frequent ones and the most used [11:40.910 --> 11:47.210] are upgrading secure requests and frame ancestors. Upgrading secure requests are used in 46% of the [11:47.210 --> 11:52.910] site that define a content security policy. Frame ancestors are used similarly in the 46%. [11:53.590 --> 11:58.470] Could be better, but it's okay. Those make sense that they are most used because they are easiest [11:58.470 --> 12:05.650] one to implement. So it looks like when it comes to maintaining an allow list, we get a bit tired [12:05.650 --> 12:09.790] and we stop implementing. So we just decide those are enough for our policy. [12:11.110 --> 12:15.910] For example, defining script sources, there is only 20% of the sites that are defining [12:16.450 --> 12:20.970] what scripts can be executed in our page. The rest are not defining. So it's not the best [12:20.970 --> 12:28.990] configuration. Then we see that those are the less popular ones. Base URI, report URI from [12:28.990 --> 12:32.850] action manifest. And I think that this is because we don't know what they are doing. There is not [12:32.850 --> 12:38.030] much popularity of those. They are not being very widely used. For example, this one, [12:38.030 --> 12:43.710] base URI, it's allowing you to prevent you against cross-site scripting that injects, [12:43.710 --> 12:50.240] for example, a base tag on your site. This base tag is telling to the agent that all the [12:52.010 --> 12:57.530] relative paths of scripts are going to be pulled from that base domain. In case an attacker injects [12:57.650 --> 13:03.750] a base tag in your web, all the scripts of your page are going to be pulled from this attacker [13:03.750 --> 13:09.790] site, from this attacker domain. So it's pretty serious, but still we're not using it enough. [13:09.790 --> 13:16.470] Okay, so you can also take a look in this dashboard to the allowed sources for different [13:17.450 --> 13:24.510] values. In this case, as an example, I took script source and the most allowed source for [13:24.510 --> 13:30.910] script source were unsafe-inline and unsafe-able. This makes me a bit sad because 20% of the sites [13:30.910 --> 13:37.910] and 21% of the sites are defining scripts source are okay with unsafe-inline and unsafe-able. [13:37.910 --> 13:43.730] It's quite popular, this configuration. So not only this guy that is the only one that is [13:43.730 --> 13:50.010] recommending you to brush your teeth is doing it, but he's only doing it 80% of the time. The other [13:50.010 --> 13:56.090] 20% of the time he's not brushing his teeth. Anyway, I had this other map there in the dashboard [13:56.090 --> 14:01.510] where you can see the current status across the globe. No, we are doing it equally wrong. [14:02.210 --> 14:08.970] This light green color here means that no more than 10% per country of the sites are [14:09.710 --> 14:15.390] implementing CSP. There are some outliers here in Africa. I can think that those are because [14:15.390 --> 14:22.050] we don't have enough sample data from them. If we have a couple or three sites there, it gets [14:22.050 --> 14:30.930] rigorous, a lot of sites. But I haven't studied them very deeply. So then we can take a look to [14:30.930 --> 14:35.670] the weaknesses. This is a way to classify the weaknesses. For example, this is the the most [14:35.670 --> 14:43.350] frequent weakness that I found. No one is using report2. This report2 directive indicates the [14:43.350 --> 14:50.790] agent where all those errors can be reported. So you can have if you implement this report2 [14:50.790 --> 14:57.350] directive on your site, you would have real-time feedback from all the servers that [14:57.350 --> 15:03.450] your clients or your user are having in your site. No one is also using base URI. [15:03.990 --> 15:10.250] So yeah, it looks like there. Yeah, it's pretty common not having those. So remember if you've [15:10.250 --> 15:14.850] 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:28.070] But those are the two ones that get me more worried. For example, 9% of the sites that [15:28.070 --> 15:35.490] define a content security policy, they can be abused by third parties domains. I will get [15:35.490 --> 15:42.070] back to that later. And lenient scheme, that means that every site... sorry, 7% of the sites [15:42.070 --> 15:49.870] are allowing HTTP handles, for example, to execute scripts on your... anything that comes from HTTPS, [15:49.870 --> 15:55.470] for example, they are okay in executing as a script. So yeah, it's a bit worrying as well. [15:56.350 --> 16:00.870] There are other parts in the dashboard that you can take a look at. There are some tables that [16:01.390 --> 16:05.610] lets you to explore some weaknesses of the sites that I gather. This is, for example, [16:05.610 --> 16:10.610] third-party orphan domains, no-csp-defined and safehavel and safeinline. So many others. Many [16:10.610 --> 16:15.670] vulnerabilities that you can take a look at. This is how it would look like if you visit this part [16:15.670 --> 16:21.530] of the dashboard. The orphan domains is the one that we are looking at now. The first column is [16:21.530 --> 16:28.810] the affected domain. And the description column tells you what are the domains that are orphan, [16:28.810 --> 16:33.690] that means not registered right now. So at the first line, for example, you see that the [16:33.690 --> 16:39.230] domain bosh-tools-results-page.com is present in the script source directive, but it's not [16:39.230 --> 16:44.810] registered. So it's sitting there for you to register and execute scripts on that page, [16:45.650 --> 16:49.350] provided that you find another cross-site scripting in that site. [16:50.110 --> 16:54.790] Now, for example, another example would be to look at the third-party abuse. In this case, [16:54.790 --> 17:00.910] the first column is the affected domain as well. And the description is telling me, for example, [17:01.630 --> 17:06.110] the third-party abuse that I can take advantage of. The second line, for example, is telling me [17:06.110 --> 17:12.170] that the directive-connect-source contains asterisk-at-hotjar.com, so I can use that to [17:12.170 --> 17:17.150] exfiltrate data. So it's at least that you can take advantage of, if you want to say that. [17:17.410 --> 17:23.890] Now what? What do we do with this information? It comes the fun part, the exploitation part. I [17:23.890 --> 17:32.010] wanted to find new bypasses. I found, just ahead, I wanted to find new vectors. I found a lot of [17:32.010 --> 17:39.050] information on the internet about how to bypass CSP using JSON with padding and AngularJS outdated [17:41.050 --> 17:47.150] libraries of AngularJS. I wanted to find different vectors, so I just forgot about them for a moment [17:47.150 --> 17:53.170] and found different ways. I came up with this list. That does not mean that this is the only [17:53.170 --> 17:58.470] list that exists out there. Probably there are others. Due to time restriction, I will only focus [17:58.470 --> 18:04.910] on this first one. I will explain a bit more the following three ones, and this last will just be [18:04.910 --> 18:11.670] mentioned by passing. But if you want to know more information about them, take a look to our [18:11.670 --> 18:19.370] blog post in sensepost.com. Details will be published soon. So yeah, to demonstrate the [18:19.370 --> 18:26.270] bypasses, I created a lab. This lab contains a private part where you can see the secret [18:26.270 --> 18:32.910] ingredient for the KFC recipe, and there is also a part here where you can change your own password [18:32.910 --> 18:38.350] and your security question, etc. So this is the lab where I want to test everything. [18:38.810 --> 18:43.070] The objectives for me to demonstrate the CSP bypasses would be first one to exfiltrate the [18:43.070 --> 18:46.930] security question and answer, second one to exfiltrate the secret ingredient, and third one [18:46.930 --> 18:51.830] to change the user password, victim password. For that, I created two different vulnerabilities [18:51.830 --> 18:59.310] on the lab. This vulnerability, just it's easier I guess to understand, gets a message parameter, [18:59.310 --> 19:06.370] no? And directly introduce the string into this JavaScript code down there. So you would get, [19:06.370 --> 19:11.670] if you visit the following page, secret.php, etc., msg, this is an error, and semicolon, [19:11.670 --> 19:16.250] you get the following JavaScript generated, which of course is a nice cross-site scripting. [19:16.250 --> 19:23.150] And the second vulnerability would be something similar, but in this case what we have is a [19:23.150 --> 19:29.650] loud script with a nonce, etc., and gets the parameter source, okay, from URL params, [19:29.650 --> 19:35.910] and the source gets introduced as the source of a script. This script is going to be appended [19:35.910 --> 19:39.810] in the head of the document, okay? So those are the two vulnerabilities that I will be using [19:39.810 --> 19:46.410] to demonstrate the CSP bypasses. So if you visit this source, you would get the script [19:46.410 --> 19:54.390] pointing to this code, script execution.js. So, showtime. The first one with Hotjar that I [19:54.390 --> 20:00.110] mentioned, I found 2050 sites in MyDB. This is a 2% of the sites that I have that are implementing [20:00.110 --> 20:06.710] CSP. It's not big, but it's not small, relatively, okay? Symptoms would be, oops, sorry, [20:06.710 --> 20:12.790] symptoms would be finding asterisk hotjar.com and askhotjar.io in the content security policy, [20:12.790 --> 20:17.530] and can be used to exfiltrate data. This is how it would look like when you go to the site. [20:17.690 --> 20:23.410] This is a content security policy, allowing default askhotjar.io, but for exfiltration purposes, [20:23.410 --> 20:28.690] you can use it as well for connect source, okay? This is the payload. Now, don't pay much [20:28.690 --> 20:33.530] attention to the mumbo-jumbo. It's just focus on those part, security question and answer, [20:33.530 --> 20:39.130] getting exfiltrated to the attacker.local domain. But, of course, due to the content policy that [20:39.130 --> 20:43.470] has been implemented, if we try this, to fetch this, and send out this information, [20:43.470 --> 20:49.630] you would get the following error, thanks to the CSP, which is good, no? But you, as an attacker, [20:49.630 --> 20:54.590] you know that they are low in Hotjar here, okay? So now what we do, as an attacker, you open [20:54.590 --> 21:01.490] yourself an account in Hotjar, you create a poll, no? You insert that poll in your own website, [21:01.490 --> 21:07.470] you sniff this traffic, you sniff the traffic of answering that poll in your own website, [21:07.470 --> 21:12.030] and then you mimic this answer, but in this case, from the victim website, or from the victim [21:12.030 --> 21:18.970] browser. So, if we take a look in BARP, for example, or your proxy of choice, we can see that [21:18.970 --> 21:24.770] the site, this is what you will see when you answer the poll in Hotjar. askhotjar.io is the [21:24.770 --> 21:30.010] host where we are exfiltrating this information to. This is a response content parameter, which [21:30.010 --> 21:36.030] contains, within the comment, we get the answer of the poll, no? So we are going to take advantage [21:36.030 --> 21:41.390] of it by introducing that in our previous proof of concept. We get now, again, the security [21:41.390 --> 21:45.910] question and answers exfiltrated from the profile of the user, we introduce them in the comment, [21:45.910 --> 21:53.650] and then fetch, post this information to askhotjar.io, etc. So we take all this JavaScript [21:53.650 --> 21:59.230] and encode it in Base64. Sorry for the red color, it doesn't look very bright here. [21:59.690 --> 22:05.430] But yeah, and you use it, and you introduce it as in the cross-site description that we saw in [22:05.430 --> 22:11.410] the first vulnerability here, append an extra message. By the way, this is a callout that [22:11.410 --> 22:15.510] you would need if you are going to use this eval, you need unsafe eval also allowed in the [22:15.510 --> 22:22.970] script source. But anyway, you shorten this to look less suspicious and deliver this script, [22:22.970 --> 22:27.770] sorry, this link to the victim, no? The victim clicks, and when the victim clicks, [22:27.770 --> 22:32.310] you get the following on your Hotjar attacker's account. I'm going to show you a video to [22:32.310 --> 22:38.470] demonstrate that. At the left side of the screen is the page. The victim is now logging in. On the [22:38.470 --> 22:44.670] right side is the attacker's perspective. It's a Hotjar account. The victim is logging in right [22:44.670 --> 22:49.090] now. There is the secret ingredient there and the profile with your password and the security [22:49.090 --> 22:55.370] answer and whatnot. Okay, so now the victim is going to click on the link, the malicious link. [22:55.370 --> 23:02.580] It gets redirected now to the cross-site scripting. We get that it was a success. And as attacker, [23:03.130 --> 23:13.250] we update our dashboard and get the following exfiltrated from the page, okay? The favorite [23:13.250 --> 23:27.970] word is the word. Anyway, so Facebook. Thank you. I found this was a bit more popular in this case, [23:27.970 --> 23:36.110] 2,750 sites in my database, just 2% of the site, 2.6% of the site implementing CSP. [23:36.110 --> 23:42.230] They're allowing facebook.com or facebook.net to be used to exfiltrate data, okay? So you can, [23:42.230 --> 23:49.750] as an attacker, go and create yourself a developer account in Facebook and exfiltrate data there. [23:49.750 --> 23:54.610] I will show that later. So this is the content security policy that you would face. This or [23:54.610 --> 23:59.710] this other configuration to exfiltrate data, okay? This is going to be shorter. In this case, [23:59.710 --> 24:05.410] we are taking advantage of the Facebook framework, the tracking pixel. The first line is just [24:05.410 --> 24:11.110] initiating the tracking pixel of Facebook to point to the attacker account ID. And the second line [24:11.110 --> 24:16.710] is just creating a fake event, a fake custom event. This fake custom event is going to exfiltrate [24:16.710 --> 24:22.550] within the data, the secret ingredient in this case, okay? So this is what you would look like, [24:22.550 --> 24:29.310] what you would see as an attacker if you get your victim clicking on that link, okay? The secret [24:29.310 --> 24:33.170] ingredient has been exfiltrated to your Facebook account, to your Facebook developer account [24:33.170 --> 24:41.450] dashboard. Okay. Demo three is with jsdeliver. I found that this was a bit more known around, [24:41.450 --> 24:48.770] but nevertheless, I think it's interesting to know. Found 1,550 sites in my database, [24:48.770 --> 24:55.290] symptoms, cdnjsdeliver allowed, and asterisk jsdeliver allowed. Can be used in this case [24:55.290 --> 25:00.970] to execute code instead of exfiltrating code, okay? That one is straightforward. You just host [25:00.970 --> 25:08.450] your code in your account, GitHub account or npm, okay? And politely ask jsdeliver cdn to [25:09.210 --> 25:16.750] cache that code, no? By using a specific URL. This URL is telling jsdeliver to go to GitHub, [25:16.750 --> 25:23.430] to the username felmoltor, to the repo name bunchofjs, and to the path exec. And it would politely [25:24.210 --> 25:29.610] get all your code and get it cached there. So now you only need to exploit the second [25:29.610 --> 25:35.150] vulnerability, the one with the source parameter here. You just need to send or deliver this [25:35.150 --> 25:40.570] script, sorry, this link to the victim. The victim clicks and gets the password changing [25:40.570 --> 25:46.370] and security question, et cetera, et cetera. Now, this is a bit more elaborate, but interesting as [25:46.370 --> 25:55.290] well. Not many sites, but relatively high. 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:06.770] So you need to define two different components here. A lambda function and an API gateway. [26:07.350 --> 26:13.510] This is the content of the lambda function. It is easy. You just get the data parameter, [26:13.510 --> 26:20.870] decode it, and print it in the console, which this console logs is going to be visible for you [26:20.870 --> 26:26.870] as an attacker in your CloudWatch logs, okay? And this is the script that you need to execute [26:26.870 --> 26:32.610] in the victim side, the code that you need to execute in the victim side. You just have your [26:32.610 --> 26:40.510] API gateway hosted here as a subdomain of amazonaws.com, and the data contains just the [26:41.710 --> 26:47.770] base64 encoded data that you want to exfiltrate, okay? And then just append this script, [26:47.770 --> 26:55.570] and you would get the following on your CloudWatch logs, okay? The secret ingredient. [26:55.570 --> 27:01.450] Okay, now this is just passing by. I found other four different vulnerabilities, sorry, [27:01.450 --> 27:08.170] CSP bypasses with Amazon CloudFront, Azure Web Applications. Similarly, 100 sites, 100 sites. [27:08.170 --> 27:14.950] First one would be the content security policy allowing asterisk cloudfront.com. The following [27:14.950 --> 27:20.970] one would be azurewebsites.net and azurestaticapps.net. Both can be used to execute and exfiltrate data, [27:20.970 --> 27:24.190] and the proof of concept would be similar. To exploit the second vulnerability, you just send [27:24.190 --> 27:32.530] to the victim. You get the information or the script executed on the victim side. [27:32.970 --> 27:36.590] Heroku, Firebase, those are not very popular, but you never know when they're going to be [27:36.590 --> 27:43.250] useful for your next bug bounty. So asteriskherokuapps.com and firebaseapp.com. [27:43.290 --> 27:49.890] Similarly, you open your account in each of those and host your code, and it could be executed by [27:49.890 --> 27:55.010] the victim. Anyway, not going to delve too much. So now that we know how many ways they can bypass [27:55.010 --> 28:03.250] this CSP, what do we do as defenders? First of all, push the big red button and encourage other [28:03.250 --> 28:10.670] people to do so, please. Do not be the dentists that are not brushing their teeth. So if you're [28:10.670 --> 28:16.470] doing that, if you're implementing CSP, do that in conjunction with self-resource integrity. [28:16.470 --> 28:22.370] So if one of your third parties get popped and one of the JavaScripts get changed, [28:22.370 --> 28:28.230] please, if you're using self-resource integrity, you won't get that code executed on your website. [28:28.230 --> 28:34.350] I know some personal stories of that. So then if you're using your CSP, don't use anything [28:34.350 --> 28:39.490] that says unsafe. Unsafe for the ones that do not know English is very bad word, okay? [28:39.490 --> 28:47.370] And use instead nonces and hashes. You can use a strict dynamic, okay? You can use a strict [28:47.370 --> 28:52.870] dynamic to reduce the operational load transitive property that I mentioned before, but be aware of [28:52.870 --> 28:58.010] the risk. That means that you have to really trust those other third parties. Then reduce [28:58.010 --> 29:03.410] the number of third parties on your content security policy, reduce it to a minimum. I'm [29:03.410 --> 29:08.810] not saying not use them, but reduce them to a minimum. And if possible, instead of opening [29:08.810 --> 29:14.910] pokes and poking holes on your CSP, to allow third parties, just host the libraries on your [29:14.910 --> 29:20.070] own domain, so you don't have to poke a hole in your CSP. Do not include, of course, if you have [29:20.070 --> 29:24.350] to do that, do not include third party domains with wildcards, such as this one. You're allowing [29:24.350 --> 29:30.650] everyone that has an Amazon AWS domain.com API gateway to execute or retrieve code from your [29:30.650 --> 29:36.470] site, no? Then use report two and report sample. This is going to be noisy, but it's giving you [29:37.330 --> 29:40.610] superpowers and you are going to be able to see what is happening in real time [29:40.610 --> 29:46.450] with your users, no? 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 --> 29:55.690] These solutions, you can search for them, they are going to tell you, they're going to highlight [29:55.690 --> 30:01.030] and alert, tell you, hey, this script has been executed in one of your user browser and it's not [30:01.030 --> 30:07.550] useful. So take a look to it. With all of that, thank you, everyone. Thank you for all my [30:07.550 --> 30:22.340] colleagues. You didn't let me thanks to my colleagues in SensePost and Orange Cyber Defense, [30:22.340 --> 30:29.160] especially Simon and Leon and John and everyone else and you guys for being here. Thank you, [30:29.160 --> 30:29.800] everyone.