MySQL验证绕过缓冲区溢出漏洞

来源:岁月联盟 编辑:zhuzhu 时间:2004-12-29
MySQL验证绕过缓冲区溢出漏洞

发布日期: 2004年7月6日
受影响系统:
MySQL AB MySQL 5.0
MySQL AB MySQL 4.1.2
MySQL AB MySQL 4.1.1
MySQL AB MySQL 4.1.0
不受影响系统:
MySQL AB MySQL 4.1.3
描述:
--------------------------------------------------------------------------------
MySQL是一款开放源代码关系型数据库系统。

MySQL验证机制实现存在问题,远程安全者可以利用这个漏洞无需用户密码通过验证。

通过提交特殊构建的验证包,可使安全者绕过MySQL 4.1中的密码验证。

check_connection (sql_parse.cpp), 837行中:

  /*
    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'可以通过超长'scramble'字符串溢出,缓冲区被从my_rnd()函数输出的字符溢出,字符范围是0x40..0x5f,在部分平台下可能可以导致任意代码执行。

<*来源:NGSSoftware (mark@ngssoftware.com)
 
  链接:http://marc.theaimsgroup.com/?l=bugtraq&m=108904917528205&w=2
*>

建议:
--------------------------------------------------------------------------------
临时解决方法:

如果您不能立刻安装补丁或者升级,NSFOCUS建议您采取以下措施以降低威胁:

* 由于此安全需要知道用户名,因此可以更改MySQL 'ROOT'帐户的默认名,并限制连接主机。

厂商补丁:

MySQL AB
--------
MySQL AB 4.1.3已经修补此漏洞,或者5.0 Build版本也已经修正此问题:

http://www.mysql.com

图片内容