21. Nmap MySQL Enumeration
MySQL is a widely used database management system that often operates on port 3306. The following Nmap commands leverage NSE scripts to gather information, enumerate database details, check for misconfigurations, and test credentials.
1. MySQL Service Information¶
Command:¶
Explanation:¶
-p 3306:- Scans port 3306, the default port for MySQL.
--script mysql-info:- Executes the
mysql-infoscript, which gathers basic information about the MySQL service.
- Executes the
Purpose:¶
- Provides metadata about the MySQL server, including version details, supported features, and capabilities.
Example Output:¶
PORT STATE SERVICE
3306/tcp open mysql
| mysql-info:
| Protocol: 10
| Version: 8.0.32
| Thread ID: 3
| Capabilities: Connect with SSL, Transactions, Secure Auth
|_ Status: Auth required
Insights:¶
- Protocol and Version: Useful for identifying vulnerabilities specific to the MySQL version.
- Capabilities: Shows the features enabled on the server (e.g., SSL support, secure authentication).
2. MySQL Enumeration¶
Command:¶
Explanation:¶
--script mysql-enum:- Executes the
mysql-enumscript, which attempts to enumerate databases, users, and privileges (if authentication details are not required).
- Executes the
Purpose:¶
- Gathers database-related information, including user accounts and privileges (if accessible).
Example Output:¶
PORT STATE SERVICE
3306/tcp open mysql
| mysql-enum:
| Users: root, admin, guest
| Databases: information_schema, test_db
|_ Privileges: root=ALL PRIVILEGES, admin=SELECT
Insights:¶
- Users: Identifies potential usernames for further testing.
- Databases: Lists databases hosted on the server.
- Privileges: Reveals misconfigurations or overly permissive user rights.
3. MySQL Empty Password Check¶
Command:¶
Explanation:¶
--script mysql-empty-password:- Executes the
mysql-empty-passwordscript, which checks if the MySQL server allows login with an empty password.
- Executes the
Purpose:¶
- Detects weak authentication configurations where accounts can log in without a password.
Example Output:¶
PORT STATE SERVICE
3306/tcp open mysql
| mysql-empty-password:
|_ Account 'root'@'localhost' has an empty password
Insights:¶
- Weak Credentials: Highlights serious misconfigurations that allow unauthorized access.
4. MySQL Brute-Forcing¶
Command:¶
Explanation:¶
--script mysql-brute:- Executes the
mysql-brutescript, which attempts to brute-force MySQL user credentials.
- Executes the
--script-args mysql-brute.thread=100:- Sets the number of concurrent threads to 100 for faster brute-forcing attempts.
Purpose:¶
- Tests the strength of MySQL account passwords by attempting logins with a pre-defined username/password list.
Example Output:¶
Insights:¶
- Discovered Credentials: Identifies weak or default passwords that can compromise the server.
- Performance: Adjusting thread count speeds up brute-forcing but may overwhelm the server.
Comparison of Scripts¶
| Script | Purpose | Output |
|---|---|---|
mysql-info |
Provides basic MySQL server information. | Protocol, version, capabilities, and status. |
mysql-enum |
Enumerates databases, users, and rights. | Usernames, database names, and user privileges. |
mysql-empty-password |
Checks for accounts with no passwords. | Lists accounts with empty passwords. |
mysql-brute |
Attempts to brute-force MySQL accounts. | Credentials discovered (if successful). |
Actionable Insights:¶
-
Information Gathering:
- Use
mysql-infoto identify the server's version and features. - Use
mysql-enumto enumerate accessible users and databases. -
Weak Credential Detection:
-
Use
mysql-empty-passwordto find accounts with no passwords. - Use
mysql-bruteto test for weak or default credentials. -
Next Steps:
-
If weak credentials are found, log in to assess the database (only if authorized).
- If a vulnerable version is detected, search for relevant exploits (e.g., CVEs).
-
Ethical Considerations:
-
Always obtain permission before performing these scans.
- Avoid brute-forcing or exploiting servers without explicit authorization.
- Use
Use Case:¶
These scripts are essential for penetration testers and security analysts to identify potential vulnerabilities in MySQL servers during security assessments.