1 00:00:00,000 --> 00:00:03,280 Hey everyone, as you start moseying in, we're going to have Bertin. 2 00:00:03,280 --> 00:00:05,740 He is an independent security researcher. 3 00:00:05,780 --> 00:00:08,300 He's going to talk to you guys about industrial protocols. 4 00:00:08,300 --> 00:00:09,640 It's going to be a really fun talk. 5 00:00:09,640 --> 00:00:11,280 I hope you all enjoy it. 6 00:00:11,320 --> 00:00:15,740 And yeah, as you start moseying in, I see the camera guy has given me the okay. 7 00:00:15,740 --> 00:00:17,620 We'll just start kicking things off. 8 00:00:17,620 --> 00:00:21,620 So please give Bertin a warm welcome and everyone enjoy themselves. 9 00:00:21,620 --> 00:00:22,380 Thanks. 10 00:00:27,770 --> 00:00:28,910 Okay, cool. 11 00:00:28,990 --> 00:00:30,010 Hello everyone. 12 00:00:30,010 --> 00:00:31,350 Welcome to my talk. 13 00:00:31,530 --> 00:00:41,310 This is about um, well, as the title says, mixing industrial protocols with web application floss. 14 00:00:41,310 --> 00:00:44,350 In order to exploit devices in the internet. 15 00:00:44,350 --> 00:00:49,910 Which is a thing that I used to do all the time for like uh, ten years ago. 16 00:00:49,910 --> 00:00:52,730 I mean, something really crazy. 17 00:00:52,810 --> 00:00:58,890 Um, let me, that too. 18 00:00:58,890 --> 00:01:00,510 Okay, here we go. 19 00:01:01,230 --> 00:01:04,110 So okay, oh, why is it so fast? 20 00:01:06,820 --> 00:01:08,400 There it is. 21 00:01:08,520 --> 00:01:09,460 So fast. 22 00:01:09,460 --> 00:01:10,160 Okay. 23 00:01:10,680 --> 00:01:17,000 Okay, hello, uh, my name is Bertin, as uh, they present me. 24 00:01:17,060 --> 00:01:18,260 Uh, this is my tutor. 25 00:01:18,260 --> 00:01:20,800 I'm uh, working as a security consultant. 26 00:01:20,880 --> 00:01:33,520 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. 27 00:01:33,520 --> 00:01:35,780 I mean, all the things that I do is remote. 28 00:01:35,840 --> 00:01:40,660 And always, all the devices that I use to exploit are connected to the internet. 29 00:01:40,660 --> 00:01:41,720 All the time. 30 00:01:43,260 --> 00:01:54,080 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. 31 00:01:54,340 --> 00:01:58,280 Uh, I'm gonna be talking about modern, modern magnet devices. 32 00:01:58,660 --> 00:02:01,140 The security problem in those devices. 33 00:02:01,660 --> 00:02:09,940 And then I'm going to be explaining how to use magnet protocol itself as an attack vector for this kind of devices. 34 00:02:10,080 --> 00:02:19,360 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. 35 00:02:19,420 --> 00:02:23,880 The theory and the technique, and the exploits and the conclusions. 36 00:02:23,940 --> 00:02:28,360 At the end, uh, there is a bonus track that I decided to include in this talk. 37 00:02:28,360 --> 00:02:33,000 It's an RCE, an, uh, industrial router. 38 00:02:33,020 --> 00:02:35,600 Yeah, that's critical, as usual. 39 00:02:36,200 --> 00:02:38,260 So, the motivation about this. 40 00:02:38,640 --> 00:02:43,660 There is a lot of fun, a lot of fun, in industrial protocol security. 41 00:02:43,880 --> 00:02:58,880 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. 42 00:02:58,880 --> 00:03:04,920 All these remotely, from your home, from your, I mean, your hotel room, everywhere in the world. 43 00:03:05,400 --> 00:03:12,120 So, I start playing around with many of them, of these protocols, visible for search engines. 44 00:03:12,120 --> 00:03:15,380 And some of them are invisible. 45 00:03:15,700 --> 00:03:25,080 That is a fun fact that many researchers, uh, ignore, because they think that current, uh, search engines are indexing all the industrial protocols. 46 00:03:25,080 --> 00:03:27,120 No, but that is not true. 47 00:03:27,380 --> 00:03:35,500 Because, uh, there are a lot of new technology, there are new, there are a lot of new devices with proprietary protocols. 48 00:03:35,940 --> 00:03:39,940 And these protocols are based usually in UDP TCP. 49 00:03:40,040 --> 00:03:48,000 So, you can, of course, scan the internet for these, uh, new protocols, and, uh, have some fun with them. 50 00:03:48,260 --> 00:04:04,240 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. 51 00:04:04,340 --> 00:04:05,920 And people don't know that. 52 00:04:06,940 --> 00:04:23,460 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. 53 00:04:25,120 --> 00:04:27,560 Okay, BACnet previous research. 54 00:04:27,560 --> 00:04:29,640 There are a lot of talk about BACnet. 55 00:04:29,640 --> 00:04:32,760 I mean, um, several talks about that. 56 00:04:32,760 --> 00:04:38,340 You can find out, uh, it's always the same thing, like, uh, on, off, start, stop attacks. 57 00:04:38,340 --> 00:04:41,800 Uh, we know that there is no security in this protocol. 58 00:04:41,800 --> 00:04:43,680 It's basically plain text. 59 00:04:43,680 --> 00:04:46,860 Uh, there is no authentication method. 60 00:04:47,180 --> 00:04:54,680 Um, you can perform, actually, BACnet network scans remotely to the BACnet topology infrastructure. 61 00:04:55,240 --> 00:05:00,980 No web applications issues find, found, until today, in this talk. 62 00:05:01,120 --> 00:05:11,380 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. 63 00:05:11,380 --> 00:05:13,420 So, basically, this is something new. 64 00:05:14,560 --> 00:05:18,100 Okay, today, I am introducing a new attack vector in BACnet devices. 65 00:05:18,100 --> 00:05:19,240 This is remote. 66 00:05:19,500 --> 00:05:24,000 And last night, I found another brand affected by this, curiously. 67 00:05:24,020 --> 00:05:26,200 So, this is a travel touch thing. 68 00:05:26,200 --> 00:05:31,860 I mean, there are several brands affected by this thing, but I don't know , and we don't know exactly which they are. 69 00:05:31,860 --> 00:05:33,000 We need to find out. 70 00:05:33,740 --> 00:05:35,940 Um, you don't need tools to do this. 71 00:05:35,940 --> 00:05:37,720 It's just a simple script. 72 00:05:37,740 --> 00:05:40,300 It's a crafted attack, very, very crafted attack. 73 00:05:40,300 --> 00:05:45,280 It's a stealth, uh, UDP base, and you can get persistence. 74 00:05:45,280 --> 00:05:50,420 And finally, code execution in browser, which is really cool. 75 00:05:51,340 --> 00:05:53,260 This thing doesn't work here. 76 00:05:53,260 --> 00:05:59,340 I mean, we're talking about web application, but this thing is not capable of, uh, find these kind of things. 77 00:05:59,340 --> 00:06:02,800 So, if you think that this is the thing, you are wrong. 78 00:06:02,800 --> 00:06:04,600 I'm gonna prove that today. 79 00:06:04,600 --> 00:06:07,620 So, please, keep in mind that this thing doesn't work here. 80 00:06:07,620 --> 00:06:09,540 It's not prepared, yet. 81 00:06:10,220 --> 00:06:16,580 Okay, so, brands affected by this issue, discovered until now, this is a traversal issue, as I mentioned. 82 00:06:16,800 --> 00:06:21,620 The first, uh, brand is called RLE Technologies. 83 00:06:21,780 --> 00:06:26,820 This is a brand who manufactures devices for industrial purposes. 84 00:06:27,300 --> 00:06:30,700 Uh, protocol converters, industrial routers, blah, blah, blah. 85 00:06:30,920 --> 00:06:37,100 They can, which, I don't know which is the relationship with MyQi, which is a Hong Kong company. 86 00:06:37,620 --> 00:06:42,700 Uh, they are using the same kind of server in both, uh, brands. 87 00:06:42,740 --> 00:06:49,520 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. 88 00:06:50,140 --> 00:06:53,720 Two brands, uh, using the same technology. 89 00:06:53,840 --> 00:06:59,340 There is another brand which is not included here, that I found last night, which is called KMC Controls. 90 00:06:59,340 --> 00:07:04,920 It's affected by the same, but it was found last night, so, it's, uh, new. 91 00:07:05,440 --> 00:07:11,800 Okay, this is the, the first device that, uh, I was able to exploit with this thing. 92 00:07:12,420 --> 00:07:16,480 Everything started here with this thing, the RLE protocol converter. 93 00:07:16,720 --> 00:07:27,920 Uh, what this, this thing does is, uh, trying to, well, actually, not trying to, okay, it converts, uh, Bagnet protocol to Modboost protocol. 94 00:07:27,920 --> 00:07:29,400 This is a protocol converter. 95 00:07:29,400 --> 00:07:41,220 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. 96 00:07:41,880 --> 00:07:51,220 Okay, the devices affected by this issue are this one, graphically, uh, Daikin and McQuay. 97 00:07:51,220 --> 00:07:57,040 They, uh, manufacture chilling, big chilling, big chillers, chillers, that's it, chillers. 98 00:07:57,680 --> 00:08:05,640 And those devices are connected to the internet, they have a web application in order to, uh, manage, configure, set up the whole thing. 99 00:08:07,180 --> 00:08:09,840 And things are just getting bigger and bigger. 100 00:08:10,780 --> 00:08:19,940 Okay, uh, this is an example of a Bagnet topology, how a Bagnet topology is, is, um, deployed in infrastructure. 101 00:08:20,600 --> 00:08:29,540 So our goal today is, or an attacker goal, is, uh, infect the engineer web browser. 102 00:08:29,540 --> 00:08:30,860 Why the engineer web browser? 103 00:08:30,860 --> 00:08:35,960 Because he's going to be connected to these kind of devices in every time. 104 00:08:36,040 --> 00:08:43,440 So usually those engineers, or these technicians, has access to another, uh, set of devices. 105 00:08:43,540 --> 00:08:55,680 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. 106 00:08:56,120 --> 00:09:00,360 Uh, we're talking about like an APT attack or some kind of thing, I don't know. 107 00:09:00,760 --> 00:09:15,500 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. 108 00:09:16,360 --> 00:09:18,780 This, this idea that I have with this. 109 00:09:19,560 --> 00:09:30,940 Okay, this is, this is taken from the Bagnet.org tutorial, um, basically the, the official documentation from Bagnet. 110 00:09:31,260 --> 00:09:35,200 And there is a little note, uh, about security. 111 00:09:35,200 --> 00:09:41,620 Because when I started this, I was, you know, interested in, uh , how the security of this thing works. 112 00:09:41,940 --> 00:09:43,920 But I found this. 113 00:09:44,280 --> 00:09:47,780 So there is a little discussion of security in this presentation. 114 00:09:47,960 --> 00:09:50,380 We have assumed that all nodes are trusted. 115 00:09:50,540 --> 00:09:54,340 Security will obviously be an important future consideration. 116 00:09:54,640 --> 00:09:58,480 For now, assume that all devices are sitting behind a firewall. 117 00:09:58,480 --> 00:10:05,000 That does packet filtering and the environment has well implemented restrictions on the software that can run inside a firewall. 118 00:10:05,360 --> 00:10:10,160 This is all the thing that this guy said about Bagnet security. 119 00:10:10,160 --> 00:10:12,400 You can find out in, in, in that link. 120 00:10:12,520 --> 00:10:18,960 This is all that you will have, uh, that you will find about, uh, security implementations and the protocol itself. 121 00:10:19,300 --> 00:10:22,900 So it means that there is no authentication methods. 122 00:10:22,900 --> 00:10:29,660 There is nothing, uh, to protect the, the protocol itself if there is no, uh, firewall, uh, very well implemented. 123 00:10:29,780 --> 00:10:31,040 And infrastructure. 124 00:10:31,840 --> 00:10:34,600 So our goal today will be the following. 125 00:10:34,860 --> 00:10:43,020 Uh, remote attacker from the internet, uh, has access to the device, but has no access to the web application. 126 00:10:43,800 --> 00:10:46,740 But has access to the Bagnet protocol. 127 00:10:46,740 --> 00:10:50,760 And he can read and modify things using just the protocol. 128 00:10:52,240 --> 00:10:54,960 So let's start with the Bagnet specs. 129 00:10:54,960 --> 00:11:01,460 In comparison with the OSI layers, uh, the Bagnet works in the application and network layer. 130 00:11:02,680 --> 00:11:04,880 And of course, IP. 131 00:11:05,500 --> 00:11:06,360 IP protocol. 132 00:11:06,360 --> 00:11:07,060 So let's start with the Bagnet protocol. 133 00:11:08,600 --> 00:11:13,080 It's, uh, the port is 47808. 134 00:11:13,080 --> 00:11:14,720 It's UDP based. 135 00:11:14,720 --> 00:11:17,700 No complex security mechanism, as, as I said. 136 00:11:17,700 --> 00:11:26,000 No CRC, no integrity checks, no hash, blank text, read write capabilities, and it's completely open in the internet. 137 00:11:26,000 --> 00:11:34,400 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. 138 00:11:35,860 --> 00:11:40,000 Okay, uh, so the Bagnet structure is basically Bagnet, Bagnet IP. 139 00:11:40,280 --> 00:11:47,500 The first layer would be the VUVLC or Bagnet virtual local control. 140 00:11:47,800 --> 00:11:55,500 The third layer, the second layer would be the MPDU, uh, network protocol data unit. 141 00:11:55,500 --> 00:12:04,800 And the last layer would be the application data unit, which contains all the information that we need to inject to the device. 142 00:12:05,220 --> 00:12:06,360 The magic happens there. 143 00:12:06,980 --> 00:12:12,300 Okay, let's talk about the first layer, the Bignot, Bagnet virtual link control. 144 00:12:12,760 --> 00:12:14,940 It's basically two bytes. 145 00:12:16,900 --> 00:12:18,600 Oh, excuse me, four bytes. 146 00:12:18,600 --> 00:12:19,700 It's four bytes. 147 00:12:19,740 --> 00:12:21,640 The first byte defines the type. 148 00:12:21,880 --> 00:12:27,140 In this case, Bagnet IP, which is, um, A1 and hex. 149 00:12:27,580 --> 00:12:29,840 The second one defines the function. 150 00:12:30,020 --> 00:12:36,520 In this case, uh, which function we, we would like to execute in, in, in the communication. 151 00:12:37,060 --> 00:12:41,180 And the last two bytes define the length of the whole packet. 152 00:12:41,180 --> 00:12:50,340 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. 153 00:12:50,340 --> 00:12:54,140 And then send it to, to the network and get the response. 154 00:12:54,300 --> 00:12:58,700 If that number is not correct, uh, you will get a more firm packet. 155 00:12:58,980 --> 00:13:00,480 So it's not going to work. 156 00:13:01,520 --> 00:13:06,240 This is a graphical representation in Wireshark about the first layer. 157 00:13:06,240 --> 00:13:08,400 The Bagnet virtual link control. 158 00:13:08,660 --> 00:13:10,360 You can see the function. 159 00:13:10,680 --> 00:13:14,460 This is our original unicast, unicast communication. 160 00:13:14,620 --> 00:13:18,300 And the two bytes are the length. 161 00:13:19,620 --> 00:13:23,040 Then we have the Bagnet network protocol data unit. 162 00:13:23,200 --> 00:13:28,300 This is a representation according to Bagnet wiki, but in practice it's just two bytes. 163 00:13:28,940 --> 00:13:30,260 Like this. 164 00:13:30,300 --> 00:13:35,160 So it's just telling you the version that you need to use and the control. 165 00:13:35,500 --> 00:13:39,320 So in this case, we set up the, the byte to four. 166 00:13:39,340 --> 00:13:43,460 Which means we are expecting reply from the device. 167 00:13:44,160 --> 00:13:52,700 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. 168 00:13:52,700 --> 00:13:54,340 If it's not properly configured. 169 00:13:54,340 --> 00:14:00,040 So you need to read the documentation and start constructing the packet byte by byte. 170 00:14:00,800 --> 00:14:04,340 And the last header is the Bagnet application data unit. 171 00:14:05,140 --> 00:14:15,540 Uh, this thing, uh, is the last header and contains, uh, variable length that also should be specified in that, in that header. 172 00:14:16,080 --> 00:14:19,900 Otherwise, you will face, uh, more phone packet issues again. 173 00:14:20,940 --> 00:14:24,180 This is how it looks like in Wireshark. 174 00:14:25,600 --> 00:14:25,940 Uh, this is a graphical representation of Wireshark . 175 00:14:26,240 --> 00:14:31,200 One important thing here is, uh, the service choice. 176 00:14:31,280 --> 00:14:39,520 The service choice is the, the byte that allows you, uh, read or write things in the Bagnet device. 177 00:14:39,840 --> 00:14:40,660 Okay? 178 00:14:41,100 --> 00:14:48,200 The magic is in the APU header that allows you to read or write values in the Bagnet data, uh, structure. 179 00:14:49,920 --> 00:14:53,500 Okay, here's what I'm talking about, the Bagnet service choice. 180 00:14:53,920 --> 00:15:02,180 So, you have all those values and bytes that allows you to set up how the communication is gonna be executed. 181 00:15:03,060 --> 00:15:11,580 So, in this case, we're gonna be using, uh, the 12 number value, which is 0C and hex, in order to read. 182 00:15:11,580 --> 00:15:12,420 Just read. 183 00:15:12,420 --> 00:15:13,140 Right? 184 00:15:15,940 --> 00:15:19,340 In order to read write, you need to set up correctly the service choice byte. 185 00:15:19,340 --> 00:15:32,380 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. 186 00:15:32,380 --> 00:15:35,340 If you send that byte, uh, the device will just restart. 187 00:15:35,340 --> 00:15:40,380 But we're not gonna be talking about this today, but keep in mind that this can be possible. 188 00:15:40,380 --> 00:15:43,240 Just sending a single packet to the network. 189 00:15:44,720 --> 00:15:52,780 So, in order to read, we'll be, and for write, it would be 0F. 190 00:15:52,800 --> 00:15:53,820 That's it. 191 00:15:56,380 --> 00:16:00,000 This is how, uh, a read packet looks like. 192 00:16:00,000 --> 00:16:06,060 You will see the read property configured there, and the number 12 in decimal. 193 00:16:08,380 --> 00:16:13,100 Okay, the values that we need to read and write will be the Bagnet objects. 194 00:16:13,100 --> 00:16:17,260 A Bagnet object is, uh, unique in a given device. 195 00:16:17,820 --> 00:16:22,040 It's a combination, uh, with many, uh, properties. 196 00:16:22,180 --> 00:16:35,760 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. 197 00:16:35,760 --> 00:16:40,680 This device has a name, and this device has, uh, his own properties . 198 00:16:40,940 --> 00:17:00,220 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. 199 00:17:02,120 --> 00:17:07,320 Okay, the object identifier contains the property identifier. 200 00:17:07,660 --> 00:17:17,220 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. 201 00:17:18,780 --> 00:17:27,740 So, in this case, we are reading, uh, that specific object, the object identifier, which is a property identifier. 202 00:17:27,740 --> 00:17:31,000 It's kind of confusing, but one thing is upon the other. 203 00:17:31,000 --> 00:17:33,880 A property identifier has an object identifier. 204 00:17:36,600 --> 00:17:41,120 So, if you see, this is encoded as a character string. 205 00:17:41,120 --> 00:17:47,440 The object name, uh, the location name, application software version is character string. 206 00:17:49,160 --> 00:17:55,040 There are several tools available you can use, uh, in order to read and write values with Bagnet. 207 00:17:55,040 --> 00:18:05,260 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. 208 00:18:05,260 --> 00:18:09,480 Uh, you can do this with any language that supports socket communication. 209 00:18:11,220 --> 00:18:15,780 Okay, let's take a look how this looks like in execution. 210 00:18:16,960 --> 00:18:25,000 So, this is an example of how our read package looks like, uh, in a really raw way, in a really primitive way. 211 00:18:25,000 --> 00:18:39,780 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? 212 00:18:42,000 --> 00:18:51,380 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. 213 00:18:52,440 --> 00:19:01,200 You will see the service choice, which is 12, properly configured, and then, uh, the object identifier. 214 00:19:01,200 --> 00:19:12,980 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. 215 00:19:13,260 --> 00:19:25,820 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. 216 00:19:25,820 --> 00:19:31,180 I mean, you can, you cannot execute something without that number specified in the packet. 217 00:19:31,440 --> 00:19:41,620 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. 218 00:19:41,620 --> 00:19:48,400 So, you need to first, uh, know this value in order to then, uh, write properly. 219 00:19:49,300 --> 00:19:54,180 Okay, let's 220 00:20:00,260 --> 00:20:08,820 develop, um, a tiny script in Python that perform all these things that I've been talking about. 221 00:20:09,680 --> 00:20:15,820 You can see the first, um, the first packet will be this thing. 222 00:20:16,300 --> 00:20:28,780 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. 223 00:20:29,200 --> 00:20:33,780 So, it's like, uh, 7 functions. 224 00:20:34,020 --> 00:20:37,660 Each packet is for each function. 225 00:20:37,660 --> 00:20:39,600 So, let's see how it works. 226 00:20:42,670 --> 00:20:47,710 Let's open the wire shark in order to see the communication flow. 227 00:20:48,630 --> 00:20:51,950 Okay, you see, there is a filter for BACnet. 228 00:20:51,950 --> 00:20:53,550 I'm going to execute this. 229 00:20:56,320 --> 00:20:58,840 And you see the communication. 230 00:20:59,220 --> 00:21:03,220 Correctly, I'm, um, I'm performing communication with the device remotely. 231 00:21:03,220 --> 00:21:06,080 This is a real device connected to the internet. 232 00:21:06,600 --> 00:21:10,920 And, uh, I am, I'm asking him information regarding BACnet. 233 00:21:10,920 --> 00:21:15,820 Specifically, I'm asking him for, uh, his object identifier. 234 00:21:16,060 --> 00:21:29,640 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. 235 00:21:29,940 --> 00:21:35,300 All this information is printed here, on, on, in the output of my script. 236 00:21:36,800 --> 00:21:41,840 This is, uh, my quite shiller, a big shiller, for sure. 237 00:21:42,600 --> 00:21:45,180 And this is how the communication works. 238 00:21:45,220 --> 00:21:50,980 When you understand this, when you, in practice, are able to do this, you are ready to write values. 239 00:21:50,980 --> 00:21:52,840 But which values are interesting? 240 00:21:52,840 --> 00:21:55,520 I mean, what can I do with this? 241 00:21:55,520 --> 00:22:03,060 That was the first question when I tried to figure out, found something in the protocol and the web application. 242 00:22:03,560 --> 00:22:09,480 Uh, the beginning, my purpose of all this whole thing was not to find web application issues. 243 00:22:09,560 --> 00:22:13,860 Uh, was to figure out how to find something in the protocol itself. 244 00:22:13,860 --> 00:22:18,420 I mean, execute the stuff, but in the process I found something cool. 245 00:22:18,780 --> 00:22:20,840 And this is the result. 246 00:22:21,880 --> 00:22:24,840 Okay, this is how you can, uh, communicate with the devices. 247 00:22:24,840 --> 00:22:47,360 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, 248 00:22:47,360 --> 00:22:49,780 uh, the plain state data coming from the device. 249 00:22:49,800 --> 00:22:50,280 Okay? 250 00:22:50,280 --> 00:22:50,900 Cool. 251 00:22:51,800 --> 00:22:53,700 Let's continue with the thing. 252 00:22:55,620 --> 00:22:57,640 Okay, let's check out the response. 253 00:22:57,640 --> 00:23:06,700 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. 254 00:23:06,700 --> 00:23:08,720 Remember that, that, that number. 255 00:23:08,760 --> 00:23:12,340 Keep this value in mind because we will use later in order to write. 256 00:23:12,720 --> 00:23:13,860 It's really important. 257 00:23:13,860 --> 00:23:28,310 Okay, now we know how to, okay, now we know how to read the specific values from the Bagnet data structure. 258 00:23:28,390 --> 00:23:31,970 But the cool thing is that we can modify those values. 259 00:23:32,530 --> 00:23:40,670 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. 260 00:23:40,730 --> 00:23:42,230 So this is cool. 261 00:23:42,250 --> 00:23:50,290 Because what if we could, uh, make a modify these string values for pieces of code. 262 00:23:50,290 --> 00:23:53,210 Pieces of Java, uh, HTML or JavaScript code. 263 00:23:53,630 --> 00:24:03,850 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. 264 00:24:04,230 --> 00:24:13,330 I needed, uh, a real device connected to the internet with this scenario, uh, in order to prove that this thing works. 265 00:24:13,330 --> 00:24:17,210 And well, I found it and, and, uh, this is what it is. 266 00:24:18,590 --> 00:24:20,210 The write property is tricky. 267 00:24:20,210 --> 00:24:29,310 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. 268 00:24:30,770 --> 00:24:34,810 Um, well the thing, the same thing about the device ID. 269 00:24:37,290 --> 00:24:50,530 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. 270 00:24:52,090 --> 00:24:57,490 So let's see how we can modify stuff. 271 00:25:02,480 --> 00:25:05,080 So this is a real thing. 272 00:25:06,520 --> 00:25:07,940 This is a real application. 273 00:25:07,940 --> 00:25:11,620 This is a real device, a MacQuietCheater connected to the internet. 274 00:25:12,360 --> 00:25:17,320 So, uh, when I found this, uh, it was the same impression as you. 275 00:25:17,320 --> 00:25:18,580 There is nothing there. 276 00:25:18,580 --> 00:25:25,700 I mean, it's not showing nothing, but if you right click on it and you check the source code, you will find Go. 277 00:25:25,800 --> 00:25:26,760 Why? 278 00:25:26,860 --> 00:25:31,140 Because here, first of all, there is a password. 279 00:25:31,240 --> 00:25:33,160 Um, let me check. 280 00:25:34,540 --> 00:25:37,240 Password for restart is 123. 281 00:25:38,280 --> 00:25:44,740 Yeah, this is out of scope today, but was a kind of, uh, nice, nice thing to find. 282 00:25:45,920 --> 00:25:53,000 And then, if you take a look closer to this thing, you will find something really cool. 283 00:25:55,020 --> 00:25:59,780 Ah, zoom in. 284 00:26:00,020 --> 00:26:01,060 Yeah, yeah, yeah. 285 00:26:02,360 --> 00:26:04,160 Let me see. 286 00:26:19,820 --> 00:26:21,920 Yeah, that's it. 287 00:26:23,240 --> 00:26:25,860 Okay, let's take a look at the password again. 288 00:26:25,860 --> 00:26:27,000 The funny part. 289 00:26:31,920 --> 00:26:35,040 Okay, there is a password for restart, 123. 290 00:26:35,680 --> 00:26:37,720 Uh, but here you cannot see any. 291 00:26:37,720 --> 00:26:41,180 I mean, on the main page you won't see any. 292 00:26:41,180 --> 00:26:44,500 You just need to check the source code in order to find cool things. 293 00:26:44,500 --> 00:26:48,160 But there was another thing that took my attention in the first place. 294 00:26:48,360 --> 00:26:50,960 The thing that is interesting here is this. 295 00:26:51,580 --> 00:26:52,680 The location. 296 00:26:52,940 --> 00:26:55,320 The location is Las Vegas. 297 00:26:55,440 --> 00:26:58,980 Well, I put this for, uh, demo purposes. 298 00:26:59,480 --> 00:27:06,240 But here, uh, I'm going to do this with, uh, this thing. 299 00:27:06,960 --> 00:27:10,000 This is, uh, Magnet Client. 300 00:27:10,660 --> 00:27:13,240 And you can do this from here. 301 00:27:13,720 --> 00:27:18,600 And now I change the location, the value from the location, right? 302 00:27:19,980 --> 00:27:24,220 So, if I reload this thing, I can see 303 00:27:27,600 --> 00:27:27,600 . 304 00:27:28,760 --> 00:27:37,390 Okay, there you go. 305 00:27:37,450 --> 00:27:39,370 Now let's check again the source code. 306 00:27:39,370 --> 00:27:43,910 And you will see how the location has changed by IOT. 307 00:27:45,950 --> 00:27:49,910 You see, now we are in IOT village. 308 00:27:50,030 --> 00:27:54,290 So, I did this from Magnet protocol. 309 00:27:54,510 --> 00:27:57,090 Uh, the device has no security. 310 00:27:57,090 --> 00:27:59,310 Actually there is no access for it. 311 00:27:59,310 --> 00:28:05,050 But I have access to the, to the protocol itself in order to modify stuff in the web application. 312 00:28:05,950 --> 00:28:10,190 So, now this is, this become a nice vector attack. 313 00:28:10,450 --> 00:28:16,770 A nice vector attack for, um, HTML or JavaScript code injection. 314 00:28:17,410 --> 00:28:18,910 And we are not using verb. 315 00:28:18,910 --> 00:28:19,990 That's the cool thing. 316 00:28:21,090 --> 00:28:24,970 Okay, so, now we know how to write. 317 00:28:26,130 --> 00:28:28,910 And now let's break it down, the exploit. 318 00:28:33,110 --> 00:28:38,350 Okay, the application is taking values from Magnet to be represented as string values in the web application. 319 00:28:38,630 --> 00:28:44,490 Those values can be modified from the Magnet data structure using the Magnet protocol write capabilities. 320 00:28:44,830 --> 00:28:50,370 And good theory is, I replace the string values for JavaScript code, the JavaScript code will be executed. 321 00:28:50,370 --> 00:28:52,510 Just in theory, at that time. 322 00:28:53,090 --> 00:28:57,730 Open up the source code, check again the value of location tag in the device. 323 00:28:58,050 --> 00:29:00,470 And our goal will be the following. 324 00:29:01,070 --> 00:29:03,830 Replace this thing for JavaScript code. 325 00:29:03,830 --> 00:29:10,430 And the result will be an stored, uh, crosshead scripting in the device web application in those tags. 326 00:29:10,750 --> 00:29:15,370 There is no need for a special XSS payload, a single alert in script tags. 327 00:29:15,370 --> 00:29:17,990 It's in order to figure the crosshead scripting. 328 00:29:18,510 --> 00:29:24,130 So, um, the application probably is password protected. 329 00:29:24,290 --> 00:29:28,650 So, as you can see, actually you don't need to touch it at all. 330 00:29:28,930 --> 00:29:36,970 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. 331 00:29:37,050 --> 00:29:38,710 Everything comes from the Magnet. 332 00:29:40,430 --> 00:29:42,350 But as I said, no problem. 333 00:29:42,450 --> 00:29:44,670 Magnet is available to inject code. 334 00:29:48,080 --> 00:29:52,920 And now we know we should place our exploit. 335 00:29:53,100 --> 00:29:54,780 So let's see the demo. 336 00:29:55,580 --> 00:29:57,760 I have a video because, you know. 337 00:30:09,840 --> 00:30:10,660 Okay, here we go. 338 00:30:10,660 --> 00:30:11,940 The same device. 339 00:30:16,980 --> 00:30:19,720 And first of all, read, of course. 340 00:30:19,820 --> 00:30:21,480 You will see the location. 341 00:30:22,240 --> 00:30:23,100 It's Vegas. 342 00:30:23,860 --> 00:30:26,760 Uh, check again the source code as I did. 343 00:30:28,180 --> 00:30:29,780 You will see the tags. 344 00:30:33,820 --> 00:30:37,180 All this information can be modified to description. 345 00:30:37,620 --> 00:30:41,920 I mean, you have several places to put JavaScript code. 346 00:30:42,140 --> 00:30:43,320 That kind of thing. 347 00:30:43,940 --> 00:30:47,160 But the cool thing is, as I said, the, the location value. 348 00:30:48,180 --> 00:30:51,280 Now let's change Vegas for a cool payload there. 349 00:30:57,300 --> 00:30:59,940 Okay, everything is still fine. 350 00:31:02,620 --> 00:31:04,820 Now let's take a look to our exploit. 351 00:31:04,820 --> 00:31:08,660 So, our exploit would be this way. 352 00:31:08,700 --> 00:31:09,660 Uh, the same thing. 353 00:31:09,660 --> 00:31:14,060 The four bytes, uh, the two bytes for the second header. 354 00:31:14,140 --> 00:31:24,280 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. 355 00:31:24,580 --> 00:31:27,580 So, you just need to send that. 356 00:31:27,900 --> 00:31:30,780 Don't expect a reply or anything because it's UDP. 357 00:31:31,200 --> 00:31:35,400 And the values are going to be injected in the web application. 358 00:31:41,280 --> 00:31:45,180 So, okay, now I just send the exploit. 359 00:31:47,320 --> 00:31:59,180 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. 360 00:32:04,100 --> 00:32:11,760 If you follow the UDP flow, you will see our payload there, our script alert payload there. 361 00:32:13,980 --> 00:32:18,240 And the acknowledgement from the device is expected. 362 00:32:19,880 --> 00:32:28,300 So, now if you reload, so there is your, uh, code executed in, in the web application. 363 00:32:28,680 --> 00:32:29,680 And it's persistent. 364 00:32:29,680 --> 00:32:33,340 I mean, this, this thing is going to be stored forever there. 365 00:32:33,480 --> 00:32:38,640 So, every time that someone connects to the device, it's going to, it's going to be, get infected, something. 366 00:32:42,380 --> 00:32:51,480 Okay, other things that you can do with this is, uh, for example, leak internal server routes. 367 00:32:51,480 --> 00:32:55,040 And you can see config object input that comes from the device. 368 00:32:55,040 --> 00:32:58,700 So, you have, uh, path leaks there. 369 00:32:58,920 --> 00:33:01,500 You can take advantage with Bagnet. 370 00:33:01,940 --> 00:33:08,660 And also, uh, check, uh, the, the device description for each, uh, profile. 371 00:33:08,660 --> 00:33:13,400 So, for example, this was, uh, elevator, free machine room temperature. 372 00:33:13,540 --> 00:33:20,840 So, you can enumerate what exactly which specific device does in the device. 373 00:33:21,260 --> 00:33:27,580 So, conclusions for this part, the techniques allow you to inject JavaScript without touching the web application at all. 374 00:33:27,720 --> 00:33:31,060 This, uh, JavaScript protocol base injection technique. 375 00:33:31,360 --> 00:33:36,080 In this particular scenario, we don't need credential or access to the web application. 376 00:33:36,100 --> 00:33:38,920 You just need to inject the payload and say goodbye. 377 00:33:39,000 --> 00:33:43,460 Several protocols are also affected by this kind of issues. 378 00:33:43,820 --> 00:33:52,240 But, you know, I can, uh, publish everything in one, in, in one talk. 379 00:33:52,260 --> 00:34:02,380 Uh, several Bagnet, several Bagnet devices with the port 47808 are vulnerable to be modified remotely using this Bagnet protocol. 380 00:34:04,180 --> 00:34:08,840 And the number of current devices affected is unknown, at least for me. 381 00:34:08,920 --> 00:34:12,300 Always, there are probably new technologies affected. 382 00:34:12,480 --> 00:34:14,640 There are several tools to read and write. 383 00:34:15,260 --> 00:34:19,740 If you're spreading issues, try to reproduce, try to reproduce the vulnerability this way. 384 00:34:19,740 --> 00:34:22,520 Check your backlinks or operation code. 385 00:34:22,560 --> 00:34:29,180 So, finally, the bonus track, uh, this is something that I found a couple of months ago. 386 00:34:29,960 --> 00:34:42,340 It's, uh, basically, uh, an RSC vulnerability and those devices from this brand called Forfait. 387 00:34:42,340 --> 00:34:47,280 So, Forfait is a Chinese brand of industrial devices. 388 00:34:48,160 --> 00:34:59,760 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. 389 00:35:00,240 --> 00:35:04,460 And, of course, they have, uh, devices connected to the internet. 390 00:35:05,080 --> 00:35:11,200 Uh, I found something really cool here, which is, uh, an option to execute commands. 391 00:35:12,080 --> 00:35:26,560 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. 392 00:35:26,980 --> 00:35:31,100 And, there is an option here, and 393 00:35:34,200 --> 00:35:40,820 application, this option called commands, administration commands, and you will find this. 394 00:35:41,560 --> 00:35:43,500 Take a look. 395 00:35:44,940 --> 00:36:01,160 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. 396 00:36:02,040 --> 00:36:23,760 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. 397 00:36:25,900 --> 00:36:37,480 So, just copy that thing, paste there, copy, and run the command. 398 00:36:44,090 --> 00:36:44,630 Great. 399 00:36:44,630 --> 00:36:49,930 Now, I'm going to show you the , here you go, and you will see the shell back to me, remotely from the internet. 400 00:36:52,310 --> 00:36:53,670 And there you go. 401 00:36:57,840 --> 00:37:04,260 And also, you can perform a cat, you know, the same thing as usual, ATC, password, and that's it. 402 00:37:04,820 --> 00:37:10,620 Well, this kind of issues are always in those kind of devices, it's the same thing all the time. 403 00:37:11,380 --> 00:37:16,740 Uh, it's really, really easy to spot RCEs, um, I don't know. 404 00:37:17,280 --> 00:37:20,160 The thing continues, I mean, the research continues. 405 00:37:22,320 --> 00:37:25,260 Well, I think that is done for today. 406 00:37:25,260 --> 00:37:27,640 Any question or something, just let me know. 407 00:37:27,660 --> 00:37:37,220 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. 408 00:37:37,500 --> 00:37:38,300 Welcome.