Magecart is the name given to notorious groups of hackers that target online shopping carts, usually Magento. We provided an overview of the group's malware last year and earlier this year, we shared details of a specific Magecart malware case we encountered during the course of an investigation. In this second installment of “Digging Deep into Magecart Malware”, we highlight a couple more Magecart attacks that we encountered during investigations. In our first case, we discuss how the Magecart attackers were able to compromise an e-commerce website and install a server-side PHP script to intercept customer data from the store’s checkout page. And in the second case, we take a closer look at a domain used to exfiltrate data by the attacker that we believe was a compromised server.
Most of the time, Magecart attacks we have encountered are malicious client-side JavaScripts that are inserted into a compromised e-commerce website. Commonly, these “card skimming” JavaScripts are heavily obfuscated and hosted at a third-party web server which may either be compromised or hosted by the attackers themselves. However, there are few attack types we encounter that use server-side PHP scripts to intercept sensitive data. Take for example this PHP script:
This script was found in a seemingly innocent path in an undisclosed e-commerce web server.
The PHP script was planted by the attacker to intercept information, including credit card details and billing information entered by their customer in the checkout page. The information collected is as follows:
Each of the items are delimited with a vertical bar character “|” then encoded with simple Base64 encoding. This encoded data is then saved to a fake image file of which the path was set to ‘/media/wysiwyg/<compromised website domain>5944.jpg’
How did the attackers exfiltrate this data? Well, they planted a web shell to access the files, specifically WSO version 4.2.5. WSO is a full-featured PHP web shell that is used by attackers to maintain persistent access to a compromised web server.
So how did the e-commerce website got compromised, you may ask? – the attacker exploited a vulnerability in a Magento utility installed in the webserver called Magento Mass Importer (Magmi). The attack exploited a local file inclusion (LFI) vulnerability in a PHP script component that allowed the attacker to retrieve the credentials for the e-commerce website’s Amazon Relational Database Service (AWS RDS) instance. It also allowed the attacker to execute a Wget command to download a web shell into the webserver that enables the upload additional malicious PHP scripts.
On a side note, this was not the first vulnerability in Magmi that was discovered, we also reported back in October 2015 of another vulnerable component “download_file.php” which was also vulnerable with LFI.
Moving on, the technique of dumping stolen data to a local drive and then exfiltrating it later on, is nothing new. In 2016, it was reported that over 6000 online stores were infected with the Visbot malware that uses a similar technique. Visbot, however, uses stronger asymmetric encryption to encrypt stolen data and the fake image file, where the dumped data is saved in one of the compromised web server’s publicly accessible folders. In our case, the attacker had complete access to the webserver by planting a web shell and they also opted to use a simpler Base64 algorithm for encoding the stolen data.
Another case we encountered was a Magecart infection in a couple of online stores based in Australia. These two e-commerce websites were hit with malicious “card-skimming” JavaScripts. Both incidents involved JavaScripts injected into the websites that were externally hosted at the same domain: darvishkhan[.]net
With the usual Magecart tactic, the JavaScript skims customer information and credit card details from the checkout page and the stolen information is then encoded twice with Base64. The data is then exfiltrated through an HTTP POST tunnel to the attacker’s domain.
We took a closer look at this exfil domain darvishkhan[.]net and found another infected e-commerce website based in Mexico.
The darvishkhan[.]net domain was also mentioned in a blog from a Korean security firm ESTSecurity. The domain once hosted a malicious file which ESTSecurity linked to Lazarus APT group.
However, this exfil domain seems to be a compromised website based in Iran which sells musical instruments.
Using a compromised webserver help attackers hide and make them more difficult to track. It also helps that they used legitimate looking names in their JavaScripts such as “google.tag.min.js” or “gtm.min.js”. As this server is also an e-commerce website, it is also possible that customer information in this website may have also been compromised. On that note, we have notified darvishkhan.net regarding this issue but haven't heard from them yet.
File |
SHA256 |
Skimmer PHP |
31AC68194FA993214E18AA2483B7187AAD0CB482667EC14A7E9A0A37F8ED7534 |
Skimmer PHP |
8B30223133EFAA61DDABF629E3FD1753B51DDB1E5E3459F82A72BA31F78BD490 |
WSO Webshell |
06305ACBF12150DCC8DAE68E1F7A326558661F1EDC9F49149D38C7450DC37654 |
Thanks to Alejandro Baca and Damian Lazarus for providing us additional information