Weaponizing XLM 4.0 macros
Last updated
Last updated
XLM macros a part of the Microsoft Office suite, and are an amazing resource to implement an initial foothold scenario to execute payloads in a red teaming exercise. This scenario is inspired on the following malwares that abuse XLM macro to load the first stage into the memory.
To start this laboratory, the first step is to create the XML macro inside an Excel document.
Click on "Sheet" / Right click / Add "XML Macro 4.0" / OK
After that, a new sheet will be created as presented below.
As a first test, we can execute "calc.exe" process when the macro is opened.
Note how we need to rename the A1
cell to Auto_Open
if we want the Macros to fire off once the document is opened:
After that, we can "save" our first PoC. Remember to save the document with Seet with privileges to execute Excel Macros (at the top of the options).
As expected, the calc.exe is launched when the excel file is opened. 😎
In order to perform a more complex scenario, we can simply adopt the approach used for instance by QakBot trojan malware.
The first two lines in the code are a particular highlight. These lines are actually an anti-evasion technique used to identify whether the file is facing a human or a machine (a sandbox). The GET.WORKSPACE() command gathers information about the properties of the environment. Each property is referenced by a number.
The documentation for the two investigated properties is as follows:
19: If a mouse is present, returns TRUE; otherwise, returns FALSE.
42: If your computer is capable of playing sounds, returns TRUE; otherwise, return FALSE.
These two properties, when being negative, are a fairly good indication for the malware to “understand” if it run inside a sandbox. Hence, the =IF(GET.WORKSPACE(19),,CLOSE(TRUE)) statement basically means that if the code is running inside a sandbox, it needs to “bail-out”, and avoid continuing to the malicious parts of the macro. This allows the sample to evade some dynamic security products that lack the proper emulation of such characteristics.