1 00:00:00,000 --> 00:00:01,580 Hi everyone. 2 00:00:01,580 --> 00:00:04,540 There are more people than I expected at 10am. 3 00:00:04,800 --> 00:00:07,280 Thank you very much for being here. 4 00:00:08,480 --> 00:00:12,580 You are the ones who survived until the last day in DEFCON. 5 00:00:12,720 --> 00:00:13,380 Awesome. 6 00:00:14,660 --> 00:00:22,800 Welcome to taking off the blindfold, detecting persistent threats on drytech edge devices. 7 00:00:23,600 --> 00:00:26,760 We are part of the Faraday research team. 8 00:00:26,760 --> 00:00:29,460 My partner here is Octavio Geno-Tiempo. 9 00:00:29,460 --> 00:00:31,120 I am Gaston Asnares. 10 00:00:31,380 --> 00:00:36,080 And we have some experience working with firmware. 11 00:00:36,080 --> 00:00:42,300 We have a foundation in computer science and we like to play CDF. 12 00:00:42,560 --> 00:00:46,860 As a resume, we like to break things and do research. 13 00:00:48,880 --> 00:00:51,540 So, what are we going to see today? 14 00:00:51,720 --> 00:00:55,900 First, we are going to see a motivation for this research and this talk. 15 00:00:56,260 --> 00:01:00,060 We are going to see some reverse engineering on drytech firmwares. 16 00:01:00,640 --> 00:01:04,940 We are going to talk about vulnerabilities and attack vectors. 17 00:01:05,560 --> 00:01:12,860 We are going to see mitigation strategies and at least we are going to see some conclusions and takeaways. 18 00:01:14,360 --> 00:01:17,280 Okay, how this started? 19 00:01:17,820 --> 00:01:22,100 We had a call of a client saying that it was compromised. 20 00:01:22,100 --> 00:01:32,160 And when we came to the scene, we saw a lot of outdated drytech equipment on the edge of the network. 21 00:01:32,160 --> 00:01:37,940 Most of them were SOHO models that run RTOS. 22 00:01:38,600 --> 00:01:40,980 And we started making some analysis. 23 00:01:40,980 --> 00:01:52,580 We found previous vulnerabilities with proven exploits on high-end models of the drytech routers that runs Linux. 24 00:01:53,120 --> 00:01:56,280 And we started making some questions about it. 25 00:01:56,280 --> 00:02:02,460 Like, are these vulnerabilities exploitable on the SOHO routers? 26 00:02:02,740 --> 00:02:06,020 There are other vulnerabilities that are known. 27 00:02:06,020 --> 00:02:10,940 And the principal question was, were these routers the entry point of the attackers? 28 00:02:12,620 --> 00:02:20,200 Okay, we know that there is an increasing threat of advanced attack targeting edge devices. 29 00:02:20,200 --> 00:02:27,440 We could name some examples, like the SOHO RAT, that was a socketical malware targeting SOHO routers. 30 00:02:27,620 --> 00:02:37,660 We also could name the HIATUS RAT, that was a malware targeting drytech routers, but the high-end models. 31 00:02:38,020 --> 00:02:51,060 And at least we could name Benin Sartain, that was an NSA tool targeting Cisco routers, that was leaked by the Shadow Brokers Group. 32 00:02:53,030 --> 00:02:58,620 Okay, so what is the attack surface of these routers? 33 00:02:58,620 --> 00:03:03,530 We found over 5,100 exposed devices. 34 00:03:04,540 --> 00:03:06,500 Mostly in the UK. 35 00:03:06,940 --> 00:03:09,300 And we found a lot of vulnerabilities. 36 00:03:09,300 --> 00:03:14,540 From an information disclosure to an authenticated remote code execution. 37 00:03:14,540 --> 00:03:16,780 So, there is a lot of stuff. 38 00:03:18,020 --> 00:03:27,500 Okay, so we had a Vigor 2925 in our office running MIPS 32 RTOS. 39 00:03:28,620 --> 00:03:34,640 And we wanted to start making some research on that, but we had a problem. 40 00:03:34,980 --> 00:03:37,240 The code is closed source. 41 00:03:37,860 --> 00:03:42,120 So, first we had to reverse engineer the firmware format. 42 00:03:42,360 --> 00:03:49,740 We had to extract the firmwares, understand previous vulnerabilities, and then look for new ones. 43 00:03:49,740 --> 00:03:54,120 And finally, determine if this was the attack vector or not. 44 00:03:57,710 --> 00:04:03,250 So, the first thing we did was trying to extract this firmware using MinWalk, but it failed. 45 00:04:03,250 --> 00:04:04,810 It produced no results. 46 00:04:04,830 --> 00:04:09,090 So, we tried to look for some specialized tools, and we found this one, DRYTOOLS. 47 00:04:09,150 --> 00:04:11,510 So, this didn't work with new firmwares. 48 00:04:11,510 --> 00:04:14,410 The last commit was 12 years ago, and that's why. 49 00:04:15,050 --> 00:04:28,390 So, luckily for us, we found a talk by Philippe Loret at Hexagon 2022, where he described that by emulating DRYTEXTBOOKLOADER, we can extract, we can make it extract the RTOS kernel. 50 00:04:28,390 --> 00:04:35,670 The disadvantage of this approach is that this is a manual process, and you have to tweak the addresses for each firmware version. 51 00:04:36,090 --> 00:04:47,710 And the other problem that it has is that these firmware images have other executable components, apart from the RTOS kernel, and file systems that you cannot extract this way. 52 00:04:48,570 --> 00:05:01,680 So, our approach was to reverse engineer the format, and to try to write a tool that can extract all firmware versions from different models, extracting all file systems, and extracting all the executable components. 53 00:05:03,150 --> 00:05:05,530 We named our tool DRYTEXT Arsenal. 54 00:05:05,530 --> 00:05:07,170 It's a collection of tools. 55 00:05:07,170 --> 00:05:09,350 We wrote this in Python. 56 00:05:09,350 --> 00:05:10,190 It's open source. 57 00:05:10,190 --> 00:05:13,270 You can check it out at that repository. 58 00:05:13,750 --> 00:05:18,250 And the idea is to support for all these new firmware versions. 59 00:05:18,650 --> 00:05:23,710 And we will be showing, along these presentations, all the features that we implemented. 60 00:05:25,590 --> 00:05:28,570 So, let's talk about the firmware format. 61 00:05:28,570 --> 00:05:30,950 It has two main sections. 62 00:05:30,950 --> 00:05:34,470 One is called the binary section, and the other one the web section. 63 00:05:34,510 --> 00:05:40,630 Both start with a header that contains the size and the pointer to the following section. 64 00:05:40,770 --> 00:05:46,410 But in the first one, we also have information about the firmware version, and some metadata. 65 00:05:47,210 --> 00:05:56,970 So, the web section has a file system that is compressed and contains all the static files that the router serves for the web UI. 66 00:05:57,690 --> 00:06:04,530 In the first section, the binary section, we have the bootloader that is raw MIPS32 code. 67 00:06:04,530 --> 00:06:06,850 This is the part that Philippe emulated. 68 00:06:07,370 --> 00:06:11,930 And then this is followed by the compressed RTOS kernel. 69 00:06:12,250 --> 00:06:16,930 And after that, we have a very interesting part of the firmware, that is the DLM code. 70 00:06:16,930 --> 00:06:20,990 This is also a file system, but it's compressed and encrypted. 71 00:06:21,370 --> 00:06:23,430 And we will talk a lot about it. 72 00:06:24,550 --> 00:06:31,690 So, to work with this, we made a specification of the structure of the firmware using KTI Structs. 73 00:06:31,690 --> 00:06:38,170 And the advantage of using this is that you can manipulate the firmware images with any language that you want from the list. 74 00:06:38,170 --> 00:06:42,570 We used Python, but you can find this in the repo and use the language that you prefer. 75 00:06:44,590 --> 00:06:50,650 And, well, by knowing all this, we started to tackle the reverse engineering of the compression algorithm. 76 00:06:51,150 --> 00:06:57,910 So, during boot, the RTOS is decompressed to the same memory space as the bootloader. 77 00:06:57,950 --> 00:07:02,750 And we did this following the steps described by Philippe in his talk. 78 00:07:02,890 --> 00:07:11,790 But when we started reverse engineering this, we mapped all this in memory, and then the RTOS after that. 79 00:07:11,850 --> 00:07:20,350 And that allowed us to discover that the decompression function is used during runtime to decompress other things, for example, the file systems. 80 00:07:20,830 --> 00:07:28,570 And we also discovered some interesting strings, like the one that you can see down to the right, that says LC4 decompression failed. 81 00:07:28,950 --> 00:07:34,470 But if it was LC4, the compression algorithm, why we couldn't work. 82 00:07:35,890 --> 00:07:48,350 And the reason for this is that while they use a standard LC4 compression block format, they have written a custom frame format. 83 00:07:48,670 --> 00:07:57,390 So, it's just a custom magic that is followed by a succession of block size and block data multiple times. 84 00:07:57,390 --> 00:08:08,010 So, we wrote a decompressor and a we moved on to the most interesting part, that is the DLM section. 85 00:08:08,570 --> 00:08:14,130 So, it turns out that the DLM stands for Dynamic Kernel Modules. 86 00:08:14,130 --> 00:08:22,090 So, this real-time operating system has the ability to load code modules during runtime dynamically. 87 00:08:22,250 --> 00:08:27,870 And this feature works independently from the firmware. 88 00:08:28,490 --> 00:08:36,830 So, during boot, we can see that some the modules that come with the firmware image are loaded. 89 00:08:36,830 --> 00:08:47,370 There are three modules, and they are called VR9 GeoIP, VR9 App-E, we will talk a lot about this one, and VR9 SSH. 90 00:08:47,370 --> 00:08:52,390 So, the first one contains information about the geolocation of IPs. 91 00:08:52,390 --> 00:08:58,510 The second one is used to block traffic from the users that are in the LAN. 92 00:08:58,790 --> 00:09:02,970 And the last one contains the implementation of SSH server. 93 00:09:02,970 --> 00:09:07,870 And this is really interesting because this implementation is separate from the firmware. 94 00:09:09,770 --> 00:09:27,130 So, these modules can be updated during runtime, and if you install a new version of App Enforcement Module or SSH, these are loaded first and prevent the modules that come with the firmware to be loaded. 95 00:09:27,230 --> 00:09:42,650 You can see down to the right that, for example, in this case, the VR9 App-E module was loaded first, and then when the router tries to load the version that comes in the firmware image, it will fail. 96 00:09:44,210 --> 00:09:56,290 So, doing some more reverse engineering, we found out that the modules are compressed using the same algorithm that is used for the RTOS, but they are also encrypted. 97 00:09:56,590 --> 00:10:05,390 So, we recognized that the algorithm used was a modified version of XTAA, and this is a symmetric encryption algorithm. 98 00:10:05,390 --> 00:10:09,950 And what this means is that the keys for decrypting these DLMs are present in the firmware. 99 00:10:10,050 --> 00:10:14,870 So, we looked for them, and we wrote a decryptor and encryptor for the modules. 100 00:10:14,890 --> 00:10:24,750 So, if you take a DLM, you decrypt it using this, and decompress it using the modified version of LC4, then what you get is a relocatable ELF. 101 00:10:25,010 --> 00:10:32,450 And this is very interesting because all the external functions that this ELF uses, they have to have their symbol names. 102 00:10:32,450 --> 00:10:34,850 So, they are really easy to reverse engineer. 103 00:10:37,030 --> 00:10:41,230 And this also means that the firmware must have an ELF loader. 104 00:10:41,230 --> 00:10:46,090 So, we looked for that code, and we found that there is also a symbol table. 105 00:10:46,090 --> 00:10:58,530 This symbol table was described before by Philippe Loret, but only as an aid for reverse engineering, because imagine that you have a table where you have function names followed by function pointers. 106 00:10:58,730 --> 00:11:06,170 But now we know that this table is actually used by the ELF loader to link these modules to the kernel. 107 00:11:07,010 --> 00:11:17,430 So, the advantage that this gives to us is that if we manage to write our own modules, we can use all these functions without knowing their actual addresses. 108 00:11:19,450 --> 00:11:24,490 So, we implemented all these in our tool. 109 00:11:24,490 --> 00:11:36,530 We have two functions, one called parse firmware that will print a lot of information about the firmware image, and the other one called extract that will extract all these pieces of the image. 110 00:11:36,530 --> 00:11:39,790 It will decrypt and decompress all the modules. 111 00:11:39,790 --> 00:11:51,890 It will extract all the file systems for the web server, and it will generate a binary image that contains the bootloader, followed by the RTOS kernel, but decompressed. 112 00:11:53,410 --> 00:11:58,910 So, if you want to start reverse engineering this, you must know the loading address. 113 00:11:59,210 --> 00:12:05,390 What we realized is that all dry type bootloaders start by calling the decompression function. 114 00:12:05,450 --> 00:12:24,590 So, this function is always located near the start of the image, and since all this has to be loaded aligned to the page, then we can search for the address of this compression function, and if we remove the last three numbers, what we get is the loading address of the whole image. 115 00:12:24,590 --> 00:12:27,890 So, with that, you can start your reverse engineering process. 116 00:12:28,990 --> 00:12:41,170 We also implemented this in a functionality called find loading address, and once we had all that, we moved on to try to find some vulnerabilities and attack vectors. 117 00:12:48,700 --> 00:12:52,900 Okay, so let's talk something about vulnerabilities. 118 00:12:52,900 --> 00:12:55,060 We are going to show some of them. 119 00:12:56,120 --> 00:13:02,040 Starting with the basics, we found that they had an insecure password storage. 120 00:13:02,040 --> 00:13:06,520 That means they stored the passwords and the credentials in plain text in memory. 121 00:13:07,070 --> 00:13:17,400 So, if someone had access to the memory, they could read the credentials or maybe chain another exploit to leak them. 122 00:13:17,940 --> 00:13:23,580 We also found a non-constant time comparison on the credential. 123 00:13:25,020 --> 00:13:38,880 So, they use a function that takes different amounts of time to compare different passwords, depending on how much correct characters are in the string. 124 00:13:39,380 --> 00:13:43,660 And that leads to a side attack channel, a timing attack. 125 00:13:45,640 --> 00:13:50,260 Okay, so, DirectX implements a second-step authentication. 126 00:13:50,260 --> 00:14:08,600 That's really nice, but that was predictable, because the code generation was done using a self-random function, but with the seed, they use the time elapsed science boot. 127 00:14:08,600 --> 00:14:17,760 So, if you know for how long the router is running, you could predict the second-factor authentication calls. 128 00:14:18,540 --> 00:14:32,500 We also found an older reference in the HCP server that leads to a denial-of-service attack, but the interesting thing about that is that it was exposed to one. 129 00:14:32,500 --> 00:14:38,940 So, if the router was exposed to the internet, you could trigger that another reference. 130 00:14:40,080 --> 00:14:58,000 And if we combine both vulnerabilities, we could predict the second-step authentication calls, because we could make the router crash, and then we know the time elapsed science boot, and we predict the calls. 131 00:14:58,780 --> 00:15:02,160 And that's what we are going to see in the next demo. 132 00:15:02,840 --> 00:15:06,520 We could see on the right, the serial communication with the router. 133 00:15:07,800 --> 00:15:11,320 Um, on the... no, that's on the left. 134 00:15:11,560 --> 00:15:14,320 On the right top is the script that we run. 135 00:15:14,540 --> 00:15:21,500 It triggers the known reference, and the router is rebooting. 136 00:15:22,180 --> 00:15:27,960 It will take like two or three reboots, because it crashed hard. 137 00:15:29,440 --> 00:15:37,200 And on the right bottom, we have the web UI, where we are going to try to log in. 138 00:15:40,460 --> 00:15:43,200 So, now it boots. 139 00:15:43,200 --> 00:15:47,780 We are going to wait until the router initializes itself. 140 00:15:49,180 --> 00:15:53,380 Okay, and now we are trying some different calls. 141 00:15:59,970 --> 00:16:04,750 And we were able to predict the call, and we are logged in. 142 00:16:08,390 --> 00:16:15,330 Okay, so Octavio talked something about the APP Enforcement Signature feature. 143 00:16:15,330 --> 00:16:16,790 It's really great. 144 00:16:16,790 --> 00:16:30,310 If you have an enterprise and you want to block your employees' web, or I don't know, you could update the signatures in order to block that traffic. 145 00:16:31,170 --> 00:16:36,130 And how this process is made, there are two ways. 146 00:16:36,130 --> 00:16:37,730 The first one is a manual. 147 00:16:37,730 --> 00:16:42,370 We will see on the right bottom that says import. 148 00:16:42,370 --> 00:16:47,970 If we click there, we could upload any file with some checks. 149 00:16:48,970 --> 00:17:05,510 And the second way is the automatic way, in which we have to select the update server or select the default one, and we have to schedule the updates. 150 00:17:05,510 --> 00:17:13,710 So, for example, every day at some point of the day, it will check if there is some update for the signatures. 151 00:17:16,170 --> 00:17:26,670 And how they implement these signatures, you could think in JSON formats or YAML or something like that. 152 00:17:26,710 --> 00:17:31,630 But Drytech has the idea to implement this as a module. 153 00:17:31,770 --> 00:17:38,430 So, to update the signatures, they upload an L file with code and everything. 154 00:17:41,540 --> 00:17:46,320 Okay, let's talk about some vulnerabilities related to the modules. 155 00:17:46,320 --> 00:17:59,120 The first one is they not also update certificates with code, but they don't check for certificates or have SSL enforcement. 156 00:17:59,120 --> 00:18:13,260 So, if someone manipulates the configuration of the router or the DNS, maybe DNS hijacking, they could upload a module to all the Drytech routers that has this feature. 157 00:18:14,160 --> 00:18:19,620 And we have found two post-authentication endpoints. 158 00:18:19,620 --> 00:18:23,240 The first one is the one that I told in the last slide. 159 00:18:23,500 --> 00:18:36,080 And the second one is that we found an endpoint to upload configurations files that doesn't have some checks, so they allow us to upload an arbitrary DLM. 160 00:18:36,100 --> 00:18:42,900 Now it's not only the APPA module, but we could upload any modules that we want. 161 00:18:43,260 --> 00:18:47,120 Maybe we could, I don't know, upload another SSH module. 162 00:18:49,440 --> 00:18:54,520 So, we have three ways for an attacker to install malicious modules. 163 00:18:54,520 --> 00:19:00,780 The first one is the post-authentication endpoints that we talked just in the last slide. 164 00:19:01,000 --> 00:19:07,180 We have the module upload process that is hijacking the configuration or the DNS. 165 00:19:07,260 --> 00:19:09,560 And the last one is the supply chain. 166 00:19:09,560 --> 00:19:28,880 Because the modules are very easy to craft, so if they are easily appended to to the firmware, and anyone with physical access or, I don't know, exploiting some vulnerability, they could upload the module before selling it. 167 00:19:31,910 --> 00:19:35,610 Okay, so knowing all of this, we could start making some modules. 168 00:19:35,610 --> 00:19:37,750 We implemented two commands. 169 00:19:37,750 --> 00:19:52,970 The first one is the MIPS compile that is going to make a compilation of source code into a ELF of the architecture of MIPS32. 170 00:19:53,790 --> 00:19:58,050 And we also have another command that is ELF to DLM. 171 00:19:58,050 --> 00:20:05,230 As the name says, it will convert an ELF to a DLM, compressing and encrypting with the provided keys. 172 00:20:05,550 --> 00:20:13,190 So, we could append some web headers so we could upload them through the web UI. 173 00:20:14,930 --> 00:20:17,670 So, we are going to see a demo. 174 00:20:17,670 --> 00:20:24,470 We could see on the left the version of the APPA module. 175 00:20:25,250 --> 00:20:34,850 On the right, in the middle, we are going to run a server, a custom server, that is pointing the configuration of the auto-updates. 176 00:20:42,430 --> 00:20:49,450 So, on the top right, we could see the serial interface with the router. 177 00:20:50,750 --> 00:20:57,890 Okay, so once the server is up, we are going to trigger a new DLM. 178 00:20:59,350 --> 00:21:00,150 So, it's triggered. 179 00:21:00,150 --> 00:21:05,390 We could see the router has fetched the new module in our server. 180 00:21:05,390 --> 00:21:08,190 We could see the Faraday logo because it's our module. 181 00:21:08,550 --> 00:21:19,670 And if we log in again, we could see that the version of the module has changed and we have some logs that said that it doesn't allow this shit. 182 00:21:24,730 --> 00:21:27,750 Okay, let's make something more funnier. 183 00:21:28,570 --> 00:21:31,430 We are going to make a SSH backdoor. 184 00:21:31,430 --> 00:21:32,430 Why not? 185 00:21:32,530 --> 00:21:35,330 Because we have the module. 186 00:21:35,330 --> 00:21:41,090 So, the original behavior of the SSH module is the top one. 187 00:21:41,130 --> 00:21:52,150 When we have a new connection, it's going to call the authentication function and the authentication function will say that it fails or it authenticates. 188 00:21:52,570 --> 00:22:05,790 But what we are going to do is when a new connection enters, when a new connection is open, that is going to call our hook and it's going to check our credentials. 189 00:22:06,570 --> 00:22:09,910 So, if they are right, it authenticates. 190 00:22:09,910 --> 00:22:16,830 If not, it's going to call the original function because we don't want to change all the behavior of the SSH module. 191 00:22:19,230 --> 00:22:21,030 How is the roadmap for this? 192 00:22:21,030 --> 00:22:27,430 First, we have to do a reverse engineer of the SSH module to find that function that makes the authentication. 193 00:22:27,690 --> 00:22:34,430 We are going to skip that part and we are going to say that the target function is the SSH account and LDAP auth function. 194 00:22:35,910 --> 00:22:39,810 After that, we have to write and compile the hook. 195 00:22:39,810 --> 00:22:50,590 We have to merge the hook with the original module and we have to modify all the relocations in the entry table. 196 00:22:51,590 --> 00:22:54,850 And last, we have to upload the DLM. 197 00:22:56,750 --> 00:23:09,190 On the right, we can see the source code of our hook function that takes the same arguments as the target function, an SSH instance, and a packet. 198 00:23:10,470 --> 00:23:13,870 And it will check for our credentials. 199 00:23:14,170 --> 00:23:18,370 If they are right, it will return one that says it authenticates. 200 00:23:18,370 --> 00:23:22,190 If not, it will call the target function. 201 00:23:24,330 --> 00:23:29,970 In order to compile this, we use our command MIPS compile. 202 00:23:32,510 --> 00:23:38,410 And then, we have to merge both binaries, both relocatable ELFs. 203 00:23:38,950 --> 00:23:41,610 So, there is a relocatable ELF. 204 00:23:41,610 --> 00:23:46,350 It has all the symbols with no fixed address. 205 00:23:46,350 --> 00:24:02,070 So, they had a relocation table that will say everything that uses a symbol has to be modified to point to that symbol after linking. 206 00:24:02,410 --> 00:24:04,870 So, we have all the symbols there. 207 00:24:04,870 --> 00:24:11,250 And once we merge it, we have the symbols of both modules. 208 00:24:11,370 --> 00:24:26,290 We wrote a command to do this with the name of MIPS merge that takes two ELF files and as an output has one file. 209 00:24:28,600 --> 00:24:28,980 Okay. 210 00:24:28,980 --> 00:24:32,920 Now, we have to modify the relocation table. 211 00:24:32,920 --> 00:24:40,060 So, first, we find all the relocation that talks about the target function. 212 00:24:40,060 --> 00:24:43,800 We can see on the top right the two examples. 213 00:24:43,960 --> 00:24:46,560 We are going to use the first one. 214 00:24:46,760 --> 00:25:05,940 If we print the code that is on that address on the bottom left, we can see that the jump is a jump instruction, but the jump instruction only has his opcode but doesn't have an address where to jump. 215 00:25:05,960 --> 00:25:12,700 That is because the relocation entry will set which one is going to be that address on link in time. 216 00:25:12,920 --> 00:25:15,940 And we can see there that is the target function. 217 00:25:15,940 --> 00:25:26,720 So, we modify that entry to give us a result the right that points to the hack function. 218 00:25:29,060 --> 00:25:31,080 So, time to hack. 219 00:25:31,080 --> 00:25:31,700 Yeah. 220 00:25:32,940 --> 00:25:33,700 Okay. 221 00:25:33,700 --> 00:25:41,220 So, on the top right, we have we are trying to log in with our credentials, but we could see that it fails. 222 00:25:41,380 --> 00:25:46,180 So, on the bottom left, we upload our backdoor module. 223 00:25:49,100 --> 00:25:57,600 And once it's uploaded, we could see that the file was written successfully, but we have to reboot the router. 224 00:26:00,890 --> 00:26:05,910 And once it reboots, we are going to try again with our credentials. 225 00:26:07,270 --> 00:26:09,650 We could see that the module was loaded. 226 00:26:17,440 --> 00:26:17,880 Okay. 227 00:26:17,880 --> 00:26:21,620 So, we tried to log in, and we could see that we were in. 228 00:26:21,760 --> 00:26:26,560 And we could see some loss in the serial communication. 229 00:26:33,980 --> 00:26:38,560 So, this attack that Gaston showed is really dangerous. 230 00:26:38,560 --> 00:26:48,420 Imagine that an attacker can craft a modified SSH module, upload it to your router, and you have no way of detecting this. 231 00:26:48,440 --> 00:26:53,320 Moreover, if you update the firmware, the module will be still there. 232 00:26:53,320 --> 00:26:54,540 It will persist. 233 00:26:54,540 --> 00:27:01,000 And even will persist if you reset the configuration of the router, because it's stored in a separate file system in the flash. 234 00:27:01,600 --> 00:27:05,440 So, we started to think about some mitigation strategies. 235 00:27:05,840 --> 00:27:14,640 The first one, the obvious that we thought about was just to remove the feature, because who wants to have dynamic modules on their router? 236 00:27:14,800 --> 00:27:19,020 But there might be some users that use this feature. 237 00:27:19,020 --> 00:27:30,820 So, well, instead of nubbing all the calls to module loading during boot and during the update process, we decided to think for a better solution. 238 00:27:31,360 --> 00:27:41,020 And we devised a mechanism for checking in-memory integrity of the other modules that are loaded. 239 00:27:41,020 --> 00:27:48,280 This mechanism should fetch signatures from a server, because the modules will get updates, so you have to update the signatures. 240 00:27:48,280 --> 00:27:52,760 But this time, you have to check the certificates. 241 00:27:52,900 --> 00:28:02,740 So, once you got those signatures, you have to find the loaded modules in memory, calculate the actual signatures, and compare them. 242 00:28:02,920 --> 00:28:10,960 And if there is a mismatch, then you have to notify the user somehow, and all this functionality should be included with the firmware. 243 00:28:12,060 --> 00:28:30,240 So, what we did, as a proof of concept, was to use the open source module to introduce this code to the router, because it's much easier to write a module than to patch the firmware, because you have all these functions from the symbol table that you can use. 244 00:28:30,800 --> 00:28:35,660 So, there are two things that we have to solve. 245 00:28:35,660 --> 00:28:46,380 The first one is how to calculate a signature for a valid DLM, and the second one is to find the actual DLMs in memory and do the comparison . 246 00:28:46,760 --> 00:28:52,100 So, we focused on that, and we accepted some limitations. 247 00:28:52,100 --> 00:28:57,620 We will not check the signatures every time a module is loaded, as it should be. 248 00:28:57,680 --> 00:29:04,960 We will only check signatures when our defensive module is loaded, and we will not try to notify users for now. 249 00:29:06,420 --> 00:29:12,340 So, the first problem that we have to solve is how to calculate a hash or a signature for a DLM. 250 00:29:12,340 --> 00:29:26,800 We will hash each signature with MD5, because MD5 was available on this table, on this symbol table, and we will hash only the static sections, because the dynamic sections will change once loaded. 251 00:29:27,080 --> 00:29:45,780 If the static section contains data, we will hash it right away, but if it contains code, then, as Gaston explained during the module installation, when it's linked, all the jams and the function calls will get the actual addresses of the functions written to them. 252 00:29:45,780 --> 00:29:52,040 So, we will hash only the opcodes for these sections, and the opcodes are the first six bits. 253 00:29:53,800 --> 00:29:59,060 So, once we got that, we have to find all the modules that are loaded. 254 00:29:59,380 --> 00:30:11,280 When the ELF loader installs a module, it creates an object to represent the module, and the space for this module is allocated using the linear allocator of the router. 255 00:30:11,620 --> 00:30:33,160 So, this allocator maintains a list of all the chunks that it has assigned, and if we manage to find this object that represents the DLM, we'll get the DLM name, a pointer to the text section of that module, and a pointer to the main section that will get executed after the module is loaded. 256 00:30:34,060 --> 00:30:42,960 So, the loader copies all the sections in a predefined order, one after the other, after the text section. 257 00:30:42,980 --> 00:30:49,880 This order is usually defined by the compiler, and we will assume that this order doesn't change. 258 00:30:50,560 --> 00:31:06,520 So, on the bottom, you can see a little bit of the code of this defensive module, the part where we traverse the list of chunks from this allocator, and we will check if each chunk corresponds to the module object. 259 00:31:06,520 --> 00:31:16,160 If the chunk corresponds to the module object, we will print some information, and if this module happens to be the SSH one, then we will calculate the hashes and compare them. 260 00:31:17,880 --> 00:31:19,580 So, here's the demonstration. 261 00:31:19,580 --> 00:31:25,680 This router is the one that has been backdoored and has a modified version of the SSH. 262 00:31:25,680 --> 00:31:44,060 Then we upload our defensive module using the UI on the left, and you can see right there that once it's uploaded, it will try to find all the modules, printing their information, and when it reaches the SSH module, it will start comparing the hashes for each section, 263 00:31:44,060 --> 00:31:49,600 and it will find that there is a mismatch between the hashes on the second section. 264 00:31:51,920 --> 00:31:55,940 So, to wrap this up, some conclusions and takeaways. 265 00:31:56,840 --> 00:32:18,600 All these vulnerabilities were found by us analyzing only the bigger 2925 router, but they are present in several models because all the SOHO routers use this real-time operating system, and even some of the higher-end routers that run Linux emulate the same real-time operating system. 266 00:32:18,960 --> 00:32:28,840 So, we found all these vulnerabilities and some more that we didn't show, and they are all patched by now, but we don't have CEIDs yet. 267 00:32:29,780 --> 00:32:33,480 And, well, some conclusions on the offensive side. 268 00:32:33,480 --> 00:32:41,500 The code for this real-time operating system is huge, it's really complex, and we only analyzed a little bit of it. 269 00:32:41,500 --> 00:32:53,180 Imagine that the functions that are present in the symbol table are maybe not up to five percent of all the functions in this firmware, so there are probably more vulnerabilities here to be found. 270 00:32:53,380 --> 00:33:02,480 And that is why we are open-sourcing our tool, and we would love for you to try it, and we would love to know if it's useful and if you find something. 271 00:33:02,640 --> 00:33:05,620 So, there's the repository if you want to check it out. 272 00:33:06,300 --> 00:33:09,420 And now, some conclusions on the defensive side. 273 00:33:09,820 --> 00:33:19,980 We show that it's possible to create a defensive module to check the integrity of other modules in memory, but in an ideal situation, this feature should be implemented by the vendor. 274 00:33:20,180 --> 00:33:36,020 It should fetch these updated signatures from a trusted server, verifying the certificates, and for all this to work, if this feature is included in the firmware, also we must have a secure blockchain to trust that this is working right. 275 00:33:37,300 --> 00:33:39,620 And to close, some takeaways. 276 00:33:39,740 --> 00:33:45,840 We think that closed-source firmware, as this example, is just another case of security by security. 277 00:33:46,360 --> 00:34:00,220 All these vulnerabilities that we have found are really simple, and they would have been reported sooner by the community if it were easier to reverse-engineer these routers. 278 00:34:00,320 --> 00:34:13,020 So, some things such as plaintext password storage, the use of insecure functions to compare sensitive data, predictable random number generation, and even the lack of SSL certificate validation. 279 00:34:13,200 --> 00:34:28,880 So, given all the increase in attacks that we are seeing to edge devices, it would be really important for vendors to include features that facilitate observability, vulnerability research by the community, and to implement threat detection solutions. 280 00:34:30,160 --> 00:34:31,740 So, this is it. 281 00:34:31,740 --> 00:34:36,960 Thank you for your time, first for coming so early, and if you have any questions, please ask us. 282 00:34:37,780 --> 00:34:40,380 There's a mic here, if you want to ask. 283 00:34:42,600 --> 00:34:44,940 The first question gets shared. 284 00:34:49,300 --> 00:34:50,860 Well, thank you, guys. 285 00:35:11,810 --> 00:35:17,030 Okay, the question was if there is memory protection between the modules and the RTOS, and there's not. 286 00:35:17,030 --> 00:35:23,430 All these runs on the same memory space, so from a module, you could modify the RTOS code and vice versa. 287 00:35:23,810 --> 00:35:24,330 Yeah. 288 00:35:34,920 --> 00:35:36,840 Well, thank you again for coming.