WEBVTT

00:00.000 --> 00:03.800
Uh welcome to track two, talk number two on Saturday.

00:03.900 --> 00:10.740
Uh this morning we uh have Martin and he's gonna talk about breaking the rules of web cache exploitation.

00:10.740 --> 00:11.800
So are you ready Martin?

00:11.800 --> 00:12.440
I'm ready.

00:12.440 --> 00:13.960
Let's hear it for Martin.

00:18.000 --> 00:19.120
Thank you.

00:19.120 --> 00:20.140
Hello everyone.

00:20.140 --> 00:23.580
Welcome to Gara Cache Mall, bending the rules of web cache exploitation.

00:27.160 --> 00:29.200
Uh it's already not working.

00:29.600 --> 00:32.780
So this is the agenda for today.

00:32.780 --> 00:49.340
First I'm going to briefly explain how a web cache works and then I'm going to show how we can abuse some discrepancies between the URL parsers of HTTP servers and cache proxies in order to steal secret information from victims using arbitrary web cache deception.

00:49.440 --> 00:59.940
Next I'm going to show how you use the same techniques or similar techniques to obtain arbitrary web cache poisoning by modifying the keys of a store resource.

01:00.300 --> 01:10.400
Then I'm going to combine both techniques in order to store whatever I want in the web cache with any key so this will allow us to create a full defacement of a website.

01:10.600 --> 01:16.920
And finally I'm going to present some protections that can be used to defend against those attacks and it takes hours of the session.

01:18.700 --> 01:37.860
So before I start, eh I want to clarify that most of the or all the examples are going to be based on CDNs like Cloudflare, Cloudfront, Akamai, but the idea is that you can use all of these techniques with any HTTP with any web cache eh proxy or with any web cache that you want even those that are included in the HTTP server.

01:38.980 --> 01:52.900
So whenever someone sends a request to a website using a web cache, basically the first thing that is going to happen is that the cache proxy is going to handle the request and is going to try to generate the response without having to communicate with the origin server.

01:53.320 --> 02:13.500
And this is going to be done by calculating a key and this key is basically an identifier of the request that states which is the resource that is being requested and it's not really important other things like the, the heaters like cookies or user agent because when we have two requests that are looking for the same resource and that resource is static,

02:13.500 --> 02:18.420
then we just need to provide the resource and we don't care about processing anything else.

02:18.420 --> 02:26.060
So we will see that the keys are just URLs and host names and in this talk we will just focus on the URL.

02:27.080 --> 02:42.700
So when the cache proxy calculated this key and is looking for a response that can be served eh to this request, he will look at the cache table and if there's nothing there, it will send the request to the origin server.

02:42.980 --> 02:50.320
Now the origin server is going to parse the URL, obtain the path and then it's going to use an endpoint to resolve the request.

02:50.320 --> 02:57.700
Sometimes it's just a static endpoint like a file and sometimes it's a dynamic one that is generated by a program back net.

02:57.880 --> 03:09.300
So when this response is sent back to the cache proxy, the well the cache proxy is going to generate to evaluate some rules to see if this response should be stored in the cache.

03:09.300 --> 03:11.060
So if it's static or not.

03:11.880 --> 03:24.400
These rules are usually evaluated on the response using the cache control heater but also in the request the cache proxy is going to extract the path and it's going to evaluate it with some of the other rules.

03:24.400 --> 03:31.500
For example the static extension one which is by default in most CDNs that looks for static extensions.

03:31.500 --> 03:34.680
So basically this is the list that Cloudflare has.

03:34.680 --> 03:38.420
And it will look for the path and the extension of that path.

03:38.500 --> 03:48.000
And if it ends with any of these eh extension, any of these strings, then it's going to decide that this is a static res- resource and it's going to store it in the in the web cache.

03:48.700 --> 03:53.280
So in this example we see that styles dot CSS ends with a static extension.

03:53.460 --> 03:57.900
And therefore it's going to be cached using the key that was calculated in the first step.

03:59.300 --> 04:15.480
Now whenever another client or even the same client sends a request to the same resource, the cache proxy is going to handle that, it's going to get the key of that request and then it's going to retrieve the res- the store resource because it doesn't need to interact with the original server.

04:16.160 --> 04:18.420
And that's basically how a web cache works.

04:18.420 --> 04:20.920
Now we can exploit this in many ways.

04:20.920 --> 04:31.680
The first one is usually is the first one I'm going to describe actually is the one that was discovered by Omer Gil in 2017 which is a web cache deception.

04:31.760 --> 04:41.600
And basically this attack is based on the idea that some backend servers use this special mapping where they are going to put some parameters in the path.

04:41.640 --> 04:43.180
This is called path parameters.

04:43.180 --> 04:52.200
And they are going to just look for the beginning of the path and they will try to match it with uh with any regex that is a relate- related with the handler.

04:52.380 --> 05:01.160
So in this case if we send a request to slash my account slash param one, param two, then only the first part is going to be used to map the end point.

05:01.660 --> 05:09.940
And then this in this case is going to the original server is going to generate a response which contains a lot of information from the victim because it is my account.

05:10.160 --> 05:15.140
And it contains for instance the mail or the credit card details.

05:15.140 --> 05:17.420
So basically this is what we want to steal.

05:18.920 --> 05:22.840
And to do so the first thing is to send uh a link to the victim.

05:22.840 --> 05:24.700
This requires user interaction.

05:24.900 --> 05:29.500
And the link will start with the end point that we want to steal the response.

05:29.500 --> 05:31.280
So in this case it's my account.

05:31.340 --> 05:34.900
And then it will use as a parameter a dot js.

05:35.380 --> 05:43.120
And the reason this is because first when it's handled by the origin server this is going to be mapped to my account using the cookies of the victim.

05:43.620 --> 05:48.660
And so the response with the sensitive information is going to be sent back to the to the proxy.

05:48.960 --> 05:52.340
And now with the cache proxy it will use the the path.

05:52.680 --> 05:56.140
This in this case it doesn't know anything about this mapping.

05:56.140 --> 06:00.640
So it will think that the last part is just a parameter is not a parameter sorry it's a path.

06:00.640 --> 06:01.660
It's part of a path.

06:01.680 --> 06:04.300
And therefore it will think that it has a static extension.

06:04.300 --> 06:05.960
In this case dot js.

06:06.280 --> 06:09.660
And so it will start this response containing all the secret information.

06:10.040 --> 06:17.380
Now the attacker can send the same request and as the cookies are not important as the only important thing is just getting the same path.

06:17.640 --> 06:22.100
Well the cache proxy is going to match it with the key that already calculated in the first place.

06:22.200 --> 06:26.500
And it will retrieve the victim's response containing all the secret information.

06:27.300 --> 06:31.060
Now the problem in this technique is that we need a special mapping for that.

06:31.060 --> 06:34.180
Basically we need this special my account thing.

06:34.180 --> 06:45.540
And then we also require that the parameters that we are sending in this case a dot js doesn't have any effect on the backend because if not maybe the the response is not going to contain that information that we want.

06:46.900 --> 06:56.640
So I started looking at different ways to obtain arbitrary web cache deception which is basically obtaining the same thing but for any kind of uh end point that we want.

06:57.140 --> 07:02.500
And to do this I started looking at how the the path is obtained at each state.

07:02.500 --> 07:16.000
So basically the path is obtained from a URL by using these delimiters which are basically characters that can then can be used to know where each part of the URL or each part of the elements of the URL start and begin uh and end.

07:16.700 --> 07:19.760
There are a lot of them defined by the RFC.

07:20.080 --> 07:26.860
So we can see that the URL has things like the scheme, the credentials, the host, the path query and fragment.

07:26.860 --> 07:30.760
So to split the each of them in a URL we need these these delimiters.

07:31.220 --> 07:40.280
The problem is that the RFC says that any any of these delimiters may or may not be or any of these characters may or may not be used as delimiters.

07:40.280 --> 07:45.940
And so each implementation can choose new delimiters and this could create some discrepancies.

07:46.660 --> 07:53.840
So let's say we find a server that is using a cache proxy and that is using the dollar sign as a delimiter.

07:53.840 --> 08:01.860
Then if we send a request to my account dollar sign eight dot JS this is just going to be interpreted as my account because of the delimiter.

08:02.400 --> 08:17.180
However as I said in the front end there's no delimiter being being said with uh the dollar sign and therefore this is going to be interpreted the entire URL is going to be interpreted as the path and the last part which is eight dot JS is going to be used as the extension.

08:17.440 --> 08:24.080
In this case actually it's dot JS the extension and so this is going to be stored in the cache just because of that delimiter.

08:25.100 --> 08:33.680
And in this case we can use it with any kind of path we want because we are not attacking a mapping we are attacking the entire way of obtaining the path from the URL.

08:35.160 --> 08:39.580
Now which kind of delimiters we can find in the well well there are a lot of them.

08:39.740 --> 08:53.160
Some I listed were in the frameworks is uh the first one is semicolon in spring so basically to define a matrix variable that is similar to a path a parameter we can use a semicolon.

08:53.180 --> 09:04.560
And the thing is that if we send something like my account semicolon eight dot JS anyone using Java probably Java in the well so they are going to consider this as my account.

09:04.560 --> 09:09.580
This includes Google or big companies that are using Java because this is how spring works.

09:10.780 --> 09:13.220
And so we can use this for the attack.

09:13.740 --> 09:32.080
Now in Rails there's another really interesting case which is they use the dot as a delimiter and that's because um the user is able to send an extension with a valid endpoint and this will the effect that this will have is that Rails will look for a specific view for that uh request.

09:32.080 --> 09:40.880
So let's say we define uh an endpoint which is my account and then when we send a request to my account Rails will just go and look for the HTML view.

09:40.880 --> 09:52.060
Now if we send something like my account dot CSS Rails will not just return a not a not found but it will look for the view of the the CSS view of my account.

09:52.080 --> 09:56.740
Usually there's no CSS view for my account so we'll just receive a 406 error.

09:56.860 --> 10:09.460
But the thing is that if the extension that we include is not recognized by Rails so let's say we send something like my account dot AAA then Rails is just going to send us the default view which is HTML.

10:10.600 --> 10:14.360
Remember all these extensions that are defined by Cloudflare.

10:14.360 --> 10:18.880
Well in green you can see the ones that are recognized by Rails.

10:18.880 --> 10:33.360
So if we send my account dot PNG or dot GPA or CSS then all of them are going to be recognized by Rails and it's going to try to look for that response and if there's no view for that extension then it's just going to return us an error.

10:33.860 --> 10:37.840
But in red we see all the other extensions that are not recognized by Rails.

10:37.840 --> 10:46.680
So we send something like my account dot ICO then we are going to get the default view but Cloudflare is going to think that this is a cacheable resource.

10:48.680 --> 10:57.540
Now there are other delimiters that can be used in HTTP servers instead of frameworks such as the encoded null byte which is the case of open light speed.

10:57.540 --> 11:06.100
So basically this works like a question mark if we send something in my account null encoded byte A dot JS then this is just going to be used as my account.

11:07.440 --> 11:14.580
The problem for this is that we cannot send it through many CDNs like Azure, Impairment, Cloudfront, Cloudflare, Google Cloud.

11:14.580 --> 11:17.520
That's because they don't accept null encoded bytes.

11:17.520 --> 11:22.600
But fortunately Akamai and Fast2DC yes so we can use them for eh this explanation.

11:22.900 --> 11:39.340
And finally in NGINX we have a delimiter whenever we define a rewrite rule and the delimiter is the new line encoded and so basically it works just as in open light with a null encoded byte and in this case we can send it through any CDN we want.

11:40.360 --> 11:49.840
So if we send a request using any of these delimiters with the correct with the corresponding eh backend then all of them are going to be interpreted as my account.

11:50.200 --> 11:57.060
The response is going to be sent back but in this case the web caches are going to just store that because of the static extension.

11:59.020 --> 12:08.040
But the problem with this attack is that many CDNs are are already aware of this and they are implementing some detection some protection for for this kind of attacks.

12:08.040 --> 12:18.240
In the case of Clover for instance is web cache deception armor which what it does is it looks for the extension of the request and the content type of the response.

12:18.240 --> 12:31.840
And if they don't match for for instance in this example we are using dot CSS as the extension and the content type is text HTML so if they don't match basically this is an attack and Clover won't store this in the cache.

12:32.960 --> 12:37.200
So we can attack other rules like the static directories one.

12:37.400 --> 12:51.900
That's a rule that we can create as users that states that anything starting with a specific path is going to be stored in the cache and that's really common in many applications because we we usually store static files in the same directory like share,

12:51.900 --> 12:55.520
public, assets, resources, anything that you can think.

12:55.580 --> 13:00.820
And so we can use this to attack this kind of eh this kind of web caches that are used in the rules.

13:01.460 --> 13:18.520
To create an attack in this case we will need some payload that is interpreted in the front end with the static directory at the beginning so basically if the static directory is called static then we want the path to start with static slash and anything we want.

13:18.520 --> 13:26.060
And then in the backend we still want my account because we in this case want to steal my account we could steal anything else we want.

13:26.740 --> 13:32.260
So if we have a delimiter in the backend we can try to do this but we will need something else.

13:32.780 --> 13:40.620
And as I said to extract the path from a URL we just need the delimiter and then that path is used in the keys rules and mapping.

13:40.740 --> 13:45.480
Well not really there's one extra step which is normalization.

13:45.500 --> 13:50.940
We need to normalize the path and most CDNs and backend servers do normalize the path.

13:51.120 --> 13:53.880
This includes decoding the characters.

13:53.880 --> 14:01.740
We can send them with URL encoded uh notation that is percentage uh and the XML value of a character .

14:01.820 --> 14:09.500
And then in some cases the uh other characters like segment delimiters like the slash or the dot are also going to be decoded.

14:09.500 --> 14:11.580
So this is going to be really useful.

14:12.420 --> 14:23.980
And then the normalization also includes dot segments uh resolution which is just resolving path traversals and whenever we find a dot segment then we just remove the previous segment.

14:24.460 --> 14:30.640
And some parsers like the IIS one uh will also convert backslashes to slashes.

14:31.580 --> 14:36.500
So now that we know this we can actually create a new payload that is going to use normalization.

14:36.860 --> 14:42.940
Again we are using a delimiter so everything before the delimiter is going to be interpreted in the backend server.

14:43.460 --> 14:47.620
But now we are also sending an encoded uh path traversal.

14:47.620 --> 14:53.740
And that is because the frontend is not using the delimiter so it's going to resolve this into this.

14:53.740 --> 14:59.300
And this includes a path traversal which is going to convert it to static WCD.

14:59.360 --> 15:05.980
So now in the frontend we see that there are static directories there so this is going to be stored in the webcache.

15:06.140 --> 15:12.320
And in this way we are able to bypass the webcache deception armor because there's no extension so nothing to convert.

15:13.760 --> 15:19.660
Now let's see how how we can how we can apply this in a real environment.

15:19.900 --> 15:24.720
And so first we need uh a frontend that is normalizing the path.

15:24.720 --> 15:25.420
Sorry.

15:25.860 --> 15:29.540
Uh this is the case for CloudFront, Imperva and Azure.

15:29.840 --> 15:43.540
And so if we combine them with any backend that is using a specific delimiter like for instance Tomcat, then we can send the same the same payload which is secret the semicolon with that represented delimiter.

15:43.720 --> 15:46.900
And this will cause that in the backend we see secret.

15:47.260 --> 15:57.940
And in the frontend again the semicolon is not a delimiter for either CloudFront, Azure or Imperva and therefore this is going to be resolved to static slash X.

15:58.000 --> 16:08.340
And this way we will be able to steal any response we want in an environment that is using basically a default configured Tomcat and any of the CDNs that I showed.

16:09.160 --> 16:20.920
This can be used also with other backends like uh Rails and Puma or even some in the same case that we observed in the in the first example when we had a special mapping in the backend.

16:20.920 --> 16:27.080
In this case there is no delimiter, the delimiter is just the the path that we are attacking.

16:28.580 --> 16:40.860
Now we could also try another attack that is using the opposite normalization so basically in the frontend we don't have normalization, that's the case of CloudFront, uh Google Cloud Platform and Fastly.

16:40.980 --> 16:45.880
And in the backend we have normalization in Nginx, IIS and open light speed.

16:46.600 --> 16:52.760
So if we use this, we can create the attack by starting with the static directory.

16:52.760 --> 16:54.980
In this case it's slash static.

16:55.080 --> 17:03.140
And this is because the path is not normalized and so CloudFront for instance will think that this is the entire URL is the path.

17:03.380 --> 17:18.280
But in the backend this is going to be normalized and therefore anyone using Nginx or IIS or open light speed is going to see that their response is going to be for secret and this will be storing the cache because of the static path.

17:19.000 --> 17:26.140
This worked on OpenAI and many other bounties that I wasn't able to be, I'm not able to talk about.

17:27.400 --> 17:36.320
And also this can be used with IIS, basically IIS is the only one that is decoding uh normalizing the backslash.

17:36.320 --> 17:52.240
So if we send something like using the, in the slide, this is going to be converted to static and basically a dot segment with a backslash and it's going to be converted to account in IIS but not in any other uh CDN because IIS decided that this is a cool idea.

17:52.340 --> 17:56.800
And so yeah, they are the only ones that I can be attacking with any other CDN.

17:58.220 --> 18:04.580
Now if we don't find one of these rules, well there's, there's another rule that we can use which is the static files.

18:04.660 --> 18:22.340
And in many, in many CDNs we will see that there's a static file rule by default to store robots dot txt but we can also find others for favicon or for index dot html or for any, any file that is usually accessed by people and is static.

18:23.000 --> 18:32.880
And in this case we can use the same attack only that we are not going to target a static directory, we are just going to target something that is being stored by the front end.

18:32.980 --> 18:44.280
So we can do something like secret then the, the limiter, the encoded dot segment and finally robot dot txt and this should work in many, in many applications.

18:44.300 --> 18:46.780
And also we can try to find other files.

18:46.780 --> 18:52.700
I found that there are many in the, in, in the wild so you should be able to find many others if you look for.

18:54.140 --> 19:01.780
So webcast deception is pretty cool but the thing is you need user interface interaction and we don't really want user interaction.

19:02.060 --> 19:14.980
So webcast poisoning is there for rescuers and the idea in webcast poisoning is that we are going to try to store a malicious response in, in a, with a key that is going to be accessed by other people.

19:14.980 --> 19:23.180
So let's say we want to hijack someone that is using this, this website, this website and is accessing through the home page.

19:23.180 --> 19:29.380
Well if we are able to find a payload that is stored in the home page then everyone navigating through the web page is going to be affected.

19:30.040 --> 19:47.280
And usually you will look for something that is not stored, like that is not using the key so in this case if the cookie value is reflected in the, in the body of the response then we are able to store this and anyone using the home page is going to be affected and is going to re,

19:47.280 --> 19:49.800
is going to retrieve the malicious response.

19:50.320 --> 20:01.320
The problem with this attack is that in many cases we will find a, an example of a cache poisoning but it's with a, it's using a key or it's using a resource that is not going to be accessed by anyone.

20:01.320 --> 20:12.680
Like for instance if we are able to poison something that starts with files then our user name and then a unique ID, no one is going to be accessing that uh, that path by themself.

20:12.700 --> 20:15.000
So we will need user interaction.

20:15.220 --> 20:16.720
And that's not really cool.

20:16.960 --> 20:28.380
So to avoid having to interact with any victim, I designed an attack that is going to be able, it's going to allow us to change the key of the uh, poison resource.

20:29.400 --> 20:36.580
Now in this case we will need key normalization and this is by default in impaired but Azure is just normalizing the key.

20:36.800 --> 20:50.380
Uh, and it's partially by default also in Akamai and it's configured in all the other CDNs and what's really interesting about this is that if you remember Cloud Front for instance was normalizing the rules but it's not normalizing the key.

20:50.380 --> 20:57.900
So that means that they have different parsers for each of these processes which is even in the same uh, in the same HTTP parser probably.

20:58.080 --> 21:08.480
So this, this tell us that we can even find other desynchronization attacks or other discrepancies even in the same uh, in the same web cache.

21:09.160 --> 21:27.300
So as I said, what we need is uh, a front end that is normalizing the key and what we can do to detect this is to send a request to a static resource like style dot CSS and whenever we see evidence that this is of being obtained from the web cache, so for instance we have an X cache hit value uh,

21:27.300 --> 21:46.200
hitter or we can just compare the time of the response and whenever we find this then we need to modify the path so that when normalized we still have style dot CSS and if we send this request and the response is still from the cache then it means that the key was normalized and so we detected key normalization.

21:47.120 --> 22:01.260
And how we can exploit a web cache poisoning with this, well basically we will try to modify as I said the key by sending first the exploit that we want so this is the, the uh, the response that we will, we will use to poison.

22:01.620 --> 22:03.820
Uh, usually contains a malicious payload.

22:04.000 --> 22:11.660
Then a delimiter, so again we will need a delimiter in the back end, but as I said this is really common and we can find them almost anywhere.

22:12.200 --> 22:21.340
And then we will need some normalization in the front end, so in Burba, Azure, and sometimes Akamai and all the others that are configured.

22:21.820 --> 22:23.780
Uh, and this is going to be a result of poison.

22:23.780 --> 22:35.020
So basically the web cache is going to store the exploit response in the poison end point which is something we control so it's arbitrary, we can just wire up a path we want, usually the home page.

22:38.590 --> 22:54.330
So in the, in the first example I didn't talk about one of the delimiters because we weren't able to send it with web cache deception and that's because the user needs to send it through his browser and anything but uh, and if the browser sees a hash,

22:54.330 --> 22:55.970
then it's not going to send the fragment.

22:56.150 --> 22:59.250
But in web cache poisoning we can use the fragment.

22:59.250 --> 23:09.050
So I, I started looking at different, at the behavior of different CDNs and HTTP servers and even frameworks in regarding the, the hash.

23:09.110 --> 23:11.950
And I found that there were a lot of differences.

23:12.750 --> 23:16.430
The most interesting one was again in purple because there were no likes in the key.

23:16.710 --> 23:23.450
A cloud front, well sorry, cloud front can be configured to, to do the same thing so it's interesting to see they are too.

23:23.630 --> 23:32.550
And basically if we have a hash and a, and key normalization then we can use in purple for, for this exploit that I'm going to show.

23:32.550 --> 23:44.170
And in the backend we can use pretty much any HTTP server like NGINX, Unicorn, Puma, then we can use also frameworks like Rails, Flash, they are not going to see the hash as a delimiter.

23:45.010 --> 23:47.450
Sorry, they are going to see the hash as a delimiter .

23:48.150 --> 23:51.950
And so basically we can send an attack that uses the hash.

23:51.950 --> 23:57.010
First we are going to send what we want to be interpreted in the backend because it's going to be using the hash.

23:57.030 --> 24:03.670
And so if we send something like this, then the XSS is going to be interpreted as the path in the backend.

24:03.930 --> 24:07.130
It's going to retrieve, retrieve the response, the malicious response.

24:07.130 --> 24:17.150
And now this is going to be normalized, the key, so we will be able to poison the homepage with any, any webcache poisoning eh, payload that we have.

24:17.910 --> 24:25.710
This was found in Vista, MasterCard and T-Mobile and again many others that I'm still unable to talk about.

24:26.270 --> 24:38.970
And of course we can use the same attack for with eh, Azure in purple and also with Tomcat, with Rails, with NGINX, with eh, new line encoded.

24:39.110 --> 24:42.890
And also again with any backend that is using a special mapping.

24:43.190 --> 24:52.550
So it should be pretty easy and I already saw many people exploiting this eh, since I give this talk in black hat so it seems like there are a lot of targets.

24:53.770 --> 25:06.650
Now we can do similar, a similar thing with Azure, only in this case Azure is considering the front, the hash as a delimiter and this is not the case for OpenLaySpeed, Express and Django.

25:07.490 --> 25:19.790
So what we are going to do is we're going to send a payload that in this case starts with what we want to poison, so the keys, the beginning and that's because the front end is using the hash as a delimiter.

25:20.030 --> 25:23.710
Then the rest is going to be normalized and we have the exploit.

25:24.050 --> 25:30.890
And again we can poison any path we want that is using Azure and OpenLight or other frameworks.

25:30.890 --> 25:37.270
There are other examples but as I, in this research I wasn't able to look for all, all servers but yeah.

25:38.230 --> 25:48.750
And this was found again in OpenAI so yeah, they, they acted really fast and they fixed the issue which I'm not sure, really sure how they fixed because it's still there.

25:50.690 --> 25:54.550
And, and so what if we don't have a payload?

25:54.650 --> 25:59.330
So let's say we don't have anything that we can use to poison a malicious response.

25:59.410 --> 26:02.190
We only, we are only able to change the keys.

26:02.190 --> 26:03.890
Well, we still can do something.

26:03.890 --> 26:07.950
We can start poisoning all the paths with a static file.

26:07.950 --> 26:20.350
So let's say we use status.css, this will poison every single path and so when a user sends a request to home, my account or any other path, he will just get CSS and therefore a denial of service.

26:20.630 --> 26:23.490
Which many companies think that this is not a vulnerability.

26:26.070 --> 26:27.850
So, sorry.

26:28.210 --> 26:37.770
So we already saw how we can poison anything we want and how we can change the key so it's just combining those ideas to create a very useful payload.

26:38.530 --> 26:46.490
And the first thing we need to do to store everything, anything we want in anywhere is to identify a malicious response that we want to use.

26:47.250 --> 26:55.530
And this malicious response, the, the, what's interesting about this attack is that we are going to combine both so the response doesn't need to be uh, cacheable.

26:55.530 --> 26:57.370
So we can use anything we want.

26:57.370 --> 27:03.530
In this case we are going to use an open redirect which is not stored, which is not cacheable and therefore is, is not a vulnerability .

27:03.530 --> 27:06.870
You can't report this to anyone because it's really not a vulnerability.

27:08.050 --> 27:19.110
Then we need to choose what we are going to poison and what I usually recommend is to poison some script that is being included in uh, in any web page, usually the home page.

27:19.170 --> 27:23.210
So in this case we have a home page that is uh, loading a main.js script.

27:23.710 --> 27:26.510
So we are going to poison that with an open redirect.

27:27.730 --> 27:28.390
Why?

27:28.390 --> 27:31.190
Well because first, as I said, we are going to use this technique.

27:31.190 --> 27:35.370
In this, in this example, this demo I'm going to show it using Azure and Tomcat.

27:35.370 --> 27:40.190
I finished coding this, this morning so it could work, it could not work.

27:40.390 --> 27:54.650
But uh, the thing is if we send something that starts with, in this case logout which is the open redirect, then the semicolon which is the delimiter, this is going to be interpreted as logout using the x forwarded host header which is going to show, to show,

27:54.650 --> 27:57.510
to send the, the victim to the evil.com.

27:58.890 --> 28:05.990
And then this is going to be normalized so we are going to poison main.js and this is because it has a static extension.

28:05.990 --> 28:13.670
So even if the operator wasn't storable by default, well we have the static extension so we are able to poison main.js using this attack.

28:14.010 --> 28:35.390
Now when a user loads the home page, he will again load the main.js script and when this request is uh, is received by the, by Azure, he will just send the open redirect which will redirect the victim to the evil.com server, will load the malicious JavaScript and we will be able to poison any,

28:35.390 --> 28:38.430
any victim with a malicious script that we completely control.

28:38.770 --> 28:49.270
And if we have the content security policy enabled to provide, to avoid this kind of attacks, then we can use something like CSX exfiltration to obtain anything we want.

28:49.270 --> 28:51.810
You can ask Gareth about that, he knows a lot.

28:53.350 --> 28:56.090
And so yeah, this is the demo.

29:01.150 --> 29:05.230
Uh, so yeah, so this is the web page.

29:06.270 --> 29:08.830
This is using Azure right now.

29:08.830 --> 29:12.570
And maybe this is, yeah, this is loading, perfect.

29:12.830 --> 29:13.770
Internet.

29:14.130 --> 29:20.290
Uh, so when we send a request to the home page, which is caches, cache all Azure blah blah.

29:21.130 --> 29:22.990
Don't hack it right now please.

29:23.230 --> 29:24.950
Uh, yeah.

29:24.950 --> 29:28.250
So we see that the main.js is being imported.

29:28.610 --> 29:30.210
So that's what we want to attack.

29:32.530 --> 29:33.990
This is main.js.

29:36.310 --> 29:36.890
Yeah.

29:36.930 --> 29:42.570
Main.js is being obtained from the cache right now.

29:42.570 --> 29:44.830
So it's going to last 20 seconds.

29:44.830 --> 29:49.670
I said 20 seconds probably is going, in a real application is going to be a day, maybe some days.

29:49.750 --> 29:54.790
So you will need to wait for that to stop doing, you can just use uh, an intruder session.

29:55.890 --> 29:58.910
Now, this is the open redirect that we are going to use.

29:59.250 --> 30:00.730
This is the evil.com.

30:04.380 --> 30:09.500
And as you can see, this is being, this is an open redirect that is not being cacheable.

30:09.500 --> 30:11.740
Config no cache means no cacheable.

30:13.120 --> 30:18.900
This is the evil.com server that is going to load our arbitrary javascript.

30:20.200 --> 30:21.660
And this is the exploit.

30:22.020 --> 30:24.320
Now I'm going to try to code it by myself.

30:24.520 --> 30:27.220
So again, the exploit is going to work like this.

30:27.220 --> 30:30.840
First we put the thing that we want to, to log.

30:30.840 --> 30:33.340
So this is going to be used in the backend.

30:34.180 --> 30:35.140
Logout.

30:35.340 --> 30:36.920
Logout is the open redirect.

30:36.920 --> 30:41.120
Then the semicolon to um, to use as a delimiter .

30:41.320 --> 30:53.320
Now, because the way that java use semicolons is uh, is uh, semicolons only work for a segment so we cannot put a slash after the semicolon because it's not going to be, it's not going to work.

30:53.320 --> 30:57.300
So we need to send the slashes and everything encoded in this case.

30:57.420 --> 30:59.620
So this is a slash encoded.

31:00.780 --> 31:02.580
This is a dot encoded.

31:05.690 --> 31:08.710
Yeah, the dot segment encoded.

31:09.010 --> 31:12.870
And then we will put what we want to poison which is main.js.

31:16.810 --> 31:19.050
And it seems we are lucky enough.

31:19.750 --> 31:20.410
Yeah.

31:20.650 --> 31:26.230
So first, as you, if you observe, the first time we got a miss, so nothing there.

31:26.230 --> 31:27.230
Now we got a hit .

31:27.230 --> 31:30.110
So it seems it worked.

31:30.310 --> 31:37.370
So if we load, if we try to get the main.js now, instead of getting the js that we had, we have an open redirect.

31:37.670 --> 31:43.890
So now, if we load, let's try this.

31:45.930 --> 31:46.890
Wow.

31:47.210 --> 31:48.250
Let's do it again.

31:50.130 --> 31:57.350
The problem is the time because, yeah, so I need to wait the 20 seconds for this to stop being cached.

31:58.950 --> 31:59.910
Unfortunately.

32:03.670 --> 32:04.790
C cached.

32:08.170 --> 32:15.470
So as you see, I'm getting the main.js, that's because it's being resolved the key and I'm getting the restore resource right now.

32:16.750 --> 32:18.050
But right now it worked.

32:18.050 --> 32:24.690
So okay, so now if I go, I do this, this is going to do everything that we saw.

32:28.950 --> 32:30.470
And it's good.

32:36.710 --> 32:37.590
Okay.

32:39.790 --> 32:41.110
I'm running out of battery.

32:43.710 --> 32:47.470
Okay, so I have time for this secret demo.

32:53.750 --> 32:54.470
Yeah.

32:58.650 --> 33:05.750
Okay, so we already saw how we can use different discrepancies between URL parsers to exploit web caches.

33:05.790 --> 33:13.910
But there are other kind of discrepancies where you can use, and there are many other discrepancies that I didn't research on, but probably you can look for them.

33:14.110 --> 33:17.750
One of them is the HTTP 0.9 smuggling.

33:18.370 --> 33:26.870
And basically, I trust that most of you already know what HTTP is, the basic protocol that we use every day to communicate in the internet.

33:26.870 --> 33:38.490
But, and probably you already know the really new HTTP 3, the still new HTTP 2, the classic HTTP 1.1 and even HTTP 1.0.

33:38.490 --> 33:41.870
But maybe you don't know that there's HTTP 0.9.

33:41.870 --> 33:52.670
0.9 is basically a legacy protocol that shouldn't be used by anyone unless you are NGINX, Apache, IIS or any other HTTP server in the world.

33:52.930 --> 34:00.770
And the thing with HTTP 0.9 is that we don't have any headers, so no header for requests, no header for responses.

34:01.010 --> 34:06.570
And the connections are not persisted, the responses of course shouldn't be cacheable.

34:07.590 --> 34:13.650
So this is basically a basic 1.1 request, a HTTP 1.1 request.

34:13.650 --> 34:17.270
We send a request to home, we get a response, nothing strange.

34:17.650 --> 34:34.090
Now if we remove the HTTP version and we just send get, and the URL, the entire URL, then we will receive a 0.9 response if we are targeting NGINX, as I said, Apache, IIS, Tomcat, any HTTP server basically.

34:34.230 --> 34:36.430
You will just get the response which is the body.

34:37.330 --> 34:41.270
If you send something like this, still HTTP 0.9.

34:41.490 --> 34:44.690
If you send this, 0.9.

34:44.830 --> 34:47.230
And if you send this, 0.9.

34:47.430 --> 34:49.870
So why is this interesting at all?

34:49.870 --> 35:01.230
Well browsers are a little bit smarter than others and they knew that it doesn't make sense to keep talking this uh this old protocol, so you cannot send a 0.9 request through browsers.

35:01.230 --> 35:04.650
So most of the attacks are discarded just because of that.

35:04.650 --> 35:12.870
But let's see what happens if the front end and the back end are not doing the same thing or they don't talk the same protocol.

35:13.110 --> 35:27.050
So if we send a request like an HTTP 0.9 request and we send it through a CDN, most CDNs will take this request and they will upgrade it to HTTP 1.1.

35:27.050 --> 35:39.450
So then the back end will just generate a 1.1 response, the body will be extracted and sorry, the response will be actually downgraded and we will just be left with the body.

35:40.810 --> 35:51.850
And this works basically even if no one should be using 0.9, this works because if the upgrade and downgrading is done correctly then this works.

35:52.010 --> 35:57.550
And also connections are not persistent so a lot of attacks are also discarded because of that.

35:58.570 --> 36:06.850
But the interesting thing is that some CDNs such as Imperva, they don't verify the HTTP version before forwarding a request.

36:07.090 --> 36:13.510
So if we send a request, a 0.9 request, Imperva will say well I will just forward it, I don't care.

36:14.090 --> 36:22.930
And the problem is Imperva is not just going to forward it, it's going to think that this is a 1.1 request because Imperva doesn't know about 0.9.

36:23.850 --> 36:30.130
And the back end will send a body because it's 0.9 and so no headers.

36:30.130 --> 36:33.870
And now Imperva is going to try to use this as a response .

36:34.030 --> 36:35.670
And probably it's going to fail.

36:35.670 --> 36:40.010
And so you are not going to see a lot of valid responses because of the parsing.

36:40.010 --> 36:47.250
Because when Imperva tries to parse a body of a response that doesn't contain valid HTTP headers then this is going to be interpreted as an error.

36:48.130 --> 36:53.510
But what if the body does have these valid HTTP response headers?

36:54.330 --> 37:08.530
So let's say we have a upload download file feature or let's say we can control the body of a plain text or let's say we are even able to modify the response using byte range or something like that.

37:08.530 --> 37:18.750
Then if by any means we are able to control the response, then the body of the response no matter what the content type, no matter anything, then we will be able to use this attack.

37:21.410 --> 37:25.310
Again this demo, I hope it works.

37:27.750 --> 37:29.530
Um, okay, yeah.

37:29.930 --> 37:35.550
So in this super page, web page I created an upload file feature.

37:36.830 --> 37:37.970
Okay.

37:37.970 --> 37:42.490
And in this upload file feature we can upload any file we want.

37:42.490 --> 37:55.810
In this case an evil file that if you want to see it, well it's really really small but basically it's a response containing a script and containing a cache control header.

37:55.810 --> 37:57.450
Probably you can't see it.

37:57.450 --> 38:03.350
But yeah, it contains a cache control header saying that it should be stored for 10 seconds I think.

38:04.010 --> 38:06.110
Let's put 100 seconds.

38:07.390 --> 38:13.150
And so when I upload this, I will also be able to retrieve this.

38:15.610 --> 38:19.670
So it seems like it was uploaded.

38:20.130 --> 38:21.410
So let's go back to burp.

38:21.410 --> 38:21.410
Okay.

38:21.410 --> 38:26.510
And so, okay, so this is the file that I uploaded.

38:26.690 --> 38:31.230
Okay, let's say we have this upload download feature which is pretty common in many applications.

38:33.370 --> 38:35.470
And this works.

38:35.470 --> 38:35.890
Yeah.

38:35.890 --> 38:41.330
As you can see, I uploaded this file which in the body we have a valid HTTP response.

38:41.390 --> 38:43.790
Containing headers, containing everything we want.

38:44.610 --> 38:55.690
Now, if I send an, let's say I send a, an HTTP 0.9 request, which is basically this request that doesn't contain any header here.

38:58.880 --> 39:05.500
As you can see, Imperva sends, says that it's an error because it was trying to load the home page as a 0 .9.

39:05.500 --> 39:09.560
It was trying to parse the response body of the home page as 0.9.

39:09.560 --> 39:10.320
Failed.

39:10.320 --> 39:11.040
Okay.

39:11.200 --> 39:17.520
Now, what if we send the same but for this response?

39:21.660 --> 39:25.760
And as you can see, Imperva thinks that this is a valid response.

39:25.880 --> 39:28.260
It's actually using the cache control header.

39:28.940 --> 39:31.000
And it's contain, it's putting everything.

39:31.000 --> 39:34.700
It's also including his own header so it seems like it's working.

39:35.480 --> 39:38.120
So, yeah, we can poison this file.

39:38.120 --> 39:39.020
Great.

39:39.020 --> 39:43.700
So someone that is accessing this file is going to receive this response and is going to be attacked.

39:43.700 --> 39:45.560
Now, not really cool.

39:45.560 --> 39:49.640
So we can use something that I just explained which is modifying the old cache key.

39:49.860 --> 39:54.500
Again, we can use the request to the thing that we want to store.

39:54.780 --> 39:57.440
Then the cache, in this case we are using Imperva.

39:57.440 --> 40:01.020
Imperva doesn't think that the cache is a, is a delimiter.

40:01.260 --> 40:03.900
Ah, this, sorry, this time we are using Imperva and Nginx.

40:04.840 --> 40:07.940
And the, then we have a path reversal.

40:07.940 --> 40:16.160
I added a few slashes because it's the way to avoid being detected as an attack by many CDNs.

40:17.060 --> 40:27.740
And so I have this path reversal that removes the files, removes the abl5.txt and so basically the path is going to be converted to the home page which is indexed.

40:27.860 --> 40:29.680
And so we are going to poison the index.

40:31.240 --> 40:34.640
So if we send this, I will have a little bit of luck.

40:35.980 --> 40:40.240
Yeah, it seems it's working because the second time was obtained from the cache.

40:40.660 --> 40:49.500
So now if I go back to the home page, it's not working.

40:49.820 --> 40:56.100
Ah, sorry, I this was, eh, this was the Azure one.

40:56.200 --> 40:58.040
This is the Imperva one, fortunately.

40:58.160 --> 41:03.080
So if we go to Imperva, arbitrary cache.

41:17.250 --> 41:22.150
Okay, so how we can defend against these kind of attacks?

41:22.150 --> 41:28.590
Well, first we need to use the, eh, cache control header for web cache deception.

41:28.590 --> 41:36.850
So whenever we have a response that we don't want to, anyone to store it, then just use private and no store for the, for the cache control header.

41:36.850 --> 41:45.990
But also, eh, I wasn't able to show it in the example but there are many CDNs that will override this cache control header if there's a rule for the path.

41:45.990 --> 41:52.810
So sometimes the rules for the request have priority and therefore it's important to check if this is happening.

41:52.810 --> 41:58.950
If this is happening, try to modify this and if it's not possible, then try to consider using another CDN.

41:59.190 --> 42:05.830
And then, eh, for cache poisoning, well, we can try to abort, to disable the key normalization.

42:05.890 --> 42:08.070
In some cases it's possible, in some cases it's not.

42:08.070 --> 42:17.430
So in those cases, I suggest using the tool that I will provide that will let you know if there's any discrepancy between normalization and, eh, delimiters and anything.

42:17.430 --> 42:23.250
So this will allow you to know if you need to change either your HTTP server or your, eh, front end server.

42:24.350 --> 42:29.550
These are all the references, eh, for the reason I, I use all this information.

42:29.570 --> 42:32.210
All the other attacks that inspired me.

42:32.230 --> 42:39.690
And also, in the slide you have the, eh, the links for the cache poisoning and cache deception academy topics.

42:39.690 --> 42:42.350
We just released the academy topic for deception.

42:42.390 --> 42:49.530
And also the extension for cache killer, which is the, the extension I created for, to detect this.

42:49.530 --> 42:57.570
It's still in progress, eh, it should work, but I will, I will keep working on, on this, on this tool for the next probably month or two.

42:57.570 --> 43:08.730
And the takeaways, basically I showed that we can use any kind of discrepancy we, we find in the, in the wild to exploit, eh, different servers using web cache.

43:08.730 --> 43:15.510
So web cache poisoning and deception, eh, can be used in many, many cases wherever we find these kind of discrepancies.

43:15.850 --> 43:24.470
Then we can use the exploitation things in many bounties because I found that these kind of delimiters are being used in many systems.

43:24.470 --> 43:32.310
So I invite you to look for them in different bounties and collect them and send me a message to just add you in the list of people that are using this.

43:32.530 --> 43:42.610
And finally, eh, I found, I showed you a way of chaining these vulnerabilities but you probably can think of many other ways to combine them with different vulnerabilities.

43:42.610 --> 43:49.850
Probably to upgrade vulnerabilities that are not really useful and probably to be, to get better payments in bad bounties.

43:49.850 --> 43:52.050
So I hope this helps everyone.

43:52.970 --> 43:54.270
And that's it.

43:54.270 --> 43:54.910
Thank you.

