字体大小: 正文
双剑合并(2008-06-02 17:50:43)

今天看一个php程序,发现有些地方很搞

FengGou@Exploit ~/LAMP/www/htdocs/Bo-blog/bo-blog/admin
$ grep -in "safe_convert" *.*
cp_category.php:260:    $newcatename=addslashes(safe_convert(stripslashes($newcatename)));
cp_category.php:262:    $newcateurlname=safe_convert(stripslashes($newcateurlname));
cp_category.php:274:    $newcatedesc=addslashes(safe_convert(stripslashes($newcatedesc), 1));

...

源码:

$newcatedesc=addslashes(safe_convert(stripslashes($newcatedesc), 1));
 $newcatedesc=str_replace('<|>', '<|>', $newcatedesc);
 
 if ($job=='new') {
  $new_cate_id=$maxrecord['maxcateid']+1;
  $targetcate=floor($targetcate);
...
   if (trim($tmpresult['cateorder'])!='') {
    $insertcateorder=$tmpresult['cateorder'];
    $result=$blog->query("UPDATE `{$db_prefix}categories` SET `cateorder`=`cateorder`+1 WHERE `cateorder`>={$insertcateorder}");
   }
  } else $insertcateorder=$new_cate_id;
  $result=$blog->query("INSERT INTO `{$db_prefix}categories` VALUES ('{$new_cate_id}', '{$newcatename}', '{$newcatedesc}', '{$newcateproperty}', '{$insertcateorder}', '{$newcatemode}', '{$newcateicon}', '{$newcateurl}', '{$newcateurlname}', '', '')");
  $result=$blog->query("UPDATE `{$db_prefix}maxrec` SET `maxcateid`='{$new_cate_id}'");

 

safe_convert是这样定义的

function safe_convert($string, $html=0, $filterslash=0) { //Words Filter
 if ($html==0) {
  $string=htmlspecialchars($string, ENT_QUOTES);
  $string=str_replace("<","<",$string);
  $string=str_replace(">",">",$string);
  if ($filterslash==1) $string=str_replace("\\", '\', $string);
 } else {
  $string=addslashes($string);
  if ($filterslash==1) $string=str_replace("
\\\\", '\', $string);
 }
 $string=str_replace("\r","
",$string);
 $string=str_replace("\n","",$string);
 $string=str_replace("\t","  ",$string);
 $string=str_replace("  ","  ",$string);
 $string=str_replace('|', '|', $string);
 $string=str_replace("`","`",$string);
 $string=str_replace("\","\",$string);
 $string=str_replace("[","[",$string);
 $string=str_replace("]","]",$string);
 return $string;
}

开始疑惑为什么要二次addslashes转义,后来恍然大悟这个是针对GBK双字节字符绕过addslashes一种聪明的处理方法0xbb27变成0xbb5c27,绕过了addslashes但是紧接着又一次,可怜的0x27又变成了0x5c27最终变成0xbb5c5c27

想玩玩搭积木游戏,发现并没有想象中的简单,因为0x27前永远会有一个0x5c,天杀的反斜杠。但是addslashessafe_convert函数的二次打击并不是无懈可击,首先在看下定义,有个if,为了分明xss转义与sqlinj攻击,但是,他把过程用了一个条件给分开了

 if ($html==0) {
  $string=htmlspecialchars($string, ENT_QUOTES);
  $string=str_replace("<","<",$string);
  $string=str_replace(">",">",$string);
  if ($filterslash==1) $string=str_replace("\\", '\', $string);
 } else {
  $string=addslashes($string);

不敢直接断言找到了漏洞,但是起码这是一种可以绕过的方面,利用程序本身,或许,还有更棒的:)

加载中,请稍候...
  • 评论加载中,请稍候...

验证码:请点击后输入验证码  收听验证码

发评论

以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

相关博文
读取中...
推荐博文
读取中...