1 00:00:00,000 --> 00:00:11,000 We know that bots are everywhere, they're scanning your servers, they're doing it fast, and database servers is obviously a big target. 2 00:00:11,940 --> 00:00:20,000 So we have created a high interaction MySQL honeypot. 3 00:00:20,260 --> 00:00:32,460 So we create a tool that mimics the database, implements MySQL protocol, and those bots start connecting to this honeypot. 4 00:00:33,780 --> 00:00:37,360 So we need to understand the MySQL protocol. 5 00:00:37,360 --> 00:00:45,020 And MySQL protocol, unlike other database protocols, actually a server initiated. 6 00:00:45,020 --> 00:00:50,200 So if we just start a TCP server, then it will not be enough. 7 00:00:50,200 --> 00:00:58,380 If you connect to your MySQL server using Telnet on the port 3306, you will see this. 8 00:00:58,860 --> 00:01:04,160 And this is what MySQL server provides for the client to be able to connect. 9 00:01:04,160 --> 00:01:09,500 It specifies version, it specifies fault, it specifies client plugin. 10 00:01:10,860 --> 00:01:15,660 So listening to the port, a TCP server is not enough. 11 00:01:16,100 --> 00:01:24,400 So what we did to create the high interaction MySQL honeypot is we used the Python module. 12 00:01:25,000 --> 00:01:28,960 The Python provides, there's a module called MySQL mimic. 13 00:01:28,960 --> 00:01:35,460 It implements MySQL protocol, it's a really powerful thing, and you can do a lot of things with that. 14 00:01:36,300 --> 00:01:43,080 So from there, we started the honeypot, and we start receiving the connections. 15 00:01:43,080 --> 00:01:49,860 So you start the honeypot as a fake MySQL server on an open port from the internet. 16 00:01:49,860 --> 00:01:52,060 And you start receiving the connections. 17 00:01:52,180 --> 00:01:57,100 And you can see a lot of information about the connection actually. 18 00:01:57,100 --> 00:02:06,480 Like the HTTP protocol, MySQL protocol also have this client version recorded and stuff like that. 19 00:02:06,480 --> 00:02:08,640 So this is called attributes. 20 00:02:08,640 --> 00:02:12,160 MySQL provides a lot of attributes as a part of the connection. 21 00:02:12,160 --> 00:02:13,420 That's part of protocol. 22 00:02:13,420 --> 00:02:17,120 We have client version, OS, and stuff like that. 23 00:02:17,140 --> 00:02:23,000 So we started the honeypot and we immediately see the fingerprints of the connections. 24 00:02:23,000 --> 00:02:31,220 And you can see the version of the client library, you can see the operating system, you can see all other stuff. 25 00:02:31,220 --> 00:02:33,060 This is very useful actually. 26 00:02:34,380 --> 00:02:41,500 Now from there, the part two is what kind of attacks we have. 27 00:02:41,500 --> 00:02:51,020 We have seen from this honeypot, we see two major attacks on MySQL. 28 00:02:51,020 --> 00:02:56,460 The first is an attempt to own MySQL server and create a backdoor. 29 00:02:56,460 --> 00:03:00,840 This actually pretty well-known attack, and there's a blog post about that. 30 00:03:00,840 --> 00:03:10,760 What is interesting about that is we can see right away that it's using a very old MySQL client version. 31 00:03:10,760 --> 00:03:14,660 It actually only works for older servers as well. 32 00:03:15,100 --> 00:03:18,140 So the second is even more interesting attack. 33 00:03:18,140 --> 00:03:19,880 It's a ransomware. 34 00:03:20,120 --> 00:03:34,840 It tries to download your data, basically brute force the password first, then try to download the data, and then drops the databases and asks for ransom. 35 00:03:35,120 --> 00:03:37,140 So this is exactly the same thing. 36 00:03:37,140 --> 00:03:38,280 We see the fingerprints. 37 00:03:38,280 --> 00:03:43,080 We see what OS version, we see what the client is using. 38 00:03:43,480 --> 00:03:50,620 So now, from there, we started an atomic version of the honeypot. 39 00:03:50,820 --> 00:03:53,320 Honeypot that strikes back. 40 00:03:53,340 --> 00:04:00,940 So what we want to do, our goal is actually interact with those attacks. 41 00:04:01,140 --> 00:04:10,560 And our goal was to see what they are doing, how they do that, and potentially download the malicious code that they are using. 42 00:04:11,380 --> 00:04:15,660 So our atomic honeypot now strikes back. 43 00:04:15,740 --> 00:04:17,500 What do we have? 44 00:04:17,500 --> 00:04:24,640 So we have been juggling with different CVEs in MySQL client. 45 00:04:25,020 --> 00:04:30,920 And we have arbitrary file read, which is super old issue. 46 00:04:31,080 --> 00:04:38,720 We have the remote code execution where MySQL server attacks you. 47 00:04:38,720 --> 00:04:43,380 We actually found that issue a year ago, 2023. 48 00:04:43,380 --> 00:04:52,500 We have presented it, and we can use that to actually execute code on the client. 49 00:04:52,760 --> 00:05:00,140 And then finally, this year we have found another issue in MySQL client utility. 50 00:05:00,140 --> 00:05:01,480 We reported it to Oracle. 51 00:05:01,480 --> 00:05:06,660 This is the second remote code execution in MySQL client. 52 00:05:07,840 --> 00:05:09,020 All right. 53 00:05:09,020 --> 00:05:13,960 So MySQL server attacks MySQL client. 54 00:05:13,960 --> 00:05:15,920 This is how it works. 55 00:05:16,320 --> 00:05:18,300 There are two things here. 56 00:05:18,560 --> 00:05:32,620 The first thing is that we have a MySQL client arbitrary file read, and we create a server, and then your client connects to the server, and the server requests a file. 57 00:05:33,080 --> 00:05:37,620 So we can have an arbitrary file read from the client. 58 00:05:37,620 --> 00:05:43,360 The second is the one that we found a year ago, and we presented it last year. 59 00:05:43,360 --> 00:05:45,400 There are lots of details there. 60 00:05:45,400 --> 00:05:54,000 And basically, the prerequisite of this attack is that you need to have the shared library uploaded to the client first. 61 00:05:54,000 --> 00:06:04,420 Then, whatever the connection will be established, you can actually take that client connection to execute your shared library. 62 00:06:04,500 --> 00:06:08,360 You don't need to execute the shared library itself. 63 00:06:08,360 --> 00:06:11,640 You just need to have that file on the client. 64 00:06:12,600 --> 00:06:25,140 And finally, we have found this year, we have found a new issue in MySQL client utility, and then I will invite Martin, my colleague Martin, to explain how it works. 65 00:06:25,140 --> 00:06:31,020 And this is the first time we are releasing the details about the CVE. 66 00:06:31,020 --> 00:06:32,280 Martin? 67 00:06:34,250 --> 00:06:35,420 Hi. 68 00:06:35,480 --> 00:06:38,880 So let's jump into this CVE. 69 00:06:39,140 --> 00:06:55,560 As you probably know, MySQL dump is a tool which allows you to produce logical backups of a database, basic script tables, and other objects and data to be transferred to another server. 70 00:06:56,060 --> 00:07:02,920 So this is an example how you can use MySQL dump together with MySQL. 71 00:07:02,920 --> 00:07:10,480 You just pipe the output of MySQL dump to MySQL to recreate a database on another server. 72 00:07:10,480 --> 00:07:14,360 And this is pretty close to what the official documentation says. 73 00:07:14,720 --> 00:07:16,400 Where is the problem? 74 00:07:16,400 --> 00:07:21,960 The MySQL utility allows you to use so-called meta comments. 75 00:07:22,060 --> 00:07:33,760 For example, if you do backslash, exclamation mark, and then space in the comment, it's going to execute a shell comment on a computer where the MySQL tool is running. 76 00:07:34,000 --> 00:07:41,720 So the CVE itself is about tricking MySQL dump to emit such a shell comment, for example. 77 00:07:42,180 --> 00:07:44,980 So how this works exactly? 78 00:07:44,980 --> 00:07:54,140 By default, MySQL dump tries to process everything it receives from a server, but it's not the case for the version. 79 00:07:54,140 --> 00:08:02,220 As you can see, there is a version string coming from a server, and it is emitted as a comment in the output of MySQL dump. 80 00:08:02,220 --> 00:08:10,040 But this is not processed, this is not sanitized, and it just is sent back to output as is. 81 00:08:10,040 --> 00:08:15,620 We can leverage this by simply creating our own server, the MySQL server. 82 00:08:15,720 --> 00:08:17,660 So this is a patched version of a server. 83 00:08:17,880 --> 00:08:26,620 As you can see here, I just replaced a version with a hard -coded string, a new line, and then my comment of choice to be executed on the machine. 84 00:08:26,620 --> 00:08:28,400 Here, just create a file. 85 00:08:28,840 --> 00:08:32,500 And if you could tell that to this patched server, you will see this. 86 00:08:32,500 --> 00:08:34,500 In red, you see our comment. 87 00:08:35,200 --> 00:08:38,940 And then, this is output of a MySQL dump. 88 00:08:38,940 --> 00:08:43,380 We have a common execution for this vulnerability. 89 00:08:43,380 --> 00:08:47,460 All we need to do is to provide a fake server. 90 00:08:48,140 --> 00:09:07,840 So, we have created Honeypot, which is a Python code, which allows you to exploit this specific vulnerability and also the plugin-loading vulnerability by passing specific configuration options to this Honeypot. 91 00:09:07,840 --> 00:09:09,960 The goal is simple. 92 00:09:09,960 --> 00:09:17,700 We try to run code on the clients who connect to our Honeypot by leveraging these vulnerabilities. 93 00:09:18,560 --> 00:09:20,620 And here's a demo. 94 00:09:24,180 --> 00:09:25,720 So, let's see. 95 00:09:25,720 --> 00:09:34,640 We have a payload script, a VBS script, which will be running on Windows, which just pops up a message, you have been pwned. 96 00:09:34,640 --> 00:09:39,360 Now, we start our Honeypot and pass the payload. 97 00:09:39,460 --> 00:09:48,260 And once... also, we start the HTTP server. 98 00:09:48,260 --> 00:10:00,020 And once the MySQL dump is executed on Windows now, the version is 36, which is one version before the latest, we get this pwned message. 99 00:10:01,240 --> 00:10:02,680 That's it. 100 00:10:03,620 --> 00:10:04,800 Back to you, Alex. 101 00:10:05,600 --> 00:10:08,500 Thank you very much. 102 00:10:08,720 --> 00:10:14,520 Alright, so now we successfully pwned the client. 103 00:10:14,620 --> 00:10:28,780 We were actually trying to figure out and scratching our heads, how do we actually attack those bad guys? 104 00:10:28,780 --> 00:10:33,420 So, back to the two attacks that we have been working on. 105 00:10:33,740 --> 00:10:39,700 The first attack, this is what we have captured, a fingerprint . 106 00:10:39,860 --> 00:10:40,800 Right? 107 00:10:40,800 --> 00:10:49,000 So, from the fingerprint itself, we can already see what we can or cannot do. 108 00:10:49,180 --> 00:10:53,080 So, arbitrary file read, we know this is old version. 109 00:10:53,080 --> 00:10:55,100 We know that it will work. 110 00:10:55,100 --> 00:10:57,500 Remote code execution with a plugin. 111 00:10:57,500 --> 00:10:58,600 We don't know. 112 00:10:58,600 --> 00:10:59,880 We will try it out. 113 00:10:59,880 --> 00:11:06,160 And there is no MySQL dump in this particular attack, so we will not be able to use the newest version. 114 00:11:06,740 --> 00:11:11,680 So, how do we use the arbitrary file read? 115 00:11:11,680 --> 00:11:13,600 Arbitrary file read is super easy. 116 00:11:13,600 --> 00:11:17,520 There is a tool that you can download from the internet, from the GitHub. 117 00:11:17,520 --> 00:11:24,720 You start this tool and you simply specify the file that you want to download from the client. 118 00:11:24,720 --> 00:11:32,400 Again, the client will be connecting to the server, this is fake server, and then we will be able to read the file. 119 00:11:32,500 --> 00:11:39,860 So, this is how the client arbitrary file read works. 120 00:11:39,860 --> 00:11:43,000 I will go through this real quick. 121 00:11:43,000 --> 00:11:57,220 So, you have this, um, uh, I download this tool, I start this tool on port 3306 and I request a password. 122 00:11:57,320 --> 00:12:08,480 And now I'm connecting from my machine with the old version of MySQL, uh, and I connect into this fake server and here I go. 123 00:12:08,480 --> 00:12:09,880 I got the file. 124 00:12:09,880 --> 00:12:11,480 So, I obtain this file. 125 00:12:11,480 --> 00:12:13,620 This is an old attack. 126 00:12:13,620 --> 00:12:16,680 Now, how can we use that? 127 00:12:18,740 --> 00:12:30,040 What we want to do is we want to first understand which version of Windows those attackers, those bots, are using. 128 00:12:30,120 --> 00:12:37,180 There are a number of, um, ways how you can determine the version of Windows by downloading the file. 129 00:12:37,180 --> 00:12:43,700 So, we started this file list and we determined that this is really old version of Windows. 130 00:12:43,700 --> 00:12:46,400 This is Windows server 2003. 131 00:12:46,800 --> 00:12:55,860 Alright, so with this attack, we were able to understand and get more details about what the attackers are using. 132 00:12:56,280 --> 00:13:00,700 Now, let's try the remote code execution. 133 00:13:00,720 --> 00:13:05,360 The remote code execution is actually on Windows you need DLL. 134 00:13:05,360 --> 00:13:12,520 We need to deliver that DLL to the attacker's machines, to the client, to be able to trigger it. 135 00:13:12,520 --> 00:13:20,940 So, we started to think, how do we deliver this code? 136 00:13:20,940 --> 00:13:23,780 Again, DLL doesn't need to be triggered on the client. 137 00:13:23,780 --> 00:13:27,420 We are triggering through the remote code execution. 138 00:13:27,980 --> 00:13:39,140 What we did is we collected the fingerprint, the actual commands that the server, the client, is running, is trying to run on the server. 139 00:13:39,560 --> 00:13:50,040 And we can see that what they are trying to do is they are trying to download the malicious code on the server. 140 00:13:50,080 --> 00:13:55,240 So, they are running an FTP server on their own machine. 141 00:13:55,260 --> 00:14:00,580 And we know the password, the username, and the port of the server. 142 00:14:00,580 --> 00:14:02,680 So, we started creating the simulation. 143 00:14:02,680 --> 00:14:04,580 Here's our plan of attack. 144 00:14:05,080 --> 00:14:12,540 We will upload the DDL to a public location on the client. 145 00:14:12,540 --> 00:14:16,140 On the actual server, Windows 2003. 146 00:14:16,260 --> 00:14:26,660 And then we will run the honeypot, wait for the connection, and through the connection we will trigger that DLL so we will have the remote code execution. 147 00:14:26,660 --> 00:14:31,840 So, we created this RCE via the simulation. 148 00:14:31,840 --> 00:14:34,640 So, this is how it could work. 149 00:14:34,640 --> 00:14:39,760 First of all, we have, we are connecting to FTP server here. 150 00:14:41,300 --> 00:14:44,720 Simulating that we are connecting to the actual machine. 151 00:14:44,720 --> 00:14:52,560 We, we do the demo demo, now we will put our evil DLL. 152 00:14:54,380 --> 00:15:05,220 And now, after we put the evil DLL in a public location, then we will start the server, the honeypot. 153 00:15:05,220 --> 00:15:06,140 So, we will start the server. 154 00:15:06,140 --> 00:15:09,140 Uh, this is the startup script. 155 00:15:09,140 --> 00:15:23,880 We specify the plugin dir, public documents, and then this thing will actually trigger the execution of our DLL via the directory traversal. 156 00:15:23,880 --> 00:15:30,880 I don't have much time to explain this attack, but this has been explained, uh, last year. 157 00:15:30,880 --> 00:15:34,540 You can actually see the recording from the HIDBI. 158 00:15:35,080 --> 00:15:47,840 Basically, there is a plugin dir in my SQL and the file name, and we use the directory traversal to actually trigger DLL open, which, or, or load library on Windows, which is in the server. 159 00:15:47,840 --> 00:15:52,880 Now, I'm listening on the port, and now here's my DDL. 160 00:15:52,880 --> 00:16:03,500 My DDL is displaying the, um, the text and actually create, uh, the, um, um, uh, dialogue. 161 00:16:03,800 --> 00:16:07,260 Here's how it works. 162 00:16:07,320 --> 00:16:16,980 So, we have this MySQL command line utility, and we have the evil DLL, uh, uploaded to the client. 163 00:16:16,980 --> 00:16:24,040 Now, the client in this simulation, that's the bad actor, they are connecting to us. 164 00:16:24,040 --> 00:16:25,240 And here's, here we go. 165 00:16:25,240 --> 00:16:30,760 We actually executed the code, remote code execution. 166 00:16:32,180 --> 00:16:33,660 Thank you. 167 00:16:37,200 --> 00:16:39,260 Alright, so this is done. 168 00:16:39,260 --> 00:16:46,060 We demonstrated arbitrary file read, we demonstrated remote code execution, uh, with a plugin. 169 00:16:46,420 --> 00:16:50,480 So, the second attack is even more interesting. 170 00:16:50,800 --> 00:16:53,380 Now, from the fingerprint, what do we see? 171 00:16:53,380 --> 00:16:59,120 We see this is later versions of MySQL client. 172 00:16:59,120 --> 00:17:04,740 We know that this remote code execution via plugin will not work. 173 00:17:04,740 --> 00:17:09,800 But, what we see immediately is that it's using MySQL dump. 174 00:17:09,800 --> 00:17:15,780 This is the utility, we actually found a way to, to do the, the code execution. 175 00:17:15,780 --> 00:17:21,720 And then again, we were scratching our heads, and then we decide, well, let's collect more information. 176 00:17:21,720 --> 00:17:26,640 Let's understand how this attack is being, uh, executed. 177 00:17:26,800 --> 00:17:29,080 So, this is what we see. 178 00:17:29,140 --> 00:17:33,940 The, the application that connects to, uh, our server, right? 179 00:17:33,940 --> 00:17:52,840 It, um, uh, connects to the server, do the show databases, and then what it will do is it will run, it will execute MySQL dump utility and, uh, pass the database and the table name. 180 00:17:52,840 --> 00:18:09,100 So, basically what it do, the, the goal of this thing is to download the database so that they can actually claim that they download your data. 181 00:18:09,180 --> 00:18:14,260 But, we can see that they're only downloading ten records. 182 00:18:14,300 --> 00:18:18,300 So, don't pay, obviously, right? 183 00:18:18,300 --> 00:18:19,060 Don't pay. 184 00:18:19,060 --> 00:18:20,960 Those guys don't have your data. 185 00:18:20,960 --> 00:18:26,860 They claim that they have downloaded, backed it up, backed your database, but they didn't. 186 00:18:26,860 --> 00:18:28,560 They only have ten records. 187 00:18:29,180 --> 00:18:29,620 Right? 188 00:18:29,620 --> 00:18:35,780 And then, from here, we were started brainstorming. 189 00:18:35,780 --> 00:18:39,060 Can we download the code via arbitrary file rate? 190 00:18:39,240 --> 00:18:39,960 No. 191 00:18:39,960 --> 00:18:42,240 Can we execute code via plugin? 192 00:18:42,420 --> 00:18:43,980 Actually, no as well. 193 00:18:43,980 --> 00:18:44,400 Right? 194 00:18:44,400 --> 00:18:47,300 We know because this is the newer versions. 195 00:18:47,340 --> 00:18:51,460 So, we started looking again, how this attack is being handled. 196 00:18:51,460 --> 00:18:55,780 So, we see that they're using MySQL, MyADB connector, right? 197 00:18:55,780 --> 00:18:57,280 This is from the fingerprint. 198 00:18:57,580 --> 00:18:59,880 This should be some application there, right? 199 00:18:59,880 --> 00:19:04,360 And then suddenly, MySQL dump connects to our server. 200 00:19:04,400 --> 00:19:14,660 So, they probably do some execution of the MySQL dump and then we see back, we see that the application connects back. 201 00:19:15,200 --> 00:19:17,880 So, we also see this. 202 00:19:18,180 --> 00:19:20,900 Again, we are providing the server. 203 00:19:20,920 --> 00:19:25,000 Whatever client will execute, we will see immediately. 204 00:19:25,580 --> 00:19:26,840 And this is what we see. 205 00:19:26,840 --> 00:19:29,280 This is our table that we generated. 206 00:19:29,280 --> 00:19:31,820 It's sending it up, up, back to us. 207 00:19:32,460 --> 00:19:39,900 So, maybe, if this is what they're doing, maybe we can actually do a command injection. 208 00:19:40,740 --> 00:19:44,660 And, we started experimenting with this. 209 00:19:44,660 --> 00:19:46,980 We created a fake database. 210 00:19:46,980 --> 00:19:48,900 A schema name is a database in MySQL. 211 00:19:48,900 --> 00:19:53,180 We created this, a classical command injection. 212 00:19:54,000 --> 00:19:56,860 And, uh, we were surprised. 213 00:19:56,860 --> 00:19:58,760 It actually worked. 214 00:19:58,760 --> 00:20:04,580 So, we use the command injection on this client attack, right? 215 00:20:04,580 --> 00:20:11,200 On this bot, just like this, and we receive all the information, uh, out of this command back to us. 216 00:20:11,200 --> 00:20:15,980 So, we downloaded the evil code from those attackers. 217 00:20:15,980 --> 00:20:19,780 This is how it is looking like. 218 00:20:19,780 --> 00:20:21,600 It's a MySQL dump. 219 00:20:21,600 --> 00:20:25,720 We have a command injection here and here's what we see. 220 00:20:25,720 --> 00:20:27,160 We got the evil code. 221 00:20:27,160 --> 00:20:29,180 So, it's a Python script. 222 00:20:29,180 --> 00:20:39,740 It's a Python script that connects to your database, try to brute force the password, and then, uh, execute the MySQL dump. 223 00:20:39,740 --> 00:20:41,040 The multiple injections. 224 00:20:41,040 --> 00:20:48,280 We were looking at this code and we were like, well, there are multiple places where you can execute the command. 225 00:20:48,800 --> 00:20:58,280 Alright, so, we successfully, we achieved our goal, but not the way we thought originally. 226 00:20:58,280 --> 00:21:00,320 We executed the command injection. 227 00:21:00,440 --> 00:21:03,360 How do you try that at home? 228 00:21:03,860 --> 00:21:12,800 Uh, I'm pretty sure this will be fixed shortly, so you need to try it right now if you want to see what it looks like. 229 00:21:12,960 --> 00:21:16,140 Uh, and you don't even need the tool. 230 00:21:16,300 --> 00:21:20,920 You can start a MySQL database server, any version. 231 00:21:21,020 --> 00:21:24,040 You will create a root with no password. 232 00:21:24,240 --> 00:21:28,700 This is a born version of, of MySQL server, right? 233 00:21:28,700 --> 00:21:32,540 You don't care if they will be downloading your data. 234 00:21:32,540 --> 00:21:33,900 Uh, I'm done almost. 235 00:21:33,900 --> 00:21:38,520 And then you open that and this is the injections that you will do. 236 00:21:38,520 --> 00:21:42,300 Create database, put it in a backticks, and that's it. 237 00:21:42,300 --> 00:21:47,620 This is how you will be able to attack, uh, the bad guys. 238 00:21:47,620 --> 00:21:48,640 Alright, this is done. 239 00:21:48,640 --> 00:21:49,500 All done. 240 00:21:49,500 --> 00:21:53,460 So, new CV, details, and thank you.