CTF Arsenal
Boot2Root/Other B2R Topics

Exposed Database Exploitation

Concept

Databases exposed directly to the network (MySQL 3306, Redis 6379, MongoDB 27017) sometimes allow unauthenticated or default-credential access, leaking application data or, for Redis, enabling file write for RCE via known techniques.

When to Use

  • Database ports found open during port scanning.

Workflow

  1. 1
    Test unauthenticated/default-credential access

    Each DB engine has its own defaults.

  2. 2
    Enumerate databases/tables/keys

    Pull application data.

  3. 3
    Check for write-based RCE primitives

    e.g. Redis module load / cron write.

Commands

mysql -h TARGET_IP -u root
mysql -h 10.10.11.25 -u root

Attempts to connect to a remote MySQL server as root with no password.

  • -h — Remote host.

When to use: First test when 3306 is open and reachable.

Expected output:

mysql> (prompt, connected)

Look for: Successful connection without a password.

Next step: SHOW DATABASES; then SELECT * FROM users; on an application database.

redis-cli -h TARGET_IP
redis-cli -h 10.10.11.25

Connects to a Redis instance; many CTF/misconfigured Redis servers require no authentication at all.

When to use: When 6379 is open.

Expected output:

10.10.11.25:6379> (prompt)

Look for: INFO command succeeding without AUTH — confirms no password is set.

Next step: Use CONFIG GET dir / CONFIG SET dir to attempt writing a file (e.g. an SSH authorized_keys entry) if the target permits it.

Tools

mysql client

Interactive MySQL/MariaDB client.

When to use: Default tool once credentials or no-auth access is confirmed.

sudo apt install mysql-client
mysql -h HOST -u USER -p

Example workflow: Connect -> SHOW DATABASES -> USE db -> SELECT * FROM users.

Findings & Interpretation

Interesting

  • Application credentials stored in plaintext in a users table
  • Writable Redis instance allowing SSH key injection

False Positives

  • A database requiring auth with no known default creds is not a vulnerability by itself — don't force-crack without justification

How to Validate

  • Confirm any extracted credential works against the actual associated service, not just the DB session

Next Step

  • Crack extracted password hashes; try credentials against SSH/web login.

Troubleshooting

mysql client: 'ERROR 2003: Can't connect'.

Likely cause: Port filtered, or MySQL bound to localhost only despite nmap showing it open (nmap can show the port open on the host without the service accepting remote connections at the application layer).

Verify: Re-run nmap -sV -p3306 to confirm the service banner responded, not just the TCP handshake.

Fix: This may be a genuine dead end for direct access — look for SSRF/local-only access via a web app instead.

Recovery: Pivot: see if an app on the box can be made to query the DB on your behalf (e.g. via SQLi).

Avoid repeating: Don't assume an open port always equals remotely usable application access.