CVE-2024-3400: PAN-OS Command Injection Vulnerability in GlobalProtect Gateway. Learn More

CVE-2024-3400: PAN-OS Command Injection Vulnerability in GlobalProtect Gateway. Learn More

Services
Capture
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

twi-managed-portal-color
Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

twi-briefcase-color-svg
Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

tw-laptop-data
Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

tw-officer
Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

tw-network
Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Offensive Security
Solutions to maximize your security ROI
Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

Stealthy VBA Macro Embedded in PDF-like Header Helps Evade Detection

In the ever-evolving landscape of malware threats, threat actors are continually creating new techniques to bypass detection. A recent discovery by JPCERT/CC sheds light on a new technique that involves embedding a malicious Word document within a seemingly benign PDF file using a .doc file extension.

In the file, researchers discovered the malicious Word document contained a magic header signature, `%PDF-1.7` - a header normally associated with PDF files. Furthermore, following the fake PDF structure, they came across a MIME encapsulation of aggregate HTML documents (MHTML Web Archive) containing an embedded Base64 encoded ActiveMIME object. ActiveMIME is an undocumented Microsoft file format that contains a ZLIB-compressed data often used to store VBA Macros.

 

VBAMacro1

Figure 1. Fake PDF header complete with PDF tags structures

 

VBAMacro2

Figure 2. Embedded in the file is a Word document in MHT format after the Fake PDF object.

 

As you may be aware, the delivery of malicious documents via MHT files is not new. We have been observing this type of malware as early as 2015. One noteworthy, but unfortunate, aspect of Microsoft Office is its wide array of file formats that can house malicious macros, allowing for unconventional file containers.

 

VBAMacro3

Figure 3. A document file can be saved with various formats including MHT or MHTML.

 

By changing the file’s extension to ‘.doc’, the Microsoft Office application can open the embedded MHT file and execute embedded malicious macros if they are enabled by the user.

 

VBAMacro4Figure 4. A sample discovered by JPCERT – an MHT file featuring a fake PDF header containing a malicious VBA macro

 

There are several obfuscation techniques employed in these new samples, all designed to evade detection based on signatures.

  1. Use of a non-compliant MIME type in the content-type header for the ActiveMIME object file. For example, as indicated in Figure 5, it utilizes the ‘image/jpeg’ MIME type instead of the anticipated ‘application/x-mso.’

 

  1. The Base64 encoded strings of the ActiveMIME Object are fragmented by multiple whitespaces (also shown in Figure 5). This tactic aids in circumventing signature-based detection, as it breaks up continuous strings.

VBAMacro5

Figure 5. ActiveMime Object uses a non-conventional MIME type in the MIME header, moreover, the Base64 encoded string is fragmented. ActiveMime comprises zlib-compressed data starting at offset 0x32, then a standard OLE file housing a VBA macro project.

 

  1. Use of URL percent-encoded strings to obscure the link to the ActiveMIME object.

VBAMacro6

Figure 6. The document conceals an MSO link to the ActiveMime Object by obfuscating it through URL percent-encoded characters.

 

We experimented with this file, and what's particularly concerning is this embedded MHT document file doesn't actually require a PDF header. Any text preceding the MHT file will still allow MS Word to open the document file and execute the malicious macro if enabled. This was not clear in the early reports of this flaw.

 

VBAMacro7

Figure 7. Removing the PDF header doesn’t hinder the MS Office application from opening the malicious MHT document.

 

This manoeuvre can evade signature-based detection systems that specifically scan for a PDF header. This is highlighted in the VirusTotal results displayed below: the DOC file with a PDF header is detected by 35 out of 59 vendors, whereas without the PDF header, only six out of 59 vendors detect the sample.

 

VBAMacro8

Figure 8. Comparing the VirusTotal detection results between a sample with a fake PDF header and one with the PDF header removed

 

To wrap up, the range of techniques used in this attack, from using non-compliant file headers and MIME types, to fragmented Base64 encoding strings, highlights a clever approach to evading traditional detection mechanisms used by most anti-virus engines. Equally concerning is the fact that MHT document files can be concealed within a plain text file, allowing Microsoft Word to open them seamlessly.

 

Here is some key mitigation advice to protect users:

  1. Configure Microsoft Office to disable macros by default, effectively blocking the execution of macros. The Center for Internet Security has provided a comprehensive article detailing the steps for both network administrators and end-users on how to implement this security measure.
  2. Restrict macro execution to documents sourced exclusively from trusted origins and consider enforcing a policy that permits only digitally signed macros to run.
  3. Educate users about the potential risks when enabling macros and promote user awareness of the consequences involved.
  4. Use a robust secure email gateway like Trustwave MailMarshal to scan incoming attachments and document files for malicious content.

Also, here’s a YARA rule, based on JPCERT’s YARA suggestions, to identify potential malicious macros embedded in files without conducting PDF header checking:

 

rule suspect_malware_mht_activemime

{

meta:

         desc = "MHT document with ActiveMime Object"

         reference = "https://blogs.jpcert.or.jp/en/2023/08/maldocinpdf.html"

strings:

         $mhtfile1 = "mso" nocase ascii

         $mhtfile2 = "nextpart" nocase ascii

         $mhtfile3 = "mime" nocase ascii

$mhtfile4 = "content-location:" nocase ascii

         $mhtfile5 = "content-type:" nocase ascii

         $mhtfile6 = /multipart\/(related|mixed)/ nocase ascii

         $mhtfile7 = "base64" nocase ascii

         $mhtfile8 = /\s-Version:/ nocase ascii

         $wordfile = "<w:WordDocument>" nocase ascii

         $excelfile = "<x:ExcelWorkbook>" nocase ascii

         $activemime1 = /\nQ\s{0,999}?W\s{0,999}?N\s{0,999}?0\s{0,999}?a/  // Base64 encoded 'ActiveMime' with spaces

         $activemime2 = "ActiveMime" base64

condition:

         all of ($mhtfile*) and ($wordfile or $excelfile) and ($activemime1 or $activemime2)

}

Figure 9. JPCERT YARA rule suggestions to identify potential malicious macros embedded in files without conducting PDF header checking

Latest SpiderLabs Blogs

Guardians of the Gateway: Identity and Access Management Best Practices

This is Part 10 in my ongoing project to cover 30 cybersecurity topics in 30 weekly blog posts. The full series can be found here.

Read More

Protecting Zion: InfoSec Encryption Concepts and Tips

This is Part 9 in my ongoing project to cover 30 cybersecurity topics in 30 weekly blog posts. The full series can be found here.

Read More

EDR – The Multi-Tool of Security Defenses

This is Part 8 in my ongoing project to cover 30 cybersecurity topics in 30 weekly blog posts. The full series can be found here.

Read More