Enumerate and exploit MySQL database servers to read files, write webshells, and extract sensitive data including credentials. MySQL often runs with elevated privileges and can be leveraged for command execution and privilege escalation.
Port Scanning
# Scan MySQL port sudo nmap -p 3306 -sV -sC --script mysql* 10.10.10.10
Authentication
# Connect to MySQL mysql -u root -h 10.10.10.10 -p
# Connect with password (no space after -p) mysql -u root -p'password' -h 10.10.10.10
# Connect to specific database mysql -u root -p'password' -h 10.10.10.10 -D database_name
Database Enumeration
List Databases
-- Show all databases SHOW DATABASES;
-- MySQL default databases: -- mysql: system database with server information -- information_schema: database metadata -- performance_schema: server execution monitoring -- sys: performance schema helper objects
Select Database
USE database_name;
List Tables
-- Show tables in current database SHOW TABLES;
-- Show tables in specific database SHOW TABLES FROM database_name;
List Columns
-- Show columns in table SHOW COLUMNS FROM table_name;
-- Alternative DESCRIBE table_name;
Query Data
-- Select all from table SELECT*FROM table_name;
-- Select specific columns SELECT username,password FROM users;
-- Filter results SELECT*FROM users WHERE username ='admin';
File Operations
Check File Privileges
-- Check secure_file_priv setting SHOW VARIABLES LIKE "secure_file_priv";
-- Empty value: no restrictions (insecure) -- Directory path: restricted to that directory -- NULL: file operations disabled
-- Check local_infile setting SHOW VARIABLES LIKE'local_infile';