[00:05.060 --> 00:11.800] So, hi DEF CON. Thanks for having me here today. Also, many thanks for those who made it to [00:12.120 --> 00:18.520] a Sunday 10 AM DEF CON talk. I really appreciate it. My name is Moritz Abra and I am super [00:18.520 --> 00:23.960] excited to present my research, Unlocking the Gates, Hacking a Secure Industrial Remote [00:23.960 --> 00:31.800] Access Gateway. In this session we will delve deep into an industrial remote access gateway, [00:31.800 --> 00:39.260] uncover vulnerabilities and exploit them to affect critical infrastructure worldwide. But [00:39.260 --> 00:44.600] first of all, a few words about myself. My name is Moritz Abra. I am working as a senior IT [00:44.600 --> 00:50.240] security consultant and penetration tester at the German company SUS. So, I love breaking [00:50.240 --> 00:57.000] stuff and I also regularly conduct security research and the results has been presented at [00:57.000 --> 01:04.360] various security conferences such as Black Hat or DEF CON. So, how does an industrial remote [01:04.360 --> 01:10.860] access solution work? Well, they all operate similarly. For instance, a device inside the [01:10.860 --> 01:17.320] industrial network establishes a VPN connection to a VPN server. And this server is usually [01:17.320 --> 01:23.660] operated by the vendor itself. Now, if a service technician wants to connect to this uh [01:23.660 --> 01:31.420] industrial network, he uses vendor-provided software to initiate a VPN connection. Finally, [01:31.420 --> 01:37.180] the VPN server routes between those connections and thus the technician is able to reach the [01:37.180 --> 01:44.440] targeted infrastructure through the industrial router. So, to analyze such a solution, we need [01:44.440 --> 01:52.480] to acquire an industrial remote access gateway. And I chose the EV1 Cozy Plus by HMS for [01:52.480 --> 02:00.560] several reasons. Firstly, it is widely used and the vendor claims that over a half of a million [02:00.560 --> 02:07.000] of devices are connected, meaning finding vulnerabilities could have a significant [02:07.000 --> 02:14.440] impact. Furthermore, a similar device has already been considered in the past where some [02:14.440 --> 02:21.740] problems were identified, resulting in a complete refactoring. So, the vendor claims that the [02:21.740 --> 02:28.300] Cozy Plus is developed with a focus on security and this involves, for example, a hardware [02:28.300 --> 02:35.700] security module with a route of trust, individual certificates, and secure boot. And the [02:35.700 --> 02:42.640] solution was also tested and analyzed by an independent company and this company issued a [02:42.640 --> 02:48.360] certificate available on the vendor's website stating that the hardware, backend, and [02:48.360 --> 02:57.120] associated software were tested. So, let's take a closer look at this secure gateway. Here we [02:57.120 --> 03:04.320] can see the hardware and here the disassembled view. And aside from the mentioned hardware [03:04.320 --> 03:11.840] security module, nothing really special is going on on the PCB. But, due to the advanced [03:11.840 --> 03:17.580] hardware security claims, I initially skipped the hardware analysis to avoid damaging [03:17.580 --> 03:25.720] something. And since firmware update files are encrypted, we need a different approach. So, the [03:25.720 --> 03:32.440] goal was to find vulnerabilities in the software or firmware using a pure black box approach. [03:33.880 --> 03:41.220] Surprisingly, this was quite easy. The device allows uploading custom open VPN configuration [03:41.220 --> 03:49.120] files and open VPN, on the other hand, allows custom com- executing custom commands using the [03:49.120 --> 03:57.240] app parameter. So, I attempted to upload a custom VPN configuration with a command, but [03:57.240 --> 04:04.380] unfortunately, the parameter was blacklisted. However, bypassing the filter was also [04:04.380 --> 04:12.000] relatively easy. I added two dashes to the app parameter and this bypassed the blacklist [04:12.420 --> 04:18.120] without breaking the parameter itself. And finally, the command executed with root [04:18.120 --> 04:26.260] privileges. I then uploaded a new VPN configuration file including a reverse shell and [04:26.260 --> 04:33.620] finally received this root shell. Nevertheless, this was only possible with administrative [04:33.620 --> 04:41.320] access to the device. But, there is a way around this. I found a persistent cross-site [04:41.320 --> 04:48.020] scripting vulnerability originating from FTP login attempts. This means, when an [04:48.020 --> 04:55.920] administrative user visits the login page, the injected JavaScript executes. And to make [04:55.920 --> 05:02.120] things more convenient, there is an insecure cookie containing the base 64 encoded [05:02.120 --> 05:08.800] administrative password in plain text. At this point, I would also like to credit Khan [05:08.800 --> 05:15.960] Ganeshin who reported probably this issue for a similar device to the vendor, uh, already in [05:15.960 --> 05:24.120] 2015. Anyway, combining these vulnerabilities creates the following exploit chain. An [05:24.120 --> 05:30.180] attacker injects JavaScript code through an FTP login attempt. An administrator visits the [05:30.180 --> 05:37.920] login page. The administrator's browser loads JavaScript from the attacker server. The [05:37.920 --> 05:43.040] malicious JavaScript accesses and sends the plain text administrative password to the [05:43.040 --> 05:50.360] attacker. The attacker then uploads a malicious open VPN configuration and the command [05:50.360 --> 06:01.070] executes with root privileges. Alright, so let's see this in action. On the left side, we [06:01.070 --> 06:13.310] can see the victim browser. And on the right side, the attacker executing the exploit. Now, [06:13.310 --> 06:23.970] the victim visits the login page and the malicious JavaScript is executed. The attacker then [06:23.970 --> 06:36.300] uploads the open VPN configuration and after a moment, finally receives a reverse shell. Now, [06:36.320 --> 06:45.120] with root access to the device, I was able to analyze the firmware internals. And one of my [06:45.120 --> 06:51.840] first interests was how encrypted passwords in configuration files are encrypted. For [06:51.840 --> 06:58.520] example, are attackers able to decrypt sensitive data such as passwords or VPN certificates [06:58.520 --> 07:05.800] found in configuration files? So, I grabbed the use prefix and found the responsible code in an [07:05.800 --> 07:13.260] ARM binary. And due to the use of well-known open SSL functions, the encryption could be [07:13.260 --> 07:18.240] quickly reverse engineered and the hard-coded key and IV could be found in the read-only [07:18.240 --> 07:25.840] data section. So, by re-implementing the encryption algorithm with the found key and IV, we are [07:25.840 --> 07:34.240] now able to decrypt encrypted passwords. Great, but now I was looking for the firmware update [07:34.240 --> 07:41.300] encryption. Remember, firmware update files are encrypted. So, during this, I found [07:41.300 --> 07:47.380] references to the use of the hardware security module. So, I decided to have a closer look to [07:47.380 --> 07:56.160] this HSM, which is from the EdgeLog family by NXP. And in regard to the application node, I [07:56.160 --> 08:04.220] analyzed the I2C communication passively. And in regard to the APDU specification, I [08:04.750 --> 08:15.140] observed the APDU command structure indicating it isn't encrypted. But the payload is. Thus, we [08:15.140 --> 08:21.560] cannot eavesdrop on the physical connection between the HSM and the SOC. So, I went back to [08:21.560 --> 08:27.360] the device and further analyzed the encryption and finally was able to reconstruct it, which [08:27.360 --> 08:34.220] can be summarized as follows. 4 bytes are read from an unencrypted flash memory, which was [08:34.240 --> 08:39.460] encrypted. And each byte represents the length of data to be read in the next step. Then this [08:39.460 --> 08:45.680] data is decrypted using the IMX6 cryptographic acceleration and assurance module. [08:46.160 --> 08:51.600] Afterwards, session keys are derived from this data and used to encrypt the communication [08:51.600 --> 09:00.100] using AES in CBC mode. And since I had a single device only, I do not know if the data stored [09:00.100 --> 09:07.800] on the unencrypted flash is unique or device specific. Next, I attempted to access keys [09:07.800 --> 09:15.100] directly from the rooted device using the block and trust middleware from NXP. So, I [09:15.100 --> 09:21.720] developed a small proof of concept tool to access data on the HSM. However, the policies are [09:21.720 --> 09:29.720] configured correctly and I was not able to access keys. Okay, so, we cannot eavesdrop on the [09:29.720 --> 09:37.900] physical communication and we also cannot access data stored on the HSM. But, how does [09:37.900 --> 09:44.020] the firmware encryption work? So, I further reverse engineered the update process, which can [09:44.020 --> 09:52.760] be summarized as follows. A key type is read from the update file. Next, an encrypted key and [09:52.760 --> 10:02.440] IV is read. The encrypted key is decrypted by the HSM and stored in a file. An encrypted [10:02.440 --> 10:09.060] bash script is extracted from the update file and decrypts, uh, and decrypted using the [10:09.060 --> 10:15.600] plain text key. And finally, the parser script extracts the different firmware parts and [10:15.600 --> 10:22.740] decrypts it using the plain text key. So, in summary, each firmware version has its own [10:22.760 --> 10:30.220] encryption key, but with access to a router device, we can decrypt the key and therefore leak [10:30.220 --> 10:37.560] firmware specific encryption keys. So, as a proof of concept, I decrypted such a key using the [10:37.560 --> 10:43.860] router device and used it to decrypt the firmware update, for example, the root file system. [10:45.260 --> 10:52.240] Alright, so, we can decrypt configuration files using static keys and we can also decrypt [10:52.240 --> 10:58.680] firmware updates using our router device and its hardware security module. So, now let's [10:58.680 --> 11:05.560] move on to the last topic, the back-end communication. As expected, communication with [11:05.560 --> 11:12.400] the vendor's API is encrypted and mutual authentication is enforced. So, if we want to [11:12.400 --> 11:18.780] analyze the communication using a TLS proxy, our certificate needs to be trusted by the [11:18.780 --> 11:26.680] Evon Cozy Plus and we also need the client certificate trusted by the back-end. So, placing [11:26.680 --> 11:32.520] our own certificate in the hard-coded trust store is simple, but extracting the client [11:32.520 --> 11:39.060] certificate turned out to be difficult. In fact, we also found the hard-coded path to the [11:39.060 --> 11:47.060] client certificate and key, but while the public key looks good, something seems to be wrong with [11:47.060 --> 11:55.120] the private key and it looks like it is filled up with null bytes. So, it turned out that this [11:55.120 --> 12:02.800] is not the private key itself, instead it is a so-called reference key and the actual key is [12:02.800 --> 12:11.920] securely stored at the HSM. So, extracting the key is not possible. But, I found a workaround. [12:12.840 --> 12:19.800] We can use this OpenSSL configuration, which references a specific OpenSSL engine, to [12:19.800 --> 12:27.640] implement the HSM for encryption. And now, by using this configuration, we can use OpenSSL [12:27.640 --> 12:36.000] aware tools, like curl, on the device itself to communicate with the back-end. This also [12:36.000 --> 12:40.840] means, without the device's private key, we cannot route the communication through a TLS [12:40.840 --> 12:47.340] proxy. And therefore, I used the following alternative approach to analyze the back-end [12:47.340 --> 12:55.800] communication. First, we intercept a request initiated by the device. Then we use curl on the [12:55.800 --> 13:04.400] device to send this exact request and retrieve the response received on the device. Afterwards, [13:04.400 --> 13:09.880] we can implement this response in our own web server and proceed with the next request or [13:09.880 --> 13:19.860] stage. And, by doing so, I observed the following endpoints. And, especially this one was quite [13:19.860 --> 13:26.340] interesting. In detail, the device generates a certificate signing request during account [13:26.340 --> 13:33.320] assignment and sends it to the back-end. The vendor server then signs this request and the [13:33.320 --> 13:39.720] signed certificate can then be requested by the device. Afterwards, the device has a [13:39.720 --> 13:46.140] certificate signed by the vendor which contains the device's serial number. And this certificate [13:46.140 --> 13:51.840] is then used for authentication against the VPN server and the serial number in the certificate [13:51.840 --> 14:00.200] is used by the VPN server to assign it to a specific account or a client. Therefore, I ask [14:00.200 --> 14:06.280] myself, can I get signed certificates for other devices by generating a certificate signing [14:06.280 --> 14:13.340] request with a foreign serial number? And, to verify this, I reported my thoughts and [14:13.340 --> 14:19.260] assumptions to the vendor and they gave me a serial number of a device located at the [14:19.260 --> 14:27.180] vendor's lab. So, I generated a certificate signing request including this serial number and sent [14:27.180 --> 14:35.320] it to the API using my routed device. And, indeed, the request was successful and I received a [14:35.320 --> 14:42.520] certificate for the foreign serial number. Afterwards, I successfully used the certificate to [14:42.520 --> 14:49.340] initiate a VPN session in the context of the device located at the vendor's lab. This, in [14:49.340 --> 14:56.080] turn, had the following impacts. First of all, the VPN session of the original device was [14:56.080 --> 15:03.100] overwritten and, therefore, no longer accessible. Next, if a user tries to connect to this [15:03.100 --> 15:10.140] serial number or device, he gets forwarded to the attacker without noticing. And, due to the [15:10.140 --> 15:15.560] missing network restrictions inside the VPN tunnel, the attacker is able to access all [15:15.560 --> 15:23.700] services of the connected clients. So, let me illustrate this. An attacker can use a routed [15:23.700 --> 15:30.520] E1COSI plus to get a correctly signed certificate for a foreign device. Then, he is able to [15:30.520 --> 15:35.920] use the certificate for VPN authentication, which results in a loss of connection of the [15:35.920 --> 15:43.360] original device. Now, if a user of this solution tries to connect to this device, he will be [15:43.360 --> 15:49.860] forwarded to the attacker and, therefore, the attacker is able to attack the victim's client, [15:49.860 --> 15:56.700] for example, accessing the client's remote desktop service. And, last but not least, the [15:56.700 --> 16:03.140] attacker can imitate the original infrastructure to eavesdrop on sensitive data, for example, [16:03.140 --> 16:11.840] authentication data, or if the victim uploads a secret program to a PLC. And, given that the [16:11.840 --> 16:18.200] serial numbers are more or less enumeratable, this attack is scalable and we are able to [16:18.200 --> 16:26.680] disconnect more than 500,000 devices. This means that energy plants, industrial facilities, [16:27.220 --> 16:33.440] critical infrastructures, or oil platforms all around the world are no longer accessible and [16:33.440 --> 16:43.460] the users trying to connect to them could be attacked. So, let me conclude. We were able to [16:43.460 --> 16:50.240] route the device and decrypt encrypted passwords. Afterwards, we used the routed device to get [16:50.240 --> 16:55.420] firmware specific encryption keys and getting correctly signed certificates for other devices [16:55.420 --> 17:02.060] used for VPN authentication. With these certificates, we were finally able to impact the [17:02.060 --> 17:07.780] whole remote access solution, accessing devices of connected users, and eavesdrop on sensitive [17:07.780 --> 17:15.220] data. Of course, we reported the vulnerabilities to the manufacturer who immediately patched [17:15.220 --> 17:22.120] the backend, so getting certificates for other devices was no longer possible and a fixed [17:22.120 --> 17:30.860] firmware version was also recently released. But, what can we learn from this? First of all, it [17:30.860 --> 17:36.320] is important to consider the risks and increase the tech surface of remote access solutions, [17:36.320 --> 17:43.140] especially with infrastructure operated in the cloud or by third parties. And, as [17:43.140 --> 17:49.000] demonstrated in this talk, exploiting vulnerabilities in such solutions could impact many [17:49.000 --> 17:57.200] facilities and maybe your infrastructure too. And, for the security researchers among us, some [17:57.200 --> 18:03.200] of the vulnerabilities shown were found by gaining root access, meaning similar vulnerabilities [18:03.200 --> 18:10.140] may exist in other solutions and waiting for you to be found. Sometimes, you just have to find [18:10.140 --> 18:16.200] the right initial foothold. And, with that said, thanks for joining this talk. Connect with [18:16.200 --> 18:19.920] me on X and feel free to check out the blog posts. Thanks.