当前位置:首页 >> 网络通讯 >> 网络安全 >> 内容

TaoCms SQL注入及修复

时间:2013/4/19 12:10:00 作者:平凡之路 来源:xuhantao.com 浏览:


版本:taoCMS2.5Beta5

 

在中include/common.php中:

30  if(!function_exists('get_magic_quotes_gpc') || get_magic_quotes_gpc())

  31  {搜狗电脑知识网

  32      $_GET = Base::magic2word( $_GET );

  33      $_POST = Base::magic2word( $_POST );

  34      $_COOKIE = Base::magic2word( $_COOKIE );

  35  }

 

magic2word在include/Model/Base.php中定义:

230    static function magic2word($text){

 231          if (is_array($text)) {

 232              foreach($text as $k=>$v){

 233              $text[$k]=self::magic2word($v);

 234              }

 235          }else{

 236              $text=stripslashes($text);

 237          }

 238          return $text;

 239      }

总体就是一开始就去除魔术引号

 

然后在:

123    static function safeword($text,$level=8){

 124          if(is_array($text))

 125          {

 126              foreach( $text as $key=>$value){

 127                  $safeword[$key]=self::safeword($value);

 128              }

 129          }

 130          else

 131          {

 132              switch ($level)

 133              {

 134                  case 0:

 135                      if (get_magic_quotes_gpc()) {// 检查magic_quotes_gpc是否打开,如果没有打开,用addslashes进行转义

 136                          $safeword = stripcslashes($text);

 137                      }else{

 138                          $safeword=$text;

 139                      }

 140                      break;

 141                  case 1:

 142                      $safeword=intval($text);

 143                      break;

 144                  case 3:

 145                      $safeword=strip_tags($text);

 146                      break;

 147                  case 5:

 148                      $safeword=nl2br(htmlspecialchars($text));

 149                      break;

 150                  case 6:

 151                      $safeword=str_replace("'","",addslashes($text));

 152                      $safeword=str_replace("select","",$safeword);

 153                      $safeword=str_replace("union","",$safeword);

 154                      $safeword=str_replace("=","",$safeword);

 155                      break;

 156                  default:

 157                      if(ucfirst(DB)=='Sqlite'){

 158                          $safeword=str_replace("'","''",$text);

 159                      }

 160                      else{

相关文章
  • 没有相关文章
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 徐汉涛(www.xuhantao.com) © 2024 版权所有 All Rights Reserved.
  • 部分内容来自网络,如有侵权请联系站长尽快处理 站长QQ:965898558(广告及站内业务受理) 网站备案号:蒙ICP备15000590号-1