Locky: JavaScript Deobfuscation
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 won't 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)
Function Decode does the re.sub call with the regular expression and DecodeExpression function:
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)'. In stead of trying to design a regular expression that will also match this expression, we can just remove the parentheses: gramme.
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"('[^']*' \+ )+'[^']*'", DecodeExpresssion, data)
Now you can clearly see the URL, but let's add a newline after each semi-colon (;) 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.
Comments
Anonymous
Dec 3rd 2022
10 months ago
Anonymous
Dec 3rd 2022
10 months ago
<a hreaf="https://technolytical.com/">the social network</a> is described as follows because they respect your privacy and keep your data secure. The social networks are not interested in collecting data about you. They don't care about what you're doing, or what you like. They don't want to know who you talk to, or where you go.
<a hreaf="https://technolytical.com/">the social network</a> is not interested in collecting data about you. They don't care about what you're doing, or what you like. They don't want to know who you talk to, or where you go. The social networks only collect the minimum amount of information required for the service that they provide. Your personal information is kept private, and is never shared with other companies without your permission
Anonymous
Dec 26th 2022
9 months ago
Anonymous
Dec 26th 2022
9 months ago
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> nearest public toilet to me</a>
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> public bathroom near me</a>
Anonymous
Dec 26th 2022
9 months ago
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> nearest public toilet to me</a>
<a hreaf="https://defineprogramming.com/the-public-bathroom-near-me-find-nearest-public-toilet/"> public bathroom near me</a>
Anonymous
Dec 26th 2022
9 months ago
Anonymous
Dec 26th 2022
9 months ago
https://defineprogramming.com/
Dec 26th 2022
9 months ago
distribute malware. Even if the URL listed on the ad shows a legitimate website, subsequent ad traffic can easily lead to a fake page. Different types of malware are distributed in this manner. I've seen IcedID (Bokbot), Gozi/ISFB, and various information stealers distributed through fake software websites that were provided through Google ad traffic. I submitted malicious files from this example to VirusTotal and found a low rate of detection, with some files not showing as malware at all. Additionally, domains associated with this infection frequently change. That might make it hard to detect.
https://clickercounter.org/
https://defineprogramming.com/
Dec 26th 2022
9 months ago
rthrth
Jan 2nd 2023
9 months ago