Trustwave SpiderLabs Uncovers Unique Cybersecurity Risks in Today's Tech Landscape. Learn More

Trustwave SpiderLabs Uncovers Unique Cybersecurity Risks in Today's Tech Landscape. Learn More

Services
Capture
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

twi-managed-portal-color
Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

twi-briefcase-color-svg
Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

tw-laptop-data
Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

tw-officer
Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

tw-network
Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

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/

Latest SpiderLabs Blogs

Zero Trust Essentials

This is Part 5 in my ongoing project to cover 30 cybersecurity topics in 30 weekly blog posts. The full series can be found here.

Read More

Why We Should Probably Stop Visually Verifying Checksums

Hello there! Thanks for stopping by. Let me get straight into it and start things off with what a checksum is to be inclusive of all audiences here, from Wikipedia [1]:

Read More

Agent Tesla's New Ride: The Rise of a Novel Loader

Malware loaders, critical for deploying malware, enable threat actors to deliver and execute malicious payloads, facilitating criminal activities like data theft and ransomware. Utilizing advanced...

Read More