[00:00.000 --> 00:07.600] My name is Mikhail Shcherbakov and today I want to tell you a few stories about Kibana backbounds. [00:08.000 --> 00:13.900] This first part of the talk is about vulnerabilities that I found in Kibana [00:13.900 --> 00:20.660] and I combined it only with remote code execution vulnerabilities in this talk, [00:20.660 --> 00:29.980] just because of time limits. A few words about me. Now I'm finishing my PhD studies at [00:29.980 --> 00:38.060] KTH University Stockholm and working on the thesis Code Reuse Attacks in Managed [00:38.060 --> 00:46.640] Programming Languages and Runtimes. My main research interest is static code analysis, [00:46.720 --> 00:54.640] dynamic program analysis, and language-based security in general. I participated in bug bounty [00:54.640 --> 01:03.580] programs of Microsoft, GitHub, some open source projects, and Elastic. And today we'll talk about [01:03.580 --> 01:15.280] Elastic bug bounty program, namely Kibana bug bounty program. Who is Kibana? Kibana is a part [01:15.280 --> 01:26.520] of popular ILCA stack that includes Elasticsearch, Logstash, and Kibana. It's used for data visualization [01:27.160 --> 01:37.380] and real-time analysis. So Kibana is an open source project. All code is available and [01:37.380 --> 01:48.160] it's possible to analyze statically or just make a manual review. It's definitely a large project, [01:48.160 --> 01:56.260] probably one of the largest. It's written in TypeScript and they have an interesting [01:56.260 --> 02:05.940] bug bounty program with 3,000-7,000 rewards for critical vulnerabilities. All of that [02:05.940 --> 02:16.620] makes Kibana a great target for bug hunters. And I contributed a lot last year in this program. [02:16.960 --> 02:24.940] And before starting to tell about vulnerabilities in Kibana, I would like to say my thanks to the [02:24.940 --> 02:32.880] Elastic security team. In my practice, in my experience, it's one of the best bug bounty [02:32.880 --> 02:40.240] programs that's managed by Elastic security team. Thank you guys for your work and the main reason [02:40.240 --> 02:49.880] that I contribute a lot in this bug bounty, it's just a good experience of this work. [02:50.490 --> 02:55.620] So story number one, how it all began. [02:57.190 --> 03:05.560] One year ago, in the last August, after DEFCON, I found that Elastic bug bounty started [03:06.760 --> 03:16.000] compiling for a new feature that's called synthetic monitoring in the Kibana product [03:16.880 --> 03:23.820] that can be used for some dashboard. The idea of the feature is that you can set up some [03:23.820 --> 03:32.700] monitors for websites and see how the website is available or some content was changed and [03:32.700 --> 03:43.300] make some reports based on such monitoring. Okay, let's see how this feature looks like in [03:43.300 --> 03:51.500] practice. It is a main page of the Kibana. You can find synthetics, the feature that we discussed. [03:51.500 --> 03:59.100] You can create a new monitor to monitor some website. You need to set a name of the monitor, [03:59.100 --> 04:07.240] location, when your agent will be run to make a request to the site. And look, you can define [04:07.240 --> 04:16.520] some script. So it's also interesting. We have some script editor and we can pass [04:16.520 --> 04:24.880] own script here. Let's check the documentation, how such scripts look like. It's one of the [04:24.880 --> 04:33.220] examples, a simple script that's just open the example.org and check some element, [04:33.220 --> 04:44.240] text in the element and check that it equals to example domain. Okay, but it looks like a [04:44.240 --> 04:52.360] JavaScript, right? So if you just replace the body of this method and write, for example, [04:52.360 --> 05:01.120] to run a reverse shell, probably we can execute it. But exactly this code doesn't work because [05:01.120 --> 05:09.480] of a query. If you did some JavaScript CTF, you probably already know about this problem. [05:09.480 --> 05:16.080] You don't have a query in the scope, but you can bypass it for Node.js, for example. You can use [05:17.180 --> 05:26.840] load, underscore load method in the process main module to load any [05:28.300 --> 05:36.520] module, including child process, and you can run reverse shell. Let's see on the demo. We [05:38.080 --> 05:44.500] paste this code, click on the run and see you have already a connection from the reverse shell, [05:44.500 --> 05:53.680] from the agent. We see the file system and the user on this agent, on the harebit engine. [05:53.680 --> 06:03.900] You can see the harebit name of the user that we get that monitor any websites. Okay, [06:03.900 --> 06:10.240] this remote code execution, I think, is the simplest remote code execution that I reported. [06:11.220 --> 06:17.860] And in the last August, I made a report. The program, the company [06:18.420 --> 06:27.140] company already finishing, and it was the last days, and also the rules for the post-exploitation [06:27.140 --> 06:33.280] was not clear, and I decided, okay, I found it, I will report it, and let's see. We discount this [06:33.280 --> 06:40.620] report with Elastic security team in September, and in October they came back with the feedback. [06:41.560 --> 06:49.260] Synthetics by design is arbitrary code execution as a service in which Elastic deploys a number [06:49.260 --> 06:57.460] of security features to prevent exploitation. For successful exploit, someone would have to do [06:57.460 --> 07:07.440] something beyond getting a shell. Okay, so it makes sense if you make such feature, [07:07.440 --> 07:17.520] probably you already isolated this code on the container, and what they actually did. [07:18.840 --> 07:26.840] Okay, we discussed it, and I decided to continue exploitation of this container and see what [07:26.840 --> 07:37.080] I can get in the end. Where we are? This is an isolated container. After some investigation, [07:37.080 --> 07:44.220] I see that it's run in the Kubernetes cluster on Google Cloud Platform. Probably it was [07:44.220 --> 07:51.400] managed Kubernetes cluster, but the details are not important here. [07:51.960 --> 07:58.820] The first idea was to try to affect another client on the same container, but the container was [07:59.780 --> 08:08.320] running paired tasks, so we don't have any persistent state after the execution of the [08:08.320 --> 08:18.100] code that we injected. The container just restarted and no any client there. Okay, try to escape the [08:18.100 --> 08:25.280] container. It was secure configuration of up-to-date Kubernetes version, so it looks like [08:25.280 --> 08:33.780] not possible. Access to Google Cloud Platform metadata API? No again, so I think it's one of [08:33.780 --> 08:43.840] the first thing that they checked. It looks like unexploitable case, so we found remote code [08:43.840 --> 08:58.590] execution, but we cannot bypass the container isolation. I continue investigated some things [08:58.950 --> 09:05.870] and found the same docker container for private Kubernetes cluster. It means we can run it in the [09:05.870 --> 09:14.930] own Kubernetes cluster. It makes threat model a little bit weak, because we don't have exactly [09:14.930 --> 09:22.770] the same settings. We can say if we can escape from container or affect some another services [09:22.770 --> 09:30.810] or features in the default configuration on the Kubernetes, it looks like a possible [09:32.130 --> 09:42.330] exploitation flaw. And I also found that this container already have natural capabilities. [09:42.950 --> 09:52.110] It means that we can send any raw package to the network. Any package. It means we can emulate [09:52.110 --> 10:02.490] any protocol. For example, we can say send ARP packages. I think you already understand my idea [10:02.490 --> 10:16.990] and get what I want to do. Yeah, let's try to do ARP spoofing attack in 2024. So, [10:16.990 --> 10:25.790] ARP protocol allows to send some request to match IP address to the MAC address of any computer. [10:25.790 --> 10:35.250] And for example, in the network, when Bob tried to connect to Mary and communicate by IP transport, [10:35.250 --> 10:42.830] we can say to Bob that Mary is an attacker computer and say to Mary that Bob is an attacker [10:42.830 --> 10:51.870] computer and intercept the traffic between these two machines. It's a simple, old, very old, [10:51.870 --> 11:03.110] old school attack. But what about Kubernetes? I already wanted to start to run Wireshark and [11:03.110 --> 11:12.690] investigate the traffic, what actually happens, and found a nice blog post from Nir Chacko. [11:12.690 --> 11:24.470] Attacking Kubernetes clusters throws your network plumbing. So, he described the same idea of ARP [11:24.470 --> 11:35.870] spoofing to replace DNS server that's available in the Kubernetes to the own DNS server. And in [11:35.870 --> 11:49.550] this case, you can hijack any DNS request and send the request to the own web server instead of any [11:49.550 --> 11:59.610] available web server. And the crucial component of this attack, this bridge, let's call it BR0 on this [11:59.610 --> 12:16.610] figure. So, this bridge supports ARP protocol and has own ARP table that has any IP addresses and MAC [12:16.610 --> 12:23.810] addresses of the ports that run on the same node. So, it looks like very restricted attack. We can [12:23.810 --> 12:35.290] affect only ports on the same node. But default network interface in Kubernetes allows us to [12:36.450 --> 12:46.110] exploit ARP spoofing. Let's see on the demo. So, the one of the idea to start this attack was to use [12:46.110 --> 12:54.710] some cloud environment. I check Microsoft Azure and they allow us to use default Kubernetes. [12:54.710 --> 13:01.590] So, you can see the console. I already started attacker at victim ports and you can see that [13:01.590 --> 13:10.250] it's run on the same node in Kubernetes cluster. It allows us to perform attack from the attacker [13:10.250 --> 13:16.730] to affect the victim. First of all, we install proof of concept and some additional [13:16.730 --> 13:21.110] proof of concept script and some additional dependencies on the attacker. At the same [13:21.110 --> 13:29.330] time, we open the victim machine. We will install KURL there to emulate some web requests. [13:29.410 --> 13:38.010] Yeah, it's the console of the victim machine. And after installation of the KURL, the idea [13:38.010 --> 13:46.650] that we try to get the data from the google.com. After that, we start the attack and try to use [13:46.650 --> 13:55.890] own web server instead of the google.com. So, now you see the usual, the valid response from the [13:55.890 --> 14:06.070] google.com. And this is the attacker port. We run DNS spoofing proof of concept that I found in that [14:07.450 --> 14:17.250] blog post. I also improved it to use it on Azure. By default, it did not support it. [14:17.670 --> 14:26.810] And we start the attack here. And now we do the same request and you can see that our web server [14:27.680 --> 14:37.730] responds instead of the google.com. So, it's a classic DNS spoofing that we demonstrated in this [14:37.730 --> 14:46.770] demo. And I updated the report to demonstrate this attack. Elastic changed the report. [14:47.330 --> 14:59.950] And a few days, one week ago, they rewarded with almost 4000 bounties for this attack. [15:00.510 --> 15:08.810] Not bad for an unexploitable case and a very exotic attack. And it was a very [15:09.330 --> 15:16.450] interesting experience to try to use ARP spoofing in the real bug bounty case. [15:17.530 --> 15:25.270] So, I missed a lot of the details of network configuration of the Kubernetes. If you're [15:25.270 --> 15:33.730] interested, you can read the blog post. I'm sure you'll enjoy it. It's one of the best blog posts [15:33.730 --> 15:41.460] about Kubernetes networking that I've read. All links will be in the end of the presentation. [15:42.260 --> 15:54.460] Let's see on another attacks. The main topic in my PhD studies for last two years was server-side [15:54.460 --> 16:02.020] prototype pollution vulnerabilities. We published three papers about that. When we implemented some [16:02.020 --> 16:07.280] toolchain to find prototype pollution vulnerabilities, we found prototype pollution [16:08.080 --> 16:15.400] gadgets that allow us to exploit prototype pollution and achieve a remote code execution [16:15.400 --> 16:24.160] attack in Node.js itself, in Deno, in npm packages. If you're interested in this, [16:24.160 --> 16:31.480] read the papers. And I also give us some short introduction of our research and prototype [16:32.020 --> 16:38.980] attack the last year on DEF CON and many technical details of the gadgets that we found in Node.js [16:38.980 --> 16:47.360] itself in another talk on the Black Hat Asia. And today I will tell you a short introduction [16:47.360 --> 16:59.960] what the prototype pollution is, just to be on the same page. So, let's assume that we have a Node.js [16:59.960 --> 17:07.480] application. We run some web server. You see index.js. It's very simple web server that can [17:07.480 --> 17:14.720] handle two requests, update and backup. For update request, we provide some arguments. For backup [17:14.720 --> 17:23.540] request, we just trigger the backup of database. Okay, it's our setup. So, we have attacker in [17:23.540 --> 17:30.820] this thread model. It's any user that can send any request to the web server. And if the attacker [17:30.820 --> 17:40.420] send such request with these parameters, and we have a handler for update request, the handler in [17:40.420 --> 17:50.800] the first line create empty object. And runtime, in the same time, create empty object with the [17:50.800 --> 17:58.180] built-in property proto that points to the object prototype that contains a lot of functions like [17:58.180 --> 18:09.320] toString, valueOf, that we can reuse. So, it's like inheritance implementation for JavaScript and [18:09.320 --> 18:20.540] TypeScript. In the second line, you can see that we read the property from the object that [18:20.540 --> 18:30.720] specified in the argument org. This is the proto. It means we get a reference to this object. In the [18:30.720 --> 18:41.600] last line of the code, we assign a value from details to another property of the prototype, [18:41.600 --> 18:52.120] the property shell. So, we read the proto, we assign a value calc in the shell, and we get it in the [18:52.120 --> 18:59.000] prototype. This code pattern is called prototype pollution, because we pollute, we add some [18:59.000 --> 19:06.760] property or replace some property in the object prototypes itself. Let's assume that we have such [19:06.760 --> 19:18.080] code for backup handler. This function tries to run the backup script, this one, and use the shell [19:18.080 --> 19:27.720] from the options and default shell if the shell is undefined. In our case, shell is undefined and it [19:27.720 --> 19:34.360] will be used as default shell. Okay, it's a very common pattern in the JavaScript. But what actually [19:34.360 --> 19:44.020] happens if we trigger this handler after prototype pollution? We create options that point to the [19:44.020 --> 19:52.700] same object prototype. We read the shell and the runtime lookups for the shell property in the [19:52.700 --> 20:02.300] prototype chain and reads the polluted shell property. And the exec command runs a calculator [20:02.300 --> 20:12.860] because we get a calc in the shell, in the cmd variable at the end. Okay, this is prototype [20:12.860 --> 20:22.360] pollution and remote code execution that we can achieve by prototype pollution in the end. [20:22.420 --> 20:31.660] And this code pattern is called a gadget, prototype pollution gadget. Let's start the story too. [20:32.300 --> 20:38.720] About prototype pollution and remote code execution based on that. [20:39.480 --> 20:44.800] So, I tried to use SilentSpring. It's our first research on the prototype [20:44.800 --> 20:52.660] pollution, the toolchain that we implemented based on the CodeQL to detect prototype [20:52.660 --> 20:59.780] pollution vulnerabilities in Kibana. So, the first attempt CodeQL terminated by timeout [21:00.740 --> 21:07.920] because of too large database that I tried to analyze. I implemented a script [21:08.720 --> 21:17.880] that rerun CodeQL for subfolders if the analysis is timed out. And this script reported 77 [21:18.820 --> 21:25.360] cases in the application itself. I will add the script in the same repository if you're [21:25.360 --> 21:36.020] interested. You can find it there. Try to play with that. So, we get 44 server-side cases [21:36.020 --> 21:45.540] including some false positive testing code. And today I will show you a couple cases from these [21:46.150 --> 21:56.040] that was exploited. So, the first case, this is prototype pollution pattern that was detected [21:56.040 --> 22:06.060] in the config parser. The config parser take some YAML document, main config of the Kibana [22:06.060 --> 22:15.860] when you restart Kibana. And after the parsing it also tried to expand dot separated names [22:15.860 --> 22:29.780] in this YAML config to such nested object. So, a.b becomes a object that contains nested object [22:29.780 --> 22:39.160] with property b. So, very simple idea. But the code that does it is vulnerable to prototype [22:39.160 --> 22:45.760] pollution. First of all, I take a key like a.b in our case, split it by the dot, so we get array [22:46.000 --> 23:01.600] a and b, and call walk function. In the walk function, we get the first key, a, [23:01.600 --> 23:10.960] and read the value of the a, and call walk recursively. So, okay, and for the next [23:13.060 --> 23:21.400] case, if we have a last case, vary the b case, it becomes an empty array now, and we assign [23:21.400 --> 23:30.040] the value to the b. So, it's absolutely the same pattern that I've shown you before in the [23:30.040 --> 23:37.920] prototype pollution, and such payload leads to prototype pollution vulnerabilities in this case. [23:37.920 --> 23:50.800] So, we can add any property, and we control the value of the polluted property. Good. I found it, [23:50.800 --> 24:02.060] and also Elastic Cloud Enterprise, it's an on-premise version of the ILCA stack, [24:02.060 --> 24:09.420] provides web UI to edit Kibana YAML. It means we can edit it with admin privileges, so [24:10.300 --> 24:16.720] we need some high-level privileges, but we can do this attack through the web. [24:20.580 --> 24:28.660] Attacker can store any payload in Kibana and restart Kibana to load all configs. [24:28.660 --> 24:35.700] The problem here is that Kibana crashes immediately after prototype pollution occurs, [24:35.700 --> 24:41.260] because other code does not expect some properties, some additional properties, [24:41.260 --> 24:55.500] than the object prototypes. It happens before we get started the web server. We cannot send [24:55.500 --> 25:10.800] any other request to trigger any gadget. It means we can only control the prototype pollution [25:10.800 --> 25:18.360] point, and it's some difficulty with that, because nothing dangerous happened between [25:18.360 --> 25:25.480] restarting Kibana and prototype pollution triggering, and the crash of the application. [25:25.790 --> 25:35.470] It just tried to load some modules, tried to load configs, prepare some caches, [25:35.900 --> 25:42.470] and nothing dangerous like starting a new process or evaluate some function. [25:42.980 --> 25:49.400] And the attack looks like unexploitable, so you can achieve denial of the service, [25:49.400 --> 25:56.240] if you are an administrator and you restart Kibana, it's nothing actually. [25:56.240 --> 26:05.600] What we can do in this case? Let's see what Kibana did before the crash. It tried to load some [26:06.140 --> 26:15.900] modules. It would be nice if we have a gadget in the require call that loads modules, [26:15.900 --> 26:24.240] because the require will read the code that it loads from the module, and if we can replace [26:24.240 --> 26:30.860] the module to the own code, we can get remote code execution before the crash. [26:30.960 --> 26:40.340] That's a nice idea, and we already found the gadget in the require when we worked on the [26:40.340 --> 26:48.160] first paper, Silent Spring, that I mentioned today. And yeah, actually we can run any malicious [26:48.820 --> 26:57.660] JS file through the prototype pollution. Let's see on the require gadget how it works. [26:57.660 --> 27:04.800] So let's assume that we have the same prototype pollution from the first example, and we can [27:04.800 --> 27:12.960] trigger and pollute some property main in the object prototype. Oh yeah, we can pollute one more [27:14.280 --> 27:22.740] property environment and trigger or handle backup. Handle backup has only one line, [27:22.820 --> 27:31.700] a require to the some module, and when require tries to load the module bytes, [27:31.700 --> 27:37.980] it has such code. It does loadConfig, and for loadConfig [27:42.160 --> 27:52.080] this function returns the parsed JSON, like this one, with all properties from the config. [27:52.340 --> 28:01.200] But some package JSON, the configuration file, does not have main. In this case, [28:01.200 --> 28:11.440] the default behavior should be getIndex.js, but we have main.read expression here, [28:11.440 --> 28:19.780] and it tries to read the main that we polluted before from the object prototype. It means we can [28:20.980 --> 28:31.020] read any JS file that exists in the system. And it's some limitation for the require gadget, [28:31.020 --> 28:38.180] but we combine it with another object. If we can find some JS file that, for example, [28:38.180 --> 28:45.440] start new process, do child process exec, we can combine it with another function. And npm.js, [28:45.440 --> 28:58.220] actually, when we load it, starts new process. It does such code. It executes spawn function [28:58.980 --> 29:05.700] with two arguments, non-executable process and some arguments. [29:05.840 --> 29:15.600] And the implementation on the spawn function, we have another gadget. Let's try to read [29:15.600 --> 29:26.940] property shell and env from the options. And options was empty, undefined. It means [29:26.940 --> 29:35.120] it becomes an empty object. And when we read env here, we read it from the empty object. [29:36.680 --> 29:43.680] And we actually read the value from the prototype. Okay, that's the idea of the require gadget. [29:44.140 --> 29:52.160] The problem is that this gadget has been fixed by Node.js team, and I already knew this [29:52.800 --> 29:59.020] when found it. And in parallel, I worked on some another tool, some dynamic analysis, [29:59.020 --> 30:03.800] it's called gHunters. I described it in the last paper that we published, [30:03.800 --> 30:09.660] and that will be presented in Usenix security in a few days, next week. [30:12.800 --> 30:21.200] And working on that tool, I investigated require gadget and the fix. And the require [30:21.200 --> 30:28.660] gadget looks like this. So the code that we already saw, we have a load config. So we have [30:29.740 --> 30:38.040] such code that read package JSON, try to parse it by JSON parse, and JSON parse return object that [30:38.040 --> 30:48.300] has a object prototype in the chain. And it tried to read the main property, and at that moment, [30:48.300 --> 30:56.140] it can read the polluted property if we already polluted main in the object prototype. So this [30:56.140 --> 31:03.560] is a gadget. And Node.js team fixed it. So the fix looks like this. They wrote some filter on [31:03.560 --> 31:11.400] properties that actually read this list of properties exactly from the object itself, [31:11.400 --> 31:17.880] does not check it in the prototype chain. So it means we cannot affect reading on the [31:17.880 --> 31:27.220] main property anymore after that fix. But at some moment, gHunters start detect [31:28.210 --> 31:37.500] the require gadget again in the new version of the Node.js. And I double-checked all experiments, [31:37.500 --> 31:44.380] and I see that require detected again and again for some cases, and I start to see on this fix [31:44.380 --> 31:57.380] more closely. And it has another gadget. I will zoom in. You can see exactly in these slides. [31:57.880 --> 32:06.600] We have this if statement. If JSON is undefined, the function returns false. The function load [32:06.600 --> 32:15.720] config returns false. ParseJSON becomes a false, and we try to read the main from the false. [32:15.720 --> 32:23.240] JsRuntime in this case tried to box primitive type, Boolean type, and add object prototype [32:23.240 --> 32:32.440] in the prototype chain. And we again can read the main, but from the false, actually. [32:32.440 --> 32:39.560] So, it's a new gadget, and when I figure out it, so I [32:42.560 --> 32:52.040] add the payload for the require in the original Kibana YAML file, and it allows us to exploit [32:52.540 --> 33:02.080] this prototype solution and achieve remote code execution. So, this vulnerability did not get [33:02.080 --> 33:10.460] high score because it required high privileged user, but still it's almost 4,000 bounces. [33:11.860 --> 33:19.300] Let's see on the next story about prototype pollution and remote code execution. Another [33:19.300 --> 33:30.040] case that was reported by our script, SilentSpring Node.js queries, was a prototype pollution in [33:30.040 --> 33:37.720] some handler, web handler. So, it's very simple prototype pollution, you can see we create [33:37.720 --> 33:44.700] empty object, it means this object has the prototype points to the object prototype, [33:44.700 --> 33:55.480] and we have this line of the code, if namespace is __prot__, and the key is the key [33:56.040 --> 34:02.620] controlled by the attacker, that's so, and the value also can be controlled by the attacker, [34:02.620 --> 34:08.560] it means we can add any key with controlled value to the object prototype. Very simple, [34:08.560 --> 34:20.160] you don't even need a script to find it. Okay, so when I started working on this script, [34:20.160 --> 34:24.700] the question, we need to find a gadget. We worked on the Dusty, it's another project [34:24.700 --> 34:33.900] that detected 49 gadgets leading to remote code execution in NPM packages. We took [34:35.540 --> 34:43.560] a thousand popular NPM packages and run dynamic analysis that try to instrument the package [34:43.560 --> 34:52.600] and investigate what the flows can lead to, read the properties from the prototype and can lead to [34:52.600 --> 35:02.660] remote code execution in the end. And one of the package that has a gadget was NotMailer, [35:02.660 --> 35:11.620] and Kibana uses this gadget to send emails. So, the idea, we have some [35:12.360 --> 35:19.500] SendMailer transport that's optional, but you also can pollute some option to enable it. [35:20.230 --> 35:31.680] And it has some options that's by default empty. And if we have [35:33.160 --> 35:41.240] path in the options, the path of the run program that should be SendMailer and args will be read [35:41.240 --> 35:48.400] from the options object and prototype, in our case, and send to the spawn function. [35:48.700 --> 35:59.380] Okay, so it means we can inject any command and execute, start any process on the victim machine. [36:03.210 --> 36:09.610] But the problem is that DeleteHandler crashes the application in less than one second after [36:09.610 --> 36:15.630] the prototype pollution. So, it also becomes immediately, because some code in the end of [36:15.630 --> 36:20.270] the handler, of the same handler, does not expect the property, some additional property, [36:20.270 --> 36:25.770] and throw exception that's not handled correctly. And we get denial of the service. [36:25.770 --> 36:33.790] That's not much interesting for such vulnerability. So, it looks like unexploitable. [36:33.790 --> 36:39.150] Denial of the service, I could not say that it's an interesting impact that we want to [36:39.150 --> 36:49.670] show. But if we try to emulate some race condition by sending a lot of gadget-triggered requests in [36:49.670 --> 36:57.770] parallel and one prototype-pollution-triggered request between them, we can try to get the [36:57.770 --> 37:07.190] situation that gadget-triggered request will be in the small time exactly after the prototype [37:07.190 --> 37:14.270] pollution request. Let me explain it based on the script, on the exploit script. [37:14.610 --> 37:23.870] So, we can implement such race condition exploit on the bash or any other language. [37:23.990 --> 37:33.030] So, the idea, we send 20 requests that trigger a gadget first, and after that we send the request [37:33.030 --> 37:41.450] that trigger a prototype pollution, and after that we send 50 requests that trigger a gadget again. [37:41.450 --> 37:51.550] And this ampersand means that all of these commands will be executed in parallel. [37:52.510 --> 37:58.510] So, we send a lot of requests. Let's see how it works in the demo. [37:59.670 --> 38:12.030] So, I run it from my laptop, through the Wi-Fi, and first of all I start some payload that created [38:12.790 --> 38:23.350] an email connector that we need to know to send the request to trigger a non-mailer package. [38:23.350 --> 38:36.210] So, we change in our exploit SH script this connector and run the exploit script. [38:36.210 --> 38:43.790] And I started this web page to see which requests we will get. So, I did not run a [38:43.790 --> 38:52.210] reverse shell, I just sent a request to this web page. You can see that five requests will [38:52.210 --> 39:04.330] be successfully received. It means that five cases will be for so short time that were [39:05.090 --> 39:11.970] executed before the crash. And this attack was run from the Wi-Fi. You can get more [39:11.970 --> 39:17.770] interesting, I guess, if you run it on the same server, in the same network, like in cloud or [39:17.770 --> 39:27.490] some cases. Okay, this attack gave me the biggest bounty that I got from the Elastic. [39:27.890 --> 39:32.550] And not only this prototype pollution that I reported was exploited, [39:32.550 --> 39:39.090] this case was closed a few days ago. I did not have time to edit in the presentation and also [39:39.090 --> 39:47.610] we don't have much time. And another case that was reported also, this is a chain that leads to [39:47.610 --> 39:54.190] account takeover. Maybe I will do it in the next presentation, let's see. [39:55.410 --> 40:06.410] As a bonus part, I want to explain some advanced technique for the prototype pollution when we [40:06.410 --> 40:16.310] pollute the objects in the prototype, not the prototype itself. When I understood this trick, [40:16.310 --> 40:23.270] it allows me to report a few new vulnerabilities that I actually thought were unexploitable [40:23.270 --> 40:32.390] before. Let's see the example. We have a prototype pollution from our original example, [40:32.390 --> 40:39.990] very simple code that we already know. We have a gadget. The gadget reads the options [40:40.730 --> 40:51.750] and checks the property runner. The options are empty object by default. If the runner is defined, [40:51.750 --> 41:01.230] we read paths and arcs and spawn a new process for that. It means we need to pollute a runner [41:01.230 --> 41:12.670] in the object prototype, like this. We add a runner with this object as a value. [41:14.070 --> 41:20.430] And after that, we trigger a handleback, of course, to trigger a gadget. [41:21.790 --> 41:29.430] What if this prototype pollution does not allow us to control the value? For example, [41:29.430 --> 41:36.410] it's some object with a predefined identifier and other properties. We cannot control it. [41:37.310 --> 41:47.030] Or it's an empty array. The array does not have any properties, right? It looks like [41:47.030 --> 41:52.830] unexploitable, at least for such a gadget. Maximum, we can get the denial of the service. [41:52.830 --> 42:02.990] But what if we have such code? It's a fixed, I call it a fixed prototype pollution. We check that [42:03.950 --> 42:12.010] arc does not equal a prototype and execute this code only for that. It cannot lead to [42:12.010 --> 42:22.970] prototype pollution, but we can combine these two code snippets. So it's absolutely [42:24.290 --> 42:31.230] safe code separately from this one. But what we can do together with these components? First of [42:31.230 --> 42:37.950] all, we need to pollute the prototype. We add a runner with a value of empty array in the prototype [42:37.950 --> 42:50.430] to trigger handle update. Good. After that, we trigger this save function with arc [42:53.070 --> 43:00.930] that has a runner value. It means we will try to read the runner from the prototype at this step. [43:00.930 --> 43:10.090] And we pollute the runner after that. We can't feel any additional properties in the runner by [43:10.090 --> 43:17.990] this call and the second call. And after that, we trigger backup handler. It gives us the remote [43:17.990 --> 43:25.690] code execution again by this chain of the calls, the web request that triggers such functions. [43:26.190 --> 43:32.710] If you think that it's unlikely that we find some fixed prototype pollution case and unfixed [43:32.710 --> 43:40.550] prototype pollution case in the same application, I can say you that, for example, merge functions [43:41.050 --> 43:49.710] are very typical in the fixed prototype pollutions. Like a merge function of the [43:49.710 --> 44:00.750] very popular package lodash allows us to pollute a runner with such payload. And you can find [44:00.750 --> 44:05.870] lodash merge calls in many applications. And that's important that these two parts [44:05.870 --> 44:15.330] can be unrelated. It could be absolutely different features in the application. [44:16.370 --> 44:26.470] So yeah, use it for fun and bounces. In conclusion, in this talk, I wanted to show the cases that [44:26.470 --> 44:34.970] look unexploitable and say, don't give up. Try to achieve remote code execution even when it looks [44:34.970 --> 44:41.910] impossible. If you're interested in prototype pollution research, check out our papers, [44:41.910 --> 44:50.310] SilentSpring, G-Hunter and Dusty that I mentioned in the talk. Check out the collection of server-side [44:50.310 --> 44:56.530] prototype pollution gadgets that we shared. This is a gadget in Node.js itself and dino and npm [44:56.530 --> 45:08.210] packages that I also use in my bug bounty cases. If you're interested in networking attacks and [45:08.210 --> 45:15.470] this story about ARP spoofing, I highly recommend to read this blog post. ARP spoofing in Kubernetes [45:15.470 --> 45:25.610] is not so easy as it looks like. It also has some difficulties with the IP table rules that were [45:25.610 --> 45:34.450] bypassed by this talk. Check out this blog post. I think you'll enjoy it. And follow me on Twitter [45:34.450 --> 45:40.230] if you're interested in some details of code reuse attacks. I want to share some findings that [45:40.230 --> 45:49.510] I am now including in my thesis. And thank you for your attention. Enjoy DEF CON. Bye-bye.