SpiderLabs Blog

Deobfuscating the Recent Emotet Epoch 4 Macro

Written by Rodel Mendrez, Joshua Deacon | Apr 4, 2023 8:05:00 PM

In early March, one of the notorious botnets, Emotet, resumed its spamming activities after a 3-month period of inactivity.  

Recently, Trustwave SpiderLabs saw Emotet switch focus to using OneNote attachments, which is a tactic also adopted by other malware groups in recent months. This analysis is intended to help the cybersecurity community better understand the wider obfuscation and padding tricks Emotet is using.  

For a more in-depth analysis of this technique, please refer to our series of blog posts which can be found here: Trojanized OneNoteA Noteworthy Threat, and OneNote Spear-Phishing Campaign 

At first, this spam campaign followed the typical scenario with a document file carrying malware that was attached to a convincing reply-chain email. However, Emotet used a ‘new old trick’ in an attempt to bypass security scanners by compressing a bloated document file into a ZIP file.  

Figure 1. Recent Emotet spam campaign with a ZIP compressed document file 

Twitter handle @Cryptolaemus1 who tracks this botnet noticed this spam activity coming from Emotet Epoch 4.     

Figure 2. A tweet from Cryptolaemus 

At the surface level, the ZIP file appears small in file size but when extracting the document from the ZIP, we see that the decompressed file size is a little over 500MB. Upon further investigation of the document, we found the reason for the abnormal file size is a zero-byte padding technique.  

This technique is where a file's size is inflated by appending null bytes or useless data to the end of a file. Often, this is done as an evasion technique to avoid security software as many tools do not allow uploading or scanning of large files. It is extremely suspicious, so much so, that our Trustwave MailMarshal email gateway simply blocked all the samples up-front due to the massively redundant data.  

Figure 3. Suspicious document before the padding is removed. 

After removing most of the padding, the file comes down to just 303KB. 

Figure 4. Suspicious document after the padding is removed. 

Deobfuscating the Macro: 

The document file is similar to previous Emotet spam campaigns and includes a highly obfuscated malicious macro. The code obfuscation may initially appear messy and difficult to read. 

Figure 5. Emotet’s obfuscated VBA macro1 

It contains random function and variable names, as well as thousands of lines of seemingly unused code. However, there is a recognizable macro name present in the code: AutoOpen. This macro is an event that is triggered when the document file is opened, making it the entry point function. 

Figure 6. Emotet’s use of random macro names2 

Within the AutoOpen macro, a specific function named ‘uYiCsM’ is called. This is repeatedly called throughout the code, appearing a total of 41 times. 

Figure 7. Function uYiCsM is the decode function3 

Before calling the decode function, a block of code initializes the variables that will be passed as parameters to the decode function. These parameters include the character table, a list of character indices, and string length.  

Figure 8. Before calling the decode function, it initializes variables for the string length, the character table.  

Deobfuscating a single string can require a block of code that is notably lengthy and may span several hundred lines of code. Nevertheless, as one delves deeper into the code, a pattern may start to emerge and become easier to discern. 

Figure 9. Initializing character indices is a pattern that becomes evident throughout the code. However, assigning a single value to one index uses three lines of code, contributing to the code's overall length and complexity. 

The length of obfuscated code is primarily due to the initialization of the list of character indices, which can be convoluted. Additionally, the use of individual lines of code to assign each value to an index can contribute to the overall length of the code. 

The code below is the decode function that takes a character table and a list of character indices and uses them to decode a string by reading characters from the character table based on the indices and appending them to a new string. 

Figure 10. Obfuscated code of the decode function. 

Figure 11. Right is the deobfuscated and beautified code for easy readability. 

Figure 12. We converted the decode function into a Python code to decode the strings in a controlled manner. 

Once strings are decoded, we can refactor the code and beautify it for easy readability. We have shared the complete deobfuscated VBA macro code in our Gists. 

Figure 13. Comparison of the obfuscated and the deobfuscated AutoOpen macro. 

This summary describes the flow of the AutoOpen macro:

  • Declare variables and assign values to the variables for URLs and file extensions. 
  • Generate a filepath with the current time and append the ‘.tmp’ file extension to it. 
  • Try to download a file from the first URL, and if that fails, try to download from the remaining URLs until a download is successful. 
  • If a download is successful, it checks whether the file is a PE or a ZIP archive. 
  • If the file is a ZIP archive, the malware unpacks the binary. 
  • Proceeds to execute the binary via regsvr32.exe. 

It is worth noting that the file extracted from the downloaded archive also contains an excessive amount of null bytes, which gives the impression that it is a much larger file than it actually is. 

IOCs

URLs

hxxp://xyktza.nbxyk.net/bwzysov/index/X3hFHbueMtgoEi/etaJ35/ 

hxxp://arlex.su/services/IE2h6fBsQRQOhHBI691U/ 

hxxp://api.660011.cc/wp-includes/b028GIRSxa4lY/ 

hxxp://www.garrett.kz/faq/B0faEHvS9msSo9xbVe/ 

hxxp://abrokov.com/lang/SZnqErcEtuE/ 

hxxp://rref.su/uchastniki/rNNdVArBjNc100n3p/ 

hxxp://mealux.by/pab4/wxuGxcqF85M/ 

 

Hashes 

File Name 

Hash Type 

Hashes 

ACH Payment info.zip   

MD5 

68612b3d0094d51d3ca89ed6e3b16b4c  

SHA1 

b80ac7dda1b65be5297ba03b1ac17dbc2bb10339  

SHA256 

7041a0d1b2d0c1199e4b7505b0ab181ad2cdc881e01a520fb66758f081e4d40d 

 

File Name 

Hash Type 

Hashes 

ACH Payment info.doc  

MD5 

141c079135312197dcb6d2adfe8b5663  

SHA1 

4f2e8fcbdb60e099241c0e8e203c700d9d4941b2  

SHA256 

57903dc1811ef431a8480dc489764d9b2dae324fcf002c924c8f3a592b96a922 

 

File Name 

Hash Type 

Hashes 

downloaded.zip  

MD5 

20758c45171dfad6bb02a77b773782d3  

SHA1 

e0ea8e2d0580ffe40ec5ed3bdd2bb78c6c7b2ffb  

SHA256 

a189c6cecce39ab05abb5386ca036887170c28a40cd1acd76dd7b4c36e0a2d9d 

 

File Name 

Hash Type 

Hashes 

sHwNyPFidh5lkT7KX86sNryPMvM4.dll  

MD5 

fa914c6c9744ea25592dfca65a9d13e1  

SHA1 

663861e36c8d55911a036bbc9108c3d774a97b2a  

SHA256 

cecdb3028c0879a850ccbf0535cc3918912d9b6e19b40b6dbfedb0c58265227c