XLMMacroDeobfuscator 可用于解码混淆的 XLM 宏(也称为 Excel 4.0 宏)。它利用内部 XLM 模拟器解释宏,而无需完全执行代码。
支持 xls、xlsm 和 xlsb 格式。
它使用 xlrd2、pyxlsb2 以及自己的解析器分别从 xls、xlsb 和 xlsm 文件中提取单元格和其他信息。
你还可以在 xlm-macro-lark.template 中找到 XLM 语法。
pip install XLMMacroDeobfuscator --force
或
pip install xlmmacrodeobfuscator[defusedxml] --force
pip install -U https://github.com/DissectMalware/XLMMacroDeobfuscator/archive/master.zip --force
对 Excel 文档中的宏进行去混淆:
xlmdeobfuscator --file document.xlsm
仅提取 Excel 文档中的宏(不进行任何去混淆):
xlmdeobfuscator --file document.xlsm -x
仅获取去混淆后的宏且不包含缩进:
xlmdeobfuscator --file document.xlsm --no-indent --output-formula-format "[[INT-FORMULA]]"
以 JSON 格式导出输出:
xlmdeobfuscator --file document.xlsm --export-json result.json
要查看 JSON 输出示例,请查看此链接。
使用配置文件:
xlmdeobfuscator --file document.xlsm -c default.config
default.config 文件必须是一个有效的 JSON 文件,例如:
{
"no-indent": true,
"output-formula-format": "[[CELL-ADDR]] [[INT-FORMULA]]",
"non-interactive": true,
"output-level": 1
}
_ _______
|\ /|( \ ( )
( \ / )| ( | () () |
\ (_) / | | | || || |
) _ ( | | | |(_)| |
/ ( ) \ | | | | | |
( / \ )| (____/\| ) ( |
|/ \|(_______/|/ \|
______ _______ _______ ______ _______ _______ _______ _______ _________ _______ _______
( __ \ ( ____ \( ___ )( ___ \ ( ____ \|\ /|( ____ \( ____ \( ___ )\__ __/( ___ )( ____ )
| ( \ )| ( \/| ( ) || ( ) )| ( \/| ) ( || ( \/| ( \/| ( ) | ) ( | ( ) || ( )|
| | ) || (__ | | | || (__/ / | (__ | | | || (_____ | | | (___) | | | | | | || (____)|
| | | || __) | | | || __ ( | __) | | | |(_____ )| | | ___ | | | | | | || __)
| | ) || ( | | | || ( \ \ | ( | | | | ) || | | ( ) | | | | | | || (\ (
| (__/ )| (____/\| (___) || )___) )| ) | (___) |/\____) || (____/\| ) ( | | | | (___) || ) \ \__
(______/ (_______/(_______)|/ \___/ |/ (_______)\_______)(_______/|/ \| )_( (_______)|/ \__/
XLMMacroDeobfuscator(v0.2.0) - https://github.com/DissectMalware/XLMMacroDeobfuscator
Error: --file is missing
usage: deobfuscator.py [-h] [-c FILE_PATH] [-f FILE_PATH] [-n] [-x]
[--sort-formulas] [--defined-names] [-2]
[--with-ms-excel] [-s] [-d DAY]
[--output-formula-format OUTPUT_FORMULA_FORMAT]
[--extract-formula-format EXTRACT_FORMULA_FORMAT]
[--no-indent] [--silent] [--export-json FILE_PATH]
[--start-point CELL_ADDR] [-p PASSWORD]
[-o OUTPUT_LEVEL] [--timeout N]
optional arguments:
-h, --help show this help message and exit
-c FILE_PATH, --config-file FILE_PATH
Specify a config file (must be a valid JSON file)
-f FILE_PATH, --file FILE_PATH
The path of a XLSM file
-n, --noninteractive Disable interactive shell
-x, --extract-only Only extract cells without any emulation
--sort-formulas Sort extracted formulas based on their cell address
(requires -x)
--defined-names Extract all defined names
-2, --no-ms-excel [Deprecated] Do not use MS Excel to process XLS files
--with-ms-excel Use MS Excel to process XLS files
-s, --start-with-shell
Open an XLM shell before interpreting the macros in
the input
-d DAY, --day DAY Specify the day of month
--output-formula-format OUTPUT_FORMULA_FORMAT
Specify the format for output formulas ([[CELL-ADDR]],
[[INT-FORMULA]], and [[STATUS]]
--extract-formula-format EXTRACT_FORMULA_FORMAT
Specify the format for extracted formulas ([[CELL-
ADDR]], [[CELL-FORMULA]], and [[CELL-VALUE]]
--no-indent Do not show indent before formulas
--silent Do not print output
--export-json FILE_PATH
Export the output to JSON
--start-point CELL_ADDR
Start interpretation from a specific cell address
-p PASSWORD, --password PASSWORD
Password to decrypt the protected document
-o OUTPUT_LEVEL, --output-level OUTPUT_LEVEL
Set the level of details to be shown (0:all commands,
1: commands no jump 2:important commands 3:strings in
important commands).
--timeout N stop emulation after N seconds (0: not interruption
N>0: stop emulation after N seconds)
以下示例展示了如何在 Python 项目中使用 XLMMacroDeobfuscator 对 XLM 宏进行去混淆:
from XLMMacroDeobfuscator.deobfuscator import process_file
result = process_file(file='path/to/an/excel/file',
noninteractive= True,
noindent= True,
output_formula_format='[[CELL-ADDR]], [[INT-FORMULA]]',
return_deobfuscated= True,
timeout= 30)
for record in result:
print(record)
请阅读 requirements.txt 以获取 XLMMacroDeobfuscator 依赖的 Python 库列表。
xlmdeobfuscator 可以在任何操作系统上执行,以提取和去混淆 xls、xlsm 和 xlsb 文件中的宏。你不需要安装 MS Excel。
注意:如果你想使用 MS Excel(在 Windows 上),你需要安装 pywin32 库并使用 --with-ms-excel 开关。 如果使用了 --with-ms-excel,xlmdeobfuscator 会首先尝试通过 MS Excel 加载 xls 文件,如果失败,则使用 xlrd2 库。
XLMMacroDeobfuscator 已被以下项目采用:
如果你已将 XLMMacroDeobfuscator 集成到你的项目中,请与我联系。
如果你发现了错误或想提出改进建议,请在问题页面上创建一个新问题。
欢迎通过复刻本项目并提交 Pull Request 来贡献代码。
你可以通过直接消息在 Twitter 上联系我(@DissectMalware)。