[00:00.000 --> 00:07.200] Uh welcome to track two, talk number two on Saturday. Uh this morning we uh have Martin and [00:07.200 --> 00:11.360] he's gonna talk about breaking the rules of web cache exploitation. So are you ready [00:11.360 --> 00:20.600] Martin? I'm ready. Let's hear it for Martin. Thank you. Hello everyone. Welcome to [00:20.600 --> 00:28.320] Gara Cache Mall, bending the rules of web cache exploitation. Uh it's already not [00:28.320 --> 00:35.400] working. So this is the agenda for today. First I'm going to briefly explain how a web [00:35.400 --> 00:40.240] cache works and then I'm going to show how we can abuse some discrepancies between the [00:40.240 --> 00:45.860] URL parsers of HTTP servers and cache proxies in order to steal secret information from [00:45.860 --> 00:52.060] victims using arbitrary web cache deception. Next I'm going to show how you use the same [00:52.060 --> 00:57.460] techniques or similar techniques to obtain arbitrary web cache poisoning by modifying the [00:57.460 --> 01:03.580] keys of a store resource. Then I'm going to combine both techniques in order to store [01:03.580 --> 01:08.800] whatever I want in the web cache with any key so this will allow us to create a full [01:08.800 --> 01:13.740] defacement of a website. And finally I'm going to present some protections that can be used to [01:13.740 --> 01:20.620] defend against those attacks and it takes hours of the session. So before I start, eh I [01:20.620 --> 01:25.140] want to clarify that most of the or all the examples are going to be based on CDNs like [01:25.140 --> 01:29.700] Cloudflare, Cloudfront, Akamai, but the idea is that you can use all of these techniques [01:29.700 --> 01:35.440] with any HTTP with any web cache eh proxy or with any web cache that you want even those [01:35.440 --> 01:42.420] that are included in the HTTP server. So whenever someone sends a request to a website using [01:42.580 --> 01:46.820] a web cache, basically the first thing that is going to happen is that the cache proxy is [01:46.820 --> 01:50.980] going to handle the request and is going to try to generate the response without having to [01:50.980 --> 01:56.700] communicate with the origin server. And this is going to be done by calculating a key and [01:56.700 --> 02:01.740] this key is basically an identifier of the request that states which is the resource that is [02:01.740 --> 02:07.300] being requested and it's not really important other things like the, the heaters like cookies [02:07.300 --> 02:11.880] or user agent because when we have two requests that are looking for the same resource and [02:11.880 --> 02:16.980] that resource is static, then we just need to provide the resource and we don't care about [02:16.980 --> 02:23.420] processing anything else. So we will see that the keys are just URLs and host names and in [02:23.420 --> 02:30.880] this talk we will just focus on the URL. So when the cache proxy calculated this key and is [02:30.880 --> 02:37.860] looking for a response that can be served eh to this request, he will look at the cache [02:37.860 --> 02:43.320] table and if there's nothing there, it will send the request to the origin server. Now the [02:43.320 --> 02:48.400] origin server is going to parse the URL, obtain the path and then it's going to use an [02:48.400 --> 02:53.480] endpoint to resolve the request. Sometimes it's just a static endpoint like a file and [02:53.480 --> 03:00.020] sometimes it's a dynamic one that is generated by a program back net. So when this response [03:00.020 --> 03:05.200] is sent back to the cache proxy, the well the cache proxy is going to generate to [03:05.200 --> 03:10.180] evaluate some rules to see if this response should be stored in the cache. So if it's static [03:10.180 --> 03:16.900] or not. These rules are usually evaluated on the response using the cache control heater but [03:16.900 --> 03:22.040] also in the request the cache proxy is going to extract the path and it's going to [03:22.040 --> 03:27.040] evaluate it with some of the other rules. For example the static extension one which is by [03:27.380 --> 03:33.500] default in most CDNs that looks for static extensions. So basically this is the list that [03:33.500 --> 03:39.160] Cloudflare has. And it will look for the path and the extension of that path. And if it [03:39.160 --> 03:43.900] ends with any of these eh extension, any of these strings, then it's going to decide that [03:43.900 --> 03:49.280] this is a static res- resource and it's going to store it in the in the web cache. So in [03:49.280 --> 03:54.180] this example we see that styles dot CSS ends with a static extension. And therefore it's [03:54.180 --> 04:00.280] going to be cached using the key that was calculated in the first step. Now whenever [04:00.280 --> 04:05.120] another client or even the same client sends a request to the same resource, the cache [04:05.120 --> 04:09.820] proxy is going to handle that, it's going to get the key of that request and then it's going [04:09.820 --> 04:14.440] to retrieve the res- the store resource because it doesn't need to interact with the [04:14.440 --> 04:19.980] original server. And that's basically how a web cache works. Now we can exploit this in [04:19.980 --> 04:25.360] many ways. The first one is usually is the first one I'm going to describe actually is the [04:25.360 --> 04:32.280] one that was discovered by Omer Gil in 2017 which is a web cache deception. And basically [04:32.280 --> 04:38.120] this attack is based on the idea that some backend servers use this special mapping where [04:38.120 --> 04:43.380] they are going to put some parameters in the path. This is called path parameters. And [04:43.380 --> 04:47.020] they are going to just look for the beginning of the path and they will try to match it with [04:47.020 --> 04:53.880] uh with any regex that is a relate- related with the handler. So in this case if we send a [04:53.880 --> 04:58.880] request to slash my account slash param one, param two, then only the first part is going to [04:58.880 --> 05:05.400] be used to map the end point. And then this in this case is going to the original server is [05:05.400 --> 05:08.800] going to generate a response which contains a lot of information from the victim because it [05:08.800 --> 05:15.220] is my account. And it contains for instance the mail or the credit card details. So [05:15.220 --> 05:22.180] basically this is what we want to steal. And to do so the first thing is to send uh a link to [05:22.180 --> 05:27.560] the victim. This requires user interaction. And the link will start with the end point that [05:27.560 --> 05:32.700] we want to steal the response. So in this case it's my account. And then it will use as a [05:32.700 --> 05:38.620] parameter a dot js. And the reason this is because first when it's handled by the [05:38.620 --> 05:43.800] origin server this is going to be mapped to my account using the cookies of the victim. And [05:43.800 --> 05:48.660] so the response with the sensitive information is going to be sent back to the to the proxy. [05:48.960 --> 05:54.660] And now with the cache proxy it will use the the path. This in this case it doesn't know [05:54.660 --> 05:59.180] anything about this mapping. So it will think that the last part is just a parameter is not a [05:59.180 --> 06:03.600] parameter sorry it's a path. It's part of a path. And therefore it will think that it has a [06:03.600 --> 06:08.820] static extension. In this case dot js. And so it will start this response containing all the [06:08.820 --> 06:13.760] secret information. Now the attacker can send the same request and as the cookies are not [06:13.760 --> 06:18.940] important as the only important thing is just getting the same path. Well the cache proxy is [06:18.940 --> 06:23.140] going to match it with the key that already calculated in the first place. And it will [06:23.140 --> 06:28.200] retrieve the victim's response containing all the secret information. Now the problem in [06:28.200 --> 06:32.840] this technique is that we need a special mapping for that. Basically we need this special [06:32.840 --> 06:37.420] my account thing. And then we also require that the parameters that we are sending in this [06:37.420 --> 06:43.140] case a dot js doesn't have any effect on the backend because if not maybe the the response is [06:43.140 --> 06:49.740] not going to contain that information that we want. So I started looking at different ways to [06:49.740 --> 06:54.220] obtain arbitrary web cache deception which is basically obtaining the same thing but for any [06:54.220 --> 07:00.720] kind of uh end point that we want. And to do this I started looking at how the the path is [07:00.720 --> 07:07.240] obtained at each state. So basically the path is obtained from a URL by using these delimiters [07:07.240 --> 07:12.600] which are basically characters that can then can be used to know where each part of the URL [07:12.600 --> 07:18.280] or each part of the elements of the URL start and begin uh and end. There are a lot of them [07:18.280 --> 07:23.600] defined by the RFC. So we can see that the URL has things like the scheme, the [07:23.600 --> 07:29.280] credentials, the host, the path query and fragment. So to split the each of them in a URL we [07:29.280 --> 07:35.520] need these these delimiters. The problem is that the RFC says that any any of these delimiters [07:35.520 --> 07:41.000] may or may not be or any of these characters may or may not be used as delimiters. And so [07:41.000 --> 07:47.220] each implementation can choose new delimiters and this could create some discrepancies. So [07:47.220 --> 07:53.060] let's say we find a server that is using a cache proxy and that is using the dollar sign as a [07:53.060 --> 07:58.420] delimiter. Then if we send a request to my account dollar sign eight dot JS this is just [07:58.420 --> 08:03.680] going to be interpreted as my account because of the delimiter. However as I said in the [08:03.680 --> 08:09.340] front end there's no delimiter being being said with uh the dollar sign and therefore this is [08:09.340 --> 08:13.320] going to be interpreted the entire URL is going to be interpreted as the path and the last [08:13.320 --> 08:18.320] part which is eight dot JS is going to be used as the extension. In this case actually it's [08:18.320 --> 08:23.240] dot JS the extension and so this is going to be stored in the cache just because of that [08:23.240 --> 08:28.340] delimiter. And in this case we can use it with any kind of path we want because we are not [08:28.340 --> 08:35.600] attacking a mapping we are attacking the entire way of obtaining the path from the URL. Now [08:35.600 --> 08:40.700] which kind of delimiters we can find in the well well there are a lot of them. Some I listed [08:40.700 --> 08:47.580] were in the frameworks is uh the first one is semicolon in spring so basically to define a [08:47.580 --> 08:54.440] matrix variable that is similar to a path a parameter we can use a semicolon. And the thing is [08:54.440 --> 09:00.400] that if we send something like my account semicolon eight dot JS anyone using Java probably [09:00.400 --> 09:05.740] Java in the well so they are going to consider this as my account. This includes Google or [09:05.740 --> 09:12.160] big companies that are using Java because this is how spring works. And so we can use this [09:12.160 --> 09:18.140] for the attack. Now in Rails there's another really interesting case which is they use the [09:18.140 --> 09:24.440] dot as a delimiter and that's because um the user is able to send an extension with a valid [09:24.440 --> 09:29.960] endpoint and this will the effect that this will have is that Rails will look for a specific [09:29.960 --> 09:35.860] view for that uh request. So let's say we define uh an endpoint which is my account and then [09:36.420 --> 09:41.660] when we send a request to my account Rails will just go and look for the HTML view. Now if [09:41.660 --> 09:47.880] we send something like my account dot CSS Rails will not just return a not a not found but it [09:47.880 --> 09:53.900] will look for the view of the the CSS view of my account. Usually there's no CSS view for my [09:53.900 --> 09:59.880] account so we'll just receive a 406 error. But the thing is that if the extension that we [09:59.880 --> 10:04.560] include is not recognized by Rails so let's say we send something like my account dot AAA [10:05.180 --> 10:11.640] then Rails is just going to send us the default view which is HTML. Remember all these [10:12.440 --> 10:16.920] extensions that are defined by Cloudflare. Well in green you can see the ones that are [10:16.920 --> 10:25.060] recognized by Rails. So if we send my account dot PNG or dot GPA or CSS then all of them are [10:25.060 --> 10:29.180] going to be recognized by Rails and it's going to try to look for that response and if there's [10:29.180 --> 10:35.600] no view for that extension then it's just going to return us an error. But in red we see all [10:35.600 --> 10:40.060] the other extensions that are not recognized by Rails. So we send something like my account [10:40.060 --> 10:45.160] dot ICO then we are going to get the default view but Cloudflare is going to think that this [10:45.160 --> 10:52.300] is a cacheable resource. Now there are other delimiters that can be used in HTTP servers [10:52.300 --> 10:57.660] instead of frameworks such as the encoded null byte which is the case of open light speed. So [10:57.660 --> 11:02.180] basically this works like a question mark if we send something in my account null encoded [11:02.180 --> 11:09.060] byte A dot JS then this is just going to be used as my account. The problem for this is that we [11:09.060 --> 11:13.920] cannot send it through many CDNs like Azure, Impairment, Cloudfront, Cloudflare, Google [11:13.920 --> 11:18.560] Cloud. That's because they don't accept null encoded bytes. But fortunately Akamai and [11:18.560 --> 11:26.320] Fast2DC yes so we can use them for eh this explanation. And finally in NGINX we have a [11:26.320 --> 11:33.220] delimiter whenever we define a rewrite rule and the delimiter is the new line encoded and so [11:33.220 --> 11:37.160] basically it works just as in open light with a null encoded byte and in this case we can send [11:37.160 --> 11:44.340] it through any CDN we want. So if we send a request using any of these delimiters with the [11:44.340 --> 11:49.000] correct with the corresponding eh backend then all of them are going to be interpreted as my [11:49.000 --> 11:54.300] account. The response is going to be sent back but in this case the web caches are going to [11:54.300 --> 12:01.640] just store that because of the static extension. But the problem with this attack is that many [12:01.640 --> 12:06.200] CDNs are are already aware of this and they are implementing some detection some [12:06.200 --> 12:10.680] protection for for this kind of attacks. In the case of Clover for instance is web cache [12:10.680 --> 12:16.680] deception armor which what it does is it looks for the extension of the request and the [12:16.680 --> 12:21.380] content type of the response. And if they don't match for for instance in this example we are [12:21.380 --> 12:28.080] using dot CSS as the extension and the content type is text HTML so if they don't match [12:28.080 --> 12:34.740] basically this is an attack and Clover won't store this in the cache. So we can attack other [12:34.740 --> 12:40.940] rules like the static directories one. That's a rule that we can create as users that states [12:40.940 --> 12:45.780] that anything starting with a specific path is going to be stored in the cache and that's [12:45.780 --> 12:50.580] really common in many applications because we we usually store static files in the same [12:50.580 --> 12:56.660] directory like share, public, assets, resources, anything that you can think. And so we can [12:56.660 --> 13:01.900] use this to attack this kind of eh this kind of web caches that are used in the rules. To [13:01.900 --> 13:07.340] create an attack in this case we will need some payload that is interpreted in the front end [13:07.340 --> 13:12.700] with the static directory at the beginning so basically if the static directory is called [13:12.700 --> 13:19.140] static then we want the path to start with static slash and anything we want. And then in the [13:19.140 --> 13:24.240] backend we still want my account because we in this case want to steal my account we could [13:24.240 --> 13:30.560] steal anything else we want. So if we have a delimiter in the backend we can try to do this [13:30.560 --> 13:36.980] but we will need something else. And as I said to extract the path from a URL we just need [13:36.980 --> 13:41.760] the delimiter and then that path is used in the keys rules and mapping. Well not really [13:41.760 --> 13:47.640] there's one extra step which is normalization. We need to normalize the path and most [13:47.640 --> 13:54.120] CDNs and backend servers do normalize the path. This includes decoding the characters. We can [13:54.120 --> 14:01.140] send them with URL encoded uh notation that is percentage uh and the XML value of a [14:01.140 --> 14:07.040] character. And then in some cases the uh other characters like segment delimiters like the [14:07.040 --> 14:13.160] slash or the dot are also going to be decoded. So this is going to be really useful. And [14:13.160 --> 14:19.200] then the normalization also includes dot segments uh resolution which is just resolving [14:19.200 --> 14:23.980] path traversals and whenever we find a dot segment then we just remove the previous segment. [14:24.460 --> 14:32.720] And some parsers like the IIS one uh will also convert backslashes to slashes. So now that we [14:32.720 --> 14:37.380] know this we can actually create a new payload that is going to use normalization. Again we [14:37.380 --> 14:41.720] are using a delimiter so everything before the delimiter is going to be interpreted in the [14:41.720 --> 14:48.140] backend server. But now we are also sending an encoded uh path traversal. And that is [14:48.140 --> 14:53.960] because the frontend is not using the delimiter so it's going to resolve this into this. And [14:53.960 --> 15:00.500] this includes a path traversal which is going to convert it to static WCD. So now in the [15:00.500 --> 15:05.100] frontend we see that there are static directories there so this is going to be stored in the [15:05.100 --> 15:10.340] webcache. And in this way we are able to bypass the webcache deception armor because there's [15:10.340 --> 15:18.400] no extension so nothing to convert. Now let's see how how we can how we can apply this in a [15:18.400 --> 15:26.340] real environment. And so first we need uh a frontend that is normalizing the path. Sorry. Uh [15:26.340 --> 15:32.080] this is the case for CloudFront, Imperva and Azure. And so if we combine them with any [15:32.080 --> 15:37.420] backend that is using a specific delimiter like for instance Tomcat, then we can send the [15:37.420 --> 15:44.000] same the same payload which is secret the semicolon with that represented delimiter. And [15:44.000 --> 15:49.100] this will cause that in the backend we see secret. And in the frontend again the [15:49.100 --> 15:54.560] semicolon is not a delimiter for either CloudFront, Azure or Imperva and therefore this is [15:54.560 --> 16:01.200] going to be resolved to static slash X. And this way we will be able to steal any response we [16:01.200 --> 16:07.100] want in an environment that is using basically a default configured Tomcat and any of the [16:07.100 --> 16:14.760] CDNs that I showed. This can be used also with other backends like uh Rails and Puma or even [16:14.760 --> 16:19.860] some in the same case that we observed in the in the first example when we had a special [16:19.860 --> 16:25.200] mapping in the backend. In this case there is no delimiter, the delimiter is just the the [16:25.200 --> 16:33.600] path that we are attacking. Now we could also try another attack that is using the opposite [16:33.600 --> 16:37.440] normalization so basically in the frontend we don't have normalization, that's the case of [16:37.440 --> 16:43.020] CloudFront, uh Google Cloud Platform and Fastly. And in the backend we have normalization [16:43.020 --> 16:51.000] in Nginx, IIS and open light speed. So if we use this, we can create the attack by starting [16:51.000 --> 16:56.840] with the static directory. In this case it's slash static. And this is because the path is [16:56.840 --> 17:02.360] not normalized and so CloudFront for instance will think that this is the entire URL is the [17:02.360 --> 17:08.700] path. But in the backend this is going to be normalized and therefore anyone using Nginx or [17:08.700 --> 17:14.780] IIS or open light speed is going to see that their response is going to be for secret and [17:14.780 --> 17:21.200] this will be storing the cache because of the static path. This worked on OpenAI and many [17:21.200 --> 17:30.060] other bounties that I wasn't able to be, I'm not able to talk about. And also this can be [17:30.060 --> 17:36.520] used with IIS, basically IIS is the only one that is decoding uh normalizing the backslash. So [17:36.520 --> 17:41.960] if we send something like using the, in the slide, this is going to be converted to static [17:41.960 --> 17:46.500] and basically a dot segment with a backslash and it's going to be converted to account in [17:46.500 --> 17:53.460] IIS but not in any other uh CDN because IIS decided that this is a cool idea. And so yeah, [17:53.460 --> 17:59.980] they are the only ones that I can be attacking with any other CDN. Now if we don't find [17:59.980 --> 18:03.960] one of these rules, well there's, there's another rule that we can use which is the static [18:03.960 --> 18:12.120] files. And in many, in many CDNs we will see that there's a static file rule by default to [18:12.120 --> 18:18.120] store robots dot txt but we can also find others for favicon or for index dot html or for [18:18.120 --> 18:24.620] any, any file that is usually accessed by people and is static. And in this case we can use [18:24.620 --> 18:29.060] the same attack only that we are not going to target a static directory, we are just going [18:29.060 --> 18:35.180] to target something that is being stored by the front end. So we can do something like [18:35.180 --> 18:41.620] secret then the, the limiter, the encoded dot segment and finally robot dot txt and this [18:41.620 --> 18:47.020] should work in many, in many applications. And also we can try to find other files. I found [18:47.020 --> 18:51.880] that there are many in the, in, in the wild so you should be able to find many others if you [18:51.880 --> 18:59.040] look for. So webcast deception is pretty cool but the thing is you need user interface [18:59.060 --> 19:04.320] interaction and we don't really want user interaction. So webcast poisoning is there for [19:04.320 --> 19:10.200] rescuers and the idea in webcast poisoning is that we are going to try to store a malicious [19:10.200 --> 19:16.160] response in, in a, with a key that is going to be accessed by other people. So let's say we [19:16.160 --> 19:22.220] want to hijack someone that is using this, this website, this website and is accessing through [19:22.220 --> 19:26.440] the home page. Well if we are able to find a payload that is stored in the home page then [19:26.440 --> 19:31.840] everyone navigating through the web page is going to be affected. And usually you will look [19:31.840 --> 19:36.260] for something that is not stored, like that is not using the key so in this case if the cookie [19:36.260 --> 19:42.180] value is reflected in the, in the body of the response then we are able to store this and [19:42.180 --> 19:48.160] anyone using the home page is going to be affected and is going to re, is going to retrieve [19:48.160 --> 19:54.600] the malicious response. The problem with this attack is that in many cases we will find a, an [19:54.600 --> 19:59.840] example of a cache poisoning but it's with a, it's using a key or it's using a resource that [19:59.840 --> 20:03.740] is not going to be accessed by anyone. Like for instance if we are able to poison something [20:03.740 --> 20:08.940] that starts with files then our user name and then a unique ID, no one is going to be [20:08.940 --> 20:15.840] accessing that uh, that path by themself. So we will need user interaction. And that's not [20:15.840 --> 20:23.160] really cool. So to avoid having to interact with any victim, I designed an attack that is [20:23.160 --> 20:30.460] going to be able, it's going to allow us to change the key of the uh, poison resource. Now in [20:30.460 --> 20:35.200] this case we will need key normalization and this is by default in impaired but Azure is just [20:35.200 --> 20:40.860] normalizing the key. Uh, and it's partially by default also in Akamai and it's configured in [20:40.860 --> 20:46.360] all the other CDNs and what's really interesting about this is that if you remember Cloud [20:46.360 --> 20:50.860] Front for instance was normalizing the rules but it's not normalizing the key. So that means [20:50.860 --> 20:56.000] that they have different parsers for each of these processes which is even in the same uh, [20:56.000 --> 21:01.800] in the same HTTP parser probably. So this, this tell us that we can even find other [21:02.400 --> 21:08.480] desynchronization attacks or other discrepancies even in the same uh, in the same web cache. [21:09.160 --> 21:15.920] So as I said, what we need is uh, a front end that is normalizing the key and what we can do to [21:15.920 --> 21:20.740] detect this is to send a request to a static resource like style dot CSS and whenever we [21:20.740 --> 21:24.520] see evidence that this is of being obtained from the web cache, so for instance we have an [21:24.520 --> 21:32.320] X cache hit value uh, hitter or we can just compare the time of the response and whenever we [21:32.320 --> 21:37.660] find this then we need to modify the path so that when normalized we still have style dot [21:37.660 --> 21:42.800] CSS and if we send this request and the response is still from the cache then it means that the [21:42.800 --> 21:50.020] key was normalized and so we detected key normalization. And how we can exploit a web [21:50.020 --> 21:55.140] cache poisoning with this, well basically we will try to modify as I said the key by sending [21:55.140 --> 22:00.360] first the exploit that we want so this is the, the uh, the response that we will, we will use [22:00.360 --> 22:06.100] to poison. Uh, usually contains a malicious payload. Then a delimiter, so again we will [22:06.100 --> 22:10.440] need a delimiter in the back end, but as I said this is really common and we can find them [22:10.440 --> 22:16.800] almost anywhere. And then we will need some normalization in the front end, so in [22:16.800 --> 22:22.720] Burba, Azure, and sometimes Akamai and all the others that are configured. Uh, and this is [22:22.720 --> 22:27.040] going to be a result of poison. So basically the web cache is going to store the exploit [22:27.040 --> 22:31.480] response in the poison end point which is something we control so it's arbitrary, we can [22:31.480 --> 22:41.650] just wire up a path we want, usually the home page. So in the, in the first example I didn't [22:41.650 --> 22:46.290] talk about one of the delimiters because we weren't able to send it with web cache [22:46.290 --> 22:51.170] deception and that's because the user needs to send it through his browser and anything [22:51.170 --> 22:57.290] but uh, and if the browser sees a hash, then it's not going to send the fragment. But in web [22:57.290 --> 23:02.990] cache poisoning we can use the fragment. So I, I started looking at different, at the [23:02.990 --> 23:08.270] behavior of different CDNs and HTTP servers and even frameworks in regarding the, the [23:08.270 --> 23:14.230] hash. And I found that there were a lot of differences. The most interesting one was again [23:14.230 --> 23:19.050] in purple because there were no likes in the key. A cloud front, well sorry, cloud front [23:19.050 --> 23:23.990] can be configured to, to do the same thing so it's interesting to see they are too. And [23:23.990 --> 23:31.110] basically if we have a hash and a, and key normalization then we can use in purple for, for [23:31.110 --> 23:35.910] this exploit that I'm going to show. And in the backend we can use pretty much any HTTP [23:35.910 --> 23:40.410] server like NGINX, Unicorn, Puma, then we can use also frameworks like Rails, Flash, [23:40.410 --> 23:47.010] they are not going to see the hash as a delimiter. Sorry, they are going to see the hash as a [23:47.010 --> 23:53.410] delimiter. And so basically we can send an attack that uses the hash. First we are going to [23:53.410 --> 23:57.330] send what we want to be interpreted in the backend because it's going to be using the [23:57.330 --> 24:02.970] hash. And so if we send something like this, then the XSS is going to be interpreted as the [24:02.970 --> 24:07.130] path in the backend. It's going to retrieve, retrieve the response, the malicious response. [24:07.130 --> 24:12.250] And now this is going to be normalized, the key, so we will be able to poison the homepage [24:12.250 --> 24:20.410] with any, any webcache poisoning eh, payload that we have. This was found in Vista, MasterCard [24:20.410 --> 24:28.150] and T-Mobile and again many others that I'm still unable to talk about. And of course we can [24:28.150 --> 24:36.710] use the same attack for with eh, Azure in purple and also with Tomcat, with Rails, with NGINX, [24:36.710 --> 24:42.110] with eh, new line encoded. And also again with any backend that is using a special [24:42.110 --> 24:48.150] mapping. So it should be pretty easy and I already saw many people exploiting this eh, since [24:48.150 --> 24:54.750] I give this talk in black hat so it seems like there are a lot of targets. Now we can do [24:54.750 --> 24:59.570] similar, a similar thing with Azure, only in this case Azure is considering the front, the [24:59.570 --> 25:08.070] hash as a delimiter and this is not the case for OpenLaySpeed, Express and Django. So what [25:08.070 --> 25:12.990] we are going to do is we're going to send a payload that in this case starts with what we [25:12.990 --> 25:18.470] want to poison, so the keys, the beginning and that's because the front end is using the [25:18.470 --> 25:24.250] hash as a delimiter. Then the rest is going to be normalized and we have the exploit. And [25:24.250 --> 25:30.170] again we can poison any path we want that is using Azure and OpenLight or other [25:30.170 --> 25:34.910] frameworks. There are other examples but as I, in this research I wasn't able to look for [25:34.910 --> 25:43.090] all, all servers but yeah. And this was found again in OpenAI so yeah, they, they acted [25:43.090 --> 25:46.950] really fast and they fixed the issue which I'm not sure, really sure how they fixed because [25:46.950 --> 25:55.730] it's still there. And, and so what if we don't have a payload? So let's say we don't have [25:55.730 --> 26:01.090] anything that we can use to poison a malicious response. We only, we are only able to [26:01.090 --> 26:06.630] change the keys. Well, we still can do something. We can start poisoning all the paths [26:06.630 --> 26:12.970] with a static file. So let's say we use status.css, this will poison every single path and [26:12.970 --> 26:17.790] so when a user sends a request to home, my account or any other path, he will just get CSS [26:18.430 --> 26:23.490] and therefore a denial of service. Which many companies think that this is not a vulnerability. [26:26.070 --> 26:32.270] So, sorry. So we already saw how we can poison anything we want and how we can change the [26:32.270 --> 26:39.590] key so it's just combining those ideas to create a very useful payload. And the first thing [26:39.590 --> 26:44.810] we need to do to store everything, anything we want in anywhere is to identify a malicious [26:44.810 --> 26:50.170] response that we want to use. And this malicious response, the, the, what's interesting [26:50.170 --> 26:54.270] about this attack is that we are going to combine both so the response doesn't need to be [26:54.270 --> 26:58.710] uh, cacheable. So we can use anything we want. In this case we are going to use an open [26:58.710 --> 27:03.310] redirect which is not stored, which is not cacheable and therefore is, is not a [27:03.310 --> 27:08.490] vulnerability. You can't report this to anyone because it's really not a vulnerability. Then [27:08.490 --> 27:14.790] we need to choose what we are going to poison and what I usually recommend is to poison some [27:14.790 --> 27:19.530] script that is being included in uh, in any web page, usually the home page. So in this [27:19.530 --> 27:24.790] case we have a home page that is uh, loading a main.js script. So we are going to poison [27:24.790 --> 27:30.730] that with an open redirect. Why? Well because first, as I said, we are going to use this [27:30.730 --> 27:35.450] technique. In this, in this example, this demo I'm going to show it using Azure and Tomcat. I [27:35.450 --> 27:42.390] finished coding this, this morning so it could work, it could not work. But uh, the thing is if [27:42.390 --> 27:46.970] we send something that starts with, in this case logout which is the open redirect, then the [27:46.970 --> 27:50.770] semicolon which is the delimiter, this is going to be interpreted as logout using the [27:50.770 --> 27:56.550] x forwarded host header which is going to show, to show, to send the, the victim to the [27:56.550 --> 28:03.610] evil.com. And then this is going to be normalized so we are going to poison main.js and this [28:03.610 --> 28:09.250] is because it has a static extension. So even if the operator wasn't storable by default, [28:09.250 --> 28:14.430] well we have the static extension so we are able to poison main.js using this attack. Now [28:14.430 --> 28:20.730] when a user loads the home page, he will again load the main.js script and when this [28:20.730 --> 28:27.650] request is uh, is received by the, by Azure, he will just send the open redirect which will [28:27.650 --> 28:33.230] redirect the victim to the evil.com server, will load the malicious JavaScript and we will [28:33.230 --> 28:39.250] be able to poison any, any victim with a malicious script that we completely control. And [28:39.250 --> 28:44.890] if we have the content security policy enabled to provide, to avoid this kind of attacks, [28:44.890 --> 28:49.690] then we can use something like CSX exfiltration to obtain anything we want. You can ask [28:49.690 --> 29:03.870] Gareth about that, he knows a lot. And so yeah, this is the demo. Uh, so yeah, so this is [29:03.870 --> 29:11.810] the web page. This is using Azure right now. And maybe this is, yeah, this is loading, [29:11.810 --> 29:18.670] perfect. Internet. Uh, so when we send a request to the home page, which is caches, cache [29:18.670 --> 29:27.270] all Azure blah blah. Don't hack it right now please. Uh, yeah. So we see that the main.js is [29:27.270 --> 29:39.030] being imported. So that's what we want to attack. This is main.js. Yeah. Main.js is being [29:40.190 --> 29:46.010] obtained from the cache right now. So it's going to last 20 seconds. I said 20 seconds [29:46.010 --> 29:50.230] probably is going, in a real application is going to be a day, maybe some days. So you will [29:50.230 --> 29:56.790] need to wait for that to stop doing, you can just use uh, an intruder session. Now, this is [29:56.790 --> 30:05.600] the open redirect that we are going to use. This is the evil.com. And as you can see, this [30:05.600 --> 30:11.000] is being, this is an open redirect that is not being cacheable. Config no cache means no [30:11.000 --> 30:20.780] cacheable. This is the evil.com server that is going to load our arbitrary javascript. And this [30:20.780 --> 30:26.420] is the exploit. Now I'm going to try to code it by myself. So again, the exploit is going to [30:26.420 --> 30:32.460] work like this. First we put the thing that we want to, to log. So this is going to be used in [30:32.460 --> 30:40.600] the backend. Logout. Logout is the open redirect. Then the semicolon to um, to use as a [30:40.600 --> 30:48.480] delimiter. Now, because the way that java use semicolons is uh, is uh, semicolons only work [30:48.480 --> 30:52.460] for a segment so we cannot put a slash after the semicolon because it's not going to be, it's [30:52.460 --> 30:57.640] not going to work. So we need to send the slashes and everything encoded in this case. So [30:57.640 --> 31:10.090] this is a slash encoded. This is a dot encoded. Yeah, the dot segment encoded. And then we [31:10.090 --> 31:20.890] will put what we want to poison which is main.js. And it seems we are lucky enough. Yeah. So [31:21.410 --> 31:27.110] first, as you, if you observe, the first time we got a miss, so nothing there. Now we got a [31:27.110 --> 31:34.290] hit. So it seems it worked. So if we load, if we try to get the main.js now, instead of [31:34.290 --> 31:43.890] getting the js that we had, we have an open redirect. So now, if we load, let's try this. [31:45.930 --> 31:54.850] Wow. Let's do it again. The problem is the time because, yeah, so I need to wait the 20 [31:54.850 --> 32:09.490] seconds for this to stop being cached. Unfortunately. C cached. So as you see, I'm [32:09.490 --> 32:14.270] getting the main.js, that's because it's being resolved the key and I'm getting the restore [32:14.270 --> 32:23.010] resource right now. But right now it worked. So okay, so now if I go, I do this, this is going [32:23.010 --> 32:45.290] to do everything that we saw. And it's good. Okay. I'm running out of battery. Okay, so I have [32:45.290 --> 33:01.910] time for this secret demo. Yeah. Okay, so we already saw how we can use different [33:01.910 --> 33:07.530] discrepancies between URL parsers to exploit web caches. But there are other kind of [33:07.530 --> 33:11.030] discrepancies where you can use, and there are many other discrepancies that I didn't [33:11.030 --> 33:18.850] research on, but probably you can look for them. One of them is the HTTP 0.9 smuggling. And [33:18.850 --> 33:23.910] basically, I trust that most of you already know what HTTP is, the basic protocol that we [33:23.910 --> 33:29.830] use every day to communicate in the internet. But, and probably you already know the [33:29.830 --> 33:39.350] really new HTTP 3, the still new HTTP 2, the classic HTTP 1.1 and even HTTP 1.0. But maybe you [33:39.350 --> 33:46.330] don't know that there's HTTP 0.9. 0.9 is basically a legacy protocol that shouldn't be [33:46.330 --> 33:53.370] used by anyone unless you are NGINX, Apache, IIS or any other HTTP server in the world. And [33:53.370 --> 33:59.490] the thing with HTTP 0.9 is that we don't have any headers, so no header for requests, no [33:59.490 --> 34:05.270] header for responses. And the connections are not persisted, the responses of course [34:05.270 --> 34:13.850] shouldn't be cacheable. So this is basically a basic 1.1 request, a HTTP 1.1 request. We [34:13.850 --> 34:19.950] send a request to home, we get a response, nothing strange. Now if we remove the HTTP [34:19.950 --> 34:27.490] version and we just send get, and the URL, the entire URL, then we will receive a 0.9 [34:27.490 --> 34:33.230] response if we are targeting NGINX, as I said, Apache, IIS, Tomcat, any HTTP server [34:33.230 --> 34:38.730] basically. You will just get the response which is the body. If you send something like this, [34:38.730 --> 34:49.150] still HTTP 0.9. If you send this, 0.9. And if you send this, 0.9. So why is this interesting [34:49.150 --> 34:54.750] at all? Well browsers are a little bit smarter than others and they knew that it doesn't [34:54.750 --> 34:59.990] make sense to keep talking this uh this old protocol, so you cannot send a 0.9 request [34:59.990 --> 35:05.870] through browsers. So most of the attacks are discarded just because of that. But let's see [35:05.870 --> 35:11.250] what happens if the front end and the back end are not doing the same thing or they don't [35:11.250 --> 35:18.050] talk the same protocol. So if we send a request like an HTTP 0.9 request and we send it [35:18.050 --> 35:27.650] through a CDN, most CDNs will take this request and they will upgrade it to HTTP 1.1. So then [35:27.650 --> 35:35.370] the back end will just generate a 1.1 response, the body will be extracted and sorry, the [35:35.370 --> 35:41.710] response will be actually downgraded and we will just be left with the body. And this works [35:41.710 --> 35:48.370] basically even if no one should be using 0.9, this works because if the upgrade and [35:48.370 --> 35:55.330] downgrading is done correctly then this works. And also connections are not persistent so a [35:55.330 --> 36:01.130] lot of attacks are also discarded because of that. But the interesting thing is that some [36:01.130 --> 36:07.730] CDNs such as Imperva, they don't verify the HTTP version before forwarding a request. So if [36:07.730 --> 36:12.750] we send a request, a 0.9 request, Imperva will say well I will just forward it, I don't [36:12.750 --> 36:18.990] care. And the problem is Imperva is not just going to forward it, it's going to think that [36:18.990 --> 36:26.690] this is a 1.1 request because Imperva doesn't know about 0.9. And the back end will send a [36:26.690 --> 36:33.350] body because it's 0.9 and so no headers. And now Imperva is going to try to use this as a [36:33.350 --> 36:38.310] response. And probably it's going to fail. And so you are not going to see a lot of valid [36:38.310 --> 36:43.550] responses because of the parsing. Because when Imperva tries to parse a body of a response [36:43.550 --> 36:49.390] that doesn't contain valid HTTP headers then this is going to be interpreted as an error. But [36:49.390 --> 36:56.670] what if the body does have these valid HTTP response headers? So let's say we have a [36:57.190 --> 37:03.610] upload download file feature or let's say we can control the body of a plain text or let's say [37:03.610 --> 37:09.910] we are even able to modify the response using byte range or something like that. Then if by [37:09.910 --> 37:14.770] any means we are able to control the response, then the body of the response no matter what [37:14.770 --> 37:22.250] the content type, no matter anything, then we will be able to use this attack. Again this [37:22.250 --> 37:34.250] demo, I hope it works. Um, okay, yeah. So in this super page, web page I created an upload [37:34.250 --> 37:42.750] file feature. Okay. And in this upload file feature we can upload any file we want. In this [37:42.750 --> 37:51.430] case an evil file that if you want to see it, well it's really really small but basically it's a [37:51.430 --> 37:56.690] response containing a script and containing a cache control header. Probably you can't [37:56.690 --> 38:02.050] see it. But yeah, it contains a cache control header saying that it should be stored for 10 [38:02.050 --> 38:12.010] seconds I think. Let's put 100 seconds. And so when I upload this, I will also be able to [38:12.010 --> 38:21.410] retrieve this. So it seems like it was uploaded. So let's go back to burp. Okay. And [38:23.630 --> 38:28.730] so, okay, so this is the file that I uploaded. Okay, let's say we have this upload download [38:28.730 --> 38:37.050] feature which is pretty common in many applications. And this works. Yeah. As you can see, I [38:37.050 --> 38:42.330] uploaded this file which in the body we have a valid HTTP response. Containing headers, [38:42.330 --> 38:51.410] containing everything we want. Now, if I send an, let's say I send a, an HTTP 0.9 request, [38:51.430 --> 39:00.000] which is basically this request that doesn't contain any header here. As you can see, [39:00.000 --> 39:04.980] Imperva sends, says that it's an error because it was trying to load the home page as a [39:04.980 --> 39:13.000] 0.9. It was trying to parse the response body of the home page as 0.9. Failed. Okay. Now, what [39:13.620 --> 39:24.620] if we send the same but for this response? And as you can see, Imperva thinks that this is a [39:24.620 --> 39:30.420] valid response. It's actually using the cache control header. And it's contain, it's putting [39:30.420 --> 39:36.720] everything. It's also including his own header so it seems like it's working. So, yeah, we [39:36.720 --> 39:41.560] can poison this file. Great. So someone that is accessing this file is going to receive this [39:41.560 --> 39:47.220] response and is going to be attacked. Now, not really cool. So we can use something that I [39:47.220 --> 39:52.500] just explained which is modifying the old cache key. Again, we can use the request to the [39:52.500 --> 39:57.800] thing that we want to store. Then the cache, in this case we are using Imperva. Imperva [39:57.800 --> 40:02.620] doesn't think that the cache is a, is a delimiter. Ah, this, sorry, this time we are using [40:02.620 --> 40:11.340] Imperva and Nginx. And the, then we have a path reversal. I added a few slashes because it's the [40:11.340 --> 40:20.220] way to avoid being detected as an attack by many CDNs. And so I have this path reversal that [40:20.220 --> 40:25.600] removes the files, removes the abl5.txt and so basically the path is going to be converted [40:25.600 --> 40:31.880] to the home page which is indexed. And so we are going to poison the index. So if we send [40:31.880 --> 40:39.040] this, I will have a little bit of luck. Yeah, it seems it's working because the second time was [40:39.040 --> 40:53.200] obtained from the cache. So now if I go back to the home page, it's not working. Ah, sorry, I [40:53.200 --> 40:58.980] this was, eh, this was the Azure one. This is the Imperva one, fortunately. So if we go to [40:58.980 --> 41:22.590] Imperva, arbitrary cache. Okay, so how we can defend against these kind of attacks? Well, [41:22.590 --> 41:29.650] first we need to use the, eh, cache control header for web cache deception. So whenever we [41:29.650 --> 41:34.550] have a response that we don't want to, anyone to store it, then just use private and no [41:34.550 --> 41:39.750] store for the, for the cache control header. But also, eh, I wasn't able to show it in the [41:39.750 --> 41:44.770] example but there are many CDNs that will override this cache control header if there's a [41:44.770 --> 41:51.070] rule for the path. So sometimes the rules for the request have priority and therefore it's [41:51.070 --> 41:55.990] important to check if this is happening. If this is happening, try to modify this and if it's [41:55.990 --> 42:02.370] not possible, then try to consider using another CDN. And then, eh, for cache poisoning, [42:02.370 --> 42:07.030] well, we can try to abort, to disable the key normalization. In some cases it's possible, in [42:07.030 --> 42:11.870] some cases it's not. So in those cases, I suggest using the tool that I will provide that [42:11.870 --> 42:17.030] will let you know if there's any discrepancy between normalization and, eh, delimiters and [42:17.030 --> 42:21.390] anything. So this will allow you to know if you need to change either your HTTP server or [42:21.390 --> 42:28.430] your, eh, front end server. These are all the references, eh, for the reason I, I use all [42:28.430 --> 42:34.390] this information. All the other attacks that inspired me. And also, in the slide you have [42:34.390 --> 42:40.070] the, eh, the links for the cache poisoning and cache deception academy topics. We just [42:40.070 --> 42:46.290] released the academy topic for deception. And also the extension for cache killer, which is [42:46.290 --> 42:52.350] the, the extension I created for, to detect this. It's still in progress, eh, it should work, [42:52.350 --> 42:57.570] but I will, I will keep working on, on this, on this tool for the next probably month or two. [42:57.570 --> 43:04.530] And the takeaways, basically I showed that we can use any kind of discrepancy we, we find in [43:04.530 --> 43:09.610] the, in the wild to exploit, eh, different servers using web cache. So web cache poisoning [43:09.610 --> 43:14.390] and deception, eh, can be used in many, many cases wherever we find these kind of [43:14.390 --> 43:21.250] discrepancies. Then we can use the exploitation things in many bounties because I found that [43:21.250 --> 43:26.130] these kind of delimiters are being used in many systems. So I invite you to look for them in [43:26.130 --> 43:30.710] different bounties and collect them and send me a message to just add you in the list of [43:30.710 --> 43:37.090] people that are using this. And finally, eh, I found, I showed you a way of chaining these [43:37.090 --> 43:41.570] vulnerabilities but you probably can think of many other ways to combine them with different [43:41.570 --> 43:46.410] vulnerabilities. Probably to upgrade vulnerabilities that are not really useful and [43:46.410 --> 43:53.490] probably to be, to get better payments in bad bounties. So I hope this helps everyone. And [43:53.490 --> 43:54.910] that's it. Thank you.