WEBVTT

00:00.000 --> 00:02.520
Hi, hello everyone.

00:03.180 --> 00:07.580
Welcome to The Missing Link, Drytex's new RCEs complete the chain.

00:09.020 --> 00:13.260
I'm Gaston Asnares and my partner here is Octavio Giana-Tiempo.

00:13.260 --> 00:16.000
We are security researchers at Faraday.

00:16.000 --> 00:21.440
We mostly focus on firmware and embedded and low-level stuff.

00:23.820 --> 00:32.940
Okay, what we are going to see today, first we are going to do an introduction and a recapitulation about our previous work and what we are doing now.

00:33.140 --> 00:47.080
We are going to show new vulnerabilities and with the vulnerabilities that we found now and the old ones, we are going to show the full chain exploit from the internet to persistence.

00:47.440 --> 00:59.240
We also are going to check the wave of routers reboots that we saw in March and we are going to give some conclusions and takeaways.

01:02.340 --> 01:05.200
Okay, so let's start with the introduction.

01:05.860 --> 01:10.240
Yes, it's not our first time with Drytex routers here in DEF CON.

01:10.240 --> 01:21.400
Last year we gave a talk about this, showing some vulnerabilities and focusing on detecting persistence and focusing on persistence on these routers.

01:23.320 --> 01:26.040
A quick recapitulation.

01:26.280 --> 01:34.840
We have a small business router with a MIPS32 CPU and running an RTOS.

01:34.840 --> 01:37.820
The name of the RTOS is DryOS.

01:38.200 --> 01:48.100
But Drytex also has medium‑sized enterprise routers that has an ARM CPU and they run Linux.

01:48.100 --> 01:58.260
But an important thing of these routers is that in the Linux they emulate, using QEMU, the same operating system as the small business routers.

01:58.260 --> 02:08.380
So, if we could find something in the small business routers, it should be also in the medium‑sized enterprise.

02:09.880 --> 02:13.840
Okay, let's talk about the attack surface.

02:13.840 --> 02:22.420
We found over 5,100 exposed devices, mostly in the UK.

02:22.540 --> 02:32.600
And we found previous vulnerabilities that affect these routers from information disclosure to remote code execution and our previous vulnerabilities.

02:35.410 --> 02:45.130
Okay, last year we released a tool for helping all the people to start reverse engineering and finding vulnerabilities on these routers.

02:45.130 --> 02:47.490
The name of this tool is Drytex Arsenal.

02:47.490 --> 02:50.510
You will find it in GitHub.

02:50.830 --> 02:55.090
And now it supports new firmware versions.

02:58.290 --> 02:59.230
Okay.

02:59.710 --> 03:00.970
Our previous vulnerabilities.

03:00.970 --> 03:03.210
We found a bunch of things.

03:03.610 --> 03:12.930
We found missing SSL certificate validation and non‑constant time password comparison that let us make a side channel attack.

03:12.990 --> 03:18.670
We found secure password storage, predictable two‑factor authentication and code generation.

03:18.730 --> 03:30.530
And the most important three are DHCP server reference that let us reboot and maybe make a service attack.

03:30.710 --> 03:39.910
And the last two allow us to upload arbitrary modules, kernel modules to the device.

03:42.610 --> 03:43.110
Okay.

03:43.110 --> 03:50.610
So, what we have now, we have to use a password reuse or a password default.

03:50.950 --> 03:54.150
And with the two‑factor authentication, we could authenticate.

03:54.410 --> 03:59.790
We have authenticated code execution and then we have kernel level persistence.

04:00.230 --> 04:01.830
But that's not enough.

04:01.830 --> 04:03.570
We wanted more.

04:04.890 --> 04:13.050
What we wanted is a pre‑authentication vulnerability to gain code execution and then have kernel level persistent.

04:13.050 --> 04:18.090
And in that way, we complete the chain from internet to the persistence.

04:20.670 --> 04:21.410
Okay.

04:21.410 --> 04:37.710
We ended up our last talk saying that there are probably more vulnerabilities in these routers because the complexity of this operating system is really high and we only looked a part of it.

04:39.270 --> 04:40.950
And that was happened.

04:41.750 --> 04:48.630
So, what got our attention to come back to see that routers was dry break.

04:48.630 --> 04:54.030
A research presented by the people of Forescout and Black Hat Europe 2024.

04:55.110 --> 05:02.790
And the most important thing that got our attention was a buffer overflow in a function with the name of getCGI.

05:03.890 --> 05:13.130
So, we reverse engineered all the firmware, found interesting vulnerabilities, brought persistent malware, but we didn't look at the CGI request parser.

05:15.070 --> 05:18.570
And then we learned something about this.

05:18.570 --> 05:23.970
We learned that there is a new vulnerable pattern and a new attack surface.

05:24.110 --> 05:30.250
So, we come back and start again to see the firmware on this attack surface.

05:30.330 --> 05:33.170
And we found two more vulnerabilities.

05:33.310 --> 05:37.550
And now we can complete the chain from the internet to the persistence.

05:40.420 --> 05:40.920
Okay.

05:40.920 --> 05:45.860
Let's talk something about the new vulnerabilities and exploitation.

05:45.880 --> 05:53.020
The first vulnerability that we found was a buffer overflow in TR-69 STAN parsing.

05:53.020 --> 05:59.600
And it's really related to one CVE that Forescout released.

05:59.600 --> 06:08.300
That CVE from Forescout was a stack overflow when processing query string parameters on the getCGI function.

06:09.060 --> 06:14.820
So, what does the CGI function or how it works?

06:15.120 --> 06:15.340
Okay.

06:15.340 --> 06:18.640
So, first it's going to have two important arguments.

06:18.640 --> 06:21.000
The first one is a buffer.

06:21.000 --> 06:22.980
And the second one is a query string.

06:23.620 --> 06:33.220
So, it will receive that parameters and will parse the string to get the parameters on the heap.

06:34.000 --> 06:39.400
We will see that it has a loop to process each argument.

06:39.440 --> 06:45.300
As we know, the arguments of a query are separated by ampersand.

06:45.300 --> 06:52.980
So, makeWord is going to grab the current argument and will copy on the heap that.

06:53.540 --> 07:00.160
And then it's going to change the plus sign for spaces and escape the URL.

07:00.160 --> 07:06.760
And then it's going to look for the equal sign, because the argument has a key and a value.

07:07.640 --> 07:13.480
And in that side, it's going to change that equal sign for a new character.

07:13.880 --> 07:20.800
And then it's going to store the address of the key and the address of the value.

07:20.820 --> 07:24.560
We are going to see an example to understand it better.

07:25.300 --> 07:25.540
Okay.

07:25.540 --> 07:30.740
So, for example, we have on the top right a URL with the arguments.

07:31.000 --> 07:40.060
And we assume that cgiHandler is going to call this getCGI with a buffer in the stack.

07:40.060 --> 07:45.580
We can see that at the left, the caller stack and the getCGI stack.

07:45.680 --> 07:53.320
So, as we said, the first thing is going to be that it's going to store the first argument on the heap.

07:53.840 --> 08:00.500
And then it's going to clean it and find the equal sign and change it for a null pointer.

08:00.500 --> 08:02.160
So, we have two strings.

08:03.280 --> 08:12.440
And then it's going to store in the first index of the buffer, the key, and in the second index of the buffer, the value.

08:13.060 --> 08:16.300
And it's going to do the same for each argument.

08:16.860 --> 08:26.480
But the important thing here is that it's not going to check the amount of parameters that it's going to parse.

08:26.540 --> 08:36.420
So, eventually, if we put in enough arguments, we are going to modify the return address of the stack, of the function.

08:36.780 --> 08:41.320
And then we will have a remote co-execution with the buffer overflow.

08:43.240 --> 08:47.520
Okay, that was how getCGI works.

08:47.800 --> 08:56.660
But this is the function that handles connections to the TR-69 stand.

08:57.320 --> 09:01.100
And we can see that it's really similar to getCGI.

09:01.100 --> 09:05.720
So, it has the same pattern, the same vulnerable pattern.

09:05.720 --> 09:13.660
At the vulnerabilities here, we think that the compiler has in line the getCGI function in this one.

09:13.980 --> 09:20.620
And for that, the force code group couldn't find it.

09:22.340 --> 09:26.340
Okay, so, we have to enable TR-69 stand.

09:26.340 --> 09:31.800
And the router is going to start listening on UDP port, that port.

09:31.800 --> 09:38.160
And all the packets received are going to be parsed by that function that we saw.

09:39.960 --> 09:49.920
In a really simple way, how TR-69 works, the router is going to send a bind request to the stand server.

09:49.920 --> 09:53.840
And the stand server is going to answer to the binding response.

09:53.840 --> 09:59.220
A funny fact that the router is listening on a non-default stone port.

10:01.000 --> 10:12.100
But we, as an attacker, could send data or queries to the router without having the binding request or binding response.

10:12.100 --> 10:14.840
The router is always listening.

10:16.520 --> 10:21.320
So, we made a proof of concept that crashed the router.

10:21.620 --> 10:28.220
And it can be converted to a remote code execution following the force code exploitation strategy.

10:28.620 --> 10:36.700
But we didn't go in that way because of the restrictions that this interface has.

10:36.700 --> 10:42.520
And we found a more interesting bug that now Octavio is going to show you.

10:45.180 --> 10:46.100
Hi.

10:46.100 --> 10:51.120
So, the second bug is an integer overflow in the CGA parsing function.

10:51.120 --> 10:57.300
Its relationship with the force code CVE is that it's located in the same getCGI function.

10:57.320 --> 11:01.940
And this function is very important because every CGI handler calls it.

11:02.000 --> 11:07.380
Every query you do to the router to a CGI endpoint ends up calling this function.

11:07.380 --> 11:09.860
So, we decided to take a better look at it.

11:11.580 --> 11:18.060
This function starts by checking the request method from the header of the request.

11:18.160 --> 11:24.080
And in this case, the part we are interested in, if it is a POST request.

11:24.200 --> 11:39.840
So, when a POST request arrives the router, then the content length is extracted from the header and it's used to allocate some memory on the heap to copy the contents of the POST request.

11:40.000 --> 11:41.920
Yes, the body of the request.

11:42.540 --> 11:47.420
So, all this is done using signed integers.

11:47.420 --> 12:02.160
So, if we set the content length header to the maximum 32-bit integer positive, then when the router calls the malloc and adds one to this, we'll get the minimum 32-bit integer, which is negative.

12:02.160 --> 12:10.220
So, if we take a look at how the malloc works in this router, it also uses signed comparisons.

12:10.560 --> 12:17.400
So, if we send this number, then we will get our heap being allocated in the smallest cache.

12:17.400 --> 12:20.840
And this cache, it has only 24 bytes.

12:21.760 --> 12:25.980
So, now we transformed our integer overflow into a heap overflow.

12:27.500 --> 12:29.480
We can see here an example.

12:29.480 --> 12:38.400
We set the content length to this number and then the router doesn't crash, but we get a message, a log, that says slap panic.

12:38.400 --> 12:42.680
The object checksum, there was an error while checking the object checksum.

12:45.120 --> 12:51.920
And this is because this lab allocator that this router uses has some metadata in its objects.

12:52.240 --> 13:01.500
So, we are landing a cache with 24-byte objects, but these objects are really represented using 32 bytes.

13:01.880 --> 13:07.420
After the user data, there is the line that made the location, the time, and the offset.

13:07.420 --> 13:09.020
But there is also a checksum.

13:09.020 --> 13:13.380
And this is the metadata that we are correcting with our overrun.

13:13.920 --> 13:24.600
When these objects are free, are not in use, the first part of the data, or where the user would put the data, is used to store a pointer to the next free object.

13:25.120 --> 13:29.200
And so, this internal structure is really a linked list.

13:30.060 --> 13:36.100
And what is stored is a pointer to the first free block on the list.

13:36.740 --> 13:41.260
So, how can we transform this into an arbitrary write?

13:41.620 --> 13:48.280
Suppose we get this first chunk, and now someone makes another allocation.

13:48.480 --> 13:56.620
We can start to write past our boundaries, and eventually we will end up overwriting a pointer to the next free chunk.

13:57.460 --> 14:05.760
So, if we made two more allocations, then the second one will be an arbitrary address that we can define.

14:05.780 --> 14:09.920
And we can arbitrarily write data at this direction.

14:09.980 --> 14:14.860
But the downside of this is that now we have a broken allocator.

14:15.560 --> 14:18.940
Luckily, this is not a problem for exploitation.

14:19.740 --> 14:22.820
So, how can we use this to execute code?

14:23.520 --> 14:27.240
Well, as Gaston said, these routers run MIPS.

14:27.340 --> 14:32.160
And in MIPS, all the exceptions trigger a jump to a general exception handler.

14:32.340 --> 14:47.760
This handler will look for the reason of the exception in the cost register, a coprocessor register, and it will use this value to index a table that has pointers to handlers for each specific exception code.

14:49.420 --> 14:58.120
So, what we can do is use this arbitrary write to overwrite an exception handler pointer in this table to some place we control.

14:58.460 --> 15:05.180
Then, we have to trigger the exception to make the code flow jump there, and we will get an arbitrary code execution.

15:07.420 --> 15:20.360
Specifically, for attacking this router, we will send a shellcode in a request, and this will get stored in a low-level network reception buffer, which is almost every time at a fixed offset in memory.

15:20.400 --> 15:32.720
Then, we will use the arbitrary write to point the illegal address load exception handler pointer from this table to the buffer that we control and that should have the shellcode.

15:32.920 --> 15:45.220
We will use the last-year talk bug in all the reference that Gaston talked about to trigger this exception, and then the shellcode will be executed in place of the exception handler.

15:46.920 --> 15:49.840
So, now a proof of concept of this.

15:54.480 --> 16:00.420
This is kind of quick, so I will pause it.

16:02.160 --> 16:04.460
So, now you see all this lab panics.

16:04.460 --> 16:16.860
We are overrunning this metadata in the heap, and this attack is just a proof of concept that executes a payload that only prints success repeatedly.

16:25.850 --> 16:32.350
So, now we have to change this with all the previous vulnerabilities to make the full chain exploit.

16:32.910 --> 16:36.010
A recap of last year's talk.

16:36.010 --> 16:39.030
The persistence strategy was based on DLMs.

16:39.030 --> 16:41.890
DLMs are dynamically loadable modules.

16:41.890 --> 16:51.370
These modules are kernel modules that provide extra functionality to the real-time operating system and are used, for example, to implement the SSH daemon.

16:51.980 --> 17:01.570
They are updated independently from the firmware, and this is what makes them persistent, and are dynamically loaded every time the router boots.

17:02.510 --> 17:09.390
So, if you modify one of these kernel modules, when the router boots, it will load them first.

17:09.390 --> 17:18.130
They will have priority over the ones that are default that come with the firmware image, and it will prevent their loading.

17:18.550 --> 17:29.250
So, this module will persist reboots, will persist factory resets, and more importantly, will persist even after firmware updates because they are stored in a separate partition on the flash.

17:31.370 --> 17:36.290
So, these modules, though, are encrypted and are also compressed.

17:36.290 --> 17:47.230
We reverse-engineered both algorithms, and it turned out that the module recryption was using a modified version of the XDA algorithm.

17:47.650 --> 17:57.450
And this is a symmetric encryption scheme, so this means that the keys are present on the firmware, so we can encrypt and decrypt modules with that.

17:57.810 --> 18:05.890
And we also found out that the module compression is the same as the firmware image, which is a modified version of the LC4 algorithm.

18:06.190 --> 18:17.110
So, we wrote the decryptor and encryptor, and we also wrote the compressor and compressor, and when we took a DLM and we decrypt it and then decompress it, what we got was a relocatable ELF.

18:17.530 --> 18:28.350
And, well, this is a very known format, so we could patch it to make a backdoor SSH demo, for example, that allowed us to log in with our credentials.

18:30.570 --> 18:42.330
So, to change everything, we have to send a request including a shell code, and we will use a shell code that changes the admin password from the default one to one we know.

18:42.870 --> 18:56.030
This request will also trigger the heap buffer overflow and will replace the interrupt handler for illegal access to memory with a pointer to the same shell code that we sent in the request.

18:56.430 --> 19:01.830
Then we will use the Nuldo reference to trigger this exception, and our shell code will execute.

19:01.830 --> 19:09.910
Now, with the new password that we have set, we can upload a malicious module and use it to access the router through SSH.

19:17.390 --> 19:19.110
So, here's the demo.

19:21.750 --> 19:24.170
First, we show that we cannot log in.

19:30.840 --> 19:33.740
Now we have successfully changed the password.

19:55.020 --> 19:59.500
We have uploaded our module, and now the router is rebooting.

20:24.070 --> 20:34.410
So, now we added a new user to the router with our preferred credentials, and this user will coexist with the existing user and the real users of the router won't notice.

20:39.410 --> 20:47.030
So, now Gaston will talk about how this relates to the router reboots that were seen in the wild at the beginning of this year.

20:50.310 --> 21:04.790
Okay, so, in March, we started receiving some news and some messages about some router devices that were rebooting itself without cause.

21:05.750 --> 21:14.370
It was like all the routers were rebooting, and we started thinking about this and what it could be.

21:14.770 --> 21:25.730
And after that, we read the security advisory of Ritec, and they say this issue appears to be linked to previous disclosure vulnerability from early March.

21:25.970 --> 21:31.750
And this matches with our two vulnerabilities that we showed to you today.

21:32.450 --> 21:38.320
So, we started thinking that possibly it could be our vulnerabilities.

21:39.270 --> 21:49.570
And we had an hypothesis, because successful exploitations depend on the landing address of the payload, and that has to be correct.

21:50.250 --> 21:54.810
If it is not correct, the router is going to crash and it's going to reboot.

21:55.150 --> 21:59.950
But these offsets vary with the firmware version and the router model.

21:59.950 --> 22:06.850
So, maybe the reboots are caused by the failed exploitation attempts.

22:07.350 --> 22:14.890
And if there was failure exploitation attempts, there also could be successes on exploitation.

22:14.890 --> 22:18.810
But the successes are silent, so we don't know about it.

22:19.170 --> 22:21.430
So, we start investigating.

22:21.430 --> 22:27.670
We set up four honeypots in different countries where the routers are more popular.

22:27.670 --> 22:31.790
We use one physical router and we emulate three others.

22:32.090 --> 22:37.830
But we couldn't detect any reboots, neither exploitation attempts.

22:37.830 --> 22:46.790
So, we think that we wouldn't know if we were late, or we need more honeypots, but the question remains open.

22:48.930 --> 22:51.770
So, Octavio is going to continue with some conclusions.

22:54.030 --> 23:01.390
Well, some of these bugs, the first ones, were fixed by Tritec from August to October of last year.

23:01.630 --> 23:07.810
And the last two ones, Tritec was very, very quick to fix them, were fixed in November of 2024.

23:09.590 --> 23:13.190
So, we learned some lessons about this research.

23:13.190 --> 23:17.610
The first one is that bugs are like cockroaches, a phrase from Ivan Arce.

23:18.910 --> 23:24.990
The surface that the Forescout team started to look at had some bugs.

23:24.990 --> 23:29.230
We looked at it, it had some more, and there are probably more bugs.

23:29.890 --> 23:37.350
And, well, from our research perspective, in our initial research, we focused on sink-to-source analysis.

23:37.390 --> 23:41.910
And this led us to a deep understanding of the inner workings of the router.

23:42.430 --> 23:52.150
But source-to-sink approach also favors completeness, and exploring all the surface would have led us to found the CGA parsing function, for example.

23:52.150 --> 23:55.270
And this router has a lot of surface.

23:55.270 --> 24:01.350
It has different VPN services and other things, so there will be more bugs here.

24:01.350 --> 24:05.130
And both strategies are complementary, we have learned that.

24:05.790 --> 24:11.070
And for users, always the same, update your firmware, do not expose unnecessary surface.

24:12.370 --> 24:18.110
So, there were vulnerabilities affecting these routers, and there will be more, we are sure of it.

24:19.050 --> 24:30.750
But we are retiring from Ditec for now, so now it's up to you to keep looking for bugs, and we have this tool to extract the firmware images that you can use to start reverse engineering.

24:31.490 --> 24:40.590
And now we are moving into car hacking, so we invite you to check Evildoggy, which is an open-source modular CAN bus research and penetration testing tool that we are developing.

24:42.790 --> 24:44.050
So, that's it.

24:44.050 --> 24:47.490
Thank you for your time, and if you have any questions, just ask.

