It's time to... Yesterday, if you were in here, we saw a Teddy Ruxpin get hacked. And today we're going to do something a little bit different. We're going to do power plants. So this is going to be very exciting. Let's give Joss and Marina a big round of applause. Have a good time. Good morning. Thank you so much to all of you for coming here. So today we will present to you an effort, what it takes to design embedded exploits to actually cause physical damage in industrial facilities from the beginning to the end. So briefly about ourselves, I will let Joss to present. Yeah, so my name is Joss Wetzels. I'm an independent security researcher with Midnight Blue, where I mainly focus on different kinds of embedded systems, industrial control systems, automotive, IoT. And I previously worked as a researcher at the University of Portugal in critical infrastructure. So my name is Marina Krotofil. I've been doing... My major specialization is physical damage, and I've been doing it for more than eight years. I presented a lot of works at Black Hat and DEF CON. And so how this combination of us came together is, on one hand, Joss can reverse engineer and develop exploits and implants for any embedded system in the world. However, what exactly do you want to do? What do you want to do on that device? And I am... My specialization, hey, here's this power plant, chemical plant, or traffic light system, robotic system. How exactly do you want to cause physical damage? So I will be designing and engineering this exploitation scenario to cause physical damage. And then at the end, I will come up with a set of algorithms which need to be implemented. And there is a long list of tasks which needs to be executed on that embedded system. So with that wish list, I would go to a guy like Joss and say, hey, this is what I need to do on that device. And maybe, like, someone... Somewhere we will also meet in between when we look at the design of the device. Like, hey, the specific design features of the device can be probably used to accomplish, like, simultaneously several tasks. So this is where we would be working together. So this is how the combination came into place. And so this is how we will be presenting the presentation. So after the introduction and industrial control system and safety systems. By the way, how many of you have heard Triton? And I hope that everybody. Good. Because that was our motivation. We also wanted to show, like, in the mass media, this Triton exploit was, like, described as, like, so sophisticated. Like, only state sponsor, only a few people. And we will show you if it's really so. So after the introduction, we will go into the device exploitation. Because at the end, you need to obtain code execution on the device. So after you have code execution, then you start already developing, for example, implant. Backdoors, like, and payloads, which actually targeted, like, design for the physical damage. And, of course, conclusions in the end. As you already probably noticed, I'm speaking very fast. And there is reason for that. Because the topic which we are presenting to you is extremely complex. But we still wanted to show you the process from the beginning to the end. And still, of course, without deep details. And it's already a lot. So it will be fast-paced talk. However, again... Again, the motivation was to show you the full process so that you could see it from the beginning to end. And we will be posting an even longer version of the slides after this talk because we have to cut out certain information. And if you're interested, you can go and review it again. So introduction. So what are the industrial control systems? Well, you probably all know, but it's important to set up a vocabulary so that all of us operate for this talk, operate on the same terms. So industrial control systems, those are computerized systems and network which control physical process. So typically, if you talk about industrial organization, there will be corporate network. There will be another network which is called SCADA or control network. And even though this is the same looking computers, one will be called information technology and another will be called operational technology or OT. Nevertheless, that is still all computing devices. And the guys who deal with those systems are studied typically. Typically, something like computer science. And as long as we are moving towards physical process, this is already engineering science and it's completely different. So the closer we come into the physical process, the computing devices which actually monitor and control physical process, they look already like this. And they're called, we typically know them as embedded systems. So they don't have operating system as we know it. So operating system. Which actually runs the device and executes the programs is called firmware. And since these systems are real-time systems, the entire firmware must be loaded and executed in the memory at all times. So on one hand, the attacker needs to execute code. So the attacker will be executed on this embedded system. So it's still cyber domain in order to cause it physical damage. And basically... Damage, for example, the machinery and operate the machinery as needed. And so when, for example, when the attacker is like going into the like penetrating financial sector, his goal is to steal money in some form. So when the attacker is penetrating the industrial network, his goal is to cause some sort of form of physical damage in the physical domain. It could be also economic damage like spoiling the product. However, in the mass media, typically this physical damage is depicted. It could also be the big explosion. So I see a threat landscape has changed in the past eight years. So I started doing this type of security before it was fashionable and nobody knew about it. Well, like in IT domain, there was a crazy amount of hacking happening all the time. Like industrial control systems lived in bubbles. Nobody knew about them. And then Stuxnet has happened. So it seemed to be like Stuxnet was kind of a trigger. A tipping point because we started seeing more and more publicly known espionage attacks and some ways like we started seeing first publicly known like activities related also ready to recon of the operational technology system. So and from 2015, it started to happen. And so there was two power grid attacks in 15 and 16 and in 17, basically it was announced at the end of 2017 Triton has happened. Uh, what? It? It was attack. I tried to install back door or remote access Trojan on the safety controller. Uh, and it was a big thing because it's, uh, it was picked up by pretty much every mass media, including Wall Street journals, which said that that is very, very, very alarming situation. And, uh, why was Triton is so special? Uh, because it does targeted safety instrumented system. So what does this mean exactly for us? Uh, physical processes are inherently hazardous, so it means that there is like like toxic, flammable liquids, fires and explosion, electrical hazard, moving parts and their machinery. So there are a lot of layers of safety protections to prevent harm or maybe even casualties to humans, first of all, and secondly to prevent environmental damage and also machinery, because it's expensive to kill machinery. So there. Layers of protection starting with the design of the process, then we have a control loop, then we have a human operator who reacts to the alarm. But as soon as the control system and human operator are no longer able to control the process in a safety manner, we have so-called safety instrumented system. That is independent control system which reacts on the hazardous condition and tries to prevent it. So, as you can see, this is the last line of defense before hazardous accident is already happening. So, and the attacker was apparently was trying to disable the system. So, that is actually attack on the civilians, which is not good. So, previously, safety instrumented system are software systems. And because it is a line of defense, typically, it is recommended that they would be run on the isolated and segmented network. But for ease of design and for ease of maintenance, they often are connected together to the main control system. And that allows the attacker to obtain remote access to safety instrumented system. And that was a triconex from Schneider. And it is a very critical safety instrumented system of safety integration. It is integrated level 3, which is only 2% of all hazardous situation, for example, in oil, is of that severity. So, it is very critical safety systems. Triconex is everywhere. For example, you could find it on the swimming ships and so on. So, the attacker obtained remote access to the engineering station, which was connected to the safety controller. So, they got the ability to communicate. So, they communicate to safety controllers. And what an attacker attempted to inject a passive backdoor, or some people refer to it as a remote access trojan, which would allow attacker to read arbitrary memory, write into the memory, for example, shell code for the attack, and then they execute that code. So, even if you have the backdoor, it really means nothing to you, because, I mean, unless you know what you want to achieve in the plant, the backdoor is actually absolutely useless and harmless. So, attack scenario depends on attacker goal. And sometimes it means explosion, but in most cases it does not, because you don't need to over-engineer if you just want to send a warning sign to your enemy or whatnot. And, like, some, you can achieve some simple, like, attacks, like, do not press, there are certain buttons on the HMIs which are so descriptive, like, stop, stop. You can press it and you achieve some effect. But, you know, that is not a long-lasting effect. So, like, yes, the first type of physical attacks were happening at the HMI. Then the attackers moved their exploits, for example, in destroy or crash override. They were executing the attack already at the level of the industrial protocol. But now we have Triton, which is already on the embedded system. So, what's going on? Why the attacker is already moving their exploits into the embedded systems? And we will explain. So, industrial processes are very complicated, and they actually build inherently and designed to be robust and recoverable. So, if the attacker wants to achieve any significant long-lasting damage, they actually need to obtain very specific process, like, very detailed process comprehension, the design, the dynamic behavior of the process physics, and so on. So, for example, like, what causes a pipe to explode? Well, what causes the right pipe to explode? And then, what causes the right pipeline to explode at the right time? And suddenly, the complexity is increasing. So, industrial control systems operate on the control loop principle. So, control systems and human operators, they use sensors to observe the state in the process, and then control systems compute the commands to instruct actuators to control the process and bring it into the right state. So, in a nutshell, when the attacker is moving, they start designing or engineering damage scenario. There are a huge number of tasks which he has to accomplish, like starting from, of course, manipulating the process, but then the attacker needs also to obtain a feedback loop to know whether the process is moving into the right state and he is successful. I've been doing this for many, many years, and I've designed a lot of damage scenarios, and I can tell you that obtaining feedback loop was one of the most hardest tasks to achieve. Because mostly sensors which are installed there in the plant, they're useful, because the attack is something always weird, and the plant was not designed to measure something weird going on. So, you have to do it indirectly. And, of course, because you are trying to bring the process into the wrong state, into the harmful state, the control system and human operators and safety system, they will try to fight you back and to bring process back into the normal state. So, the attacker also has to prevent the response. And tried and false. So, they went into this category, preventing response, because they wanted to prevent response from the safety systems. So, in a nutshell, the cyber-physical attack or damaging attack, that will be a collection of clandestine control loops, because the attacker is becoming a control system. And you have to have the cycle of observation and manipulations to achieve unsafe state. So, attack timing is crucial. So, because process is not vulnerable at all times, so you have to find that vulnerable time. And when the attack has to be executed, the attack coordination is critical. As you have seen, there have been a lot of tasks. And, for example, observation is of state 8 and component B needs to trigger payload XYZ. So, this requires very granular control across the entire process and to manage tasks quantity and timing. So, that was a very nice presentation, even though I've been presenting on this topic a lot of times. Like, many times. So, there have been a nice presentation from Jason Larson, who decided to compare different damage scenarios. And he came up with this timing and state diagram where he divided all the control damage tasks into different tasks, where he also tried to map, like, hey, this is a set of tasks which I need to execute. How do I map them now to the different device and to different implants? And so... Basically, as soon as the amount of tasks which you need to execute to achieve damage is becoming large, you need to have an implant. Because, like, if you use separate tasks, you will not be able to coordinate them. So... And this also allows you... It allows you, actually, to coordinate. So, you can easily then install the coordination between the implants via the communication links or you can implement the routine to detect specific state. So... And it's also much more stealthy, because you don't have, like, anomalous... You do not create anomalous network traffic. So, but before... Like, in order to actually achieve this, to implement an implant, you first have to exploit the device. And you better enjoy extreme programming, because those devices are extremely small, have very limited resources, they're packed with the functionality, so you first have to actually find something what device does not need. Eliminate it, so that you could put your actual exploitation code. So, at the end, Jason came up with this diagram where he has, like, put a score on different tasks and he compared the reliability, because it's not only the reliability of the attack scenario, but it's also reliability of your exploit or implant on the device. And... So, basically, it's kind of... You have to find this trade-off, like, what is the most reliable attacks implant and attack damage scenario and implant stability. So, now, after this long introduction, I am giving back to Jos, and he will walk you through the device exploitation and design and, like, basically implementing. So, now I have my wish list of tasks and I'm giving it to him to implement. All right. Thank you, Marina. So, before we can do all this... So, before we can get, you know, to the cool stage where things are actually exploding, we'll have to get to another cool stage, which is exploiting the device. And, basically, the process is as follows, and I'll walk through these steps. And we start by obtaining the necessary materials. So, we need a couple of things before we can devise an exploit and an implant. And the first thing we'll need is documentation and a lot of it. You know, developer's guide, planning and installation manuals, all that kind of stuff. And... Yeah, in the case of TriConnex, it was very useful that these things are safety certified at a certain level, and that means that all of the documents were available on the website of the U.S. Nuclear Regulatory Commission. So, very detailed information was out there. In other cases, you might have to buy it, but this is the first step you go about. And then the second step was obtaining the engineering software. So, these devices, they're connected to a workstation running, I don't know, Windows XP, with some software that is used to program them. And this software usually contains the functionality for talking to this device and the protocols you want to take a look at. So, you obtain this by just going to the vendor website or asking them nicely, which is the easiest route, or if you have already compromised asset owner networks, you might take it from their own network because you're in there already, so why not grab a souvenir? Or you might go to the various sketchy sources on the internet, like eBay or Alibaba, or open directories hosting this kind of stuff. So, you know, it's usually relatively easy to come by. In the case of TriConnex, we found a TriStation software for the equivalent of three U.S. dollars on some Chinese website. So, yeah, that was relatively easy. And then we have to obtain the device, and that's a little trickier because you're not going to find that kind of stuff at a yard sale or in a corner shop or whatever. It's very expensive, and you might have to buy multiple copies because you might have to do a teardown or you might brick a device, etc., etc. So, ideally, you buy it directly from the vendor, but if you're a nation-state-sponsored attacker, you don't maybe want to directly do that. So, you need Strawman, or you buy it at a bankruptcy auction, or, again, eBay or Alibaba are your friend. So, here you can see, I'm not sure if it's... Yeah, it's all coming up. It's relatively expensive in most cases, a couple of thousand bucks for one of these controllers, and you need multiple parts to put the whole thing together. So, it's not, you know, very cheap. Then you need to obtain the device firmware, the stuff that runs on the device itself. So, we have various options here. You can sometimes download it from the vendor websites or extract it from some update utility. That's the easy approaches. Or you might have to extract it from the flash chip on the device itself, go the hardware hacking route. And this can become very complicated because in the worst-case scenario, you'll have encrypted firmware, you'll have chip readout protection, and you need to bypass it and do side-channel attacks and all that kind of stuff. But for TriConnex, that was not necessary because there was no readout protection on the flash. You could just desolder it, put it into an adapter and use a universal cellular programmer, and you'd be good. Or you could just get it from the firmware update utility, which also holds it all, so, you know. The second step you have to do is usually device teardown and PCB analysis. So, we need info on what kind of microcontroller is on this device. We need the device functional domain, so what is happening where on this device. We need to know about interesting interfaces like UART, JTAG, what have you. And sometimes we're lucky if it's an FCC-certified device. You have an FCC ID and you get internal photos and documentation on the FCC website. Sometimes other people have done your job for you and you have public teardowns, and that's very nice. In the case of TriConnex, the planning and installation guide has very detailed internal block diagrams, and that helps a lot because that saves you the effort of opening it up. But in some cases, we're not so lucky and we will have to do teardowns. Now, people who don't come from a hardware hacking background are usually terrified of it, but it's not that complicated in most cases. Like the picture shows, it's RAM, Flash, or you Google it. And there is this persistent narrative that, especially among some OT people, that ICS devices, they're all different, and operational technology, it's not like the embedded devices you're used to. But for our purposes, it's like all the IoT devices out there that are getting hacked by the billions every day. For example, take these two PLCs by Schneider Electric, the Modicon M238 and M340. Usually you have a central processor module which does all the heavy lifting, and then you have a couple of input-output modules which you stitch onto it on the side, as you can see on the right of the slide. You might have an integrated Ethernet, as you can see on the right example, or maybe you have a dedicated module that does the Ethernet stuff and then connects to the main module over serial link. And internally, they typically look something like this. So you have a couple of I.O. pins, you've got your serial link or Ethernet link or whatever, and then you have a microcontroller in the middle, and typically this microcontroller will run the main firmware, which has the operating system and some of the application stuff, like maybe a web server or an FTP server or whatever. And then you typically have a logic handler, which might be an FPGA or another microcontroller executing the actual programs that this thing is configured and programmed in. Now, this might differ between PLCs because this is a generalization, but it roughly comes down to something like this. And for TriConnex, it looks like this. So you have three main processors, and they communicate over Tribus, which is an internal bus that does some voting on input values for consistency. It has a triple modular redundancy architecture to ensure that a vote of two out of three overwrites any errors that are introduced there. Yeah, that's basically what it looks like, the main processor. And there you have it. It runs a PowerPC chip, and you have a dedicated other chip for input, output, and communication stuff. And we'll delve into this a little bit later when it becomes relevant. So the first thing you want to look at for most ICS stuff is reverse engineering of all the protocols they talk to. Because in many cases, these are legacy and proprietary protocols, usually ports of old serial protocols that have been retrofitted onto Ethernet. They control very sensitive functionality, like starting and stopping the PLC, updating the firmware, and so on. And you might find a way to get into the device itself by remote code execution here, and that's what we want. So the first thing we need to know when encountering a protocol we don't know is knowing the packet structure and the semantics. So we can do this in a couple of ways, and this is a very quick generalization, but usually you go about comparing it to functionally similar protocols, that have been documented. So if it's a port of an old serial protocol, maybe take a look at, you know, what that looked like and what you can recognize in there. Test for common encoding structures like TLV, sequential identifiers, checksums, any entropic analysis for fields that indicate cryptographic functionality. Or you might want to do a differential analysis of functional batches of packets. So you have like one packet that corresponds to starting the PLC, one that corresponds to stopping the PLC in different kind of conditions, and then see what kind of bit fields in the packets change and what you can make of that. And like Rob Savoy said, believe it or not, if you stare at the hexdoms long enough, you start to see the patterns. And that is definitely true for PCAP-only analysis, as you can see here. It's basically like looking at the matrix. Now ideally you want to assist this traffic-only analysis with binary reverse engineering because you want your reconstruction to be complete and sound. You want to write a reliable exploit, not because you don't want to fuck things up, but because you don't want to fuck things up for yourself. So a PCAP-only analysis can be incomplete, inaccurate, or opaque. You know, you can have undocumented or rare behavior that you don't see in the field but that's in there and you're interested in. You might guess at semantics that might not actually be what you think it is. There might be encryption, compression, blah, blah, blah, blah, blah. And most importantly, PCAP-only analysis damages your sanity. So you want to do some binary reverse engineering, which does that to a lesser extent. So in the case of TriConnex, the TriStation software has a communications DLL, and this has all the jobs and juicy stuff we need. It's a single DLL in the engineering software and it has debug symbols, so that greatly eases our life. And as you can see on the slide, I hope it's visible, basically all these functions, they have a good semantic mapping between the functionality it does, like starting the PLC, stopping the PLC, downloading the control logic, and the function code within the protocol itself. So you can relatively easily identify all that functionality. And you can see that the attacker probably went about it this way. Now, the benefit for attackers is that you don't need to fully reverse engineer the protocol. You only need to understand a few interesting packet types, because we don't want to craft a full protocol parser, we want to craft an exploit. So I don't care about all the rest. I care about that one packet type that does the good stuff. Now, when it comes to vulnerability discovery, which is typically the step that comes after this, the next step is getting code execution, right? And ideally, this is a pre-authentication vulnerability. As we'll see, pre-auth is a relative concept in the ICS world. And in many cases, ICS vulnerabilities are often a byproduct of the reverse engineering. So you won't need to go about, in most cases, about fuzzing or static analysis of the firmware. In many cases, it's insecure by default. There's ancient legacy shit everywhere, and you shake a stick at it, and vulnerabilities fall out. So let me briefly drink something. So an example of this, for example, is the Moxa endpoint serial to Ethernet Wi-Fi converter. You plug a serial cable in, converts it to Ethernet. It has a web interface with broken authentication, so it hashes on the client side. That's good. Once you're in, you can do command injection in the ping test form. So you got your code execution right there. Other example, the opto energy monitoring and control device used in fairly sensitive environments. It's got FTP. It's got a proprietary protocol without authentication. Now, the thing is, you can configure FTP with a password. You can enable IP filtering, all that kind of stuff. But then you can use this unauthenticated proprietary protocol to disable IP filtering, enable FTP, and ask the credentials nicely. And then you get them. And you can use the FTP to upload a new piece of firmware and reflash the device over FTP, and there's no firmware signing. So again, that's easy code execution right there. Another example, in case you're not believing me yet, the Modicum Quantum PLC. That's a large PLC for process applications. It has FTP with hard-coded credentials, which allows you to read and write configuration, firmware, what have you. It has Telnet with a hard-coded backdoor, and that's actually a C interpreter, which, you know, is nice. It also has an unauthenticated proprietary Modbus extension for starting and stopping the PLC, overriding the programmable logic. There's basically a gazillion ways to get code execution on this thing. And finally, to drive the point home, another serial-to-ethernet converter by Advantech. It has a web interface, again. And the nice thing is that if anyone unlocks the web interface on one PC, let's say a legitimate operator, it's disabled for everyone. So, you know. And then you have a command injection in the email alert setup form. And again, easy code execution right there. I mean, you get the idea. It's like shooting fish in a barrel, right? And for Trident, it was basically the same thing. It was an execute-my-packet-please vulnerability. So the vulnerability was a freebie of the protocol reverse engineering. You have this safety program download functionality, which is how the engineers put, like, the actual logic on the thing. And it has no authentication. And the safety logic that gets downloaded to the device has no secure signing. Right. So you can basically skip all the way from reverse engineering to exploit development. And that's neat from an attacker point of view, not so neat from a defender point of view. And then that brings us to exploit development. So after we find a suitable vulnerability and we get our code execution, we need to craft an exploit to actually, you know, not execute just the logic we want, but execute, you know, the instructions on the microcontroller we want. And how would this look like in the case of Trident? Well, Trident has safety and control applications, which are developed in one of these IEC languages. Many of them look like graphical language, like you can see on the bottom of the slide. And they typically get compiled and downloaded and executed on the main processor there. And that's nice because that gives you another exploit development freebie, because you don't need to break out of any sandboxes. You don't need to exploit any runtimes. And because in the case of the TriConnex controller, the logic was executed on the same chip that the operating system was executed on, you don't need to hop across any chip perimeters. You're right where you want to be. So Trident did have to add some additional functionality, so it doesn't overwrite the original programming, but it appends to it. And the reason why it did this is because it allows the safety logic to continue running without interruption. Because once you're implanting this device, you don't want everything to stop and potentially already cause a process shutdown. You want to be stealthy, at least at that point. Another complication is the key switch on the TriConnex controllers. So these devices have a physical key switch that allows you to set it to a certain mode. And only if it's set into the programming mode, then you can actually download new logic to it. And this is something that will be relevant later when we discuss the payloads. Another complication of embedded exploitation in general is the heterogeneity. So embedded devices are far more heterogeneous than general-purpose ones. You deal with a billion architectures from ARM to MIPS to PowerPC to whatever. A billion kind of operating systems like VxWorks or QNX or even custom operating systems. And in the case of TriConnex, that means that you have different architectures and operating systems between different versions. So version 9 had a national semiconductor chip. Versions 10 and 11 had PowerPC. And for the attacker, this means that scaling the attack requires writing and modifying payloads and implants for each different version. So there's some effort involved there. And that brings us to the development of the implant and the OT payload. And you know, that's the stage that's close to what Marina mentioned of mapping like the TSD to the implants on the devices. And then we get to this stage. Now we have code execution. We can run arbitrary PowerPC shellcode. So now what? Well, exploitation is just one step among many. So for complicated OT payloads, we will need to develop this implant and then after that craft the OT payload. We have different kind of strategies here. So we can directly implant the OT payload straight away after exploiting device. Or we can implement a backdoor, which would allow us to keep the OT payload secret until zero hour and basically provide you with kill switch capabilities or in the jargon of some people, a dormant cyber pathogen. That basically would allow you at a later stage to execute any kind of payload you'd want to. The second thing we'll have to decide on is whether we'd go for cross boot persistence, which would require modifying the flash and we need enough space there to insert the implant or, which is what Triton did, we just go fully memory resident. That requires executable writing. But it does mean that on reboot, the implant is gone. Now for safety controls, this is not that relevant because these have an extremely high uptime. So even if it would be gone upon reboot, it's probably going to be there all the time anyway. This has the added benefit for the attacker that it does complicate forensics. The other thing you want to think about when designing an implant is the scalability of the implant. So you want to target devices that are common throughout ICS. So not only for one particular facility, you might be interested in, but across different kind of facilities, different kind of industries. And TriConnex fits this bill. So there are 18,000 or more than 80,000 TriConnex systems in over 80 countries. So having these kind of capabilities is very interesting from a strategic point of view. You also want to target, if you're targeting software instead of controllers, you want to target the software that is common throughout ICS. So used across multiple vendors. So protocol and connectivity stacks are usually reused by multiple vendors. So having exploits for that kind of stuff really scales well. And the same goes for control runtimes or the operating systems in question. You basically want to construct an arsenal of exploits and implants against common devices and software stacks, because that means that it is a one-time upfront investment. And now there is no huge turnover in these devices. These have an extremely long field life. They get deployed for 10, 20 years. They don't get updated very often. If there are even updates out there, so if you invest once in an arsenal for, let's say, all safety controllers that are relevant in the market right now, it's going to be an investment that's going to be paying off for a long time. So try to make more sense as a tool in such an arsenal than a very expensive one-off that was engineered for this particular attack. So that brings us to the reverse engineering of the ICS firmware. The first thing you'll have to do is extracting the firmware. So you have to determine the firmware format and then unpack. Sometimes there will be firmwares for multiple chips on the board or data blobs and they're glued together and you'll have to get them out of the firmware. And then you'll have to do the decompression and the decryption if there is any of that present. This might be simple. Keys might be present in a firmware loading utility or you might have to actually do side channel attacks. In the case of TriConnex, this was very easy because the firmware was unencrypted. So basically this step could be skipped. The step that you do after that is pre-processing the firmware. So you need to obtain a memory map. You need to know where on this chip does the ROM live, where does the RAM live, where does the external memory live, the purpose registers for interacting with peripherals, all that kind of stuff. And you typically get this from the datasheet. So very important if you do this kind of stuff, you need to learn the law of reading datasheets. So after you know basically the lay of the land here, you go about identifying the base address. So you need to know where this particular firmware image is loaded into memory. Now there are many approaches here and this is a gross oversimplification, but we simply don't have the time to go into all the details. But this can be as simple as, you know, being loaded at a chip fixed address. You can reverse engineer the update utility and see where it places it. Or you can extract it from something like the intrafactor table or the bootloader or self-relocating code, jump tables, string tables, all that. Let's consider, for example, this RTU firmware piece. This is a piece of firmware for a remote terminal unit that's deployed somewhere in the field. It's ARM based. And we have this piece of firmware and we don't know what the base address is. So we load it just at address 0. And then we see all these different basically branches. Does anyone recognize what this is? Yeah, a couple of people. Well, yeah, that's the intrafactor table of an ARM chip. So the first entry is a branch to the reset handler. And basically if we look at the offset, we have 100 as an offset here. And here we have 102. And if we look at that offset, we see a lot of toggling with these special purpose registers. And that's very typical behavior of a reset handler. So if we then deduct the thousand, basically that becomes the base address. We rebase the firmware image, and we can see that it cleans up nicely. Now we know how to load it into memory. So after you've done this, you know where to load it. You know where everything is laid out. You have to reconstruct the complete code and data topology of the firmware. So all of these challenges are not neat executable formats, like PE or ALF or Mac-O. And your mileage might vary for what qualifies as a neat executable format, but this definitely is not it. We will have to heuristically identify the functions in there, the strings, the jump tables, the structs, and all that kind of stuff. On the upside, this is usually the bulk of the work, doing all this reverse engineering. The upside is that we don't need to reverse engineer the full firmware, only up until readiness for this next step. Because we want to hunt for interesting functionality. We want to reverse engineer in a sniper-like fashion. So we want to know how does the control runtime work that actually interprets and handles this safety logic. Where are the protocol parsers? Where are the communications and peripheral I.O. handlers? Where is any security or safety-related functionality there? So what would this look like for the Tricon X-3008, which was targeted by the Triton attack? Well, it's firmware that's PowerPC-based, which is nice because the Hax-Rays decompiler is available for that, and that saves you a lot of work. It's not a substitute for reading the disassembly, but it eases your navigation across this firmware. It uses a custom operating system with 27 system calls, and some sparse documentation exists. Thank you, NRC. Basically, this is what the operating system looks like. You have a scan task, a communications task, and a background task, and we're really only... We're really only interested in the scan task, which fetches inputs from shared memory, which is where all the analog and digital I.O. gets put. Then we do a tribus transfer for the voting on consistency, and then we run the actual control logic, and then we send the outputs again to the shared memory, and basically this implements all these control loops. So the targets here would have been the memory layout and management because we want to achieve this memory residency, so we need to know how to do that. Then we need to look for consistency, so we need to look for consistency checks and diagnostics functionality for implant stability. We don't want anything messing with our implant while we're running. We need to know where the network command dispatcher functionality is because we want to be able to communicate with it over the network and achieve that. We want to be able to know if there's any privilege mode management. We want to do anything we can on this device, so if there is privilege management, we want to escalate them. Yeah. And possibly, finally, we need to know the scan task and I.O. transfer stuff. So that's basically what the Triton implant looks like and does. So it has four stages. It has an argument setter, an implant installer, the backdoor implant, and then the missing OT payload. So the argument setter, it's not that interesting, but it basically controls the finite state machine of this thing, which does, at first, if you can see that properly, it does an exploit for privilege escalation, and then basically it relocates the implant, the third stage. So the privilege escalation exploit, it looks complicated, but it's not. It's basically a write-for-anywhere because of improper handling of memory privileges that allows you to write this value to this address. What does this mean? Basically, what happens is that once you invoke a system call on this particular firmware, it saves the machine state register, and when it returns, it restores it, and it is stored at this particular address that anyone can write to, regardless of privileges. So if we overwrite it with this value, we set bit 17 to supervisor privileges. And that allows us to do these next steps to install the implant, the first of which is copying the payload into the firmware area of memory, which allows us to achieve residence even if they wipe all the safety logic on the controller. Then we patch an entry in the jump table, which allows us to hook a network command and then invoke our implant when this particular network command is called. And then finally, we patch a certain RAM check, which was used for consistency between the firmware in ROM and in RAM, which would otherwise mess with our stuff. And this is basically the backdoor implant. Like Marina mentioned, it allows for reading, writing, and executing arbitrary memory, and basically allows you to overwrite this key switch. So once you implant it, it doesn't matter what position they turn the key switch into. It allows you to execute anything you want in memory. So you have persistence on this device. So the fourth stage, which is the most engineering related, is the OT payload. And this was missing because this carries out the meat of the attack, and we can only speculate what this might have looked like. And that's something we'll do. So because Triton is positioned here in the attack tree, the control and safety system, this is what the OT payload would have been related to. So basically, it could have been, for example, an IO spoofing scenario. And that would have been a scenario that Marina would have given to me, and said, you know, we want to do spoofing of input and output values. As you can see, for example, here, you have measurement values. They come as an input signal to the controller, and as an output signal go to the instrumentation. And then we want to mess with either the input or the output to cause some unsafe state. Now internally, this looks like this on these devices. So you have the physical IO, you have the logic, and there is an intermediary variable table that manages this. On the TriConnex, this is handled by an IO processor that has shared memory connection to the main microcontroller, and that's where it places this variable table. So we didn't have a TriConnex controller, but we did have a WAGO PLC, and I mean, it basically comes down to the same thing. It's an ARM Cortex PLC running real-time Linux. It has a vulnerability in the code system runtime on TCP that you can explode remotely and gain root. And basically, what we do in our attack is we use the CPU debug registers to catch any access to this memory mapped IO. And then we write a custom exception handler that gets invoked when this debug trap is invoked, and we change the pin mode, for example, from output to input. So any writes that would have been going to an actuator, like closing a valve, are now going to an input pin, and they don't actually go out. And we have a little demo of this that should be coming up. We don't have a lot of time, but... All right, so what you can see here is you have the WAGO PLC on the right, and then you have LED, which is our stand-in for a valve. And it's supposed to be blinking every couple of seconds. And now you can see it... Yeah, now you can see, basically, on the engineering software, and the attacker will soon... Yeah, I can't really skip anything here, but... There should pop up, like, a shell at some point. Now you can see the LED blinking there. All right. Yeah, so, you know, this is a root shell on the PLC. We execute our payload, which is basically a Linux kernel module that does this thing I just mentioned about the CPU debug registers. And then we stop it, and you can see the LED will stop blinking. Well, it should be consistently blinking, because it, you know, now thinks it's an input pin. And then at some point, you know, we'll change it back again to an output pin, and then you can see it's starting blinking again. Right, if this was a valve, it would have had an impact. Now it's a LED, and, you know, it's just a demo. So that brings us to the second possible payload, which is alarm suppression. So let's say we want to mess, for example, with a chemical process like this, and our goal is catalyst deactivation. Now, industrial processes, they have alarms. So if something is about to go into an unsafe state or something is out of bounds, an alarm is raised somewhere in the process, and these are propagated throughout the process and eventually lead to a safety shutdown. And as an attacker, we want to prevent this, because we want the attack to continue. So how do we go about this? We can hide the alarms by compromising, like, the safety view or the DCS view or some local HMIs. And this is the benefit of, you know, hiding them centrally, but still these alarms go out as network traffic, right? And we don't want any kind of network inspection to see these alarms. So we want to suppress them either at the field level, the level of the field devices, or at the level of the safety controller itself, which is what TriConnex is. So for TriConnex, you have safety view, which is a PC-based HMI solution. It allows for management and bypasses of all these alarms, and each HMI function is mapped to a TriConnex logic function block. And that looks somewhat... Oop, that was a little bit too quick. That looks something like this. So you have, for example, a water tank level alarm here. You have a water high, a water low signal, and an aura of them raises an alarm. So as an attacker, these safety programs reside in memory as code, which is how we got, you know, code execution in the first place. So the OT payload here could modify the instructions to set the alarm to a fixed vols, regardless of the water levels that are coming as inputs to this alarm function. The attacker needs to know, of course, first where the program lives in memory, and which instructions of the program to modify. Now, luckily for TriConnex, these programs are stored as a circular linked list in memory, as you can see here. This is actually our implant living in memory. And then you can walk this linked list and find the target program you want to modify. And this is what basically the alarm looks like. The core of the logic is a simple OR instruction, which the attacker can then, you know, hot patch. You know, it's PowerPC. It's a RISC architecture with a fixed instruction size. So we just set it to a fixed vols there. It's relatively easy. And this is the result that comes out of it. On the left, you have normal functionality. You know, water is getting dangerously high. The alarm is going off. On the right, you have the exploited functionality. Water is getting dangerously high. Alarm is sleeping. All right. So some more speculation. Why did this attack fail? I don't think we mentioned that, but the attack was discovered because it failed in the actual field. It caused a safety shutdown of the process. There are a couple of possibilities. You could have had a Borg payload. You know, the privilege escalation could have failed. It could have targeted a different firmware version than they actually had developed the exploit for, which could have caused an access violation. I mean, the backdoor allows for, you know, a raw reading, writing, and executing of memory. They could have caused some memory corruption by, you know, a payload that was written wrongly. They could have gotten into a fight with the watchdog. So very common on embedded systems, you have this watchdog timer, and you need to periodically kick it to keep the counter high, because if the counter expires, it resets the CPU. Or they could have missed some additional diagnostics. I mean, there's a ton of diagnostics functionality in here, and just because they patched the RAM and ROM check doesn't mean that they patched everything right. These are all options. Another option is that they got into a fight with the triple modular redundancy. I mean, this is just a voting on the inputs and the output, but it's a very complicated patent that covers a lot of ground, and it could have been that the OT payload violated something in the triple modular redundancy that in turn led to a safety shutdown. That brings us to the conclusions, which I'll give to Marina again. Well, we probably have just, like, a couple of minutes for conclusions. So just to summarize, like, so, again, the purpose was also to go through this process of development implants for embedded system and see whether it is really that complicated. So what is the actual real threat? Is it also only for elite, and we should not expect this type of attack or implant on a mass scale, or it's not? And apparently it is not. Not only that exploitation and implanting of industrial control systems relatively easy, like, it's cheap because there is no, any exploit mitigations, but also obtaining equipment, it is relatively easy. We went through the process. Obtaining documentation is relatively easy. So you kind of have all of the needed components to quickly obtain code execution and be able to backdoor this type of devices. So exploit development, again, easy, if I will just go quickly through this. Implant development, relatively easy. So, for example, in the case of Triton, the attack already had privileges. Typically, on industrial control system, you would not have, like, separation of privileges, so the attacker had privileges to escalate his privileges. Neat. So, however, for example, in case, in safety system, you typically have this triple, like, redundancy. Sometimes it's quadruple redundancy, which makes things a little bit complicated because you have to reverse engineer more. So the most difficult part, which we were able to establish, is actually developing OT payloads. So basically, my task is harder. And especially whenever we come together, like, for example, Jos and I come together. This is my wish lift, and he already has an implant. This is where reverse engineering started going further, and that is becoming more difficult. So, basically, so the open questions which we have, and this is, I think, Jos has covered it very nicely, that it's probably just, what we've seen is just one tool among many. So, basically, development costs should be seen as relatively low. And I think we should, what we definitely should expect relatively soon is copy-capt. Security is a fashionable industry. So as soon as you, like, for example, somebody will release a first ransomware malware, everybody will be designing ransomware malware. So this is what we're going probably to see. So many more other, like, state-sponsored threat actors will join this, basically, game. And again, it's not necessarily so. This is what, like, people think. On one hand, yes, it's easy to exploit. Then why don't we see a lot of those attacks? Because first of all, you have to have a motive. Why would you do that? And secondly, it's, of course, like, crossing this red line. So on one hand, it probably will be something like the nuclear weapons. You will have the arsenal, and maybe you will be showing the capabilities just in a slight manner, like it has happened with power grid attacks in Ukraine. You just show that you are capable of, but you do not cause massive, like, damage which hurts. So you basically will be having it as a, like, economical and political negotiation. So we wanted to thank a couple of people, including Felix Lindner. He was, like, a frequent DEFCON speaker who kindly helped us to review the slides. We have the slides with the toolkit which you will need. And with that, we are at the end. And thank you very much for your attention. Thank you.