### 简要描述:
PHPYUN最新版(phpyun_v3.1.0604_gbk)多处SQL注入及越权操作
虽然PHPYUN在注入防御上已经做得很不错了,方的很严格,像吃掉引号,宽字节的基本上很少了,但是不需要跟引号斗争的地方还有很多,得好好检查,好好修复了!!!
这里再来三处SQL注入及越权操作!!!
### 详细说明:
文件/member/model/com.class.php
第一处SQL注入、越权修改企业环境展示信息:
```
function saveshow_action(){
		if($_POST['submitbtn']){
			$pid=@implode(',',$_POST['id']);
			$company_show=$this->obj->DB_select_all("company_show","`id` in (".$pid.") and `uid`='".$this->uid."'","`id`");
			if($company_show&&is_array($company_show)){
				foreach($company_show as $val){
					$title=$_POST['title_'.$val['id']];
					$this->obj->update_once("company_show",array("title"=>trim($title)),array("id"=>(int)$val['id']));
				}
				$this->obj->ACT_layer_msg("修改成功!",9,"index.php?c=show");
			}else{
				$this->obj->ACT_layer_msg("非法操作!",3,"index.php");
			}
		}else{
			$this->obj->ACT_msg("index.php","非法操作!");
		}
	}
```
这里的$pid=@implode(',',$_POST['id']);
没有经过引号保护,直接进入DB_select_all,在DB_select_all中也未进行处理:
```
function DB_select_all($tablename, $where = 1, $select = "*") {
		$cachename=$tablename.$where;
		if(!$row_return=$this->Memcache_set($cachename)){
			$row_return=array();
			$SQL = "SELECT $select FROM `" . $this->def . $tablename . "` WHERE $where";
			$query=$this->db->query($SQL);
			 while($row=$this->db->fetch_array($query)){$row_return[]=$row;}
		 	$this->Memcache_set($cachename,$row_return);
		}
		 return $row_return;
	}
```
导致存在SQL注入。
第二处SQL注入、越权删除企业新闻
```
function news_action(){
		$this->public_action();
		$where='';
		if($_POST['delid'] || $_GET['delid'])
		{
	    	if($_POST['delid'] || $_GET['delid'])
	    	{
	    		if(is_array($_POST['delid']))
	    		{
	    			$delid=@implode(",",$_POST['delid']);
					$layer_type='1';
		    	}else{
		    		$delid=$_GET['delid'];
					$layer_type='0';
		    	}
				$oid=$this->obj->DB_delete_all("company_news","`id` in (".$delid.") and `uid`='".$this->uid."'","");
				$oid?$this->layer_msg('删除成功!',9,$layer_type):$this->layer_msg('删除失败!',8,$layer_type);
	    	}else{
 	    		$this->obj->ACT_layer_msg("请选择您要删除的新闻!",8,$_SERVER['HTTP_REFERER']);
	    	}
	    }
```
这里的$delid=$_GET['delid'];
没有经过引号保护,直接进入了DB_delete_all中
```
function DB_delete_all($tablename, $where, $limit = 'limit 1'){
	 	$SQL = "DELETE FROM `" . $this->def . $tablename . "` WHERE $where $limit";
		$this->db->query("set `sql_mode`=''");
		return $this->db->query($SQL);
	}
```
导致SQL注入。
又由于,通过截断,修改后面的uid,就可以导致越权操作,删除任意企业用户的企业新闻。
第三处SQL注入、越权删除任意企业用户产品
```
function product_action()
	{
		$this->public_action();
		$delid=$_GET['delid'];
		if($delid){
			if(is_array($delid)){
				$ids=implode(',',$delid);
				$layer_type=1;
			}else{
				$ids=$delid;
				$layer_type=0;
			}
			$row=$this->obj->DB_select_all("company_product","`id` in (".$ids.") and `uid`='".$this->uid."'","`pic`");
			if(is_array($row)){
				foreach($row as $k=>$v){
					$this->obj->unlink_pic("..".$v['pic']);
				}
			}
			$oid=$this->obj->DB_delete_all("company_product","`id` in (".$ids.") and `uid`='".$this->uid."'","");
			$oid?$this->layer_msg('删除成功!',9,$layer_type,$_SERVER['HTTP_REFERER']):$this->layer_msg('删除失败!',8,$layer_type,$_SERVER['HTTP_REFERER']);
		}
```
这里的$delid=$_GET['delid'];$ids=$delid;
$ids没有经过引号保护,直接进入SQL语句,导致SQL注入
由于通过截断,修改后面的uid,就可以导致越权操作,删除任意企业用户的企业产品。 
### 漏洞证明:
拿第一处SQL注入、越权修改企业环境展示信息为例:
从代码可以看出,当查询失败时,会返回“非法操作!”:
[<img src="https://images.seebug.org/upload/201406/101605075de1056708c72fa872b1f1edd1c23748.png" alt="1.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201406/101605075de1056708c72fa872b1f1edd1c23748.png)
当查询正常时,会返回“修改成功!”:
[<img src="https://images.seebug.org/upload/201406/1016052228da846c65a8e57bd76edf1aaa7c1525.png" alt="2.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201406/1016052228da846c65a8e57bd76edf1aaa7c1525.png)
[<img src="https://images.seebug.org/upload/201406/10160555aebe788a796d6b47919ed7e9d8d23c4b.png" alt="4.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201406/10160555aebe788a796d6b47919ed7e9d8d23c4b.png)
这里可以看出user()的第一个字符就是r
依次遍历char的值,得到user()=root
其他几处SQL注入漏洞证明验证过程方法见漏洞:
 [WooYun: PHPYUN最新版多处SQL注入及越权操作](http://www.wooyun.org/bugs/wooyun-2014-064323)  
                      
                       
                    
                  
                
              
             
        
          
暂无评论