1 00:00:02,380 --> 00:00:07,400 Hello, DEF CON! Uh, we're very excited to have you here. Uh, today we're going to talk 2 00:00:07,400 --> 00:00:12,960 about a very long research we've conducted in the past few years. Exploiting OPC UA in 3 00:00:12,960 --> 00:00:18,580 every possible way. So, let's start. My name is Jaron Brezinov. I'm a vulnerability 4 00:00:18,580 --> 00:00:25,080 researcher at Cloud AT Media 2. I also have a DEF CON black badge. Woo! Uh, with me is Noah 5 00:00:25,080 --> 00:00:30,680 Moshe, uh, is also our senior researcher. And, uh, we would like to say thank you very much 6 00:00:30,680 --> 00:00:36,200 for the other researchers who worked on this project, Uri Katz and Vera Menz. So, thank you 7 00:00:36,200 --> 00:00:42,920 very much. Today, we're going to talk about a very long research we've conducted on OPC UA 8 00:00:42,920 --> 00:00:49,400 security. So, basically, we researched a lot of, uh, actually dozens of OPC UA protocol stacks 9 00:00:49,400 --> 00:00:54,980 and different products. And we found some core issues in their implementations. So, 10 00:00:54,980 --> 00:01:00,600 it's not like we found a one-off vulnerability in one product. Rather, we found and were able to 11 00:01:00,600 --> 00:01:08,300 develop multiple attack vectors that exploited multiple products that support OPC UA. So, all in 12 00:01:08,300 --> 00:01:15,440 all, we found around 50 CVs and, uh, we developed 12 unique generic attacks that we gathered into 13 00:01:15,440 --> 00:01:22,140 one huge framework. And, uh, we're going to release it open source. Uh, we also released, uh, a 14 00:01:22,140 --> 00:01:27,800 phaser, OPC UA phaser, uh, that, uh, actually many vendors are currently using as part of, uh, 15 00:01:27,880 --> 00:01:33,040 secure, secure development. And they also found a couple of bugs with it. So, uh, I think it was 16 00:01:33,040 --> 00:01:39,340 very helpful. Um, and finally, big thanks to ZDI. Um, some of this research, at least, uh, 17 00:01:39,340 --> 00:01:46,680 were very incentivized because of Pwn2Own. So, ZDI has their Pwn2Own competitions, uh, and 18 00:01:46,680 --> 00:01:53,320 also they have the specific ICS category, which they emphasized on OPC UA. So, it gave us, uh, the 19 00:01:53,320 --> 00:01:59,040 cash prize, obviously. Uh, gave us, uh, a good incentive to research OPC UA, find bugs, and get 20 00:01:59,040 --> 00:02:07,000 200K. So, today we're going to talk about, uh, what is OPC UA, uh, cover some protocol stack 21 00:02:07,000 --> 00:02:13,120 implementations, go over bits and bytes, uh, which is a bit boring. Uh, we're going to, to 22 00:02:13,120 --> 00:02:16,660 cover the research methodology. So, how we approach OPC UA. Uh, we're going to, uh, 23 00:02:16,680 --> 00:02:22,100 approach this project, how we research different protocol stacks, uh, et cetera. Uh, and 24 00:02:22,100 --> 00:02:27,280 afterwards, we're going to show you, uh, some cool vulnerabilities and exploits, uh, we're 25 00:02:27,280 --> 00:02:33,680 able to find and finally release our OPC UA exploit, uh, framework. So, let's start with what 26 00:02:33,680 --> 00:02:39,640 is the problem. So, why OPC UA was created from the fir- first place. So, in the past, uh, 27 00:02:39,720 --> 00:02:46,600 let's say we had, uh, physical process. In this case, uh, water tank, uh, that we want to keep 28 00:02:46,680 --> 00:02:53,480 track of the water level. So, we have a PLC, uh, with some kind of a logic that keeps track, uh, 29 00:02:53,560 --> 00:03:00,220 using sensors on the water level. And these are configured as variables. So, the sensor is 30 00:03:00,220 --> 00:03:05,000 reading where the water level, uh, is. And we have a variable that is changing in the 31 00:03:05,000 --> 00:03:11,300 process. Now, if we want to monitor this, uh, procedure, uh, for example, from an HMI or a 32 00:03:11,300 --> 00:03:16,660 SCADA server, uh, we had to use the specific proprietary ICS protocol. So, we had to use the 33 00:03:16,680 --> 00:03:22,620 protocol, um, in order to communicate with the PLC to read and write, uh, these tags values or 34 00:03:22,620 --> 00:03:27,520 variables. Um, and obviously it's not very convenient because if you want different products to 35 00:03:27,520 --> 00:03:33,680 communicate with it, uh, we're very limited. So, OPC UA was introduced, uh, in order to have 36 00:03:33,680 --> 00:03:40,340 kind of a unified way to communicate between different devices and products within a SCADA 37 00:03:40,340 --> 00:03:46,420 network. So, now, we could all communicate OPC UA and we do not- do not have to be, uh, 38 00:03:46,420 --> 00:03:54,540 limited by the specific ICS protocol. Uh, and this is why many vendors joined in and today most of 39 00:03:54,540 --> 00:04:00,780 the vendors are supporting OPC UA, uh, in various ways, uh, from servers to clients to support 40 00:04:00,780 --> 00:04:06,960 in PLCs, SCADA servers. So, it became, uh, kind of, uh, the new standard, uh, and it's very 41 00:04:06,960 --> 00:04:15,820 popular today. Um, and if- in essence, the- the protocol was created for kind of a unified way for 42 00:04:15,820 --> 00:04:16,400 data extraction, uh, and, uh, it's very popular today. Um, and if- in essence, the- the protocol was 43 00:04:16,400 --> 00:04:19,440 created for kind of a unified way for data exchange between industrial devices. So, we have the 44 00:04:19,440 --> 00:04:25,680 server, which stores the variables, for example, the water level variable, and we have clients 45 00:04:25,680 --> 00:04:32,720 that read or write to these variables to, uh, monitor the process or also alter and modify the 46 00:04:32,720 --> 00:04:40,340 process. Now, it's very used, uh, it's very widely used, uh, by almost any vendor. So, let's go 47 00:04:40,340 --> 00:04:46,380 over a bit of the history of OPC UA. Now, OPC UA was created by OPC family. Uh, OPC UA was, uh, 48 00:04:46,400 --> 00:04:54,140 the foundation, uh, and the first specs goes back to 2006, and it was created based on lesson 49 00:04:54,140 --> 00:05:00,200 learned from the OPC Classic, OPC DA. So, in the past, there was a different protocol with 50 00:05:00,200 --> 00:05:06,860 similar purpose, uh, but it wasn't good enough. Uh, it lacked, uh, independent- platform 51 00:05:06,860 --> 00:05:13,180 independent, so it was very tied to Windows, uh, and it was not scalable, it was not secure, so, 52 00:05:13,840 --> 00:05:15,660 OPC foundation created OPC UA. 53 00:05:16,400 --> 00:05:24,580 also created a very thorough and uh deep specifications to make sure everybody are using it 54 00:05:24,580 --> 00:05:29,840 correctly and also to cover all the topics that anyone needs to know about OPC UA. So for 55 00:05:29,840 --> 00:05:36,520 example uh how uh objects are created in OPC UA is found in a specification. How security 56 00:05:36,520 --> 00:05:43,120 works is also found in specification. So if everyone anyone wants to implement OPC UA uh 57 00:05:43,120 --> 00:05:47,300 obviously they need to read the specification and they're pretty good so it's uh very kind of 58 00:05:47,300 --> 00:05:56,000 uh uh easy to read and follow. Now to accelerate the use of OPC UA, OPC foundation created uh 59 00:05:56,000 --> 00:06:02,440 three main protocol stacks. They created the Java protocol stack, .net protocol stack and 60 00:06:02,440 --> 00:06:08,820 NCC protocol stack. Basically what they tried to do is they tried to create some kind of 61 00:06:08,820 --> 00:06:13,100 SDKs or core libraries that other protocols don't have. So basically what they tried to do 62 00:06:13,120 --> 00:06:14,980 is they tried to create some kind of SDKs that other products could easily implement in their 63 00:06:14,980 --> 00:06:22,340 software to add support to OPC UA. So in essence to expedite popularity OPC foundation created 64 00:06:22,660 --> 00:06:29,100 the first OPC UA protocol stacks. And today there are hundreds uh maybe thousands of 65 00:06:29,100 --> 00:06:35,640 products using OPC UA from servers to clients to protocol gateways and they can all be found in 66 00:06:35,640 --> 00:06:43,100 the OPC UA uh OPC foundation website. And when we started this research we also went back to 67 00:06:43,120 --> 00:06:49,120 this website and we looked at the different products and it's very convenient uh to see what 68 00:06:49,120 --> 00:06:57,300 products are supporting OPC UA. Now the problem is that most products are actually heavily relying 69 00:06:57,300 --> 00:07:04,260 on the base protocol stacks that OPC foundation created. So if we look at uh some of the top 70 00:07:04,260 --> 00:07:12,520 products today that implement OPC UA we can see that most of them are using OPC foundation core 71 00:07:12,520 --> 00:07:22,060 libraries. So for example the OPC foundation dot net is actually the the actual first OPC UA 72 00:07:22,060 --> 00:07:30,860 dot net uh protocol stack. So the the vendors created products that use the core libraries and 73 00:07:30,860 --> 00:07:38,780 added a little bit uh of their own touch or their own code to modify it but in essence they're still 74 00:07:38,780 --> 00:07:42,500 using the same protocol stack as the core libraries so that's where the problem is. So this is a kind of a 75 00:07:42,500 --> 00:07:51,100 So we wanted to find vulnerabilities in the base protocol stocks so we will not exploit or 76 00:07:51,100 --> 00:07:56,700 find vulnerabilities in just one product rather we will exploit all of them or at least a big 77 00:07:56,700 --> 00:08:03,560 portion of them. And to do this we created a very long list of different OPC UA protocol 78 00:08:03,560 --> 00:08:10,360 stocks and products and we tried to divide them into different categories. So we picked 79 00:08:10,360 --> 00:08:20,220 different protocol stocks from C to C++, Python, Java, basically any modern programming 80 00:08:20,220 --> 00:08:26,720 language and we divided all of these products to different categories which in each category is 81 00:08:26,720 --> 00:08:34,400 based on a very similar protocol stock. In this way if we found a bug or a vulnerability in one 82 00:08:34,400 --> 00:08:40,320 of the core libraries of a specific category we could exploit all of the product that 83 00:08:40,360 --> 00:08:46,820 used the same core. So before we dive in into the vulnerabilities themselves let's go over 84 00:08:46,820 --> 00:08:57,880 quickly how OPC UA is implemented. So in OPC UA we have this concept that is called nodes. So in 85 00:08:57,880 --> 00:09:05,540 OPC UA everything is a node. For example our water level variable is a node of type variable and 86 00:09:05,540 --> 00:09:10,340 it has its own subtype float. So basically it's a variable that has its own subtype float. So 87 00:09:10,340 --> 00:09:19,460 it's a variable that has a value of type float. And in OPC UA also we have the concept of 88 00:09:19,460 --> 00:09:24,760 name spaces so name spaces are kind of containers for nodes and we can have different 89 00:09:24,760 --> 00:09:31,160 name spaces for different purposes. So for example we can have a name space with all the base 90 00:09:31,160 --> 00:09:39,440 nodes and we can create our own name space that extends different objects for our purposes. In name 91 00:09:39,440 --> 00:09:47,720 namespaces we have the nodes so therefore nodes are identified by namespace ID and also node 92 00:09:47,720 --> 00:09:53,980 ID. So if we want to refer to a specific node in the entire address space we'll need to 93 00:09:53,980 --> 00:10:01,180 specify the namespace and the identifier. Now since the specifications are very very 94 00:10:01,540 --> 00:10:07,500 thorough and uh detailed uh they also tell us how to encode these nodes. So for example in 95 00:10:07,500 --> 00:10:13,340 the specification they tell us that uh we can encode uh namespace with a single byte and 96 00:10:13,340 --> 00:10:18,600 identify with two bytes and we actually looked at the specification in order to understand how 97 00:10:18,600 --> 00:10:24,500 to implement it ourselves so it was very uh beneficial for us to read the specification and 98 00:10:24,500 --> 00:10:31,680 understand this. In OPC UI we also have this concept of services so uh services is our 99 00:10:31,680 --> 00:10:37,140 interaction with the server and by activating some kind of a services and we can activate 100 00:10:37,140 --> 00:10:43,240 different services on different nodes. So for example if we want to read a variable or a tag we 101 00:10:43,240 --> 00:10:49,620 can use the read service to read its value. If we want to write to it we'll use the OPC UI write 102 00:10:49,620 --> 00:10:55,680 service. So services are very uh is our way to interact with the server and actually to 103 00:10:55,680 --> 00:11:01,880 implement OPC UI you need to implement a lot of these services. So if we sum up uh this uh crash 104 00:11:01,880 --> 00:11:07,120 course uh so we have uh for in our example for example uh uh a uh a uh a uh a uh a uh a uh a uh a uh a 105 00:11:07,140 --> 00:11:14,140 tag water tank in our water tank we want to monitor this process um so the water level in our 106 00:11:14,140 --> 00:11:21,280 OPC UI model will be a variable of type float and if we want to read it we will use the read 107 00:11:21,280 --> 00:11:27,940 service from our HMI and our HMI will continuously read this variable using OPC UI the read 108 00:11:27,940 --> 00:11:36,720 service. Sorry for the boring stuff let's go uh to some more exciting stuff. Uh so we have uh uh 109 00:11:37,140 --> 00:11:43,280 research we researched OPC UI for a very long time. And uh when we came up to start this 110 00:11:43,280 --> 00:11:51,120 research we needed to come up with a plan. So we started with buying two Intel NUCs uh which are 111 00:11:51,120 --> 00:11:58,540 very powerful computers somewhat powerful. Uh and we installed uh VMware E6I on those uh NUCs. 112 00:11:58,600 --> 00:12:05,500 Uh we did this because we wanted to install many many products from uh different categories. So for 113 00:12:05,500 --> 00:12:13,080 example to install OPC UI servers, OPC UI clients, OPC UI uh protocol gateways uh and also 114 00:12:13,080 --> 00:12:18,720 different protocol stocks and SDKs. So we needed a lot of different virtual machines in order to 115 00:12:18,720 --> 00:12:26,400 install all of these products so we could research their binaries or review the code. And to do 116 00:12:26,400 --> 00:12:33,280 this we started to build our own client. So we wanted a way to interact with these products and 117 00:12:33,280 --> 00:12:40,860 we wanted a way for us to uh kind of poke these servers to reach some uh code path. And we 118 00:12:40,860 --> 00:12:48,760 decided from very early on the research to build our own uh protocol stack. So we wanted to build 119 00:12:48,760 --> 00:12:54,880 our client that we could easily modify or change and play with the different packets. We also 120 00:12:54,880 --> 00:13:00,940 wanted hands on experience with OPC UI. So we wanted to understand better how objects are created. 121 00:13:00,940 --> 00:13:09,680 We wanted to understand better how uh services are being used. And so we used we created our own 122 00:13:09,680 --> 00:13:18,080 client to make sure we really understand how OPC UI is being used. After building our client uh 123 00:13:18,080 --> 00:13:24,280 the next step for us was to have some kind of fuzzers running passively in the background. Uh so 124 00:13:24,280 --> 00:13:30,600 we wanted uh something to fuzz all of the products that we installed and we had dozens of 125 00:13:30,600 --> 00:13:36,220 products installed in our in our uh environment and we created our network fuzzer. Uh so the 126 00:13:36,220 --> 00:13:42,560 network fuzzer uh was based on bufuz framework. Uh it's uh very convenient to easily write uh 127 00:13:42,560 --> 00:13:49,400 network fuzzers based on this framework. Uh and we implemented six different services including 128 00:13:49,400 --> 00:13:58,020 grid, browse, write, etc. Uh and we fuzzed them all on all the product. So we had dozens uh or 129 00:13:58,020 --> 00:14:00,580 even more than dozens of uh uh products installed. Uh so we had uh a number of products installed. Uh 130 00:14:00,580 --> 00:14:06,200 fuzzers trying to exploit or at least find crashes in all the products that we installed. 131 00:14:06,440 --> 00:14:12,660 And it was actually very beneficial because it helped us to find a couple of bugs and we also 132 00:14:13,100 --> 00:14:19,260 released it as open source so now vendors are using this as part of their security development 133 00:14:20,280 --> 00:14:30,000 cycle. We also created coverage based fuzzers so at one point we found NCC OPC UA stock so it 134 00:14:30,000 --> 00:14:37,400 was a source code of the implementation of a protocol stock and we took it, we created some 135 00:14:37,400 --> 00:14:45,240 harnesses with lib fuzzer and AFL and we also ran this for a couple of weeks. Unfortunately we 136 00:14:45,240 --> 00:14:52,780 did not find any bugs mostly because Kaspersky did the same thing a few years ago but it was still 137 00:14:52,780 --> 00:14:59,680 very helpful for us because we created a lot of corpuses so we created a way to reach a certain 138 00:14:59,680 --> 00:14:59,980 code and we were able to do that. So we were able to do that. So we were able to do that. So 139 00:14:59,980 --> 00:15:04,820 this gives us the source code path within these products. Finally we needed a way to control 140 00:15:04,820 --> 00:15:11,400 all the fuzzers, all the running fuzzers. So we built umm a slack bot that monitors all the 141 00:15:11,400 --> 00:15:16,660 different fuzzers and whenever we reached the crash we received a notification and also a 142 00:15:16,660 --> 00:15:22,220 screenshot so it was very helpful for us to monitor these hundreds of fuzzers running in our 143 00:15:22,220 --> 00:15:29,320 infrastructure. And it also it also helped us to understand what's going on and keep, uh, 144 00:15:30,540 --> 00:15:39,020 and getting the status every single time. Next, while we have all of our fuzzers running in 145 00:15:39,020 --> 00:15:45,720 the background, we wanted to move on and do some manual research. So we turned out to the 146 00:15:45,720 --> 00:15:52,140 specification and started to understand and look for esoteric and complex features and 147 00:15:52,140 --> 00:15:58,820 mechanisms. So basically we asked ourselves, what will developers overlook when implementing 148 00:15:59,320 --> 00:16:07,080 the specification? And just to give you an idea what it means, let's go over this example. So 149 00:16:08,110 --> 00:16:16,020 when we read the message header specification, so in OPC UA we have a very strict way to send 150 00:16:16,020 --> 00:16:22,040 OPC UA messages and part of these messages we have the header. And inside the header we have a 151 00:16:22,040 --> 00:16:29,300 flag saying whether the message we're sending is complete or whether it is chunked. So we can 152 00:16:29,320 --> 00:16:35,080 send a very, very, very big, long message and we can send and we can divide it into different 153 00:16:35,080 --> 00:16:42,280 chunks and send each chunk every time. So in the header we have a way of saying, of notifying the 154 00:16:42,280 --> 00:16:49,380 server whether this specific packet is a chunk or it's the final message and now it needs to 155 00:16:49,380 --> 00:16:54,960 process all the different chunks we sent. So we asked ourselves, what happens if we're 156 00:16:54,960 --> 00:16:59,300 sending the server a chunk and another chunk and another chunk? And the answer is no. So we're 157 00:16:59,320 --> 00:17:04,660 sending a chunk without ever sending the final chunk. What will happen? The server will 158 00:17:05,320 --> 00:17:12,800 terminate the session, the server will crash. So these types of features we tried to research and 159 00:17:12,800 --> 00:17:20,420 explore. So let's move on to the cool stuff. The vulnerabilities and exploits. And we'll start 160 00:17:20,420 --> 00:17:26,540 with the denial of service scenarios. Obviously denial of service is a big deal when we're 161 00:17:26,540 --> 00:17:29,300 talking about ICS or Scudam. Because, you know, it's a big deal. It's a big deal. It's a big deal. 162 00:17:30,120 --> 00:17:37,780 Shutting down a server might mean shutting down an entire factory. So obviously we wanted to 163 00:17:37,780 --> 00:17:43,220 research and explore denial of service scenarios. For example, what happens if we're able to 164 00:17:43,220 --> 00:17:50,840 crush the OPC UA server? And to do this we did not just want to think about, okay, a single 165 00:17:50,840 --> 00:17:59,300 crash or something that our father found. We actually approached it from a very thorough way, I would say. 166 00:17:59,320 --> 00:18:06,820 Because we created ourselves categories. For example, uncontrolled memory management. And we followed 167 00:18:06,820 --> 00:18:13,980 these categories to find specific attacks against these categories. So we actually, when we 168 00:18:13,980 --> 00:18:21,880 reversed engineered the code or when we did the code review, we tried to think what will cause 169 00:18:21,880 --> 00:18:27,200 uncontrolled memory management. Or what will cause a thread deadlock. And we followed different 170 00:18:27,200 --> 00:18:29,300 code paths that we believed will get us to a deadlock. And we followed different code paths that we believed will get 171 00:18:29,320 --> 00:18:36,300 us to this point. So if we take example, the chunk floating, as I started to describe earlier, 172 00:18:36,920 --> 00:18:43,940 then as I mentioned, we have in the OPC UA header, we have the chunk type. This is the flag I was 173 00:18:43,940 --> 00:18:52,860 referring to. And it has two main values. C or F. C means this specific packet is a chunk. And it's 174 00:18:52,860 --> 00:18:59,300 part of a longer chain of chunks. And F means this is the final chunk. And now you need to 175 00:18:59,320 --> 00:19:06,600 process all the previous chunks. If we look at different servers, for example, this is the OPC UA 176 00:19:06,600 --> 00:19:15,680 .NET stack. We will see an if statement checking for is final meaning is the flag F. And if so, 177 00:19:15,860 --> 00:19:23,440 stop processing the message. Stop to receive more chunks and start to process the entire message. 178 00:19:23,700 --> 00:19:29,300 So what we did was simple. We sent a lot of chunks. And we just needed to process the whole 179 00:19:29,300 --> 00:19:38,020 never sent the final chunk. And finally the server crashed. So we used this vulnerability not 180 00:19:38,020 --> 00:19:43,980 once. So it was not an off one vulnerability. We actually used this vulnerability against 181 00:19:44,400 --> 00:19:50,620 different protocol stocks because apparently many developers did not think what will happen if 182 00:19:50,620 --> 00:19:56,720 they will receive a lot of different chunks. And we're able to exploit and actually crash a lot 183 00:19:56,720 --> 00:20:05,320 of different OPC UA servers. Another example from our use after free category is method 184 00:20:05,320 --> 00:20:12,000 calling from a dead session. Now it turns out that in OPC UA we have a way to activate 185 00:20:12,000 --> 00:20:19,760 methods remotely. So we can configure in the OPC UA server a method. For example here we have a 186 00:20:19,760 --> 00:20:26,660 method to multiply two nodes and these nodes are obviously from type integer or float. And 187 00:20:26,720 --> 00:20:35,560 we have a way to activate this message remotely by sending a method activation or invoke. Now we 188 00:20:35,560 --> 00:20:40,820 looked at the specification and we noticed something very interesting. It actually says in 189 00:20:40,820 --> 00:20:50,480 the specification what if the if the method calling is created from a session and we actually 190 00:20:50,480 --> 00:20:56,700 send a lot of different methods and then terminate the session. The specification say that the method 191 00:20:56,720 --> 00:20:57,260 calling is created from a session and then terminate the session. The specification say that the 192 00:20:57,260 --> 00:21:03,520 server should not return answer to the client because the session is terminated. Obviously we 193 00:21:03,520 --> 00:21:10,060 thought ourselves OK. What happens if the developers did not implement this correctly? So what 194 00:21:10,060 --> 00:21:18,860 will happen if we will send a very long list of methods for example 255 methods in an array for the 195 00:21:18,860 --> 00:21:26,380 OPC UA server to start processing and we terminate our session in between. So how it looks like? 196 00:21:26,420 --> 00:21:26,700 We have a very long list of methods. So we have a very long list of methods. We have a very 197 00:21:26,720 --> 00:21:32,280 we're preparing a lot of methods to send to the server, we're sending all these methods to 198 00:21:32,280 --> 00:21:38,760 the server, the server starts analyzing all the methods and in between we're terminating our 199 00:21:38,760 --> 00:21:45,520 session. Now the server continues to process all the methods and finally it needs to send 200 00:21:45,520 --> 00:21:51,980 back the result to the client. However the session is gone and if developers are not 201 00:21:51,980 --> 00:21:57,580 implementing this correctly they will try to dereference non-existing session which will 202 00:21:57,580 --> 00:22:05,580 result with an access violation. So again this was, this scenario was based on something we read 203 00:22:05,580 --> 00:22:10,780 in the specification and we thought ourselves will be interesting to implement. And by the 204 00:22:10,780 --> 00:22:16,880 way all the attack vectors are implemented in our uh framework, exploit framework uh which 205 00:22:16,880 --> 00:22:21,960 you can access uh through GitHub and we'll show you later how to access it. Okay, so 206 00:22:21,980 --> 00:22:29,040 the null of service is okay uh I mean we can cross over into a scan networks, but that's 207 00:22:29,040 --> 00:22:35,780 not a big deal enough. We wanted to have a way to remote code execution. We wanted a way to control 208 00:22:35,780 --> 00:22:42,800 the OPC UA server and maybe modify these tags. So for example not just crushing the opposite 209 00:22:42,800 --> 00:22:48,000 service, but actually change the water level from zero to one hundred and change how 210 00:22:48,000 --> 00:22:51,960 factories and change how the physical process looks like. This news come back totally episode. It makes 211 00:22:51,960 --> 00:22:58,940 is much more interesting. So, uh, we decided to research, uh, the PTC capware. Um, this is a 212 00:22:58,940 --> 00:23:05,360 very popular software. Uh, it's one of the industry leading, uh, OPC UA servers used in the 213 00:23:05,360 --> 00:23:11,260 biggest manufacturing lines including oil rigs, wind farms, uh, etc. Uh, it's Windows based, 214 00:23:11,460 --> 00:23:18,220 uh, 32 bits implemented as a server, as a service. And we, we, we searched this, uh, product 215 00:23:18,220 --> 00:23:25,960 for, uh, quite some time. By the way, uh, we all, we also let our fuzzer to fuzz this, uh, 216 00:23:26,740 --> 00:23:33,280 process, uh, and this, uh, product for quite some time. And, uh, one day, uh, at night, uh, we 217 00:23:33,280 --> 00:23:38,800 received a notification from our slack bot, uh, that there is a crash. Uh, and at the beginning 218 00:23:38,800 --> 00:23:45,920 we were very spectac-spectacled that, uh, it's not a real crash. Um, but our researchers, uh, 219 00:23:45,920 --> 00:23:52,560 Uri and Vera, started to look at it and they discovered it has something to do with, uh, string 220 00:23:52,560 --> 00:24:02,140 manipulation. So, they tried to get even deeper into this, what happened exactly in the process 221 00:24:02,140 --> 00:24:07,060 of converting strings and they discovered something very interesting that we'll cover now. 222 00:24:07,860 --> 00:24:14,160 In OPC UA, uh, we needed to encode our strings in some way and transfer it over the network line. 223 00:24:14,160 --> 00:24:22,720 So, uh, if we, for example, have, uh, a tonic ID in our example, we have a tonic ID, uh, or a 224 00:24:22,720 --> 00:24:28,940 tonic location name, uh, then we need to encode the string, as you can see here, in some way, uh, 225 00:24:29,100 --> 00:24:36,540 and send it over the line to the OPC UA server. Now, in OPC UA, all the strings are UTF-8 226 00:24:36,540 --> 00:24:44,140 encoded. But, some of the servers are using UTF-16. For example, Kepler is using UTF-16 227 00:24:44,160 --> 00:24:51,840 as a way to encode the strings. So, whenever Kepler read the strings from the packet, it 228 00:24:51,840 --> 00:24:58,760 actually tried to convert from UTF-8 to UTF-16 and there we noticed the crash. So, there was 229 00:24:58,760 --> 00:25:06,800 something in the conversion between UTF-8 to UTF-16. So, before I explain what 230 00:25:06,800 --> 00:25:14,140 happened, let's go over what is UTF-8 and UTF-16 encoding. UTF-8, uh, uh, is a very good 231 00:25:14,160 --> 00:25:24,500 encoding that we can uh represent symbols for example uh the letter A with some bits uh for 232 00:25:24,500 --> 00:25:34,020 example A is uh 41 hexa. But if we have other symbols that are bigger than uh 7 f hex we 233 00:25:34,020 --> 00:25:42,400 need uh we need another byte to represent this symbol. So for example uh this funny looking A 234 00:25:42,400 --> 00:25:51,240 is represented as a C380. So some bytes or sorry some symbols are represented as a single 235 00:25:51,240 --> 00:25:57,920 byte and some symbols are represented as 2 bytes or 3 bytes or even 4 bytes. And capware 236 00:25:57,920 --> 00:26:04,000 whenever it received a message OPCA message with a string it tried to understand how many 237 00:26:04,000 --> 00:26:11,000 symbols are within this string. Why? Because it needed to understand how to allocate memory for 238 00:26:11,000 --> 00:26:12,380 the UTF-8 uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh uh 239 00:26:12,400 --> 00:26:19,780 UTF-16 conversion. So for example if we're sending uh this string capware will try to 240 00:26:19,780 --> 00:26:27,360 understand how many symbols are inside. So it knows that 41 means one symbol and C3 probably 241 00:26:27,360 --> 00:26:35,520 means 2 symbols because this is above 7 f. And so it tries to calculate how many symbols we 242 00:26:35,520 --> 00:26:41,440 have. For example here we have one symbol represent represented with 1 byte. Another symbol 243 00:26:41,440 --> 00:26:47,660 represented with 1 byte. Another one with another byte. And we have a symbol this funny 244 00:26:47,660 --> 00:26:53,660 looking A with 2 bytes until it reaches a null terminator. And whenever it reaches a null 245 00:26:53,660 --> 00:27:00,900 terminator it stops and calculating exactly how many symbols it has so it could convert it to 246 00:27:00,900 --> 00:27:11,260 UTF-16. But what happens if we're sending just the C3 at the end? Capware will probably think it's 247 00:27:12,280 --> 00:27:18,220 symbol, one symbol represented with two bytes and will jump two bytes. So let's see how it 248 00:27:18,220 --> 00:27:24,120 happens. So we have the 41 which is one symbol, one byte. 41, one symbol, one byte. Another 249 00:27:24,120 --> 00:27:33,280 one. And then we have C3. C3 in Kepler logic means to jump two bytes. So it will jump above 250 00:27:33,280 --> 00:27:39,200 the null terminator and we're starting to jump on the heap. And this means we will jump on 251 00:27:39,200 --> 00:27:46,680 the heap until we're reaching another null terminator and we could leak data. So we actually 252 00:27:46,680 --> 00:27:53,840 used this vulnerability in order to leak a lot of data from the heap. But we also were able to 253 00:27:53,840 --> 00:28:01,400 leverage this further. So first of all, leaking data from the heap, we used the read tag. So for 254 00:28:01,400 --> 00:28:09,100 example, if we want to read variables or tags from the OPCA server, we'll use the read service 255 00:28:09,200 --> 00:28:16,480 and we could just specify the node ID. Uh so node ID and namespace ID. And we could read the 256 00:28:16,480 --> 00:28:24,640 tag. Tag information. But if we're sending uh if the the node is encoding with a C3 at the end, 257 00:28:24,760 --> 00:28:32,120 whenever Kepler will try to convert, we'll start to read data from the heap. So we used it to 258 00:28:32,120 --> 00:28:39,100 leak a lot of data from the heap. And this way we were able to leak pointers and defeat ASLR. We also 259 00:28:39,200 --> 00:28:46,520 did kind of the opposite. So we used the write service in order to write memory into the heap. 260 00:28:46,660 --> 00:28:53,140 And we used the write functionality. So for example, we wrote a tag that ends with C3. And 261 00:28:53,140 --> 00:28:59,260 whenever Kepler tried to convert it from UTF-8 to UTF-16, we started to write, overwrite the 262 00:28:59,260 --> 00:29:07,600 heap. So now we had uh uh out of bound read to leak pointers and defeat ASLR. And we also had out 263 00:29:07,600 --> 00:29:14,680 of bound write to construct our rope chain and eventually get remote code execution. So uh our 264 00:29:14,680 --> 00:29:21,240 researcher Uri uh we're able to really convert it into a full chain. And first of all he used uh 265 00:29:21,520 --> 00:29:29,080 the leak uh primitive to leak a lot of data from the heap. Then he overwrote uh he calculated some 266 00:29:29,080 --> 00:29:35,780 addresses uh that are needed in order to create our rope chain. Overwrote some uh information on 267 00:29:35,780 --> 00:29:37,580 the heap. And finally triggered a block. So we were able to convert it into a full chain. And we 268 00:29:37,600 --> 00:29:40,120 cleared the bug and got full remote code execution. 269 00:29:47,850 --> 00:29:52,940 Great. So we covered the denial of service scenarios. Also remote code execution 270 00:29:52,940 --> 00:29:58,300 scenarios in OPCA servers. Let's see how to do this with remote code execution in clients. 271 00:30:01,660 --> 00:30:07,380 Okay. Thank you very much Sharon. Uh like Sharon said at this point we exploited many different 272 00:30:07,600 --> 00:30:15,780 products. It started with OPCA uh uh servers. Also some OPCA gateway protocols. But that's when 273 00:30:15,780 --> 00:30:22,560 we thought to ourselves let's try and look at clients as well. Now what is the usual suspect and 274 00:30:22,560 --> 00:30:27,080 like the immediate thing that you think about whenever you're talking about exploiting OPCA 275 00:30:27,080 --> 00:30:33,820 clients? Well it might look like this. We have an OPCA client connecting to a rogue or malicious 276 00:30:33,820 --> 00:30:40,180 OPCA server. And whenever he does it, he tries to read, write or interact with different tags. 277 00:30:40,460 --> 00:30:48,520 And somehow by returning malicious data uh the server is able to exploit and run code and execute 278 00:30:48,520 --> 00:30:54,340 code on the OPCA clients. Now when we realized this is the attack scenario we thought to 279 00:30:54,340 --> 00:31:00,900 ourselves yeah we looked at pretty much logical bugs and memory corruptions and these are very 280 00:31:00,900 --> 00:31:03,640 very tough. Meaning they take a lot of time to research but when you do these things, they go to 281 00:31:03,640 --> 00:31:03,700 the right direction. So you just don't want them to be active. So we did our own way to get 282 00:31:03,820 --> 00:31:11,200 fully exploit and it's not that easy. I mean, just on the memory corruption Sharon showed you just now, to actually fully exploit it on 283 00:31:11,200 --> 00:31:17,940 Windows 10 machine, it takes months and months and many of our researchers like Uri worked on it for a very long time. 284 00:31:18,340 --> 00:31:25,100 However, we thought to ourselves, maybe there's an easier way to exploit OPC UA clients that are less relevant to OPC UA servers. 285 00:31:25,700 --> 00:31:33,440 And that's when we looked at two very, very popular OPC UA clients, being Inductive Automation Ignition and 286 00:31:33,440 --> 00:31:41,280 Softing Data Feed Edge Aggregators. Now, this is kind of the big names in OPC UA clients. These are SCADA and data 287 00:31:41,280 --> 00:31:47,500 servers that also have the functionality to connect to an OPC UA server and read and write tags to it. 288 00:31:47,780 --> 00:31:54,260 However, one more thing they have in common is that they are both web based. Meaning they are used from a 289 00:31:54,260 --> 00:32:00,720 browser by a client and connect to the Ignition, Inductive Automation Ignition server using web 290 00:32:00,720 --> 00:32:03,420 browser. And that's when we thought to ourselves, maybe this is the right way to exploit OPC UA. So, 291 00:32:03,440 --> 00:32:09,440 yeah, web browsers are a little bit easier. What can we do in them? Well, of course, the main 292 00:32:09,440 --> 00:32:15,600 functionality in OPC UA clients is reading, writing or subscribing to tags. Meaning I want to read a 293 00:32:15,600 --> 00:32:21,820 variable, so I'll read or write to it. That's when we thought to ourselves, yeah, let's say this 294 00:32:21,820 --> 00:32:27,800 scenario will happen. We have our OPC UA client connecting to our malicious server and trying to 295 00:32:27,800 --> 00:32:33,420 read a tag. Like in Sharon's example, trying to read the water level. Well, this is a very, very 296 00:32:33,420 --> 00:32:37,280 simple scenario. So, whenever it tries to read a tag, our server simply says, yeah, sure, here you go, 297 00:32:37,320 --> 00:32:43,720 read a tag. However, instead of returning actual value, like a float number or a string, we return a 298 00:32:43,720 --> 00:32:51,140 simple XSS script tag, which then the client takes and inserts it into its DOM. Now, whenever it 299 00:32:51,140 --> 00:32:56,540 inserts into its DOM, it simply executes it and we have the ability to execute code in the 300 00:32:56,540 --> 00:33:02,940 context of the client's browser. And as it turns out, both of these servers are actually 301 00:33:02,940 --> 00:33:08,960 have an XSS vulnerability in the reading and writing tag functionality. Meaning we were able to, 302 00:33:09,020 --> 00:33:15,360 as you can see here, achieve alert in softening and, of course, in ignition as well. Now, XSS is 303 00:33:15,360 --> 00:33:20,300 pretty cool, but I guess all you can do with it is maybe re-crawl the user. I mean, it's not 304 00:33:20,300 --> 00:33:27,000 remote code execution per se. That's when we thought to ourselves, how can we take it further and 305 00:33:27,000 --> 00:33:32,920 actually leverage our XSS vulnerability into achieving a full-on remote code execution on the 306 00:33:32,920 --> 00:33:39,440 ignition, the inductive automation ignition and softening edge aggregator servers? Well, as it 307 00:33:39,440 --> 00:33:44,860 turns out, we actually chained multiple vulnerabilities in both servers in order to achieve 308 00:33:44,860 --> 00:33:49,380 the remote code execution vulnerability. So, let's take a look at both of these exploitation 309 00:33:49,380 --> 00:33:55,820 chains and see how easy it was in comparison to the full-on pledged memory corruption 310 00:33:55,820 --> 00:34:00,540 vulnerability we showcased to you before. So, in the case of ignition, one of the main 311 00:34:00,540 --> 00:34:02,900 functionalities the server offers is that it's able to execute a full-on memory corruption 312 00:34:02,920 --> 00:34:09,020 ability to import and basically upload a new project. Now, in this project, we can set up 313 00:34:09,020 --> 00:34:13,880 something called gateway events. What's gateway event, you might ask? Well, basically, it's a 314 00:34:13,880 --> 00:34:20,600 callback script that we can add that will be executed whenever a certain thing happens. Like in 315 00:34:20,600 --> 00:34:25,920 this case, we're talking about a script being executed every few seconds on a scheduled event. 316 00:34:26,400 --> 00:34:32,320 Now, inductive automation ignition chose to allow users to add Python code to their gateway 317 00:34:32,920 --> 00:34:40,660 events. Meaning, by simply having our, by simply uploading our callback script, we are able to 318 00:34:40,660 --> 00:34:48,020 execute arbitrary Python code and achieve remote code execution on the ignition server. Now, this 319 00:34:48,020 --> 00:34:55,160 was a whole chain starting from the XSS in the OPC UA client read. However, we also wanted to look 320 00:34:55,160 --> 00:35:01,080 at softening and try and exploit a few functionality there. Well, in softening, we don't have a 321 00:35:01,080 --> 00:35:02,880 project upload. However, we have software that is able to do that. So, in softening, we don't have a project upload. However, we have 322 00:35:02,920 --> 00:35:07,880 something that could be similar. Procedure restore. Meaning, we want to restore our old 323 00:35:07,880 --> 00:35:13,860 configuration of the server and go back in time and basically have the old settings. Well, 324 00:35:14,000 --> 00:35:20,300 whenever we do it, perform a procedure restore procedure, we actually upload a zip file to the 325 00:35:20,300 --> 00:35:26,320 server. And the server basically unpacks it and loads an XML and configuration files from this 326 00:35:26,320 --> 00:35:32,800 zip. Well, we looked at the softening server and found a few vulnerabilities involving zip 327 00:35:32,920 --> 00:35:38,380 slip and Pratt traversal. Meaning, we had the ability to basically write files anywhere in the 328 00:35:38,380 --> 00:35:45,160 system whenever we invoke the procedure restore. And by uploading a shared object that will 329 00:35:45,160 --> 00:35:51,140 execute code whenever it is loaded, we are able to execute code on the server, allowing us to 330 00:35:51,140 --> 00:35:56,300 basically control it and having remote code execution on both servers. Now, these 331 00:35:56,300 --> 00:36:02,160 exploitations started from the OPC UA vector. Meaning, we had the ability to execute code in the 332 00:36:02,160 --> 00:36:07,260 context of the browser. However, by chaining it with a few different vulnerabilities, we are 333 00:36:07,260 --> 00:36:12,960 able to achieve full on remote code execution on the client, allowing us basically to exploit it as 334 00:36:12,960 --> 00:36:20,380 well and achieve fully off pledged remote code execution. Now, everything we showed you is 335 00:36:20,380 --> 00:36:28,000 pretty cool and pretty extensive. However, during the development of this entire process and 336 00:36:28,000 --> 00:36:32,060 research, we developed our own exploitation framework that we're going to share with you 337 00:36:32,060 --> 00:36:38,080 today. And like Sharon showed you, we researched dozens and dozens of different protocols and we 338 00:36:38,080 --> 00:36:44,020 actually discovered over 50 unique CVAs. I think we are getting closer to 60 at the moment. And 339 00:36:44,020 --> 00:36:49,960 developed a lot of the, what we call attack concept. Meaning, one vulnerability, one kind of 340 00:36:49,960 --> 00:36:54,520 logic flaw that could affect multiple different servers and multiple different products. 341 00:36:55,200 --> 00:37:01,860 That's why we created our own OPC UA client and our own actually OPC UA exploitation framework that you 342 00:37:01,860 --> 00:37:08,280 can feel free to clone it and scan it and do it for your own. And this framework is pretty 343 00:37:08,280 --> 00:37:13,640 extensive and contains the entire knowledge base that we researched in the last few years. And we 344 00:37:13,640 --> 00:37:19,700 hope it will be useful. And basically it is released as an open source project. So feel free to 345 00:37:19,700 --> 00:37:28,760 download it from our GitHub account. And in this framework you'll find the full on POC script and 346 00:37:29,500 --> 00:37:31,840 exploitation techniques of all of the OPC UA projects. So, we're going to show you some of the 347 00:37:31,860 --> 00:37:37,260 different attacking scenarios we developed. Like the chunk flooding that Sharon showed you. Like 348 00:37:37,260 --> 00:37:45,540 the capware vulnerability in the UTF-8 beta location and bed string concatenation. And of course 349 00:37:45,540 --> 00:37:51,900 dozens and dozens of other vulnerabilities we uncovered over the last three years. So feel free to 350 00:37:51,900 --> 00:37:59,340 use it and feel free to share it and use it in your own servers, environments, etc. So, let's 351 00:37:59,340 --> 00:38:01,400 summarize everything up and see the entire. 352 00:38:01,860 --> 00:38:06,620 Process we've done. So, like Sharon told you, during the last three years we researched 353 00:38:06,620 --> 00:38:12,780 Pwn2Own heavily. We researched OPC UA heavily. Mainly as the Pwn2Own contest. However, also on 354 00:38:12,780 --> 00:38:17,440 our own. Looking at different products, different OPC UA implementation, protocol stacks, code 355 00:38:17,440 --> 00:38:24,560 bases, etc. We found and discovered over 50 vulnerabilities, exospecies, protocol stacks that 356 00:38:24,560 --> 00:38:30,120 affects dozens and dozens and actually probably thousands of different OT environments. And work 357 00:38:30,120 --> 00:38:35,960 closely with the vendors to fix every vulnerability and disclose it to them and make sure that the 358 00:38:35,960 --> 00:38:41,960 environments are more safe and more secure. We actually gave them early access to our OPC UA 359 00:38:41,960 --> 00:38:48,240 exploitation framework and we can basically giving the OPC UA vendors and developers the ability 360 00:38:48,240 --> 00:38:53,300 to test their products. Again, the different attack techniques we developed and look for bugs in 361 00:38:53,300 --> 00:38:58,700 their own code base. And we are happy to say that a lot of them used it and actually found new 362 00:38:58,700 --> 00:39:04,620 vulnerabilities using our own OPC UA exploitation framework. So, please do use it as well in 363 00:39:04,620 --> 00:39:10,940 your OT environments, in your products, etc. Use it. Add to it. It is open source. And so of 364 00:39:10,940 --> 00:39:16,160 course you can contribute to it as well. And thank you very much for our talk, for attending our 365 00:39:16,160 --> 00:39:18,020 talk on OPC UA. Thank you very much.