[00:00.000 --> 00:07.140] We know that bots are everywhere, they're scanning your servers, they're doing it fast, and [00:07.140 --> 00:18.420] database servers is obviously a big target. So we have created a high interaction MySQL [00:18.420 --> 00:28.160] honeypot. So we create a tool that mimics the database, implements MySQL protocol, and those [00:28.160 --> 00:37.500] bots start connecting to this honeypot. So we need to understand the MySQL protocol. And [00:37.500 --> 00:46.160] MySQL protocol, unlike other database protocols, actually a server initiated. So if we just [00:46.160 --> 00:53.700] start a TCP server, then it will not be enough. If you connect to your MySQL server using [00:53.700 --> 01:02.060] Telnet on the port 3306, you will see this. And this is what MySQL server provides for the [01:02.060 --> 01:08.460] client to be able to connect. It specifies version, it specifies fault, it specifies client [01:08.460 --> 01:18.120] plugin. So listening to the port, a TCP server is not enough. So what we did to create the [01:18.120 --> 01:27.560] high interaction MySQL honeypot is we used the Python module. The Python provides, there's a [01:27.560 --> 01:33.540] module called MySQL mimic. It implements MySQL protocol, it's a really powerful thing, and you [01:33.540 --> 01:41.960] can do a lot of things with that. So from there, we started the honeypot, and we start receiving [01:41.960 --> 01:49.000] the connections. So you start the honeypot as a fake MySQL server on an open port from the [01:49.000 --> 01:55.500] internet. And you start receiving the connections. And you can see a lot of information about the [01:55.500 --> 02:03.800] connection actually. Like the HTTP protocol, MySQL protocol also have this client version [02:03.800 --> 02:10.980] recorded and stuff like that. So this is called attributes. MySQL provides a lot of attributes as [02:11.080 --> 02:16.040] a part of the connection. That's part of protocol. We have client version, OS, and stuff [02:16.040 --> 02:22.320] like that. So we started the honeypot and we immediately see the fingerprints of the [02:22.320 --> 02:28.440] connections. And you can see the version of the client library, you can see the operating [02:28.440 --> 02:36.820] system, you can see all other stuff. This is very useful actually. Now from there, the part [02:36.820 --> 02:49.960] two is what kind of attacks we have. We have seen from this honeypot, we see two major [02:49.960 --> 02:56.640] attacks on MySQL. The first is an attempt to own MySQL server and create a backdoor. This [02:56.640 --> 03:01.640] actually pretty well-known attack, and there's a blog post about that. What is interesting [03:01.640 --> 03:10.840] about that is we can see right away that it's using a very old MySQL client version. It [03:10.840 --> 03:17.400] actually only works for older servers as well. So the second is even more interesting [03:17.400 --> 03:24.840] attack. It's a ransomware. It tries to download your data, basically brute force the [03:24.840 --> 03:33.740] password first, then try to download the data, and then drops the databases and asks for [03:33.740 --> 03:39.860] ransom. So this is exactly the same thing. We see the fingerprints. We see what OS version, [03:39.860 --> 03:49.940] we see what the client is using. So now, from there, we started an atomic version of the [03:49.940 --> 03:59.080] honeypot. Honeypot that strikes back. So what we want to do, our goal is actually interact [03:59.080 --> 04:05.880] with those attacks. And our goal was to see what they are doing, how they do that, and [04:05.880 --> 04:13.780] potentially download the malicious code that they are using. So our atomic honeypot now [04:13.780 --> 04:24.640] strikes back. What do we have? So we have been juggling with different CVEs in MySQL client. [04:25.020 --> 04:34.760] And we have arbitrary file read, which is super old issue. We have the remote code execution [04:34.760 --> 04:43.760] where MySQL server attacks you. We actually found that issue a year ago, 2023. We have [04:43.780 --> 04:54.380] presented it, and we can use that to actually execute code on the client. And then finally, [04:54.380 --> 05:01.620] this year we have found another issue in MySQL client utility. We reported it to Oracle. This [05:01.620 --> 05:13.360] is the second remote code execution in MySQL client. All right. So MySQL server attacks MySQL [05:13.360 --> 05:21.420] client. This is how it works. There are two things here. The first thing is that we have a MySQL [05:21.420 --> 05:29.320] client arbitrary file read, and we create a server, and then your client connects to the server, and [05:29.320 --> 05:38.900] the server requests a file. So we can have an arbitrary file read from the client. The second is [05:38.900 --> 05:44.360] the one that we found a year ago, and we presented it last year. There are lots of details [05:44.360 --> 05:50.920] there. And basically, the prerequisite of this attack is that you need to have the shared [05:50.920 --> 05:57.460] library uploaded to the client first. Then, whatever the connection will be established, you [05:57.460 --> 06:05.580] can actually take that client connection to execute your shared library. You don't need to [06:06.240 --> 06:14.080] execute the shared library itself. You just need to have that file on the client. And finally, we [06:14.080 --> 06:20.520] have found this year, we have found a new issue in MySQL client utility, and then I will [06:20.520 --> 06:27.980] invite Martin, my colleague Martin, to explain how it works. And this is the first time we are [06:27.980 --> 06:32.280] releasing the details about the CVE. Martin? [06:34.250 --> 06:42.800] Hi. So let's jump into this CVE. As you probably know, MySQL dump is a tool which allows you to [06:42.800 --> 06:52.360] produce logical backups of a database, basic script tables, and other objects and data to be [06:52.360 --> 07:01.700] transferred to another server. So this is an example how you can use MySQL dump together with [07:01.700 --> 07:09.480] MySQL. You just pipe the output of MySQL dump to MySQL to recreate a database on another [07:09.480 --> 07:15.720] server. And this is pretty close to what the official documentation says. Where is the [07:15.720 --> 07:23.500] problem? The MySQL utility allows you to use so-called meta comments. For example, if you do [07:23.500 --> 07:29.880] backslash, exclamation mark, and then space in the comment, it's going to execute a shell [07:29.880 --> 07:37.940] comment on a computer where the MySQL tool is running. So the CVE itself is about tricking MySQL [07:37.940 --> 07:45.700] dump to emit such a shell comment, for example. So how this works exactly? By default, MySQL [07:46.340 --> 07:54.280] dump tries to process everything it receives from a server, but it's not the case for the version. As [07:54.280 --> 08:00.380] you can see, there is a version string coming from a server, and it is emitted as a comment in the [08:00.380 --> 08:08.620] output of MySQL dump. But this is not processed, this is not sanitized, and it just is sent back to [08:08.620 --> 08:15.620] output as is. We can leverage this by simply creating our own server, the MySQL server. [08:15.720 --> 08:21.360] So this is a patched version of a server. As you can see here, I just replaced a version with a [08:21.360 --> 08:27.300] hard-coded string, a new line, and then my comment of choice to be executed on the machine. Here, [08:27.300 --> 08:33.180] just create a file. And if you could tell that to this patched server, you will see this. In red, [08:33.180 --> 08:41.980] you see our comment. And then, this is output of a MySQL dump. We have a common execution for [08:41.980 --> 08:51.520] this vulnerability. All we need to do is to provide a fake server. So, we have created Honeypot, [08:51.520 --> 08:59.980] which is a Python code, which allows you to exploit this specific vulnerability and also the [08:59.980 --> 09:08.760] plugin-loading vulnerability by passing specific configuration options to this Honeypot. The goal [09:08.760 --> 09:16.080] is simple. We try to run code on the clients who connect to our Honeypot by leveraging these [09:16.600 --> 09:30.200] vulnerabilities. And here's a demo. So, let's see. We have a payload script, a VBS script, which [09:30.200 --> 09:35.920] will be running on Windows, which just pops up a message, you have been pwned. Now, we start our [09:35.920 --> 09:49.800] Honeypot and pass the payload. And once... also, we start the HTTP server. And once the MySQL dump [09:49.800 --> 09:58.500] is executed on Windows now, the version is 36, which is one version before the latest, we get this [09:58.500 --> 10:04.800] pwned message. That's it. Back to you, Alex. [10:05.600 --> 10:19.620] Thank you very much. Alright, so now we successfully pwned the client. We were actually trying to [10:19.620 --> 10:30.980] figure out and scratching our heads, how do we actually attack those bad guys? So, back to the two [10:30.980 --> 10:39.160] attacks that we have been working on. The first attack, this is what we have captured, a [10:39.160 --> 10:50.320] fingerprint. Right? So, from the fingerprint itself, we can already see what we can or cannot do. So, [10:50.320 --> 10:56.420] arbitrary file read, we know this is old version. We know that it will work. Remote code execution [10:56.420 --> 11:02.760] with a plugin. We don't know. We will try it out. And there is no MySQL dump in this particular [11:02.760 --> 11:11.680] attack, so we will not be able to use the newest version. So, how do we use the arbitrary file read? [11:11.680 --> 11:16.840] Arbitrary file read is super easy. There is a tool that you can download from the internet, from the [11:16.840 --> 11:24.160] GitHub. You start this tool and you simply specify the file that you want to download from the [11:24.160 --> 11:30.580] client. Again, the client will be connecting to the server, this is fake server, and then we will be [11:30.580 --> 11:41.560] able to read the file. So, this is how the client arbitrary file read works. I will go through this [11:41.560 --> 11:54.140] real quick. So, you have this, um, uh, I download this tool, I start this tool on port 3306 and I [11:55.020 --> 12:04.040] request a password. And now I'm connecting from my machine with the old version of MySQL, uh, and I [12:04.040 --> 12:12.900] connect into this fake server and here I go. I got the file. So, I obtain this file. This is an old [12:12.900 --> 12:25.260] attack. Now, how can we use that? What we want to do is we want to first understand which version of [12:25.260 --> 12:32.920] Windows those attackers, those bots, are using. There are a number of, um, ways how you can [12:32.920 --> 12:40.060] determine the version of Windows by downloading the file. So, we started this file list and we [12:40.060 --> 12:47.720] determined that this is really old version of Windows. This is Windows server 2003. Alright, so [12:47.720 --> 12:54.960] with this attack, we were able to understand and get more details about what the attackers are [12:54.960 --> 13:03.620] using. Now, let's try the remote code execution. The remote code execution is actually on [13:03.620 --> 13:10.920] Windows you need DLL. We need to deliver that DLL to the attacker's machines, to the client, to be [13:10.920 --> 13:22.400] able to trigger it. So, we started to think, how do we deliver this code? Again, DLL doesn't need to [13:22.400 --> 13:29.440] be triggered on the client. We are triggering through the remote code execution. What we did is [13:29.440 --> 13:37.560] we collected the fingerprint, the actual commands that the server, the client, is running, is [13:37.560 --> 13:44.980] trying to run on the server. And we can see that what they are trying to do is they are trying to [13:44.980 --> 13:54.140] download the malicious code on the server. So, they are running an FTP server on their own [13:54.140 --> 14:01.320] machine. And we know the password, the username, and the port of the server. So, we started [14:01.320 --> 14:10.900] creating the simulation. Here's our plan of attack. We will upload the DDL to a public location on [14:10.900 --> 14:20.580] the client. On the actual server, Windows 2003. And then we will run the honeypot, wait for the [14:20.580 --> 14:25.700] connection, and through the connection we will trigger that DLL so we will have the remote code [14:25.700 --> 14:35.240] execution. So, we created this RCE via the simulation. So, this is how it could work. First of [14:35.240 --> 14:43.460] all, we have, we are connecting to FTP server here. Simulating that we are connecting to the [14:43.460 --> 14:56.480] actual machine. We, we do the demo demo, now we will put our evil DLL. And now, after we put [14:56.480 --> 15:05.220] the evil DLL in a public location, then we will start the server, the honeypot. So, we will [15:05.240 --> 15:14.820] start the server. Uh, this is the startup script. We specify the plugin dir, public documents, and [15:14.820 --> 15:25.160] then this thing will actually trigger the execution of our DLL via the directory traversal. I don't [15:25.160 --> 15:31.520] have much time to explain this attack, but this has been explained, uh, last year. You can [15:31.520 --> 15:37.860] actually see the recording from the HIDBI. Basically, there is a plugin dir in my SQL and the [15:37.860 --> 15:44.820] file name, and we use the directory traversal to actually trigger DLL open, which, or, or load [15:44.820 --> 15:51.820] library on Windows, which is in the server. Now, I'm listening on the port, and now here's my [15:51.820 --> 16:01.500] DDL. My DDL is displaying the, um, the text and actually create, uh, the, um, um, uh, [16:02.420 --> 16:11.800] dialogue. Here's how it works. So, we have this MySQL command line utility, and we have the evil [16:11.800 --> 16:22.740] DLL, uh, uploaded to the client. Now, the client in this simulation, that's the bad actor, they are [16:22.740 --> 16:29.700] connecting to us. And here's, here we go. We actually executed the code, remote code [16:29.700 --> 16:41.640] execution. Thank you. Alright, so this is done. We demonstrated arbitrary file read, we [16:41.640 --> 16:49.360] demonstrated remote code execution, uh, with a plugin. So, the second attack is even more [16:49.360 --> 16:58.340] interesting. Now, from the fingerprint, what do we see? We see this is later versions of MySQL [16:58.340 --> 17:06.320] client. We know that this remote code execution via plugin will not work. But, what we see [17:06.320 --> 17:13.500] immediately is that it's using MySQL dump. This is the utility, we actually found a way to, to [17:13.500 --> 17:20.100] do the, the code execution. And then again, we were scratching our heads, and then we decide, [17:20.100 --> 17:25.740] well, let's collect more information. Let's understand how this attack is being, uh, [17:25.740 --> 17:33.600] executed. So, this is what we see. The, the application that connects to, uh, our server, [17:33.600 --> 17:41.880] right? It, um, uh, connects to the server, do the show databases, and then what it will do is it [17:41.880 --> 17:52.840] will run, it will execute MySQL dump utility and, uh, pass the database and the table name. [17:52.840 --> 18:04.220] So, basically what it do, the, the goal of this thing is to download the database so that they [18:04.220 --> 18:11.700] can actually claim that they download your data. But, we can see that they're only [18:11.700 --> 18:20.220] downloading ten records. So, don't pay, obviously, right? Don't pay. Those guys don't [18:20.220 --> 18:24.980] have your data. They claim that they have downloaded, backed it up, backed your [18:24.980 --> 18:33.820] database, but they didn't. They only have ten records. Right? And then, from here, we [18:33.820 --> 18:40.420] were started brainstorming. Can we download the code via arbitrary file rate? No. Can we [18:40.420 --> 18:46.480] execute code via plugin? Actually, no as well. Right? We know because this is the newer [18:46.480 --> 18:52.460] versions. So, we started looking again, how this attack is being handled. So, we see [18:52.460 --> 18:58.040] that they're using MySQL, MyADB connector, right? This is from the fingerprint. This should [18:58.040 --> 19:04.700] be some application there, right? And then suddenly, MySQL dump connects to our server. So, [19:04.700 --> 19:12.240] they probably do some execution of the MySQL dump and then we see back, we see that the [19:12.240 --> 19:21.140] application connects back. So, we also see this. Again, we are providing the server. Whatever [19:21.140 --> 19:28.120] client will execute, we will see immediately. And this is what we see. This is our table that [19:28.120 --> 19:36.340] we generated. It's sending it up, up, back to us. So, maybe, if this is what they're doing, [19:36.340 --> 19:44.760] maybe we can actually do a command injection. And, we started experimenting with this. We [19:44.760 --> 19:50.960] created a fake database. A schema name is a database in MySQL. We created this, a [19:50.960 --> 20:00.040] classical command injection. And, uh, we were surprised. It actually worked. So, we use the [20:00.040 --> 20:07.640] command injection on this client attack, right? On this bot, just like this, and we receive all [20:07.640 --> 20:14.300] the information, uh, out of this command back to us. So, we downloaded the evil code from [20:14.300 --> 20:22.320] those attackers. This is how it is looking like. It's a MySQL dump. We have a command [20:22.320 --> 20:29.740] injection here and here's what we see. We got the evil code. So, it's a Python script. It's a [20:29.740 --> 20:37.920] Python script that connects to your database, try to brute force the password, and then, uh, [20:37.920 --> 20:43.660] execute the MySQL dump. The multiple injections. We were looking at this code and we were [20:43.660 --> 20:49.980] like, well, there are multiple places where you can execute the command. Alright, so, we [20:49.980 --> 20:59.200] successfully, we achieved our goal, but not the way we thought originally. We executed the [20:59.200 --> 21:07.980] command injection. How do you try that at home? Uh, I'm pretty sure this will be fixed shortly, [21:07.980 --> 21:14.800] so you need to try it right now if you want to see what it looks like. Uh, and you don't even [21:14.800 --> 21:22.520] need the tool. You can start a MySQL database server, any version. You will create a root [21:22.520 --> 21:30.000] with no password. This is a born version of, of MySQL server, right? You don't care if they [21:30.000 --> 21:35.760] will be downloading your data. Uh, I'm done almost. And then you open that and this is the [21:35.760 --> 21:42.860] injections that you will do. Create database, put it in a backticks, and that's it. This is [21:42.860 --> 21:50.640] how you will be able to attack, uh, the bad guys. Alright, this is done. All done. So, new [21:50.640 --> 21:53.460] CV, details, and thank you.