1 00:00:05,060 --> 00:00:06,640 So, hi DEF CON. 2 00:00:06,640 --> 00:00:09,040 Thanks for having me here today. 3 00:00:09,060 --> 00:00:14,520 Also, many thanks for those who made it to a Sunday 10 AM DEF CON talk. 4 00:00:14,520 --> 00:00:16,120 I really appreciate it. 5 00:00:16,120 --> 00: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. 6 00:00:25,820 --> 00: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. 7 00:00:38,540 --> 00:00:41,460 But first of all, a few words about myself. 8 00:00:41,460 --> 00:00:42,880 My name is Moritz Abra. 9 00:00:42,880 --> 00:00:49,340 I am working as a senior IT security consultant and penetration tester at the German company SUS. 10 00:00:49,340 --> 00: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. 11 00:01:02,380 --> 00:01:05,980 So, how does an industrial remote access solution work? 12 00:01:05,980 --> 00:01:08,780 Well, they all operate similarly. 13 00:01:08,780 --> 00:01:15,720 For instance, a device inside the industrial network establishes a VPN connection to a VPN server. 14 00:01:15,800 --> 00:01:19,600 And this server is usually operated by the vendor itself. 15 00:01:20,180 --> 00: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. 16 00:01:30,240 --> 00: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. 17 00:01:41,440 --> 00:01:47,640 So, to analyze such a solution, we need to acquire an industrial remote access gateway. 18 00:01:47,740 --> 00:01:54,520 And I chose the EV1 Cozy Plus by HMS for several reasons. 19 00:01:54,620 --> 00: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. 20 00:02:09,400 --> 00:02:19,140 Furthermore, a similar device has already been considered in the past where some problems were identified, resulting in a complete refactoring. 21 00:02:19,980 --> 00: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. 22 00:02:34,940 --> 00: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. 23 00:02:51,520 --> 00:02:55,500 So, let's take a closer look at this secure gateway. 24 00:02:56,280 --> 00:03:01,140 Here we can see the hardware and here the disassembled view. 25 00:03:01,740 --> 00:03:09,080 And aside from the mentioned hardware security module, nothing really special is going on on the PCB. 26 00:03:09,960 --> 00:03:18,700 But, due to the advanced hardware security claims, I initially skipped the hardware analysis to avoid damaging something. 27 00:03:19,040 --> 00:03:24,320 And since firmware update files are encrypted, we need a different approach. 28 00:03:24,540 --> 00:03:32,440 So, the goal was to find vulnerabilities in the software or firmware using a pure black box approach. 29 00:03:33,880 --> 00:03:37,000 Surprisingly, this was quite easy. 30 00:03:38,060 --> 00: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. 31 00:03:50,640 --> 00:04:00,880 So, I attempted to upload a custom VPN configuration with a command, but unfortunately, the parameter was blacklisted. 32 00:04:01,460 --> 00:04:06,140 However, bypassing the filter was also relatively easy. 33 00:04:06,340 --> 00:04:15,340 I added two dashes to the app parameter and this bypassed the blacklist without breaking the parameter itself. 34 00:04:15,540 --> 00:04:19,340 And finally, the command executed with root privileges. 35 00:04:20,400 --> 00:04:29,200 I then uploaded a new VPN configuration file including a reverse shell and finally received this root shell. 36 00:04:30,360 --> 00:04:35,680 Nevertheless, this was only possible with administrative access to the device. 37 00:04:36,120 --> 00:04:38,960 But, there is a way around this. 38 00:04:39,220 --> 00:04:46,140 I found a persistent cross-site scripting vulnerability originating from FTP login attempts. 39 00:04:46,480 --> 00:04:53,920 This means, when an administrative user visits the login page, the injected JavaScript executes. 40 00:04:54,500 --> 00:05:05,100 And to make things more convenient, there is an insecure cookie containing the base 64 encoded administrative password in plain text. 41 00:05:06,320 --> 00: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. 42 00:05:18,460 --> 00:05:23,540 Anyway, combining these vulnerabilities creates the following exploit chain. 43 00:05:23,940 --> 00:05:27,980 An attacker injects JavaScript code through an FTP login attempt. 44 00:05:28,460 --> 00:05:31,480 An administrator visits the login page. 45 00:05:31,900 --> 00:05:36,820 The administrator's browser loads JavaScript from the attacker server. 46 00:05:37,340 --> 00:05:44,060 The malicious JavaScript accesses and sends the plain text administrative password to the attacker. 47 00:05:44,500 --> 00:05:52,520 The attacker then uploads a malicious open VPN configuration and the command executes with root privileges. 48 00:05:53,400 --> 00:05:56,340 Alright, so let's see this in action. 49 00:05:59,670 --> 00:06:03,390 On the left side, we can see the victim browser. 50 00:06:04,750 --> 00:06:09,450 And on the right side, the attacker executing the exploit. 51 00:06:12,110 --> 00:06:20,350 Now, the victim visits the login page and the malicious JavaScript is executed. 52 00:06:22,750 --> 00:06:33,210 The attacker then uploads the open VPN configuration and after a moment, finally receives a reverse shell. 53 00:06:35,960 --> 00:06:43,020 Now, with root access to the device, I was able to analyze the firmware internals. 54 00:06:43,280 --> 00:06:51,040 And one of my first interests was how encrypted passwords in configuration files are encrypted. 55 00:06:51,380 --> 00:07:01,180 For example, are attackers able to decrypt sensitive data such as passwords or VPN certificates found in configuration files? 56 00:07:01,660 --> 00:07:06,960 So, I grabbed the use prefix and found the responsible code in an ARM binary. 57 00:07:07,640 --> 00: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. 58 00:07:20,540 --> 00:07:28,900 So, by re-implementing the encryption algorithm with the found key and IV, we are now able to decrypt encrypted passwords. 59 00:07:30,200 --> 00:07:35,280 Great, but now I was looking for the firmware update encryption. 60 00:07:35,780 --> 00:07:38,980 Remember, firmware update files are encrypted. 61 00:07:39,720 --> 00:07:44,760 So, during this, I found references to the use of the hardware security module. 62 00:07:45,180 --> 00:07:51,980 So, I decided to have a closer look to this HSM, which is from the EdgeLog family by NXP. 63 00:07:52,620 --> 00:07:59,740 And in regard to the application node, I analyzed the I2C communication passively. 64 00:08:00,600 --> 00:08:10,460 And in regard to the APDU specification, I observed the APDU command structure indicating it isn't encrypted. 65 00:08:10,620 --> 00:08:13,140 But the payload is. 66 00:08:14,260 --> 00:08:19,500 Thus, we cannot eavesdrop on the physical connection between the HSM and the SOC. 67 00:08:20,400 --> 00: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. 68 00:08:30,580 --> 00:08:34,660 4 bytes are read from an unencrypted flash memory, which was encrypted. 69 00:08:34,660 --> 00:08:38,000 And each byte represents the length of data to be read in the next step. 70 00:08:38,780 --> 00:08:45,680 Then this data is decrypted using the IMX6 cryptographic acceleration and assurance module. 71 00:08:46,160 --> 00:08:54,380 Afterwards, session keys are derived from this data and used to encrypt the communication using AES in CBC mode. 72 00:08:55,800 --> 00: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. 73 00:09:05,540 --> 00:09:13,320 Next, I attempted to access keys directly from the rooted device using the block and trust middleware from NXP. 74 00:09:14,300 --> 00:09:19,420 So, I developed a small proof of concept tool to access data on the HSM. 75 00:09:20,100 --> 00:09:25,800 However, the policies are configured correctly and I was not able to access keys. 76 00:09:27,120 --> 00:09:35,740 Okay, so, we cannot eavesdrop on the physical communication and we also cannot access data stored on the HSM. 77 00:09:36,160 --> 00:09:39,760 But, how does the firmware encryption work? 78 00:09:40,340 --> 00:09:45,860 So, I further reverse engineered the update process, which can be summarized as follows. 79 00:09:46,660 --> 00:09:49,880 A key type is read from the update file. 80 00:09:50,620 --> 00:09:54,180 Next, an encrypted key and IV is read. 81 00:09:54,960 --> 00:10:00,500 The encrypted key is decrypted by the HSM and stored in a file. 82 00:10:01,740 --> 00:10:10,440 An encrypted bash script is extracted from the update file and decrypts, uh, and decrypted using the plain text key. 83 00:10:11,120 --> 00:10:18,520 And finally, the parser script extracts the different firmware parts and decrypts it using the plain text key. 84 00:10:20,020 --> 00: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. 85 00:10:33,320 --> 00: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. 86 00:10:45,260 --> 00: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. 87 00:10:57,640 --> 00:11:02,500 So, now let's move on to the last topic, the back-end communication. 88 00:11:03,380 --> 00:11:10,600 As expected, communication with the vendor's API is encrypted and mutual authentication is enforced. 89 00:11:11,160 --> 00: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. 90 00:11:25,860 --> 00: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. 91 00:11:35,840 --> 00: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. 92 00:11:53,260 --> 00: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. 93 00:12:05,880 --> 00:12:08,540 So, extracting the key is not possible. 94 00:12:09,620 --> 00:12:11,920 But, I found a workaround. 95 00:12:12,840 --> 00:12:22,220 We can use this OpenSSL configuration, which references a specific OpenSSL engine, to implement the HSM for encryption. 96 00:12:23,100 --> 00: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. 97 00:12:35,040 --> 00:12:41,980 This also means, without the device's private key, we cannot route the communication through a TLS proxy. 98 00:12:42,480 --> 00:12:48,600 And therefore, I used the following alternative approach to analyze the back-end communication. 99 00:12:49,100 --> 00:12:53,820 First, we intercept a request initiated by the device. 100 00:12:54,200 --> 00:13:02,320 Then we use curl on the device to send this exact request and retrieve the response received on the device. 101 00:13:03,380 --> 00:13:10,980 Afterwards, we can implement this response in our own web server and proceed with the next request or stage. 102 00:13:12,360 --> 00:13:16,700 And, by doing so, I observed the following endpoints. 103 00:13:17,040 --> 00:13:21,060 And, especially this one was quite interesting. 104 00:13:22,000 --> 00:13:29,180 In detail, the device generates a certificate signing request during account assignment and sends it to the back-end. 105 00:13:29,720 --> 00:13:36,660 The vendor server then signs this request and the signed certificate can then be requested by the device. 106 00:13:37,940 --> 00:13:44,480 Afterwards, the device has a certificate signed by the vendor which contains the device's serial number. 107 00:13:45,120 --> 00: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. 108 00:13:58,800 --> 00: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? 109 00:14:09,800 --> 00: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. 110 00:14:21,700 --> 00:14:30,340 So, I generated a certificate signing request including this serial number and sent it to the API using my routed device. 111 00:14:31,260 --> 00:14:37,840 And, indeed, the request was successful and I received a certificate for the foreign serial number. 112 00:14:39,440 --> 00: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. 113 00:14:48,820 --> 00:14:51,460 This, in turn, had the following impacts. 114 00:14:52,360 --> 00:14:59,280 First of all, the VPN session of the original device was overwritten and, therefore, no longer accessible. 115 00:15:00,440 --> 00:15:08,560 Next, if a user tries to connect to this serial number or device, he gets forwarded to the attacker without noticing. 116 00:15:09,400 --> 00: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. 117 00:15:19,140 --> 00:15:21,440 So, let me illustrate this. 118 00:15:21,900 --> 00:15:28,720 An attacker can use a routed E1COSI plus to get a correctly signed certificate for a foreign device. 119 00:15:29,440 --> 00: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. 120 00:15:38,420 --> 00: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. 121 00:15:54,620 --> 00: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. 122 00:16:10,720 --> 00: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. 123 00:16:23,500 --> 00: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. 124 00:16:38,540 --> 00:16:42,040 So, let me conclude. 125 00:16:42,320 --> 00:16:46,960 We were able to route the device and decrypt encrypted passwords. 126 00:16:47,420 --> 00: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. 127 00:16:58,820 --> 00: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. 128 00:17:09,740 --> 00: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. 129 00:17:25,960 --> 00:17:29,080 But, what can we learn from this? 130 00:17:29,420 --> 00: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. 131 00:17:42,440 --> 00:17:52,500 And, as demonstrated in this talk, exploiting vulnerabilities in such solutions could impact many facilities and maybe your infrastructure too. 132 00:17:53,180 --> 00: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. 133 00:18:08,220 --> 00:18:11,940 Sometimes, you just have to find the right initial foothold. 134 00:18:12,780 --> 00:18:15,800 And, with that said, thanks for joining this talk. 135 00:18:15,800 --> 00:18:19,280 Connect with me on X and feel free to check out the blog posts. 136 00:18:19,280 --> 00:18:19,920 Thanks.