start	end	text
0	2520	Hi, hello everyone.
3180	7580	Welcome to The Missing Link, Drytex's new RCEs complete the chain.
9020	13260	I'm Gaston Asnares and my partner here is Octavio Giana-Tiempo.
13260	16000	We are security researchers at Faraday.
16000	21440	We mostly focus on firmware and embedded and low-level stuff.
23820	32940	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.
33140	47080	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.
47440	59240	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.
62340	65200	Okay, so let's start with the introduction.
65860	70240	Yes, it's not our first time with Drytex routers here in DEF CON.
70240	81400	Last year we gave a talk about this, showing some vulnerabilities and focusing on detecting persistence and focusing on persistence on these routers.
83320	86040	A quick recapitulation.
86280	94840	We have a small business router with a MIPS32 CPU and running an RTOS.
94840	97820	The name of the RTOS is DryOS.
98200	108100	But Drytex also has medium‑sized enterprise routers that has an ARM CPU and they run Linux.
108100	118260	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.
118260	128380	So, if we could find something in the small business routers, it should be also in the medium‑sized enterprise.
129880	133840	Okay, let's talk about the attack surface.
133840	142420	We found over 5,100 exposed devices, mostly in the UK.
142540	152600	And we found previous vulnerabilities that affect these routers from information disclosure to remote code execution and our previous vulnerabilities.
155410	165130	Okay, last year we released a tool for helping all the people to start reverse engineering and finding vulnerabilities on these routers.
165130	167490	The name of this tool is Drytex Arsenal.
167490	170510	You will find it in GitHub.
170830	175090	And now it supports new firmware versions.
178290	179230	Okay.
179710	180970	Our previous vulnerabilities.
180970	183210	We found a bunch of things.
183610	192930	We found missing SSL certificate validation and non‑constant time password comparison that let us make a side channel attack.
192990	198670	We found secure password storage, predictable two‑factor authentication and code generation.
198730	210530	And the most important three are DHCP server reference that let us reboot and maybe make a service attack.
210710	219910	And the last two allow us to upload arbitrary modules, kernel modules to the device.
222610	223110	Okay.
223110	230610	So, what we have now, we have to use a password reuse or a password default.
230950	234150	And with the two‑factor authentication, we could authenticate.
234410	239790	We have authenticated code execution and then we have kernel level persistence.
240230	241830	But that's not enough.
241830	243570	We wanted more.
244890	253050	What we wanted is a pre‑authentication vulnerability to gain code execution and then have kernel level persistent.
253050	258090	And in that way, we complete the chain from internet to the persistence.
260670	261410	Okay.
261410	277710	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.
279270	280950	And that was happened.
281750	288630	So, what got our attention to come back to see that routers was dry break.
288630	294030	A research presented by the people of Forescout and Black Hat Europe 2024.
295110	302790	And the most important thing that got our attention was a buffer overflow in a function with the name of getCGI.
303890	313130	So, we reverse engineered all the firmware, found interesting vulnerabilities, brought persistent malware, but we didn't look at the CGI request parser.
315070	318570	And then we learned something about this.
318570	323970	We learned that there is a new vulnerable pattern and a new attack surface.
324110	330250	So, we come back and start again to see the firmware on this attack surface.
330330	333170	And we found two more vulnerabilities.
333310	337550	And now we can complete the chain from the internet to the persistence.
340420	340920	Okay.
340920	345860	Let's talk something about the new vulnerabilities and exploitation.
345880	353020	The first vulnerability that we found was a buffer overflow in TR-69 STAN parsing.
353020	359600	And it's really related to one CVE that Forescout released.
359600	368300	That CVE from Forescout was a stack overflow when processing query string parameters on the getCGI function.
369060	374820	So, what does the CGI function or how it works?
375120	375340	Okay.
375340	378640	So, first it's going to have two important arguments.
378640	381000	The first one is a buffer.
381000	382980	And the second one is a query string.
383620	393220	So, it will receive that parameters and will parse the string to get the parameters on the heap.
394000	399400	We will see that it has a loop to process each argument.
399440	405300	As we know, the arguments of a query are separated by ampersand.
405300	412980	So, makeWord is going to grab the current argument and will copy on the heap that.
413540	420160	And then it's going to change the plus sign for spaces and escape the URL.
420160	426760	And then it's going to look for the equal sign, because the argument has a key and a value.
427640	433480	And in that side, it's going to change that equal sign for a new character.
433880	440800	And then it's going to store the address of the key and the address of the value.
440820	444560	We are going to see an example to understand it better.
445300	445540	Okay.
445540	450740	So, for example, we have on the top right a URL with the arguments.
451000	460060	And we assume that cgiHandler is going to call this getCGI with a buffer in the stack.
460060	465580	We can see that at the left, the caller stack and the getCGI stack.
465680	473320	So, as we said, the first thing is going to be that it's going to store the first argument on the heap.
473840	480500	And then it's going to clean it and find the equal sign and change it for a null pointer.
480500	482160	So, we have two strings.
483280	492440	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.
493060	496300	And it's going to do the same for each argument.
496860	506480	But the important thing here is that it's not going to check the amount of parameters that it's going to parse.
506540	516420	So, eventually, if we put in enough arguments, we are going to modify the return address of the stack, of the function.
516780	521320	And then we will have a remote co-execution with the buffer overflow.
523240	527520	Okay, that was how getCGI works.
527800	536660	But this is the function that handles connections to the TR-69 stand.
537320	541100	And we can see that it's really similar to getCGI.
541100	545720	So, it has the same pattern, the same vulnerable pattern.
545720	553660	At the vulnerabilities here, we think that the compiler has in line the getCGI function in this one.
553980	560620	And for that, the force code group couldn't find it.
562340	566340	Okay, so, we have to enable TR-69 stand.
566340	571800	And the router is going to start listening on UDP port, that port.
571800	578160	And all the packets received are going to be parsed by that function that we saw.
579960	589920	In a really simple way, how TR-69 works, the router is going to send a bind request to the stand server.
589920	593840	And the stand server is going to answer to the binding response.
593840	599220	A funny fact that the router is listening on a non-default stone port.
601000	612100	But we, as an attacker, could send data or queries to the router without having the binding request or binding response.
612100	614840	The router is always listening.
616520	621320	So, we made a proof of concept that crashed the router.
621620	628220	And it can be converted to a remote code execution following the force code exploitation strategy.
628620	636700	But we didn't go in that way because of the restrictions that this interface has.
636700	642520	And we found a more interesting bug that now Octavio is going to show you.
645180	646100	Hi.
646100	651120	So, the second bug is an integer overflow in the CGA parsing function.
651120	657300	Its relationship with the force code CVE is that it's located in the same getCGI function.
657320	661940	And this function is very important because every CGI handler calls it.
662000	667380	Every query you do to the router to a CGI endpoint ends up calling this function.
667380	669860	So, we decided to take a better look at it.
671580	678060	This function starts by checking the request method from the header of the request.
678160	684080	And in this case, the part we are interested in, if it is a POST request.
684200	699840	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.
700000	701920	Yes, the body of the request.
702540	707420	So, all this is done using signed integers.
707420	722160	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.
722160	730220	So, if we take a look at how the malloc works in this router, it also uses signed comparisons.
730560	737400	So, if we send this number, then we will get our heap being allocated in the smallest cache.
737400	740840	And this cache, it has only 24 bytes.
741760	745980	So, now we transformed our integer overflow into a heap overflow.
747500	749480	We can see here an example.
749480	758400	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.
758400	762680	The object checksum, there was an error while checking the object checksum.
765120	771920	And this is because this lab allocator that this router uses has some metadata in its objects.
772240	781500	So, we are landing a cache with 24-byte objects, but these objects are really represented using 32 bytes.
781880	787420	After the user data, there is the line that made the location, the time, and the offset.
787420	789020	But there is also a checksum.
789020	793380	And this is the metadata that we are correcting with our overrun.
793920	804600	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.
805120	809200	And so, this internal structure is really a linked list.
810060	816100	And what is stored is a pointer to the first free block on the list.
816740	821260	So, how can we transform this into an arbitrary write?
821620	828280	Suppose we get this first chunk, and now someone makes another allocation.
828480	836620	We can start to write past our boundaries, and eventually we will end up overwriting a pointer to the next free chunk.
837460	845760	So, if we made two more allocations, then the second one will be an arbitrary address that we can define.
845780	849920	And we can arbitrarily write data at this direction.
849980	854860	But the downside of this is that now we have a broken allocator.
855560	858940	Luckily, this is not a problem for exploitation.
859740	862820	So, how can we use this to execute code?
863520	867240	Well, as Gaston said, these routers run MIPS.
867340	872160	And in MIPS, all the exceptions trigger a jump to a general exception handler.
872340	887760	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.
889420	898120	So, what we can do is use this arbitrary write to overwrite an exception handler pointer in this table to some place we control.
898460	905180	Then, we have to trigger the exception to make the code flow jump there, and we will get an arbitrary code execution.
907420	920360	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.
920400	932720	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.
932920	945220	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.
946920	949840	So, now a proof of concept of this.
954480	960420	This is kind of quick, so I will pause it.
962160	964460	So, now you see all this lab panics.
964460	976860	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.
985850	992350	So, now we have to change this with all the previous vulnerabilities to make the full chain exploit.
992910	996010	A recap of last year's talk.
996010	999030	The persistence strategy was based on DLMs.
999030	1001890	DLMs are dynamically loadable modules.
1001890	1011370	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.
1011980	1021570	They are updated independently from the firmware, and this is what makes them persistent, and are dynamically loaded every time the router boots.
1022510	1029390	So, if you modify one of these kernel modules, when the router boots, it will load them first.
1029390	1038130	They will have priority over the ones that are default that come with the firmware image, and it will prevent their loading.
1038550	1049250	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.
1051370	1056290	So, these modules, though, are encrypted and are also compressed.
1056290	1067230	We reverse-engineered both algorithms, and it turned out that the module recryption was using a modified version of the XDA algorithm.
1067650	1077450	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.
1077810	1085890	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.
1086190	1097110	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.
1097530	1108350	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.
1110570	1122330	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.
1122870	1136030	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.
1136430	1141830	Then we will use the Nuldo reference to trigger this exception, and our shell code will execute.
1141830	1149910	Now, with the new password that we have set, we can upload a malicious module and use it to access the router through SSH.
1157390	1159110	So, here's the demo.
1161750	1164170	First, we show that we cannot log in.
1170840	1173740	Now we have successfully changed the password.
1195020	1199500	We have uploaded our module, and now the router is rebooting.
1224070	1234410	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.
1239410	1247030	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.
1250310	1264790	Okay, so, in March, we started receiving some news and some messages about some router devices that were rebooting itself without cause.
1265750	1274370	It was like all the routers were rebooting, and we started thinking about this and what it could be.
1274770	1285730	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.
1285970	1291750	And this matches with our two vulnerabilities that we showed to you today.
1292450	1298320	So, we started thinking that possibly it could be our vulnerabilities.
1299270	1309570	And we had an hypothesis, because successful exploitations depend on the landing address of the payload, and that has to be correct.
1310250	1314810	If it is not correct, the router is going to crash and it's going to reboot.
1315150	1319950	But these offsets vary with the firmware version and the router model.
1319950	1326850	So, maybe the reboots are caused by the failed exploitation attempts.
1327350	1334890	And if there was failure exploitation attempts, there also could be successes on exploitation.
1334890	1338810	But the successes are silent, so we don't know about it.
1339170	1341430	So, we start investigating.
1341430	1347670	We set up four honeypots in different countries where the routers are more popular.
1347670	1351790	We use one physical router and we emulate three others.
1352090	1357830	But we couldn't detect any reboots, neither exploitation attempts.
1357830	1366790	So, we think that we wouldn't know if we were late, or we need more honeypots, but the question remains open.
1368930	1371770	So, Octavio is going to continue with some conclusions.
1374030	1381390	Well, some of these bugs, the first ones, were fixed by Tritec from August to October of last year.
1381630	1387810	And the last two ones, Tritec was very, very quick to fix them, were fixed in November of 2024.
1389590	1393190	So, we learned some lessons about this research.
1393190	1397610	The first one is that bugs are like cockroaches, a phrase from Ivan Arce.
1398910	1404990	The surface that the Forescout team started to look at had some bugs.
1404990	1409230	We looked at it, it had some more, and there are probably more bugs.
1409890	1417350	And, well, from our research perspective, in our initial research, we focused on sink-to-source analysis.
1417390	1421910	And this led us to a deep understanding of the inner workings of the router.
1422430	1432150	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.
1432150	1435270	And this router has a lot of surface.
1435270	1441350	It has different VPN services and other things, so there will be more bugs here.
1441350	1445130	And both strategies are complementary, we have learned that.
1445790	1451070	And for users, always the same, update your firmware, do not expose unnecessary surface.
1452370	1458110	So, there were vulnerabilities affecting these routers, and there will be more, we are sure of it.
1459050	1470750	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.
1471490	1480590	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.
1482790	1484050	So, that's it.
1484050	1487490	Thank you for your time, and if you have any questions, just ask.
