Skip to main content
Default Port: 3306 MySQL is the most common open-source database backend behind web applications, which means it shows up constantly and often holds the actual data an engagement is after. A low-privilege account gets you data; an account with FILE privilege can read and write files on the underlying server, which turns a database compromise into a full host compromise.

Standard Access

A valid login without elevated privileges. Enough to enumerate databases, tables, and whatever data the account can SELECT.

FILE Privilege

Lets the account read arbitrary files with LOAD_FILE() and write them with INTO OUTFILE, the basis for webshell drops and, combined with UDFs, full RCE.
Always try root with a blank password first. It’s still the single most common finding on exposed MySQL instances, especially on dev and staging servers.

Connecting

Running a single query without dropping into an interactive session is useful for quick checks or scripting:
mysqldump pulls an entire database (or all of them) out in one command, faster than manually exporting table by table once you’ve confirmed access:

Recon

A raw banner grab works even without the mysql client installed:

Enumeration

Once connected, these cover the standard recon pass: what version is running, what databases exist, and what the current account can actually do.
Checking privileges tells you whether file read/write and RCE paths are even worth attempting before you try them.
An empty secure_file_priv value means no restriction at all; a specific path restricts file operations to that directory; NULL disables file operations entirely.

Brute Forcing


Metasploit Modules


File Read and Write

Both of these require the FILE privilege, and are blocked outright if secure_file_priv is set to a restrictive path. Check it first (see the Accordion above) before assuming either is possible.
The file path for INTO OUTFILE resolves relative to MySQL’s own working directory, not yours, so prefixing a path with ../../ can sometimes shorten it or get around a restriction that assumes an absolute path.

UDF-Based Remote Code Execution

This requires FILE and usually INSERT/CREATE privileges, and directly executes OS commands as the MySQL service account. Treat a successful UDF load as a critical finding, it’s a direct path to full code execution on the host.
User Defined Functions let MySQL call out to a compiled shared library. If you can write that library into the plugin directory (via INTO OUTFILE or INTO DUMPFILE) and the FILE privilege allows it, you can register a function that runs arbitrary OS commands.

Hash Extraction and Cracking


Privilege Escalation and Persistence

Creating accounts or modifying existing credentials changes the target environment directly. Confirm this is explicitly in scope before going beyond read-only enumeration.
With sufficient privileges, creating a standing admin account is faster than repeatedly using a found credential, though it’s a noisy, high-impact action.

Credential Harvesting from the Host

If you’ve already got OS-level access (or RCE through a UDF), these files commonly leak MySQL credentials directly rather than needing to crack anything.

Quick Reference Tools

Hackviser: MySQL

Quick-reference pentesting guide for the MySQL service.

HackTricks: MySQL

Deeper breakdown of MySQL enumeration and exploitation techniques.
File write access, UDF loading, and account creation are all high-impact actions capable of modifying or compromising the underlying host. Confirm scope before going past read-only enumeration.