Skip to content
RCE Write-up Advanced

MySQL Remote Root Code Execution/Privilege Escalation Exploit

MySQL's mysqld_safe wrapper loads configuration files from locations writable by the mysql user, and logging functions can be abused to inject a malicious malloc_lib setting. An attacker with database access could preload a shared library and execute code as root when the service restarts.

legalhackers.com

Published on legalhackers.com

~~~~~~~~~~~~~ ExploitBox.io ~~~~~~~~~~~~~~~~ Interested in security / vulns / exploits ? ExploitBox.ioA Playground & Labs for security folks into hacking & the art of exploitation

The author, on legalhackers.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the mysqld_safe script trusts configuration files in locations writable by the mysql user, and MySQL's logging functions allow low-privileged users to write to those files.

Impact

An attacker could execute arbitrary code with root privileges, fully compromising the server, even with SELinux and AppArmor active.

What the attacker needed

Authenticated MySQL access or SQL injection; FILE privilege or logging access; service restart

How it was found

  1. Set the general log file to a MySQL configuration file path.
  2. Turn on the general log.
  3. Run a SELECT statement containing the malicious configuration entry.
  4. Turn off the general log.
  5. Restart the MySQL service to trigger loading of the malicious library.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

MySQL is a database program. When it starts, a helper script reads settings from files. The report shows that a logged-in database user can trick the database into writing extra settings into one of those files. Those settings tell the helper script to load a malicious library, which runs with the highest system permissions.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.