> ## Documentation Index
> Fetch the complete documentation index at: https://www.0101isnothacking.nl/llms.txt
> Use this file to discover all available pages before exploring further.

# MySQL enumeration

> Quick reference for enumerating MySQL on port 3306, including nmap scripts, brute force, and SQL commands.

MySQL is a structured query language database that runs on port 3306.

> [!WARNING]
>
> Only run brute-force and hashdump actions against systems you are authorized to test.

## Nmap

```sh theme={null}
nmap -p3306 <ip>
```

## Banner grabbing

```sh theme={null}
telnet <ip> 3306
nc -nv <ip> 3306
```

## Nmap scripts

```sh theme={null}
sudo nmap -p3306 --script=mysql-info <ip>
sudo nmap <ip> -p3306 -sVC --script mysql*
sudo nmap -p3306 -sVC -A <ip>
```

## Users enumeration and brute force

```sh theme={null}
# Check default credentials
mysql -h <ip> -u root -p

# Work around SSL certificate chain errors
mysql -h $ip -u user -ppassword --ssl-verify-server-cert=FALSE

# Brute force usernames and passwords
hydra -L users.txt -P pass.txt <ip> mysql
```

## Database enumeration

### Metasploit modules

```text theme={null}
use auxiliary/admin/mysql/mysql_sql
use auxiliary/scanner/mysql/mysql_schemadump
use auxiliary/scanner/mysql/mysql_hashdump
use auxiliary/admin/mysql/mysql_enum
use auxiliary/scanner/mysql/mysql_file_enum
```

### SQL statements

```sql theme={null}
show databases;
use <database>;
show tables;
select * from <table_name>;
select column1, column2, column3 from <table_name>;
```

## Steps

![MySQL enumeration steps](https://mintcdn.com/non-9fcb5a21/P-t86H21MW2fT7Il/images/09e702eb1925.png?fit=max\&auto=format\&n=P-t86H21MW2fT7Il\&q=85\&s=12d67abbde6025965722387546ba3c20)

## Dangerous Settings

| Setting | Description |
| - | - |
| `user` | Sets which user the MySQL service will run as. |
| `password` | Sets the password for the MySQL user. |
| `admin_address` | The IP address on which to listen for TCP/IP connections on the administrative network interface. |
| `debug` | This variable indicates the current debugging settings. |
| `sql_warnings` | This variable controls whether single-row INSERT statements produce an information string if warnings occur. |
| `secure_file_priv` | This variable is used to limit the effect of data import and export operations. |

## Commands

| Command | Description |
| - | - |
| `mysql -u <user> -p<password> -h <IP address>` | Connect to the MySQL server. There should **not** be a space between the `-p` flag and the password. |
| `show databases;` | Show all databases. |
| `use <database>;` | Select one of the existing databases. |
| `show tables;` | Show all available tables in the selected database. |
| `show columns from <table>;` | Show all columns in the selected table. |
| `select * from <table>;` | Show everything in the desired table. |
| `select * from <table> where <column> = "<string>";` | Search for the needed string in the desired table. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.