githubEdit

MySQL Pentesting

It is a relational database management system. A default port is 3306.

Enumeration

nmap --script mysql-info -p 3306 <target-ip>
nmap --script mysql-enum -p 3306 <target-ip>
nmap --script mysql-brute -p 3306 <target-ip>
nmap --script mysql-databases -p 3306 <target-ip>
nmap --script mysql-users -p 3306 <target-ip>
nmap --script mysql-* -p 3306 <target-ip>

Brute Force Credentials

hydra -l username -P passwords.txt <target-ip> mysql
hydra -L usernames.txt -p password <target-ip> mysql

Configuration Files

cat /etc/mysql/my.cnf
cat /etc/mysql/mysql.conf.d/mysqld.cnf

Connect

mysql command can be replaced with mariadb .

Local

Remote

Commands

Execute from File

After connecting MySQL, you can execute SQL commands from a .sql file. Note that we need to change the current directory to the directory in which the .sql file is located.

Basic Commands

Belows are basic commands.

Command Injection

We can inject the OS command to column values e.g. email address. Depending on the situation, we may be able to execute arbitrary command.

System Commands

We can run the system command in MySQL shell as below. Depending on the situation, we may be able to escalate privileges.

Last updated