[00:00.000 --> 00:07.320] Welcome to my talk, No VPN Needed, Cryptographic Attacks Against the OPC UA Protocol. [00:07.840 --> 00:18.820] My name is Tom Tervoords, I work as a pen tester, general security consultant for Bureau Veritas Cyber Security, and I'm personally based in the Netherlands. [00:19.760 --> 00:39.960] When it comes to research projects, my specialization is kind of lies at the edge between offensive crypto research and pen testing, basically trying to achieve useful, well, pen testing results, pwning things, through practically exploitable crypto bugs. [00:40.840 --> 00:54.640] I got a lot of publicity after I happened to find a flaw in an obscure protocol used for Active Directory, which led to the zero logon vulnerability, and now I get to spend a lot of time on research projects such as this. [00:55.420 --> 01:10.740] So, during this talk, I'll first give a little bit of background on what OPC UA actually is, how the cryptography in this protocol works, and then I'll outline two vulnerabilities that I found, followed up with some conclusions. [01:11.700 --> 01:14.640] So, OPC UA. [01:14.760 --> 01:18.620] It's a protocol used for industrial automation. [01:18.620 --> 01:31.300] Think of things like PLCs, SCADA systems, basically computers that monitor or manage or change things in the real world, on real machines. [01:31.300 --> 01:37.540] Think of pipelines, solar parks, windmills, gas turbines, and so on. [01:37.660 --> 01:42.100] There's of course many protocols in this space. [01:42.100 --> 02:01.220] A lot of them are pretty old, based on old serial protocols, or they're proprietary, but OPC UA is a relatively new protocol, about 15 years old, and unlike a lot of others, it is standardized in an open standard, it has a lot of open source reference implementations, [02:01.220 --> 02:05.220] and it's interoperable through different vendors. [02:05.820 --> 02:12.400] But the aspect about it that I personally find most interesting is that it has security features. [02:13.130 --> 02:32.560] And it has features for authentication, it has features for transport encryption, and because of this, a lot of users of OPC UA applications and vendors, they point out that, hey, now that we've got these nice security features, we can actually use this OT protocol across our trust boundaries. [02:32.560 --> 02:39.740] Maybe even put a server on the internet, so we can more easily remotely manage things that are in the field. [02:39.860 --> 02:46.360] And because we already have cryptography, we already have security features, we don't need to tunnel it over a complicated VPN anymore. [02:46.360 --> 02:52.860] We can rely on these convenient security features that are already present. [02:53.160 --> 03:07.040] So that, of course, makes it an interesting research target for me, especially because they're not relying on an existing standard protocol like DLS, but they implemented their own cryptographic protocol, so I decided to take a look at how these security features work, [03:07.040 --> 03:09.820] and are there maybe any issues with it. [03:10.740 --> 03:16.300] So in general, OPC UA, it has kind of two different layers in the protocol. [03:16.300 --> 03:34.180] It has a communication layer or a secure channel layer, and that part is responsible for, well, doing the key exchange, to arrive at a symmetric key to encrypt subsequent messages with, and to authenticate the client and server device, to do basically the machine authentication parts. [03:34.180 --> 03:50.320] Then once you've established this secure channel, you've got keys, you can start encrypting your messages, then before you really do anything, you need to also do a handshake on the so-called session layer or the application layer, and that is mostly responsible for user authentication. [03:50.780 --> 03:57.240] And you can have different, you can start a new session on the same channel, and every channel needs to have a session. [03:57.760 --> 04:03.080] It's also optional which authentication features you actually want to use, or which encryption features you want to use. [04:03.080 --> 04:14.600] You can go for no encryption at all, you can go for only integrity protection, or also confidentiality protection, you can go for the machine authentication or user authentication, or both, or neither. [04:15.220 --> 04:31.920] And for the machine authentication parts, certificates are being used, and, well, the protocol allows for different types of trust models, but what most implementers do in practice is that a device connects to a server for the first time, their certificate gets rejected, [04:31.920 --> 04:41.980] then in a list the certificate will pop up as a rejected certificate, and the administrator can then choose to accept this certificate from then on. [04:41.980 --> 04:56.280] So it's kind of a bit of a pretty pragmatic trust-on-first-use model that makes it easy to configure or to set up these connections without too much pre-configuration, although you can also just preload certificates on all devices that are talking with each other. [04:56.980 --> 05:05.740] And all these different options, do we want to encrypt or not, do we want to authenticate or not, they're all being negotiated during these initial handshakes. [05:06.440 --> 05:19.700] So the first of these two security handshakes, the secure channel handshake, it consists of two messages, an open secure channel request and an open secure channel response. [05:19.960 --> 05:37.080] Both sides will generate a random number called a nonce, that will be different for every session, and then the clients, it will already know the certificates and configurations of the server in advance, because these are pre-configured or they are discovered through a mechanism that's kind of out of the scope of this talk. [05:37.180 --> 05:48.860] So the clients, they will use the certificates, take the public key from it and encrypt the message from the server and they will also sign it with their own private key and they will attach their own certificates that the server can then validate. [05:49.000 --> 05:59.940] If the server looks at the certificate, thinks it's fine, it will decrypt the message, verify the signature and then send its own response, also encrypted and signed. [06:00.340 --> 06:11.060] And then both sides, they have exchanged this random nonce and they plug it into a key derivation function and they will be able to get a symmetric session key that they will use for all the follow-up communication. [06:12.420 --> 06:18.220] Now part of this handshake is that the client will pick a so-called security policy that it knows that the server supports. [06:18.400 --> 06:21.720] And the security policy is basically, it's like a cipher suite in TLS. [06:21.720 --> 06:24.560] It decides what kind of crypto you're using. [06:24.640 --> 06:26.140] There's a variety of options. [06:26.140 --> 06:38.260] Most that are currently implemented in practice are either we don't want to use any cryptography at all or we use some variation of RSA and AES that are actually really pretty similar and mostly interchangeable. [06:39.700 --> 06:48.100] So once you've done this handshake, the second handshake will happen and all the messages in this handshake, they're all encrypted with a negotiated session key. [06:51.360 --> 06:55.580] And here once again, both sides generate a random number. [06:55.580 --> 06:57.260] The standard also calls this a nonce. [06:57.260 --> 07:00.620] I call this a challenge to make it easier to distinguish it. [07:00.860 --> 07:05.700] And they will put this challenge in the encrypted message. [07:06.440 --> 07:09.000] The client will send a challenge to the server. [07:09.000 --> 07:16.380] The server will sign this challenge with its private key, which is the exact same private key that was used in the previous step. [07:17.040 --> 07:19.300] And send the client its own challenge. [07:19.300 --> 07:22.280] The challenge will sign that challenge, send it back. [07:22.420 --> 07:27.740] This can be combined with user authentication and how the user authentication is used. [07:27.740 --> 07:33.660] That depends a little bit on what authentication method you pick, like passwords or tokens or something else. [07:33.660 --> 07:39.320] I'm actually not going to go too much into user authentication because that's not where the vulnerabilities were that I found. [07:40.320 --> 07:46.420] So yeah, you basically just got a pretty straightforward challenge response protocol. [07:46.500 --> 07:53.460] I give you a random number, you sign it to prove that you own a certain private key and to prove that you are who you say you are. [07:55.000 --> 08:08.500] Something that's, well, if your experience with cryptographic protocol design that you may notice is that it seems a little bit redundant, all these signatures, because in the previous step, we already were doing signing and encrypting, now we're signing again. [08:08.520 --> 08:15.160] Your, uh, both sides during the protocol are doing three different RSA private key operations, which are pretty expensive. [08:15.340 --> 08:21.520] While if you want to have an authenticated key exchange, you can design a protocol that really only does one RSA decryption. [08:21.840 --> 08:26.120] Uh, so, it's not really a great design in my opinion. [08:26.120 --> 08:32.420] Uh, on the other hand, you could argue, well, better to do three times as many, uh, uh, operations than, uh, none at all. [08:32.420 --> 08:36.480] Uh, maybe this will add some defense in depth or something, uh, uh, who knows. [08:36.480 --> 08:41.180] So, let's take a look at, uh, how, uh, well this protocol actually stacks up. [08:42.000 --> 08:57.440] So, what I, uh, noticed, uh, about these, uh, the signing of these challenges in this, uh, session handshake, uh, was that the type of message that's being signed, it's like the challenge of the other, uh, of the other party concatenated with the certificate of the other party. [08:57.640 --> 09:06.280] And regardless of whether it's the signature going from the client to the server or from the server to the client, the stuff that's being signed is formatted in exactly the same format. [09:06.280 --> 09:11.800] There's not like some meta data included that says this is a message intended from the client to the server or the other way around. [09:11.860 --> 09:14.260] They really look exactly the same. [09:14.600 --> 09:27.580] And that is something, when you see something like this, this may invite an opportunity for a so-called signing Oracle attack, where you pick one, uh, one message signed in one particular context, but actually plug it in in a different context. [09:28.560 --> 09:44.480] And then I started working out on paper like a theoretical attack, um, that I would call a signing Oracle relay attack, where let's say you have two different OPC servers, and server A and server B, and me as an attacker, I go to server A and I say, hello, [09:44.480 --> 09:47.980] I am actually server B, and you present a certificate of server B. [09:48.200 --> 09:50.440] Um, I would like to log in. [09:50.440 --> 09:56.080] Well, then the server A will say, okay , please prove that you're server B, here's my challenge, please sign it. [09:56.420 --> 10:05.640] Uh, then you go to start a session with server B, and you say, hello, I am server A, um, I have a challenge here, I want to log into you, please sign my challenge. [10:05.880 --> 10:10.080] So server B will sign the challenge , uh, as part of the first step of the protocol. [10:10.080 --> 10:16.660] So you've got this nice signature now , that is actually a signature over the challenge that's originally server A generated . [10:16.880 --> 10:25.500] So then you cut off the connection with server B, don't need it anymore, and then you actually plug in this signed challenge that you got from server B in the exchange with server A. [10:26.540 --> 10:37.820] And that should allow you to finish the whole, uh, authentication protocol, and now you've effectively bypassed authentication, you've tricked these two servers in logging into each other, but actually giving you access. [10:38.940 --> 10:53.140] Or even better, because it turns out in practice, many OPC implementations are set up in a way that servers by default trust their own certificates, so you can actually just log into server A while claiming to be server A, you're logging into the server as itself. [10:53.500 --> 11:05.880] And you just set up a second connection where you make the server sign its own challenge, drop that second connection again, resume the first connection, and then you've got an authentication bypass where you're logged into server A as server A, which usually has, [11:05.880 --> 11:07.280] uh, maximal privileges . [11:08.620 --> 11:16.080] Of course, this whole theoretical attack only really works on the second phase that I showed, this, uh, this session handshake. [11:16.080 --> 11:24.640] Before you can even make any encrypted messages in this session handshake, you first need to do this, uh, this whole secure channel, uh, handshake that also involves the private keys. [11:24.960 --> 11:31.160] So if our attack would make any sense in practice, we first need to somehow bypass this first step. [11:32.040 --> 11:38.460] And it turns out there's actually a very easy way to bypass this first step by looking at OPC UA protocol varieties. [11:39.000 --> 11:49.600] Uh, in most use cases, uh, OPC UA is used as a binary protocol directly layered over TCP, but there is a variance that's, uh, based on HTTPS. [11:49.980 --> 12:01.240] There, um, uh, basically all your OPC messages are wrapped in HTTP, uh, challenges and responses and you set up a standard, uh, server authenticated HTTPS, uh, connection. [12:01.780 --> 12:10.780] And because then the TLS layer will already offer a transport crypto, uh, the protocol designer says, okay, now we can skip this whole, uh, secure channel step. [12:10.780 --> 12:14.340] We can directly move into the session step because we already have encryption. [12:14.340 --> 12:16.380] We don't need to establish it ourselves anymore. [12:17.300 --> 12:20.280] Um, and then we go right to the vulnerable session handshake. [12:21.180 --> 12:33.460] And what's interesting about this is that when you do server authenticated HTTPS, well, it authenticates the server, but it doesn't authenticate the clients while their own custom handshake implicitly does authenticate the client. [12:33.460 --> 12:44.120] So they actually have kind of different properties and we can take advantage of that by, well, just simply skipping this, starting on HTTPS. [12:44.120 --> 12:47.800] I don't need to prove my identity to set up an HTTPS connection. [12:48.000 --> 12:51.000] And then I, uh, try to carry out this attack or this attack. [12:51.180 --> 12:55.420] So I wrote a tool that does exactly that and it turns out it totally works. [12:55.420 --> 13:01.100] Uh, you just point it at an HTTPS based OPC UA server that uses this client authentication feature. [13:01.180 --> 13:03.820] It's not going to bypass the usual authentication. [13:03.820 --> 13:08.240] So if the server, uh, is configured to always require a password, that's not going to work. [13:08.240 --> 13:19.580] But in most cases where you have like really machine to machine authentication, so you're really talking about automated device, then it's, yeah, makes sense to not use user authentication, but use this client server authentication. [13:19.640 --> 13:24.140] And if you support HTTPS, well, I just completely bypassed it. [13:24.560 --> 13:32.100] Uh, only downside though, from the attacker's perspective, in practice, almost nobody actually really uses this HTTPS variant of the protocol. [13:32.100 --> 13:33.980] It's a relatively new feature. [13:34.120 --> 13:39.160] It's, uh, supported in a few implementations, but it turns out there's not really much need for it. [13:39.200 --> 13:40.800] People don't really care about it. [13:40.880 --> 13:45.520] There are a bunch of implementations that open up an HTTPS port by default. [13:45.520 --> 13:48.980] So if you don't change the default configuration, it will expose this. [13:48.980 --> 13:54.900] And even if you don't use it, you may still be, uh, completely vulnerable, assuming that you don't block off this port in your firewall. [13:55.020 --> 14:01.800] So it definitely is a potential risk, especially when you use an implementation that turns this on or when you actually do rely on HTTPS. [14:02.380 --> 14:07.140] But it probably does not affect the majority of OPC UA, uh, deployments. [14:07.420 --> 14:14.600] So I wanted to look a little further and see, is there a way where I can actually attack the standard TCP version of the protocol? [14:14.600 --> 14:17.760] And then I need to get past this first secure channel step. [14:18.280 --> 14:24.860] Now something that's, um, I noticed is in the list of supported, uh, ciphers of supported security policies. [14:24.860 --> 14:31.060] There is one that has a, uh, well, a familiar, uh, uh, name for me. [14:31.060 --> 14:45.900] Uh, it uses, uh, RSA for encryption using the PKCS1 panning scheme, which is a, uh, a way of using RSA that has pretty much been definitively broken in 1998 by Daniel Blankenbacher in this, uh, really nice paper. [14:46.160 --> 14:55.680] Uh, but a lot of protocol designers since didn't appear to have gotten a memo about this and kept putting PKCS, uh, one in their protocols. [14:55.680 --> 15:05.000] Just as the case for OPC UA, which I think the first version was from like 2006, but they still supported this basically broken, uh, encryption mechanism. [15:06.220 --> 15:08.780] However, they eventually did deprecate it. [15:08.780 --> 15:22.160] So there's one, uh, security policy that supports this broken mechanism, but, uh, implementers, they're told, hey, please implement support for this, but turn it off by default and discourage its use. [15:22.600 --> 15:27.280] Um, of course that doesn't stop a lot of implementations from just turning this on by default. [15:27.280 --> 15:30.380] Anyway, this deprecation advice is not always followed in practice. [15:31.260 --> 15:36.140] Um, also the reason giving for the deprecation advice is about SHA-1. [15:36.140 --> 15:38.080] It's not about PKCS, uh, one. [15:38.080 --> 15:40.940] So, uh, people may get the wrong idea. [15:40.940 --> 15:46.000] Think, uh, rightly think that, oh, the fact that you use SHA-1 is completely unexploitable in practice. [15:46.000 --> 15:46.820] I don't care. [15:46.820 --> 15:48.040] I'm going to turn this on. [15:48.160 --> 15:54.100] Uh, there can also be a lot of users that have like a preexisting configuration from before the deprecation advice. [15:54.100 --> 16:01.340] Then if the vendor implements a patch to change the defaults, they're probably not going to change preexisting configurations because that may break stuff. [16:01.860 --> 16:13.020] Also, very interestingly, there are applications that even when, uh, the weak cipher is turned off, uh, you can still send a message that's encrypted using PKCS-1. [16:13.080 --> 16:20.960] The server will still try to decrypt it and only realize that, hey, this, uh, I'm not actually supposed to use this after it's done the decryption. [16:20.960 --> 16:29.600] So in a later stage it will block the connection, but then it has already done a decryption and for, uh, the particular attack that I'm going to explain, that's really all you need. [16:30.320 --> 16:33.760] And besides that, you only really need one vulnerable server. [16:33.880 --> 16:44.780] Uh, once you've got one place where you can do an attack on PKCS-1, you can also attack, uh, other servers that implement a more secure protocol, uh, but that reuse the same public key. [16:45.680 --> 17:04.240] So a quick, simplified primer on Bleichenbacher's attack, um, RSA encryption is, uh, basically just, um, uh, modular exponentiation of a large integer and because the message that you're trying to encrypt may not actually be a large integer, it may be like a value like one or something that you don't really want to exponentiate, [17:04.240 --> 17:06.640] you need to turn it into an appropriate integer. [17:06.880 --> 17:20.080] So how PKCS-1 padding does this, it, uh, adds a zero in front, it adds a two byte in front, some random bytes, a zero byte, and then it adds the message bytes and it treats this, this as a big integer it's going to encrypt. [17:20.500 --> 17:29.600] Um, then after the server decrypts it, well, it gets, it gets this integer and it needs to convert it back in a message, so it checks this padding and then it removes the padding. [17:30.160 --> 17:38.640] However, if you do the decryption operation and you get an integer that doesn't match this, uh, padding format, uh, then the server should fail decryption. [17:38.640 --> 17:42.040] So it's, uh, will probably just, uh, reject the message. [17:42.600 --> 17:56.300] And the attack becomes possible at the moment when you, as an attacker, can distinguish the case where a server says, hey, this padding is wrong, I'm going to reject this message, or when it behaves differently and it does accept the padding, but maybe then fails in a follow-up step. [17:56.720 --> 18:07.040] Uh, and when you know that you've given, like, some kind of forged cipher text and you know the end result of decrypting it has valid padding, tells you a really important piece of information. [18:07.040 --> 18:12.240] Apparently, when I make the cipher text, it will decrypt to something that starts with a zero with a two. [18:12.300 --> 18:19.640] So it's apparently greater than the, uh, than an integer that starts with zero two, and it's smaller than an integer that starts with zero three. [18:19.640 --> 18:22.700] So it leaks a bunch of information about the plain text. [18:23.020 --> 18:31.300] And RSA also has the property that if you have a, um, encrypted value that you don't know, you still have the capability of multiplying it with the value that you choose. [18:31.300 --> 18:45.480] So you can kind of multiply this unknown plain text with chosen, uh, with chosen values, give it to the server, get it to decrypt it, and if you do that in a, uh, in a clever way and you pick the right values, you can kind of, uh, look at all these, uh, [18:45.480 --> 18:51.600] padding results and you can kind of narrow down what the original plain text is supposed to be by constantly asking like, hey, does this have valid padding? [18:51.600 --> 18:52.600] Does this have valid padding? [18:52.740 --> 19:07.280] And then eventually after about a million attempts, which is why the attack is also sometimes called a million message attack, you should eventually be able to have decrypted all the, uh, all the bytes in the message and you've effectively broken RSA. [19:08.680 --> 19:13.700] So how would we, uh, use this attack against OPC UA? [19:14.020 --> 19:23.460] Uh, well, in this, uh, handshake, there's really two things that are being done with RSA, uh, private keys, uh, on the side of you as a client and you're trying to impersonate the client. [19:23.460 --> 19:24.720] So that's what you want to attack. [19:25.060 --> 19:31.800] First, you have to sign a message and then, uh, you get the message back from the server and you have to decrypt that message. [19:32.100 --> 19:33.860] Uh, well, decryption is straightforward. [19:33.860 --> 19:38.840] You just do the attack, uh, in its, in its standard form and you have decrypted that message. [19:38.840 --> 19:41.860] You know the nonce, you can proceed to derive the session keys. [19:42.520 --> 19:54.020] Um, and for signature forgery, uh, that's actually, uh, like I've already pointed out, uh, not a big problem as well because RSA signatures are basically just decryptions of hashes. [19:54.120 --> 20:04.660] Uh, you can just do the exact same attack, um, trying to decrypt a hash value and, uh, you will end up with a valid, uh, signature value. [20:05.440 --> 20:07.580] So this would look something like this. [20:07.580 --> 20:12.220] You start out by doing this whole, a million message attack until you've spoofed the signature. [20:12.240 --> 20:16.860] What's nice about this first step that once you've done this once, you can just keep reusing this message for the signature. [20:16.860 --> 20:20.560] So you, so even if the second step fails, you don't have to repeat the first step. [20:21.120 --> 20:23.500] Uh, so you do the whole exchange with the spoofed signature. [20:23.500 --> 20:25.720] You get a message back that's encrypted. [20:25.720 --> 20:28.000] You can't pick out the nonce from it yet. [20:28.080 --> 20:36.500] So you do this whole attack again, uh, while you keep the session open, which is important because if the moment you close the connection, the nonce will be forgotten. [20:36.540 --> 20:37.880] It's no longer useful. [20:37.880 --> 20:46.940] So you kind of have to keep like one TCP session open and use a different TCP connection to do this whole black and bucket attack and keep sending some people lives because the attack may take a while. [20:47.040 --> 20:51.760] And then once you're done, you know the nonces, you can proceed with the next step. [20:52.100 --> 20:57.140] And, uh, as I've showed with the attack against HPS, we've already broken this next step. [20:57.140 --> 21:03.140] And even if you couldn't use that attack, you could also use black and buckers attack, even for the session handshake in just the exact same way. [21:05.700 --> 21:09.000] So to make this work in practice, you need a padding oracle. [21:09.000 --> 21:13.760] You need a way to have the server tell you, is my padding correct or is my padding not correct? [21:13.820 --> 21:17.880] For some implementations this is really easy because you just, they just give different error messages. [21:17.940 --> 21:20.780] With wrong padding, it says something like decrypt failed. [21:20.780 --> 21:24.480] When the padding is right, it says something like signature validation failed and you're done. [21:24.480 --> 21:26.760] You can just use the attack in its standard form. [21:27.220 --> 21:32.180] Unfortunately, most implementations that I tested have a very generic error message. [21:32.180 --> 21:40.020] So in either of the two cases, they show exactly the same error codes and you can't really tell by looking at it what actually happens. [21:40.240 --> 21:42.240] So then we need a different approach. [21:42.240 --> 21:47.360] And the typical way to do that is by using a timing side channel attack. [21:48.580 --> 21:54.140] Maybe if you have correct padding, their server will take a different amount of time than if you have wrong padding. [21:54.380 --> 21:58.960] And that's something that at first to me, well, sounded like, ah, this is probably not going to work. [21:58.960 --> 21:59.980] This sounds really hard. [21:59.980 --> 22:09.360] I've seen plenty of papers where people managed to pull themselves in practice against a padding Oracle attack like this, but you're probably going to have to send a lot of messages. [22:09.360 --> 22:13.420] You have to do some complicated statistics, deal with network, jitter. [22:13.420 --> 22:15.720] It sounds pretty hard to do a timing attack. [22:15.720 --> 22:22.040] I mean, timing attacks have the reputation of being complicated, but keep in mind, not all timing attacks are hard. [22:22.040 --> 22:26.740] Think of like the SQL injection, where you add like a sleep five second statement to your query. [22:26.740 --> 22:30.800] Well, seeing if a server blocks for five seconds or not is very, very easy. [22:30.800 --> 22:41.660] And it turns out you can do something a little bit like that in OPC UA and actually make your timing attack super easy because the way that they're using RSA is very weird. [22:44.760 --> 22:55.760] The messages that they encrypt instead of like first encrypting a symmetric key, encrypting the message with that, they directly encrypt the message itself, but Oh no, the message always contains a signature. [22:55.760 --> 22:58.500] It's way too long to fit into a single RSA block. [22:58.500 --> 23:03.200] So what we do, we split up the messages in different blocks and we encrypt each block individually. [23:03.200 --> 23:10.280] So it's kind of the same principle as like the ECB modes, the notorious ECB modes in block ciphers. [23:10.640 --> 23:17.660] Now for RSA it does have a little bit different weaknesses and different properties when you use like this kind of ECB modes. [23:17.740 --> 23:27.340] Actually you could probably hide penguin pictures pretty well when you do this, but it opens up all kinds of potential chosen ciphertext attacks. [23:27.340 --> 23:29.720] It's really a bad idea to do it this way. [23:30.360 --> 23:41.980] But what I could use it for when trying to get this black and bucket attack to work is to take like my guess for this whole black and bucket attack, this one ciphertext I want to try and I simply repeat it a hundred times. [23:42.840 --> 23:47.320] And then I sent this long message of like 100 concatenated ciphertext to the server. [23:47.680 --> 23:52.940] If my padding is wrong, it will try to decrypt the first message, see the padding is wrong, throw an exception, stop. [23:53.520 --> 23:57.120] If the padding is correct, it will decrypt the first message, move on to the second message. [23:57.120 --> 23:59.220] Well, it's the same, so the padding is also going to be fine there. [23:59.220 --> 24:03.880] Decrypts the third, fourth, fifth, sixth, and then it does like 100 RSA decryptions. [24:04.020 --> 24:06.940] And then at the end it realizes my message is bogus. [24:07.460 --> 24:17.940] But yeah, RSA decryption is a very expensive operation and doing it a hundred times, you get some pretty sizable timing differences even when you use less than a hundred messages. [24:17.940 --> 24:20.140] So this is like a screenshot of my tool. [24:20.140 --> 24:28.400] And in this example you can see like when you have incorrect padding, it takes the server about 0.005 seconds. [24:29.080 --> 24:33.300] But when the padding is right, there's actually like a 10th of a second difference. [24:33.300 --> 24:38.180] So these are really huge timing differences that are like super easy to measure with just a simple Python script. [24:38.280 --> 24:42.060] Of course, maybe you have some weird network jitter or issues. [24:42.060 --> 24:51.140] So to weed out these false positives, I just simply made my Python scripts, try it a few times again when it does have a hit. [24:51.540 --> 24:59.160] And the nice thing about Bleichenbacher attacks is that the cases where you have correct paddings, so the slow cases in this, those are far more rare. [24:59.160 --> 25:03.200] So by far the most of these, like 99% of the messages you're sending will have wrong padding. [25:03.200 --> 25:05.100] So they actually go by really fast. [25:05.300 --> 25:09.780] And only the few interesting ones that give you more information, these are slow. [25:09.780 --> 25:17.380] So carrying out this attack with these big messages isn't actually that much slower than using an error-based padding oracle. [25:18.340 --> 25:21.320] So I implemented this whole attack in a tool. [25:23.400 --> 25:25.760] I threw it at the lab environments. [25:25.760 --> 25:31.980] I made a nice little spitting progress bar thing with numbers that will slowly go up and they go up a little further. [25:31.980 --> 25:36.700] And then after about, in this case, eight and a half minutes, it has done the first stage. [25:36.700 --> 25:38.360] It has managed to spoof a signature. [25:38.420 --> 25:42.320] Then it goes to repeat the whole attack again while keeping the connection open. [25:42.320 --> 26:01.780] And then in 15 minutes total, bam, we've completely bypassed authentication on the OPC server by using a timing attack involving about a million messages that really only took 15 minutes, which suddenly starts to sound pretty practical for a timing attack involving a million messages. [26:01.860 --> 26:11.940] Now I'm cheating a little bit here because this is basically the fastest example I had, because this was against a server that had a very fast implementation written in C. [26:11.960 --> 26:16.480] On other servers, the attack may take like 30 minutes, one hour. [26:16.480 --> 26:18.980] Slowest case I found was two hours. [26:18.980 --> 26:25.400] It's kind of the difference between you as an attacker having to go out for a coffee or having to go out for lunch while waiting for this attack to finish. [26:25.800 --> 26:34.980] And what I also noticed in most implementations, because this attack kind of happens in an early stage of the protocol and it's not really something that's really expected to happen. [26:34.980 --> 26:37.940] A lot of implementations don't do any logging because this happens. [26:37.940 --> 26:42.500] So if you're like an administrator and you look at the logs, you don't see anything suspicious. [26:42.500 --> 26:43.820] You really don't see anything at all. [26:43.820 --> 26:48.560] You don't see somebody is pounding your server with like millions of weird messages. [26:50.280 --> 27:01.260] So I tried out these two attacks on seven different implementations, which I choose because that's where I happen to be able to get a lab environment to work. [27:01.260 --> 27:04.360] Didn't need like expensive hardware or software licenses. [27:05.300 --> 27:13.460] And out of these seven implementations, five of them were vulnerable to at least one of the attack variants. [27:13.820 --> 27:18.820] And four of those had like one of the two attacks that would work in the default configuration. [27:18.820 --> 27:22.460] So you didn't have to like turn on the legacy cipher. [27:22.460 --> 27:25.620] You didn't have to tweak anything. [27:25.620 --> 27:26.820] You just go for a default. [27:26.820 --> 27:31.140] You only turn on like the fact that you want to use this client authentication. [27:31.580 --> 27:34.520] And one of my attacks would work out of the box. [27:34.720 --> 27:39.240] And for some other implementations it would work if you had a particular kind of changed configuration. [27:40.380 --> 27:44.980] Now these are just seven implementations I managed to get my hands on. [27:44.980 --> 27:46.840] Five out of seven is a pretty high number. [27:46.840 --> 27:57.520] You can probably extrapolate from that that's well if we would try this against more implementations there's going to be more that's going to be affected. [27:57.520 --> 28:02.960] In the end, these doing these attacks successfully, they do depend on configuration. [28:02.960 --> 28:08.000] They do, they do depend on implementation details, but they are still protocol flaws. [28:08.120 --> 28:12.520] So it's safe to say that probably a lot more implementations will be affected. [28:12.880 --> 28:22.020] And indeed, after I did a responsible disclosure, I saw like advisories coming in from different vendors that had confirmed that they were also affected. [28:22.600 --> 28:31.680] Like CodeSys, Siemens, had a whole bunch of like WinCC products where they managed to confirm, okay, this attack is actually very relevant for us. [28:31.680 --> 28:37.060] And there will probably be more implementations like that coming forward. [28:37.780 --> 28:43.380] So, well, I found this for seven different products, but there's probably going to be many, many more that are affected. [28:43.380 --> 28:45.400] How the hell do you even disclose this? [28:45.580 --> 28:59.600] Well, thankfully, I didn't really have to do this myself because OPC UA, practically all the vendors that make an implementation of the protocol, they're all connected to the OPC foundation, which like curates the standards. [28:59.600 --> 29:05.280] And they have like their own responsible disclosure policy, their own like security processes. [29:05.960 --> 29:07.760] And I could just go to them. [29:07.800 --> 29:09.420] I could just contact them. [29:09.420 --> 29:11.420] So I sent like a responsible disclosure. [29:12.120 --> 29:22.280] And they responded to me in like two hours and invited me to like a meeting in the exact same day to where I could explain the details of the attack, which is very impressive. [29:22.280 --> 29:24.240] Actually, my compliments to the OPC foundation. [29:24.240 --> 29:28.540] That's not how responsible your disclosure usually goes in my experience. [29:29.260 --> 29:37.200] And they basically took over all the hard work of going through all these vendors, sharing the details with them. [29:37.200 --> 29:50.320] Some of them came back with specific questions for me and together the foundation would figure out like ways, okay, how do we solve these tricky issues in a way without breaking stuff for our customers? [29:51.000 --> 29:52.640] Which is very, very nice. [29:52.640 --> 29:53.380] I'm very happy. [29:53.380 --> 30:02.420] I didn't have to go through all these vendors one by one and maybe even vendors where I'm like, well, I didn't actually test your solution, but you may be potentially vulnerable because you're using a flawed protocol. [30:02.440 --> 30:07.000] I'm very happy that the foundation would pick this up for me. [30:07.200 --> 30:09.400] A bunch of CVEs got issued. [30:09.600 --> 30:22.740] What may be a little bit confusing here is that some vendors, they issued their own CVE and some, they reused the same like standard CVEs to describe the whole protocol flaw, but some products, they give different CVSS scores to the same CVE. [30:22.740 --> 30:25.520] So it's a little bit confusing when you're looking at the CVE number. [30:25.520 --> 30:27.280] Sometimes you see one CVSS score. [30:27.280 --> 30:32.180] Sometimes you see another CVSS score and it kind of depends on the particularities of one implementation. [30:32.800 --> 30:36.020] The way this got fixed, it kind of depended on the vendor. [30:36.140 --> 30:38.000] Some were like, well, nobody uses HTTPS. [30:38.000 --> 30:40.520] I'm going to turn HTTPS off, for example. [30:41.880 --> 30:56.860] So for some, they tried to implement like mitigating measures to make it like very difficult to exploit like the padding Oracle in practice, made it impossible to do like the timing attack in the way that I described and also weren't like their end users. [30:56.860 --> 30:59.260] Hey, please turn off this legacy cipher. [30:59.900 --> 31:11.780] If you want to know what your vendor did or more importantly, what you should do when you are using an OPC UA implementation, I recommend to look at their advisories and their documentation. [31:12.520 --> 31:18.920] And when you're not entirely sure about that, I will first check if this is relevant for you. [31:18.920 --> 31:27.460] And this is relevant for you if you rely on this certificate based authentication, but you don't use user authentication because once again, my attack, it's still not going to get user passwords. [31:27.780 --> 31:29.200] There's one small exception. [31:29.200 --> 31:32.120] There's like a feature where users can also use certificates to log in. [31:32.120 --> 31:34.680] And there's like a few edge cases where you can bypass that as well. [31:35.500 --> 31:41.480] But in generally it's, this only really applies to the certificate based system authentication. [31:42.180 --> 31:45.660] And if you're not sure, well, did my vendor patch this or not? [31:45.660 --> 31:47.000] Am I affected or not? [31:47.000 --> 31:51.280] I'm using something very different than what's listed here and maybe I can't patch it. [31:51.440 --> 32:04.940] I published a tool that's available now, that allows you to like scan for like these vulnerabilities, try to carry them out in practice. [32:05.660 --> 32:08.560] And well, I tested them against these seven implementations. [32:08.560 --> 32:15.260] So I kind of hope that if it works against these seven, it should probably work against other compliant implementations as well. [32:15.260 --> 32:18.800] If they don't, please send in a bug report. [32:18.800 --> 32:25.840] And hopefully that can help people out to try this out in practice and test their own setups. [32:27.160 --> 32:30.380] So what can we take away from this? [32:31.400 --> 32:39.000] Well, first of all, always important to reiterate, protocol design, cryptographic protocol design is hard. [32:39.000 --> 32:46.280] You may be using like military grade encryption because you use AES and RSA and SHA-2 and so on. [32:46.280 --> 32:55.420] But these are really low level building blocks and putting them together in a way to make a, a valid protocol is very difficult. [32:55.420 --> 33:02.840] Ideally you really want to involve cryptographic experts, especially of course this protocol is like 15 years old. [33:02.840 --> 33:13.040] We know a lot more now on how you can actually design better protocols, how to use formal methods to test them, how to, uh, just better design practices in general. [33:13.040 --> 33:20.020] So for, to an extent, you can't really blame the original designers that they didn't really know, uh, these more modern approaches. [33:20.040 --> 33:28.440] Uh, but yeah, uh, if you would, if I would design a protocol like OPC UA nowadays, I would just say, yeah, I'm not going to design the crypto myself. [33:28.440 --> 33:29.620] I'm just going to use TLS. [33:29.960 --> 33:30.420] Done. [33:30.420 --> 33:34.120] Please just use TLS when you have a client server protocol like this. [33:34.120 --> 33:38.260] If you don't have very particular properties that you need, just use TLS. [33:38.880 --> 33:49.260] Um, also, uh, well more than a quarter century later, once again, it's, uh, it's shown that like a Bucker's attack is still relevant. [33:49.260 --> 33:51.820] It was still relevant against TLS for a long time. [33:51.820 --> 33:57.420] People try to implement fixes to make PKCS1 work in some other way, constantly kept getting broken. [33:57.420 --> 34:02.280] It was broken when they decided it was a good idea to support this in JSON web tokens. [34:02.280 --> 34:03.780] It just keeps getting broken. [34:03.780 --> 34:06.660] Just never ever use PKCS1, turn it off. [34:06.820 --> 34:10.720] Uh, just treat this whole petting scheme as fundamentally, uh, broken. [34:11.320 --> 34:18.740] Uh, and yeah, when you look at vulnerabilities like this, of course, I am, uh, I may only be scratching the surface here. [34:18.740 --> 34:26.420] You really can't rule out that other people may find other crypto bugs in OPC UA or maybe in one of the other elements. [34:26.420 --> 34:33.820] I didn't even go for like the old pops up protocol or discovery protocol or certificate updating protocol. [34:33.820 --> 34:35.960] There is quite some attack surface here. [34:35.960 --> 34:37.840] Uh, interesting research area. [34:38.300 --> 34:44.520] And we can't expect that, uh, well, once these particular issues are fixed, you'll be fine in the future. [34:44.920 --> 34:52.880] Um, so does that mean we all have to go back to using VPNs again when we, uh, post OPC UA over a trust boundary? [34:53.600 --> 34:56.840] Well, I would say depends a bit on the circumstances. [34:56.840 --> 35:13.580] If you're in a situation where you cannot easily patch and you know, you cannot easily patch in the future, then I would definitely say, okay, uh, like it's common in, uh, OT setups, you need to rely on network segmentation because you probably cannot respond quickly to when new vulnerabilities like this crop up in the future. [35:14.020 --> 35:24.700] If you can, uh, uh, patch promptly when like another crypto bug would turn up or, uh, uh, or another type of vulnerability, then it may be acceptable. [35:24.700 --> 35:42.880] Although I would recommend to use IP allow listing, uh, because if there's like something like a pre-authentication bypass or, uh, and the crypto bug that's allows a similar type of authentication bypass or a certificate validation bug and especially researchers from clarity have found a lot of those types of issues. [35:43.540 --> 35:46.300] Um, you don't want to expose your thing to anyone on the internet. [35:46.300 --> 35:53.060] So at the very least for these authentication bugs, I would recommend to always use IP allow listing, especially if your server controls something important. [35:53.620 --> 35:56.320] Uh, and otherwise it really just depends on your threat model. [35:56.320 --> 35:59.500] And, uh, this is probably an eventuality you should take into account. [36:00.180 --> 36:02.180] And, uh, yeah, this was my talk. [36:02.180 --> 36:04.800] I think I finished, uh, in the time pretty well. [36:04.820 --> 36:11.880] Uh, if people have questions, uh, you can just, uh, approach me right around the corner outside of the hall here. [36:11.880 --> 36:13.680] And, uh, thank you all very much for attending.