BH US 12 Miller Exploit Mitigation Slides
BH US 12 Miller Exploit Mitigation Slides
Charles
Chen,
Greg
Colombo,
Jason
Garms,
Stephen
Hufnagel,
Arun
Kishan,
Joe
Laughlin,
Pavel
Windows
Lebedynskiy,
John
Lin,
Gov
Maharaj,
Hari
Pulapaka,
Pierre-‐Yves
Santerre,
Neeraj
Singh,
Evan
Tice,
Valeriy
Tsuryk,
Suma
Uppuluri,
Landy
Wang,
Ma,hew
Woolman
Jonathan
Caves,
Tanveer
Gani,
Mark
Hall,
Lawrence
Joel,
Louis
Lafreniere,
Mark
Levine,
Steve
Visual
Studio
Lucco,
Mark
Roberts,
Andre
Vachon,
YongKang
Zhu
Internet Explorer David Fields, Forbes Higman, Eric Lawrence, Zach Murphy, JusYn Rogers
MicrosoA Research Richard Black, Miguel Castro, Manuel Costa, Ben Livshits, Jay Stokes, Ben Zorn
MicrosoA
Security
Eugene
Bobukh,
Tim
Burrell,
Thomas
Garnier,
NiYn
Kumar
Goel,
Ken
Johnson,
John
Lambert,
Ma,
Engineering
Center
Miller,
Dave
Probert,
Tony
Rice,
Richard
Shupak,
Julien
Vanegue,
Greg
Wroblewski
2
Windows
8
Security
Overview
The
development
of
Windows
8
followed
the
Windows
8
includes
new
protecYons
against
Security
Development
Lifecycle
(SDL)
which
root
and
boot
kits.
UEFI
systems
prevent
defines
best
pracYces
for
secure
so1ware
malware
from
starYng
before
Windows
and
design,
implementaYon,
and
tesYng.
protects
the
remainder
of
the
boot
process,
including
early
launch
anYmalware
so1ware.
Windows
8
includes
numerous
security
Windows
Defender
is
shipped
with
every
features,
such
as
miYgaYons,
that
make
it
ediYon
of
Windows
8
and
Internet
Explorer’s
difficult
and
costly
for
malware
authors
to
ApplicaYon
reputaYon
features
have
been
develop
reliable
exploits
for
vulnerabiliYes.
such
that
users
are
moved
into
the
placorm
protected
regardless
of
the
browser
they
use.
3
Framing
the
problem
with
exploit
economics
Use
sandboxing
to
protect
user
privacy
Cheaply
find
Find
and
eliminate
&
data
vulnerabiliDes
(they
vulnerability
classes
only
need
one)
A,ackers
want
to
maximize
ROI
We
want
to
minimize
ROI
Maximize
Use
telemetry
the
to
Break
cookbook
window
minimize
of
Dme
aJack
for
Cheaply
develop
techniques
&
make
using
an
window
exploit
exploits
exploits
unreliable
Today
we
will
describe
exploit
miYgaYon
improvements
in
Windows
8
that
increase
the
cost
of
developing
reliable
exploits
4
History
of
exploit
miYgaYons
on
Windows
VOID Function(LPCSTR Input) {
Stack-‐based
CHAR Buffer[256];
vulnerability
strcpy(Buffer, Input);
}
Stack-‐based
exploitaYon
and
miYgaYon
techniques
Linear
return
Linear
local
Linear
Linear
Non-‐linear/backward
address
variable
parameter
SEH
record
overwrites
overwrite
overwrite
overwrite
overwrite
(e.g.
a[n]
=
0)
GS
v1
(2002)
GS
v1.1
SafeSEH
(2003)
(2003)
GS
v2
(2005)
SEHOP
(2008)
GS
v3
(2010)
Control
of
InstrucDon
Pointer
5
History
of
exploit
miYgaYons
on
Windows
VOID Function(LPCSTR Input) {
Heap-‐based
PCHAR *Buffer = malloc(256);
vulnerability
strcpy(Buffer, Input);
}
Safe
unlinking
Vista
heap
hardening
(2006)
(2004)
Overwrite
or
Heap-‐based
exploitaYon
control
a
funcDon
and
miYgaYon
pointer
techniques
Control
of
InstrucDon
Pointer
6
History
of
exploit
miYgaYons
on
Windows
Control
of
eip=41414141 esp=0023f7dc ebp=0023f808…
cs=0023 ss=002b ds=002b es=002b fs=…
InstrucDon
Pointer
41414141 ?? ???
Execute
code
Execute
code
Execute
JIT’d
code
from
heap
Execute
code
from
a
loaded
image
from
stack
(JIT
spray)
(incl.
heap
spray)
DEP
(2004)
ASLR
(2006)
Predictable
ExecuYng
arbitrary
code
mappings/info
leaks
a1er
gaining
control
of
EIP
Arbitrary
code
execuDon
7
The
state
of
memory
safety
exploits
• About
6%
of
MSRT
detecYons
were
likely
caused
by
exploits
[29]
Most
systems
are
not
• Updates
were
available
for
more
than
a
year
for
most
of
the
exploited
compromised
by
exploits
issues
[29]
Most
exploits
target
third
• 11
of
13
CVEs
targeted
by
popular
exploit
kits
in
2011
were
for
issues
in
party
applicaYons
non-‐Microso1
applicaYons
[27]
Most
exploits
target
older
• Only
5%
of
184
sampled
exploits
succeeded
on
Windows
7
[28]
versions
of
Windows
(e.g.
XP)
• ASLR
and
other
miYgaYons
in
Windows
7
make
exploitaYon
costly
[30]
Most
exploits
fail
when
• 14
of
19
exploits
from
popular
exploit
kits
fail
with
DEP
enabled
[27]
miYgaYons
are
enabled
• 89%
of
184
sampled
exploits
failed
with
EMET
enabled
on
XP
[28]
Bo,om
line:
we
must
conYnue
to
increase
the
cost
of
exploitaYon
for
a,ackers
8
ObjecYves
&
focus
areas
in
Windows
8
ObjecDves
Code
GeneraYon
Security
MiYgate
enYre
classes
of
vulnerabiliYes
Address
Space
Layout
RandomizaYon
Break
known
exploitaYon
Windows
Heap
techniques
Increase
Windows
Kernel
the
cost
of
exploitaYon
in
key
domains
Default
Setngs
9
Enhanced
/GS,
range
checks,
sealed
opYmizaYon,
and
virtual
table
guard
CODE GENERATION
10
Enhanced
/GS
• Enhanced
GS
stack
buffer
overrun
protecYon
– Released
with
Visual
Studio
2010
[1]
– Windows
8
is
built
with
this
enabled
11
Range
Checks
• Compiler-‐inserted
array
bounds
check
(via
/GS)
CHAR Buffer[256];
UINT i; // possibly attacker controlled
Buffer[i] = 0;
12
Sealed
opYmizaYon
• OpYmizaYon
for
“sealed”
C++
types
&
methods
13
Virtual
Table
Guard
ProbabilisYc
miYgaYon
for
vulnerabiliYes
that
enable
vtable
ptr
corrupYon
mshtml!CElement::Doc:
CElement::`vftable’ 63700e70 mov eax,dword ptr [ecx]
VirtualMethod1 63700e72 cmp [eax+1B8h],offset mshtml!_vtguard
63700e7c jne mshtml!CElement::Doc+0x18 (63700e88)
VirtualMethod2
63700e7e call dword ptr [eax+0ACh]
VirtualMethod3 63700e84 mov eax,dword ptr [eax+0Ch]
VirtualMethod4 63700e87 ret
… 63700e88 call mshtml!__report_gsfailure
_vtguard
Extra
entry
added
to
vtable.
Check
added
at
virtual
method
call
sites.
ASLR
makes
this
entry’s
value
If
vtable[vtguard_vte]
!=
vtguard
unknown
to
the
aJacker.
then
terminate
the
process.
14
Force
ASLR,
bo,om-‐up/top-‐down
randomizaYon,
and
high
entropy
15
RetrospecYve:
ASLR
• ASLR
was
first
introduced
in
Windows
Vista
– Led
to
a
big
shi1
in
a,acker
mentality
• A,ackers
now
depend
on
gaps
in
ASLR
– EXEs/DLLs
not
linked
with
/DYNAMICBASE
[2]
– Address
space
spraying
(heap/JIT)
[3]
– Predictable
memory
regions
[4]
– InformaYon
disclosures
[5]
16
Force
ASLR
• Many
exploits
depend
on
non-‐ASLR
DLLs
0:000> !dh dirapi
...
4B4C111C time date stamp Mon Jan 11 22:05:16 2010
...
1000 base of code
----- new ----- Images
are
not
68000000 image base
1000 section alignment randomized
unless
the
...
00001000 size of heap commit DYNAMIC_BASE
bit
is
set
0 DLL characteristics
187A80 [ 402F] address [size] of Export Directory
1869F4 [ C8] address [size] of Import Directory
19B000 [ 12178] address [size] of Resource Directory
Address space
Windows
8
• All
bo,om-‐up/top-‐down
allocaYons
are
randomized
• Accomplished
by
biasing
start
address
of
allocaYons
Bo,om-‐up
allocaYons
• PEBs/TEBs
now
receive
much
more
entropy
(stacks,
heaps,
mapped
files,
VirtualAlloc,
etc)
• Both
are
opt-‐in
(EXE
must
be
dynamicbase)
High
entropy
• 8
GB
of
variance
in
top-‐down
start
address
top-‐down
• AutomaYcally
enabled
if
top-‐down
randomizaYon
is
on
randomizaYon
High
entropy
• Images
based
above
4
GB
receive
more
entropy
image
• All
system
images
have
been
moved
above
4
GB
randomizaYon
Outcome:
probability
of
guessing
an
address
is
decreased
and
disclosures
of
memory
addresses
must
include
more
than
the
low
32
bits
19
ASLR
entropy
improvements
Windows
7
Windows
8
Entropy
(in
bits)
by
region
32-‐bit
64-‐bit
32-‐bit
64-‐bit
64-‐bit
(HE)
Bo,om-‐up
allocaYons
(opt-‐in)
0
0
8
8
24
Stacks
14
14
17
17
33
Heaps
5
5
8
8
24
Top-‐down
allocaYons
(opt-‐in)
0
0
8
17
17
PEBs/TEBs
4
4
8
17
17
EXE
images
8
8
8
17*
17*
DLL
images
8
8
8
19*
19*
Non-‐ASLR
DLL
images
(opt-‐in)
0
0
8
8
24
*
64-‐bit
DLLs
based
below
ASLR
entropy
is
the
same
for
both
64-‐bit
processes
receive
much
more
4GB
receive
14
bits,
EXEs
32-‐bit
and
64-‐bit
processes
entropy
on
Windows
8,
especially
with
below
4GB
receive
8
bits
on
Windows
7
high
entropy
(HE)
enabled
20
Removal
of
informaYon
disclosure
vectors
WINDOWS HEAP
22
RetrospecYve:
Windows
Heap
• Windows
Vista
heap
hardening
was
very
effecYve
[11]
– Only
one
documented
exploit
that
corrupts
metadata
[9]
Frontend
allocator
(LFH)
Used
for
sizes
<
16KB
Backend
allocator
Used
by
frontend
and
for
sizes
less
than
512K
(x86)
or
1MB
(x64)
Virtual
memory
allocator
Used
by
backend
and
for
large
allocaYon
sizes
Kernel
memory
manager
24
LFH
design
changes
&
integrity
checks
Change
in
Windows
8
Impact
LFH
is
now
a
bitmap-‐based
allocator
LinkOffset
corrupYon
no
longer
possible
[8]
MulYple
catch-‐all
EH
blocks
removed
ExcepYons
are
no
longer
swallowed
Prevents
a,acks
that
try
to
corrupt
HEAP
HEAP
handle
can
no
longer
be
freed
handle
state
[7]
Prevents
a,acks
that
enable
reliable
control
HEAP
CommitRouYne
encoded
with
global
key
of
the
CommitRouYne
pointer
[7]
Prevents
unintended
free
of
in-‐use
heap
ValidaYon
of
extended
block
header
blocks
[7]
Prevents
various
a,acks
that
reallocate
an
Busy
blocks
cannot
be
allocated
in-‐use
block
[8,11]
Heap
encoding
is
now
enabled
in
kernel
mode
Be,er
protecYon
of
heap
entry
headers
[19]
Outcome: a,acking metadata used by the heap is now even more difficult
25
Guard
pages
• Guard
pages
are
now
used
to
parYYon
the
heap
– Designed
to
prevent
&
localize
corrupYon
in
some
cases
– Touching
a
guard
page
results
in
an
excepYon
…
Heap
memory
PAGE_NOACCESS
Guard
page
Heap
memory
…
26
AllocaYon
order
randomizaYon
• AllocaYon
order
is
now
nondeterminisYc
(LFH
only)
– Exploits
o1en
rely
on
surgical
heap
layout
manipulaYon
[10]
– RandomizaYon
makes
heap
normalizaYon
unreliable
Windows
7
LFH
block
allocaYon
behavior
O
T
27
DEP,
ASLR,
SMEP/PXN,
NULL
dereference
protecYon,
and
pool
integrity
checks
WINDOWS KERNEL
28
RetrospecYve:
Windows
Kernel
• Kernel
vulnerabiliYes
have
been
less
targeted
– RelaYvely
few
remote
kernel
exploits
exist
– User
mode
exploitaYon
is
be,er
researched
29
DEP
is
broadly
enabled
in
the
Windows
8
kernel
Many
kernel
memory
regions
were
unnecessarily
executable
in
Windows
7
and
prior
x86
(PAE)
x64
ARM
Win7
Win8
Win7
Win8
Win8
Paged
pool
X
X
NX
NX
NX
Windows
8
introduces
NonPagedPoolNx
for
Non-‐paged
pool
X
X
X
X
X
non-‐executable
non-‐
Non-‐paged
pool
(NX)
N/A
NX
N/A
NX
NX
paged
pool
allocaDons
(default
on
ARM)
Session
pool
X
X
NX
NX
NX
Image
data
secYons
X
X
NX
NX
NX
Kernel
stacks
NX
NX
NX
NX
NX
Idle/DPC/IniYal
stacks
X
NX
X
NX
NX
Page
table
pages
X
NX
X
NX
NX
PFN
database
X
NX
X
NX
NX
NX
HAL
heap
and
System
cache
X
NX
X
NX
NX
NonPagedPoolNx
break
the
assumpDons
of
Shared
user
data
X
NX
X
NX
NX
exploits
for
MS09-‐050
HAL
heap
X
NX
X
NX
NX
X
=
executable
NX
=
non-‐executable
30
Kernel
ASLR
improvements
• Kernel
ASLR
was
first
added
in
Server
2008
RTM
– 4
bits
of
entropy
for
drivers,
5
bits
for
NTOS/HAL
– Driver
entropy
was
improved
in
Windows
7
31
Support
for
SMEP/PXN
• New
processor
security
feature
– Prevents
supervisor
from
execuYng
code
in
user
pages
– Most
exploits
for
local
kernel
EOPs
rely
on
this
today
– Requires
Intel
Ivy
Bridge
or
ARM
with
PXN
support
32
NULL
dereference
protecYon
• Kernel
NULL
dereferences
are
a
common
issue
– Examples
include
MS08-‐025,
MS08-‐061,
MS09-‐001
33
Kernel
pool
integrity
checks
• The
kernel
pool
allocator
is
similar
to
the
heap
– ImplementaYon
is
very
different,
though
34
Other
improvements
• Safe
unlinking
has
been
enabled
globally
– Previously
only
used
in
the
heap
and
kernel
pool
– Now
applies
to
all
usage
of
LIST_ENTRY,
closing
known
gaps
[16]
– New
“FastFail”
mechanism
enables
rapid
&
safe
process
terminaYon
35
ARM,
Inbox,
Windows
8
style
apps,
IE
10,
the
new
Office,
and
other
applicaYons
DEFAULT SETTINGS
36
ARM
default
setngs
All
applicable
miYgaYons
are
enabled
on
ARM
DEP
On
ARM
PE
images
ASLR
(images)
On
must
opt-‐in
to
DEP
and
ASLR
ASLR
(force
relocate)
N/A
(all
images
are
ASLR)
ASLR
(bo,om-‐up)
On
Kernel
will
fail
to
load
images
ASLR
(top-‐down)
On
that
do
not
ASLR
(high
entropy)
N/A
(not
64-‐bit)
SEHOP
N/A
(not
needed)
Heap
terminaYon
On
Kernel
NULL
dereference
On
Kernel
SMEP
On
Lack of applicaYon compaYbility concerns enables us to be more aggressive
37
ApplicaYon
default
setngs
All
applicable
miYgaYons
are
enabled
for
Windows
8
UI
style
apps
32
bit
(x86)
64
bit
(x64)
Default
setngs
for
Windows
8
client
Win8
UI
Inbox
IE10
Default
Win8
UI
Inbox
IE10
Default
apps
apps
DEP
On
On
On
OptIn
On
On
On
OptIn
ASLR
(images)
On
On
On
OptIn
On
On
On
OptIn
ASLR
(force
relocate)
On
OptIn
On
OptIn
On
OptIn
On
OptIn
ASLR
(bo,om-‐up)
On
On
On
OptIn
On
On
On
OptIn
ASLR
(top-‐down)
On
On
On
OptIn
On
On
On
OptIn
ASLR
(high
entropy)
N/A
N/A
N/A
N/A
On
On
On
OptIn
SEHOP
On
On
On
OptIn
N/A
N/A
N/A
N/A
Heap
terminaYon
On
On
On
OptIn
On
On
On
On
Internet
Explorer
10
and
the
new
Office
also
enable
all
applicable
miYgaYons
38
Enabling
opt-‐in
miYgaYons
Opt-‐in
methods
• “MiYgaYonOpYons”
Image
File
ExecuYon
OpYon
(IFEO)
• Process
creaYon
a,ribute
(via
UpdateProcThreadA,ribute)
• SetProcessMiYgaYonPolicy
API
• Linker
flag
40
Call
to
acYon
• Upgrade
to
Windows
8
and
IE
10
J
– 64-‐bit
is
best
from
a
miYgaYons
perspecYve
– Enable
“Enhanced
Protected
Mode”
for
IE
10
• So1ware
vendors
– Build
your
applicaYons
with
Visual
Studio
2012
[31]
– Enable
new
opt-‐in
miYgaYons
• Driver
writers
– Port
your
drivers
to
use
NonPagedPoolNx
41
Contact
us
at
[email protected]
Were
you
fascinated
by
the
topics
discussed
in
this
presentaYon?
We
are
hiring.
h,p://www.microso1-‐careers.com/go/Trustworthy-‐CompuYng-‐Jobs/194701/
42
43
References
1. Enhanced
GS
in
Visual
Studio
2010.
Tim
Burrell.
March,
2009.
h,p://blogs.technet.com/b/srd/archive/2009/03/20/enhanced-‐gs-‐in-‐visual-‐studio-‐2010.aspx
2. Adobe
CoolType
SING
Table
“uniqueName”
Stack
Buffer
Overflow
Exploit.
Metasploit.
Sep,
2010.
h,p://dev.metasploit.com/redmine/projects/framework/repository/revisions/master/entry/modules/exploits/windows/
browser/adobe_cooltype_sing.rb
3. Interpreter
ExploitaYon:
Pointer
Inference
and
JIT
Spraying.
Dionysus
Blazakis.
Black
Hat
Federal,
2010.
h,p://www.semanYscope.com/research/BHDC2010/BHDC-‐2010-‐Paper.pdf
4. Defeat
Windows
7
Browser
Memory
ProtecYon.
XiaBo
Chen,
Jun
Xie.
XCon
2010.
5. Memory
Retrieval
VulnerabiliYes.
Derek
Soeder.
2006.
h,p://www.eeye.com/eEyeDigitalSecurity/media/ResearchPapers/eeyeMRV-‐Oct2006.pdf
6. Win32
ASLR
round
2.
JusYn
Ferguson,
March,
2010.
h,p://nietmenja.blogspot.com/2010/03/win32-‐aslr-‐round-‐2.html
7. A,acking
the
Vista
Heap.
Ben
Hawkes.
Nov,
2008.
h,p://www.lateralsecurity.com/downloads/hawkes_ruxcon-‐nov-‐2008.pdf
8. Understanding
the
Low
FragmentaYon
Heap.
Chris
Valasek.
July,
2010.
h,p://illmaYcs.com/Understanding_the_LFH_Slides.pdf.
9. Modern
Heap
ExploitaYon
using
the
Low
FragmentaYon
Heap.
Chris
Valasek.
2011.
10. Heap
Feng
Shui
in
JavaScript.
Alex
SoYrov.
2007.
h,p://www.phreedom.org/research/heap-‐feng-‐shui/heap-‐feng-‐shui.html
11. PrevenYng
the
exploitaYon
of
user
mode
heap
corrupYon
vulnerabiliYes.
Ma,
Miller.
2009.
h,p://blogs.technet.com/b/srd/archive/2009/08/04/prevenYng-‐the-‐exploitaYon-‐of-‐user-‐mode-‐heap-‐corrupYon-‐
vulnerabiliYes.aspx
12. Ghost
in
the
Windows
7
Allocator.
Steven
Seeley,
2012.
h,p://conference.hitb.org/hitbsecconf2012ams/materials/D2T2%20-‐%20Steven%20Seeley%20-‐%20Ghost%20In%20the
%20Windows%207%20Allocator.pdf
44
References
13. Kernel
Pool
ExploitaYon
on
Windows
7.
Tarjei
Mandt.
Black
Hat
DC,
2011.
h,ps://media.blackhat.com/bh-‐dc-‐11/Mandt/BlackHat_DC_2011_Mandt_kernelpool-‐wp.pdf.
14. 351
packets
from
trampoline.
Piotr
Bania.
October,
2009.
h,p://blog.piotrbania.com/2009/10/351-‐packets-‐from-‐trampoline.html.
15. SMEP:
What
is
it,
and
how
to
beat
it
on
Windows.
Mateusz
Jurczyk,
Gynvael
Coldwind.
June,
2011.
h,p://j00ru.vexillium.org/?p=783.
16. VEH.
Ben
Hawkes.
2011.
h,p://sota.gen.nz/veh/.
17. Windows
Kernel-‐mode
GS
Cookies
and
1
bit
of
entropy.
Mateusz
Jurczyk,
Gynvael
Coldwind.
January,
2011.
h,p://j00ru.vexillium.org/?p=690.
18. Reducing
the
effecYve
entropy
of
GS
cookies.
Skape.
May,
2007.
h,p://www.uninformed.org/?v=7&a=2&t=sumry.
19. Kernel
A,acks
through
User-‐Mode
Callbacks.
Tarjei
Mandt.
Black
Hat
USA,
2011.
h,p://mista.nu/research/mandt-‐win32k-‐slides.pdf.
20. Windows
8
Heap
Internals.
Chris
Valasek
and
Tarjei
Mandt.
Black
Hat
USA,
2012.
21. More
informaYon
on
MS11-‐087.
Chengyun
Chu,
Jonathan
Ness.
December,
2011.
h,p://blogs.technet.com/b/srd/archive/2011/12/13/more-‐informaYon-‐on-‐ms11-‐087.aspx.
22. Subtle
informaYon
disclosure
in
win32k.sys
syscall
return
values.
Mateusz
Jurczyk.
May,
2011.
h,p://j00ru.vexillium.org/?p=762.
45
References
26. On
the
effecYveness
of
DEP
and
ASLR.
Microso1.
December,
2010.
h,p://blogs.technet.com/b/srd/archive/2010/12/08/on-‐the-‐effecYveness-‐of-‐dep-‐and-‐aslr.aspx.
27. The
Exploit
Intelligence
Project
v2.
Dan
Guido.
December,
2011.
h,p://vimeo.com/31548167.
28. Microso1
Security
Intelligence
Report
(SIR):
Volume
12.
Microso1.
April,
2012.
h,p://www.microso1.com/en-‐us/download/details.aspx?id=29569.
29. Microso1
Security
Intelligence
Report
(SIR):
Volume
11.
Microso1.
October,
2011.
h,p://www.microso1.com/en-‐us/download/details.aspx?id=27605.
30. MiYgaYng
So1ware
VulnerabiliYes.
Microso1.
July,
2011.
h,p://www.microso1.com/en-‐us/download/details.aspx?id=26788.
31. Compiler
Security
Enhancements
in
Visual
Studio
11.
Tim
Burrell.
December,
2011.
h,p://blogs.msdn.com/b/sdl/archive/2011/12/02/security.aspx.
46