WEBVTT

00:00.000 --> 00:01.580
Hi everyone.

00:01.580 --> 00:04.540
There are more people than I expected at 10am.

00:04.800 --> 00:07.280
Thank you very much for being here.

00:08.480 --> 00:12.580
You are the ones who survived until the last day in DEFCON.

00:12.720 --> 00:13.380
Awesome.

00:14.660 --> 00:22.800
Welcome to taking off the blindfold, detecting persistent threats on drytech edge devices.

00:23.600 --> 00:26.760
We are part of the Faraday research team.

00:26.760 --> 00:29.460
My partner here is Octavio Geno-Tiempo.

00:29.460 --> 00:31.120
I am Gaston Asnares.

00:31.380 --> 00:36.080
And we have some experience working with firmware.

00:36.080 --> 00:42.300
We have a foundation in computer science and we like to play CDF.

00:42.560 --> 00:46.860
As a resume, we like to break things and do research.

00:48.880 --> 00:51.540
So, what are we going to see today?

00:51.720 --> 00:55.900
First, we are going to see a motivation for this research and this talk.

00:56.260 --> 01:00.060
We are going to see some reverse engineering on drytech firmwares.

01:00.640 --> 01:04.940
We are going to talk about vulnerabilities and attack vectors.

01:05.560 --> 01:12.860
We are going to see mitigation strategies and at least we are going to see some conclusions and takeaways.

01:14.360 --> 01:17.280
Okay, how this started?

01:17.820 --> 01:22.100
We had a call of a client saying that it was compromised.

01:22.100 --> 01:32.160
And when we came to the scene, we saw a lot of outdated drytech equipment on the edge of the network.

01:32.160 --> 01:37.940
Most of them were SOHO models that run RTOS.

01:38.600 --> 01:40.980
And we started making some analysis.

01:40.980 --> 01:52.580
We found previous vulnerabilities with proven exploits on high-end models of the drytech routers that runs Linux.

01:53.120 --> 01:56.280
And we started making some questions about it.

01:56.280 --> 02:02.460
Like, are these vulnerabilities exploitable on the SOHO routers?

02:02.740 --> 02:06.020
There are other vulnerabilities that are known.

02:06.020 --> 02:10.940
And the principal question was, were these routers the entry point of the attackers?

02:12.620 --> 02:20.200
Okay, we know that there is an increasing threat of advanced attack targeting edge devices.

02:20.200 --> 02:27.440
We could name some examples, like the SOHO RAT, that was a socketical malware targeting SOHO routers.

02:27.620 --> 02:37.660
We also could name the HIATUS RAT, that was a malware targeting drytech routers, but the high-end models.

02:38.020 --> 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.

02:53.030 --> 02:58.620
Okay, so what is the attack surface of these routers?

02:58.620 --> 03:03.530
We found over 5,100 exposed devices.

03:04.540 --> 03:06.500
Mostly in the UK.

03:06.940 --> 03:09.300
And we found a lot of vulnerabilities.

03:09.300 --> 03:14.540
From an information disclosure to an authenticated remote code execution.

03:14.540 --> 03:16.780
So, there is a lot of stuff.

03:18.020 --> 03:27.500
Okay, so we had a Vigor 2925 in our office running MIPS 32 RTOS.

03:28.620 --> 03:34.640
And we wanted to start making some research on that, but we had a problem.

03:34.980 --> 03:37.240
The code is closed source.

03:37.860 --> 03:42.120
So, first we had to reverse engineer the firmware format.

03:42.360 --> 03:49.740
We had to extract the firmwares, understand previous vulnerabilities, and then look for new ones.

03:49.740 --> 03:54.120
And finally, determine if this was the attack vector or not.

03:57.710 --> 04:03.250
So, the first thing we did was trying to extract this firmware using MinWalk, but it failed.

04:03.250 --> 04:04.810
It produced no results.

04:04.830 --> 04:09.090
So, we tried to look for some specialized tools, and we found this one, DRYTOOLS.

04:09.150 --> 04:11.510
So, this didn't work with new firmwares.

04:11.510 --> 04:14.410
The last commit was 12 years ago, and that's why.

04:15.050 --> 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.

04:28.390 --> 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.

04:36.090 --> 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.

04:48.570 --> 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.

05:03.150 --> 05:05.530
We named our tool DRYTEXT Arsenal.

05:05.530 --> 05:07.170
It's a collection of tools.

05:07.170 --> 05:09.350
We wrote this in Python.

05:09.350 --> 05:10.190
It's open source.

05:10.190 --> 05:13.270
You can check it out at that repository.

05:13.750 --> 05:18.250
And the idea is to support for all these new firmware versions.

05:18.650 --> 05:23.710
And we will be showing, along these presentations, all the features that we implemented.

05:25.590 --> 05:28.570
So, let's talk about the firmware format.

05:28.570 --> 05:30.950
It has two main sections.

05:30.950 --> 05:34.470
One is called the binary section, and the other one the web section.

05:34.510 --> 05:40.630
Both start with a header that contains the size and the pointer to the following section.

05:40.770 --> 05:46.410
But in the first one, we also have information about the firmware version, and some metadata.

05:47.210 --> 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.

05:57.690 --> 06:04.530
In the first section, the binary section, we have the bootloader that is raw MIPS32 code.

06:04.530 --> 06:06.850
This is the part that Philippe emulated.

06:07.370 --> 06:11.930
And then this is followed by the compressed RTOS kernel.

06:12.250 --> 06:16.930
And after that, we have a very interesting part of the firmware, that is the DLM code.

06:16.930 --> 06:20.990
This is also a file system, but it's compressed and encrypted.

06:21.370 --> 06:23.430
And we will talk a lot about it.

06:24.550 --> 06:31.690
So, to work with this, we made a specification of the structure of the firmware using KTI Structs.

06:31.690 --> 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.

06:38.170 --> 06:42.570
We used Python, but you can find this in the repo and use the language that you prefer.

06:44.590 --> 06:50.650
And, well, by knowing all this, we started to tackle the reverse engineering of the compression algorithm.

06:51.150 --> 06:57.910
So, during boot, the RTOS is decompressed to the same memory space as the bootloader.

06:57.950 --> 07:02.750
And we did this following the steps described by Philippe in his talk.

07:02.890 --> 07:11.790
But when we started reverse engineering this, we mapped all this in memory, and then the RTOS after that.

07:11.850 --> 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.

07:20.830 --> 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.

07:28.950 --> 07:34.470
But if it was LC4, the compression algorithm, why we couldn't work.

07:35.890 --> 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.

07:48.670 --> 07:57.390
So, it's just a custom magic that is followed by a succession of block size and block data multiple times.

07:57.390 --> 08:08.010
So, we wrote a decompressor and a we moved on to the most interesting part, that is the DLM section.

08:08.570 --> 08:14.130
So, it turns out that the DLM stands for Dynamic Kernel Modules.

08:14.130 --> 08:22.090
So, this real-time operating system has the ability to load code modules during runtime dynamically.

08:22.250 --> 08:27.870
And this feature works independently from the firmware.

08:28.490 --> 08:36.830
So, during boot, we can see that some the modules that come with the firmware image are loaded.

08:36.830 --> 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.

08:47.370 --> 08:52.390
So, the first one contains information about the geolocation of IPs.

08:52.390 --> 08:58.510
The second one is used to block traffic from the users that are in the LAN.

08:58.790 --> 09:02.970
And the last one contains the implementation of SSH server.

09:02.970 --> 09:07.870
And this is really interesting because this implementation is separate from the firmware.

09:09.770 --> 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.

09:27.230 --> 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.

09:44.210 --> 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.

09:56.590 --> 10:05.390
So, we recognized that the algorithm used was a modified version of XTAA, and this is a symmetric encryption algorithm.

10:05.390 --> 10:09.950
And what this means is that the keys for decrypting these DLMs are present in the firmware.

10:10.050 --> 10:14.870
So, we looked for them, and we wrote a decryptor and encryptor for the modules.

10:14.890 --> 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.

10:25.010 --> 10:32.450
And this is very interesting because all the external functions that this ELF uses, they have to have their symbol names.

10:32.450 --> 10:34.850
So, they are really easy to reverse engineer.

10:37.030 --> 10:41.230
And this also means that the firmware must have an ELF loader.

10:41.230 --> 10:46.090
So, we looked for that code, and we found that there is also a symbol table.

10:46.090 --> 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.

10:58.730 --> 11:06.170
But now we know that this table is actually used by the ELF loader to link these modules to the kernel.

11:07.010 --> 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.

11:19.450 --> 11:24.490
So, we implemented all these in our tool.

11:24.490 --> 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.

11:36.530 --> 11:39.790
It will decrypt and decompress all the modules.

11:39.790 --> 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.

11:53.410 --> 11:58.910
So, if you want to start reverse engineering this, you must know the loading address.

11:59.210 --> 12:05.390
What we realized is that all dry type bootloaders start by calling the decompression function.

12:05.450 --> 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.

12:24.590 --> 12:27.890
So, with that, you can start your reverse engineering process.

12:28.990 --> 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.

12:48.700 --> 12:52.900
Okay, so let's talk something about vulnerabilities.

12:52.900 --> 12:55.060
We are going to show some of them.

12:56.120 --> 13:02.040
Starting with the basics, we found that they had an insecure password storage.

13:02.040 --> 13:06.520
That means they stored the passwords and the credentials in plain text in memory.

13:07.070 --> 13:17.400
So, if someone had access to the memory, they could read the credentials or maybe chain another exploit to leak them.

13:17.940 --> 13:23.580
We also found a non-constant time comparison on the credential.

13:25.020 --> 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.

13:39.380 --> 13:43.660
And that leads to a side attack channel, a timing attack.

13:45.640 --> 13:50.260
Okay, so, DirectX implements a second-step authentication.

13:50.260 --> 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.

14:08.600 --> 14:17.760
So, if you know for how long the router is running, you could predict the second-factor authentication calls.

14:18.540 --> 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.

14:32.500 --> 14:38.940
So, if the router was exposed to the internet, you could trigger that another reference.

14:40.080 --> 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.

14:58.780 --> 15:02.160
And that's what we are going to see in the next demo.

15:02.840 --> 15:06.520
We could see on the right, the serial communication with the router.

15:07.800 --> 15:11.320
Um, on the... no, that's on the left.

15:11.560 --> 15:14.320
On the right top is the script that we run.

15:14.540 --> 15:21.500
It triggers the known reference, and the router is rebooting.

15:22.180 --> 15:27.960
It will take like two or three reboots, because it crashed hard.

15:29.440 --> 15:37.200
And on the right bottom, we have the web UI, where we are going to try to log in.

15:40.460 --> 15:43.200
So, now it boots.

15:43.200 --> 15:47.780
We are going to wait until the router initializes itself.

15:49.180 --> 15:53.380
Okay, and now we are trying some different calls.

15:59.970 --> 16:04.750
And we were able to predict the call, and we are logged in.

16:08.390 --> 16:15.330
Okay, so Octavio talked something about the APP Enforcement Signature feature.

16:15.330 --> 16:16.790
It's really great.

16:16.790 --> 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.

16:31.170 --> 16:36.130
And how this process is made, there are two ways.

16:36.130 --> 16:37.730
The first one is a manual.

16:37.730 --> 16:42.370
We will see on the right bottom that says import.

16:42.370 --> 16:47.970
If we click there, we could upload any file with some checks.

16:48.970 --> 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.

17:05.510 --> 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.

17:16.170 --> 17:26.670
And how they implement these signatures, you could think in JSON formats or YAML or something like that.

17:26.710 --> 17:31.630
But Drytech has the idea to implement this as a module.

17:31.770 --> 17:38.430
So, to update the signatures, they upload an L file with code and everything.

17:41.540 --> 17:46.320
Okay, let's talk about some vulnerabilities related to the modules.

17:46.320 --> 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.

17:59.120 --> 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.

18:14.160 --> 18:19.620
And we have found two post-authentication endpoints.

18:19.620 --> 18:23.240
The first one is the one that I told in the last slide.

18:23.500 --> 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.

18:36.100 --> 18:42.900
Now it's not only the APPA module, but we could upload any modules that we want.

18:43.260 --> 18:47.120
Maybe we could, I don't know, upload another SSH module.

18:49.440 --> 18:54.520
So, we have three ways for an attacker to install malicious modules.

18:54.520 --> 19:00.780
The first one is the post-authentication endpoints that we talked just in the last slide.

19:01.000 --> 19:07.180
We have the module upload process that is hijacking the configuration or the DNS.

19:07.260 --> 19:09.560
And the last one is the supply chain.

19:09.560 --> 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.

19:31.910 --> 19:35.610
Okay, so knowing all of this, we could start making some modules.

19:35.610 --> 19:37.750
We implemented two commands.

19:37.750 --> 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.

19:53.790 --> 19:58.050
And we also have another command that is ELF to DLM.

19:58.050 --> 20:05.230
As the name says, it will convert an ELF to a DLM, compressing and encrypting with the provided keys.

20:05.550 --> 20:13.190
So, we could append some web headers so we could upload them through the web UI.

20:14.930 --> 20:17.670
So, we are going to see a demo.

20:17.670 --> 20:24.470
We could see on the left the version of the APPA module.

20:25.250 --> 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.

20:42.430 --> 20:49.450
So, on the top right, we could see the serial interface with the router.

20:50.750 --> 20:57.890
Okay, so once the server is up, we are going to trigger a new DLM.

20:59.350 --> 21:00.150
So, it's triggered.

21:00.150 --> 21:05.390
We could see the router has fetched the new module in our server.

21:05.390 --> 21:08.190
We could see the Faraday logo because it's our module.

21:08.550 --> 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.

21:24.730 --> 21:27.750
Okay, let's make something more funnier.

21:28.570 --> 21:31.430
We are going to make a SSH backdoor.

21:31.430 --> 21:32.430
Why not?

21:32.530 --> 21:35.330
Because we have the module.

21:35.330 --> 21:41.090
So, the original behavior of the SSH module is the top one.

21:41.130 --> 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.

21:52.570 --> 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.

22:06.570 --> 22:09.910
So, if they are right, it authenticates.

22:09.910 --> 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.

22:19.230 --> 22:21.030
How is the roadmap for this?

22:21.030 --> 22:27.430
First, we have to do a reverse engineer of the SSH module to find that function that makes the authentication.

22:27.690 --> 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.

22:35.910 --> 22:39.810
After that, we have to write and compile the hook.

22:39.810 --> 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.

22:51.590 --> 22:54.850
And last, we have to upload the DLM.

22:56.750 --> 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.

23:10.470 --> 23:13.870
And it will check for our credentials.

23:14.170 --> 23:18.370
If they are right, it will return one that says it authenticates.

23:18.370 --> 23:22.190
If not, it will call the target function.

23:24.330 --> 23:29.970
In order to compile this, we use our command MIPS compile.

23:32.510 --> 23:38.410
And then, we have to merge both binaries, both relocatable ELFs.

23:38.950 --> 23:41.610
So, there is a relocatable ELF.

23:41.610 --> 23:46.350
It has all the symbols with no fixed address.

23:46.350 --> 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.

24:02.410 --> 24:04.870
So, we have all the symbols there.

24:04.870 --> 24:11.250
And once we merge it, we have the symbols of both modules.

24:11.370 --> 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.

24:28.600 --> 24:28.980
Okay.

24:28.980 --> 24:32.920
Now, we have to modify the relocation table.

24:32.920 --> 24:40.060
So, first, we find all the relocation that talks about the target function.

24:40.060 --> 24:43.800
We can see on the top right the two examples.

24:43.960 --> 24:46.560
We are going to use the first one.

24:46.760 --> 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.

25:05.960 --> 25:12.700
That is because the relocation entry will set which one is going to be that address on link in time.

25:12.920 --> 25:15.940
And we can see there that is the target function.

25:15.940 --> 25:26.720
So, we modify that entry to give us a result the right that points to the hack function.

25:29.060 --> 25:31.080
So, time to hack.

25:31.080 --> 25:31.700
Yeah.

25:32.940 --> 25:33.700
Okay.

25:33.700 --> 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.

25:41.380 --> 25:46.180
So, on the bottom left, we upload our backdoor module.

25:49.100 --> 25:57.600
And once it's uploaded, we could see that the file was written successfully, but we have to reboot the router.

26:00.890 --> 26:05.910
And once it reboots, we are going to try again with our credentials.

26:07.270 --> 26:09.650
We could see that the module was loaded.

26:17.440 --> 26:17.880
Okay.

26:17.880 --> 26:21.620
So, we tried to log in, and we could see that we were in.

26:21.760 --> 26:26.560
And we could see some loss in the serial communication.

26:33.980 --> 26:38.560
So, this attack that Gaston showed is really dangerous.

26:38.560 --> 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.

26:48.440 --> 26:53.320
Moreover, if you update the firmware, the module will be still there.

26:53.320 --> 26:54.540
It will persist.

26:54.540 --> 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.

27:01.600 --> 27:05.440
So, we started to think about some mitigation strategies.

27:05.840 --> 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?

27:14.800 --> 27:19.020
But there might be some users that use this feature.

27:19.020 --> 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.

27:31.360 --> 27:41.020
And we devised a mechanism for checking in-memory integrity of the other modules that are loaded.

27:41.020 --> 27:48.280
This mechanism should fetch signatures from a server, because the modules will get updates, so you have to update the signatures.

27:48.280 --> 27:52.760
But this time, you have to check the certificates.

27:52.900 --> 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.

28:02.920 --> 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.

28:12.060 --> 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.

28:30.800 --> 28:35.660
So, there are two things that we have to solve.

28:35.660 --> 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 .

28:46.760 --> 28:52.100
So, we focused on that, and we accepted some limitations.

28:52.100 --> 28:57.620
We will not check the signatures every time a module is loaded, as it should be.

28:57.680 --> 29:04.960
We will only check signatures when our defensive module is loaded, and we will not try to notify users for now.

29:06.420 --> 29:12.340
So, the first problem that we have to solve is how to calculate a hash or a signature for a DLM.

29:12.340 --> 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.

29:27.080 --> 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.

29:45.780 --> 29:52.040
So, we will hash only the opcodes for these sections, and the opcodes are the first six bits.

29:53.800 --> 29:59.060
So, once we got that, we have to find all the modules that are loaded.

29:59.380 --> 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.

30:11.620 --> 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.

30:34.060 --> 30:42.960
So, the loader copies all the sections in a predefined order, one after the other, after the text section.

30:42.980 --> 30:49.880
This order is usually defined by the compiler, and we will assume that this order doesn't change.

30:50.560 --> 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.

31:06.520 --> 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.

31:17.880 --> 31:19.580
So, here's the demonstration.

31:19.580 --> 31:25.680
This router is the one that has been backdoored and has a modified version of the SSH.

31:25.680 --> 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,

31:44.060 --> 31:49.600
and it will find that there is a mismatch between the hashes on the second section.

31:51.920 --> 31:55.940
So, to wrap this up, some conclusions and takeaways.

31:56.840 --> 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.

32:18.960 --> 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.

32:29.780 --> 32:33.480
And, well, some conclusions on the offensive side.

32:33.480 --> 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.

32:41.500 --> 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.

32:53.380 --> 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.

33:02.640 --> 33:05.620
So, there's the repository if you want to check it out.

33:06.300 --> 33:09.420
And now, some conclusions on the defensive side.

33:09.820 --> 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.

33:20.180 --> 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.

33:37.300 --> 33:39.620
And to close, some takeaways.

33:39.740 --> 33:45.840
We think that closed-source firmware, as this example, is just another case of security by security.

33:46.360 --> 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.

34:00.320 --> 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.

34:13.200 --> 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.

34:30.160 --> 34:31.740
So, this is it.

34:31.740 --> 34:36.960
Thank you for your time, first for coming so early, and if you have any questions, please ask us.

34:37.780 --> 34:40.380
There's a mic here, if you want to ask.

34:42.600 --> 34:44.940
The first question gets shared.

34:49.300 --> 34:50.860
Well, thank you, guys.

35:11.810 --> 35:17.030
Okay, the question was if there is memory protection between the modules and the RTOS, and there's not.

35:17.030 --> 35:23.430
All these runs on the same memory space, so from a module, you could modify the RTOS code and vice versa.

35:23.810 --> 35:24.330
Yeah.

35:34.920 --> 35:36.840
Well, thank you again for coming.

