start	end	text
0	7200	Uh welcome to track two, talk number two on Saturday. Uh this morning we uh have Martin and
7200	11360	he's gonna talk about breaking the rules of web cache exploitation. So are you ready
11360	20600	Martin? I'm ready. Let's hear it for Martin. Thank you. Hello everyone. Welcome to
20600	28320	Gara Cache Mall, bending the rules of web cache exploitation. Uh it's already not
28320	35400	working. So this is the agenda for today. First I'm going to briefly explain how a web
35400	40240	cache works and then I'm going to show how we can abuse some discrepancies between the
40240	45860	URL parsers of HTTP servers and cache proxies in order to steal secret information from
45860	52060	victims using arbitrary web cache deception. Next I'm going to show how you use the same
52060	57460	techniques or similar techniques to obtain arbitrary web cache poisoning by modifying the
57460	63580	keys of a store resource. Then I'm going to combine both techniques in order to store
63580	68800	whatever I want in the web cache with any key so this will allow us to create a full
68800	73740	defacement of a website. And finally I'm going to present some protections that can be used to
73740	80620	defend against those attacks and it takes hours of the session. So before I start, eh I
80620	85140	want to clarify that most of the or all the examples are going to be based on CDNs like
85140	89700	Cloudflare, Cloudfront, Akamai, but the idea is that you can use all of these techniques
89700	95440	with any HTTP with any web cache eh proxy or with any web cache that you want even those
95440	102420	that are included in the HTTP server. So whenever someone sends a request to a website using
102580	106820	a web cache, basically the first thing that is going to happen is that the cache proxy is
106820	110980	going to handle the request and is going to try to generate the response without having to
110980	116700	communicate with the origin server. And this is going to be done by calculating a key and
116700	121740	this key is basically an identifier of the request that states which is the resource that is
121740	127300	being requested and it's not really important other things like the, the heaters like cookies
127300	131880	or user agent because when we have two requests that are looking for the same resource and
131880	136980	that resource is static, then we just need to provide the resource and we don't care about
136980	143420	processing anything else. So we will see that the keys are just URLs and host names and in
143420	150880	this talk we will just focus on the URL. So when the cache proxy calculated this key and is
150880	157860	looking for a response that can be served eh to this request, he will look at the cache
157860	163320	table and if there's nothing there, it will send the request to the origin server. Now the
163320	168400	origin server is going to parse the URL, obtain the path and then it's going to use an
168400	173480	endpoint to resolve the request. Sometimes it's just a static endpoint like a file and
173480	180020	sometimes it's a dynamic one that is generated by a program back net. So when this response
180020	185200	is sent back to the cache proxy, the well the cache proxy is going to generate to
185200	190180	evaluate some rules to see if this response should be stored in the cache. So if it's static
190180	196900	or not. These rules are usually evaluated on the response using the cache control heater but
196900	202040	also in the request the cache proxy is going to extract the path and it's going to
202040	207040	evaluate it with some of the other rules. For example the static extension one which is by
207380	213500	default in most CDNs that looks for static extensions. So basically this is the list that
213500	219160	Cloudflare has. And it will look for the path and the extension of that path. And if it
219160	223900	ends with any of these eh extension, any of these strings, then it's going to decide that
223900	229280	this is a static res- resource and it's going to store it in the in the web cache. So in
229280	234180	this example we see that styles dot CSS ends with a static extension. And therefore it's
234180	240280	going to be cached using the key that was calculated in the first step. Now whenever
240280	245120	another client or even the same client sends a request to the same resource, the cache
245120	249820	proxy is going to handle that, it's going to get the key of that request and then it's going
249820	254440	to retrieve the res- the store resource because it doesn't need to interact with the
254440	259980	original server. And that's basically how a web cache works. Now we can exploit this in
259980	265360	many ways. The first one is usually is the first one I'm going to describe actually is the
265360	272280	one that was discovered by Omer Gil in 2017 which is a web cache deception. And basically
272280	278120	this attack is based on the idea that some backend servers use this special mapping where
278120	283380	they are going to put some parameters in the path. This is called path parameters. And
283380	287020	they are going to just look for the beginning of the path and they will try to match it with
287020	293880	uh with any regex that is a relate- related with the handler. So in this case if we send a
293880	298880	request to slash my account slash param one, param two, then only the first part is going to
298880	305400	be used to map the end point. And then this in this case is going to the original server is
305400	308800	going to generate a response which contains a lot of information from the victim because it
308800	315220	is my account. And it contains for instance the mail or the credit card details. So
315220	322180	basically this is what we want to steal. And to do so the first thing is to send uh a link to
322180	327560	the victim. This requires user interaction. And the link will start with the end point that
327560	332700	we want to steal the response. So in this case it's my account. And then it will use as a
332700	338620	parameter a dot js. And the reason this is because first when it's handled by the
338620	343800	origin server this is going to be mapped to my account using the cookies of the victim. And
343800	348660	so the response with the sensitive information is going to be sent back to the to the proxy.
348960	354660	And now with the cache proxy it will use the the path. This in this case it doesn't know
354660	359180	anything about this mapping. So it will think that the last part is just a parameter is not a
359180	363600	parameter sorry it's a path. It's part of a path. And therefore it will think that it has a
363600	368820	static extension. In this case dot js. And so it will start this response containing all the
368820	373760	secret information. Now the attacker can send the same request and as the cookies are not
373760	378940	important as the only important thing is just getting the same path. Well the cache proxy is
378940	383140	going to match it with the key that already calculated in the first place. And it will
383140	388200	retrieve the victim's response containing all the secret information. Now the problem in
388200	392840	this technique is that we need a special mapping for that. Basically we need this special
392840	397420	my account thing. And then we also require that the parameters that we are sending in this
397420	403140	case a dot js doesn't have any effect on the backend because if not maybe the the response is
403140	409740	not going to contain that information that we want. So I started looking at different ways to
409740	414220	obtain arbitrary web cache deception which is basically obtaining the same thing but for any
414220	420720	kind of uh end point that we want. And to do this I started looking at how the the path is
420720	427240	obtained at each state. So basically the path is obtained from a URL by using these delimiters
427240	432600	which are basically characters that can then can be used to know where each part of the URL
432600	438280	or each part of the elements of the URL start and begin uh and end. There are a lot of them
438280	443600	defined by the RFC. So we can see that the URL has things like the scheme, the
443600	449280	credentials, the host, the path query and fragment. So to split the each of them in a URL we
449280	455520	need these these delimiters. The problem is that the RFC says that any any of these delimiters
455520	461000	may or may not be or any of these characters may or may not be used as delimiters. And so
461000	467220	each implementation can choose new delimiters and this could create some discrepancies. So
467220	473060	let's say we find a server that is using a cache proxy and that is using the dollar sign as a
473060	478420	delimiter. Then if we send a request to my account dollar sign eight dot JS this is just
478420	483680	going to be interpreted as my account because of the delimiter. However as I said in the
483680	489340	front end there's no delimiter being being said with uh the dollar sign and therefore this is
489340	493320	going to be interpreted the entire URL is going to be interpreted as the path and the last
493320	498320	part which is eight dot JS is going to be used as the extension. In this case actually it's
498320	503240	dot JS the extension and so this is going to be stored in the cache just because of that
503240	508340	delimiter. And in this case we can use it with any kind of path we want because we are not
508340	515600	attacking a mapping we are attacking the entire way of obtaining the path from the URL. Now
515600	520700	which kind of delimiters we can find in the well well there are a lot of them. Some I listed
520700	527580	were in the frameworks is uh the first one is semicolon in spring so basically to define a
527580	534440	matrix variable that is similar to a path a parameter we can use a semicolon. And the thing is
534440	540400	that if we send something like my account semicolon eight dot JS anyone using Java probably
540400	545740	Java in the well so they are going to consider this as my account. This includes Google or
545740	552160	big companies that are using Java because this is how spring works. And so we can use this
552160	558140	for the attack. Now in Rails there's another really interesting case which is they use the
558140	564440	dot as a delimiter and that's because um the user is able to send an extension with a valid
564440	569960	endpoint and this will the effect that this will have is that Rails will look for a specific
569960	575860	view for that uh request. So let's say we define uh an endpoint which is my account and then
576420	581660	when we send a request to my account Rails will just go and look for the HTML view. Now if
581660	587880	we send something like my account dot CSS Rails will not just return a not a not found but it
587880	593900	will look for the view of the the CSS view of my account. Usually there's no CSS view for my
593900	599880	account so we'll just receive a 406 error. But the thing is that if the extension that we
599880	604560	include is not recognized by Rails so let's say we send something like my account dot AAA
605180	611640	then Rails is just going to send us the default view which is HTML. Remember all these
612440	616920	extensions that are defined by Cloudflare. Well in green you can see the ones that are
616920	625060	recognized by Rails. So if we send my account dot PNG or dot GPA or CSS then all of them are
625060	629180	going to be recognized by Rails and it's going to try to look for that response and if there's
629180	635600	no view for that extension then it's just going to return us an error. But in red we see all
635600	640060	the other extensions that are not recognized by Rails. So we send something like my account
640060	645160	dot ICO then we are going to get the default view but Cloudflare is going to think that this
645160	652300	is a cacheable resource. Now there are other delimiters that can be used in HTTP servers
652300	657660	instead of frameworks such as the encoded null byte which is the case of open light speed. So
657660	662180	basically this works like a question mark if we send something in my account null encoded
662180	669060	byte A dot JS then this is just going to be used as my account. The problem for this is that we
669060	673920	cannot send it through many CDNs like Azure, Impairment, Cloudfront, Cloudflare, Google
673920	678560	Cloud. That's because they don't accept null encoded bytes. But fortunately Akamai and
678560	686320	Fast2DC yes so we can use them for eh this explanation. And finally in NGINX we have a
686320	693220	delimiter whenever we define a rewrite rule and the delimiter is the new line encoded and so
693220	697160	basically it works just as in open light with a null encoded byte and in this case we can send
697160	704340	it through any CDN we want. So if we send a request using any of these delimiters with the
704340	709000	correct with the corresponding eh backend then all of them are going to be interpreted as my
709000	714300	account. The response is going to be sent back but in this case the web caches are going to
714300	721640	just store that because of the static extension. But the problem with this attack is that many
721640	726200	CDNs are are already aware of this and they are implementing some detection some
726200	730680	protection for for this kind of attacks. In the case of Clover for instance is web cache
730680	736680	deception armor which what it does is it looks for the extension of the request and the
736680	741380	content type of the response. And if they don't match for for instance in this example we are
741380	748080	using dot CSS as the extension and the content type is text HTML so if they don't match
748080	754740	basically this is an attack and Clover won't store this in the cache. So we can attack other
754740	760940	rules like the static directories one. That's a rule that we can create as users that states
760940	765780	that anything starting with a specific path is going to be stored in the cache and that's
765780	770580	really common in many applications because we we usually store static files in the same
770580	776660	directory like share, public, assets, resources, anything that you can think. And so we can
776660	781900	use this to attack this kind of eh this kind of web caches that are used in the rules. To
781900	787340	create an attack in this case we will need some payload that is interpreted in the front end
787340	792700	with the static directory at the beginning so basically if the static directory is called
792700	799140	static then we want the path to start with static slash and anything we want. And then in the
799140	804240	backend we still want my account because we in this case want to steal my account we could
804240	810560	steal anything else we want. So if we have a delimiter in the backend we can try to do this
810560	816980	but we will need something else. And as I said to extract the path from a URL we just need
816980	821760	the delimiter and then that path is used in the keys rules and mapping. Well not really
821760	827640	there's one extra step which is normalization. We need to normalize the path and most
827640	834120	CDNs and backend servers do normalize the path. This includes decoding the characters. We can
834120	841140	send them with URL encoded uh notation that is percentage uh and the XML value of a
841140	847040	character. And then in some cases the uh other characters like segment delimiters like the
847040	853160	slash or the dot are also going to be decoded. So this is going to be really useful. And
853160	859200	then the normalization also includes dot segments uh resolution which is just resolving
859200	863980	path traversals and whenever we find a dot segment then we just remove the previous segment.
864460	872720	And some parsers like the IIS one uh will also convert backslashes to slashes. So now that we
872720	877380	know this we can actually create a new payload that is going to use normalization. Again we
877380	881720	are using a delimiter so everything before the delimiter is going to be interpreted in the
881720	888140	backend server. But now we are also sending an encoded uh path traversal. And that is
888140	893960	because the frontend is not using the delimiter so it's going to resolve this into this. And
893960	900500	this includes a path traversal which is going to convert it to static WCD. So now in the
900500	905100	frontend we see that there are static directories there so this is going to be stored in the
905100	910340	webcache. And in this way we are able to bypass the webcache deception armor because there's
910340	918400	no extension so nothing to convert. Now let's see how how we can how we can apply this in a
918400	926340	real environment. And so first we need uh a frontend that is normalizing the path. Sorry. Uh
926340	932080	this is the case for CloudFront, Imperva and Azure. And so if we combine them with any
932080	937420	backend that is using a specific delimiter like for instance Tomcat, then we can send the
937420	944000	same the same payload which is secret the semicolon with that represented delimiter. And
944000	949100	this will cause that in the backend we see secret. And in the frontend again the
949100	954560	semicolon is not a delimiter for either CloudFront, Azure or Imperva and therefore this is
954560	961200	going to be resolved to static slash X. And this way we will be able to steal any response we
961200	967100	want in an environment that is using basically a default configured Tomcat and any of the
967100	974760	CDNs that I showed. This can be used also with other backends like uh Rails and Puma or even
974760	979860	some in the same case that we observed in the in the first example when we had a special
979860	985200	mapping in the backend. In this case there is no delimiter, the delimiter is just the the
985200	993600	path that we are attacking. Now we could also try another attack that is using the opposite
993600	997440	normalization so basically in the frontend we don't have normalization, that's the case of
997440	1003020	CloudFront, uh Google Cloud Platform and Fastly. And in the backend we have normalization
1003020	1011000	in Nginx, IIS and open light speed. So if we use this, we can create the attack by starting
1011000	1016840	with the static directory. In this case it's slash static. And this is because the path is
1016840	1022360	not normalized and so CloudFront for instance will think that this is the entire URL is the
1022360	1028700	path. But in the backend this is going to be normalized and therefore anyone using Nginx or
1028700	1034780	IIS or open light speed is going to see that their response is going to be for secret and
1034780	1041200	this will be storing the cache because of the static path. This worked on OpenAI and many
1041200	1050060	other bounties that I wasn't able to be, I'm not able to talk about. And also this can be
1050060	1056520	used with IIS, basically IIS is the only one that is decoding uh normalizing the backslash. So
1056520	1061960	if we send something like using the, in the slide, this is going to be converted to static
1061960	1066500	and basically a dot segment with a backslash and it's going to be converted to account in
1066500	1073460	IIS but not in any other uh CDN because IIS decided that this is a cool idea. And so yeah,
1073460	1079980	they are the only ones that I can be attacking with any other CDN. Now if we don't find
1079980	1083960	one of these rules, well there's, there's another rule that we can use which is the static
1083960	1092120	files. And in many, in many CDNs we will see that there's a static file rule by default to
1092120	1098120	store robots dot txt but we can also find others for favicon or for index dot html or for
1098120	1104620	any, any file that is usually accessed by people and is static. And in this case we can use
1104620	1109060	the same attack only that we are not going to target a static directory, we are just going
1109060	1115180	to target something that is being stored by the front end. So we can do something like
1115180	1121620	secret then the, the limiter, the encoded dot segment and finally robot dot txt and this
1121620	1127020	should work in many, in many applications. And also we can try to find other files. I found
1127020	1131880	that there are many in the, in, in the wild so you should be able to find many others if you
1131880	1139040	look for. So webcast deception is pretty cool but the thing is you need user interface
1139060	1144320	interaction and we don't really want user interaction. So webcast poisoning is there for
1144320	1150200	rescuers and the idea in webcast poisoning is that we are going to try to store a malicious
1150200	1156160	response in, in a, with a key that is going to be accessed by other people. So let's say we
1156160	1162220	want to hijack someone that is using this, this website, this website and is accessing through
1162220	1166440	the home page. Well if we are able to find a payload that is stored in the home page then
1166440	1171840	everyone navigating through the web page is going to be affected. And usually you will look
1171840	1176260	for something that is not stored, like that is not using the key so in this case if the cookie
1176260	1182180	value is reflected in the, in the body of the response then we are able to store this and
1182180	1188160	anyone using the home page is going to be affected and is going to re, is going to retrieve
1188160	1194600	the malicious response. The problem with this attack is that in many cases we will find a, an
1194600	1199840	example of a cache poisoning but it's with a, it's using a key or it's using a resource that
1199840	1203740	is not going to be accessed by anyone. Like for instance if we are able to poison something
1203740	1208940	that starts with files then our user name and then a unique ID, no one is going to be
1208940	1215840	accessing that uh, that path by themself. So we will need user interaction. And that's not
1215840	1223160	really cool. So to avoid having to interact with any victim, I designed an attack that is
1223160	1230460	going to be able, it's going to allow us to change the key of the uh, poison resource. Now in
1230460	1235200	this case we will need key normalization and this is by default in impaired but Azure is just
1235200	1240860	normalizing the key. Uh, and it's partially by default also in Akamai and it's configured in
1240860	1246360	all the other CDNs and what's really interesting about this is that if you remember Cloud
1246360	1250860	Front for instance was normalizing the rules but it's not normalizing the key. So that means
1250860	1256000	that they have different parsers for each of these processes which is even in the same uh,
1256000	1261800	in the same HTTP parser probably. So this, this tell us that we can even find other
1262400	1268480	desynchronization attacks or other discrepancies even in the same uh, in the same web cache.
1269160	1275920	So as I said, what we need is uh, a front end that is normalizing the key and what we can do to
1275920	1280740	detect this is to send a request to a static resource like style dot CSS and whenever we
1280740	1284520	see evidence that this is of being obtained from the web cache, so for instance we have an
1284520	1292320	X cache hit value uh, hitter or we can just compare the time of the response and whenever we
1292320	1297660	find this then we need to modify the path so that when normalized we still have style dot
1297660	1302800	CSS and if we send this request and the response is still from the cache then it means that the
1302800	1310020	key was normalized and so we detected key normalization. And how we can exploit a web
1310020	1315140	cache poisoning with this, well basically we will try to modify as I said the key by sending
1315140	1320360	first the exploit that we want so this is the, the uh, the response that we will, we will use
1320360	1326100	to poison. Uh, usually contains a malicious payload. Then a delimiter, so again we will
1326100	1330440	need a delimiter in the back end, but as I said this is really common and we can find them
1330440	1336800	almost anywhere. And then we will need some normalization in the front end, so in
1336800	1342720	Burba, Azure, and sometimes Akamai and all the others that are configured. Uh, and this is
1342720	1347040	going to be a result of poison. So basically the web cache is going to store the exploit
1347040	1351480	response in the poison end point which is something we control so it's arbitrary, we can
1351480	1361650	just wire up a path we want, usually the home page. So in the, in the first example I didn't
1361650	1366290	talk about one of the delimiters because we weren't able to send it with web cache
1366290	1371170	deception and that's because the user needs to send it through his browser and anything
1371170	1377290	but uh, and if the browser sees a hash, then it's not going to send the fragment. But in web
1377290	1382990	cache poisoning we can use the fragment. So I, I started looking at different, at the
1382990	1388270	behavior of different CDNs and HTTP servers and even frameworks in regarding the, the
1388270	1394230	hash. And I found that there were a lot of differences. The most interesting one was again
1394230	1399050	in purple because there were no likes in the key. A cloud front, well sorry, cloud front
1399050	1403990	can be configured to, to do the same thing so it's interesting to see they are too. And
1403990	1411110	basically if we have a hash and a, and key normalization then we can use in purple for, for
1411110	1415910	this exploit that I'm going to show. And in the backend we can use pretty much any HTTP
1415910	1420410	server like NGINX, Unicorn, Puma, then we can use also frameworks like Rails, Flash,
1420410	1427010	they are not going to see the hash as a delimiter. Sorry, they are going to see the hash as a
1427010	1433410	delimiter. And so basically we can send an attack that uses the hash. First we are going to
1433410	1437330	send what we want to be interpreted in the backend because it's going to be using the
1437330	1442970	hash. And so if we send something like this, then the XSS is going to be interpreted as the
1442970	1447130	path in the backend. It's going to retrieve, retrieve the response, the malicious response.
1447130	1452250	And now this is going to be normalized, the key, so we will be able to poison the homepage
1452250	1460410	with any, any webcache poisoning eh, payload that we have. This was found in Vista, MasterCard
1460410	1468150	and T-Mobile and again many others that I'm still unable to talk about. And of course we can
1468150	1476710	use the same attack for with eh, Azure in purple and also with Tomcat, with Rails, with NGINX,
1476710	1482110	with eh, new line encoded. And also again with any backend that is using a special
1482110	1488150	mapping. So it should be pretty easy and I already saw many people exploiting this eh, since
1488150	1494750	I give this talk in black hat so it seems like there are a lot of targets. Now we can do
1494750	1499570	similar, a similar thing with Azure, only in this case Azure is considering the front, the
1499570	1508070	hash as a delimiter and this is not the case for OpenLaySpeed, Express and Django. So what
1508070	1512990	we are going to do is we're going to send a payload that in this case starts with what we
1512990	1518470	want to poison, so the keys, the beginning and that's because the front end is using the
1518470	1524250	hash as a delimiter. Then the rest is going to be normalized and we have the exploit. And
1524250	1530170	again we can poison any path we want that is using Azure and OpenLight or other
1530170	1534910	frameworks. There are other examples but as I, in this research I wasn't able to look for
1534910	1543090	all, all servers but yeah. And this was found again in OpenAI so yeah, they, they acted
1543090	1546950	really fast and they fixed the issue which I'm not sure, really sure how they fixed because
1546950	1555730	it's still there. And, and so what if we don't have a payload? So let's say we don't have
1555730	1561090	anything that we can use to poison a malicious response. We only, we are only able to
1561090	1566630	change the keys. Well, we still can do something. We can start poisoning all the paths
1566630	1572970	with a static file. So let's say we use status.css, this will poison every single path and
1572970	1577790	so when a user sends a request to home, my account or any other path, he will just get CSS
1578430	1583490	and therefore a denial of service. Which many companies think that this is not a vulnerability.
1586070	1592270	So, sorry. So we already saw how we can poison anything we want and how we can change the
1592270	1599590	key so it's just combining those ideas to create a very useful payload. And the first thing
1599590	1604810	we need to do to store everything, anything we want in anywhere is to identify a malicious
1604810	1610170	response that we want to use. And this malicious response, the, the, what's interesting
1610170	1614270	about this attack is that we are going to combine both so the response doesn't need to be
1614270	1618710	uh, cacheable. So we can use anything we want. In this case we are going to use an open
1618710	1623310	redirect which is not stored, which is not cacheable and therefore is, is not a
1623310	1628490	vulnerability. You can't report this to anyone because it's really not a vulnerability. Then
1628490	1634790	we need to choose what we are going to poison and what I usually recommend is to poison some
1634790	1639530	script that is being included in uh, in any web page, usually the home page. So in this
1639530	1644790	case we have a home page that is uh, loading a main.js script. So we are going to poison
1644790	1650730	that with an open redirect. Why? Well because first, as I said, we are going to use this
1650730	1655450	technique. In this, in this example, this demo I'm going to show it using Azure and Tomcat. I
1655450	1662390	finished coding this, this morning so it could work, it could not work. But uh, the thing is if
1662390	1666970	we send something that starts with, in this case logout which is the open redirect, then the
1666970	1670770	semicolon which is the delimiter, this is going to be interpreted as logout using the
1670770	1676550	x forwarded host header which is going to show, to show, to send the, the victim to the
1676550	1683610	evil.com. And then this is going to be normalized so we are going to poison main.js and this
1683610	1689250	is because it has a static extension. So even if the operator wasn't storable by default,
1689250	1694430	well we have the static extension so we are able to poison main.js using this attack. Now
1694430	1700730	when a user loads the home page, he will again load the main.js script and when this
1700730	1707650	request is uh, is received by the, by Azure, he will just send the open redirect which will
1707650	1713230	redirect the victim to the evil.com server, will load the malicious JavaScript and we will
1713230	1719250	be able to poison any, any victim with a malicious script that we completely control. And
1719250	1724890	if we have the content security policy enabled to provide, to avoid this kind of attacks,
1724890	1729690	then we can use something like CSX exfiltration to obtain anything we want. You can ask
1729690	1743870	Gareth about that, he knows a lot. And so yeah, this is the demo. Uh, so yeah, so this is
1743870	1751810	the web page. This is using Azure right now. And maybe this is, yeah, this is loading,
1751810	1758670	perfect. Internet. Uh, so when we send a request to the home page, which is caches, cache
1758670	1767270	all Azure blah blah. Don't hack it right now please. Uh, yeah. So we see that the main.js is
1767270	1779030	being imported. So that's what we want to attack. This is main.js. Yeah. Main.js is being
1780190	1786010	obtained from the cache right now. So it's going to last 20 seconds. I said 20 seconds
1786010	1790230	probably is going, in a real application is going to be a day, maybe some days. So you will
1790230	1796790	need to wait for that to stop doing, you can just use uh, an intruder session. Now, this is
1796790	1805600	the open redirect that we are going to use. This is the evil.com. And as you can see, this
1805600	1811000	is being, this is an open redirect that is not being cacheable. Config no cache means no
1811000	1820780	cacheable. This is the evil.com server that is going to load our arbitrary javascript. And this
1820780	1826420	is the exploit. Now I'm going to try to code it by myself. So again, the exploit is going to
1826420	1832460	work like this. First we put the thing that we want to, to log. So this is going to be used in
1832460	1840600	the backend. Logout. Logout is the open redirect. Then the semicolon to um, to use as a
1840600	1848480	delimiter. Now, because the way that java use semicolons is uh, is uh, semicolons only work
1848480	1852460	for a segment so we cannot put a slash after the semicolon because it's not going to be, it's
1852460	1857640	not going to work. So we need to send the slashes and everything encoded in this case. So
1857640	1870090	this is a slash encoded. This is a dot encoded. Yeah, the dot segment encoded. And then we
1870090	1880890	will put what we want to poison which is main.js. And it seems we are lucky enough. Yeah. So
1881410	1887110	first, as you, if you observe, the first time we got a miss, so nothing there. Now we got a
1887110	1894290	hit. So it seems it worked. So if we load, if we try to get the main.js now, instead of
1894290	1903890	getting the js that we had, we have an open redirect. So now, if we load, let's try this.
1905930	1914850	Wow. Let's do it again. The problem is the time because, yeah, so I need to wait the 20
1914850	1929490	seconds for this to stop being cached. Unfortunately. C cached. So as you see, I'm
1929490	1934270	getting the main.js, that's because it's being resolved the key and I'm getting the restore
1934270	1943010	resource right now. But right now it worked. So okay, so now if I go, I do this, this is going
1943010	1965290	to do everything that we saw. And it's good. Okay. I'm running out of battery. Okay, so I have
1965290	1981910	time for this secret demo. Yeah. Okay, so we already saw how we can use different
1981910	1987530	discrepancies between URL parsers to exploit web caches. But there are other kind of
1987530	1991030	discrepancies where you can use, and there are many other discrepancies that I didn't
1991030	1998850	research on, but probably you can look for them. One of them is the HTTP 0.9 smuggling. And
1998850	2003910	basically, I trust that most of you already know what HTTP is, the basic protocol that we
2003910	2009830	use every day to communicate in the internet. But, and probably you already know the
2009830	2019350	really new HTTP 3, the still new HTTP 2, the classic HTTP 1.1 and even HTTP 1.0. But maybe you
2019350	2026330	don't know that there's HTTP 0.9. 0.9 is basically a legacy protocol that shouldn't be
2026330	2033370	used by anyone unless you are NGINX, Apache, IIS or any other HTTP server in the world. And
2033370	2039490	the thing with HTTP 0.9 is that we don't have any headers, so no header for requests, no
2039490	2045270	header for responses. And the connections are not persisted, the responses of course
2045270	2053850	shouldn't be cacheable. So this is basically a basic 1.1 request, a HTTP 1.1 request. We
2053850	2059950	send a request to home, we get a response, nothing strange. Now if we remove the HTTP
2059950	2067490	version and we just send get, and the URL, the entire URL, then we will receive a 0.9
2067490	2073230	response if we are targeting NGINX, as I said, Apache, IIS, Tomcat, any HTTP server
2073230	2078730	basically. You will just get the response which is the body. If you send something like this,
2078730	2089150	still HTTP 0.9. If you send this, 0.9. And if you send this, 0.9. So why is this interesting
2089150	2094750	at all? Well browsers are a little bit smarter than others and they knew that it doesn't
2094750	2099990	make sense to keep talking this uh this old protocol, so you cannot send a 0.9 request
2099990	2105870	through browsers. So most of the attacks are discarded just because of that. But let's see
2105870	2111250	what happens if the front end and the back end are not doing the same thing or they don't
2111250	2118050	talk the same protocol. So if we send a request like an HTTP 0.9 request and we send it
2118050	2127650	through a CDN, most CDNs will take this request and they will upgrade it to HTTP 1.1. So then
2127650	2135370	the back end will just generate a 1.1 response, the body will be extracted and sorry, the
2135370	2141710	response will be actually downgraded and we will just be left with the body. And this works
2141710	2148370	basically even if no one should be using 0.9, this works because if the upgrade and
2148370	2155330	downgrading is done correctly then this works. And also connections are not persistent so a
2155330	2161130	lot of attacks are also discarded because of that. But the interesting thing is that some
2161130	2167730	CDNs such as Imperva, they don't verify the HTTP version before forwarding a request. So if
2167730	2172750	we send a request, a 0.9 request, Imperva will say well I will just forward it, I don't
2172750	2178990	care. And the problem is Imperva is not just going to forward it, it's going to think that
2178990	2186690	this is a 1.1 request because Imperva doesn't know about 0.9. And the back end will send a
2186690	2193350	body because it's 0.9 and so no headers. And now Imperva is going to try to use this as a
2193350	2198310	response. And probably it's going to fail. And so you are not going to see a lot of valid
2198310	2203550	responses because of the parsing. Because when Imperva tries to parse a body of a response
2203550	2209390	that doesn't contain valid HTTP headers then this is going to be interpreted as an error. But
2209390	2216670	what if the body does have these valid HTTP response headers? So let's say we have a
2217190	2223610	upload download file feature or let's say we can control the body of a plain text or let's say
2223610	2229910	we are even able to modify the response using byte range or something like that. Then if by
2229910	2234770	any means we are able to control the response, then the body of the response no matter what
2234770	2242250	the content type, no matter anything, then we will be able to use this attack. Again this
2242250	2254250	demo, I hope it works. Um, okay, yeah. So in this super page, web page I created an upload
2254250	2262750	file feature. Okay. And in this upload file feature we can upload any file we want. In this
2262750	2271430	case an evil file that if you want to see it, well it's really really small but basically it's a
2271430	2276690	response containing a script and containing a cache control header. Probably you can't
2276690	2282050	see it. But yeah, it contains a cache control header saying that it should be stored for 10
2282050	2292010	seconds I think. Let's put 100 seconds. And so when I upload this, I will also be able to
2292010	2301410	retrieve this. So it seems like it was uploaded. So let's go back to burp. Okay. And
2303630	2308730	so, okay, so this is the file that I uploaded. Okay, let's say we have this upload download
2308730	2317050	feature which is pretty common in many applications. And this works. Yeah. As you can see, I
2317050	2322330	uploaded this file which in the body we have a valid HTTP response. Containing headers,
2322330	2331410	containing everything we want. Now, if I send an, let's say I send a, an HTTP 0.9 request,
2331430	2340000	which is basically this request that doesn't contain any header here. As you can see,
2340000	2344980	Imperva sends, says that it's an error because it was trying to load the home page as a
2344980	2353000	0.9. It was trying to parse the response body of the home page as 0.9. Failed. Okay. Now, what
2353620	2364620	if we send the same but for this response? And as you can see, Imperva thinks that this is a
2364620	2370420	valid response. It's actually using the cache control header. And it's contain, it's putting
2370420	2376720	everything. It's also including his own header so it seems like it's working. So, yeah, we
2376720	2381560	can poison this file. Great. So someone that is accessing this file is going to receive this
2381560	2387220	response and is going to be attacked. Now, not really cool. So we can use something that I
2387220	2392500	just explained which is modifying the old cache key. Again, we can use the request to the
2392500	2397800	thing that we want to store. Then the cache, in this case we are using Imperva. Imperva
2397800	2402620	doesn't think that the cache is a, is a delimiter. Ah, this, sorry, this time we are using
2402620	2411340	Imperva and Nginx. And the, then we have a path reversal. I added a few slashes because it's the
2411340	2420220	way to avoid being detected as an attack by many CDNs. And so I have this path reversal that
2420220	2425600	removes the files, removes the abl5.txt and so basically the path is going to be converted
2425600	2431880	to the home page which is indexed. And so we are going to poison the index. So if we send
2431880	2439040	this, I will have a little bit of luck. Yeah, it seems it's working because the second time was
2439040	2453200	obtained from the cache. So now if I go back to the home page, it's not working. Ah, sorry, I
2453200	2458980	this was, eh, this was the Azure one. This is the Imperva one, fortunately. So if we go to
2458980	2482590	Imperva, arbitrary cache. Okay, so how we can defend against these kind of attacks? Well,
2482590	2489650	first we need to use the, eh, cache control header for web cache deception. So whenever we
2489650	2494550	have a response that we don't want to, anyone to store it, then just use private and no
2494550	2499750	store for the, for the cache control header. But also, eh, I wasn't able to show it in the
2499750	2504770	example but there are many CDNs that will override this cache control header if there's a
2504770	2511070	rule for the path. So sometimes the rules for the request have priority and therefore it's
2511070	2515990	important to check if this is happening. If this is happening, try to modify this and if it's
2515990	2522370	not possible, then try to consider using another CDN. And then, eh, for cache poisoning,
2522370	2527030	well, we can try to abort, to disable the key normalization. In some cases it's possible, in
2527030	2531870	some cases it's not. So in those cases, I suggest using the tool that I will provide that
2531870	2537030	will let you know if there's any discrepancy between normalization and, eh, delimiters and
2537030	2541390	anything. So this will allow you to know if you need to change either your HTTP server or
2541390	2548430	your, eh, front end server. These are all the references, eh, for the reason I, I use all
2548430	2554390	this information. All the other attacks that inspired me. And also, in the slide you have
2554390	2560070	the, eh, the links for the cache poisoning and cache deception academy topics. We just
2560070	2566290	released the academy topic for deception. And also the extension for cache killer, which is
2566290	2572350	the, the extension I created for, to detect this. It's still in progress, eh, it should work,
2572350	2577570	but I will, I will keep working on, on this, on this tool for the next probably month or two.
2577570	2584530	And the takeaways, basically I showed that we can use any kind of discrepancy we, we find in
2584530	2589610	the, in the wild to exploit, eh, different servers using web cache. So web cache poisoning
2589610	2594390	and deception, eh, can be used in many, many cases wherever we find these kind of
2594390	2601250	discrepancies. Then we can use the exploitation things in many bounties because I found that
2601250	2606130	these kind of delimiters are being used in many systems. So I invite you to look for them in
2606130	2610710	different bounties and collect them and send me a message to just add you in the list of
2610710	2617090	people that are using this. And finally, eh, I found, I showed you a way of chaining these
2617090	2621570	vulnerabilities but you probably can think of many other ways to combine them with different
2621570	2626410	vulnerabilities. Probably to upgrade vulnerabilities that are not really useful and
2626410	2633490	probably to be, to get better payments in bad bounties. So I hope this helps everyone. And
2633490	2634910	that's it. Thank you.
