1 00:00:00,000 --> 00:00:02,520 Hi, hello everyone. 2 00:00:03,180 --> 00:00:07,580 Welcome to The Missing Link, Drytex's new RCEs complete the chain. 3 00:00:09,020 --> 00:00:13,260 I'm Gaston Asnares and my partner here is Octavio Giana-Tiempo. 4 00:00:13,260 --> 00:00:16,000 We are security researchers at Faraday. 5 00:00:16,000 --> 00:00:21,440 We mostly focus on firmware and embedded and low-level stuff. 6 00:00:23,820 --> 00: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. 7 00:00:33,140 --> 00: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. 8 00:00:47,440 --> 00: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. 9 00:01:02,340 --> 00:01:05,200 Okay, so let's start with the introduction. 10 00:01:05,860 --> 00:01:10,240 Yes, it's not our first time with Drytex routers here in DEF CON. 11 00:01:10,240 --> 00: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. 12 00:01:23,320 --> 00:01:26,040 A quick recapitulation. 13 00:01:26,280 --> 00:01:34,840 We have a small business router with a MIPS32 CPU and running an RTOS. 14 00:01:34,840 --> 00:01:37,820 The name of the RTOS is DryOS. 15 00:01:38,200 --> 00:01:48,100 But Drytex also has medium‑sized enterprise routers that has an ARM CPU and they run Linux. 16 00:01:48,100 --> 00: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. 17 00:01:58,260 --> 00:02:08,380 So, if we could find something in the small business routers, it should be also in the medium‑sized enterprise. 18 00:02:09,880 --> 00:02:13,840 Okay, let's talk about the attack surface. 19 00:02:13,840 --> 00:02:22,420 We found over 5,100 exposed devices, mostly in the UK. 20 00:02:22,540 --> 00:02:32,600 And we found previous vulnerabilities that affect these routers from information disclosure to remote code execution and our previous vulnerabilities. 21 00:02:35,410 --> 00: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. 22 00:02:45,130 --> 00:02:47,490 The name of this tool is Drytex Arsenal. 23 00:02:47,490 --> 00:02:50,510 You will find it in GitHub. 24 00:02:50,830 --> 00:02:55,090 And now it supports new firmware versions. 25 00:02:58,290 --> 00:02:59,230 Okay. 26 00:02:59,710 --> 00:03:00,970 Our previous vulnerabilities. 27 00:03:00,970 --> 00:03:03,210 We found a bunch of things. 28 00:03:03,610 --> 00:03:12,930 We found missing SSL certificate validation and non‑constant time password comparison that let us make a side channel attack. 29 00:03:12,990 --> 00:03:18,670 We found secure password storage, predictable two‑factor authentication and code generation. 30 00:03:18,730 --> 00:03:30,530 And the most important three are DHCP server reference that let us reboot and maybe make a service attack. 31 00:03:30,710 --> 00:03:39,910 And the last two allow us to upload arbitrary modules, kernel modules to the device. 32 00:03:42,610 --> 00:03:43,110 Okay. 33 00:03:43,110 --> 00:03:50,610 So, what we have now, we have to use a password reuse or a password default. 34 00:03:50,950 --> 00:03:54,150 And with the two‑factor authentication, we could authenticate. 35 00:03:54,410 --> 00:03:59,790 We have authenticated code execution and then we have kernel level persistence. 36 00:04:00,230 --> 00:04:01,830 But that's not enough. 37 00:04:01,830 --> 00:04:03,570 We wanted more. 38 00:04:04,890 --> 00:04:13,050 What we wanted is a pre‑authentication vulnerability to gain code execution and then have kernel level persistent. 39 00:04:13,050 --> 00:04:18,090 And in that way, we complete the chain from internet to the persistence. 40 00:04:20,670 --> 00:04:21,410 Okay. 41 00:04:21,410 --> 00: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. 42 00:04:39,270 --> 00:04:40,950 And that was happened. 43 00:04:41,750 --> 00:04:48,630 So, what got our attention to come back to see that routers was dry break. 44 00:04:48,630 --> 00:04:54,030 A research presented by the people of Forescout and Black Hat Europe 2024. 45 00:04:55,110 --> 00:05:02,790 And the most important thing that got our attention was a buffer overflow in a function with the name of getCGI. 46 00:05:03,890 --> 00: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. 47 00:05:15,070 --> 00:05:18,570 And then we learned something about this. 48 00:05:18,570 --> 00:05:23,970 We learned that there is a new vulnerable pattern and a new attack surface. 49 00:05:24,110 --> 00:05:30,250 So, we come back and start again to see the firmware on this attack surface. 50 00:05:30,330 --> 00:05:33,170 And we found two more vulnerabilities. 51 00:05:33,310 --> 00:05:37,550 And now we can complete the chain from the internet to the persistence. 52 00:05:40,420 --> 00:05:40,920 Okay. 53 00:05:40,920 --> 00:05:45,860 Let's talk something about the new vulnerabilities and exploitation. 54 00:05:45,880 --> 00:05:53,020 The first vulnerability that we found was a buffer overflow in TR-69 STAN parsing. 55 00:05:53,020 --> 00:05:59,600 And it's really related to one CVE that Forescout released. 56 00:05:59,600 --> 00:06:08,300 That CVE from Forescout was a stack overflow when processing query string parameters on the getCGI function. 57 00:06:09,060 --> 00:06:14,820 So, what does the CGI function or how it works? 58 00:06:15,120 --> 00:06:15,340 Okay. 59 00:06:15,340 --> 00:06:18,640 So, first it's going to have two important arguments. 60 00:06:18,640 --> 00:06:21,000 The first one is a buffer. 61 00:06:21,000 --> 00:06:22,980 And the second one is a query string. 62 00:06:23,620 --> 00:06:33,220 So, it will receive that parameters and will parse the string to get the parameters on the heap. 63 00:06:34,000 --> 00:06:39,400 We will see that it has a loop to process each argument. 64 00:06:39,440 --> 00:06:45,300 As we know, the arguments of a query are separated by ampersand. 65 00:06:45,300 --> 00:06:52,980 So, makeWord is going to grab the current argument and will copy on the heap that. 66 00:06:53,540 --> 00:07:00,160 And then it's going to change the plus sign for spaces and escape the URL. 67 00:07:00,160 --> 00:07:06,760 And then it's going to look for the equal sign, because the argument has a key and a value. 68 00:07:07,640 --> 00:07:13,480 And in that side, it's going to change that equal sign for a new character. 69 00:07:13,880 --> 00:07:20,800 And then it's going to store the address of the key and the address of the value. 70 00:07:20,820 --> 00:07:24,560 We are going to see an example to understand it better. 71 00:07:25,300 --> 00:07:25,540 Okay. 72 00:07:25,540 --> 00:07:30,740 So, for example, we have on the top right a URL with the arguments. 73 00:07:31,000 --> 00:07:40,060 And we assume that cgiHandler is going to call this getCGI with a buffer in the stack. 74 00:07:40,060 --> 00:07:45,580 We can see that at the left, the caller stack and the getCGI stack. 75 00:07:45,680 --> 00: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. 76 00:07:53,840 --> 00:08:00,500 And then it's going to clean it and find the equal sign and change it for a null pointer. 77 00:08:00,500 --> 00:08:02,160 So, we have two strings. 78 00:08:03,280 --> 00: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. 79 00:08:13,060 --> 00:08:16,300 And it's going to do the same for each argument. 80 00:08:16,860 --> 00: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. 81 00:08:26,540 --> 00: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. 82 00:08:36,780 --> 00:08:41,320 And then we will have a remote co-execution with the buffer overflow. 83 00:08:43,240 --> 00:08:47,520 Okay, that was how getCGI works. 84 00:08:47,800 --> 00:08:56,660 But this is the function that handles connections to the TR-69 stand. 85 00:08:57,320 --> 00:09:01,100 And we can see that it's really similar to getCGI. 86 00:09:01,100 --> 00:09:05,720 So, it has the same pattern, the same vulnerable pattern. 87 00:09:05,720 --> 00:09:13,660 At the vulnerabilities here, we think that the compiler has in line the getCGI function in this one. 88 00:09:13,980 --> 00:09:20,620 And for that, the force code group couldn't find it. 89 00:09:22,340 --> 00:09:26,340 Okay, so, we have to enable TR-69 stand. 90 00:09:26,340 --> 00:09:31,800 And the router is going to start listening on UDP port, that port. 91 00:09:31,800 --> 00:09:38,160 And all the packets received are going to be parsed by that function that we saw. 92 00:09:39,960 --> 00: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. 93 00:09:49,920 --> 00:09:53,840 And the stand server is going to answer to the binding response. 94 00:09:53,840 --> 00:09:59,220 A funny fact that the router is listening on a non-default stone port. 95 00:10:01,000 --> 00:10:12,100 But we, as an attacker, could send data or queries to the router without having the binding request or binding response. 96 00:10:12,100 --> 00:10:14,840 The router is always listening. 97 00:10:16,520 --> 00:10:21,320 So, we made a proof of concept that crashed the router. 98 00:10:21,620 --> 00:10:28,220 And it can be converted to a remote code execution following the force code exploitation strategy. 99 00:10:28,620 --> 00:10:36,700 But we didn't go in that way because of the restrictions that this interface has. 100 00:10:36,700 --> 00:10:42,520 And we found a more interesting bug that now Octavio is going to show you. 101 00:10:45,180 --> 00:10:46,100 Hi. 102 00:10:46,100 --> 00:10:51,120 So, the second bug is an integer overflow in the CGA parsing function. 103 00:10:51,120 --> 00:10:57,300 Its relationship with the force code CVE is that it's located in the same getCGI function. 104 00:10:57,320 --> 00:11:01,940 And this function is very important because every CGI handler calls it. 105 00:11:02,000 --> 00:11:07,380 Every query you do to the router to a CGI endpoint ends up calling this function. 106 00:11:07,380 --> 00:11:09,860 So, we decided to take a better look at it. 107 00:11:11,580 --> 00:11:18,060 This function starts by checking the request method from the header of the request. 108 00:11:18,160 --> 00:11:24,080 And in this case, the part we are interested in, if it is a POST request. 109 00:11:24,200 --> 00: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. 110 00:11:40,000 --> 00:11:41,920 Yes, the body of the request. 111 00:11:42,540 --> 00:11:47,420 So, all this is done using signed integers. 112 00:11:47,420 --> 00: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. 113 00:12:02,160 --> 00:12:10,220 So, if we take a look at how the malloc works in this router, it also uses signed comparisons. 114 00:12:10,560 --> 00:12:17,400 So, if we send this number, then we will get our heap being allocated in the smallest cache. 115 00:12:17,400 --> 00:12:20,840 And this cache, it has only 24 bytes. 116 00:12:21,760 --> 00:12:25,980 So, now we transformed our integer overflow into a heap overflow. 117 00:12:27,500 --> 00:12:29,480 We can see here an example. 118 00:12:29,480 --> 00: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. 119 00:12:38,400 --> 00:12:42,680 The object checksum, there was an error while checking the object checksum. 120 00:12:45,120 --> 00:12:51,920 And this is because this lab allocator that this router uses has some metadata in its objects. 121 00:12:52,240 --> 00:13:01,500 So, we are landing a cache with 24-byte objects, but these objects are really represented using 32 bytes. 122 00:13:01,880 --> 00:13:07,420 After the user data, there is the line that made the location, the time, and the offset. 123 00:13:07,420 --> 00:13:09,020 But there is also a checksum. 124 00:13:09,020 --> 00:13:13,380 And this is the metadata that we are correcting with our overrun. 125 00:13:13,920 --> 00: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. 126 00:13:25,120 --> 00:13:29,200 And so, this internal structure is really a linked list. 127 00:13:30,060 --> 00:13:36,100 And what is stored is a pointer to the first free block on the list. 128 00:13:36,740 --> 00:13:41,260 So, how can we transform this into an arbitrary write? 129 00:13:41,620 --> 00:13:48,280 Suppose we get this first chunk, and now someone makes another allocation. 130 00:13:48,480 --> 00: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. 131 00:13:57,460 --> 00:14:05,760 So, if we made two more allocations, then the second one will be an arbitrary address that we can define. 132 00:14:05,780 --> 00:14:09,920 And we can arbitrarily write data at this direction. 133 00:14:09,980 --> 00:14:14,860 But the downside of this is that now we have a broken allocator. 134 00:14:15,560 --> 00:14:18,940 Luckily, this is not a problem for exploitation. 135 00:14:19,740 --> 00:14:22,820 So, how can we use this to execute code? 136 00:14:23,520 --> 00:14:27,240 Well, as Gaston said, these routers run MIPS. 137 00:14:27,340 --> 00:14:32,160 And in MIPS, all the exceptions trigger a jump to a general exception handler. 138 00:14:32,340 --> 00: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. 139 00:14:49,420 --> 00: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. 140 00:14:58,460 --> 00: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. 141 00:15:07,420 --> 00: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. 142 00:15:20,400 --> 00: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. 143 00:15:32,920 --> 00: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. 144 00:15:46,920 --> 00:15:49,840 So, now a proof of concept of this. 145 00:15:54,480 --> 00:16:00,420 This is kind of quick, so I will pause it. 146 00:16:02,160 --> 00:16:04,460 So, now you see all this lab panics. 147 00:16:04,460 --> 00: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. 148 00:16:25,850 --> 00:16:32,350 So, now we have to change this with all the previous vulnerabilities to make the full chain exploit. 149 00:16:32,910 --> 00:16:36,010 A recap of last year's talk. 150 00:16:36,010 --> 00:16:39,030 The persistence strategy was based on DLMs. 151 00:16:39,030 --> 00:16:41,890 DLMs are dynamically loadable modules. 152 00:16:41,890 --> 00: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. 153 00:16:51,980 --> 00: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. 154 00:17:02,510 --> 00:17:09,390 So, if you modify one of these kernel modules, when the router boots, it will load them first. 155 00:17:09,390 --> 00: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. 156 00:17:18,550 --> 00: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. 157 00:17:31,370 --> 00:17:36,290 So, these modules, though, are encrypted and are also compressed. 158 00:17:36,290 --> 00: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. 159 00:17:47,650 --> 00: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. 160 00:17:57,810 --> 00: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. 161 00:18:06,190 --> 00: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. 162 00:18:17,530 --> 00: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. 163 00:18:30,570 --> 00: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. 164 00:18:42,870 --> 00: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. 165 00:18:56,430 --> 00:19:01,830 Then we will use the Nuldo reference to trigger this exception, and our shell code will execute. 166 00:19:01,830 --> 00: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. 167 00:19:17,390 --> 00:19:19,110 So, here's the demo. 168 00:19:21,750 --> 00:19:24,170 First, we show that we cannot log in. 169 00:19:30,840 --> 00:19:33,740 Now we have successfully changed the password. 170 00:19:55,020 --> 00:19:59,500 We have uploaded our module, and now the router is rebooting. 171 00:20:24,070 --> 00: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. 172 00:20:39,410 --> 00: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. 173 00:20:50,310 --> 00: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. 174 00:21:05,750 --> 00:21:14,370 It was like all the routers were rebooting, and we started thinking about this and what it could be. 175 00:21:14,770 --> 00: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. 176 00:21:25,970 --> 00:21:31,750 And this matches with our two vulnerabilities that we showed to you today. 177 00:21:32,450 --> 00:21:38,320 So, we started thinking that possibly it could be our vulnerabilities. 178 00:21:39,270 --> 00: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. 179 00:21:50,250 --> 00:21:54,810 If it is not correct, the router is going to crash and it's going to reboot. 180 00:21:55,150 --> 00:21:59,950 But these offsets vary with the firmware version and the router model. 181 00:21:59,950 --> 00:22:06,850 So, maybe the reboots are caused by the failed exploitation attempts. 182 00:22:07,350 --> 00:22:14,890 And if there was failure exploitation attempts, there also could be successes on exploitation. 183 00:22:14,890 --> 00:22:18,810 But the successes are silent, so we don't know about it. 184 00:22:19,170 --> 00:22:21,430 So, we start investigating. 185 00:22:21,430 --> 00:22:27,670 We set up four honeypots in different countries where the routers are more popular. 186 00:22:27,670 --> 00:22:31,790 We use one physical router and we emulate three others. 187 00:22:32,090 --> 00:22:37,830 But we couldn't detect any reboots, neither exploitation attempts. 188 00:22:37,830 --> 00: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. 189 00:22:48,930 --> 00:22:51,770 So, Octavio is going to continue with some conclusions. 190 00:22:54,030 --> 00:23:01,390 Well, some of these bugs, the first ones, were fixed by Tritec from August to October of last year. 191 00:23:01,630 --> 00:23:07,810 And the last two ones, Tritec was very, very quick to fix them, were fixed in November of 2024. 192 00:23:09,590 --> 00:23:13,190 So, we learned some lessons about this research. 193 00:23:13,190 --> 00:23:17,610 The first one is that bugs are like cockroaches, a phrase from Ivan Arce. 194 00:23:18,910 --> 00:23:24,990 The surface that the Forescout team started to look at had some bugs. 195 00:23:24,990 --> 00:23:29,230 We looked at it, it had some more, and there are probably more bugs. 196 00:23:29,890 --> 00:23:37,350 And, well, from our research perspective, in our initial research, we focused on sink-to-source analysis. 197 00:23:37,390 --> 00:23:41,910 And this led us to a deep understanding of the inner workings of the router. 198 00:23:42,430 --> 00: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. 199 00:23:52,150 --> 00:23:55,270 And this router has a lot of surface. 200 00:23:55,270 --> 00:24:01,350 It has different VPN services and other things, so there will be more bugs here. 201 00:24:01,350 --> 00:24:05,130 And both strategies are complementary, we have learned that. 202 00:24:05,790 --> 00:24:11,070 And for users, always the same, update your firmware, do not expose unnecessary surface. 203 00:24:12,370 --> 00:24:18,110 So, there were vulnerabilities affecting these routers, and there will be more, we are sure of it. 204 00:24:19,050 --> 00: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. 205 00:24:31,490 --> 00: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. 206 00:24:42,790 --> 00:24:44,050 So, that's it. 207 00:24:44,050 --> 00:24:47,490 Thank you for your time, and if you have any questions, just ask.