Blogs & Stories

SpiderLabs Blog

Attracting more than a half-million annual readers, this is the security community's go-to destination for technical breakdowns of the latest threats, critical vulnerability disclosures and cutting-edge research.

Deobfuscating the Recent Emotet Epoch 4 Macro

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 OneNote, A 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. 











File Name 

Hash Type 


ACH Payment info.zip   








File Name 

Hash Type 


ACH Payment info.doc  








File Name 

Hash Type 










File Name 

Hash Type