start	end	text
5060	11800	So, hi DEF CON. Thanks for having me here today. Also, many thanks for those who made it to
12120	18520	a Sunday 10 AM DEF CON talk. I really appreciate it. My name is Moritz Abra and I am super
18520	23960	excited to present my research, Unlocking the Gates, Hacking a Secure Industrial Remote
23960	31800	Access Gateway. In this session we will delve deep into an industrial remote access gateway,
31800	39260	uncover vulnerabilities and exploit them to affect critical infrastructure worldwide. But
39260	44600	first of all, a few words about myself. My name is Moritz Abra. I am working as a senior IT
44600	50240	security consultant and penetration tester at the German company SUS. So, I love breaking
50240	57000	stuff and I also regularly conduct security research and the results has been presented at
57000	64360	various security conferences such as Black Hat or DEF CON. So, how does an industrial remote
64360	70860	access solution work? Well, they all operate similarly. For instance, a device inside the
70860	77320	industrial network establishes a VPN connection to a VPN server. And this server is usually
77320	83660	operated by the vendor itself. Now, if a service technician wants to connect to this uh
83660	91420	industrial network, he uses vendor-provided software to initiate a VPN connection. Finally,
91420	97180	the VPN server routes between those connections and thus the technician is able to reach the
97180	104440	targeted infrastructure through the industrial router. So, to analyze such a solution, we need
104440	112480	to acquire an industrial remote access gateway. And I chose the EV1 Cozy Plus by HMS for
112480	120560	several reasons. Firstly, it is widely used and the vendor claims that over a half of a million
120560	127000	of devices are connected, meaning finding vulnerabilities could have a significant
127000	134440	impact. Furthermore, a similar device has already been considered in the past where some
134440	141740	problems were identified, resulting in a complete refactoring. So, the vendor claims that the
141740	148300	Cozy Plus is developed with a focus on security and this involves, for example, a hardware
148300	155700	security module with a route of trust, individual certificates, and secure boot. And the
155700	162640	solution was also tested and analyzed by an independent company and this company issued a
162640	168360	certificate available on the vendor's website stating that the hardware, backend, and
168360	177120	associated software were tested. So, let's take a closer look at this secure gateway. Here we
177120	184320	can see the hardware and here the disassembled view. And aside from the mentioned hardware
184320	191840	security module, nothing really special is going on on the PCB. But, due to the advanced
191840	197580	hardware security claims, I initially skipped the hardware analysis to avoid damaging
197580	205720	something. And since firmware update files are encrypted, we need a different approach. So, the
205720	212440	goal was to find vulnerabilities in the software or firmware using a pure black box approach.
213880	221220	Surprisingly, this was quite easy. The device allows uploading custom open VPN configuration
221220	229120	files and open VPN, on the other hand, allows custom com- executing custom commands using the
229120	237240	app parameter. So, I attempted to upload a custom VPN configuration with a command, but
237240	244380	unfortunately, the parameter was blacklisted. However, bypassing the filter was also
244380	252000	relatively easy. I added two dashes to the app parameter and this bypassed the blacklist
252420	258120	without breaking the parameter itself. And finally, the command executed with root
258120	266260	privileges. I then uploaded a new VPN configuration file including a reverse shell and
266260	273620	finally received this root shell. Nevertheless, this was only possible with administrative
273620	281320	access to the device. But, there is a way around this. I found a persistent cross-site
281320	288020	scripting vulnerability originating from FTP login attempts. This means, when an
288020	295920	administrative user visits the login page, the injected JavaScript executes. And to make
295920	302120	things more convenient, there is an insecure cookie containing the base 64 encoded
302120	308800	administrative password in plain text. At this point, I would also like to credit Khan
308800	315960	Ganeshin who reported probably this issue for a similar device to the vendor, uh, already in
315960	324120	2015. Anyway, combining these vulnerabilities creates the following exploit chain. An
324120	330180	attacker injects JavaScript code through an FTP login attempt. An administrator visits the
330180	337920	login page. The administrator's browser loads JavaScript from the attacker server. The
337920	343040	malicious JavaScript accesses and sends the plain text administrative password to the
343040	350360	attacker. The attacker then uploads a malicious open VPN configuration and the command
350360	361070	executes with root privileges. Alright, so let's see this in action. On the left side, we
361070	373310	can see the victim browser. And on the right side, the attacker executing the exploit. Now,
373310	383970	the victim visits the login page and the malicious JavaScript is executed. The attacker then
383970	396300	uploads the open VPN configuration and after a moment, finally receives a reverse shell. Now,
396320	405120	with root access to the device, I was able to analyze the firmware internals. And one of my
405120	411840	first interests was how encrypted passwords in configuration files are encrypted. For
411840	418520	example, are attackers able to decrypt sensitive data such as passwords or VPN certificates
418520	425800	found in configuration files? So, I grabbed the use prefix and found the responsible code in an
425800	433260	ARM binary. And due to the use of well-known open SSL functions, the encryption could be
433260	438240	quickly reverse engineered and the hard-coded key and IV could be found in the read-only
438240	445840	data section. So, by re-implementing the encryption algorithm with the found key and IV, we are
445840	454240	now able to decrypt encrypted passwords. Great, but now I was looking for the firmware update
454240	461300	encryption. Remember, firmware update files are encrypted. So, during this, I found
461300	467380	references to the use of the hardware security module. So, I decided to have a closer look to
467380	476160	this HSM, which is from the EdgeLog family by NXP. And in regard to the application node, I
476160	484220	analyzed the I2C communication passively. And in regard to the APDU specification, I
484750	495140	observed the APDU command structure indicating it isn't encrypted. But the payload is. Thus, we
495140	501560	cannot eavesdrop on the physical connection between the HSM and the SOC. So, I went back to
501560	507360	the device and further analyzed the encryption and finally was able to reconstruct it, which
507360	514220	can be summarized as follows. 4 bytes are read from an unencrypted flash memory, which was
514240	519460	encrypted. And each byte represents the length of data to be read in the next step. Then this
519460	525680	data is decrypted using the IMX6 cryptographic acceleration and assurance module.
526160	531600	Afterwards, session keys are derived from this data and used to encrypt the communication
531600	540100	using AES in CBC mode. And since I had a single device only, I do not know if the data stored
540100	547800	on the unencrypted flash is unique or device specific. Next, I attempted to access keys
547800	555100	directly from the rooted device using the block and trust middleware from NXP. So, I
555100	561720	developed a small proof of concept tool to access data on the HSM. However, the policies are
561720	569720	configured correctly and I was not able to access keys. Okay, so, we cannot eavesdrop on the
569720	577900	physical communication and we also cannot access data stored on the HSM. But, how does
577900	584020	the firmware encryption work? So, I further reverse engineered the update process, which can
584020	592760	be summarized as follows. A key type is read from the update file. Next, an encrypted key and
592760	602440	IV is read. The encrypted key is decrypted by the HSM and stored in a file. An encrypted
602440	609060	bash script is extracted from the update file and decrypts, uh, and decrypted using the
609060	615600	plain text key. And finally, the parser script extracts the different firmware parts and
615600	622740	decrypts it using the plain text key. So, in summary, each firmware version has its own
622760	630220	encryption key, but with access to a router device, we can decrypt the key and therefore leak
630220	637560	firmware specific encryption keys. So, as a proof of concept, I decrypted such a key using the
637560	643860	router device and used it to decrypt the firmware update, for example, the root file system.
645260	652240	Alright, so, we can decrypt configuration files using static keys and we can also decrypt
652240	658680	firmware updates using our router device and its hardware security module. So, now let's
658680	665560	move on to the last topic, the back-end communication. As expected, communication with
665560	672400	the vendor's API is encrypted and mutual authentication is enforced. So, if we want to
672400	678780	analyze the communication using a TLS proxy, our certificate needs to be trusted by the
678780	686680	Evon Cozy Plus and we also need the client certificate trusted by the back-end. So, placing
686680	692520	our own certificate in the hard-coded trust store is simple, but extracting the client
692520	699060	certificate turned out to be difficult. In fact, we also found the hard-coded path to the
699060	707060	client certificate and key, but while the public key looks good, something seems to be wrong with
707060	715120	the private key and it looks like it is filled up with null bytes. So, it turned out that this
715120	722800	is not the private key itself, instead it is a so-called reference key and the actual key is
722800	731920	securely stored at the HSM. So, extracting the key is not possible. But, I found a workaround.
732840	739800	We can use this OpenSSL configuration, which references a specific OpenSSL engine, to
739800	747640	implement the HSM for encryption. And now, by using this configuration, we can use OpenSSL
747640	756000	aware tools, like curl, on the device itself to communicate with the back-end. This also
756000	760840	means, without the device's private key, we cannot route the communication through a TLS
760840	767340	proxy. And therefore, I used the following alternative approach to analyze the back-end
767340	775800	communication. First, we intercept a request initiated by the device. Then we use curl on the
775800	784400	device to send this exact request and retrieve the response received on the device. Afterwards,
784400	789880	we can implement this response in our own web server and proceed with the next request or
789880	799860	stage. And, by doing so, I observed the following endpoints. And, especially this one was quite
799860	806340	interesting. In detail, the device generates a certificate signing request during account
806340	813320	assignment and sends it to the back-end. The vendor server then signs this request and the
813320	819720	signed certificate can then be requested by the device. Afterwards, the device has a
819720	826140	certificate signed by the vendor which contains the device's serial number. And this certificate
826140	831840	is then used for authentication against the VPN server and the serial number in the certificate
831840	840200	is used by the VPN server to assign it to a specific account or a client. Therefore, I ask
840200	846280	myself, can I get signed certificates for other devices by generating a certificate signing
846280	853340	request with a foreign serial number? And, to verify this, I reported my thoughts and
853340	859260	assumptions to the vendor and they gave me a serial number of a device located at the
859260	867180	vendor's lab. So, I generated a certificate signing request including this serial number and sent
867180	875320	it to the API using my routed device. And, indeed, the request was successful and I received a
875320	882520	certificate for the foreign serial number. Afterwards, I successfully used the certificate to
882520	889340	initiate a VPN session in the context of the device located at the vendor's lab. This, in
889340	896080	turn, had the following impacts. First of all, the VPN session of the original device was
896080	903100	overwritten and, therefore, no longer accessible. Next, if a user tries to connect to this
903100	910140	serial number or device, he gets forwarded to the attacker without noticing. And, due to the
910140	915560	missing network restrictions inside the VPN tunnel, the attacker is able to access all
915560	923700	services of the connected clients. So, let me illustrate this. An attacker can use a routed
923700	930520	E1COSI plus to get a correctly signed certificate for a foreign device. Then, he is able to
930520	935920	use the certificate for VPN authentication, which results in a loss of connection of the
935920	943360	original device. Now, if a user of this solution tries to connect to this device, he will be
943360	949860	forwarded to the attacker and, therefore, the attacker is able to attack the victim's client,
949860	956700	for example, accessing the client's remote desktop service. And, last but not least, the
956700	963140	attacker can imitate the original infrastructure to eavesdrop on sensitive data, for example,
963140	971840	authentication data, or if the victim uploads a secret program to a PLC. And, given that the
971840	978200	serial numbers are more or less enumeratable, this attack is scalable and we are able to
978200	986680	disconnect more than 500,000 devices. This means that energy plants, industrial facilities,
987220	993440	critical infrastructures, or oil platforms all around the world are no longer accessible and
993440	1003460	the users trying to connect to them could be attacked. So, let me conclude. We were able to
1003460	1010240	route the device and decrypt encrypted passwords. Afterwards, we used the routed device to get
1010240	1015420	firmware specific encryption keys and getting correctly signed certificates for other devices
1015420	1022060	used for VPN authentication. With these certificates, we were finally able to impact the
1022060	1027780	whole remote access solution, accessing devices of connected users, and eavesdrop on sensitive
1027780	1035220	data. Of course, we reported the vulnerabilities to the manufacturer who immediately patched
1035220	1042120	the backend, so getting certificates for other devices was no longer possible and a fixed
1042120	1050860	firmware version was also recently released. But, what can we learn from this? First of all, it
1050860	1056320	is important to consider the risks and increase the tech surface of remote access solutions,
1056320	1063140	especially with infrastructure operated in the cloud or by third parties. And, as
1063140	1069000	demonstrated in this talk, exploiting vulnerabilities in such solutions could impact many
1069000	1077200	facilities and maybe your infrastructure too. And, for the security researchers among us, some
1077200	1083200	of the vulnerabilities shown were found by gaining root access, meaning similar vulnerabilities
1083200	1090140	may exist in other solutions and waiting for you to be found. Sometimes, you just have to find
1090140	1096200	the right initial foothold. And, with that said, thanks for joining this talk. Connect with
1096200	1099920	me on X and feel free to check out the blog posts. Thanks.
