Home→Blog→Incidents→June 09 2011→Dangerous whitespaces
A few days ago, I blogged about a PHP/JS malware targeting the osCommerce platform, which used an interesting new technique to obfuscate the malicious code. It so happens, that today I came across even more advanced sample of a PHP infector, also in the context of a vulnerable e-commerce solution.
When I came to work today, my colleague from our Polish office asked me to help him with finding malware which was affecting his friend's online store. The HTML page, viewed with the browser, contained a link to a jquery.js script in some randomly generated cx.cc domain, although there was no sign of this link in the source files on the server. Reaching a verdict was simple - this piece of code was being added dynamically, by some infected PHP script.
We looked into all of PHP files stored on the server and got a bit confused - there was nothing really suspicious at first glance. But having in mind the div_colors malware, I started to study the code line by line. What at last attracted my attention was a small function at the beginning of one of the core PHP files.
This code owes its innocent look to the several layers of obfuscation. The first (and very tricky one) is that the function pretends to be commented out. If we look more closely, we will see that comment tags are situated in the wrong way, starting the comment at the end of each line and closing it at the beginning of another. It's easier to catch that with the use of syntax highlighting. The second misleading thing is the function description, along with the names in the code, which suggest the function should deal with some libraries.
And now the most interesting stuff: how does this function really work? Could you determine that at first sight? The key here is to understand what we have between the brackets of the $session_key variable; and "nothing" is the wrong answer ;) It may seem not so obvious, but there's a bit more than a bunch of spaces too: it's a mix of spaces and tabulators. We can see that clearly, when the non-printable characters are shown in an editor.
The function splits this whitespace mix into 8-digit pieces, and then it changes all TAB chars into "1" and all spaces into "0". In this way it gets the binary code, which is later transformed into decimal value and printed as ASCII character... Pretty inventive, Mr. malware writer!
Execution of PHP file containing this CoreLibrariesHandler() function results in a malicious link appended to the end of HTML files:
The script is redirected to another script, which redirected to another... and so on, but the final destination seems to be already offline. The interesting thing is that the final URL is quite the same as in case of div_colors malware, which led us to the conclusion, that both div_colors and CoreLibraries malware have the same origin.
The signature for this PHP script was added to our bases as Trojan.PHP.Injecter.c.
|
2011 Jun 09, 14:31
This technique was the subject of a talk at Defcon 16 To be fair the malware author was not really inventive since this technique was presented at Defcon 16 :) The talk was named "WhiteSpace: A Different Approach to JavaScript Obfuscation" by Kolisar. It's the first time however I hear of attacks using it, good catch. |
|
1 |
Re: This technique was the subject of a talk at Defcon 16
I wasn't aware of that. Old stuff then. ;)
Thank you for pointing me to this presentation!
|
2011 Jun 09, 19:07
|
|
2011 Jun 10, 06:54
Kind of Steganography The idea is even older than the DefCon talk. It's about steganography. The steganography program "Snow" is able to hide a message in whitespaces and Tabulations. |
|
0 |
Re: Kind of Steganography
Well, the idea of hiding text with use of tabs and spaces seem to be around for quite a long time... Actually I'm not very surprised - it's clever, yet obvious. :)
Nonetheless, I've never seen malware using this technique before.
|
0 |
Re: Re: Kind of Steganography
well in fact i have seen many variations of this technique in many wargames, but i'm agree, not in malware...
I bet that soon we'll see malware in LSB too, and in future will be common
|
0 |
Re: Re: Kind of Steganography
Actually for those who don't know there is also a programming language that uses only whitespace characters http://en.wikipedia.org/wiki/Whitespace_%28programming_language%29 tried to write a source code that would compile in C and whitespace and do the same thing a while ago.
Analysis
Blog