One day I received a message on Twitter. It looked something like this:
All tweets pictured were to other users. His message to me was pretty far back and I’m lazy.
Intrigued, I immediately clicked on it and got my computer rooted and my
identity stolen after taking proper precautions. What followed was a
fantastic, surreal journey into the land of unnecessarily obfuscated
Javascript.
The link sent to me lead to a free site hosted by the Russian Google equivalent
Yandex (I hope this doesn’t sound dismissive. It’s a
massive, popular multi-media search engine
that offers maps and site hosting
and makes most of its money through the
display of ads. It’s pretty Googly.).
The page contained the string “Redirecting” and some code for a view counter.
But what could it be?
Painstaking analysis of the code (use of console.log) produced this:
Which, when unescaped, yields a similar packed function to the one above. One more spin of console.log yields (ascii decoded from \x## form for your convenience):
So, pretty much exactly the same thing, but with some elements pulled out into a variable. This packing strategy is used two more times.
The plot thickens! The script checks the browser’s userAgent string, rejecting the browser if its userAgent is too short or contains strings indicating that it might be a bot or twitter app.
And then, after seven layers of obfuscation and a userAgent check, it triggers a Javascript redirect. Great.