Yesterday, Wayne Smith submitted a sample (MD5 F1F31B18259DC9768D8B6132E543E3EE) to the ISC. Xavier, handler on duty, analyzed the (malicious) JavaScript in his sandbox, but it failed with an error. As I wrote in a previous diary, if malware malfunctions, you can still use static analysis.

Here is the script:

The expression I labeled 1 is a list of strings. The last string has a method call (e.()). This String method is defined farther down in the script: look at the function definition I labeled 2. Method e() returns the first character of the string to which it is applied. So the expression (office, modal, dialect, \u0074informer.e()) can be replace with expression (office, modal, dialect, \u0074), or (office, modal, dialect, t). When a list is evaluated in JavaScript, it evaluates to its last emelent. So the expression finally becomes t. You can see that this script contains many expressions similar to the one I just reduced: this is the kind of string obfuscation used in this sample.

So what I would like to do is replace each expression with the character it evaluates to. Python has an interesting function I want to use in this case: re.sub. re.sub takes a regular expression and applies it to a given string. For each match in the string, it will replace the matched character sequence with a string or (and this is what I need) the return value of a function that is called for each match. So I can write a regular expression that will match strings like (office, modal, dialect, \u0074informer.e()), and then write a function that will evaluate this expression (to t in this case). I wont write a Python program from scratch to do this, but I will use my translate.py tool. Here is the Python code (decode-1.py) I will use:

import re

def DecodeExpresssion(oMatch):
return + chr(int(oMatch.group(1), 16)) +

def Decode(data):
return re.sub(r\([^\\\(]+\\u([0-9a-f]{4})[a-z]+\.e\(\)\), DecodeExpresssion, data)

" />

This translates the expressions as we wanted, expect for one: (sabotage, arctic, special, minimal, gram(me), memorial, \u0045international.e()). Our translation failed for this expression, because my regular expression is not designed to match words that contain parentheses: gram(me)" />

If you look closely, you will see some keywords and maybe a URL. But to make it easier to read, we will concatenate the string expressions with this Python script (decode-2.py):

import re

def DecodeExpresssion(oMatch):
return + eval(oMatch.group(0)) +

def Decode(data):
return re.sub(r([^]* \+ )+[^]*" />

Now you can clearly see the URL, but let) to make the script a bit more readable:

I downloaded this Locky sample with the deobfuscated URL: MD5 91d8ab08a37f9c26a743380677aa200d

Didier Stevens
SANS ISC Handler
Microsoft MVP Consumer Security
blog.DidierStevens.com DidierStevensLabs.com
IT Security consultant at Contraste Europe.

(c) SANS Internet Storm Center. https://isc.sans.edu Creative Commons Attribution-Noncommercial 3.0 United States License.
[SYSS-2015-064] Thru Managed File Transfer Portal 9.0.2 - Insecure Direct Object Reference (CWE-932)
[SYSS-2015-062] ownCloud - Information Exposure Through Directory Listing (CWE-548)
[SYSS-2015-058] Thru Managed File Transfer Portal 9.0.2 - Insecure Direct Object Reference (CWE-932)
[SYSS-2015-055] Novell Filr - Cross-Site Scripting (CWE-79)
[SECURITY] [DSA 3484-1] xdelta3 security update
Internet Storm Center Infocon Status