1 00:00:08,380 --> 00:00:10,020 Thank you, everyone, for coming. 2 00:00:10,280 --> 00:00:12,620 It was said this is going to be big data. 3 00:00:12,620 --> 00:00:14,220 Well, press code, sorry. 4 00:00:14,220 --> 00:00:16,780 Big data approach to understanding the content security policy. 5 00:00:18,020 --> 00:00:21,920 At the end of the talk I would like to share with you eight bypasses. 6 00:00:21,920 --> 00:00:24,420 Six of them I think that they are not so well known. 7 00:00:24,460 --> 00: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. 8 00:00:32,520 --> 00:00:36,720 Okay, starting with that, I would like everyone here to imagine a big red button. 9 00:00:37,300 --> 00: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. 10 00:00:49,820 --> 00:00:51,200 Would you push that button? 11 00:00:51,200 --> 00:00:51,720 Wouldn't you? 12 00:00:51,720 --> 00:00:52,420 Yes, no? 13 00:00:52,780 --> 00:00:54,060 Me included? 14 00:00:54,060 --> 00:00:54,880 Everyone here? 15 00:00:54,880 --> 00:00:57,120 I guess that would do the same. 16 00:00:57,120 --> 00: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. 17 00:01:07,680 --> 00: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. 18 00:01:16,420 --> 00:01:18,820 But before that, I would like to introduce myself. 19 00:01:18,820 --> 00:01:20,200 I'm Felipe Molina. 20 00:01:20,240 --> 00:01:25,280 I've been working with Orange Cyber Defence SensePost team for four years and something more. 21 00:01:25,320 --> 00:01:28,720 Ten years in the information security industry. 22 00:01:29,080 --> 00:01:31,880 Proud dad, Futurama and Simpson fan, of course. 23 00:01:32,060 --> 00:01:36,020 You can find me on Twitter, if you want to chat with me about Futurama. 24 00:01:36,600 --> 00:01:40,160 Anyway, I have divided this talk in three different blocks. 25 00:01:40,160 --> 00:01:43,480 The first one is going to be the context with a bit of history, brief. 26 00:01:43,720 --> 00:01:46,420 The aim of CSP, the content security policy. 27 00:01:46,600 --> 00: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. 28 00:02:02,020 --> 00:02:06,620 The third block is going to be the bypasses themselves, with a bit of demo, if we have enough time. 29 00:02:07,200 --> 00:02:09,960 Okay, I want to clarify what the dress code name. 30 00:02:09,960 --> 00:02:12,020 It comes from UI redressing attacks. 31 00:02:12,020 --> 00:02:19,500 UI redressing attacks, as you may know, it comes from different kind of injection, JavaScript injection in your pages. 32 00:02:19,600 --> 00: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. 33 00:02:28,640 --> 00:02:34,960 So I was reading that they have this cross-site scripting, store one, in many places of their web pages. 34 00:02:34,960 --> 00:02:36,960 And I said, okay, let's try it. 35 00:02:37,080 --> 00: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. 36 00:02:44,680 --> 00:02:48,560 I said, damn, I'm not going to be able to exploit them again. 37 00:02:48,560 --> 00:02:53,060 They didn't care about the base code of the application, but instead implemented the CSP. 38 00:02:53,060 --> 00:02:54,400 So what happened? 39 00:02:54,520 --> 00:03:00,340 As a hacker, you think that you have to bypass that and resurface the cross-site scripting. 40 00:03:00,640 --> 00:03:08,820 So yeah, what I did is that, found a bypass on CSP policy and resurrected the old cross-site scripting. 41 00:03:08,860 --> 00:03:12,160 The client was a bit sad, I was a bit happy, sorry for that. 42 00:03:12,780 --> 00:03:16,260 But the thing is that it made sense at that point. 43 00:03:16,480 --> 00: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. 44 00:03:34,460 --> 00:03:35,400 So yeah, nice. 45 00:03:35,400 --> 00:03:35,800 Okay. 46 00:03:35,800 --> 00:03:37,300 This is the context. 47 00:03:37,540 --> 00:03:43,320 After that assessment, I thought to myself, okay, this is like, I want to know more about CSP. 48 00:03:43,320 --> 00:03:50,140 So I decided to understand how CSP works for real, how prevalent it is across internet, how well configured. 49 00:03:50,140 --> 00: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. 50 00:03:58,860 --> 00:04:01,660 So let's start with what is CSP? 51 00:04:01,660 --> 00:04:04,440 Define Verbatim from Mozilla.org site. 52 00:04:04,440 --> 00:04:11,640 It's another layer of security to detect and mitigate injection attacks. 53 00:04:12,240 --> 00:04:15,340 More so if it's cross-site scripting. 54 00:04:15,340 --> 00: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. 55 00:04:29,240 --> 00:04:35,620 And this could result in very ugly impacts, such as data theft, site displacement, malware distribution. 56 00:04:35,920 --> 00:04:40,060 Very, very bad things could happen if you don't protect against that. 57 00:04:40,060 --> 00:04:44,040 So it looks like CSP has a really good end. 58 00:04:44,220 --> 00:04:46,380 It's really good to implement in that. 59 00:04:46,380 --> 00:04:53,640 But yet, even knowing how good could be implementing CSP, most of us are not pushing that button. 60 00:04:53,640 --> 00:04:59,180 Only 10% of the sites that I scan were implementing CSP. 61 00:04:59,180 --> 00:05:06,440 This is a chart that indicates how many of those 1 million sites that I scan were implementing CSP headers. 62 00:05:06,600 --> 00:05:10,880 These top 1 million sites were pulled from a database . 63 00:05:11,060 --> 00:05:13,180 Well, the source was Majestic Million. 64 00:05:13,180 --> 00:05:20,420 It's a list of popular sites on the internet constructed by a company called Majestic. 65 00:05:20,420 --> 00:05:22,320 They do SEO, so they know their stuff. 66 00:05:22,320 --> 00:05:25,740 So yeah, I target that 1 million site list. 67 00:05:26,160 --> 00:05:28,380 And it was a concerning outcome. 68 00:05:29,180 --> 00:05:32,960 So we are implementing only 10% of the sites are implementing this. 69 00:05:32,960 --> 00: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. 70 00:05:41,840 --> 00:05:43,800 We are just doing completely opposite. 71 00:05:43,800 --> 00:05:48,060 The dentists being us, the security and the developers here, we are not doing the right thing. 72 00:05:48,060 --> 00:05:50,520 We are just not brushing our teeth. 73 00:05:50,720 --> 00:05:54,780 So with that in mind, I was a bit disappointed. 74 00:05:54,780 --> 00:05:57,320 And I thought, OK, but maybe this is a modern technology. 75 00:05:57,320 --> 00:05:58,060 No, it is not. 76 00:05:58,060 --> 00:05:59,800 It has been a long time with us. 77 00:05:59,800 --> 00:06:03,000 It started as an idea with a snake in 2004. 78 00:06:03,300 --> 00: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. 79 00:06:12,700 --> 00:06:15,960 In 2012, it was issued as a standard. 80 00:06:15,960 --> 00: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. 81 00:06:28,600 --> 00: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. 82 00:06:38,940 --> 00:06:44,940 The policy would be separated in different directives, each directive separated by a semicolon. 83 00:06:45,080 --> 00:06:50,760 And each directive would have a directive name separated by a space with one, sorry, zero or more values. 84 00:06:50,760 --> 00:06:52,740 So this is the structure that it has. 85 00:06:52,780 --> 00:06:57,880 When you go to a random site of internet, you find this is the answer in the response. 86 00:06:57,880 --> 00:07:05,200 And if we structure this by separating it by semicolons and by spaces later, this is how it would look like. 87 00:07:05,380 --> 00:07:09,460 The first line, for example, well, I must say that this is just three examples. 88 00:07:09,500 --> 00:07:16,580 Content security policy has a lot of other directive names, which can have a lot of other purposes here. 89 00:07:16,760 --> 00:07:18,780 But those are just three examples. 90 00:07:19,100 --> 00:07:24,720 Script source is indicating the agent or the browser what scripts are allowed to be running on your page. 91 00:07:24,720 --> 00:07:31,820 Okay, this first value is telling the agent that scripts that contain these nouns are allowed to be executed. 92 00:07:31,940 --> 00:07:34,660 This or any other randomly generated nouns. 93 00:07:34,660 --> 00:07:36,440 The following one is a strict dynamic. 94 00:07:36,440 --> 00: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. 95 00:07:47,680 --> 00: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. 96 00:07:56,740 --> 00: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. 97 00:08:05,680 --> 00:08:10,080 Okay, then we have two additional ones that I want to put a bit of more attention in. 98 00:08:10,080 --> 00:08:11,320 Connect source and default source. 99 00:08:11,320 --> 00:08:20,640 Connect source is telling the agent what pages are being allowed to be connected out from the page. 100 00:08:20,840 --> 00: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. 101 00:08:32,100 --> 00: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. 102 00:08:39,780 --> 00:08:44,980 So I'm not a developer myself, so this is me, the dog, not knowing what how to program. 103 00:08:45,220 --> 00:08:50,480 But I wanted to do something scalable and something that could be finished in my own lifetime. 104 00:08:50,480 --> 00:08:54,700 So I did it, I wanted to do something that was fast. 105 00:08:54,700 --> 00:08:56,660 So to scan this one million sites. 106 00:08:56,660 --> 00: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. 107 00:09:08,560 --> 00: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. 108 00:09:23,060 --> 00:09:26,240 So anyway, this is the solution that I came with. 109 00:09:26,240 --> 00: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. 110 00:09:36,230 --> 00: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. 111 00:09:48,030 --> 00:09:49,630 Okay, the process would be simple. 112 00:09:49,670 --> 00:09:54,530 Collecting the headers with a scanner, two different sources are used, Majestic Million and Cisco Umbrella. 113 00:09:54,630 --> 00:09:58,470 Both of them gave me the same results, 10% of the sites using it. 114 00:09:58,570 --> 00: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. 115 00:10:10,190 --> 00:10:15,670 Then I would scan everything there, spot weaknesses and bypasses that you can take for profit. 116 00:10:15,690 --> 00: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. 117 00:10:25,170 --> 00:10:27,670 Okay, this is how the data looks like in the database. 118 00:10:27,670 --> 00:10:33,090 So you start by with an ID, URL, and final URL, because you can be redirected multiple times. 119 00:10:33,090 --> 00: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. 120 00:10:44,130 --> 00:10:49,030 Now I'm going to show you a brief view of how the dashboard is. 121 00:10:49,030 --> 00:10:53,670 I'm not going to delve into details of this dashboard, it's just for you to get an idea. 122 00:10:53,750 --> 00: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. 123 00:11:01,690 --> 00:11:08,890 Now you get down there, the pie chart that shows you how many sites are using CSP at that moment. 124 00:11:08,890 --> 00: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. 125 00:11:21,050 --> 00:11:26,210 This is a frequency chart showing the most frequent directives that I will show you later. 126 00:11:26,210 --> 00: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. 127 00:11:30,390 --> 00:11:33,350 The results of this chart would be shown here. 128 00:11:33,450 --> 00:11:36,290 So this is the CSP directive sort by frequency. 129 00:11:36,290 --> 00:11:38,470 We can take a look at the first ones there. 130 00:11:38,730 --> 00:11:43,810 The most frequent ones and the most used are upgrading secure requests and frame ancestors. 131 00:11:43,810 --> 00:11:49,890 Upgrading secure requests are used in 46% of the site that define a content security policy. 132 00:11:49,890 --> 00:11:52,910 Frame ancestors are used similarly in the 46%. 133 00:11:53,590 --> 00:11:55,490 Could be better, but it's okay. 134 00:11:55,490 --> 00:11:59,350 Those make sense that they are most used because they are easiest one to implement. 135 00:11:59,350 --> 00:12:06,890 So it looks like when it comes to maintaining an allow list, we get a bit tired and we stop implementing. 136 00:12:06,890 --> 00:12:09,790 So we just decide those are enough for our policy. 137 00:12:11,110 --> 00: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. 138 00:12:18,910 --> 00:12:20,110 The rest are not defining. 139 00:12:20,110 --> 00:12:22,290 So it's not the best configuration. 140 00:12:23,490 --> 00:12:26,730 Then we see that those are the less popular ones. 141 00:12:26,730 --> 00:12:29,850 Base URI, report URI from action manifest. 142 00:12:29,850 --> 00:12:32,430 And I think that this is because we don't know what they are doing. 143 00:12:32,430 --> 00:12:34,510 There is not much popularity of those. 144 00:12:34,510 --> 00:12:36,410 They are not being very widely used. 145 00:12:36,410 --> 00: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. 146 00:12:46,510 --> 00: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. 147 00:12:56,310 --> 00: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. 148 00:13:05,770 --> 00:13:09,790 So it's pretty serious, but still we're not using it enough. 149 00:13:09,790 --> 00:13:18,150 Okay , so you can also take a look in this dashboard to the allowed sources for different values. 150 00:13:18,150 --> 00: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. 151 00:13:26,830 --> 00: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. 152 00:13:37,910 --> 00:13:40,010 It's quite popular, this configuration. 153 00:13:40,010 --> 00: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. 154 00:13:49,530 --> 00:13:52,530 The other 20% of the time he's not brushing his teeth. 155 00:13:52,930 --> 00:13:59,450 Anyway, I had this other map there in the dashboard where you can see the current status across the globe. 156 00:13:59,450 --> 00:14:01,510 No, we are doing it equally wrong. 157 00:14:02,210 --> 00:14:10,810 This light green color here means that no more than 10% per country of the sites are implementing CSP. 158 00:14:10,810 --> 00:14:13,410 There are some outliers here in Africa. 159 00:14:13,450 --> 00:14:17,950 I can think that those are because we don't have enough sample data from them. 160 00:14:18,110 --> 00:14:24,010 If we have a couple or three sites there, it gets rigorous, a lot of sites. 161 00:14:24,010 --> 00:14:27,030 But I haven't studied them very deeply. 162 00:14:27,090 --> 00:14:31,890 So then we can take a look to the weaknesses. 163 00:14:32,110 --> 00:14:34,090 This is a way to classify the weaknesses. 164 00:14:34,090 --> 00:14:37,170 For example, this is the the most frequent weakness that I found. 165 00:14:37,170 --> 00:14:39,490 No one is using report2. 166 00:14:39,490 --> 00:14:48,330 This report2 directive indicates the agent where all those errors can be reported. 167 00:14:48,330 --> 00: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. 168 00:15:01,330 --> 00:15:03,450 No one is also using base URI. 169 00:15:03,990 --> 00:15:05,790 So yeah, it looks like there. 170 00:15:05,790 --> 00:15:08,790 Yeah, it's pretty common not having those. 171 00:15:08,790 --> 00: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? 172 00:15:16,970 --> 00:15:22,750 So the least frequent weaknesses are... yeah, and safeinline and safehabit, they are there. 173 00:15:22,750 --> 00:15:26,530 But those are the two ones that get me more worried. 174 00:15:26,530 --> 00:15:34,250 For example, 9% of the sites that define a content security policy, they can be abused by third parties domains. 175 00:15:34,610 --> 00:15:36,910 I will get back to that later. 176 00:15:37,730 --> 00: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. 177 00:15:53,610 --> 00:15:55,470 So yeah, it's a bit worrying as well. 178 00:15:56,350 --> 00:15:59,330 There are other parts in the dashboard that you can take a look at. 179 00:15:59,330 --> 00:16:04,390 There are some tables that lets you to explore some weaknesses of the sites that I gather. 180 00:16:04,570 --> 00:16:09,630 This is, for example, third-party orphan domains, no-csp-defined and safehavel and safeinline. 181 00:16:09,630 --> 00:16:10,490 So many others. 182 00:16:10,490 --> 00:16:12,770 Many vulnerabilities that you can take a look at. 183 00:16:12,910 --> 00:16:17,770 This is how it would look like if you visit this part of the dashboard. 184 00:16:17,790 --> 00:16:20,790 The orphan domains is the one that we are looking at now. 185 00:16:20,790 --> 00:16:22,890 The first column is the affected domain. 186 00:16:23,190 --> 00:16:30,910 And the description column tells you what are the domains that are orphan, that means not registered right now. 187 00:16:31,050 --> 00: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. 188 00:16:39,710 --> 00: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. 189 00:16:50,110 --> 00:16:54,270 Now, for example, another example would be to look at the third-party abuse. 190 00:16:54,270 --> 00:16:58,290 In this case, the first column is the affected domain as well. 191 00:16:58,450 --> 00:17:04,190 And the description is telling me, for example, the third-party abuse that I can take advantage of. 192 00:17:04,190 --> 00: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. 193 00:17:13,410 --> 00:17:17,150 So it's at least that you can take advantage of, if you want to say that. 194 00:17:17,410 --> 00:17:18,050 Now what? 195 00:17:18,050 --> 00:17:19,790 What do we do with this information? 196 00:17:19,790 --> 00:17:22,210 It comes the fun part, the exploitation part. 197 00:17:23,410 --> 00:17:25,930 I wanted to find new bypasses. 198 00:17:26,350 --> 00:17:31,310 I found, just ahead, I wanted to find new vectors. 199 00:17:31,310 --> 00: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. 200 00:17:43,250 --> 00:17:49,350 I wanted to find different vectors, so I just forgot about them for a moment and found different ways. 201 00:17:49,730 --> 00:17:51,550 I came up with this list. 202 00:17:51,550 --> 00:17:54,530 That does not mean that this is the only list that exists out there. 203 00:17:54,530 --> 00:17:55,870 Probably there are others. 204 00:17:56,390 --> 00:17:59,690 Due to time restriction, I will only focus on this first one. 205 00:18:00,110 --> 00:18:07,690 I will explain a bit more the following three ones, and this last will just be mentioned by passing. 206 00:18:08,070 --> 00:18:14,330 But if you want to know more information about them, take a look to our blog post in sensepost.com. 207 00:18:14,750 --> 00:18:16,910 Details will be published soon. 208 00:18:17,810 --> 00:18:21,330 So yeah, to demonstrate the bypasses, I created a lab. 209 00:18:21,330 --> 00: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. 210 00:18:35,070 --> 00:18:38,350 So this is the lab where I want to test everything. 211 00:18:38,810 --> 00: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. 212 00:18:49,990 --> 00:18:52,970 For that, I created two different vulnerabilities on the lab. 213 00:18:52,970 --> 00:18:59,710 This vulnerability, just it's easier I guess to understand, gets a message parameter, no? 214 00:18:59,710 --> 00:19:05,170 And directly introduce the string into this JavaScript code down there. 215 00:19:05,350 --> 00: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. 216 00:19:16,250 --> 00: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. 217 00:19:34,290 --> 00:19:37,410 This script is going to be appended in the head of the document, okay? 218 00:19:37,410 --> 00:19:42,450 So those are the two vulnerabilities that I will be using to demonstrate the CSP bypasses. 219 00:19:42,490 --> 00:19:50,550 So if you visit this source, you would get the script pointing to this code, script execution.js. 220 00:19:50,870 --> 00:19:52,090 So, showtime. 221 00:19:52,470 --> 00:19:57,130 The first one with Hotjar that I mentioned, I found 2050 sites in MyDB. 222 00:19:57,210 --> 00:20:01,310 This is a 2% of the sites that I have that are implementing CSP. 223 00:20:01,310 --> 00:20:04,630 It's not big, but it's not small, relatively, okay? 224 00:20:04,630 --> 00: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. 225 00:20:14,790 --> 00:20:17,530 This is how it would look like when you go to the site. 226 00:20:17,690 --> 00: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? 227 00:20:26,490 --> 00:20:27,770 This is the payload. 228 00:20:27,770 --> 00:20:30,350 Now, don't pay much attention to the mumbo-jumbo. 229 00:20:30,350 --> 00:20:36,450 It's just focus on those part, security question and answer, getting exfiltrated to the attacker.local domain. 230 00:20:36,450 --> 00: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? 231 00:20:48,230 --> 00:20:52,610 But you, as an attacker, you know that they are low in Hotjar here, okay? 232 00:20:52,610 --> 00:20:59,310 So now what we do, as an attacker, you open yourself an account in Hotjar, you create a poll, no? 233 00:20:59,310 --> 00: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. 234 00:21:13,130 --> 00: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. 235 00:21:23,190 --> 00:21:27,390 askhotjar.io is the host where we are exfiltrating this information to. 236 00:21:27,390 --> 00:21:34,810 This is a response content parameter, which contains, within the comment, we get the answer of the poll, no? 237 00:21:34,810 --> 00:21:39,290 So we are going to take advantage of it by introducing that in our previous proof of concept. 238 00:21:39,290 --> 00: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. 239 00:21:51,270 --> 00:21:55,390 So we take all this JavaScript and encode it in Base64. 240 00:21:55,390 --> 00:21:59,230 Sorry for the red color, it doesn't look very bright here. 241 00:21:59,690 --> 00: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. 242 00:22:08,970 --> 00: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. 243 00:22:16,870 --> 00:22:24,830 But anyway, you shorten this to look less suspicious and deliver this script, sorry, this link to the victim, no? 244 00:22:24,830 --> 00:22:30,950 The victim clicks, and when the victim clicks, you get the following on your Hotjar attacker's account. 245 00:22:31,010 --> 00:22:33,230 I'm going to show you a video to demonstrate that. 246 00:22:33,230 --> 00:22:36,510 At the left side of the screen is the page. 247 00:22:36,890 --> 00:22:38,230 The victim is now logging in. 248 00:22:38,230 --> 00:22:40,510 On the right side is the attacker's perspective. 249 00:22:40,510 --> 00:22:42,350 It's a Hotjar account. 250 00:22:43,590 --> 00:22:45,210 The victim is logging in right now. 251 00:22:45,210 --> 00:22:50,370 There is the secret ingredient there and the profile with your password and the security answer and whatnot. 252 00:22:50,570 --> 00:22:55,370 Okay, so now the victim is going to click on the link, the malicious link. 253 00:22:55,370 --> 00:23:00,030 It gets redirected now to the cross-site scripting. 254 00:23:00,030 --> 00:23:01,790 We get that it was a success. 255 00:23:01,790 --> 00:23:11,630 And as attacker, we update our dashboard and get the following exfiltrated from the page, okay? 256 00:23:12,150 --> 00:23:15,710 The favorite word is the word. 257 00:23:15,790 --> 00:23:19,510 Anyway, so Facebook. 258 00:23:21,930 --> 00:23:23,230 Thank you. 259 00:23:24,890 --> 00: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. 260 00:23:36,110 --> 00:23:41,510 They're allowing facebook.com or facebook.net to be used to exfiltrate data, okay? 261 00:23:41,510 --> 00:23:49,750 So you can, as an attacker, go and create yourself a developer account in Facebook and exfiltrate data there. 262 00:23:49,750 --> 00:23:50,910 I will show that later. 263 00:23:50,910 --> 00:23:53,950 So this is the content security policy that you would face. 264 00:23:54,010 --> 00:23:57,150 This or this other configuration to exfiltrate data, okay? 265 00:23:57,650 --> 00:23:59,310 This is going to be shorter. 266 00:23:59,310 --> 00:24:03,770 In this case, we are taking advantage of the Facebook framework, the tracking pixel. 267 00:24:04,050 --> 00:24:10,210 The first line is just initiating the tracking pixel of Facebook to point to the attacker account ID. 268 00:24:10,250 --> 00:24:14,730 And the second line is just creating a fake event, a fake custom event. 269 00:24:14,730 --> 00:24:20,090 This fake custom event is going to exfiltrate within the data, the secret ingredient in this case, okay? 270 00:24:20,430 --> 00: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? 271 00:24:28,970 --> 00:24:34,190 The secret ingredient has been exfiltrated to your Facebook account, to your Facebook developer account dashboard. 272 00:24:34,690 --> 00:24:35,330 Okay. 273 00:24:35,330 --> 00:24:37,690 Demo three is with jsdeliver. 274 00:24:37,690 --> 00:24:43,930 I found that this was a bit more known around, but nevertheless, I think it's interesting to know. 275 00:24:43,990 --> 00:24:54,270 Found 1,550 sites in my database, symptoms, cdnjsdeliver allowed, and asterisk jsdeliver allowed. 276 00:24:54,270 --> 00:24:58,310 Can be used in this case to execute code instead of exfiltrating code, okay? 277 00:24:58,590 --> 00:25:00,230 That one is straightforward. 278 00:25:00,230 --> 00:25:05,270 You just host your code in your account, GitHub account or npm, okay? 279 00:25:05,390 --> 00:25:10,970 And politely ask jsdeliver cdn to cache that code, no? 280 00:25:10,970 --> 00:25:13,230 By using a specific URL. 281 00:25:13,230 --> 00: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. 282 00:25:22,430 --> 00:25:27,350 And it would politely get all your code and get it cached there. 283 00:25:27,350 --> 00:25:33,390 So now you only need to exploit the second vulnerability, the one with the source parameter here. 284 00:25:33,390 --> 00:25:37,590 You just need to send or deliver this script, sorry, this link to the victim. 285 00:25:37,590 --> 00:25:42,590 The victim clicks and gets the password changing and security question, et cetera, et cetera. 286 00:25:43,670 --> 00:25:46,770 Now, this is a bit more elaborate, but interesting as well. 287 00:25:46,970 --> 00:25:49,970 Not many sites, but relatively high. 288 00:25:50,210 --> 00:25:55,290 550 sites in my DB, amazonaws.com, asterisk, okay? 289 00:25:55,290 --> 00:25:59,310 Can be used to exfiltrate, but I'm pretty positive that you can use it to execute code as well. 290 00:25:59,610 --> 00:26:02,930 So you need to define two different components here. 291 00:26:03,370 --> 00:26:06,770 A lambda function and an API gateway. 292 00:26:07,350 --> 00:26:09,670 This is the content of the lambda function. 293 00:26:09,670 --> 00:26:10,550 It is easy. 294 00:26:10,550 --> 00: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? 295 00:26:24,910 --> 00: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. 296 00:26:30,890 --> 00: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? 297 00:26:45,330 --> 00:26:53,050 And then just append this script, and you would get the following on your CloudWatch logs, okay? 298 00:26:53,510 --> 00:26:55,570 The secret ingredient. 299 00:26:55,570 --> 00:26:58,550 Okay, now this is just passing by. 300 00:26:58,550 --> 00:27:05,670 I found other four different vulnerabilities, sorry, CSP bypasses with Amazon CloudFront, Azure Web Applications. 301 00:27:05,670 --> 00:27:08,170 Similarly, 100 sites, 100 sites. 302 00:27:08,170 --> 00:27:13,830 First one would be the content security policy allowing asterisk cloudfront.com. 303 00:27:13,870 --> 00:27:18,450 The following one would be azurewebsites.net and azurestaticapps.net. 304 00:27:18,450 --> 00:27:22,370 Both can be used to execute and exfiltrate data, and the proof of concept would be similar. 305 00:27:22,370 --> 00:27:26,230 To exploit the second vulnerability, you just send to the victim. 306 00:27:26,230 --> 00:27:32,530 You get the information or the script executed on the victim side. 307 00:27:32,970 --> 00: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. 308 00:27:38,790 --> 00:27:43,250 So asteriskherokuapps.com and firebaseapp.com. 309 00:27:43,290 --> 00:27:50,370 Similarly, you open your account in each of those and host your code, and it could be executed by the victim. 310 00:27:50,370 --> 00:27:52,210 Anyway, not going to delve too much. 311 00:27:52,210 --> 00:27:58,390 So now that we know how many ways they can bypass this CSP, what do we do as defenders? 312 00:27:59,330 --> 00:28:04,790 First of all, push the big red button and encourage other people to do so, please. 313 00:28:05,110 --> 00:28:08,930 Do not be the dentists that are not brushing their teeth. 314 00:28:09,110 --> 00:28:16,470 So if you're doing that, if you're implementing CSP, do that in conjunction with self-resource integrity. 315 00:28:16,470 --> 00: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. 316 00:28:28,230 --> 00:28:30,430 I know some personal stories of that. 317 00:28:30,850 --> 00:28:35,330 So then if you're using your CSP, don't use anything that says unsafe. 318 00:28:35,330 --> 00:28:39,490 Unsafe for the ones that do not know English is very bad word, okay? 319 00:28:39,490 --> 00:28:43,050 And use instead nonces and hashes. 320 00:28:44,570 --> 00:28:46,790 You can use a strict dynamic, okay? 321 00:28:46,790 --> 00: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. 322 00:28:53,410 --> 00:28:56,230 That means that you have to really trust those other third parties. 323 00:28:57,090 --> 00:29:03,310 Then reduce the number of third parties on your content security policy, reduce it to a minimum. 324 00:29:03,310 --> 00:29:06,770 I'm not saying not use them, but reduce them to a minimum. 325 00:29:06,770 --> 00: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. 326 00:29:18,350 --> 00: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. 327 00:29:23,750 --> 00: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? 328 00:29:31,530 --> 00:29:33,930 Then use report two and report sample. 329 00:29:33,970 --> 00: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? 330 00:29:42,410 --> 00:29:46,450 What code is being executed on your client's or user's side. 331 00:29:46,470 --> 00:29:51,230 And then finally, consider available commercial solutions to monitor client-side JavaScript. 332 00:29:51,230 --> 00: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. 333 00:30:01,890 --> 00:30:03,850 So take a look to it. 334 00:30:04,430 --> 00:30:06,390 With all of that, thank you, everyone. 335 00:30:06,390 --> 00:30:08,370 Thank you for all my colleagues. 336 00:30:17,780 --> 00: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. 337 00:30:28,800 --> 00:30:29,800 Thank you, everyone.