Sign Up for Your FREE Weekly SecurityTracker E-mail Alert Summary
Put SecurityTracker Vulnerability Alerts on Your Web Site -- It's Free!
Become a Partner and License Our Database or Notification Service
MySQL check_scramble_323() Zero-Length Comparison Lets Remote Users Bypass Authentication
SecurityTracker Alert ID: 1010645|
SecurityTracker URL: http://securitytracker.com/id/1010645
(Links to External Site)
Updated: Jul 8 2004|
Original Entry Date: Jul 5 2004
Execution of arbitrary code via network, User access via network|
Fix Available: Yes Vendor Confirmed: Yes |
Version(s): 4.1 prior to version 4.1.3; also version 5.0|
A buffer overflow and authentication bypass vulnerability was reported in MySQL. A remote user can authenticate to the database server without a password. A remote user may be able to execute arbitrary code in some cases.|
Chris Anley of NGSSoftware reported that a remote user can submit a specially crafted authentication packet to bypass the password authentication mechanims on MySQL. The flaw reportedly resides in the check_scramble_323() function [CVE: CAN-2004-0627].
A remote user can specify an arbitrary 'passwd_len' value to cause the function to compare a known 'scrambled' password value with a zero-length string. The function reportedly allows a remote user to authenticate successfully with a zero-length string.
It is also reported that there is a stack-based buffer overflow that can be triggered by a long 'scramble' string generated by my_rnd() [CVE: CAN-2004-0628]. On some platforms, arbitrary code execution is possible, according to the report.
The vendor was reportedly notified on June 1, 2004.
A paper describing MySQL protection techniques is available at:
A remote user can authenticate to the target database.|
A remote user may be able to execute arbitrary code on the target system.
The vendor has released a fix in version 4.1.3 and in the most recent builds of version 5.0.|
Vendor URL: www.mysql.com/ (Links to External Site)
Authentication error, Boundary error|
Linux (Any), UNIX (Any)|
Source Message Contents
Date: Mon, 5 Jul 2004 13:21:41 +0100 (GMT Daylight Time)|
Subject: MySQL Authentication Bypass
NGSSoftware Insight Security Research Advisory
Name: MySQL Authentication Bypass / Buffer Overflow
Systems Affected: MySQL 4.1 prior to 4.1.3, and MySQL 5.0.
Vendor URL: http://www.mysql.com
Author: Chris Anley [ email@example.com ]
Date of Advisory: 1st July 2004
We have written a paper that accompanies this advisory. The paper
provides details of various MySQL lockdown techniques, and a review of
common attacks on MySQL, including SQL injection. The paper can be found
"The MySQL database server is the world's most popular open source
This advisory details a bug that allows a remote user to entirely bypass
the MySQL password authentication mechanism, allowing them to authenticate
as a MySQL user without knowing that user's password. Using a similar
method, a stack buffer used in the authentication mechanism can be
overflowed, though exploitation of the overflow is not straightforward.
MySQL 4.1 Authentication Bypass
By submitting a carefully crafted authentication packet, it is possible
for an attacker to bypass password authentication in MySQL 4.1.
>From check_connection (sql_parse.cpp), line ~837:
Old clients send null-terminated string as password; new clients send
the size (1 byte) + string (not null-terminated). Hence in case of
password both send '\0'.
uint passwd_len= thd->client_capabilities & CLIENT_SECURE_CONNECTION ?
*passwd++ : strlen(passwd);
Provided 0x8000 is specified in the client capabilities flags, the use can
specify the passwd_len field of their choice. For this attack, we will
choose 0x14 (20) which is the expected SHA1 hash length.
Several checks are now carried out to ensure that the user is
authenticating from a host that is permitted to connect. Provided these
checks are passed, we reach:
/* check password: it should be empty or valid */
if (passwd_len == acl_user_tmp->salt_len)
if (acl_user_tmp->salt_len == 0 ||
acl_user_tmp->salt_len == SCRAMBLE_LENGTH &&
check_scramble(passwd, thd->scramble, acl_user_tmp->salt) == 0 ||
(ulong *) acl_user_tmp->salt) == 0)
the check_scramble function fails, but within the check_scramble_323
function we see:
check_scramble_323(const char *scrambled, const char *message,
struct rand_struct rand_st;
char buff,*to,extra; /* Big enough for check */
const char *pos;
hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
randominit(&rand_st,hash_pass ^ hash_message,
hash_pass ^ hash_message);
for (pos=scrambled ; *pos ; pos++)
if (*scrambled++ != (char) (*to++ ^ extra))
return 1; /* Wrong password */
At this point, the user has specified a 'scrambled' string that is as long
as they wish. In the case of the straightforward authentication bypass,
this is a zero-length string. The final loop compares each character in
the 'scrambled' string against the string that mysql knows is the correct
response, until there are no more characters in 'scrambled'. Since there
are no characters *at all* in 'scrambled', the function returns '0'
immediately, allowing the user to authenticate with a zero-length string.
This bug is relatively easy to exploit, although it is necessary to write
a custom MySQL client in order to do so.
In addition to the zero-length string authentication bypass, the
stack-based buffer 'buff' can be overflowed by a long 'scramble' string.
The buffer is overflowed with characters output from my_rnd(), a pseudo
random number generator. The characters are in the range 0x40..0x5f. On
some platforms, arbitrary code execution is possible, though the exploit
is complex and requires either brute force, or knowledge of at least one
Fix Information and workarounds
MySQL AB were contacted on the 1st of June 2004 and the patch for this bug
was present in the source code by the 2nd of June. Since MySQL prefer
users to install via pre-built binary packages, NGS have delayed the
release of this advisory until appropriate 'patch' packages were
MySQL AB have fixed this bug in version 4.1.3, and the most recent builds
of version 5.0.
In addition to patching, various workarounds are possible for this bug.
The attacker must know or be able to guess the name of a user in order
for this attack to work, so renaming the default MySQL 'root' account is
a reasonable precaution. Also, the account in question must be accessible
from the attacker's host, so applying ip-address based login restrictions
will also mitigate this bug.
A check for this vulnerability has been added to Typhon III, NGSSoftware's
advanced vulnerability assessment scanner. For more information please
visit the NGSSoftware website at http://www.ngssoftware.com/
NGSSoftware design, research and develop intelligent, advanced application
security assessment scanners. Based in the United Kingdom, NGSSoftware
have offices in the South of London and the East Coast of Scotland.
NGSSoftware's sister company NGSConsulting, offers best of breed security
consulting services, specializing in application, host and network
Telephone +44 208 401 0070
Fax +44 208 401 0076
Go to the Top of This SecurityTracker Archive Page