Magento websites are under attack from a new credit card harvesting technique designed to evade detection while harvesting payment card data from major payment processor iframes - a new malware called Magento Cloud Harvester.
The Forensic Team at Foregenix are regularly finding new techniques that attackers are adopting in attempts to remain undetected by victim websites – and it seems they have added a new tactic to attack Shoplift-affected eCommerce websites. Not only are they changing the way that traditional cardholder data harvesting methods are executed – the malicious payload is now retrieved from an external resource.
The basics of the standard client-side attack are pretty straight forward and follow this process:
However, this new JavaScript attack is slightly altered - because it creates a pseudo payment card data form (like below) and therefore steals all of the cardholder’s data.
In order for Cloud Harvester to work, the attacker needs to know which payment processing service the targeted organisation is using. While this particluar website uses a well known UK payment gateway for payment processing, this code could work for “all” eCommerce payment services and is certainly no reflection on the security of the actual payment processor. This attack is only possible by exploiting vulnerabilities in an insecure website.
If the attacker has access to the backend administration panel, they can easily view which modules are implemented and are able to adjust the code below as appropriate. Similarly with one of the myriad of web shells that we frequently see deployed to compromised sites, reviewing the site’s source code in this manner will produce the same results.
Once injected, the Cloud Harvester malicious code sits within the database that runs behind Magento; so, when a page is generated certain aspects of the database are ‘pulled’, including the header and the footer. In this instance the header is where the script is stored and then executed upon serving the web page to the customer. Once the script has been executed, it creates and renders its own payment form. The above screen shot provides an example of the code generating the fake payment form.
Within the script itself there is a call to an external URL where it will pull down the remainder of the malicious content which allows the attacker to harvest the data that has been entered into the pseudo payment form by the customer.
The code above is an extract from the payload called from the external URL. This code opens a connection to the attacker's drop site using the XMLHttpRequest() method . Then the entire contents of the POST request from the victim’s website/pseudo payment form, are presented to what can only be assumed is a system within the control of the attacker.
The previous malicious JavaScript that we identified took a different approach to steal payment card data. The script would run through all the input fields on the form and search for a card number by using a regular expression for 14-16 numerical digits. This time due to the malicious script generating the pseudo payment form itself, there is no requirement for the regular expression or indeed the search itself.
The most common way this malicious JavaScript is uploaded into the database is through the Magento administration panel. By gaining access to the administration panel the attacker is then able to go to System → Configure → Design and then place their script into the HTML head section within the miscellaneous scripts section, then save. The Shoplift vulnerability can also be exploited in order to either inject the code straight into the database itself or can be used to create a new Administrative user in the database which will allow the attacker to log in and do as they please.
Upon saving the changes within the Magento administration panel, the malware is then stored into the database itself. This makes it harder to detect - there are no file changes to help identify what has changed or is different, and it is also not stored on the web server itself, which makes any internal scanning oblivious to its existence.
In order to identify the above malicious script within your Magento ecommerce environment please see a list of recommendations below: