Blogs & Stories

SpiderLabs Blog

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

Demystifying Obfuscation Used in the Thanksgiving Spam Campaign

During Thanksgiving week, we noticed this quite unusual XML-format MS Office Document file

Emailsample
Figure 1: Email Sample

 

Saving a Word document file as XML is a legitimate option but criminals had taken advantage of this file format to circumvent malware scanners and spam filters.

Figure2
Figure 2. XML header of a Word document file saved as XML file format

 

This Microsoft Office Word document file has an almost "hidden" TextFrame object sitting in the corner. The document also has macro in it which we will also be investigating.

Figure3
Figure 3. Screen capture of the document file when opened

 

If you expand this tiny TextFrame object you will see an obfuscated CMD shell:

Figure4
Figure 4 An Obfuscated CMD shell in the hidden TextFrame

 

The entire CMD code can be seen below:

Picture1
Figure 5 The full CMD shell extracted from the TextFrame

 

Next in the investigation, we de-obfuscated this shell command, by first removing all the caret characters "^", this is because CMD shell omits this on execution.

Figure 6
Figure 6 Part of the CMD shell after removing the Caret character

 

Taking a look at the first line of code:

cmd /c %LOCalAPpdaTA:~ -3,-2%^M%SysTEmrOoT:~ +6, +1%; ; ; ; /V:^o^ ; /%appDATa:~-7, 1%"

When printing this command using the echo command, it prints "cMD; ;;; /V:o /R"

Figure 7
Figure 7

The code extracts the substring from the value of the environment variable and from this, it builds a command string. For example:

%localappdata% environment variable is equivalent to this path "C:\Users\Username\AppData\Local"

Then using substring command in cmd shell "%localappdata:~-3,-2%" it extracts a character between position 3 from the end of the string and position 2 from the end string

"C:\Users\Username\AppData\Local"

Substring
Figure 8. How the " cMD; ;;; /V:o /R " string was built

 

We are not sure why the malware writer obfuscated this, since they already had a fairly obvious precursor "cmd" string in the command shell.

Figure 9
Figure 9. Highlighted in the red block is the obfuscated Powershell command, highlighted in blue is the deobfuscation routine

 

Next, we take a look at the block of obfuscated strings assigned to the variable t8Vb and the FOR loop after that (as seen in Figure 9):

for /l %m IN (2143, -4, 3) do (SeT yN5H=!yN5H!!t8Vb:~ %m, 1!) if %m==3 ;(call; %yN5H:*yN5H!=%)

The loop actually extracts each character starting from the end of the string of the variable t8Vb and steps 4 positions backward each loop until it reaches the 3rd position of the string.

To make it a lot easier, we can reverse the string block:

Figure 10
Figure 10. Reversing the obfuscated string

 

Then starting from the first position we extract every 4th character from the string block.

Pshell
Figure 11.

 

After extracting, it builds a stringof the powershell command shown below:

Figure 12
Figure 12.

 

So how does the powershell command get executed? The answer is a macro code. When a user opens this document file and enables the macros. A VBA macro code will trigger. This code extracts the string from the TextFrame then executes it using VBA Shell command

Figure 13
Figure 14
Figure 13.

 

So what is the payload?

Figure 15
Figure 15. A beautified code of the Powershell command

 

The PowerShell attempts to download a binary from a list of URLs:

hxxp:// danzarspiritandtruth[.]com /J7B5TiAIp

hxxp:// littlepeonyphotos[.]ru /jPGDyvIm

hxxp:// iuyouth.hcmiu.edu[.]vn /mVayv0I7S

hxxp:// exploraverde[.]co /mmR4TaGu8

hxxp:// turkaline[.]com /zGiFH0X

Then the script saves the binary to the Windows temporary folder and executes it.

The binary files at the end of the URL are Emotet - a notorious banking trojan that rolls out different behavior such as info-stealing modules for emails and browsers.

https://www.virustotal.com/gui/file/5f8aee58ec2f1342e84ed02d276c4369b1c2359a5e57ead9269bc6fa5d67ce59/detection

 

Recent SpiderLabs Blog Posts