WEBVTT

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:23.240
This first part of the talk is about vulnerabilities that I found in Kibana and I combined it only with remote code execution vulnerabilities in this talk, just because of time limits.

00:23.520 --> 00:26.720
A few words about me.

00:27.240 --> 00:41.580
Now I'm finishing my PhD studies at KTH University Stockholm and working on the thesis Code Reuse Attacks in Managed Programming Languages and Runtimes.

00:41.580 --> 00:52.620
My main research interest is static code analysis, dynamic program analysis, and language-based security in general.

00:52.620 --> 01:01.860
I participated in bug bounty programs of Microsoft, GitHub, some open source projects, and Elastic.

01:01.860 --> 01:11.360
And today we'll talk about Elastic bug bounty program, namely Kibana bug bounty program.

01:11.360 --> 01:13.360
Who is Kibana?

01:13.360 --> 01:24.300
Kibana is a part of popular ILCA stack that includes Elasticsearch, Logstash, and Kibana.

01:24.300 --> 01:32.140
It's used for data visualization and real-time analysis.

01:33.220 --> 01:35.700
So Kibana is an open source project.

01:35.700 --> 01:44.500
All code is available and it's possible to analyze statically or just make a manual review.

01:44.500 --> 01:50.180
It's definitely a large project, probably one of the largest.

01:50.180 --> 02:05.200
It's written in TypeScript and they have an interesting bug bounty program with 3,000-7,000 rewards for critical vulnerabilities.

02:05.200 --> 02:11.200
All of that makes Kibana a great target for bug hunters.

02:11.200 --> 02:16.620
And I contributed a lot last year in this program.

02:16.960 --> 02:26.980
And before starting to tell about vulnerabilities in Kibana, I would like to say my thanks to the Elastic security team.

02:27.180 --> 02:37.140
In my practice, in my experience, it's one of the best bug bounty programs that's managed by Elastic security team.

02:37.160 --> 02:49.880
Thank you guys for your work and the main reason 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:20.200
One year ago, in the last August, after DEFCON, I found that Elastic bug bounty started compiling for a new feature that's called synthetic monitoring in the Kibana product that can be used for some dashboard.

03:20.200 --> 03:37.500
The idea of the feature is that you can set up some monitors for websites and see how the website is available or some content was changed and make some reports based on such monitoring.

03:38.320 --> 03:44.120
Okay, let's see how this feature looks like in practice.

03:44.120 --> 03:47.340
It is a main page of the Kibana.

03:47.340 --> 03:51.500
You can find synthetics, the feature that we discussed.

03:51.500 --> 03:56.400
You can create a new monitor to monitor some website.

03:56.640 --> 04:04.480
You need to set a name of the monitor, location, when your agent will be run to make a request to the site.

04:04.480 --> 04:09.280
And look, you can define some script.

04:09.440 --> 04:13.260
So it's also interesting.

04:13.300 --> 04:18.480
We have some script editor and we can pass own script here.

04:18.480 --> 04:23.540
Let's check the documentation, how such scripts look like.

04:24.000 --> 04:40.420
It's one of the examples, a simple script that's just open the example.org and check some element, text in the element and check that it equals to example domain.

04:40.820 --> 04:45.140
Okay, but it looks like a JavaScript , right?

04:45.140 --> 04:57.040
So if you just replace the body of this method and write, for example, to run a reverse shell, probably we can execute it.

04:57.600 --> 05:02.120
But exactly this code doesn't work because of a query.

05:02.120 --> 05:09.480
If you did some JavaScript CTF, you probably already know about this problem.

05:09.480 --> 05:15.260
You don't have a query in the scope, but you can bypass it for Node.js, for example.

05:15.260 --> 05:34.400
You can use load, underscore load method in the process main module to load any module, including child process, and you can run reverse shell.

05:34.560 --> 05:36.260
Let's see on the demo.

05:36.260 --> 05:45.500
We paste this code, click on the run and see you have already a connection from the reverse shell, from the agent.

05:45.500 --> 05:53.680
We see the file system and the user on this agent, on the harebit engine.

05:53.680 --> 06:03.140
You can see the harebit name of the user that we get that monitor any websites.

06:03.280 --> 06:10.240
Okay, this remote code execution, I think, is the simplest remote code execution that I reported.

06:11.220 --> 06:15.040
And in the last August, I made a report.

06:15.040 --> 06:32.460
The program, the company company already finishing, and it was the last days, and also the rules for the post-exploitation was not clear, and I decided, okay, I found it, I will report it, and let's see.

06:32.460 --> 06:40.620
We discount this report with Elastic security team in September, and in October they came back with the feedback.

06:41.560 --> 06:53.280
Synthetics by design is arbitrary code execution as a service in which Elastic deploys a number of security features to prevent exploitation.

06:53.280 --> 07:01.920
For successful exploit, someone would have to do something beyond getting a shell.

07:02.520 --> 07:17.520
Okay, so it makes sense if you make such feature, probably you already isolated this code on the container, and what they actually did.

07:18.840 --> 07:30.160
Okay, we discussed it, and I decided to continue exploitation of this container and see what I can get in the end.

07:30.740 --> 07:32.280
Where we are?

07:32.320 --> 07:35.580
This is an isolated container.

07:35.580 --> 07:42.240
After some investigation, I see that it's run in the Kubernetes cluster on Google Cloud Platform.

07:42.420 --> 07:51.400
Probably it was managed Kubernetes cluster, but the details are not important here.

07:51.960 --> 08:10.760
The first idea was to try to affect another client on the same container, but the container was running paired tasks, so we don't have any persistent state after the execution of the code that we injected.

08:10.760 --> 08:15.660
The container just restarted and no any client there.

08:16.000 --> 08:19.400
Okay, try to escape the container.

08:19.500 --> 08:27.440
It was secure configuration of up-to-date Kubernetes version, so it looks like not possible.

08:27.440 --> 08:31.160
Access to Google Cloud Platform metadata API?

08:31.160 --> 08:37.900
No again, so I think it's one of the first thing that they checked.

08:37.900 --> 08:50.720
It looks like unexploitable case, so we found remote code execution, but we cannot bypass the container isolation.

08:55.290 --> 09:03.630
I continue investigated some things and found the same docker container for private Kubernetes cluster.

09:03.630 --> 09:08.090
It means we can run it in the own Kubernetes cluster.

09:08.090 --> 09:16.370
It makes threat model a little bit weak, because we don't have exactly the same settings.

09:16.370 --> 09:34.230
We can say if we can escape from container or affect some another services or features in the default configuration on the Kubernetes, it looks like a possible exploitation flaw.

09:34.430 --> 09:42.330
And I also found that this container already have natural capabilities.

09:42.950 --> 09:49.130
It means that we can send any raw package to the network.

09:49.170 --> 09:50.910
Any package.

09:50.910 --> 09:53.610
It means we can emulate any protocol.

09:53.610 --> 09:59.110
For example, we can say send ARP packages.

09:59.110 --> 10:06.250
I think you already understand my idea and get what I want to do.

10:06.250 --> 10:14.990
Yeah, let's try to do ARP spoofing attack in 2024.

10:15.230 --> 10:25.790
So, ARP protocol allows to send some request to match IP address to the MAC address of any computer.

10:25.790 --> 10:47.390
And for example, in the network, when Bob tried to connect to Mary and communicate by IP transport, we can say to Bob that Mary is an attacker computer and say to Mary that Bob is an attacker computer and intercept the traffic between these two machines.

10:47.390 --> 10:55.010
It's a simple, old, very old, old school attack.

10:55.070 --> 10:58.210
But what about Kubernetes?

10:58.870 --> 11:12.690
I already wanted to start to run Wireshark and investigate the traffic, what actually happens, and found a nice blog post from Nir Chacko.

11:12.690 --> 11:17.930
Attacking Kubernetes clusters throws your network plumbing.

11:18.090 --> 11:35.250
So, he described the same idea of ARP spoofing to replace DNS server that's available in the Kubernetes to the own DNS server.

11:35.250 --> 11:51.310
And in this case, you can hijack any DNS request and send the request to the own web server instead of any available web server.

11:51.430 --> 12:00.690
And the crucial component of this attack, this bridge, let's call it BR0 on this figure.

12:00.690 --> 12:20.710
So, this bridge supports ARP protocol and has own ARP table that has any IP addresses and MAC addresses of the ports that run on the same node.

12:20.710 --> 12:23.490
So, it looks like very restricted attack.

12:23.490 --> 12:28.010
We can affect only ports on the same node.

12:28.290 --> 12:38.870
But default network interface in Kubernetes allows us to exploit ARP spoofing.

12:38.870 --> 12:40.830
Let's see on the demo.

12:41.290 --> 12:48.750
So, the one of the idea to start this attack was to use some cloud environment.

12:48.750 --> 12:54.710
I check Microsoft Azure and they allow us to use default Kubernetes.

12:54.710 --> 12:56.630
So, you can see the console.

12:56.630 --> 13:05.310
I already started attacker at victim ports and you can see that it's run on the same node in Kubernetes cluster.

13:05.310 --> 13:12.150
It allows us to perform attack from the attacker to affect the victim.

13:12.390 --> 13:20.610
First of all, we install proof of concept and some additional proof of concept script and some additional dependencies on the attacker.

13:20.610 --> 13:23.910
At the same time, we open the victim machine.

13:23.950 --> 13:29.330
We will install KURL there to emulate some web requests.

13:29.410 --> 13:31.950
Yeah, it's the console of the victim machine.

13:33.910 --> 13:42.530
And after installation of the KURL, the idea that we try to get the data from the google.com.

13:42.530 --> 13:51.290
After that, we start the attack and try to use own web server instead of the google.com.

13:51.290 --> 13:57.630
So, now you see the usual, the valid response from the google.com.

13:57.630 --> 13:59.950
And this is the attacker port.

13:59.950 --> 14:09.050
We run DNS spoofing proof of concept that I found in that blog post.

14:09.050 --> 14:14.150
I also improved it to use it on Azure.

14:14.150 --> 14:17.250
By default, it did not support it.

14:17.670 --> 14:20.550
And we start the attack here.

14:20.550 --> 14:31.650
And now we do the same request and you can see that our web server responds instead of the google.com.

14:31.650 --> 14:38.590
So, it's a classic DNS spoofing that we demonstrated in this demo.

14:38.590 --> 14:43.850
And I updated the report to demonstrate this attack.

14:43.850 --> 14:46.770
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:06.230
Not bad for an unexploitable case and a very exotic attack.

15:06.330 --> 15:16.450
And it was a very interesting experience to try to use ARP spoofing in the real bug bounty case.

15:17.530 --> 15:24.950
So, I missed a lot of the details of network configuration of the Kubernetes.

15:24.950 --> 15:29.390
If you're interested, you can read the blog post.

15:29.390 --> 15:30.710
I'm sure you'll enjoy it.

15:30.710 --> 15:37.650
It's one of the best blog posts about Kubernetes networking that I've read.

15:38.530 --> 15:41.460
All links will be in the end of the presentation.

15:42.260 --> 15:45.800
Let's see on another attacks.

15:46.120 --> 15:56.440
The main topic in my PhD studies for last two years was server-side prototype pollution vulnerabilities.

15:56.440 --> 15:59.060
We published three papers about that.

15:59.060 --> 16:22.280
When we implemented some toolchain to find prototype pollution vulnerabilities, we found prototype pollution gadgets that allow us to exploit prototype pollution and achieve a remote code execution attack in Node.js itself, in Deno, in npm packages.

16:22.280 --> 16:25.880
If you're interested in this, read the papers.

16:25.880 --> 16:42.260
And I also give us some short introduction of our research and prototype attack the last year on DEF CON and many technical details of the gadgets that we found in Node.js itself in another talk on the Black Hat Asia.

16:42.780 --> 16:52.980
And today I will tell you a short introduction what the prototype pollution is, just to be on the same page.

16:53.800 --> 17:01.060
So, let's assume that we have a Node.js application.

17:01.240 --> 17:03.420
We run some web server.

17:03.420 --> 17:04.980
You see index.js.

17:04.980 --> 17:11.040
It's very simple web server that can handle two requests, update and backup.

17:11.040 --> 17:14.100
For update request, we provide some arguments.

17:14.100 --> 17:18.320
For backup request, we just trigger the backup of database.

17:18.860 --> 17:20.700
Okay, it's our setup.

17:21.640 --> 17:24.800
So, we have attacker in this thread model.

17:24.800 --> 17:29.420
It's any user that can send any request to the web server.

17:29.640 --> 17:44.820
And if the attacker send such request with these parameters, and we have a handler for update request, the handler in the first line create empty object.

17:45.100 --> 18:02.520
And runtime, in the same time, create empty object with the built-in property proto that points to the object prototype that contains a lot of functions like toString, valueOf, that we can reuse.

18:02.520 --> 18:11.120
So, it's like inheritance implementation for JavaScript and TypeScript.

18:11.500 --> 18:23.800
In the second line, you can see that we read the property from the object that specified in the argument org.

18:23.800 --> 18:25.240
This is the proto.

18:25.240 --> 18:30.140
It means we get a reference to this object.

18:30.140 --> 18:44.120
In the last line of the code, we assign a value from details to another property of the prototype, the property shell.

18:44.400 --> 18:53.140
So, we read the proto, we assign a value calc in the shell, and we get it in the prototype.

18:53.300 --> 19:04.940
This code pattern is called prototype pollution, because we pollute, we add some property or replace some property in the object prototypes itself.

19:05.300 --> 19:08.820
Let's assume that we have such code for backup handler.

19:08.820 --> 19:24.580
This function tries to run the backup script, this one, and use the shell from the options and default shell if the shell is undefined.

19:24.580 --> 19:30.220
In our case, shell is undefined and it will be used as default shell.

19:30.220 --> 19:33.320
Okay, it's a very common pattern in the JavaScript.

19:33.320 --> 19:40.620
But what actually happens if we trigger this handler after prototype pollution?

19:40.620 --> 19:46.100
We create options that point to the same object prototype.

19:46.280 --> 19:58.380
We read the shell and the runtime lookups for the shell property in the prototype chain and reads the polluted shell property.

19:58.380 --> 20:11.100
And the exec command runs a calculator because we get a calc in the shell, in the cmd variable at the end.

20:11.100 --> 20:22.360
Okay, this is prototype pollution and remote code execution that we can achieve by prototype pollution in the end.

20:22.420 --> 20:28.640
And this code pattern is called a gadget, prototype pollution gadget.

20:28.880 --> 20:31.660
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:42.480
So, I tried to use SilentSpring.

20:42.480 --> 20:55.380
It's our first research on the prototype pollution, the toolchain that we implemented based on the CodeQL to detect prototype pollution vulnerabilities in Kibana.

20:55.380 --> 21:05.940
So, the first attempt CodeQL terminated by timeout because of too large database that I tried to analyze.

21:06.460 --> 21:15.720
I implemented a script that rerun CodeQL for subfolders if the analysis is timed out.

21:15.720 --> 21:22.100
And this script reported 77 cases in the application itself.

21:22.100 --> 21:25.880
I will add the script in the same repository if you're interested.

21:25.880 --> 21:27.140
You can find it there.

21:27.140 --> 21:29.400
Try to play with that.

21:29.680 --> 21:39.380
So, we get 44 server-side cases including some false positive testing code.

21:39.380 --> 21:48.680
And today I will show you a couple cases from these that was exploited.

21:49.160 --> 21:58.300
So, the first case, this is prototype pollution pattern that was detected in the config parser.

21:58.300 --> 22:08.820
The config parser take some YAML document, main config of the Kibana when you restart Kibana.

22:08.820 --> 22:23.880
And after the parsing it also tried to expand dot separated names in this YAML config to such nested object.

22:23.880 --> 22:31.500
So, a.b becomes a object that contains nested object with property b.

22:31.500 --> 22:35.060
So, very simple idea.

22:35.540 --> 22:39.940
But the code that does it is vulnerable to prototype pollution.

22:39.940 --> 22:52.620
First of all, I take a key like a.b in our case, split it by the dot, so we get array a and b, and call walk function.

22:52.700 --> 23:07.740
In the walk function, we get the first key, a, and read the value of the a, and call walk recursively.

23:07.800 --> 23:24.940
So, okay, and for the next case, if we have a last case, vary the b case, it becomes an empty array now, and we assign the value to the b.

23:24.940 --> 23:37.920
So, it's absolutely the same pattern that I've shown you before in the prototype pollution, and such payload leads to prototype pollution vulnerabilities in this case.

23:37.920 --> 23:47.500
So, we can add any property, and we control the value of the polluted property.

23:47.500 --> 23:48.580
Good.

23:48.580 --> 24:05.240
I found it, and also Elastic Cloud Enterprise, it's an on-premise version of the ILCA stack, provides web UI to edit Kibana YAML.

24:05.240 --> 24:16.720
It means we can edit it with admin privileges, so 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:43.020
The problem here is that Kibana crashes immediately after prototype pollution occurs, because other code does not expect some properties, some additional properties, than the object prototypes.

24:43.380 --> 24:54.480
It happens before we get started the web server.

24:54.480 --> 25:03.920
We cannot send any other request to trigger any gadget.

25:03.920 --> 25:25.480
It means we can only control the prototype pollution point, and it's some difficulty with that, because nothing dangerous happened between restarting Kibana and prototype pollution triggering, and the crash of the application.

25:25.790 --> 25:42.470
It just tried to load some modules, tried to load configs, prepare some caches, and nothing dangerous like starting a new process or evaluate some function.

25:42.980 --> 25:56.240
And the attack looks like unexploitable, so you can achieve denial of the service, if you are an administrator and you restart Kibana, it's nothing actually.

25:56.240 --> 25:59.320
What we can do in this case?

25:59.640 --> 26:04.320
Let's see what Kibana did before the crash.

26:04.320 --> 26:07.500
It tried to load some modules.

26:07.500 --> 26:30.860
It would be nice if we have a gadget in the require call that loads modules, because the require will read the code that it loads from the module, and if we can replace the module to the own code, we can get remote code execution before the crash.

26:30.960 --> 26:43.320
That's a nice idea, and we already found the gadget in the require when we worked on the first paper, Silent Spring, that I mentioned today.

26:44.340 --> 26:52.740
And yeah, actually we can run any malicious JS file through the prototype pollution.

26:53.000 --> 26:57.660
Let's see on the require gadget how it works.

26:57.660 --> 27:11.040
So let's assume that we have the same prototype pollution from the first example, and we can trigger and pollute some property main in the object prototype.

27:11.040 --> 27:19.940
Oh yeah, we can pollute one more property environment and trigger or handle backup.

27:19.940 --> 27:33.340
Handle backup has only one line, a require to the some module, and when require tries to load the module bytes, it has such code.

27:33.340 --> 27:37.980
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:00.080
But some package JSON, the configuration file, does not have main.

28:00.080 --> 28:18.220
In this case, the default behavior should be getIndex.js, but we have main.read expression here, and it tries to read the main that we polluted before from the object prototype.

28:18.220 --> 28:26.520
It means we can read any JS file that exists in the system.

28:26.740 --> 28:33.300
And it's some limitation for the require gadget, but we combine it with another object.

28:33.300 --> 28:44.140
If we can find some JS file that, for example, start new process, do child process exec, we can combine it with another function.

28:44.140 --> 28:52.200
And npm.js, actually, when we load it, starts new process.

28:52.440 --> 28:56.180
It does such code.

28:56.180 --> 29:05.700
It executes spawn function with two arguments, non-executable process and some arguments.

29:05.840 --> 29:13.520
And the implementation on the spawn function, we have another gadget.

29:13.520 --> 29:20.900
Let's try to read property shell and env from the options.

29:21.580 --> 29:26.400
And options was empty, undefined.

29:26.400 --> 29:29.460
It means it becomes an empty object.

29:29.860 --> 29:35.120
And when we read env here, we read it from the empty object.

29:36.680 --> 29:40.640
And we actually read the value from the prototype.

29:41.040 --> 29:43.680
Okay, that's the idea of the require gadget.

29:44.140 --> 29:54.600
The problem is that this gadget has been fixed by Node.js team, and I already knew this when found it.

29:54.760 --> 30:00.300
And in parallel, I worked on some another tool, some dynamic analysis, it's called gHunters.

30:00.300 --> 30:09.660
I described it in the last paper that we published, and that will be presented in Usenix security in a few days, next week.

30:12.800 --> 30:20.160
And working on that tool, I investigated require gadget and the fix.

30:20.160 --> 30:23.400
And the require gadget looks like this.

30:23.400 --> 30:27.800
So the code that we already saw, we have a load config.

30:27.800 --> 30:42.440
So we have such code that read package JSON, try to parse it by JSON parse, and JSON parse return object that has a object prototype in the chain.

30:42.440 --> 30:55.400
And it tried to read the main property, and at that moment, it can read the polluted property if we already polluted main in the object prototype.

30:55.400 --> 30:57.380
So this is a gadget.

30:57.380 --> 30:59.660
And Node.js team fixed it.

30:59.660 --> 31:01.760
So the fix looks like this.

31:01.760 --> 31:14.280
They wrote some filter on properties that actually read this list of properties exactly from the object itself, does not check it in the prototype chain.

31:14.280 --> 31:21.480
So it means we cannot affect reading on the main property anymore after that fix.

31:22.000 --> 31:33.020
But at some moment, gHunters start detect the require gadget again in the new version of the Node.js.

31:33.500 --> 31:46.340
And I double-checked all experiments, and I see that require detected again and again for some cases, and I start to see on this fix more closely.

31:46.340 --> 31:50.300
And it has another gadget.

31:50.720 --> 31:52.760
I will zoom in.

31:53.100 --> 31:57.380
You can see exactly in these slides.

31:57.880 --> 32:00.600
We have this if statement.

32:00.600 --> 32:05.260
If JSON is undefined, the function returns false.

32:05.260 --> 32:09.760
The function load config returns false.

32:09.900 --> 32:15.720
ParseJSON becomes a false, and we try to read the main from the false.

32:15.720 --> 32:24.940
JsRuntime in this case tried to box primitive type, Boolean type, and add object prototype in the prototype chain.

32:24.940 --> 32:32.440
And we again can read the main, but from the false, actually.

32:32.440 --> 32:58.680
So, it's a new gadget, and when I figure out it, so I add the payload for the require in the original Kibana YAML file, and it allows us to exploit this prototype solution and achieve remote code execution.

32:58.680 --> 33:10.460
So, this vulnerability did not get high score because it required high privileged user, but still it's almost 4,000 bounces.

33:11.860 --> 33:18.940
Let's see on the next story about prototype pollution and remote code execution.

33:18.940 --> 33:34.280
Another case that was reported by our script, SilentSpring Node.js queries, was a prototype pollution in some handler, web handler.

33:34.320 --> 33:58.120
So, it's very simple prototype pollution, you can see we create empty object, it means this object has the prototype points to the object prototype, and we have this line of the code, if namespace is __prot__, and the key is the key controlled by the attacker,

33:58.120 --> 34:07.460
that's so, and the value also can be controlled by the attacker, it means we can add any key with controlled value to the object prototype.

34:07.480 --> 34:12.080
Very simple, you don't even need a script to find it.

34:14.860 --> 34:22.220
Okay, so when I started working on this script, the question, we need to find a gadget.

34:22.220 --> 34:33.500
We worked on the Dusty, it's another project that detected 49 gadgets leading to remote code execution in NPM packages.

34:33.500 --> 34:54.800
We took a thousand popular NPM packages and run dynamic analysis that try to instrument the package and investigate what the flows can lead to, read the properties from the prototype and can lead to remote code execution in the end.

34:54.800 --> 35:08.100
And one of the package that has a gadget was NotMailer, and Kibana uses this gadget to send emails.

35:08.580 --> 35:19.500
So, the idea, we have some SendMailer transport that's optional, but you also can pollute some option to enable it.

35:20.230 --> 35:28.280
And it has some options that's by default empty.

35:29.640 --> 35:48.400
And if we have path in the options, the path of the run program that should be SendMailer and args will be read 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:11.030
But the problem is that DeleteHandler crashes the application in less than one second after the prototype pollution.

36:11.030 --> 36:23.470
So, it also becomes immediately, because some code in the end of the handler, of the same handler, does not expect the property, some additional property, and throw exception that's not handled correctly.

36:23.490 --> 36:25.770
And we get denial of the service.

36:25.770 --> 36:30.730
That's not much interesting for such vulnerability.

36:31.070 --> 36:33.790
So, it looks like unexploitable.

36:33.790 --> 36:40.770
Denial of the service, I could not say that it's an interesting impact that we want to show.

36:40.830 --> 37:08.550
But if we try to emulate some race condition by sending a lot of gadget-triggered requests in parallel and one prototype-pollution-triggered request between them, we can try to get the situation that gadget-triggered request will be in the small time exactly after the prototype pollution request.

37:08.870 --> 37:14.270
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:41.450
So, the idea, we send 20 requests that trigger a gadget first, and after that we send the request 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:55.210
So, we send a lot of requests.

37:55.310 --> 37:58.510
Let's see how it works in the demo.

37:59.670 --> 38:23.350
So, I run it from my laptop, through the Wi-Fi, and first of all I start some payload that created 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:42.170
And I started this web page to see which requests we will get.

38:42.170 --> 38:50.010
So, I did not run a reverse shell, I just sent a request to this web page.

38:50.010 --> 38:55.910
You can see that five requests will be successfully received.

38:55.910 --> 39:07.230
It means that five cases will be for so short time that were executed before the crash.

39:07.810 --> 39:10.990
And this attack was run from the Wi-Fi.

39:10.990 --> 39:18.990
You can get more interesting, I guess, if you run it on the same server, in the same network, like in cloud or some cases.

39:19.490 --> 39:27.490
Okay, this attack gave me the biggest bounty that I got from the Elastic.

39:27.890 --> 39:35.370
And not only this prototype pollution that I reported was exploited, this case was closed a few days ago.

39:35.370 --> 39:41.090
I did not have time to edit in the presentation and also we don't have much time.

39:41.250 --> 39:49.710
And another case that was reported also, this is a chain that leads to account takeover.

39:49.850 --> 39:54.190
Maybe I will do it in the next presentation, let's see.

39:55.410 --> 40:10.830
As a bonus part, I want to explain some advanced technique for the prototype pollution when we pollute the objects in the prototype, not the prototype itself.

40:12.590 --> 40:24.410
When I understood this trick, it allows me to report a few new vulnerabilities that I actually thought were unexploitable before.

40:24.530 --> 40:26.690
Let's see the example.

40:26.970 --> 40:34.290
We have a prototype pollution from our original example, very simple code that we already know.

40:34.290 --> 40:35.630
We have a gadget.

40:35.630 --> 40:44.470
The gadget reads the options and checks the property runner.

40:44.470 --> 40:49.070
The options are empty object by default.

40:49.070 --> 40:58.890
If the runner is defined, we read paths and arcs and spawn a new process for that.

40:58.890 --> 41:05.010
It means we need to pollute a runner in the object prototype, like this.

41:05.770 --> 41:12.670
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:28.870
What if this prototype pollution does not allow us to control the value?

41:28.870 --> 41:34.770
For example, it's some object with a predefined identifier and other properties.

41:34.770 --> 41:36.410
We cannot control it.

41:37.310 --> 41:40.010
Or it's an empty array.

41:40.010 --> 41:44.170
The array does not have any properties, right?

41:45.910 --> 41:50.110
It looks like unexploitable, at least for such a gadget.

41:50.110 --> 41:52.830
Maximum, we can get the denial of the service.

41:52.830 --> 41:58.010
But what if we have such code?

41:58.250 --> 42:01.750
It's a fixed, I call it a fixed prototype pollution.

42:01.750 --> 42:10.330
We check that arc does not equal a prototype and execute this code only for that.

42:10.330 --> 42:20.650
It cannot lead to prototype pollution, but we can combine these two code snippets.

42:20.650 --> 42:27.530
So it's absolutely safe code separately from this one.

42:27.530 --> 42:30.690
But what we can do together with these components?

42:30.690 --> 42:33.790
First of all, we need to pollute the prototype.

42:33.790 --> 42:42.050
We add a runner with a value of empty array in the prototype to trigger handle update.

42:42.050 --> 42:43.270
Good.

42:43.430 --> 42:55.150
After that, we trigger this save function with arc that has a runner value.

42:55.150 --> 43:00.930
It means we will try to read the runner from the prototype at this step.

43:00.930 --> 43:04.130
And we pollute the runner after that.

43:04.130 --> 43:12.390
We can't feel any additional properties in the runner by this call and the second call.

43:12.390 --> 43:15.970
And after that, we trigger backup handler.

43:15.970 --> 43:25.690
It gives us the remote code execution again by this chain of the calls, the web request that triggers such functions.

43:26.190 --> 43:48.070
If you think that it's unlikely that we find some fixed prototype pollution case and unfixed prototype pollution case in the same application, I can say you that, for example, merge functions are very typical in the fixed prototype pollutions.

43:48.070 --> 43:59.270
Like a merge function of the very popular package lodash allows us to pollute a runner with such payload.

43:59.270 --> 44:03.410
And you can find lodash merge calls in many applications.

44:03.410 --> 44:07.930
And that's important that these two parts can be unrelated.

44:07.930 --> 44:15.330
It could be absolutely different features in the application.

44:16.370 --> 44:20.790
So yeah, use it for fun and bounces.

44:21.290 --> 44:31.030
In conclusion, in this talk, I wanted to show the cases that look unexploitable and say, don't give up.

44:31.150 --> 44:36.890
Try to achieve remote code execution even when it looks impossible.

44:37.310 --> 44:46.430
If you're interested in prototype pollution research, check out our papers, SilentSpring, G-Hunter and Dusty that I mentioned in the talk.

44:46.730 --> 44:52.890
Check out the collection of server-side prototype pollution gadgets that we shared.

44:52.890 --> 45:02.170
This is a gadget in Node.js itself and dino and npm packages that I also use in my bug bounty cases.

45:02.690 --> 45:13.610
If you're interested in networking attacks and this story about ARP spoofing, I highly recommend to read this blog post.

45:13.610 --> 45:18.370
ARP spoofing in Kubernetes is not so easy as it looks like.

45:18.370 --> 45:27.510
It also has some difficulties with the IP table rules that were bypassed by this talk.

45:27.510 --> 45:30.570
Check out this blog post.

45:30.570 --> 45:32.930
I think you'll enjoy it.

45:32.930 --> 45:38.370
And follow me on Twitter if you're interested in some details of code reuse attacks.

45:38.370 --> 45:43.250
I want to share some findings that I am now including in my thesis.

45:43.850 --> 45:46.550
And thank you for your attention.

45:47.730 --> 45:48.890
Enjoy DEF CON.

45:48.890 --> 45:49.510
Bye-bye.

