Exploiting with Metasploit
Getting Started
Before beginning, deploy the room and give it time to boot. This can take up to five minutes, so be patient.
When You Would Begin Attacking MySQL
MySQL is likely not the first point of call when gathering initial information about a server. As in previous tasks, you can try to brute-force default account passwords if you really have nothing else to go on, but in most CTF scenarios that is unlikely to be the intended avenue.
The Scenario
Typically you will have gained some initial credentials by enumerating other services, which you then use to enumerate and exploit MySQL. Since this room focuses on exploiting and enumerating the network service, we'll assume we found the credentials: "root:password" while enumerating subdomains of a web server. After trying them against SSH without success, we try them against MySQL.
Requirements
You'll want a MySQL client to connect to the remote server. If it isn't installed, you can add it with sudo apt install default-mysql-client. This installs only the client, not the server package.
We'll again be using Metasploit, which is installed by default on both Kali Linux and Parrot OS.
Alternatives
As with the previous task, everything done here with Metasploit can also be done manually or with non-Metasploit tools, such as Nmap's mysql-enum script (https://nmap.org/nsedoc/scripts/mysql-enum.html) or https://www.exploit-db.com/exploits/23081. After finishing the room, it's worth going back and attempting it manually to make sure you understand the process behind the information you acquire.
Manually connecting to a MySQL server, which is important for OSCP:
mysql -h [IP] -u [username] -p
The relevant Metasploit modules can be found by searching for mysql_sql, mysql_schemadump, or mysql_hashdump:
search mysql_sql
Once connected, these queries give the version and list the databases:
select version()
show databases
Schema
In MySQL, physically, a schema is synonymous with a database. You can substitute the keyword "SCHEMA" instead of DATABASE in MySQL SQL syntax, for example using CREATE SCHEMA instead of CREATE DATABASE. It's important to understand this relationship because some other database products draw a distinction. For example, in the Oracle Database product, a schema represents only a part of a database: the tables and other objects owned by a single user.
Hashes
Hashes are, very simply, the product of a cryptographic algorithm that turns a variable-length input into a fixed-length output.
In MySQL, hashes can be used in different ways, for instance to index data into a hash table. Each hash has a unique ID that serves as a pointer to the original data. This creates an index significantly smaller than the original data, letting the values be searched and accessed more efficiently.
The data we're going to extract, though, is password hashes, which are simply a way of storing passwords rather than keeping them in plaintext.
Let's get cracking.