
CVE-2012-2122 - MySQL Authentication Bypass
Proof of Concept (PoC) for CVE-2012-2122, a critical authentication bypass vulnerability affecting vulnerable MySQL and MariaDB servers.
Disclaimer
This project is intended for educational purposes, security research, and authorized penetration testing only. Do not use this software against systems you do not own or have explicit permission to test.
CVE-2012-2122 is an authentication bypass vulnerability discovered in MySQL's password verification logic.
Due to an integer casting/comparison bug, authentication can incorrectly succeed when an invalid password comparison evaluates as equal under certain conditions.
Rather than requiring knowledge of a valid password, an attacker can repeatedly attempt authentication using arbitrary passwords until the comparison bug is triggered.
The probability of success is approximately:
Because of this relatively high probability, automated tools can usually bypass authentication within a few hundred login attempts.
| Metric | Value |
|---|---|
| CVE | CVE-2012-2122 |
| CVSS v2 | 7.5 (High) |
| Attack Vector | Network |
| Authentication | None |
| User Interaction | None |
| Impact | Authentication Bypass |
The vulnerability affects MySQL builds compiled with vulnerable compiler optimizations, including versions such as:
The issue primarily affected Linux distributions whose compiler behavior exposed the bug.
Not every installation of these versions is vulnerable.
During password verification, MySQL internally compares two hash values using the memcmp() function.
Under normal circumstances:
memcmp(hash1, hash2)
returns:
0 when equalThe vulnerability arose because the return value was stored in a signed integer and later converted in a way that allowed certain non-zero values to be interpreted as authentication success.
Simplified logic:
if (memcmp(hash1, hash2) == 0)
{
// Login successful
}
Under vulnerable compiler behavior, specific return values from memcmp() could incorrectly satisfy the comparison.
As a result, incorrect passwords occasionally authenticated successfully.
An attacker only needs:
No password knowledge is required.
The attacker continuously submits login attempts using random passwords.
Eventually, one authentication succeeds because of the comparison bug.
Typical attack flow:
Attempt #1
↓
Authentication Failed
Attempt #57
↓
Authentication Failed
Attempt #141
↓
Authentication Failed
Attempt #237
↓
Authentication Successful
Average success occurs roughly once every 256 attempts.
Successful exploitation allows an attacker to:
If administrative credentials are targeted, complete control of the database server may be obtained.
Indicators include:
Review MySQL authentication logs for excessive failed login activity.
The recommended mitigation is to upgrade to a patched release.
Additional defensive measures include:
---
## Example Usage
```bash
python3 exploit.py -ip <target>
Example:
python3 exploit.py -ip 192.168.1.100
This repository demonstrates how a subtle implementation bug in authentication logic can completely undermine password verification.
Although the vulnerability is over a decade old, it remains an important case study in: