LevelBlue Completes Acquisition of Cybereason. Learn more

LevelBlue Completes Acquisition of Cybereason. Learn more

Services
Cyber Advisory
Managed Cloud Security
Data Security
Manage Detection & Response
Email Security
Managed Network Infrastructure Security
Exposure Management
Security Operations Platforms
Incident Readiness & Response
SpiderLabs Threat Intelligence
Solutions
BY TOPIC
Offensive Security
Solutions to maximize your security ROI
Operational Technology
End-to-end OT security
Microsoft Security
Unlock the full power of Microsoft Security
Securing the IoT Landscape
Test, monitor and secure network objects
Why LevelBlue
About Us
Awards and Accolades
LevelBlue SpiderLabs
LevelBlue Security Operations Platforms
Security Colony
Partners
Microsoft
Unlock the full power of Microsoft Security
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings

Multiple Web Application Vulnerabilities in RockMongo

During a recent code review for a client, I also took a brief look at a tool they were using to manage their MongoDB platform. The tool, called RockMongo, provides similar functionality for MongoDB NoSQL databases as PHPMyAdmin does for MySQL. Fortunately this client follows recommended practices and has restricted this tool to internal access only.

We have attempted multiple times to contact the RockMongo developers to disclose these vulnerabilities to them. However, we have received no response. Our recommendation is to restrict access to this tool and not expose it to the Internet. Additionally, I will be providing mitigation recommendations in this post.

The first vulnerability identified was Reflected Cross-Site Scripting (XSS) in the main login page of the application. It was as simple as this…

http://A.B.C.D/rockmongo/index.php?action=login.index&host=0&username=%22%3E%3Cscript%3Ealert%28%27XSS%27%29%3B%3C%2Fscript%3E

11509_bca88918-dbb0-488a-aed9-0e4da8477d56

The interesting thing about this vulnerability was that they actually have a means to mitigate it in their code already. This is the function in "rock.php" that gets the parameters from the URL…

/**
* 获取参数的值
*
* 与x($name)不同的是,该函数获取的参数不会被自动过滤(通过trim和htmlspecialchars)
*
* @param string $name 参数名
* @return mixed
* @see x
*/
function xn($name = nil) {
if ($name == nil) {
return
array_merge(rock_filter_param($GLOBALS["ROCK_HTTP_VARS"], false), $GLOBALS["ROCK_USER_VARS"]);
}

if (array_key_exists($name,
$GLOBALS["ROCK_USER_VARS"])) {
return $GLOBALS["ROCK_USER_VARS"][$name];
}
if (array_key_exists($name,
$GLOBALS["ROCK_HTTP_VARS"])) {
return
rock_filter_param($GLOBALS["ROCK_HTTP_VARS"][$name], false);
}
return null;
}

When the comments are translated, we find this "theparameters of this function are not automatically get filtered (through thetrim and htmlspecialchars)". Filtering is normally provided by anotherfunction…

/**
* 过滤参数
*
* @param string $param 参数
* @param boolean $filter 是否过滤
* @return mixed
*/
function rock_filter_param($param, $filter = true) {
if (!is_array($param) && !is_object($param)) {
if (ini_get("magic_quotes_gpc")) {
$param = stripslashes($param);
}
return $filter ? htmlspecialchars(trim($param)) : $param;
}
foreach ($param as $key => $value) {
$param[$key] = rock_filter_param($value, $filter);
}
return $param;
}

As you can see in the xn()function, they are explicitly disabling the filter [rock_filter_param($GLOBALS["ROCK_HTTP_VARS"], false)]. As such, anywhere that function gets used isvulnerable. Until an official patch is available from the vendor, you mightconsider changing this second parameter to true in the calls to rock_filter_param() from the xn() function.

The second vulnerability discovered was a Local FileInclusion (LFI) and Path Traversal vulnerability. This vulnerability is alsopre-authentication. It allows an attacker to read arbitrary files on the serverand possibly execute arbitrary code.

The vulnerability lies with the use of the "ROCK_LANG"cookie. The application uses this cookie's value in the included path to alanguage file, and since the platform runs on PHP it also suffers from NULLbyte injection. The following example shows how this can be used to display theserver's "/etc/password" file.

Here is the request to the server…

GET/index.php?action=login.index&host=0 HTTP/1.1
Host: A.B.C.D
User-Agent: Mozilla/5.0
(Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/20100101 Firefox/18.0
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:en-US,en;q=0.5
Accept-Encoding: gzip,deflate
Cookie:ROCK_LANG=../../../../etc/passwd%00
Connection: keep-alive

…with the following result.

10413_87f7faa5-acc2-466e-913a-809112879f5e

There appear to be two functions that arevulnerable to this attack, rock_lang() in "rock.php" and message() in"app/lib/page/RPage.php". For example in "rock.php", the __LANG__constant gets set from rock_init_lang() function…

function rock_init_lang()
{
if (isset($_COOKIE["ROCK_LANG"])) {
define("__LANG__", $_COOKIE["ROCK_LANG"]);
...

…which is then included in the rock_lang()function.

function rock_lang($code)
{
if (!isset($GLOBALS["ROCK_LANGS"])) {
$file = __ROOT__ . "/langs/" . __LANG__ . "/message.php";
require($file);
...

Until the developer can provide a patch, you may consider validating the __LANG__ parameter in "rock.php" with a regular expression like so…

function rock_init_lang()
{
if (isset($_COOKIE["ROCK_LANG"])) {
if (preg_match('/^[a-z]{2}_[a-z]{2}$/', $_COOKIE["ROCK_LANG"]) {
define("__LANG__",$_COOKIE["ROCK_LANG"]);
}
else {
define("__LANG__", "en_en");
}
...

I would also recommend you keep checking back with the developer to see if they release a patch. The latest version of RockMongo can be downloaded here.

http://rockmongo.com/

ABOUT LEVELBLUE

LevelBlue is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo