The Complexity amidst Simplicity: Exploiting the MS Office DDE Feature

Albert Einstein once said, "Out of Complexity, Find Simplicity" but it also seems that simplicity is always related to a puzzle of complexity. This statement also applies to the Microsoft's Dynamic Data Exchange (DDE) protocol vulnerability exploit which was recently disclosed by Sensepost. The exploit itself is so simple that novice users will have no problems creating and replicating it. The complexity comes when you try to protect unsuspecting users from such threats.

The Simplicity

The Dynamic Data Exchange (DDE) Protocol is a feature in Windows that allows sharing of data from one application to another. Using DDEAUTO allows for automatic code execution that is prone to abuse for those who have malicious intent.

Here is the simple two-step process to create a possible malicious sample:

  1. Press CRTL-F9 will enable you to create an Field Identifier
  2. Type the DDEAUTO [path of executable] [arguments]

Example

Simple enough? Then let's elaborate on how this simple trick becomes complex from a defender's point of view when it only takes a few keyboard strokes to generate a working sample.

The Complexity

After doing the quick two-step process, the user can choose whether to save the resulting file as Open XML Format (*.DOCX) or Compound File Binary Format – Word 97-2003 format (*.DOC) or save it as Rich Text Format (*.RTF). This is where it becomes tricky since, as defenders, we need to create multiple signatures to handle each file formats without creating False Positives.

In the Office Open XML format, the exploit code can always be found after the <w:fldChar w:fldCharType="begin"/> followed by DDEAUTO.

01XMLModFigure 1 – DDE Code Execution on XML based Formats running a PowerShell script

In the RTF format, the code will start with the "{\field{\*\fldinst"

02RTFModFigure 2 – DDE Code Execution running a PowerShell script on RTF File.

While within the old Compound File Binary Format (CFBF), it will always start with the double bang "!!" or 0x13 and followed by DDEAUTO.

03DOCModFigure 3 – DDE Code Execution running a PowerShell script on CFBF

One significant angle to look at is that some samples in the wild uses "DDE" instead of "DDEAUTO". Another major concern is obfuscation using string segmentation, which was used by threat actors in CVE-2017-8759 RTF exploits.

04RTF02ModFigure 4 – DDE Code Segmentation on RTF

This segmentation technique has also been seen applied to XML based formats.

05XML03ModFigure 5 – DDE Code Segmentation on XML

To add to the complexity, it is not just MS Word that is affected but also MS Outlook. Using a Rich Text format to create an email message or a meeting invite, one can copy-paste the DDEAUTO exploit code from MSWord to the email body and basically send it or save it as a *.MSG file.

05OutlookFigure 6 – Creating a Calendar/Meeting Invites as Rich Text Format

But wait, there's more! Major threat actors have started to play around with this exploit and recently we observed that Necurs botnet has spearheaded massive attacks on email gateways everywhere.

Email DDEEmail DDEFigure 7 – Email Templates used by Necurs Spambot

The Necurs-driven email campaign has an attached Open Office Word document with the malicious DDE exploit code.

06_XML_EMAILFigure 8 – Document.XML from the attached DOC file

Here is the extracted DDEAUTO that executes a PowerShell script.

Ps_from documentFigure 9 – Complete DDE code execution string

Which downloads another PowerShell script that will eventually download a Locky ransonmware file.

Downloaded_psFigure 10 – PowerShell script that downloads a binary file from the listed URLs

How Can We Protect Ourselves?

Obviously, we are focusing on a range of protections in our products. However, sometimes the simplest solutions come from our daily life choices and that is everyone should learn to say "NO". The neat thing about DDE is that it provides the user with a prompt. Simple enough! Click NO!!

SayNO1st
Figure 11 – First DDE Prompt

But people have this tendency to say "YES" and after that may not have the luxury to go back. Luckily, with DDE, you have a second chance to say "NO", so use that chance very well.

SayNO2nd

Figure 12 – Second DDE Prompt

Conclusion

The ease of this attack combined with the complexity of handling the variety of file formats, the number of applications affected, and the possible obfuscations that can be incorporated, means that exploiting DDE will become a favorite pastime of attackers for some time to come. The fact that the Necurs botnet has jumped on the bandwagon with mass spam campaigns bears witness to this. Expect to see much more of this in the near future.

Trustwave reserves the right to review all comments in the discussion below. Please note that for security and other reasons, we may not approve comments containing links.