1 00:00:00,000 --> 00:00:03,800 Uh welcome to track two, talk number two on Saturday. 2 00:00:03,900 --> 00:00:10,740 Uh this morning we uh have Martin and he's gonna talk about breaking the rules of web cache exploitation. 3 00:00:10,740 --> 00:00:11,800 So are you ready Martin? 4 00:00:11,800 --> 00:00:12,440 I'm ready. 5 00:00:12,440 --> 00:00:13,960 Let's hear it for Martin. 6 00:00:18,000 --> 00:00:19,120 Thank you. 7 00:00:19,120 --> 00:00:20,140 Hello everyone. 8 00:00:20,140 --> 00:00:23,580 Welcome to Gara Cache Mall, bending the rules of web cache exploitation. 9 00:00:27,160 --> 00:00:29,200 Uh it's already not working. 10 00:00:29,600 --> 00:00:32,780 So this is the agenda for today. 11 00:00:32,780 --> 00: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. 12 00:00:49,440 --> 00: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. 13 00:01:00,300 --> 00: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. 14 00:01:10,600 --> 00: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. 15 00:01:18,700 --> 00: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. 16 00:01:38,980 --> 00: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. 17 00:01:53,320 --> 00: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, 18 00:02:13,500 --> 00:02:18,420 then we just need to provide the resource and we don't care about processing anything else. 19 00:02:18,420 --> 00: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. 20 00:02:27,080 --> 00: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. 21 00:02:42,980 --> 00: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. 22 00:02:50,320 --> 00: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. 23 00:02:57,880 --> 00: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. 24 00:03:09,300 --> 00:03:11,060 So if it's static or not. 25 00:03:11,880 --> 00: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. 26 00:03:24,400 --> 00:03:31,500 For example the static extension one which is by default in most CDNs that looks for static extensions. 27 00:03:31,500 --> 00:03:34,680 So basically this is the list that Cloudflare has. 28 00:03:34,680 --> 00:03:38,420 And it will look for the path and the extension of that path. 29 00:03:38,500 --> 00: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. 30 00:03:48,700 --> 00:03:53,280 So in this example we see that styles dot CSS ends with a static extension. 31 00:03:53,460 --> 00:03:57,900 And therefore it's going to be cached using the key that was calculated in the first step. 32 00:03:59,300 --> 00: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. 33 00:04:16,160 --> 00:04:18,420 And that's basically how a web cache works. 34 00:04:18,420 --> 00:04:20,920 Now we can exploit this in many ways. 35 00:04:20,920 --> 00: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. 36 00:04:31,760 --> 00: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. 37 00:04:41,640 --> 00:04:43,180 This is called path parameters. 38 00:04:43,180 --> 00: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. 39 00:04:52,380 --> 00: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. 40 00:05:01,660 --> 00: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. 41 00:05:10,160 --> 00:05:15,140 And it contains for instance the mail or the credit card details. 42 00:05:15,140 --> 00:05:17,420 So basically this is what we want to steal. 43 00:05:18,920 --> 00:05:22,840 And to do so the first thing is to send uh a link to the victim. 44 00:05:22,840 --> 00:05:24,700 This requires user interaction. 45 00:05:24,900 --> 00:05:29,500 And the link will start with the end point that we want to steal the response. 46 00:05:29,500 --> 00:05:31,280 So in this case it's my account. 47 00:05:31,340 --> 00:05:34,900 And then it will use as a parameter a dot js. 48 00:05:35,380 --> 00: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. 49 00:05:43,620 --> 00:05:48,660 And so the response with the sensitive information is going to be sent back to the to the proxy. 50 00:05:48,960 --> 00:05:52,340 And now with the cache proxy it will use the the path. 51 00:05:52,680 --> 00:05:56,140 This in this case it doesn't know anything about this mapping. 52 00:05:56,140 --> 00:06:00,640 So it will think that the last part is just a parameter is not a parameter sorry it's a path. 53 00:06:00,640 --> 00:06:01,660 It's part of a path. 54 00:06:01,680 --> 00:06:04,300 And therefore it will think that it has a static extension. 55 00:06:04,300 --> 00:06:05,960 In this case dot js. 56 00:06:06,280 --> 00:06:09,660 And so it will start this response containing all the secret information. 57 00:06:10,040 --> 00: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. 58 00:06:17,640 --> 00:06:22,100 Well the cache proxy is going to match it with the key that already calculated in the first place. 59 00:06:22,200 --> 00:06:26,500 And it will retrieve the victim's response containing all the secret information. 60 00:06:27,300 --> 00:06:31,060 Now the problem in this technique is that we need a special mapping for that. 61 00:06:31,060 --> 00:06:34,180 Basically we need this special my account thing. 62 00:06:34,180 --> 00: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. 63 00:06:46,900 --> 00: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. 64 00:06:57,140 --> 00:07:02,500 And to do this I started looking at how the the path is obtained at each state. 65 00:07:02,500 --> 00: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. 66 00:07:16,700 --> 00:07:19,760 There are a lot of them defined by the RFC. 67 00:07:20,080 --> 00:07:26,860 So we can see that the URL has things like the scheme, the credentials, the host, the path query and fragment. 68 00:07:26,860 --> 00:07:30,760 So to split the each of them in a URL we need these these delimiters. 69 00:07:31,220 --> 00: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. 70 00:07:40,280 --> 00:07:45,940 And so each implementation can choose new delimiters and this could create some discrepancies. 71 00:07:46,660 --> 00: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. 72 00:07:53,840 --> 00: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. 73 00:08:02,400 --> 00: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. 74 00:08:17,440 --> 00: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. 75 00:08:25,100 --> 00: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. 76 00:08:35,160 --> 00:08:39,580 Now which kind of delimiters we can find in the well well there are a lot of them. 77 00:08:39,740 --> 00: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. 78 00:08:53,180 --> 00: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. 79 00:09:04,560 --> 00:09:09,580 This includes Google or big companies that are using Java because this is how spring works. 80 00:09:10,780 --> 00:09:13,220 And so we can use this for the attack. 81 00:09:13,740 --> 00: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. 82 00:09:32,080 --> 00: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. 83 00:09:40,880 --> 00: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. 84 00:09:52,080 --> 00:09:56,740 Usually there's no CSS view for my account so we'll just receive a 406 error. 85 00:09:56,860 --> 00: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. 86 00:10:10,600 --> 00:10:14,360 Remember all these extensions that are defined by Cloudflare. 87 00:10:14,360 --> 00:10:18,880 Well in green you can see the ones that are recognized by Rails. 88 00:10:18,880 --> 00: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. 89 00:10:33,860 --> 00:10:37,840 But in red we see all the other extensions that are not recognized by Rails. 90 00:10:37,840 --> 00: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. 91 00:10:48,680 --> 00: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. 92 00:10:57,540 --> 00: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. 93 00:11:07,440 --> 00:11:14,580 The problem for this is that we cannot send it through many CDNs like Azure, Impairment, Cloudfront, Cloudflare, Google Cloud. 94 00:11:14,580 --> 00:11:17,520 That's because they don't accept null encoded bytes. 95 00:11:17,520 --> 00:11:22,600 But fortunately Akamai and Fast2DC yes so we can use them for eh this explanation. 96 00:11:22,900 --> 00: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. 97 00:11:40,360 --> 00: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. 98 00:11:50,200 --> 00: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. 99 00:11:59,020 --> 00: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. 100 00:12:08,040 --> 00: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. 101 00:12:18,240 --> 00: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. 102 00:12:32,960 --> 00:12:37,200 So we can attack other rules like the static directories one. 103 00:12:37,400 --> 00: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, 104 00:12:51,900 --> 00:12:55,520 public, assets, resources, anything that you can think. 105 00:12:55,580 --> 00: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. 106 00:13:01,460 --> 00: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. 107 00:13:18,520 --> 00: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. 108 00:13:26,740 --> 00:13:32,260 So if we have a delimiter in the backend we can try to do this but we will need something else. 109 00:13:32,780 --> 00: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. 110 00:13:40,740 --> 00:13:45,480 Well not really there's one extra step which is normalization. 111 00:13:45,500 --> 00:13:50,940 We need to normalize the path and most CDNs and backend servers do normalize the path. 112 00:13:51,120 --> 00:13:53,880 This includes decoding the characters. 113 00:13:53,880 --> 00:14:01,740 We can send them with URL encoded uh notation that is percentage uh and the XML value of a character . 114 00:14:01,820 --> 00: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. 115 00:14:09,500 --> 00:14:11,580 So this is going to be really useful. 116 00:14:12,420 --> 00: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. 117 00:14:24,460 --> 00:14:30,640 And some parsers like the IIS one uh will also convert backslashes to slashes. 118 00:14:31,580 --> 00:14:36,500 So now that we know this we can actually create a new payload that is going to use normalization. 119 00:14:36,860 --> 00:14:42,940 Again we are using a delimiter so everything before the delimiter is going to be interpreted in the backend server. 120 00:14:43,460 --> 00:14:47,620 But now we are also sending an encoded uh path traversal. 121 00:14:47,620 --> 00:14:53,740 And that is because the frontend is not using the delimiter so it's going to resolve this into this. 122 00:14:53,740 --> 00:14:59,300 And this includes a path traversal which is going to convert it to static WCD. 123 00:14:59,360 --> 00: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. 124 00:15:06,140 --> 00: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. 125 00:15:13,760 --> 00:15:19,660 Now let's see how how we can how we can apply this in a real environment. 126 00:15:19,900 --> 00:15:24,720 And so first we need uh a frontend that is normalizing the path. 127 00:15:24,720 --> 00:15:25,420 Sorry. 128 00:15:25,860 --> 00:15:29,540 Uh this is the case for CloudFront, Imperva and Azure. 129 00:15:29,840 --> 00: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. 130 00:15:43,720 --> 00:15:46,900 And this will cause that in the backend we see secret. 131 00:15:47,260 --> 00: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. 132 00:15:58,000 --> 00: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. 133 00:16:09,160 --> 00: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. 134 00:16:20,920 --> 00:16:27,080 In this case there is no delimiter, the delimiter is just the the path that we are attacking. 135 00:16:28,580 --> 00: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. 136 00:16:40,980 --> 00:16:45,880 And in the backend we have normalization in Nginx, IIS and open light speed. 137 00:16:46,600 --> 00:16:52,760 So if we use this, we can create the attack by starting with the static directory. 138 00:16:52,760 --> 00:16:54,980 In this case it's slash static. 139 00:16:55,080 --> 00: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. 140 00:17:03,380 --> 00: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. 141 00:17:19,000 --> 00: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. 142 00:17:27,400 --> 00:17:36,320 And also this can be used with IIS, basically IIS is the only one that is decoding uh normalizing the backslash. 143 00:17:36,320 --> 00: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. 144 00:17:52,340 --> 00:17:56,800 And so yeah, they are the only ones that I can be attacking with any other CDN. 145 00:17:58,220 --> 00: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. 146 00:18:04,660 --> 00: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. 147 00:18:23,000 --> 00: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. 148 00:18:32,980 --> 00: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. 149 00:18:44,300 --> 00:18:46,780 And also we can try to find other files. 150 00:18:46,780 --> 00: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. 151 00:18:54,140 --> 00: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. 152 00:19:02,060 --> 00: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. 153 00:19:14,980 --> 00: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. 154 00:19:23,180 --> 00: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. 155 00:19:30,040 --> 00: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, 156 00:19:47,280 --> 00:19:49,800 is going to retrieve the malicious response. 157 00:19:50,320 --> 00: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. 158 00:20:01,320 --> 00: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. 159 00:20:12,700 --> 00:20:15,000 So we will need user interaction. 160 00:20:15,220 --> 00:20:16,720 And that's not really cool. 161 00:20:16,960 --> 00: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. 162 00:20:29,400 --> 00: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. 163 00:20:36,800 --> 00: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. 164 00:20:50,380 --> 00: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. 165 00:20:58,080 --> 00: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. 166 00:21:09,160 --> 00: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, 167 00:21:27,300 --> 00: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. 168 00:21:47,120 --> 00: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. 169 00:22:01,620 --> 00:22:03,820 Uh, usually contains a malicious payload. 170 00:22:04,000 --> 00: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. 171 00:22:12,200 --> 00: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. 172 00:22:21,820 --> 00:22:23,780 Uh, and this is going to be a result of poison. 173 00:22:23,780 --> 00: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. 174 00:22:38,590 --> 00: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, 175 00:22:54,330 --> 00:22:55,970 then it's not going to send the fragment. 176 00:22:56,150 --> 00:22:59,250 But in web cache poisoning we can use the fragment. 177 00:22:59,250 --> 00: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. 178 00:23:09,110 --> 00:23:11,950 And I found that there were a lot of differences. 179 00:23:12,750 --> 00:23:16,430 The most interesting one was again in purple because there were no likes in the key. 180 00:23:16,710 --> 00: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. 181 00:23:23,630 --> 00: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. 182 00:23:32,550 --> 00: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. 183 00:23:45,010 --> 00:23:47,450 Sorry, they are going to see the hash as a delimiter . 184 00:23:48,150 --> 00:23:51,950 And so basically we can send an attack that uses the hash. 185 00:23:51,950 --> 00: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. 186 00:23:57,030 --> 00: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. 187 00:24:03,930 --> 00:24:07,130 It's going to retrieve, retrieve the response, the malicious response. 188 00:24:07,130 --> 00: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. 189 00:24:17,910 --> 00:24:25,710 This was found in Vista, MasterCard and T-Mobile and again many others that I'm still unable to talk about. 190 00:24:26,270 --> 00: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. 191 00:24:39,110 --> 00:24:42,890 And also again with any backend that is using a special mapping. 192 00:24:43,190 --> 00: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. 193 00:24:53,770 --> 00: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. 194 00:25:07,490 --> 00: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. 195 00:25:20,030 --> 00:25:23,710 Then the rest is going to be normalized and we have the exploit. 196 00:25:24,050 --> 00:25:30,890 And again we can poison any path we want that is using Azure and OpenLight or other frameworks. 197 00:25:30,890 --> 00: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. 198 00:25:38,230 --> 00: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. 199 00:25:50,690 --> 00:25:54,550 And, and so what if we don't have a payload? 200 00:25:54,650 --> 00:25:59,330 So let's say we don't have anything that we can use to poison a malicious response. 201 00:25:59,410 --> 00:26:02,190 We only, we are only able to change the keys. 202 00:26:02,190 --> 00:26:03,890 Well, we still can do something. 203 00:26:03,890 --> 00:26:07,950 We can start poisoning all the paths with a static file. 204 00:26:07,950 --> 00: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. 205 00:26:20,630 --> 00:26:23,490 Which many companies think that this is not a vulnerability. 206 00:26:26,070 --> 00:26:27,850 So, sorry. 207 00:26:28,210 --> 00: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. 208 00:26:38,530 --> 00: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. 209 00:26:47,250 --> 00: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. 210 00:26:55,530 --> 00:26:57,370 So we can use anything we want. 211 00:26:57,370 --> 00: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 . 212 00:27:03,530 --> 00:27:06,870 You can't report this to anyone because it's really not a vulnerability. 213 00:27:08,050 --> 00: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. 214 00:27:19,170 --> 00:27:23,210 So in this case we have a home page that is uh, loading a main.js script. 215 00:27:23,710 --> 00:27:26,510 So we are going to poison that with an open redirect. 216 00:27:27,730 --> 00:27:28,390 Why? 217 00:27:28,390 --> 00:27:31,190 Well because first, as I said, we are going to use this technique. 218 00:27:31,190 --> 00:27:35,370 In this, in this example, this demo I'm going to show it using Azure and Tomcat. 219 00:27:35,370 --> 00:27:40,190 I finished coding this, this morning so it could work, it could not work. 220 00:27:40,390 --> 00: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, 221 00:27:54,650 --> 00:27:57,510 to send the, the victim to the evil.com. 222 00:27:58,890 --> 00: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. 223 00:28:05,990 --> 00: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. 224 00:28:14,010 --> 00: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, 225 00:28:35,390 --> 00:28:38,430 any victim with a malicious script that we completely control. 226 00:28:38,770 --> 00: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. 227 00:28:49,270 --> 00:28:51,810 You can ask Gareth about that, he knows a lot. 228 00:28:53,350 --> 00:28:56,090 And so yeah, this is the demo. 229 00:29:01,150 --> 00:29:05,230 Uh, so yeah, so this is the web page. 230 00:29:06,270 --> 00:29:08,830 This is using Azure right now. 231 00:29:08,830 --> 00:29:12,570 And maybe this is, yeah, this is loading, perfect. 232 00:29:12,830 --> 00:29:13,770 Internet. 233 00:29:14,130 --> 00:29:20,290 Uh, so when we send a request to the home page, which is caches, cache all Azure blah blah. 234 00:29:21,130 --> 00:29:22,990 Don't hack it right now please. 235 00:29:23,230 --> 00:29:24,950 Uh, yeah. 236 00:29:24,950 --> 00:29:28,250 So we see that the main.js is being imported. 237 00:29:28,610 --> 00:29:30,210 So that's what we want to attack. 238 00:29:32,530 --> 00:29:33,990 This is main.js. 239 00:29:36,310 --> 00:29:36,890 Yeah. 240 00:29:36,930 --> 00:29:42,570 Main.js is being obtained from the cache right now. 241 00:29:42,570 --> 00:29:44,830 So it's going to last 20 seconds. 242 00:29:44,830 --> 00:29:49,670 I said 20 seconds probably is going, in a real application is going to be a day, maybe some days. 243 00:29:49,750 --> 00:29:54,790 So you will need to wait for that to stop doing, you can just use uh, an intruder session. 244 00:29:55,890 --> 00:29:58,910 Now, this is the open redirect that we are going to use. 245 00:29:59,250 --> 00:30:00,730 This is the evil.com. 246 00:30:04,380 --> 00:30:09,500 And as you can see, this is being, this is an open redirect that is not being cacheable. 247 00:30:09,500 --> 00:30:11,740 Config no cache means no cacheable. 248 00:30:13,120 --> 00:30:18,900 This is the evil.com server that is going to load our arbitrary javascript. 249 00:30:20,200 --> 00:30:21,660 And this is the exploit. 250 00:30:22,020 --> 00:30:24,320 Now I'm going to try to code it by myself. 251 00:30:24,520 --> 00:30:27,220 So again, the exploit is going to work like this. 252 00:30:27,220 --> 00:30:30,840 First we put the thing that we want to, to log. 253 00:30:30,840 --> 00:30:33,340 So this is going to be used in the backend. 254 00:30:34,180 --> 00:30:35,140 Logout. 255 00:30:35,340 --> 00:30:36,920 Logout is the open redirect. 256 00:30:36,920 --> 00:30:41,120 Then the semicolon to um, to use as a delimiter . 257 00:30:41,320 --> 00: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. 258 00:30:53,320 --> 00:30:57,300 So we need to send the slashes and everything encoded in this case. 259 00:30:57,420 --> 00:30:59,620 So this is a slash encoded. 260 00:31:00,780 --> 00:31:02,580 This is a dot encoded. 261 00:31:05,690 --> 00:31:08,710 Yeah, the dot segment encoded. 262 00:31:09,010 --> 00:31:12,870 And then we will put what we want to poison which is main.js. 263 00:31:16,810 --> 00:31:19,050 And it seems we are lucky enough. 264 00:31:19,750 --> 00:31:20,410 Yeah. 265 00:31:20,650 --> 00:31:26,230 So first, as you, if you observe, the first time we got a miss, so nothing there. 266 00:31:26,230 --> 00:31:27,230 Now we got a hit . 267 00:31:27,230 --> 00:31:30,110 So it seems it worked. 268 00:31:30,310 --> 00: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. 269 00:31:37,670 --> 00:31:43,890 So now, if we load, let's try this. 270 00:31:45,930 --> 00:31:46,890 Wow. 271 00:31:47,210 --> 00:31:48,250 Let's do it again. 272 00:31:50,130 --> 00:31:57,350 The problem is the time because, yeah, so I need to wait the 20 seconds for this to stop being cached. 273 00:31:58,950 --> 00:31:59,910 Unfortunately. 274 00:32:03,670 --> 00:32:04,790 C cached. 275 00:32:08,170 --> 00: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. 276 00:32:16,750 --> 00:32:18,050 But right now it worked. 277 00:32:18,050 --> 00:32:24,690 So okay, so now if I go, I do this, this is going to do everything that we saw. 278 00:32:28,950 --> 00:32:30,470 And it's good. 279 00:32:36,710 --> 00:32:37,590 Okay. 280 00:32:39,790 --> 00:32:41,110 I'm running out of battery. 281 00:32:43,710 --> 00:32:47,470 Okay, so I have time for this secret demo. 282 00:32:53,750 --> 00:32:54,470 Yeah. 283 00:32:58,650 --> 00:33:05,750 Okay, so we already saw how we can use different discrepancies between URL parsers to exploit web caches. 284 00:33:05,790 --> 00: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. 285 00:33:14,110 --> 00:33:17,750 One of them is the HTTP 0.9 smuggling. 286 00:33:18,370 --> 00: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. 287 00:33:26,870 --> 00: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. 288 00:33:38,490 --> 00:33:41,870 But maybe you don't know that there's HTTP 0.9. 289 00:33:41,870 --> 00: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. 290 00:33:52,930 --> 00: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. 291 00:34:01,010 --> 00:34:06,570 And the connections are not persisted, the responses of course shouldn't be cacheable. 292 00:34:07,590 --> 00:34:13,650 So this is basically a basic 1.1 request, a HTTP 1.1 request. 293 00:34:13,650 --> 00:34:17,270 We send a request to home, we get a response, nothing strange. 294 00:34:17,650 --> 00: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. 295 00:34:34,230 --> 00:34:36,430 You will just get the response which is the body. 296 00:34:37,330 --> 00:34:41,270 If you send something like this, still HTTP 0.9. 297 00:34:41,490 --> 00:34:44,690 If you send this, 0.9. 298 00:34:44,830 --> 00:34:47,230 And if you send this, 0.9. 299 00:34:47,430 --> 00:34:49,870 So why is this interesting at all? 300 00:34:49,870 --> 00: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. 301 00:35:01,230 --> 00:35:04,650 So most of the attacks are discarded just because of that. 302 00:35:04,650 --> 00: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. 303 00:35:13,110 --> 00: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. 304 00:35:27,050 --> 00: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. 305 00:35:40,810 --> 00: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. 306 00:35:52,010 --> 00:35:57,550 And also connections are not persistent so a lot of attacks are also discarded because of that. 307 00:35:58,570 --> 00: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. 308 00:36:07,090 --> 00: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. 309 00:36:14,090 --> 00: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. 310 00:36:23,850 --> 00:36:30,130 And the back end will send a body because it's 0.9 and so no headers. 311 00:36:30,130 --> 00:36:33,870 And now Imperva is going to try to use this as a response . 312 00:36:34,030 --> 00:36:35,670 And probably it's going to fail. 313 00:36:35,670 --> 00:36:40,010 And so you are not going to see a lot of valid responses because of the parsing. 314 00:36:40,010 --> 00: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. 315 00:36:48,130 --> 00:36:53,510 But what if the body does have these valid HTTP response headers? 316 00:36:54,330 --> 00: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. 317 00:37:08,530 --> 00: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. 318 00:37:21,410 --> 00:37:25,310 Again this demo, I hope it works. 319 00:37:27,750 --> 00:37:29,530 Um, okay, yeah. 320 00:37:29,930 --> 00:37:35,550 So in this super page, web page I created an upload file feature. 321 00:37:36,830 --> 00:37:37,970 Okay. 322 00:37:37,970 --> 00:37:42,490 And in this upload file feature we can upload any file we want. 323 00:37:42,490 --> 00: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. 324 00:37:55,810 --> 00:37:57,450 Probably you can't see it. 325 00:37:57,450 --> 00:38:03,350 But yeah, it contains a cache control header saying that it should be stored for 10 seconds I think. 326 00:38:04,010 --> 00:38:06,110 Let's put 100 seconds. 327 00:38:07,390 --> 00:38:13,150 And so when I upload this, I will also be able to retrieve this. 328 00:38:15,610 --> 00:38:19,670 So it seems like it was uploaded. 329 00:38:20,130 --> 00:38:21,410 So let's go back to burp. 330 00:38:21,410 --> 00:38:21,410 Okay. 331 00:38:21,410 --> 00:38:26,510 And so, okay, so this is the file that I uploaded. 332 00:38:26,690 --> 00:38:31,230 Okay, let's say we have this upload download feature which is pretty common in many applications. 333 00:38:33,370 --> 00:38:35,470 And this works. 334 00:38:35,470 --> 00:38:35,890 Yeah. 335 00:38:35,890 --> 00:38:41,330 As you can see, I uploaded this file which in the body we have a valid HTTP response. 336 00:38:41,390 --> 00:38:43,790 Containing headers, containing everything we want. 337 00:38:44,610 --> 00: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. 338 00:38:58,880 --> 00: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. 339 00:39:05,500 --> 00:39:09,560 It was trying to parse the response body of the home page as 0.9. 340 00:39:09,560 --> 00:39:10,320 Failed. 341 00:39:10,320 --> 00:39:11,040 Okay. 342 00:39:11,200 --> 00:39:17,520 Now, what if we send the same but for this response? 343 00:39:21,660 --> 00:39:25,760 And as you can see, Imperva thinks that this is a valid response. 344 00:39:25,880 --> 00:39:28,260 It's actually using the cache control header. 345 00:39:28,940 --> 00:39:31,000 And it's contain, it's putting everything. 346 00:39:31,000 --> 00:39:34,700 It's also including his own header so it seems like it's working. 347 00:39:35,480 --> 00:39:38,120 So, yeah, we can poison this file. 348 00:39:38,120 --> 00:39:39,020 Great. 349 00:39:39,020 --> 00:39:43,700 So someone that is accessing this file is going to receive this response and is going to be attacked. 350 00:39:43,700 --> 00:39:45,560 Now, not really cool. 351 00:39:45,560 --> 00:39:49,640 So we can use something that I just explained which is modifying the old cache key. 352 00:39:49,860 --> 00:39:54,500 Again, we can use the request to the thing that we want to store. 353 00:39:54,780 --> 00:39:57,440 Then the cache, in this case we are using Imperva. 354 00:39:57,440 --> 00:40:01,020 Imperva doesn't think that the cache is a, is a delimiter. 355 00:40:01,260 --> 00:40:03,900 Ah, this, sorry, this time we are using Imperva and Nginx. 356 00:40:04,840 --> 00:40:07,940 And the, then we have a path reversal. 357 00:40:07,940 --> 00:40:16,160 I added a few slashes because it's the way to avoid being detected as an attack by many CDNs. 358 00:40:17,060 --> 00: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. 359 00:40:27,860 --> 00:40:29,680 And so we are going to poison the index. 360 00:40:31,240 --> 00:40:34,640 So if we send this, I will have a little bit of luck. 361 00:40:35,980 --> 00:40:40,240 Yeah, it seems it's working because the second time was obtained from the cache. 362 00:40:40,660 --> 00:40:49,500 So now if I go back to the home page, it's not working. 363 00:40:49,820 --> 00:40:56,100 Ah, sorry, I this was, eh, this was the Azure one. 364 00:40:56,200 --> 00:40:58,040 This is the Imperva one, fortunately. 365 00:40:58,160 --> 00:41:03,080 So if we go to Imperva, arbitrary cache. 366 00:41:17,250 --> 00:41:22,150 Okay, so how we can defend against these kind of attacks? 367 00:41:22,150 --> 00:41:28,590 Well, first we need to use the, eh, cache control header for web cache deception. 368 00:41:28,590 --> 00: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. 369 00:41:36,850 --> 00: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. 370 00:41:45,990 --> 00:41:52,810 So sometimes the rules for the request have priority and therefore it's important to check if this is happening. 371 00:41:52,810 --> 00:41:58,950 If this is happening, try to modify this and if it's not possible, then try to consider using another CDN. 372 00:41:59,190 --> 00:42:05,830 And then, eh, for cache poisoning, well, we can try to abort, to disable the key normalization. 373 00:42:05,890 --> 00:42:08,070 In some cases it's possible, in some cases it's not. 374 00:42:08,070 --> 00: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. 375 00:42:17,430 --> 00: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. 376 00:42:24,350 --> 00:42:29,550 These are all the references, eh, for the reason I, I use all this information. 377 00:42:29,570 --> 00:42:32,210 All the other attacks that inspired me. 378 00:42:32,230 --> 00:42:39,690 And also, in the slide you have the, eh, the links for the cache poisoning and cache deception academy topics. 379 00:42:39,690 --> 00:42:42,350 We just released the academy topic for deception. 380 00:42:42,390 --> 00:42:49,530 And also the extension for cache killer, which is the, the extension I created for, to detect this. 381 00:42:49,530 --> 00: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. 382 00:42:57,570 --> 00: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. 383 00:43:08,730 --> 00:43:15,510 So web cache poisoning and deception, eh, can be used in many, many cases wherever we find these kind of discrepancies. 384 00:43:15,850 --> 00: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. 385 00:43:24,470 --> 00: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. 386 00:43:32,530 --> 00: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. 387 00:43:42,610 --> 00:43:49,850 Probably to upgrade vulnerabilities that are not really useful and probably to be, to get better payments in bad bounties. 388 00:43:49,850 --> 00:43:52,050 So I hope this helps everyone. 389 00:43:52,970 --> 00:43:54,270 And that's it. 390 00:43:54,270 --> 00:43:54,910 Thank you.