MySQL

MySQL Services

MySQL is one of the most widely used relational database management systems in the world. As an open-source solution, it powers countless web applications, content management systems, and enterprise solutions. From a penetration testing perspective, MySQL databases often contain valuable information and can serve as stepping stones for deeper network penetration.

Basic Concepts

MySQL typically operates on port 3306/TCP and uses a client-server architecture:

  • mysqld: The server daemon that handles database operations

  • mysql: The command-line client for interacting with the server

Default Databases in MySQL

MySQL installations include several system databases:

  • mysql: System database containing user accounts and privileges

  • information_schema: Provides access to database metadata

  • performance_schema: Used for monitoring MySQL server execution

  • sys: A set of objects that helps interpret performance schema data

Enumeration Techniques

Port Scanning

Example output:

The server responds with a banner that often includes version information:

Authentication Methods

Authentication Basics

MySQL supports multiple authentication methods:

  • Username/password authentication

  • Unix socket authentication (local)

  • Windows authentication (when on Windows)

  • Plugin-based authentication (PAM, LDAP, etc.)

Connecting to MySQL

Testing for Default Credentials

Common default credentials include:

  • root with no password

  • root/root

  • root/password

  • admin/admin

Brute Force Attacks

Post-Authentication Enumeration

Once authenticated, gather information about the database environment:

Listing Databases

Example output:

Selecting a Database

Listing Tables

Example output:

Viewing Table Structure

Example output:

Querying Data

Example output:

Server Configuration Information

User Information and Privileges

Exploiting MySQL Vulnerabilities

File System Access

MySQL can be used to read from and write to the file system if configured improperly:

Reading Files

Writing Files

Common locations to target:

User-Defined Functions (UDFs)

If the MySQL user has sufficient privileges, UDFs can be loaded to execute system commands:

SQL Injection

When MySQL is used by web applications, SQL injection vulnerabilities may exist:

Privilege Escalation

Exploiting MySQL for System Access

If MySQL is running as root or a privileged user, it can be leveraged for privilege escalation:

Abusing MySQL Administration Tools

Network Attacks

Capturing MySQL Traffic

Man-in-the-Middle (MITM) Attacks

If MySQL is not using SSL/TLS, credentials and queries may be intercepted:

Relay Attacks

Similar to SMB relay attacks, MySQL credentials can sometimes be relayed to other services:

Defense Evasion Techniques

Avoiding Detection During Testing

  1. Rate limiting: Space out authentication attempts

  2. Minimal queries: Only execute necessary queries

  3. Controlled connections: Don't establish too many connections simultaneously

  4. Clean up: Remove temporary files or artifacts

Securing MySQL Services

When testing MySQL services, consider these security recommendations:

  1. Authentication: Use strong, unique passwords and consider MFA

  2. Network security: Restrict access to MySQL port

  3. File privileges: Restrict secure_file_priv appropriately

  4. User privileges: Apply principle of least privilege

  5. Encryption: Enable SSL/TLS for connections

  6. Auditing: Enable audit logging

  7. Regular updates: Keep MySQL software updated

Penetration Testing Methodology

When testing MySQL services, follow these steps:

  1. Discovery: Identify MySQL services through port scanning

  2. Enumeration: Determine version and configuration

  3. Authentication testing: Test for weak credentials

  4. Privilege assessment: Identify permissions of authenticated users

  5. Data analysis: Enumerate and analyze accessible databases

  6. Vulnerability testing: Test for known vulnerabilities based on version

  7. Configuration review: Assess security settings

  8. Exploitation: Leverage identified vulnerabilities

Practical Testing Scripts

Automated MySQL User Enumeration

Database Schema Mapper

Common MySQL Commands Reference

By understanding MySQL services and their security implications, penetration testers can effectively identify vulnerabilities and provide valuable recommendations for securing these critical database systems.

Last updated