dtyz76562 2016-10-19 00:41
浏览 51

我的PHP代码是安全的吗? php to pdo over eval function

i'm writing a php web script with mvc, but i'm concerned about code is safe.

i fear most "eval($str)", but i try a lot of php function string but nothing happened.

$a = func_get_args();
  if((func_num_args()-1)%2 == 0){
    $str = "";
    array_shift($a);
    for($i = 0;$i<sizeof($a);$i++){
      if($i%2==0){
        if(!is_numeric($a[$i])){
          if($a[$i] == 'filter'){
            $filter=1;
          }
          $str.= "$".stripslashes($a[$i])." = ";
        }else{
          $str.= 'page';
        }
      }else{
        if($filter != 1){
          if(is_numeric($a[$i])){
            $str.= stripslashes($a[$i]).";";
          }else{
            $str.=1;
          }
        }else{
          $arr = explode("-",$a[$i]);
          $dizz = 'array(';
          for($j=0;$j<sizeof($arr);$j++){
            if(($j%2)==0){
            $dizz .= '\''.stripslashes($arr[$j]).'\'=>';
            }else{
            $dizz .= '\''.stripslashes($arr[$j]).'\',';
            }
          }
          $dizz = rtrim($dizz,',');
          $dizz .= ');';
          $str.= $dizz;
        }
      }
    }
    eval($str);
  }

  $filter = isset($filter) ? $filter : false;
  $page= isset($page) ? $page: '';
  $count= isset($count) ? $count: '';
  if($count == ''){
    switch ($process) {
      case 'table':
      $count = 40;
      break;
      case 'detailed':
      $count = 3;
      break;
      case 'mobile':
      $count = 12;
      break;
      default:
      $count = '';
      break;
    }
  }
  if($count != ''){
    if(is_numeric($count )){
      if($count <=200 && $count >0){
        $count = $count ;
      }else{
        $count = 40;
      }
    }else{
      $count = 1;
    }
  }
  if(!is_numeric($page)){
    $page= 1;
  }

to sql query->

$new_filter = "Where ";
  if($filter){
    foreach ($filteras $key => $value) {
      $new_filter .= 'k.'.$key.'='.$value.' and ';
    }
    $new_filter = rtrim($new_filter,' and ');
    $filter= $new_filter;
  }else{
    $filter= '';
  }
  $limit = ($limit) ? 'LIMIT 30' : '';
  if($id == ''){
    $where = $filter;
  }else{
    $where = $id;
  }

  $query = 'select * from kullanici as k join kisiler as ki on k.id = ki.kullanici_id join iletisim as i on k.id = i.kullanici_id '.$where.' '.$siralama.' '.$limit;
  $query = $this->_db->prepare($query);
  $query->execute();

example url:

profile/show/mobile/page/4/count/5/filter/echo-"'xzcxza'"-sadas-asdxc

this results:

$page = 4;$count= 5;$filter= array('echo'=>'%22%27xzcxza%27%22','sadas'=>'asdxc');

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
    • ¥100 求采集电商背景音乐的方法
    • ¥15 数学建模竞赛求指导帮助