Listing MySQL databases

MySQL servers may contain several databases. As system administrators with legitimate access or penetration testers who just compromised the server, we can list the available databases using Nmap.

This recipe teaches how to use Nmap NSE to list databases in a MySQL server.

How to do it...

Open a terminal and enter the following command:

$ nmap -p3306 --script mysql-databases --script-args mysqluser=<user>,mysqlpass=<password> <target>

The databases should be listed under the script results.

3306/tcp open  mysql
| mysql-databases:  
|   information_schema
|   temp
|   websec
|   ids
|_  crm

How it works...

The argument -p3306 --script mysql-databases --script-args mysqluser=<user>,mysqlpass=<password> tells Nmap to attempt a connection to the MySQL server using the given credentials (--script-args mysqluser=<user>,mysqlpass=<password>) and tries to list all the available databases in the server.

The script mysql-databases was written by Patrik Karlsson to help Nmap users enumerate databases in MySQL installations.

There's more...

To try to enumerate databases if an empty root account is found we can use the command:

# nmap -p3306 --script mysql-empty-password,mysql-databases <target>  

If the service is running on an port different than 3306 we can use Nmap's service detection (-sV), or set the port manually with the argument -p.

# nmap -sV --script mysql-databases <target>$ nmap -p1111 –script mysql-databases <target>

See also

  • The Listing MySQL users recipe
  • The Listing MySQL variables recipe
  • The Finding root accounts with empty passwords in MySQL servers recipe
  • The Brute forcing MySQL passwords recipe
  • The Detecting insecure configurations in MySQL servers recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.74.232