Hey everyone, as you start moseying in, we're going to have Bertin. He is an independent security researcher. He's going to talk to you guys about industrial protocols. It's going to be a really fun talk. I hope you all enjoy it. And yeah, as you start moseying in, I see the camera guy has given me the okay. We'll just start kicking things off. So please give Bertin a warm welcome and everyone enjoy themselves. Thanks. Okay, cool. Hello everyone. Welcome to my talk. This is about um, well, as the title says, mixing industrial protocols with web application floss. In order to exploit devices in the internet. Which is a thing that I used to do all the time for like uh, ten years ago. I mean, something really crazy. Um, let me, that too. Okay, here we go. So okay, oh, why is it so fast? There it is. So fast. Okay. Okay, hello, uh, my name is Bertin, as uh, they present me. Uh, this is my tutor. I'm uh, working as a security consultant. Uh, professionally in network engineering, security research, device security, protocol security, uh, basically all of my uh, research is based in remote exploitation all the time. I mean, all the things that I do is remote. And always, all the devices that I use to exploit are connected to the internet. All the time. Okay, agenda for today, uh, the motivation for this research, how it started, how I found this, and how I developed exploit and all this stuff. Uh, I'm gonna be talking about modern, modern magnet devices. The security problem in those devices. And then I'm going to be explaining how to use magnet protocol itself as an attack vector for this kind of devices. Uh, the fundamentals for magnet, because in order to understand this, we need to recap all the things about magnets, how it works, how it's designed, and all this stuff. The theory and the technique, and the exploits and the conclusions. At the end, uh, there is a bonus track that I decided to include in this talk. It's an RCE, an, uh, industrial router. Yeah, that's critical, as usual. So, the motivation about this. There is a lot of fun, a lot of fun, in industrial protocol security. Usually you can, uh, on off things, uh, start stuff, uh, start and stop stuff, read critical data, uh, modify critical data, inject malicious data, execute malicious stuff, and so on. All these remotely, from your home, from your, I mean, your hotel room, everywhere in the world. So, I start playing around with many of them, of these protocols, visible for search engines. And some of them are invisible. That is a fun fact that many researchers, uh, ignore, because they think that current, uh, search engines are indexing all the industrial protocols. No, but that is not true. Because, uh, there are a lot of new technology, there are new, there are a lot of new devices with proprietary protocols. And these protocols are based usually in UDP TCP. So, you can, of course, scan the internet for these, uh, new protocols, and, uh, have some fun with them. So, uh, please, uh, keep in mind that thing, that there are security, I mean, there are industrial security protocols, or industrial protocols that, uh, are not being indexed by current search engines, like Shodan or Sumai. And people don't know that. So, the following is the result of hours of reading documentations, analyzing servers in the internet, and testing on common things, trying to find out new paths for remote injection and web application services for specific devices using the BACnet protocol. Okay, BACnet previous research. There are a lot of talk about BACnet. I mean, um, several talks about that. You can find out, uh, it's always the same thing, like, uh, on, off, start, stop attacks. Uh, we know that there is no security in this protocol. It's basically plain text. Uh, there is no authentication method. Um, you can perform, actually, BACnet network scans remotely to the BACnet topology infrastructure. No web applications issues find, found, until today, in this talk. I was, uh, trying to figure out if someone else, years before, tried to do something that I, uh, am going to show you today, but I had no luck. So, basically, this is something new. Okay, today, I am introducing a new attack vector in BACnet devices. This is remote. And last night, I found another brand affected by this, curiously. So, this is a travel touch thing. I mean, there are several brands affected by this thing, but I don't know, and we don't know exactly which they are. We need to find out. Um, you don't need tools to do this. It's just a simple script. It's a crafted attack, very, very crafted attack. It's a stealth, uh, UDP base, and you can get persistence. And finally, code execution in browser, which is really cool. This thing doesn't work here. I mean, we're talking about web application, but this thing is not capable of, uh, find these kind of things. So, if you think that this is the thing, you are wrong. I'm gonna prove that today. So, please, keep in mind that this thing doesn't work here. It's not prepared, yet. Okay, so, brands affected by this issue, discovered until now, this is a traversal issue, as I mentioned. The first, uh, brand is called RLE Technologies. This is a brand who manufactures devices for industrial purposes. Uh, protocol converters, industrial routers, blah, blah, blah. They can, which, I don't know which is the relationship with MyQi, which is a Hong Kong company. Uh, they are using the same kind of server in both, uh, brands. So, they have, uh, one device here and another device here, and they are using the same technology, so they are affected by the same issue. Two brands, uh, using the same technology. There is another brand which is not included here, that I found last night, which is called KMC Controls. It's affected by the same, but it was found last night, so, it's, uh, new. Okay, this is the, the first device that, uh, I was able to exploit with this thing. Everything started here with this thing, the RLE protocol converter. Uh, what this, this thing does is, uh, trying to, well, actually, not trying to, okay, it converts, uh, Bagnet protocol to Modboost protocol. This is a protocol converter. When you don't have, um, a way to communicate with devices, this thing helps you to, uh, modify this kind of protocol conversion, and you will be able to reach devices through this thing. Okay, the devices affected by this issue are this one, graphically, uh, Daikin and McQuay. They, uh, manufacture chilling, big chilling, big chillers, chillers, that's it, chillers. And those devices are connected to the internet, they have a web application in order to, uh, manage, configure, set up the whole thing. And things are just getting bigger and bigger. Okay, uh, this is an example of a Bagnet topology, how a Bagnet topology is, is, um, deployed in infrastructure. So our goal today is, or an attacker goal, is, uh, infect the engineer web browser. Why the engineer web browser? Because he's going to be connected to these kind of devices in every time. So usually those engineers, or these technicians, has access to another, uh, set of devices. So if we are able to, uh, execute code in their machine browser, probably we could steal, uh, other things that could be more interesting in, in this kind of, uh, particular attacks. Uh, we're talking about like an APT attack or some kind of thing, I don't know. But if you get persistent and the technician machine, you could probably, uh, steal other more critical devices in that infrastructure, or probably another, uh, more critical computer. This, this idea that I have with this. Okay, this is, this is taken from the Bagnet.org tutorial, um, basically the, the official documentation from Bagnet. And there is a little note, uh, about security. Because when I started this, I was, you know, interested in, uh, how the security of this thing works. But I found this. So there is a little discussion of security in this presentation. We have assumed that all nodes are trusted. Security will obviously be an important future consideration. For now, assume that all devices are sitting behind a firewall. That does packet filtering and the environment has well implemented restrictions on the software that can run inside a firewall. This is all the thing that this guy said about Bagnet security. You can find out in, in, in that link. This is all that you will have, uh, that you will find about, uh, security implementations and the protocol itself. So it means that there is no authentication methods. There is nothing, uh, to protect the, the protocol itself if there is no, uh, firewall, uh, very well implemented. And infrastructure. So our goal today will be the following. Uh, remote attacker from the internet, uh, has access to the device, but has no access to the web application. But has access to the Bagnet protocol. And he can read and modify things using just the protocol. So let's start with the Bagnet specs. In comparison with the OSI layers, uh, the Bagnet works in the application and network layer. And of course, IP. IP protocol. So let's start with the Bagnet protocol. It's, uh, the port is 47808. It's UDP based. No complex security mechanism, as, as I said. No CRC, no integrity checks, no hash, blank text, read write capabilities, and it's completely open in the internet. You just need to perform a query in some extensions and you will find out that, um, there are a lot of devices connect, connected. Okay, uh, so the Bagnet structure is basically Bagnet, Bagnet IP. The first layer would be the VUVLC or Bagnet virtual local control. The third layer, the second layer would be the MPDU, uh, network protocol data unit. And the last layer would be the application data unit, which contains all the information that we need to inject to the device. The magic happens there. Okay, let's talk about the first layer, the Bignot, Bagnet virtual link control. It's basically two bytes. Oh, excuse me, four bytes. It's four bytes. The first byte defines the type. In this case, Bagnet IP, which is, um, A1 and hex. The second one defines the function. In this case, uh, which function we, we would like to execute in, in, in the communication. And the last two bytes define the length of the whole packet. So you need to sum the three layers and put the result in that first layer in order to create a correct, uh, Bagnet packet. And then send it to, to the network and get the response. If that number is not correct, uh, you will get a more firm packet. So it's not going to work. This is a graphical representation in Wireshark about the first layer. The Bagnet virtual link control. You can see the function. This is our original unicast, unicast communication. And the two bytes are the length. Then we have the Bagnet network protocol data unit. This is a representation according to Bagnet wiki, but in practice it's just two bytes. Like this. So it's just telling you the version that you need to use and the control. So in this case, we set up the, the byte to four. Which means we are expecting reply from the device. So if you don't configure this control byte, uh, you probably, you could, uh, you can, you can get the reply back to you. If it's not properly configured. So you need to read the documentation and start constructing the packet byte by byte. And the last header is the Bagnet application data unit. Uh, this thing, uh, is the last header and contains, uh, variable length that also should be specified in that, in that header. Otherwise, you will face, uh, more phone packet issues again. This is how it looks like in Wireshark. Uh, this is a graphical representation of Wireshark. One important thing here is, uh, the service choice. The service choice is the, the byte that allows you, uh, read or write things in the Bagnet device. Okay? The magic is in the APU header that allows you to read or write values in the Bagnet data, uh, structure. Okay, here's what I'm talking about, the Bagnet service choice. So, you have all those values and bytes that allows you to set up how the communication is gonna be executed. So, in this case, we're gonna be using, uh, the 12 number value, which is 0C and hex, in order to read. Just read. Right? In order to read write, you need to set up correctly the service choice byte. At this point, probably you're thinking, you're taking a look into the 14 byte, because the 14 byte here, allows you to, uh, restart the device. If you send that byte, uh, the device will just restart. But we're not gonna be talking about this today, but keep in mind that this can be possible. Just sending a single packet to the network. So, in order to read, we'll be, and for write, it would be 0F. That's it. This is how, uh, a read packet looks like. You will see the read property configured there, and the number 12 in decimal. Okay, the values that we need to read and write will be the Bagnet objects. A Bagnet object is, uh, unique in a given device. It's a combination, uh, with many, uh, properties. Specifically, when you create a device in a Bagnet device, it means that every sensor, every in-out output, input output, will be created in a single device. This device has a name, and this device has, uh, his own properties. Every, every sensor in the Bagnet device has this, uh, segmentation, like, uh, specific, uh, may I compare this with, uh, profiles, would be kind of a specific profile, and the property of each profile can be modified, remodeled. Okay, the object identifier contains the property identifier. Basically, the string values represent the unary and readable strings like location, device model, device name, and so on, in a few words, or targets today. So, in this case, we are reading, uh, that specific object, the object identifier, which is a property identifier. It's kind of confusing, but one thing is upon the other. A property identifier has an object identifier. So, if you see, this is encoded as a character string. The object name, uh, the location name, application software version is character string. There are several tools available you can use, uh, in order to read and write values with Bagnet. There are a lot of Bagnet clients, uh, but the purpose of this thing is go deep and do this without tools in order to understand exactly how it works. Uh, you can do this with any language that supports socket communication. Okay, let's take a look how this looks like in execution. So, this is an example of how our read package looks like, uh, in a really raw way, in a really primitive way. You can see the four bytes, the first layer, the B-U-L-C, and then two bytes, the M-P-D-U, and then the biggest layer, which is the A-P-D-U, which is, uh, a lot of bytes, two, four, five, six, nine bytes, okay? So, if you want to read a property identifier and an object identifier inside that thing, you need to send a packet that looks like this. You will see the service choice, which is 12, properly configured, and then, uh, the object identifier. The object identifier is the only thing that I found as a security mechanism, because you cannot read or write without that value, uh, configured there. So, in this case, the device is using a 3,000, uh, string, uh, excuse me, um, uh, integer in order to, uh, execute, uh, functions. I mean, you can, you cannot execute something without that number specified in the packet. So, for example, if you try to write values there, and the value is not matching with this value 3,000 in the device, you are going to be able to, to write something. So, you need to first, uh, know this value in order to then, uh, write properly. Okay, let's develop, um, a tiny script in Python that perform all these things that I've been talking about. You can see the first, um, the first packet will be this thing. So, this thing, uh, is just asking for the object identifier, and then the second packet is asking for the vendor name, uh, the software version, and so on. So, it's like, uh, 7 functions. Each packet is for each function. So, let's see how it works. Let's open the wire shark in order to see the communication flow. Okay, you see, there is a filter for BACnet. I'm going to execute this. And you see the communication. Correctly, I'm, um, I'm performing communication with the device remotely. This is a real device connected to the internet. And, uh, I am, I'm asking him information regarding BACnet. Specifically, I'm asking him for, uh, his object identifier. You will see he, he ask me like, uh, yeah, my object identifier is 5,000, my vendor name, the firmware version, the description, the location, model name, application software, and other object name. All this information is printed here, on, on, in the output of my script. This is, uh, my quite shiller, a big shiller, for sure. And this is how the communication works. When you understand this, when you, in practice, are able to do this, you are ready to write values. But which values are interesting? I mean, what can I do with this? That was the first question when I tried to figure out, found something in the protocol and the web application. Uh, the beginning, my purpose of all this whole thing was not to find web application issues. Uh, was to figure out how to find something in the protocol itself. I mean, execute the stuff, but in the process I found something cool. And this is the result. Okay, this is how you can, uh, communicate with the devices. We just, with a simple script, as you can see, uh, all that I did was just read the documentation, understand how the protocol, uh, works, and then, uh, put it in code, in just a, a single socket connection, just sending row bytes, and then splitting the response in order to show, uh, the plain state data coming from the device. Okay? Cool. Let's continue with the thing. Okay, let's check out the response. At this point you will notice that the communication with by the, when the device is successful, also the response back contains a specific value for the object identifier. Remember that, that, that number. Keep this value in mind because we will use later in order to write. It's really important. Okay, now we know how to, okay, now we know how to read the specific values from the Bagnet data structure. But the cool thing is that we can modify those values. And also the same values are being taken from the application to represent the string values, I mean, in the, in the web application from N. So this is cool. Because what if we could, uh, make a modify these string values for pieces of code. Pieces of Java, uh, HTML or JavaScript code. In theory, this could be works or couldn't be, but at the beginning I had no place to test this because that was just in theory. I needed, uh, a real device connected to the internet with this scenario, uh, in order to prove that this thing works. And well, I found it and, and, uh, this is what it is. The write property is tricky. Sometimes objects are restricted to be modified, but most of the time the property value location is able to be modified from the Bagnet protocol. Um, well the thing, the same thing about the device ID. Okay, in order to write, the property, uh, tells you that you need mandatory, uh, specific values, like the object identifier, the property identifier, and the property value that you want to modify. So let's see how we can modify stuff. So this is a real thing. This is a real application. This is a real device, a MacQuietCheater connected to the internet. So, uh, when I found this, uh, it was the same impression as you. There is nothing there. I mean, it's not showing nothing, but if you right click on it and you check the source code, you will find Go. Why? Because here, first of all, there is a password. Um, let me check. Password for restart is 123. Yeah, this is out of scope today, but was a kind of, uh, nice, nice thing to find. And then, if you take a look closer to this thing, you will find something really cool. Ah, zoom in. Yeah, yeah, yeah. Let me see. Yeah, that's it. Okay, let's take a look at the password again. The funny part. Okay, there is a password for restart, 123. Uh, but here you cannot see any. I mean, on the main page you won't see any. You just need to check the source code in order to find cool things. But there was another thing that took my attention in the first place. The thing that is interesting here is this. The location. The location is Las Vegas. Well, I put this for, uh, demo purposes. But here, uh, I'm going to do this with, uh, this thing. This is, uh, Magnet Client. And you can do this from here. And now I change the location, the value from the location, right? So, if I reload this thing, I can see. Okay, there you go. Now let's check again the source code. And you will see how the location has changed by IOT. You see, now we are in IOT village. So, I did this from Magnet protocol. Uh, the device has no security. Actually there is no access for it. But I have access to the, to the protocol itself in order to modify stuff in the web application. So, now this is, this become a nice vector attack. A nice vector attack for, um, HTML or JavaScript code injection. And we are not using verb. That's the cool thing. Okay, so, now we know how to write. And now let's break it down, the exploit. Okay, the application is taking values from Magnet to be represented as string values in the web application. Those values can be modified from the Magnet data structure using the Magnet protocol write capabilities. And good theory is, I replace the string values for JavaScript code, the JavaScript code will be executed. Just in theory, at that time. Open up the source code, check again the value of location tag in the device. And our goal will be the following. Replace this thing for JavaScript code. And the result will be an stored, uh, crosshead scripting in the device web application in those tags. There is no need for a special XSS payload, a single alert in script tags. It's in order to figure the crosshead scripting. So, um, the application probably is password protected. So, as you can see, actually you don't need to touch it at all. This kind of cool because I, I, I didn't did any special, I mean with the web application actually was not touched at all. Everything comes from the Magnet. But as I said, no problem. Magnet is available to inject code. And now we know we should place our exploit. So let's see the demo. I have a video because, you know. Okay, here we go. The same device. And first of all, read, of course. You will see the location. It's Vegas. Uh, check again the source code as I did. You will see the tags. All this information can be modified to description. I mean, you have several places to put JavaScript code. That kind of thing. But the cool thing is, as I said, the, the location value. Now let's change Vegas for a cool payload there. Okay, everything is still fine. Now let's take a look to our exploit. So, our exploit would be this way. Uh, the same thing. The four bytes, uh, the two bytes for the second header. And the APDU with the biggest header, which includes our, our payload, our JavaScript payload, but encoded in hex because it's going to be sent on the network. So, you just need to send that. Don't expect a reply or anything because it's UDP. And the values are going to be injected in the web application. So, okay, now I just send the exploit. You will get the simple acknowledge reply from the device telling you that, you know, I received your packet and everything has been written, so you're good, you're good to know. If you follow the UDP flow, you will see our payload there, our script alert payload there. And the acknowledgement from the device is expected. So, now if you reload, so there is your, uh, code executed in, in the web application. And it's persistent. I mean, this, this thing is going to be stored forever there. So, every time that someone connects to the device, it's going to, it's going to be, get infected, something. Okay, other things that you can do with this is, uh, for example, leak internal server routes. And you can see config object input that comes from the device. So, you have, uh, path leaks there. You can take advantage with Bagnet. And also, uh, check, uh, the, the device description for each, uh, profile. So, for example, this was, uh, elevator, free machine room temperature. So, you can enumerate what exactly which specific device does in the device. So, conclusions for this part, the techniques allow you to inject JavaScript without touching the web application at all. This, uh, JavaScript protocol base injection technique. In this particular scenario, we don't need credential or access to the web application. You just need to inject the payload and say goodbye. Several protocols are also affected by this kind of issues. But, you know, I can, uh, publish everything in one, in, in one talk. Uh, several Bagnet, several Bagnet devices with the port 47808 are vulnerable to be modified remotely using this Bagnet protocol. And the number of current devices affected is unknown, at least for me. Always, there are probably new technologies affected. There are several tools to read and write. If you're spreading issues, try to reproduce, try to reproduce the vulnerability this way. Check your backlinks or operation code. So, finally, the bonus track, uh, this is something that I found a couple of months ago. It's, uh, basically, uh, an RSC vulnerability and those devices from this brand called Forfait. So, Forfait is a Chinese brand of industrial devices. Uh, they manufacture a lot of stuff with, um, 3G, 4G, industrial routers, Zigbee, LoRa, a lot of that thing that is related to industrial stuff. And, of course, they have, uh, devices connected to the internet. Uh, I found something really cool here, which is, uh, an option to execute commands. At first place, you would think, okay, it's just put the command there, put a netcat inside, and probably you would, you could get a reversal back, but that doesn't work, so I need to figure out how to execute code there. And, there is an option here, and application, this option called commands, administration commands, and you will find this. Take a look. Okay, this box, this command shell, allows you to execute Linux commands, but as I said, if you try to execute a netcat or something like that for easy stuff, it won't work, won't work correctly. So, I had to figure out how to execute command here, commands here, and I found out, uh, this payload, this payload that create like a, um, descriptor or something, and then you will see the netcat command included here, pointing to my IP and my port. So, just copy that thing, paste there, copy, and run the command. Great. Now, I'm going to show you the, here you go, and you will see the shell back to me, remotely from the internet. And there you go. And also, you can perform a cat, you know, the same thing as usual, ATC, password, and that's it. Well, this kind of issues are always in those kind of devices, it's the same thing all the time. Uh, it's really, really easy to spot RCEs, um, I don't know. The thing continues, I mean, the research continues. Well, I think that is done for today. Any question or something, just let me know. This is my Twitter, if you want to follow me, I always publish in stuff related to this kind of, uh, IoT stuff, OT stuff, ICS stuff, so, thank for your time. Welcome.