Zero-day in Magmi database client for popular e-commerce platform Magento targeted in the wild

We've observed HTTP requests associated with an exploit attempt on the Magento e-commerce platform. The flaw is not within Magento itself but introduced by installing and failing to change the default security configuration of a vulnerable version of an open-source utility for the platform – Magmi. Magmi is a "Magento Mass Importer developed as a Magento DATABASE client." Evidence of the malicious activity was discovered in Trustwave SpiderLabs honeypots. The Trustwave Web Application Firewall (WAF) detected the HTTP requests, and the requests suggest that malicious actors are attempting to exploit this directory traversal vulnerability in the wild. Successful exploitation results in access to Magento site credentials and the encryption key for the database.

Magento's website claims that more than 240,000 merchants use their e-commerce software, but it's difficult to determine how many instances of the platform include the vulnerable Magmi installation. Magmi is available for download from either SourceForge or GitHub. Only versions downloaded from SourceForge are vulnerable. Magmi was downloaded from SourceForge more than 2,800 times in September alone.

After we disclosed the vulnerability to the owner of Magmi (dweeves) and to Magento, Magento responded to us acknowledging the issue and stating that they issued a security notification to their partners and users that opt to receive such notifications. Magento also reported that they assessed all known Magento sites and contacted the owners of 1,700 sites they believe to be vulnerable.

Magento offers two versions of the software: Community Edition and Enterprise Edition (hosted by Magento). Security firm Checkpoint published extensive research on the security of Magento earlier this year, and in-the-wild attacks on the reported vulnerabilities were observed soon after disclosure (Sucuri blog - Impact of Hacks to Magento and Security Week 24 Apr 2015).

Beginning last month, Trustwave SpiderLabs researchers discovered requests such as the following:

GET /…sanitized.../magmi-importer/web/download_file.php?file=../../app/etc/local.xml HTTP/1.1

Trustwave WAF categorized these requests as directory traversal attacks because of the presence of '../..' in the request. This is an attempt to access the Linux password file by backtracking the path.

The Vulnerability

Magmi-importer is commonly used in the path of Magmi installations. Magmi allows users to import content directly into the Magento database. Again, the vulnerable version of Magmi is available on SourceForge.

As described in Magmi Wiki installation Guide, most users will install Magmi in the same directory as Magento. Therefore the path"../../app/etc/local.xml" will point at the local.xml file used by Magento. Magento uses app/etc/local.xml to store the database credentials and encryption key. Securing access to this file is an elementary step in securing Magento as described in their security guide: Magento Security: Check your app/etc/local.xml file. Moreover, Magento Enterprise Edition periodically checks whether this file is externally visible and throws an alert if it is.

The Magmi repository in GitHub is maintained by "dweeves" - Sebastian Beacuemont. The code is also available via SourceForge. While the two repositories are said to remain in sync, that doesn't appear to be the case.

The latest Magmi version 0.7.21 from SourceForge included the following download.php file:

Img1

In lines four and five, you can see that the program opens the file stated in the request parameter without performing any checks required to avoid directory traversal—herein lies the vulnerability. The latest Magmi repository on GitHub does not contain the download_file.php. Therefore, only downloads from SourceForge are vulnerable to this attack. The GitHub repository is up to date with file changes over the last month, while the last change to the SourceForge version occurred at the end of 2014.

What's disturbing is the inconsistency between the two repositories and the popularity of the out-dated, SourceForge repository. The graphic below illustrates more than 500 downloads of Magmi on SourceForge during the first week of October. The prevalence of the outdated version might be because a search for "magmi" at Google.com returns the vulnerable, SourceForge version as the first result with a rating of 4.5 out of 5.

Img2

Img3

Exploitability

The vulnerability can only be exploited if the Magmi installation including the "\web" location is not secured. It's best to protect Magmi wherever it resides using HTTP basic authentication or other methods (see how-to-secure-magmi).

If you installed Magmi without securing it, you're already vulnerable because credentials can be found in the Magmi UI admin pages. However, the directory traversal vulnerability in download_file.php makes the attack much easier to perform using a single GET request.

The site protected by Trustwave WAF that detected the malicious HTTP requests was not hosting Magento, suggesting that the attack was random and not targeted. However, identifying sites that host Magento is easy based on X-Magento and X-Varnish headers. A search in the Shodan search engine will reveal several Magento sites.

Summary

Above we've illustrated how a severe security flaw can be introduced into a Magento based e-commerce system by installing a commonly used, vulnerable version of the open-source Magmi utility and failing to change the default security configuration. Our discovery of probe HTTP requests in Trustwave SpiderLabs honeypots, suggest that bad actors are aware of the vulnerability and how to exploit it.

WAFs provide an essential layer of protection against such attacks for e-commerce and other web sites. Trustwave WAF and ModSecurity use generic rules and learning capabilities to successfully detect and block such attempts out-of-the-box.

Trustwave reserves the right to review all comments in the discussion below. Please note that for security and other reasons, we may not approve comments containing links.