首页 -> 安全研究

安全研究

安全漏洞
MySQL空口令HASH绕过认证及缓冲区溢出漏洞

发布日期:2004-07-05
更新日期:2004-07-06

受影响系统:
MySQL AB MySQL 5.0
MySQL AB MySQL 4.1.2
MySQL AB MySQL 4.1.1
不受影响系统:
MySQL AB MySQL 4.1.3
描述:
BUGTRAQ  ID: 10654
CVE(CAN) ID: CVE-2004-0627,CVE-2004-0628

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,在部分平台下可能可以导致任意代码执行。

<*来源: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

浏览次数:5803
严重程度:3(网友投票)
本安全漏洞由绿盟科技翻译整理,版权所有,未经许可,不得转载
绿盟科技给您安全的保障