So, hi DEF CON. Thanks for having me here today. Also, many thanks for those who made it to a Sunday 10 AM DEF CON talk. I really appreciate it. My name is Moritz Abra and I am super excited to present my research, Unlocking the Gates, Hacking a Secure Industrial Remote Access Gateway. In this session we will delve deep into an industrial remote access gateway, uncover vulnerabilities and exploit them to affect critical infrastructure worldwide. But first of all, a few words about myself. My name is Moritz Abra. I am working as a senior IT security consultant and penetration tester at the German company SUS. 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. So, how does an industrial remote access solution work? Well, they all operate similarly. For instance, a device inside the industrial network establishes a VPN connection to a VPN server. And this server is usually operated by the vendor itself. Now, if a service technician wants to connect to this uh industrial network, he uses vendor-provided software to initiate a VPN connection. Finally, the VPN server routes between those connections and thus the technician is able to reach the targeted infrastructure through the industrial router. So, to analyze such a solution, we need to acquire an industrial remote access gateway. And I chose the EV1 Cozy Plus by HMS for several reasons. 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. Furthermore, a similar device has already been considered in the past where some problems were identified, resulting in a complete refactoring. 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. 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. So, let's take a closer look at this secure gateway. Here we can see the hardware and here the disassembled view. And aside from the mentioned hardware security module, nothing really special is going on on the PCB. But, due to the advanced hardware security claims, I initially skipped the hardware analysis to avoid damaging something. And since firmware update files are encrypted, we need a different approach. So, the goal was to find vulnerabilities in the software or firmware using a pure black box approach. Surprisingly, this was quite easy. 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. So, I attempted to upload a custom VPN configuration with a command, but unfortunately, the parameter was blacklisted. However, bypassing the filter was also relatively easy. I added two dashes to the app parameter and this bypassed the blacklist without breaking the parameter itself. And finally, the command executed with root privileges. I then uploaded a new VPN configuration file including a reverse shell and finally received this root shell. Nevertheless, this was only possible with administrative access to the device. But, there is a way around this. I found a persistent cross-site scripting vulnerability originating from FTP login attempts. This means, when an administrative user visits the login page, the injected JavaScript executes. And to make things more convenient, there is an insecure cookie containing the base 64 encoded administrative password in plain text. 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. Anyway, combining these vulnerabilities creates the following exploit chain. An attacker injects JavaScript code through an FTP login attempt. An administrator visits the login page. The administrator's browser loads JavaScript from the attacker server. The malicious JavaScript accesses and sends the plain text administrative password to the attacker. The attacker then uploads a malicious open VPN configuration and the command executes with root privileges. Alright, so let's see this in action. On the left side, we can see the victim browser. And on the right side, the attacker executing the exploit. Now, the victim visits the login page and the malicious JavaScript is executed. The attacker then uploads the open VPN configuration and after a moment, finally receives a reverse shell. Now, with root access to the device, I was able to analyze the firmware internals. And one of my first interests was how encrypted passwords in configuration files are encrypted. For example, are attackers able to decrypt sensitive data such as passwords or VPN certificates found in configuration files? So, I grabbed the use prefix and found the responsible code in an ARM binary. 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. So, by re-implementing the encryption algorithm with the found key and IV, we are now able to decrypt encrypted passwords. Great, but now I was looking for the firmware update encryption. Remember, firmware update files are encrypted. So, during this, I found references to the use of the hardware security module. So, I decided to have a closer look to this HSM, which is from the EdgeLog family by NXP. And in regard to the application node, I analyzed the I2C communication passively. And in regard to the APDU specification, I observed the APDU command structure indicating it isn't encrypted. But the payload is. Thus, we cannot eavesdrop on the physical connection between the HSM and the SOC. 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. 4 bytes are read from an unencrypted flash memory, which was encrypted. And each byte represents the length of data to be read in the next step. Then this data is decrypted using the IMX6 cryptographic acceleration and assurance module. Afterwards, session keys are derived from this data and used to encrypt the communication using AES in CBC mode. 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. Next, I attempted to access keys directly from the rooted device using the block and trust middleware from NXP. So, I developed a small proof of concept tool to access data on the HSM. However, the policies are configured correctly and I was not able to access keys. Okay, so, we cannot eavesdrop on the physical communication and we also cannot access data stored on the HSM. But, how does the firmware encryption work? So, I further reverse engineered the update process, which can be summarized as follows. A key type is read from the update file. Next, an encrypted key and IV is read. The encrypted key is decrypted by the HSM and stored in a file. An encrypted bash script is extracted from the update file and decrypts, uh, and decrypted using the plain text key. And finally, the parser script extracts the different firmware parts and decrypts it using the plain text key. 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. 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. 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. So, now let's move on to the last topic, the back-end communication. As expected, communication with the vendor's API is encrypted and mutual authentication is enforced. 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. So, placing our own certificate in the hard-coded trust store is simple, but extracting the client certificate turned out to be difficult. 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. 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. So, extracting the key is not possible. But, I found a workaround. We can use this OpenSSL configuration, which references a specific OpenSSL engine, to implement the HSM for encryption. And now, by using this configuration, we can use OpenSSL aware tools, like curl, on the device itself to communicate with the back-end. This also means, without the device's private key, we cannot route the communication through a TLS proxy. And therefore, I used the following alternative approach to analyze the back-end communication. First, we intercept a request initiated by the device. Then we use curl on the device to send this exact request and retrieve the response received on the device. Afterwards, we can implement this response in our own web server and proceed with the next request or stage. And, by doing so, I observed the following endpoints. And, especially this one was quite interesting. In detail, the device generates a certificate signing request during account assignment and sends it to the back-end. The vendor server then signs this request and the signed certificate can then be requested by the device. Afterwards, the device has a certificate signed by the vendor which contains the device's serial number. 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. Therefore, I ask myself, can I get signed certificates for other devices by generating a certificate signing request with a foreign serial number? 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. So, I generated a certificate signing request including this serial number and sent it to the API using my routed device. And, indeed, the request was successful and I received a certificate for the foreign serial number. Afterwards, I successfully used the certificate to initiate a VPN session in the context of the device located at the vendor's lab. This, in turn, had the following impacts. First of all, the VPN session of the original device was overwritten and, therefore, no longer accessible. Next, if a user tries to connect to this serial number or device, he gets forwarded to the attacker without noticing. And, due to the missing network restrictions inside the VPN tunnel, the attacker is able to access all services of the connected clients. So, let me illustrate this. An attacker can use a routed E1COSI plus to get a correctly signed certificate for a foreign device. Then, he is able to use the certificate for VPN authentication, which results in a loss of connection of the original device. 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. 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. 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. 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. So, let me conclude. We were able to route the device and decrypt encrypted passwords. Afterwards, we used the routed device to get firmware specific encryption keys and getting correctly signed certificates for other devices used for VPN authentication. With these certificates, we were finally able to impact the whole remote access solution, accessing devices of connected users, and eavesdrop on sensitive data. 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. But, what can we learn from this? 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. And, as demonstrated in this talk, exploiting vulnerabilities in such solutions could impact many facilities and maybe your infrastructure too. 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. Sometimes, you just have to find the right initial foothold. And, with that said, thanks for joining this talk. Connect with me on X and feel free to check out the blog posts. Thanks.