00:00:00.133-->00:00:03.804 >>All right it’s about that time to get the show on the road so everyone please give a very warm 00:00:03.804-->00:00:08.809 welcome to Thiago who will be talking about hacking PLCs. [applause] >>Sorry I have a 00:00:21.355-->00:00:26.360 little experiment. Sorry I have a little experiment here and uh it took a little longer to set 00:00:29.196-->00:00:34.201 up than I was expecting but I am very very happy to be here at Defcon today and uh I was 00:00:37.704-->00:00:42.709 honestly expecting like 50 maybe a hundred people so thank you guys for taking the time to be 00:00:45.078-->00:00:51.485 here on Saturday morning and listen to me. Uh I am Thiago Alves and a little bit about me, 00:00:51.485-->00:00:56.490 about me uh I am a PhD student at UAH and I also work um at the center for cybersecurity 00:01:01.295-->00:01:04.831 research and education it’s called CCRE at the University. And uh yeah this what I do I 00:01:04.831-->00:01:06.833 love to hack stuff and I try to break as many things as I can. Um and I'm also the creator of 00:01:06.833-->00:01:08.835 the open PLC project if you guys haven't heard of it you'll hear about it a little bit today. 00:01:08.835-->00:01:10.837 Hands up if somebody have heard about PLC before. Wow thank you that's great. Wow that’s great, 00:01:10.837-->00:01:14.741 thank you. [applause] Also today um it’s a very important date for me because this trip to 00:01:14.741-->00:01:19.279 Vegas marks our 9th year anniversary. Me and my wife were together for 9 years and uh 00:01:19.279-->00:01:24.518 yeah. [applause] I used to have more hair back then, but she is still pretty the same way. So 00:01:24.518-->00:01:29.523 I’m a lucky guy. And uh she always complain about being like slowing me down because now we 00:01:31.692-->00:01:37.698 have kids and I have other things to focus on but I keep telling her that if you want to 00:01:37.698-->00:01:44.438 go fast you go alone. Life is not about speed. But if you want to go further, if you want to go 00:01:44.438-->00:01:49.943 far, you go together. That's why I'm here, that's because of you. Alright. And I’m very happy I 00:01:49.943-->00:01:54.948 invited her to be here at my talk. [applause] Thank you. And she has a very important job 00:02:02.923-->00:02:07.928 actually because I have really bad jokes and she laughs of all of them so if you hear her 00:02:36.556-->00:02:43.430 laughing just please laugh as well so we have a nice presentation. Ok? Ok. So a 00:02:43.430-->00:02:49.369 little outline about today. Um I’ll I’m gonna um start with background info, you know a 00:02:49.369-->00:02:54.274 little bit about PLCs, if you guys know about PLCs I’ll try to go fast. If you guys don’t know 00:02:54.274-->00:03:00.313 about PLCs please pay attention because I will go fast. K. Then we’ll go and talk about little 00:03:00.313-->00:03:06.153 attack vectors, some stuff we can do to break those things, and finally we’ll demo if the 00:03:06.153-->00:03:10.691 demo demons haven’t gotten me because I did not have time to set up so hopefully things will 00:03:10.691-->00:03:13.727 go out fine. So what is a PLC after all? Uh it is, that’s what it looks like right, it’s a 00:03:13.727-->00:03:17.097 brick and uh it stands for Programmable Logic Controller and basically it’s a digital 00:03:17.097-->00:03:22.102 computer, right? It’s used in automation since 1970 so it’s a long time ago. And uh basically 00:03:25.705-->00:03:30.710 it is an embedded system with a CPU with some RAM, some ROM, right, some flash nowadays, you 00:03:36.083-->00:03:41.088 put your program in there, you run your program and uh your program decides what to do with 00:03:44.391-->00:03:50.030 the input data it senses from the in-in-input modules the PLC has. So PLC has a bunch of 00:03:50.030-->00:03:55.035 inputs, a bunch of outputs, um I have 3 PLCs set up here trying to heat water and um they’re 00:03:58.972-->00:04:03.910 doing a poor job doing that. Uh but then you program those devices to any logic you want 00:04:07.481-->00:04:12.385 and it has output modules to control real life stuff, right? So like for example in this 00:04:12.385-->00:04:16.890 setup it’s controlling the heater based on the temperature setter that's attached to the 00:04:16.890-->00:04:22.963 input module. And you will see PLCs in many different places. So here I have like a damn, a 00:04:22.963-->00:04:28.502 substation, a gas distribution system and a petrochemical fac-facility. Um PLCS are there. 00:04:28.502-->00:04:33.507 And imagine what happens if you hack into those PLCs and make it crash,k right? Or change a 00:04:36.576-->00:04:41.581 setting. So for all those situations disaster will follow if you break into a PLC because 00:04:44.451-->00:04:50.423 they’re controlling large huge stuff that can cause even physical damage and life loss, 00:04:50.423-->00:04:55.428 right? So what is the problem with the current PLCs we have? First of all they are freaking 00:04:57.731-->00:05:03.470 expensive. You know if you're building an embedded system it shouldn't cost that much. 00:05:03.470-->00:05:09.876 Nowadays there is some companies selling what they call cheapo PLCs. They can uh you can buy 00:05:09.876-->00:05:14.748 one for like a hundred or 2 hundred dollars but then they get you on software..Uh there 00:05:14.748-->00:05:19.319 are companies selling software programming, software for PLCs, for up to 5000 dollars per 00:05:19.319-->00:05:24.324 station. And that is ridiculous, right? That is ridiculous. And uh also they rely on legacy 00:05:27.294-->00:05:33.233 technology. PLCS were built like 40 years ago. That's also a major problem because this 00:05:33.233-->00:05:40.006 legacy technology was created at a time when the internet didn't exist. So uh they used insecure 00:05:40.006-->00:05:46.646 protocols to communicate um most companies rather patch their devices instead of redesign. 00:05:46.646-->00:05:53.620 We’re in a situation where we need redesign and they’re close sourced. So it’s a problem if 00:05:53.620-->00:05:59.025 you’re researcher and trying to figure out how they work. So I came up with a solution if you 00:05:59.025-->00:06:05.398 guys know about it. Open PLC, that’s my thing. Right? Open PLC is the world’s first and only 00:06:05.398-->00:06:11.371 one PLC available with the full source code. They are other approaches that people try to 00:06:11.371-->00:06:18.044 develop their own PLCs, but it is not close to what a PLC should look like. Uh PLC the 00:06:18.044-->00:06:24.551 there are many standards that define what a PLC should do and how it should bhave and I try to 00:06:24.551-->00:06:31.191 follow those standards close uh so that it will look like a real PLC and behave as much as 00:06:31.191-->00:06:36.663 possible to a real PLC and make the source code available anyone can go take a look at the code 00:06:36.663-->00:06:43.036 and use it. It is free, right? And basically open PLC has 3 main components, the runtime 00:06:43.036-->00:06:47.540 that is the big thing that I am creating, uh is the that goes into the embedded system, 00:06:47.540-->00:06:53.146 embedded device and initially i started creating my own hardware but then I gave up and started 00:06:53.146-->00:06:58.151 using raspberry pi and arduino and stuff that everybody have. So you can load the runtime on 00:07:00.253-->00:07:06.626 you embedded system and have it read your PLC programs. You create your PLC programs on the 00:07:06.626-->00:07:11.798 editor that’s supposed to run on your computer, right, on your windows linux machine some 00:07:11.798-->00:07:18.271 people have boarded it to mac os as well. And uh the third portion of it is scadabr which 00:07:18.271-->00:07:24.411 is a GUI builder that allows you to build nice animated graphical screens for your PLC um um uh 00:07:24.411-->00:07:29.416 programs, right. So for the open PLC runtime it runs on many different platforms. These are 00:07:33.320-->00:07:38.892 the platforms that are currently supported, officially supported, like I said raspberry pi, 00:07:38.892-->00:07:45.265 arduinos, but also there are some industrial uh devices that people created that also runs on 00:07:45.265-->00:07:51.137 open PLC like unipi and pixtend. Uh this is really cool you can go and buy those devices and and 00:07:51.137-->00:07:56.209 install open PLC today if you want. There are other devices that are not here that are not 00:07:56.209-->00:08:00.413 officially supported that were created by the community so I have a forum with lots of people 00:08:00.413-->00:08:05.585 in there and they you know make all sorts of questions and uh they also contribute to the 00:08:05.585-->00:08:11.424 project and they created unofficial pat-patches that uh make open PLC run on like orange 00:08:11.424-->00:08:17.030 pi and other platforms that basically run linux. This is the editor what it looks like. Uh it 00:08:17.030-->00:08:21.835 supports five programming languages this these are all the 5 languages uh the 5 on the 00:08:21.835-->00:08:26.840 standard. And this is ScadaBR right. Uh this is a real nice graphical screen created on 00:08:28.942-->00:08:33.213 ScadaBr so it can create many things. This is the water temperature control you're gonna 00:08:33.213-->00:08:38.218 see today. So lets gonna talk about PLC protocols for a bit. Uh I don’t know if you touch 00:08:42.655-->00:08:47.660 what I on Scada protocols before but what it looks like, there problems with those protocols um 00:08:51.364-->00:08:56.369 basically most protocols today are derived from legacy serial networks so if you’re old enough 00:08:58.905-->00:09:04.711 you might remember those RS-485 networks where you hook up a bunch of devices on the serial 00:09:04.711-->00:09:08.982 cable and all the devices receive the same message and decide if they want to accept it 00:09:08.982-->00:09:14.621 or not. This is great for hacking right. Uh you just listen to the bus and you get 00:09:14.621-->00:09:19.392 everything. Uh there’s no authentication of course. There’s no integrity and when I 00:09:19.392-->00:09:24.964 mean integrity I’m not talking about error correction I’m talking about if someone tampers 00:09:24.964-->00:09:29.969 the message is that gonna be uh uh figured out at the other end or not. So they don’t have any 00:09:33.940-->00:09:40.647 integrity mechanisms and there’s no confidentiality so the message goes um on on-on-on the 00:09:40.647-->00:09:45.652 field with no um no confidentiality which means it it goes in plain text right. So 00:09:48.888-->00:09:55.595 the most popular Scada protocol is modbus. It’s about 90 percent of the PLCs support that. 00:09:55.595-->00:10:00.567 Actually I haven’t found any PLC that does not support modbus. They usually support their own 00:10:00.567-->00:10:06.773 protocol plus something else plus modbus. Everybody talks modbus. And uh in essence modbus 00:10:06.773-->00:10:13.580 is very simple. There’s nothing very complicated with that. Uh it’s of course based on serial 00:10:13.580-->00:10:19.185 networks and uh the commands basically how it works is that the commands for the the 00:10:19.185-->00:10:23.289 protocol are encoded into function codes. SO you have different function codes for 00:10:23.289-->00:10:28.628 different things you want to do. And it’s open. That’s probably why everyone supports modbus 00:10:28.628-->00:10:33.800 because it doesn’t require any licensing. You can go and pay modbus foundation to have your 00:10:33.800-->00:10:39.038 device certified os that they make sure your device is actually following in the full 00:10:39.038-->00:10:43.343 standards but you don’t have to do that to support the protocol. There’s no licensing right 00:10:43.343-->00:10:48.348 licensing fee. Uh and this is the modbus frame that’s how what it looks like. Basically it has 00:10:52.352-->00:10:57.957 the first byte is a slave ID. Uh and the slave ID is a unique address because it was based on 00:10:57.957-->00:11:02.362 serial networks so you have to have a way to address the device. The function code is 00:11:02.362-->00:11:09.035 what what I was talking about. It tells the slave device what to do, it it's like the command 00:11:09.035-->00:11:13.273 it should obey right. And the function code varies from reading or writing to more 00:11:13.273-->00:11:18.278 memory areas. Data, well data is data, right. It depends on the function code you’re using. And 00:11:21.014-->00:11:26.753 finally CRC uh it is just error correction verification. Again this does not check integrity of 00:11:26.753-->00:11:31.724 the message itself it’s just checking if there are any physical errors that happened on 00:11:31.724-->00:11:37.096 the transmission right. If somebody can tamper this frame, change the date recalculates the 00:11:37.096-->00:11:43.803 CRC and send it through it will go right it will be accepted by the PLC. So those are the most 00:11:43.803-->00:11:48.808 used function codes. Um there is um function codes to read digital output, to read digital 00:11:51.077-->00:11:55.181 inputs, and also to read and write registers. Basically all it is is working with memory. So 00:11:55.181-->00:11:57.183 modbus gives you free access to the PLC memory you can read whatever you want you can write 00:11:57.183-->00:11:59.185 whatever you want with no authentication. Who loves that? Right. Uh they updated modbus to 00:11:59.185-->00:12:01.120 make it compatible with TCPIP networks, what it mean is that they added a frame on top of the 00:12:01.120-->00:12:03.122 modbus frame so basically it has a transaction ID to keep track of all the transactions you’re 00:12:03.122-->00:12:08.127 making so if the host makes a transaction it makes a random number on that transaction ID so 00:12:11.764-->00:12:16.769 when it receives a response it might receive a bunch of response from the same slave 00:12:20.607-->00:12:25.612 device and uh it will match the transaction ID to make sure that response is related to the query 00:12:27.814-->00:12:32.819 it was making. Uh protocol ID it seems that originally modbus on TCP was meant to work on other 00:12:37.423-->00:12:42.428 protocols as well so they created this field so that different values on that field 00:12:52.372-->00:12:57.377 will mean different protocols. I’ve never seen anybody using anything different than 00. And 00:13:00.246-->00:13:06.686 00 stands for modbus so I think they failed on this. Uh length is length. [laughs] Right. How 00:13:06.686-->00:13:11.691 many bytes there are after it. And after that is just plain uh serial modbus frame as it was 00:13:13.960-->00:13:18.965 before. They kept the slave ID byte on that frame because some people will just convert between 00:13:21.100-->00:13:25.672 TCIP networks and serial networks. So you have all devices talking serial and new 00:13:25.672-->00:13:30.677 devices talking TCP so keeping that byte over there means that serial devices will also be able 00:13:33.212-->00:13:38.618 to receive that message, right. Even though if they are addressed on TCP. Uh for TCP 00:13:38.618-->00:13:43.623 only PLCs usually that that bye means nothing. They will accept anything. Attack scenarios. What 00:13:45.892-->00:13:52.532 can we do with this? So you can create a few a few different attacks on that. Because the 00:13:52.532-->00:13:57.737 message is so simple you can just interrupt the communication cause a denial of service and 00:13:57.737-->00:14:02.608 there are many ways to do that. Uh you can intercept the message and read the contents because 00:14:02.608-->00:14:07.613 there’s no encryption no uh um confidentiality at all. You can also modify the message. You get 00:14:10.016-->00:14:15.021 the message you get uh uh bump in the wire or some sort of ether cap R poisoning hack and 00:14:17.056-->00:14:23.396 you you get the message since its plain text you modify the contents send it back yeah. That 00:14:23.396-->00:14:28.401 is pretty disastrous. And my favorite. Injection. You can only just send a freaking frame. 00:14:31.671-->00:14:36.676 The PLC will accept you right. It accepts everybody. So let’s demo it. Hopefully it will work. 00:14:42.815-->00:14:47.820 So I have here ScadaBR. And uh let me start the last PLC I didn’t have the time to do it. 00:14:50.757-->00:14:55.762 Um. Hopefully I will now uh let me get back to ScadaBR. So this is ScadaBr for you to get 00:15:04.971-->00:15:11.577 familiar with it. Uh it’s it’s an old tool but it works very well and I incorporated it into 00:15:11.577-->00:15:16.582 the whole PLC project so so that we can update it and and renovate it over time. So here I 00:15:18.584-->00:15:24.257 have all my data sources. These are all my PLCs. So here on the table I have 3 different PLCs. 00:15:24.257-->00:15:29.262 The first one here is open PLC running on unipod platform this is an industrial platform um the 00:15:32.365-->00:15:37.370 second one is an Allen-Bradley micrologics 1400 series and the third one is um a Schneider 00:15:41.440-->00:15:46.445 modicon m 221. So let me go ahead and try to turn them all on. Hopefully they they’re good. 00:15:49.549-->00:15:56.088 Okay. So let me start this PLC as well. In the meantime while this thing is starting let me 00:15:56.088-->00:16:01.027 show you the graphical screen and see how it looks like. So these um this screen shows my my 00:16:08.668-->00:16:15.608 system my setup here. So what I have as I said before I have a cup filled with water and um a 00:16:15.608-->00:16:20.680 water heater element inside it and a temperature sensor right. The temperature sensor is 00:16:20.680-->00:16:27.286 connected to the PLC. So I have 3 identical setups. And since PLCs love ladder logic I just 00:16:27.286-->00:16:31.791 created the same ladder logic for all the same 3 PLCs. So they are running identical logic 00:16:31.791-->00:16:37.129 programs. Of course each architectural just inter-interprets that logic 00:16:37.129-->00:16:42.635 differently internally right. Some will compile that to binary code that’s a case for Open PLC. 00:16:42.635-->00:16:47.940 Some will just convert that to virtual machine that will just run uh interpreted instructions. 00:16:47.940-->00:16:54.080 Um so it varies by vendor but they all in essence doing the same logic. I just copy paste 00:16:54.080-->00:16:59.886 the same ladder diagram to make sure that they are all running the same thing, ok? So on that 00:16:59.886-->00:17:05.391 configuration I have uh flexibility here that I can set the PLC for mangual mode uh turn 00:17:05.391-->00:17:10.563 on the heater if I want manually so you can see the heater going up here just a little break to 00:17:10.563-->00:17:15.568 turn on the PLCs sorry. Um and uh I can turn the heater off. I can put it in auto mode so the 00:17:19.939-->00:17:21.941 auto mode will try to keep the temperature around 40 degrees celcius and you know temperature 00:17:21.941-->00:17:23.943 is a slow thing so it might go up slowly and go down slowly. Um but in essence all the PLCs are 00:17:23.943-->00:17:28.948 trying to keep that around 40 except this third little one because it’s not on yet. Sorry 00:17:31.417-->00:17:36.422 about that. Uh let me just log in here. And in one second I will turn it on. So my job here 00:17:43.596-->00:17:48.601 it try to attack these PLCs. Once I am in in the network I’ll show you how easy it is to 00:17:50.803-->00:17:55.808 create a modbus frame and um attack it. Right? Last click. Not yet. Uh. Ok. It should be 00:17:58.678-->00:18:03.616 good to go. Let me start it. Yes I want. By the way this is somachine basic this is the 00:18:07.186-->00:18:12.191 software used to program the Schneider modicom m221 we will have a lot of fun with that 00:18:14.226-->00:18:19.231 software today. Um ok. So let me start my terminal here. Um. So I have a injection attack ready. 00:18:26.772-->00:18:31.777 What this injection attack does is uh it-it tries to send modbus packets that will switch the 00:18:34.246-->00:18:40.419 PLCs in manual mode and keep the heater on. Right? And this will this message will be sent over 00:18:40.419-->00:18:44.924 and over and over again so that the operator will lose control of the PLC and will not be able 00:18:44.924-->00:18:49.929 to turn it off right. So I’ll start the attack and I’ll this little attack uh I hate sound. 00:18:52.598-->00:18:57.003 This little attack has 2 parameters I created this software by the way everything 00:18:57.003-->00:19:02.842 is available on my github so if you wanna get those tools go ahead you have it. So it has 2 00:19:02.842-->00:19:08.914 parameters the first one is the host. So the host is 100 100 100 100 because I’m really bad with 00:19:08.914-->00:19:14.053 numbers I had to choose a good one. And uh the other para-parameter is frequency I 00:19:14.053-->00:19:20.826 won’t use it the default frequency is 1000 messages per second. So let's try that on 00:19:20.826-->00:19:25.831 open PLC. Go. Alright cool. Heater is on. Let’s turn it off. [clicking] Well doesn’t work. So 00:19:34.073-->00:19:39.512 let’s put in auto mode. [clicking] It doesn’t work either! I’m screwed. Right. 00:19:39.512-->00:19:41.514 [audience laughter] So that’s probably what the operator will be thinking. You see the 00:19:41.514-->00:19:43.516 temperature going up and you can’t do anything about it. And all it takes is sending freaking 00:19:43.516-->00:19:45.518 modbus frames. Right? That’s all it takes. What I’m doing here is writing to a portion of the 00:19:45.518-->00:19:47.520 memory to the PLC that I know its its storing the setting for manual or auto mode and the 00:19:47.520-->00:19:49.522 other area that is storing the setting for the heater if it’s on or off. That’s all it takes. 00:19:49.522-->00:19:54.527 Right. And I can guarantee you that this kind of attack works with 100% of the PLCs that I 00:20:08.941-->00:20:13.946 know of. [Chuckles] Right? Um so ok. Let’s stop this because I have boiling water already. And 00:20:21.353-->00:20:26.358 let me put back on auto mode and we’ll shut off the heater. Now let’s start try this same thing 00:20:28.627-->00:20:33.632 with our friend Allen-Bradley. It is at the same IP except 101. I know I’m bad with numbers. So 00:20:36.735-->00:20:41.741 let’s try that again. Boom. Oh gosh no. It’s on. [clicking] Doesn't work. Right. Auto mode 00:20:45.911-->00:20:50.916 does not work. Temperature will go up. And uh yeah. It it works the same way you see different 00:20:56.555-->00:21:03.496 brand of PLC freaking same modbus protocol that’s the culprit ok. Let me stop this. 00:21:03.496-->00:21:08.501 Auto mode again. Last time last attack lets try that on the Schneider modicom please 00:21:11.837-->00:21:16.842 misbehave. Ok it’s on even though the temperature is also over the set point. [clicking] 00:21:19.812-->00:21:24.817 It does not work either. Right. So um that’s how simple it is. You can today start creating 00:21:27.586-->00:21:32.591 your own PLC attacks. Ok let me stop this. Now um this was this was pretty fun and uh I had a 00:21:43.169-->00:21:48.174 lot of fun creating this but I have one more thing. For those of you who are fan of Steve Jobs 00:21:50.209-->00:21:56.649 this is where the best part happens right. So let’s talk about micrologics. Micrologics 00:21:56.649-->00:22:03.222 is a PLC from Allen-Bradley. Um and Rocco Automation I don’t know the history who bought who 00:22:03.222-->00:22:08.227 but they keep both names and so I just say both names. But what-what are the fun facts 00:22:10.596-->00:22:16.135 about micrologics 1400 series you should be buying one today to hack it’s pretty fun device. 00:22:16.135-->00:22:22.141 Right so first of all it runs VxWorks. VxWorks is one of the most popular uh real time 00:22:22.141-->00:22:27.646 operating systems on the industry it’s on everything right including PLCs and there 00:22:27.646-->00:22:32.885 are a bunch of vulnerabilities reported for that device. Guess what? I bet most of those works 00:22:32.885-->00:22:34.887 with Allen-Bradley as well. Right? It is one of the most popular Allen-Bradley PLC uh you 00:22:34.887-->00:22:39.191 see that everywhere and it supports modbus TCP that’s why the injection attack works. Uh 00:22:39.191-->00:22:44.196 this is my favorite feature. It can be killed remotely by sending a bad modbus packet. 00:22:53.939-->00:22:58.944 This is great. So um let me talk about this what I called micrologics deadly packets. 00:23:00.946-->00:23:05.951 Basically all it takes uh it’s a trick the memory [indiscernible] memory allocation algorithm of 00:23:08.687-->00:23:13.692 the um micrologics PLC. So what I do is I start a new transaction ID uh protocol of 00:23:16.729-->00:23:21.734 course it uh um modbus 00 and on the length field I say I’m I’m I will need 20 256 bytes right. 00:23:27.740-->00:23:32.745 But I only have 6. Uh alright. So it might try to allocate that much memory but it’s only 00:23:35.347-->00:23:41.320 receiving less than that. And right immediately after I start a new transaction ID where the 00:23:41.320-->00:23:46.759 length is the length of the previous packet and its incomplete. It stops at the unit 00:23:46.759-->00:23:53.065 ID. So it makes the PLC confused with this memory management system and I cause a buffer 00:23:53.065-->00:23:59.538 overflow writing that that uh message on a different area of the device crashing the device 00:23:59.538-->00:24:04.476 and making it unrecoverable. So let’s try to do that. Ok. Alright. So just to check here I 00:24:12.084-->00:24:18.957 should have everybody running wow I left that PLC on for too long. [laughter from audience] 00:24:18.957-->00:24:23.696 Alright uh so we’re targeting Allen-Bradley now it should be working fine its all just put on 00:24:23.696-->00:24:28.434 manual mode to prove like the heater is on, the heater is off, everything should work 00:24:28.434-->00:24:35.341 beautifully. Auto mode should keep the heater off. Let me just keep that on heater on so that 00:24:35.341-->00:24:40.346 iwll be more fun . Uh let me go it’s hard to type when you’re uh hands are shaking. [laughter 00:24:45.617-->00:24:50.622 from audience] uh should be Allen-Bradley exploit. This is also available on my github um 00:24:54.727-->00:25:00.466 so all the only argument it takes is the IP address of the PLC. So all it does it send 00:25:00.466-->00:25:05.471 those 2 deadly packets and lets see what happens when I do it. Dead. So you’ll see right now 00:25:09.641-->00:25:13.812 that the PLC is not communicating anymore. You see the exclamation point all 00:25:13.812-->00:25:16.415 around? Ha dead. How cool is that right? [audience applause] You can even try to press the 00:25:16.415-->00:25:18.417 buttons over there it’s completely dead and you know the fun fact of it is if you if you 00:25:18.417-->00:25:20.419 power cycle it still dead. [audience laughter] I’ll prove it. I just power cycled it and 00:25:20.419-->00:25:25.424 it will boot again it managed to boot again but the fault LED keeps on for some reason. So 00:25:53.252-->00:26:00.159 yeah it it it is booting up and you still see the exclamation points here you wil see it til 00:26:00.159-->00:26:06.131 the end of the presentation. So the point the problem is that that application got corrupted 00:26:06.131-->00:26:12.371 so the PLC cannot launch it again. Uh the fault mode is always on. The only way to make 00:26:12.371-->00:26:17.376 it work again si to reprogram it with the ladder logic. This is creepy right. So um if you lost 00:26:19.745-->00:26:24.750 the ladder logic you screwed. Please don’t send it on uh the wild. There are too many 00:26:26.885-->00:26:31.890 micrologics PLCs out there. Uh alright. Let’s behave. Um ok let me see if I have something else. 00:26:38.330-->00:26:43.335 Uh this is um a problem that affects all micrologics 1400 series. I don’t know about 00:26:45.504-->00:26:51.510 others because I’m not rich to buy all the PLCs but I bet it also affects some other related 00:26:51.510-->00:26:58.217 series like 1100 and so. Uh I talked to Allen-Bradley through ICS-CERT to publish this 00:26:58.217-->00:27:03.989 vulnerability and uh they are really nice they responded back and tried to work with me to 00:27:03.989-->00:27:08.994 create a patch so they uh they released recently about few months ago a firmware update uh 00:27:11.630-->00:27:17.169 this firmware update fixes this vulnerability although it’s a pain to update it. I spent like 00:27:17.169-->00:27:22.875 half an hour trying to do that and um I’m supposed to be a security expert. Imagine people 00:27:22.875-->00:27:29.181 out in the field what they will do to try to update this thin they won’t right. They won’t 00:27:29.181-->00:27:34.186 stop their factory to update their PLC firmwares. Hopefully the new PLCs that will be sell 00:27:34.186-->00:27:39.191 sold now will have this new update uh already built in. Uh there are other mitigations 00:27:42.394-->00:27:48.967 where please disable modbus TCP. This is not a fix. Dude if you’re disabling the protocol 00:27:48.967-->00:27:53.972 you’re not fixing it you’re just disabling it uh right. So this mentality is common for all the 00:27:56.275-->00:28:02.848 PLC vendors that I usually talk to. Uh minimize network exposure. Put PLCs behind a 00:28:02.848-->00:28:08.453 firewall. So basically what what they are telling you is the security is on you right we 00:28:08.453-->00:28:14.726 don’t provide security. You’re freaking alone. So try to do your best. Um these are good 00:28:14.726-->00:28:19.331 practices but I honestly believe that a PLC the device itself should provide any sort of 00:28:19.331-->00:28:24.336 security. And one last thing. Alright. Schneider that’s there’s a special reason why I 00:28:26.471-->00:28:31.476 brought the Schneider PLC with me. Um the Scheider has a protocol that is common to all 00:28:33.879-->00:28:40.852 the modicom family and I think other families also use this. It’s called unity protocol at 00:28:40.852-->00:28:45.857 least me and some other researches are working with this call it unity. Or UMAS you might 00:28:48.293-->00:28:55.000 hear both names. And this protocol is obscure. It is undocumented. It runs on top of 00:28:55.000-->00:28:59.938 modbus TCP so you have normal modbus transaction uh but when you have function code 0X5A the 00:29:02.641-->00:29:05.210 access decimal over 5A this triggers the subprotocol that runs on the data field of the 00:29:05.210-->00:29:07.212 modbus frame and uh the for the modbus documentation 5A is uh reserved function code for 00:29:07.212-->00:29:12.217 specific vendors, specific um functions right. Uh and this is nice part. This protocol is used 00:29:24.763-->00:29:29.768 to configure and monitor the PLC down to the operating system level. You can do a total memory 00:29:32.170-->00:29:37.175 dump using this protocol right. You can get the freaking operating system image using 00:29:39.745-->00:29:44.750 that. So this is this is crazy right. Um it’s proprietary and undocumented um so they try to 00:29:48.654-->00:29:54.393 make secure by obscurity but that won’t prevent us from figuring that out how it works. 00:29:54.393-->00:30:00.265 So um basically you need to have a bunch of function codes so it’s a functon code insde a 00:30:00.265-->00:30:05.270 function code right. You have the modbus frame and then you have the unity frame and these 00:30:05.270-->00:30:11.209 are uh the function codes you can play with. And I have to thank Luis Liras uh he um is a 00:30:11.209-->00:30:15.580 researcher on the same field we started talking and communicating like uh one year 00:30:15.580-->00:30:20.585 ago because i figured he was working on the unity devices as well and we started contributing 00:30:20.585-->00:30:25.590 to each other and he has a very nice blog liras en la red dot xyz if you go if you want you 00:30:27.659-->00:30:34.232 can go and check it out he has step by step how he managed to get those function codes and 00:30:34.232-->00:30:39.938 reverse engineer the DLLs for the somachine basic and get that information so this is pretty 00:30:39.938-->00:30:44.943 cool and uh basically you can take a look at some um messages here um they’re pretty cool like 00:30:47.245-->00:30:52.250 read memory block. [speaker chuckles] This is my favorite. Ok so um but today given the 00:30:54.519-->00:30:59.524 time constraint we’ll only play with a few of those so basically uh we’ll start a communication 00:31:02.527-->00:31:09.067 an ed communication we’ll read a project info to reap some data about the project uh this is all 00:31:09.067-->00:31:14.072 so cool take PLC reservation. It means that the PLC needs to be connected to someone. Someone 00:31:14.072-->00:31:19.611 needs to reserve the PLC uh if you take the PLC reservation you’re taking the other party 00:31:19.611-->00:31:26.551 down. This is DOS built in the protocol dudes. [audience laughs] This is what? Right? So 00:31:26.551-->00:31:32.924 you just keep setting this take PLC reservation and I think nobody else can connect so um 00:31:32.924-->00:31:39.798 release PLC reservation you’re uh releasing it because you just don’t want to communicate 00:31:39.798-->00:31:44.803 anymore and um um start PLC and stop PLC will basic main functions to start and stop the 00:31:52.377-->00:31:57.382 PLC. Alright. So um let’s play with it. I’ll just keep this slide open so we can play a 00:32:03.188-->00:32:08.193 little bit with how it works. Is that up? Ok. So I created also a little software m-modicum tester 00:32:17.769-->00:32:22.774 I don’t remember the name of the executable. Ok. So this is software was created in C sharp 00:32:25.010-->00:32:30.015 in a hurry. Please don’t look at the code it’s messy. But the good thing is it works. Uh and 00:32:33.685-->00:32:38.723 all I did was created this thing to help me reverse engineer the protocols so it basically 00:32:38.723-->00:32:43.562 encapsulates my messages on the modbus frame with the function code 5a so I can send anything 00:32:43.562-->00:32:48.567 and it will be accepted as unity messages right. So all you do you connect to the PLC it’s 00:32:50.735-->00:32:55.740 already set up with the uh m221 IP address. I connect and then it gives me the access decimal 00:32:58.276-->00:33:03.782 output and the access key related to that. So let’s start by starting our communication so 00:33:03.782-->00:33:08.787 every function code has uh 2 bytes. 0001 and I’ll end it with 00. So it just gave me back a hi 00:33:14.292-->00:33:19.297 I’m here that’s fine. Hello. So let’s go ahead and uh release PLC reservation if somebody was 00:33:23.602-->00:33:28.607 talking to it sorry and I’ll take the reservation. Ten zero zero. And now the take 00:33:32.711-->00:33:37.682 reservation is an interesting thing. I don’t know if you can see it sorry I should have make 00:33:37.682-->00:33:42.687 it bigger but I’ll promise I’ll read it right. Uh the message is is sending me back with the take 00:33:45.790-->00:33:50.795 PLC reservation it-it ends with a magic byte. In this case it’s 8e. Right it’s even smaller for 00:33:54.499-->00:34:01.206 me. So 8e means it’s this magic byte that I need to send before an message that I want to send 00:34:01.206-->00:34:07.379 now on now that I have a session I have a reservation I have reserved the PLC for me uh I’ll 00:34:07.379-->00:34:12.350 have to use this magic byte. That means that um before people were trying to do replay attacks 00:34:14.986-->00:34:17.789 so the replay attacks would be successful just because they didn’t’ have any session 00:34:17.789-->00:34:21.559 management so you could just get messages that the uh the main station was sending and just 00:34:21.559-->00:34:23.561 replay that and it will work. Now you need the session number but that won’t prevent us from 00:34:23.561-->00:34:25.563 sending stuff. Right? So now let’s let’s play with this. I have 8e as my session number um 00:34:25.563-->00:34:27.565 you can see here oh urgent Allen-Bradley’s not talking still. Sorry. Sorry dude. You 00:34:27.565-->00:34:29.567 can see that the modicum is still working fine. Temperature is 40 degrees celcius I can turn 00:34:29.567-->00:34:34.572 the heater on manually and off right. It works. So um what I'll do here I will send a stop PLC 00:34:39.044-->00:34:44.049 command so I need to start with my 8e. And then the stop message is 41. It ends with FF00. And 00:35:12.677-->00:35:17.682 lets see. Stopped. Now the PLC can still communicate but the heater is off. I cannot turn it 00:35:21.219-->00:35:27.459 on. I cannot turn it off. I cannot put it on auto or manual mode. It’s off. How cool is 00:35:27.459-->00:35:34.099 that? [audience laughs] So uh just by sending a few messages, I can uh have few control of the 00:35:34.099-->00:35:40.672 PLC. But here comes my favorite feature of this protocol. This is really interesting. So I’m 00:35:40.672-->00:35:46.945 gonna use the somachine basic here for a second. Let me just create something new. So I’m 00:35:46.945-->00:35:51.950 just using their application to talk to the PLC over here. Right. And uh when I click here 00:35:54.352-->00:35:59.357 it already identified my PLC I try to log in and it’s trying to log in but this application is 00:36:01.593-->00:36:06.598 password protected. How come? So I cannot access my PLC without the password if I try to type 00:36:09.467-->00:36:14.472 anything um it won’t give me access right? Alright. What can we do about it? Ok. Let me get 00:36:19.477-->00:36:24.482 back to my unity tester here. So remember that message read project info? For some reason 00:36:27.886-->00:36:32.891 that thing doesn’t even require a session. So I’ll go ahead and send this zero zero new session 00:36:35.960-->00:36:42.000 zero three is the function code for that and zero zero. Zero zero is just get the header um 00:36:42.000-->00:36:47.005 so let’s see what comes out of it. My header for the project that is stored on the PLC and 00:36:49.774-->00:36:54.779 this is the name of the project. What is this? Yes. The freaking password. [audience laughter and 00:37:01.586-->00:37:08.393 applause] Right? So if I were Steve Jobs and I was working at Schneider I would say this is 00:37:08.393-->00:37:12.630 not a bug it’s a feature. [audience laughter] What if you forgot the password? The device 00:37:12.630-->00:37:17.635 needs to tell you that. Right? So let’s try it. Defcon is my password. So when I type Defcon. 00:37:23.842-->00:37:28.847 Boom! I mean super hard. Right? Now I have full control of the PLC again using their own 00:37:33.685-->00:37:40.458 software just because I stole the password. And it works. I’ve tried with different uh slightly 00:37:40.458-->00:37:45.463 different types of modicoms m m something serious and uh the same thing works. So yeah you 00:37:47.699-->00:37:54.038 can play with that uh I can start the control of it because I stopped it before and I can 00:37:54.038-->00:37:59.043 see the programming on it uh yeah. I have full access. So this is pretty hilarious. Um now 00:38:02.714-->00:38:07.719 that’s to show you how secure PLC is and imagine that those things are controlling your 00:38:10.355-->00:38:15.660 nuclear power plants and your water filtration systems. [Speaker sighs] I’ll just go 00:38:15.660-->00:38:20.665 live in a jungle. So Schneider also they were also really nice. I submitted this through 00:38:23.601-->00:38:28.606 ICS-CERT and they talk with me and we try to come up with some mitigations and they they 00:38:31.476-->00:38:38.316 recommended the following things. Disable unity protocol. [audience laughter] This is the 00:38:38.316-->00:38:43.288 best mitigation ever. So again you see a different vendor with the same mentality. Just turn 00:38:43.288-->00:38:49.627 that freaking thing off. It doesn't work. Right? They also recommended because of that 00:38:49.627-->00:38:55.366 password vulnerability and all all of that they recommended to store your project files in 00:38:55.366-->00:39:00.305 secure access re-restricted locations and encrypt your project files reputable third 00:39:02.340-->00:39:08.146 party file encryption tools. Again they’re giving you the responsibility to fix stuff, to 00:39:08.146-->00:39:13.151 to secure your settings. Um and this is pretty uh it gets me worried right. And a little bit 00:39:16.120-->00:39:21.125 about that what I plan to do on the future um by the way I haven’t showed you this. This is 00:39:24.095-->00:39:29.834 what open PLC looks like. This is a web interface that is running on the device so once 00:39:29.834-->00:39:34.839 installed the one time you have that interface up and you can see your programs uh you can see 00:39:37.242-->00:39:43.414 your hardware you can even mess up with the code live right so it’s pretty cool. Um and uh this 00:39:43.414-->00:39:48.786 thing is also vulnerable and insecure I created it to be like that because I’m trying to mimic 00:39:48.786-->00:39:54.926 what other vendors are doing so we can kinda research about it but um my PhD thesis is about 00:39:54.926-->00:39:59.931 creating a secure version of open PLC that uh will try to prevent those types of attacks 00:40:02.200-->00:40:07.205 from happening ok. So it was really fun to be here at Defcon today um it was really an honor 00:40:11.743-->00:40:16.748 to me to be here and thank you very much for coming and staying with me this Saturday morning. 00:40:18.983-->00:40:22.287 If anybody have any questions [applause from audience].