1 00:00:00,000 --> 00:00:07,320 Welcome to my talk, No VPN Needed, Cryptographic Attacks Against the OPC UA Protocol. 2 00:00:07,840 --> 00: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. 3 00:00:19,760 --> 00: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. 4 00:00:40,840 --> 00: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. 5 00:00:55,420 --> 00: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. 6 00:01:11,700 --> 00:01:14,640 So, OPC UA. 7 00:01:14,760 --> 00:01:18,620 It's a protocol used for industrial automation. 8 00:01:18,620 --> 00: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. 9 00:01:31,300 --> 00:01:37,540 Think of pipelines, solar parks, windmills, gas turbines, and so on. 10 00:01:37,660 --> 00:01:42,100 There's of course many protocols in this space. 11 00:01:42,100 --> 00: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, 12 00:02:01,220 --> 00:02:05,220 and it's interoperable through different vendors. 13 00:02:05,820 --> 00:02:12,400 But the aspect about it that I personally find most interesting is that it has security features. 14 00:02:13,130 --> 00: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. 15 00:02:32,560 --> 00:02:39,740 Maybe even put a server on the internet, so we can more easily remotely manage things that are in the field. 16 00:02:39,860 --> 00: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. 17 00:02:46,360 --> 00:02:52,860 We can rely on these convenient security features that are already present. 18 00:02:53,160 --> 00: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, 19 00:03:07,040 --> 00:03:09,820 and are there maybe any issues with it. 20 00:03:10,740 --> 00:03:16,300 So in general, OPC UA, it has kind of two different layers in the protocol. 21 00:03:16,300 --> 00: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. 22 00:03:34,180 --> 00: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. 23 00:03:50,780 --> 00: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. 24 00:03:57,760 --> 00:04:03,080 It's also optional which authentication features you actually want to use, or which encryption features you want to use. 25 00:04:03,080 --> 00: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. 26 00:04:15,220 --> 00: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, 27 00:04:31,920 --> 00: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. 28 00:04:41,980 --> 00: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. 29 00:04:56,980 --> 00: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. 30 00:05:06,440 --> 00: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. 31 00:05:19,960 --> 00: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. 32 00:05:37,180 --> 00: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. 33 00:05:49,000 --> 00: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. 34 00:06:00,340 --> 00: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. 35 00:06:12,420 --> 00: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. 36 00:06:18,400 --> 00:06:21,720 And the security policy is basically, it's like a cipher suite in TLS. 37 00:06:21,720 --> 00:06:24,560 It decides what kind of crypto you're using. 38 00:06:24,640 --> 00:06:26,140 There's a variety of options. 39 00:06:26,140 --> 00: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. 40 00:06:39,700 --> 00: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. 41 00:06:51,360 --> 00:06:55,580 And here once again, both sides generate a random number. 42 00:06:55,580 --> 00:06:57,260 The standard also calls this a nonce. 43 00:06:57,260 --> 00:07:00,620 I call this a challenge to make it easier to distinguish it. 44 00:07:00,860 --> 00:07:05,700 And they will put this challenge in the encrypted message. 45 00:07:06,440 --> 00:07:09,000 The client will send a challenge to the server. 46 00:07:09,000 --> 00: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. 47 00:07:17,040 --> 00:07:19,300 And send the client its own challenge. 48 00:07:19,300 --> 00:07:22,280 The challenge will sign that challenge, send it back. 49 00:07:22,420 --> 00:07:27,740 This can be combined with user authentication and how the user authentication is used. 50 00:07:27,740 --> 00:07:33,660 That depends a little bit on what authentication method you pick, like passwords or tokens or something else. 51 00:07:33,660 --> 00: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. 52 00:07:40,320 --> 00:07:46,420 So yeah, you basically just got a pretty straightforward challenge response protocol. 53 00:07:46,500 --> 00: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. 54 00:07:55,000 --> 00: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. 55 00:08:08,520 --> 00:08:15,160 Your, uh, both sides during the protocol are doing three different RSA private key operations, which are pretty expensive. 56 00:08:15,340 --> 00: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. 57 00:08:21,840 --> 00:08:26,120 Uh, so, it's not really a great design in my opinion. 58 00:08:26,120 --> 00: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. 59 00:08:32,420 --> 00:08:36,480 Uh, maybe this will add some defense in depth or something, uh, uh, who knows. 60 00:08:36,480 --> 00:08:41,180 So, let's take a look at, uh, how, uh, well this protocol actually stacks up. 61 00:08:42,000 --> 00: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. 62 00:08:57,640 --> 00: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. 63 00:09:06,280 --> 00: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. 64 00:09:11,860 --> 00:09:14,260 They really look exactly the same. 65 00:09:14,600 --> 00: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. 66 00:09:28,560 --> 00: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, 67 00:09:44,480 --> 00:09:47,980 I am actually server B, and you present a certificate of server B. 68 00:09:48,200 --> 00:09:50,440 Um, I would like to log in. 69 00:09:50,440 --> 00: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. 70 00:09:56,420 --> 00: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. 71 00:10:05,880 --> 00:10:10,080 So server B will sign the challenge , uh, as part of the first step of the protocol. 72 00:10:10,080 --> 00: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 . 73 00:10:16,880 --> 00: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. 74 00:10:26,540 --> 00: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. 75 00:10:38,940 --> 00: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. 76 00:10:53,500 --> 00: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, 77 00:11:05,880 --> 00:11:07,280 uh, maximal privileges . 78 00:11:08,620 --> 00:11:16,080 Of course, this whole theoretical attack only really works on the second phase that I showed, this, uh, this session handshake. 79 00:11:16,080 --> 00: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. 80 00:11:24,960 --> 00:11:31,160 So if our attack would make any sense in practice, we first need to somehow bypass this first step. 81 00:11:32,040 --> 00: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. 82 00:11:39,000 --> 00: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. 83 00:11:49,980 --> 00: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. 84 00:12:01,780 --> 00: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. 85 00:12:10,780 --> 00:12:14,340 We can directly move into the session step because we already have encryption. 86 00:12:14,340 --> 00:12:16,380 We don't need to establish it ourselves anymore. 87 00:12:17,300 --> 00:12:20,280 Um, and then we go right to the vulnerable session handshake. 88 00:12:21,180 --> 00: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. 89 00:12:33,460 --> 00: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. 90 00:12:44,120 --> 00:12:47,800 I don't need to prove my identity to set up an HTTPS connection. 91 00:12:48,000 --> 00:12:51,000 And then I, uh, try to carry out this attack or this attack. 92 00:12:51,180 --> 00:12:55,420 So I wrote a tool that does exactly that and it turns out it totally works. 93 00:12:55,420 --> 00:13:01,100 Uh, you just point it at an HTTPS based OPC UA server that uses this client authentication feature. 94 00:13:01,180 --> 00:13:03,820 It's not going to bypass the usual authentication. 95 00:13:03,820 --> 00:13:08,240 So if the server, uh, is configured to always require a password, that's not going to work. 96 00:13:08,240 --> 00: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. 97 00:13:19,640 --> 00:13:24,140 And if you support HTTPS, well, I just completely bypassed it. 98 00:13:24,560 --> 00: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. 99 00:13:32,100 --> 00:13:33,980 It's a relatively new feature. 100 00:13:34,120 --> 00:13:39,160 It's, uh, supported in a few implementations, but it turns out there's not really much need for it. 101 00:13:39,200 --> 00:13:40,800 People don't really care about it. 102 00:13:40,880 --> 00:13:45,520 There are a bunch of implementations that open up an HTTPS port by default. 103 00:13:45,520 --> 00:13:48,980 So if you don't change the default configuration, it will expose this. 104 00:13:48,980 --> 00: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. 105 00:13:55,020 --> 00: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. 106 00:14:02,380 --> 00:14:07,140 But it probably does not affect the majority of OPC UA, uh, deployments. 107 00:14:07,420 --> 00: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? 108 00:14:14,600 --> 00:14:17,760 And then I need to get past this first secure channel step. 109 00:14:18,280 --> 00:14:24,860 Now something that's, um, I noticed is in the list of supported, uh, ciphers of supported security policies. 110 00:14:24,860 --> 00:14:31,060 There is one that has a, uh, well, a familiar, uh, uh, name for me. 111 00:14:31,060 --> 00: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. 112 00:14:46,160 --> 00: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. 113 00:14:55,680 --> 00: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. 114 00:15:06,220 --> 00:15:08,780 However, they eventually did deprecate it. 115 00:15:08,780 --> 00: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. 116 00:15:22,600 --> 00:15:27,280 Um, of course that doesn't stop a lot of implementations from just turning this on by default. 117 00:15:27,280 --> 00:15:30,380 Anyway, this deprecation advice is not always followed in practice. 118 00:15:31,260 --> 00:15:36,140 Um, also the reason giving for the deprecation advice is about SHA-1. 119 00:15:36,140 --> 00:15:38,080 It's not about PKCS, uh, one. 120 00:15:38,080 --> 00:15:40,940 So, uh, people may get the wrong idea. 121 00:15:40,940 --> 00:15:46,000 Think, uh, rightly think that, oh, the fact that you use SHA-1 is completely unexploitable in practice. 122 00:15:46,000 --> 00:15:46,820 I don't care. 123 00:15:46,820 --> 00:15:48,040 I'm going to turn this on. 124 00:15:48,160 --> 00:15:54,100 Uh, there can also be a lot of users that have like a preexisting configuration from before the deprecation advice. 125 00:15:54,100 --> 00: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. 126 00:16:01,860 --> 00: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. 127 00:16:13,080 --> 00: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. 128 00:16:20,960 --> 00: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. 129 00:16:30,320 --> 00:16:33,760 And besides that, you only really need one vulnerable server. 130 00:16:33,880 --> 00: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. 131 00:16:45,680 --> 00: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, 132 00:17:04,240 --> 00:17:06,640 you need to turn it into an appropriate integer. 133 00:17:06,880 --> 00: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. 134 00:17:20,500 --> 00: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. 135 00:17:30,160 --> 00: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. 136 00:17:38,640 --> 00:17:42,040 So it's, uh, will probably just, uh, reject the message. 137 00:17:42,600 --> 00: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. 138 00:17:56,720 --> 00: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. 139 00:18:07,040 --> 00:18:12,240 Apparently, when I make the cipher text, it will decrypt to something that starts with a zero with a two. 140 00:18:12,300 --> 00: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. 141 00:18:19,640 --> 00:18:22,700 So it leaks a bunch of information about the plain text. 142 00:18:23,020 --> 00: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. 143 00:18:31,300 --> 00: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, 144 00:18:45,480 --> 00: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? 145 00:18:51,600 --> 00:18:52,600 Does this have valid padding? 146 00:18:52,740 --> 00: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. 147 00:19:08,680 --> 00:19:13,700 So how would we, uh, use this attack against OPC UA? 148 00:19:14,020 --> 00: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. 149 00:19:23,460 --> 00:19:24,720 So that's what you want to attack. 150 00:19:25,060 --> 00: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. 151 00:19:32,100 --> 00:19:33,860 Uh, well, decryption is straightforward. 152 00:19:33,860 --> 00:19:38,840 You just do the attack, uh, in its, in its standard form and you have decrypted that message. 153 00:19:38,840 --> 00:19:41,860 You know the nonce, you can proceed to derive the session keys. 154 00:19:42,520 --> 00: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. 155 00:19:54,120 --> 00: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. 156 00:20:05,440 --> 00:20:07,580 So this would look something like this. 157 00:20:07,580 --> 00:20:12,220 You start out by doing this whole, a million message attack until you've spoofed the signature. 158 00:20:12,240 --> 00: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. 159 00:20:16,860 --> 00:20:20,560 So you, so even if the second step fails, you don't have to repeat the first step. 160 00:20:21,120 --> 00:20:23,500 Uh, so you do the whole exchange with the spoofed signature. 161 00:20:23,500 --> 00:20:25,720 You get a message back that's encrypted. 162 00:20:25,720 --> 00:20:28,000 You can't pick out the nonce from it yet. 163 00:20:28,080 --> 00: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. 164 00:20:36,540 --> 00:20:37,880 It's no longer useful. 165 00:20:37,880 --> 00: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. 166 00:20:47,040 --> 00:20:51,760 And then once you're done, you know the nonces, you can proceed with the next step. 167 00:20:52,100 --> 00:20:57,140 And, uh, as I've showed with the attack against HPS, we've already broken this next step. 168 00:20:57,140 --> 00: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. 169 00:21:05,700 --> 00:21:09,000 So to make this work in practice, you need a padding oracle. 170 00:21:09,000 --> 00:21:13,760 You need a way to have the server tell you, is my padding correct or is my padding not correct? 171 00:21:13,820 --> 00:21:17,880 For some implementations this is really easy because you just, they just give different error messages. 172 00:21:17,940 --> 00:21:20,780 With wrong padding, it says something like decrypt failed. 173 00:21:20,780 --> 00:21:24,480 When the padding is right, it says something like signature validation failed and you're done. 174 00:21:24,480 --> 00:21:26,760 You can just use the attack in its standard form. 175 00:21:27,220 --> 00:21:32,180 Unfortunately, most implementations that I tested have a very generic error message. 176 00:21:32,180 --> 00: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. 177 00:21:40,240 --> 00:21:42,240 So then we need a different approach. 178 00:21:42,240 --> 00:21:47,360 And the typical way to do that is by using a timing side channel attack. 179 00:21:48,580 --> 00:21:54,140 Maybe if you have correct padding, their server will take a different amount of time than if you have wrong padding. 180 00:21:54,380 --> 00:21:58,960 And that's something that at first to me, well, sounded like, ah, this is probably not going to work. 181 00:21:58,960 --> 00:21:59,980 This sounds really hard. 182 00:21:59,980 --> 00: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. 183 00:22:09,360 --> 00:22:13,420 You have to do some complicated statistics, deal with network, jitter. 184 00:22:13,420 --> 00:22:15,720 It sounds pretty hard to do a timing attack. 185 00:22:15,720 --> 00:22:22,040 I mean, timing attacks have the reputation of being complicated, but keep in mind, not all timing attacks are hard. 186 00:22:22,040 --> 00:22:26,740 Think of like the SQL injection, where you add like a sleep five second statement to your query. 187 00:22:26,740 --> 00:22:30,800 Well, seeing if a server blocks for five seconds or not is very, very easy. 188 00:22:30,800 --> 00: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. 189 00:22:44,760 --> 00: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. 190 00:22:55,760 --> 00:22:58,500 It's way too long to fit into a single RSA block. 191 00:22:58,500 --> 00:23:03,200 So what we do, we split up the messages in different blocks and we encrypt each block individually. 192 00:23:03,200 --> 00:23:10,280 So it's kind of the same principle as like the ECB modes, the notorious ECB modes in block ciphers. 193 00:23:10,640 --> 00: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. 194 00:23:17,740 --> 00: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. 195 00:23:27,340 --> 00:23:29,720 It's really a bad idea to do it this way. 196 00:23:30,360 --> 00: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. 197 00:23:42,840 --> 00:23:47,320 And then I sent this long message of like 100 concatenated ciphertext to the server. 198 00:23:47,680 --> 00: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. 199 00:23:53,520 --> 00:23:57,120 If the padding is correct, it will decrypt the first message, move on to the second message. 200 00:23:57,120 --> 00:23:59,220 Well, it's the same, so the padding is also going to be fine there. 201 00:23:59,220 --> 00:24:03,880 Decrypts the third, fourth, fifth, sixth, and then it does like 100 RSA decryptions. 202 00:24:04,020 --> 00:24:06,940 And then at the end it realizes my message is bogus. 203 00:24:07,460 --> 00: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. 204 00:24:17,940 --> 00:24:20,140 So this is like a screenshot of my tool. 205 00:24:20,140 --> 00:24:28,400 And in this example you can see like when you have incorrect padding, it takes the server about 0.005 seconds. 206 00:24:29,080 --> 00:24:33,300 But when the padding is right, there's actually like a 10th of a second difference. 207 00:24:33,300 --> 00:24:38,180 So these are really huge timing differences that are like super easy to measure with just a simple Python script. 208 00:24:38,280 --> 00:24:42,060 Of course, maybe you have some weird network jitter or issues. 209 00:24:42,060 --> 00: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. 210 00:24:51,540 --> 00: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. 211 00:24:59,160 --> 00:25:03,200 So by far the most of these, like 99% of the messages you're sending will have wrong padding. 212 00:25:03,200 --> 00:25:05,100 So they actually go by really fast. 213 00:25:05,300 --> 00:25:09,780 And only the few interesting ones that give you more information, these are slow. 214 00:25:09,780 --> 00: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. 215 00:25:18,340 --> 00:25:21,320 So I implemented this whole attack in a tool. 216 00:25:23,400 --> 00:25:25,760 I threw it at the lab environments. 217 00:25:25,760 --> 00: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. 218 00:25:31,980 --> 00:25:36,700 And then after about, in this case, eight and a half minutes, it has done the first stage. 219 00:25:36,700 --> 00:25:38,360 It has managed to spoof a signature. 220 00:25:38,420 --> 00:25:42,320 Then it goes to repeat the whole attack again while keeping the connection open. 221 00:25:42,320 --> 00: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. 222 00:26:01,860 --> 00: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. 223 00:26:11,960 --> 00:26:16,480 On other servers, the attack may take like 30 minutes, one hour. 224 00:26:16,480 --> 00:26:18,980 Slowest case I found was two hours. 225 00:26:18,980 --> 00: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. 226 00:26:25,800 --> 00: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. 227 00:26:34,980 --> 00:26:37,940 A lot of implementations don't do any logging because this happens. 228 00:26:37,940 --> 00:26:42,500 So if you're like an administrator and you look at the logs, you don't see anything suspicious. 229 00:26:42,500 --> 00:26:43,820 You really don't see anything at all. 230 00:26:43,820 --> 00:26:48,560 You don't see somebody is pounding your server with like millions of weird messages. 231 00:26:50,280 --> 00: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. 232 00:27:01,260 --> 00:27:04,360 Didn't need like expensive hardware or software licenses. 233 00:27:05,300 --> 00:27:13,460 And out of these seven implementations, five of them were vulnerable to at least one of the attack variants. 234 00:27:13,820 --> 00:27:18,820 And four of those had like one of the two attacks that would work in the default configuration. 235 00:27:18,820 --> 00:27:22,460 So you didn't have to like turn on the legacy cipher. 236 00:27:22,460 --> 00:27:25,620 You didn't have to tweak anything. 237 00:27:25,620 --> 00:27:26,820 You just go for a default. 238 00:27:26,820 --> 00:27:31,140 You only turn on like the fact that you want to use this client authentication. 239 00:27:31,580 --> 00:27:34,520 And one of my attacks would work out of the box. 240 00:27:34,720 --> 00:27:39,240 And for some other implementations it would work if you had a particular kind of changed configuration. 241 00:27:40,380 --> 00:27:44,980 Now these are just seven implementations I managed to get my hands on. 242 00:27:44,980 --> 00:27:46,840 Five out of seven is a pretty high number. 243 00:27:46,840 --> 00: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. 244 00:27:57,520 --> 00:28:02,960 In the end, these doing these attacks successfully, they do depend on configuration. 245 00:28:02,960 --> 00:28:08,000 They do, they do depend on implementation details, but they are still protocol flaws. 246 00:28:08,120 --> 00:28:12,520 So it's safe to say that probably a lot more implementations will be affected. 247 00:28:12,880 --> 00: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. 248 00:28:22,600 --> 00: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. 249 00:28:31,680 --> 00:28:37,060 And there will probably be more implementations like that coming forward. 250 00:28:37,780 --> 00: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. 251 00:28:43,380 --> 00:28:45,400 How the hell do you even disclose this? 252 00:28:45,580 --> 00: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. 253 00:28:59,600 --> 00:29:05,280 And they have like their own responsible disclosure policy, their own like security processes. 254 00:29:05,960 --> 00:29:07,760 And I could just go to them. 255 00:29:07,800 --> 00:29:09,420 I could just contact them. 256 00:29:09,420 --> 00:29:11,420 So I sent like a responsible disclosure. 257 00:29:12,120 --> 00: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. 258 00:29:22,280 --> 00:29:24,240 Actually, my compliments to the OPC foundation. 259 00:29:24,240 --> 00:29:28,540 That's not how responsible your disclosure usually goes in my experience. 260 00:29:29,260 --> 00:29:37,200 And they basically took over all the hard work of going through all these vendors, sharing the details with them. 261 00:29:37,200 --> 00: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? 262 00:29:51,000 --> 00:29:52,640 Which is very, very nice. 263 00:29:52,640 --> 00:29:53,380 I'm very happy. 264 00:29:53,380 --> 00: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. 265 00:30:02,440 --> 00:30:07,000 I'm very happy that the foundation would pick this up for me. 266 00:30:07,200 --> 00:30:09,400 A bunch of CVEs got issued. 267 00:30:09,600 --> 00: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. 268 00:30:22,740 --> 00:30:25,520 So it's a little bit confusing when you're looking at the CVE number. 269 00:30:25,520 --> 00:30:27,280 Sometimes you see one CVSS score. 270 00:30:27,280 --> 00:30:32,180 Sometimes you see another CVSS score and it kind of depends on the particularities of one implementation. 271 00:30:32,800 --> 00:30:36,020 The way this got fixed, it kind of depended on the vendor. 272 00:30:36,140 --> 00:30:38,000 Some were like, well, nobody uses HTTPS. 273 00:30:38,000 --> 00:30:40,520 I'm going to turn HTTPS off, for example. 274 00:30:41,880 --> 00: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. 275 00:30:56,860 --> 00:30:59,260 Hey, please turn off this legacy cipher. 276 00:30:59,900 --> 00: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. 277 00:31:12,520 --> 00:31:18,920 And when you're not entirely sure about that, I will first check if this is relevant for you. 278 00:31:18,920 --> 00: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. 279 00:31:27,780 --> 00:31:29,200 There's one small exception. 280 00:31:29,200 --> 00:31:32,120 There's like a feature where users can also use certificates to log in. 281 00:31:32,120 --> 00:31:34,680 And there's like a few edge cases where you can bypass that as well. 282 00:31:35,500 --> 00:31:41,480 But in generally it's, this only really applies to the certificate based system authentication. 283 00:31:42,180 --> 00:31:45,660 And if you're not sure, well, did my vendor patch this or not? 284 00:31:45,660 --> 00:31:47,000 Am I affected or not? 285 00:31:47,000 --> 00:31:51,280 I'm using something very different than what's listed here and maybe I can't patch it. 286 00:31:51,440 --> 00: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. 287 00:32:05,660 --> 00:32:08,560 And well, I tested them against these seven implementations. 288 00:32:08,560 --> 00: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. 289 00:32:15,260 --> 00:32:18,800 If they don't, please send in a bug report. 290 00:32:18,800 --> 00:32:25,840 And hopefully that can help people out to try this out in practice and test their own setups. 291 00:32:27,160 --> 00:32:30,380 So what can we take away from this? 292 00:32:31,400 --> 00:32:39,000 Well, first of all, always important to reiterate, protocol design, cryptographic protocol design is hard. 293 00:32:39,000 --> 00:32:46,280 You may be using like military grade encryption because you use AES and RSA and SHA-2 and so on. 294 00:32:46,280 --> 00: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. 295 00:32:55,420 --> 00:33:02,840 Ideally you really want to involve cryptographic experts, especially of course this protocol is like 15 years old. 296 00:33:02,840 --> 00: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. 297 00:33:13,040 --> 00: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. 298 00:33:20,040 --> 00: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. 299 00:33:28,440 --> 00:33:29,620 I'm just going to use TLS. 300 00:33:29,960 --> 00:33:30,420 Done. 301 00:33:30,420 --> 00:33:34,120 Please just use TLS when you have a client server protocol like this. 302 00:33:34,120 --> 00:33:38,260 If you don't have very particular properties that you need, just use TLS. 303 00:33:38,880 --> 00: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. 304 00:33:49,260 --> 00:33:51,820 It was still relevant against TLS for a long time. 305 00:33:51,820 --> 00:33:57,420 People try to implement fixes to make PKCS1 work in some other way, constantly kept getting broken. 306 00:33:57,420 --> 00:34:02,280 It was broken when they decided it was a good idea to support this in JSON web tokens. 307 00:34:02,280 --> 00:34:03,780 It just keeps getting broken. 308 00:34:03,780 --> 00:34:06,660 Just never ever use PKCS1, turn it off. 309 00:34:06,820 --> 00:34:10,720 Uh, just treat this whole petting scheme as fundamentally, uh, broken. 310 00:34:11,320 --> 00: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. 311 00:34:18,740 --> 00: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. 312 00:34:26,420 --> 00:34:33,820 I didn't even go for like the old pops up protocol or discovery protocol or certificate updating protocol. 313 00:34:33,820 --> 00:34:35,960 There is quite some attack surface here. 314 00:34:35,960 --> 00:34:37,840 Uh, interesting research area. 315 00:34:38,300 --> 00:34:44,520 And we can't expect that, uh, well, once these particular issues are fixed, you'll be fine in the future. 316 00:34:44,920 --> 00: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? 317 00:34:53,600 --> 00:34:56,840 Well, I would say depends a bit on the circumstances. 318 00:34:56,840 --> 00: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. 319 00:35:14,020 --> 00: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. 320 00:35:24,700 --> 00: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. 321 00:35:43,540 --> 00:35:46,300 Um, you don't want to expose your thing to anyone on the internet. 322 00:35:46,300 --> 00: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. 323 00:35:53,620 --> 00:35:56,320 Uh, and otherwise it really just depends on your threat model. 324 00:35:56,320 --> 00:35:59,500 And, uh, this is probably an eventuality you should take into account. 325 00:36:00,180 --> 00:36:02,180 And, uh, yeah, this was my talk. 326 00:36:02,180 --> 00:36:04,800 I think I finished, uh, in the time pretty well. 327 00:36:04,820 --> 00:36:11,880 Uh, if people have questions, uh, you can just, uh, approach me right around the corner outside of the hall here. 328 00:36:11,880 --> 00:36:13,680 And, uh, thank you all very much for attending.