WEBVTT

00:05.060 --> 00:06.640
So, hi DEF CON.

00:06.640 --> 00:09.040
Thanks for having me here today.

00:09.060 --> 00:14.520
Also, many thanks for those who made it to a Sunday 10 AM DEF CON talk.

00:14.520 --> 00:16.120
I really appreciate it.

00:16.120 --> 00:25.200
My name is Moritz Abra and I am super excited to present my research, Unlocking the Gates, Hacking a Secure Industrial Remote Access Gateway.

00:25.820 --> 00:37.840
In this session we will delve deep into an industrial remote access gateway, uncover vulnerabilities and exploit them to affect critical infrastructure worldwide.

00:38.540 --> 00:41.460
But first of all, a few words about myself.

00:41.460 --> 00:42.880
My name is Moritz Abra.

00:42.880 --> 00:49.340
I am working as a senior IT security consultant and penetration tester at the German company SUS.

00:49.340 --> 01:01.320
So, I love breaking stuff and I also regularly conduct security research and the results has been presented at various security conferences such as Black Hat or DEF CON.

01:02.380 --> 01:05.980
So, how does an industrial remote access solution work?

01:05.980 --> 01:08.780
Well, they all operate similarly.

01:08.780 --> 01:15.720
For instance, a device inside the industrial network establishes a VPN connection to a VPN server.

01:15.800 --> 01:19.600
And this server is usually operated by the vendor itself.

01:20.180 --> 01:29.700
Now, if a service technician wants to connect to this uh industrial network, he uses vendor-provided software to initiate a VPN connection.

01:30.240 --> 01:40.780
Finally, the VPN server routes between those connections and thus the technician is able to reach the targeted infrastructure through the industrial router.

01:41.440 --> 01:47.640
So, to analyze such a solution, we need to acquire an industrial remote access gateway.

01:47.740 --> 01:54.520
And I chose the EV1 Cozy Plus by HMS for several reasons.

01:54.620 --> 02:08.260
Firstly, it is widely used and the vendor claims that over a half of a million of devices are connected, meaning finding vulnerabilities could have a significant impact.

02:09.400 --> 02:19.140
Furthermore, a similar device has already been considered in the past where some problems were identified, resulting in a complete refactoring.

02:19.980 --> 02:34.500
So, the vendor claims that the Cozy Plus is developed with a focus on security and this involves, for example, a hardware security module with a route of trust, individual certificates, and secure boot.

02:34.940 --> 02:50.980
And the solution was also tested and analyzed by an independent company and this company issued a certificate available on the vendor's website stating that the hardware, backend, and associated software were tested.

02:51.520 --> 02:55.500
So, let's take a closer look at this secure gateway.

02:56.280 --> 03:01.140
Here we can see the hardware and here the disassembled view.

03:01.740 --> 03:09.080
And aside from the mentioned hardware security module, nothing really special is going on on the PCB.

03:09.960 --> 03:18.700
But, due to the advanced hardware security claims, I initially skipped the hardware analysis to avoid damaging something.

03:19.040 --> 03:24.320
And since firmware update files are encrypted, we need a different approach.

03:24.540 --> 03:32.440
So, the goal was to find vulnerabilities in the software or firmware using a pure black box approach.

03:33.880 --> 03:37.000
Surprisingly, this was quite easy.

03:38.060 --> 03:50.440
The device allows uploading custom open VPN configuration files and open VPN, on the other hand, allows custom com- executing custom commands using the app parameter.

03:50.640 --> 04:00.880
So, I attempted to upload a custom VPN configuration with a command, but unfortunately, the parameter was blacklisted.

04:01.460 --> 04:06.140
However, bypassing the filter was also relatively easy.

04:06.340 --> 04:15.340
I added two dashes to the app parameter and this bypassed the blacklist without breaking the parameter itself.

04:15.540 --> 04:19.340
And finally, the command executed with root privileges.

04:20.400 --> 04:29.200
I then uploaded a new VPN configuration file including a reverse shell and finally received this root shell.

04:30.360 --> 04:35.680
Nevertheless, this was only possible with administrative access to the device.

04:36.120 --> 04:38.960
But, there is a way around this.

04:39.220 --> 04:46.140
I found a persistent cross-site scripting vulnerability originating from FTP login attempts.

04:46.480 --> 04:53.920
This means, when an administrative user visits the login page, the injected JavaScript executes.

04:54.500 --> 05:05.100
And to make things more convenient, there is an insecure cookie containing the base 64 encoded administrative password in plain text.

05:06.320 --> 05:17.440
At this point, I would also like to credit Khan Ganeshin who reported probably this issue for a similar device to the vendor, uh, already in 2015.

05:18.460 --> 05:23.540
Anyway, combining these vulnerabilities creates the following exploit chain.

05:23.940 --> 05:27.980
An attacker injects JavaScript code through an FTP login attempt.

05:28.460 --> 05:31.480
An administrator visits the login page.

05:31.900 --> 05:36.820
The administrator's browser loads JavaScript from the attacker server.

05:37.340 --> 05:44.060
The malicious JavaScript accesses and sends the plain text administrative password to the attacker.

05:44.500 --> 05:52.520
The attacker then uploads a malicious open VPN configuration and the command executes with root privileges.

05:53.400 --> 05:56.340
Alright, so let's see this in action.

05:59.670 --> 06:03.390
On the left side, we can see the victim browser.

06:04.750 --> 06:09.450
And on the right side, the attacker executing the exploit.

06:12.110 --> 06:20.350
Now, the victim visits the login page and the malicious JavaScript is executed.

06:22.750 --> 06:33.210
The attacker then uploads the open VPN configuration and after a moment, finally receives a reverse shell.

06:35.960 --> 06:43.020
Now, with root access to the device, I was able to analyze the firmware internals.

06:43.280 --> 06:51.040
And one of my first interests was how encrypted passwords in configuration files are encrypted.

06:51.380 --> 07:01.180
For example, are attackers able to decrypt sensitive data such as passwords or VPN certificates found in configuration files?

07:01.660 --> 07:06.960
So, I grabbed the use prefix and found the responsible code in an ARM binary.

07:07.640 --> 07:19.620
And due to the use of well-known open SSL functions, the encryption could be quickly reverse engineered and the hard-coded key and IV could be found in the read-only data section.

07:20.540 --> 07:28.900
So, by re-implementing the encryption algorithm with the found key and IV, we are now able to decrypt encrypted passwords.

07:30.200 --> 07:35.280
Great, but now I was looking for the firmware update encryption.

07:35.780 --> 07:38.980
Remember, firmware update files are encrypted.

07:39.720 --> 07:44.760
So, during this, I found references to the use of the hardware security module.

07:45.180 --> 07:51.980
So, I decided to have a closer look to this HSM, which is from the EdgeLog family by NXP.

07:52.620 --> 07:59.740
And in regard to the application node, I analyzed the I2C communication passively.

08:00.600 --> 08:10.460
And in regard to the APDU specification, I observed the APDU command structure indicating it isn't encrypted.

08:10.620 --> 08:13.140
But the payload is.

08:14.260 --> 08:19.500
Thus, we cannot eavesdrop on the physical connection between the HSM and the SOC.

08:20.400 --> 08:29.480
So, I went back to the device and further analyzed the encryption and finally was able to reconstruct it, which can be summarized as follows.

08:30.580 --> 08:34.660
4 bytes are read from an unencrypted flash memory, which was encrypted.

08:34.660 --> 08:38.000
And each byte represents the length of data to be read in the next step.

08:38.780 --> 08:45.680
Then this data is decrypted using the IMX6 cryptographic acceleration and assurance module.

08:46.160 --> 08:54.380
Afterwards, session keys are derived from this data and used to encrypt the communication using AES in CBC mode.

08:55.800 --> 09:04.160
And since I had a single device only, I do not know if the data stored on the unencrypted flash is unique or device specific.

09:05.540 --> 09:13.320
Next, I attempted to access keys directly from the rooted device using the block and trust middleware from NXP.

09:14.300 --> 09:19.420
So, I developed a small proof of concept tool to access data on the HSM.

09:20.100 --> 09:25.800
However, the policies are configured correctly and I was not able to access keys.

09:27.120 --> 09:35.740
Okay, so, we cannot eavesdrop on the physical communication and we also cannot access data stored on the HSM.

09:36.160 --> 09:39.760
But, how does the firmware encryption work?

09:40.340 --> 09:45.860
So, I further reverse engineered the update process, which can be summarized as follows.

09:46.660 --> 09:49.880
A key type is read from the update file.

09:50.620 --> 09:54.180
Next, an encrypted key and IV is read.

09:54.960 --> 10:00.500
The encrypted key is decrypted by the HSM and stored in a file.

10:01.740 --> 10:10.440
An encrypted bash script is extracted from the update file and decrypts, uh, and decrypted using the plain text key.

10:11.120 --> 10:18.520
And finally, the parser script extracts the different firmware parts and decrypts it using the plain text key.

10:20.020 --> 10:32.820
So, in summary, each firmware version has its own encryption key, but with access to a router device, we can decrypt the key and therefore leak firmware specific encryption keys.

10:33.320 --> 10:43.860
So, as a proof of concept, I decrypted such a key using the router device and used it to decrypt the firmware update, for example, the root file system.

10:45.260 --> 10:57.240
Alright, so, we can decrypt configuration files using static keys and we can also decrypt firmware updates using our router device and its hardware security module.

10:57.640 --> 11:02.500
So, now let's move on to the last topic, the back-end communication.

11:03.380 --> 11:10.600
As expected, communication with the vendor's API is encrypted and mutual authentication is enforced.

11:11.160 --> 11:24.660
So, if we want to analyze the communication using a TLS proxy, our certificate needs to be trusted by the Evon Cozy Plus and we also need the client certificate trusted by the back-end.

11:25.860 --> 11:35.160
So, placing our own certificate in the hard-coded trust store is simple, but extracting the client certificate turned out to be difficult.

11:35.840 --> 11:51.940
In fact, we also found the hard-coded path to the client certificate and key, but while the public key looks good, something seems to be wrong with the private key and it looks like it is filled up with null bytes.

11:53.260 --> 12:05.100
So, it turned out that this is not the private key itself, instead it is a so-called reference key and the actual key is securely stored at the HSM.

12:05.880 --> 12:08.540
So, extracting the key is not possible.

12:09.620 --> 12:11.920
But, I found a workaround.

12:12.840 --> 12:22.220
We can use this OpenSSL configuration, which references a specific OpenSSL engine, to implement the HSM for encryption.

12:23.100 --> 12:33.440
And now, by using this configuration, we can use OpenSSL aware tools, like curl, on the device itself to communicate with the back-end.

12:35.040 --> 12:41.980
This also means, without the device's private key, we cannot route the communication through a TLS proxy.

12:42.480 --> 12:48.600
And therefore, I used the following alternative approach to analyze the back-end communication.

12:49.100 --> 12:53.820
First, we intercept a request initiated by the device.

12:54.200 --> 13:02.320
Then we use curl on the device to send this exact request and retrieve the response received on the device.

13:03.380 --> 13:10.980
Afterwards, we can implement this response in our own web server and proceed with the next request or stage.

13:12.360 --> 13:16.700
And, by doing so, I observed the following endpoints.

13:17.040 --> 13:21.060
And, especially this one was quite interesting.

13:22.000 --> 13:29.180
In detail, the device generates a certificate signing request during account assignment and sends it to the back-end.

13:29.720 --> 13:36.660
The vendor server then signs this request and the signed certificate can then be requested by the device.

13:37.940 --> 13:44.480
Afterwards, the device has a certificate signed by the vendor which contains the device's serial number.

13:45.120 --> 13:57.500
And this certificate is then used for authentication against the VPN server and the serial number in the certificate is used by the VPN server to assign it to a specific account or a client.

13:58.800 --> 14:08.920
Therefore, I ask myself, can I get signed certificates for other devices by generating a certificate signing request with a foreign serial number?

14:09.800 --> 14:20.580
And, to verify this, I reported my thoughts and assumptions to the vendor and they gave me a serial number of a device located at the vendor's lab.

14:21.700 --> 14:30.340
So, I generated a certificate signing request including this serial number and sent it to the API using my routed device.

14:31.260 --> 14:37.840
And, indeed, the request was successful and I received a certificate for the foreign serial number.

14:39.440 --> 14:47.960
Afterwards, I successfully used the certificate to initiate a VPN session in the context of the device located at the vendor's lab.

14:48.820 --> 14:51.460
This, in turn, had the following impacts.

14:52.360 --> 14:59.280
First of all, the VPN session of the original device was overwritten and, therefore, no longer accessible.

15:00.440 --> 15:08.560
Next, if a user tries to connect to this serial number or device, he gets forwarded to the attacker without noticing.

15:09.400 --> 15:17.920
And, due to the missing network restrictions inside the VPN tunnel, the attacker is able to access all services of the connected clients.

15:19.140 --> 15:21.440
So, let me illustrate this.

15:21.900 --> 15:28.720
An attacker can use a routed E1COSI plus to get a correctly signed certificate for a foreign device.

15:29.440 --> 15:37.260
Then, he is able to use the certificate for VPN authentication, which results in a loss of connection of the original device.

15:38.420 --> 15:53.300
Now, if a user of this solution tries to connect to this device, he will be forwarded to the attacker and, therefore, the attacker is able to attack the victim's client, for example, accessing the client's remote desktop service.

15:54.620 --> 16:09.080
And, last but not least, the attacker can imitate the original infrastructure to eavesdrop on sensitive data, for example, authentication data, or if the victim uploads a secret program to a PLC.

16:10.720 --> 16:21.460
And, given that the serial numbers are more or less enumeratable, this attack is scalable and we are able to disconnect more than 500,000 devices.

16:23.500 --> 16:37.280
This means that energy plants, industrial facilities, critical infrastructures, or oil platforms all around the world are no longer accessible and the users trying to connect to them could be attacked.

16:38.540 --> 16:42.040
So, let me conclude.

16:42.320 --> 16:46.960
We were able to route the device and decrypt encrypted passwords.

16:47.420 --> 16:58.040
Afterwards, we used the routed device to get firmware specific encryption keys and getting correctly signed certificates for other devices used for VPN authentication.

16:58.820 --> 17:08.860
With these certificates, we were finally able to impact the whole remote access solution, accessing devices of connected users, and eavesdrop on sensitive data.

17:09.740 --> 17:25.100
Of course, we reported the vulnerabilities to the manufacturer who immediately patched the backend, so getting certificates for other devices was no longer possible and a fixed firmware version was also recently released.

17:25.960 --> 17:29.080
But, what can we learn from this?

17:29.420 --> 17:41.600
First of all, it is important to consider the risks and increase the tech surface of remote access solutions, especially with infrastructure operated in the cloud or by third parties.

17:42.440 --> 17:52.500
And, as demonstrated in this talk, exploiting vulnerabilities in such solutions could impact many facilities and maybe your infrastructure too.

17:53.180 --> 18:07.880
And, for the security researchers among us, some of the vulnerabilities shown were found by gaining root access, meaning similar vulnerabilities may exist in other solutions and waiting for you to be found.

18:08.220 --> 18:11.940
Sometimes, you just have to find the right initial foothold.

18:12.780 --> 18:15.800
And, with that said, thanks for joining this talk.

18:15.800 --> 18:19.280
Connect with me on X and feel free to check out the blog posts.

18:19.280 --> 18:19.920
Thanks.

