MySQL Enumeration
Overview
MySQL is an open-source SQL relational database management system developed and supported by Oracle. A database is simply a structured collection of data organized for easy use and retrieval. The database system can quickly process large amounts of data with high performance.
Key Characteristics:
Port 3306: Default MySQL port
Protocol: MySQL native protocol over TCP
Authentication: Username/password based
Default Users: root, mysql
File Extension: .sql files (e.g., wordpress.sql)
MySQL Architecture
MySQL Clients
The MySQL clients can retrieve and edit data using structured queries to the database engine. Operations include:
Inserting: Adding new records
Deleting: Removing records
Modifying: Updating existing records
Retrieving: Querying data
MySQL Databases
MySQL is ideally suited for applications such as:
Dynamic websites: Efficient syntax and high response speed
Web applications: Content management systems like WordPress
LAMP Stack: Linux, Apache, MySQL, PHP
LEMP Stack: Linux, Nginx, MySQL, PHP
Database Content Types
MySQL databases commonly store:
Headers
Page titles, meta information
Texts
Article content, descriptions
Meta tags
SEO tags, keywords
Forms
Contact forms, registration data
Users
Customers, Usernames, Administrators, Moderators
Authentication
Email addresses, User information, Permissions, Passwords
Links
External/Internal links, Links to Files
Content
Specific contents, Values
Security Note: Sensitive data like passwords can be stored in plain-text form by MySQL, but are generally encrypted by PHP scripts using secure methods like One-Way-Encryption.
MySQL Commands
A MySQL database translates commands internally into executable code. SQL commands can:
Display, modify, add, or delete rows in tables
Change table structure
Create or delete relationships and indexes
Manage users and permissions
Default Configuration
Installation and Configuration Analysis
Default Configuration Output
Dangerous Settings
Security-Relevant Configuration Options
user
Sets which user the MySQL service will run as
High
password
Sets the password for the MySQL user
Critical
admin_address
IP address for TCP/IP connections on administrative network interface
High
debug
Indicates current debugging settings
Medium
sql_warnings
Controls whether single-row INSERT statements produce information strings
Medium
secure_file_priv
Limits the effect of data import and export operations
High
Security Issues
Plain-text Credentials: user, password, and admin_address entries are in plain text
File Permissions: Configuration files often have incorrect permissions
Information Disclosure: debug and sql_warnings provide verbose error output
Privilege Escalation: Verbose errors can reveal system information
Command Execution: SQL injections can potentially execute system commands
Footprinting the Service
Service Detection
Important Note: Scan results should be manually verified as some information might be false-positive.
Connection Testing
SSL/TLS Connection Issues
SSL/TLS Error Types:
ERROR 2026: TLS/SSL error with self-signed certificates
Solution: Use
--ssl=0or--ssl-mode=DISABLEDto bypass SSL verificationSecurity Note: Only disable SSL in testing environments, not production
Interaction with MySQL Server
Successful Connection Example
System Schema Exploration
System Schema (sys) Analysis
Essential MySQL Commands
Connection and Basic Operations
mysql -u <user> -p<password> -h <IP address>
Connect to MySQL server (no space between -p and 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 needed string in the desired table
Advanced Query Examples
Database Schema Information
Important System Databases
information_schema: Contains metadata about all databases (ANSI/ISO standard)
mysql: Contains MySQL server system data and configurations
performance_schema: Contains performance monitoring information
sys: Contains system schema with interpreted performance data
Schema Differences:
System Schema: Microsoft system catalog (more comprehensive)
Information Schema: ANSI/ISO standard metadata (standardized)
HTB Academy Lab Questions
Question 1: Version Detection
Task: Enumerate the MySQL server and determine the version in use Format: MySQL X.X.XX
Solution:
Question 2: Data Extraction
Task: Using credentials "robin:robin", find email address of customer "Otto Lang"
Solution:
Security Assessment
Common Vulnerabilities
Default Credentials: Testing root with empty password
Weak Passwords: Common password patterns
Information Disclosure: Version information, database names
Excessive Privileges: Users with unnecessary permissions
Configuration Issues: Dangerous settings enabled
Network Exposure: MySQL accessible from external networks
Enumeration Checklist
MariaDB Relationship
MariaDB is a fork of MySQL created when Oracle acquired MySQL AB. Key points:
Created by original MySQL chief developer
Based on MySQL source code
Often used interchangeably with MySQL
Compatible with MySQL protocols and commands
Common in Linux distributions
Reference Documentation
MySQL Reference Manual: Comprehensive configuration options
Security Issues Section: Best practices for securing MySQL servers
HTB Academy: Practical enumeration techniques
Penetration Testing: Real-world attack scenarios
Last updated