Hi, hello everyone. Welcome to The Missing Link, Drytex's new RCEs complete the chain. I'm Gaston Asnares and my partner here is Octavio Giana-Tiempo. We are security researchers at Faraday. We mostly focus on firmware and embedded and low-level stuff. 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. 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. 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. Okay, so let's start with the introduction. Yes, it's not our first time with Drytex routers here in DEF CON. Last year we gave a talk about this, showing some vulnerabilities and focusing on detecting persistence and focusing on persistence on these routers. A quick recapitulation. We have a small business router with a MIPS32 CPU and running an RTOS. The name of the RTOS is DryOS. But Drytex also has medium‑sized enterprise routers that has an ARM CPU and they run Linux. 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. So, if we could find something in the small business routers, it should be also in the medium‑sized enterprise. Okay, let's talk about the attack surface. We found over 5,100 exposed devices, mostly in the UK. And we found previous vulnerabilities that affect these routers from information disclosure to remote code execution and our previous vulnerabilities. Okay, last year we released a tool for helping all the people to start reverse engineering and finding vulnerabilities on these routers. The name of this tool is Drytex Arsenal. You will find it in GitHub. And now it supports new firmware versions. Okay. Our previous vulnerabilities. We found a bunch of things. We found missing SSL certificate validation and non‑constant time password comparison that let us make a side channel attack. We found secure password storage, predictable two‑factor authentication and code generation. And the most important three are DHCP server reference that let us reboot and maybe make a service attack. And the last two allow us to upload arbitrary modules, kernel modules to the device. Okay. So, what we have now, we have to use a password reuse or a password default. And with the two‑factor authentication, we could authenticate. We have authenticated code execution and then we have kernel level persistence. But that's not enough. We wanted more. What we wanted is a pre‑authentication vulnerability to gain code execution and then have kernel level persistent. And in that way, we complete the chain from internet to the persistence. Okay. 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. And that was happened. So, what got our attention to come back to see that routers was dry break. A research presented by the people of Forescout and Black Hat Europe 2024. And the most important thing that got our attention was a buffer overflow in a function with the name of getCGI. So, we reverse engineered all the firmware, found interesting vulnerabilities, brought persistent malware, but we didn't look at the CGI request parser. And then we learned something about this. We learned that there is a new vulnerable pattern and a new attack surface. So, we come back and start again to see the firmware on this attack surface. And we found two more vulnerabilities. And now we can complete the chain from the internet to the persistence. Okay. Let's talk something about the new vulnerabilities and exploitation. The first vulnerability that we found was a buffer overflow in TR-69 STAN parsing. And it's really related to one CVE that Forescout released. That CVE from Forescout was a stack overflow when processing query string parameters on the getCGI function. So, what does the CGI function or how it works? Okay. So, first it's going to have two important arguments. The first one is a buffer. And the second one is a query string. So, it will receive that parameters and will parse the string to get the parameters on the heap. We will see that it has a loop to process each argument. As we know, the arguments of a query are separated by ampersand. So, makeWord is going to grab the current argument and will copy on the heap that. And then it's going to change the plus sign for spaces and escape the URL. And then it's going to look for the equal sign, because the argument has a key and a value. And in that side, it's going to change that equal sign for a new character. And then it's going to store the address of the key and the address of the value. We are going to see an example to understand it better. Okay. So, for example, we have on the top right a URL with the arguments. And we assume that cgiHandler is going to call this getCGI with a buffer in the stack. We can see that at the left, the caller stack and the getCGI stack. So, as we said, the first thing is going to be that it's going to store the first argument on the heap. And then it's going to clean it and find the equal sign and change it for a null pointer. So, we have two strings. 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. And it's going to do the same for each argument. But the important thing here is that it's not going to check the amount of parameters that it's going to parse. So, eventually, if we put in enough arguments, we are going to modify the return address of the stack, of the function. And then we will have a remote co-execution with the buffer overflow. Okay, that was how getCGI works. But this is the function that handles connections to the TR-69 stand. And we can see that it's really similar to getCGI. So, it has the same pattern, the same vulnerable pattern. At the vulnerabilities here, we think that the compiler has in line the getCGI function in this one. And for that, the force code group couldn't find it. Okay, so, we have to enable TR-69 stand. And the router is going to start listening on UDP port, that port. And all the packets received are going to be parsed by that function that we saw. In a really simple way, how TR-69 works, the router is going to send a bind request to the stand server. And the stand server is going to answer to the binding response. A funny fact that the router is listening on a non-default stone port. But we, as an attacker, could send data or queries to the router without having the binding request or binding response. The router is always listening. So, we made a proof of concept that crashed the router. And it can be converted to a remote code execution following the force code exploitation strategy. But we didn't go in that way because of the restrictions that this interface has. And we found a more interesting bug that now Octavio is going to show you. Hi. So, the second bug is an integer overflow in the CGA parsing function. Its relationship with the force code CVE is that it's located in the same getCGI function. And this function is very important because every CGI handler calls it. Every query you do to the router to a CGI endpoint ends up calling this function. So, we decided to take a better look at it. This function starts by checking the request method from the header of the request. And in this case, the part we are interested in, if it is a POST request. 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. Yes, the body of the request. So, all this is done using signed integers. 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. So, if we take a look at how the malloc works in this router, it also uses signed comparisons. So, if we send this number, then we will get our heap being allocated in the smallest cache. And this cache, it has only 24 bytes. So, now we transformed our integer overflow into a heap overflow. We can see here an example. 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. The object checksum, there was an error while checking the object checksum. And this is because this lab allocator that this router uses has some metadata in its objects. So, we are landing a cache with 24-byte objects, but these objects are really represented using 32 bytes. After the user data, there is the line that made the location, the time, and the offset. But there is also a checksum. And this is the metadata that we are correcting with our overrun. 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. And so, this internal structure is really a linked list. And what is stored is a pointer to the first free block on the list. So, how can we transform this into an arbitrary write? Suppose we get this first chunk, and now someone makes another allocation. We can start to write past our boundaries, and eventually we will end up overwriting a pointer to the next free chunk. So, if we made two more allocations, then the second one will be an arbitrary address that we can define. And we can arbitrarily write data at this direction. But the downside of this is that now we have a broken allocator. Luckily, this is not a problem for exploitation. So, how can we use this to execute code? Well, as Gaston said, these routers run MIPS. And in MIPS, all the exceptions trigger a jump to a general exception handler. 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. So, what we can do is use this arbitrary write to overwrite an exception handler pointer in this table to some place we control. Then, we have to trigger the exception to make the code flow jump there, and we will get an arbitrary code execution. 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. 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. 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. So, now a proof of concept of this. This is kind of quick, so I will pause it. So, now you see all this lab panics. 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. So, now we have to change this with all the previous vulnerabilities to make the full chain exploit. A recap of last year's talk. The persistence strategy was based on DLMs. DLMs are dynamically loadable modules. 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. They are updated independently from the firmware, and this is what makes them persistent, and are dynamically loaded every time the router boots. So, if you modify one of these kernel modules, when the router boots, it will load them first. They will have priority over the ones that are default that come with the firmware image, and it will prevent their loading. 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. So, these modules, though, are encrypted and are also compressed. We reverse-engineered both algorithms, and it turned out that the module recryption was using a modified version of the XDA algorithm. 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. 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. 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. 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. 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. 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. Then we will use the Nuldo reference to trigger this exception, and our shell code will execute. Now, with the new password that we have set, we can upload a malicious module and use it to access the router through SSH. So, here's the demo. First, we show that we cannot log in. Now we have successfully changed the password. We have uploaded our module, and now the router is rebooting. 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. 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. Okay, so, in March, we started receiving some news and some messages about some router devices that were rebooting itself without cause. It was like all the routers were rebooting, and we started thinking about this and what it could be. 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. And this matches with our two vulnerabilities that we showed to you today. So, we started thinking that possibly it could be our vulnerabilities. And we had an hypothesis, because successful exploitations depend on the landing address of the payload, and that has to be correct. If it is not correct, the router is going to crash and it's going to reboot. But these offsets vary with the firmware version and the router model. So, maybe the reboots are caused by the failed exploitation attempts. And if there was failure exploitation attempts, there also could be successes on exploitation. But the successes are silent, so we don't know about it. So, we start investigating. We set up four honeypots in different countries where the routers are more popular. We use one physical router and we emulate three others. But we couldn't detect any reboots, neither exploitation attempts. So, we think that we wouldn't know if we were late, or we need more honeypots, but the question remains open. So, Octavio is going to continue with some conclusions. Well, some of these bugs, the first ones, were fixed by Tritec from August to October of last year. And the last two ones, Tritec was very, very quick to fix them, were fixed in November of 2024. So, we learned some lessons about this research. The first one is that bugs are like cockroaches, a phrase from Ivan Arce. The surface that the Forescout team started to look at had some bugs. We looked at it, it had some more, and there are probably more bugs. And, well, from our research perspective, in our initial research, we focused on sink-to-source analysis. And this led us to a deep understanding of the inner workings of the router. 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. And this router has a lot of surface. It has different VPN services and other things, so there will be more bugs here. And both strategies are complementary, we have learned that. And for users, always the same, update your firmware, do not expose unnecessary surface. So, there were vulnerabilities affecting these routers, and there will be more, we are sure of it. 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. 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. So, that's it. Thank you for your time, and if you have any questions, just ask.