Skip to content

Commit 7f7433e

Browse files
committed
Xlm Macro deobfuscation
1 parent d78926f commit 7f7433e

File tree

7 files changed

+116
-2
lines changed

7 files changed

+116
-2
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import logging
2+
from XLMMacroDeobfuscator.deobfuscator import process_file
3+
from api_app.script_analyzers.classes import FileAnalyzer
4+
from celery.exceptions import SoftTimeLimitExceeded
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
class XlmMacroDeobfuscator(FileAnalyzer):
10+
def set_config(self, additional_config_params):
11+
self.passwords_to_check = [""]
12+
additional_passwords_to_check = additional_config_params.get(
13+
"passwords_to_check", []
14+
)
15+
if isinstance(additional_passwords_to_check, list):
16+
self.passwords_to_check.extend(additional_passwords_to_check)
17+
elif isinstance(additional_passwords_to_check, str):
18+
self.passwords_to_check.append(additional_passwords_to_check)
19+
20+
def run(self):
21+
results = {}
22+
try:
23+
for password in self.passwords_to_check:
24+
results = self.decrypt(password)
25+
if results:
26+
break
27+
if not results:
28+
results["error"] = "Can't decrypt with current passwords"
29+
except SoftTimeLimitExceeded as e:
30+
error_message = (
31+
f"job_id:{self.job_id} analyzer:{self.analyzer_name} md5:{self.md5}"
32+
f"filename: {self.filename}. Soft Time Limit Exceeded Error {e}"
33+
)
34+
logger.error(error_message)
35+
self.report["errors"].append(str(e))
36+
self.report["success"] = False
37+
return results
38+
39+
def decrypt(self, xlmpassword=""):
40+
args = {
41+
"file": self.filepath,
42+
"noindent": True,
43+
"nointeractive": True,
44+
"return_deobfuscated": True,
45+
"output_level": 3,
46+
}
47+
if xlmpassword:
48+
args["password"] = xlmpassword
49+
try:
50+
results = {"output": process_file(**args), "correct_password": xlmpassword}
51+
52+
return results
53+
except Exception as e:
54+
if "Failed to decrypt" in str(e):
55+
return {}
56+
return {"errors": str(e)}

configuration/analyzer_config.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@
165165
"text/x-ms-iqy",
166166
"application/excel",
167167
"text/xml",
168-
"application/xml"
168+
"application/xml",
169+
"application/zip"
169170
],
170171
"decription": "static generic document analysis",
171172
"python_module": "docinfo_run"
@@ -938,6 +939,23 @@
938939
"directories_with_rules": ["/opt/deploy/yara/rules"]
939940
}
940941
},
942+
"Xlm_Macro_Deobfuscator": {
943+
"type": "file",
944+
"supported_filetypes": [
945+
"application/vnd.ms-excel.addin.macroEnabled",
946+
"application/x-mspublisher",
947+
"application/vnd.ms-excel",
948+
"application/vnd.ms-excel.sheet.macroEnabled.12",
949+
"application/excel",
950+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
951+
"application/zip"
952+
],
953+
"decription": "Xlm macro deobfuscator",
954+
"python_module": "xlm_deobfuscator_run",
955+
"additional_config_params": {
956+
"passwords_to_check": ["agenzia", "inps", "coronavirus"]
957+
}
958+
},
941959
"Yara_Scan_Florian": {
942960
"type": "file",
943961
"description": "scan a file with Neo23x0 yara rules",

docs/source/Usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The following is the list of the available analyzers you can run out-of-the-box:
3737
* `Rtf_Info`: static RTF analysis
3838
* `Doc_Info`: static generic document analysis
3939
* `Doc_Info_Experimental`: static document analysis with new features to analyze XLM macros, encrypted macros and more
40+
* `Xlm_Macro_Deobfuscator`: [XlmMacroDeobfuscator](https://github.com/DissectMalware/XLMMacroDeobfuscator) deobfuscate xlm macros
4041
* `PE_Info`: static PE analysis
4142
* `Signature_Info`: PE signature extractor
4243
* `Speakeasy`: Speakeasy binary emulation

intel_owl/tasks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
apkid,
2323
quark_engine,
2424
unpac_me,
25+
xlm_macro_deobfuscator,
2526
)
2627
from api_app.script_analyzers.observable_analyzers import (
2728
abuseipdb,
@@ -612,6 +613,15 @@ def docinfo_run(
612613
).start()
613614

614615

616+
@shared_task(soft_time_limit=30)
617+
def xlm_deobfuscator_run(
618+
analyzer_name, job_id, filepath, filename, md5, additional_config_params
619+
):
620+
xlm_macro_deobfuscator.XlmMacroDeobfuscator(
621+
analyzer_name, job_id, filepath, filename, md5, additional_config_params
622+
).start()
623+
624+
615625
@shared_task(soft_time_limit=30)
616626
def rtfinfo_run(
617627
analyzer_name, job_id, filepath, filename, md5, additional_config_params

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ djangorestframework-guardian==0.3.0
8080
flake8==3.8.2
8181
black==19.10b0
8282
quark-engine==20.8
83-
git+git://github.com/DissectMalware/XLMMacroDeobfuscator.git@c78b9e443e2667399470462fd863ebe4e2b8c978
83+
git+git://github.com/DissectMalware/XLMMacroDeobfuscator.git@89fbce0c87014a4b5a22c1aef09c8b3ea9bf16c0
8484
speakeasy-emulator==1.4.4

tests/test_files.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
apkid,
2828
quark_engine,
2929
unpac_me,
30+
xlm_macro_deobfuscator,
3031
)
3132
from api_app.script_analyzers.observable_analyzers import vt3_get
3233

@@ -295,6 +296,34 @@ def test_speakeasy_dll(self):
295296
self.assertEqual(report.get("success", False), True)
296297

297298

299+
class FileAnalyzersExcelTests(TestCase):
300+
def setUp(self):
301+
params = {
302+
"source": "test",
303+
"is_sample": True,
304+
"file_mimetype": "application/vnd.ms-excel",
305+
"force_privacy": False,
306+
"analyzers_requested": ["test"],
307+
}
308+
filename = "document.xls"
309+
test_job = _generate_test_job_with_file(params, filename)
310+
self.job_id = test_job.id
311+
self.filepath, self.filename = utils.get_filepath_filename(self.job_id)
312+
self.runtime_configuration = test_job.runtime_configuration
313+
self.md5 = test_job.md5
314+
315+
def test_xlm_macro_deobfuscator_excel(self):
316+
report = xlm_macro_deobfuscator.XlmMacroDeobfuscator(
317+
"Xlm_Macro_Deobfuscator",
318+
self.job_id,
319+
self.filepath,
320+
self.filename,
321+
self.md5,
322+
{},
323+
).start()
324+
self.assertEqual(report.get("success", False), True)
325+
326+
298327
class FileAnalyzersDocTests(TestCase):
299328
def setUp(self):
300329
params = {

tests/test_files.zip

224 KB
Binary file not shown.

0 commit comments

Comments
 (0)