csw2017 peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

54
Win32k Dark Composition Attacking the Shadow Part of Graphic Subsystem @360Vulcan Team Peng Qiu (@pgboy) SheFang Zhong (@zhong_sf)

Upload: cansecwest

Post on 21-Mar-2017

1.000 views

Category:

Internet


5 download

TRANSCRIPT

Page 1: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Win32k Dark Composition

Attacking the Shadow Part of Graphic Subsystem

@360Vulcan Team

PengQiu(@pgboy)

SheFangZhong(@zhong_sf)

Page 2: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

About US

Member of 360 vulcan team.

Windows kernel security researcher

Pwn2Own winners 2016 .pwned Chrome pwn2own 2016

.pwned Flash pwn2own 2016

Pwnfest winners 2016 .pwned Edge PwnFest 2016

.pwned Flash PwnFest 2016

Pwn2Own winners 2015 .pwned IE pwn2own 2015

Page 3: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Page 4: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Agdenda

Direct Composition Overview

0day & Exploitation

Fuzzing

Mitigation & Bypass

Page 5: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

•  High-performance bitmap composition with transforms, effects and animations graphic engine

•  Introduced from windows 8.

•  Working based on dwm(desktop windows manager).

Direct Composition Overview

Page 6: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Direction Composition Architecture

dwmcore dcomp ...userland

kernel

DirectComposiAonCApplicaAonChannel

visual

CExpressionMarshaler CFilterEffectMarshaler CScaleTransformMarshaler...

submit

DWM (desktop windows manager)

DXGK (directX graphic kernel)

call

Page 7: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Significant Change since win10 RS1

•  kernelimplementchanged

•  InterfacechangedRemovelotsofinterface.10+?

LotsoffuncAonhasbeenrewrite,notfixvuln

Addsomeinterface.eg:

Page 8: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Beforewin10RS1Existindependentlyandsomeinthewin32kfiltertable

Sincewin10RS1

all included in

Thisfunc1onisoutofWin32kfilterlist�

Page 9: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 10: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Why attack DirectComposition

•  ReachableinAppContainerandoutofwin32kfilter

•  Thispartimplementwithc++inkernel

•  Introducedfromwindows8,everbeenfocusbyanotherresearchers,!!!asfarasweknow!!!

Page 11: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Important functions

Page 12: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Channel Object

•  knowasDeviceObjectinuserinterface

•  ownerofresource,usetocreateresource

•  pArgSec(onBaseMapInProcessreturnabatchbufferweneedlater

Page 13: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Resource Object

•  knowasvisualinuserinterface�

•  similartowin32ksurface•  Ithasalotsoftypes.

CScaleTransformMarshaler CTranslateTransformMarshaler

CRectangleClipMarshaler CBaseClipMarshaler

CSharedSecAonMarshaler CMatrixTransformMarshaler

CMatrixTransform3DMarshaler CShadowEffectMarshaler

. . .

Page 14: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Batch Buffer

•  Associatewithachannel •  ReturnedfromNtDComposiAonCreateChannel•  NtDComposiAonProcessChannelBatchBufferparseit

•  ThisfuncAonsupportalotofcommands

Page 15: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 16: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

How to fuzz

Page 17: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Bydefaultis1,weincreasethosefuncAon’sprobabilityto100. �

Page 18: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 19: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

•  Theyneedachannelwegivethemone.•  Theyneedaresourcewegivethemone.•  Ifwedonotknownwhattheywant,givethemarandom

one.

Page 20: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

0day & Exploition

Page 21: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Resource Double free (CVE-2017-XXXX)

Page 22: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Root Cause

Free the resource(visual)'s property buffer forget to clear resource->Databuffer. result in free again when resource is free

First time free

Page 23: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 24: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Second time free

Page 25: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Exploition

Res1 First time free ResY

Free this one

Res2 Res3 Res4 …

Res1 palette

Occupy with palette

Res2 Res3 Res4 …

Res1 palette

Free palette

Res2 Res3 Res4 … Second time free

Res1 ResX

Occupy with ResX

Res2 Res3 Res4 …

Page 26: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Modify the palette->pEntries to what you want when occupy palette with a ResourceBuffer

palette pEntries

ResX->DataBuf

xxxxx

occupy second time

Content Replace

palette

pEntries

bitmap

pScan0

Usually, cover palette1->pEntries to a bitmap address

Page 27: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Read&Writeprimity

Replaceprocesstoken,exploited

Page 28: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Fix BSOD •  We finished privilege escalation, but BSOD when process exit

•  There still has double either Palette or ResX's DataBuffer, because they share the same kernel buffer

•  Double free happened in clear process handle table when process exit

•  Close palette handle first, Resource handle next

•  So? must clear ResX->DataBuffer or remove ResX handle from handle table before process exit

Page 29: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Clear ResX->DataBuffer

•  It's a binary tree struct, search the binary tree to find the channel that Resource belongs to.

•  Channel handle table locate in: _EPROCESS->Win32Process->GenericTable

GenericTable

channel1

channel2 channel3

channel4 channel5

1. Locate ResX address

2. Locate channel address

Resource address store in channel's resource table

Page 30: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Resource table in channel implement as a array

void*ptrNull=0;AddressWrite(&ResX->DataBuffer,sizeof(void*),&ptrNull);

Clear

Page 31: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 32: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

BagMarshaler Integer overflow (CVE-2016-XXXX)

Page 33: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Root cause Integer overflow while dataOffset < DataSize-0xc if DataSize < 0xc

If(dwOffet<(DWORD)(0x1-0xc)){

if(DataBuffer[dwOffset]==0x66){

DataBuffer[dwOffset+0xc]=xxxx;}} �

•  By default,this->Databuffer==NULL && this->DataSize==0

•  Write anywhere in x86 system.

•  Not so easy in x64 system. 1.this->Databuffer must not NULL 2.this->DataSize < 0xC && this->DataSize!=0 3.*(this->Databuffer + inbuf->offset)==(0x45 or 0x66)

Exploitation:

Page 34: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

1.this->Databuffer must not NULL wecouldcallCPropertyBagMarshaler::SetBufferProperty(...)withproperty==2toallocabuffer,thenstoreinthis->DataBuffer

Page 35: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

*(this->DataBuffer+inbuf->offset)==(0x45 or 0x66)

SpraylotsofbufferXtoenablethatbufferXbehindthis->DataBuffer

DataBuffer bufferX...

Calcinbuf->offsetvalue,itmustbesaAsfy:

bufferX

•  (Databuffer+offset)locateinbufferX,(bufferX->Filed1)

•  bufferX->Flied1mustbemodifyablefromusermod,setitto(0x45or0x66)

•  (Databuffer+offset+0xc)locateinbufferX,anditmustbeexploitable.

DataBuffer

bufferX

...

Offset

0xc

Flied1 Flied2

Page 36: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Fortunately,wefoundbitmapsaAsfythiscaseperfectly

DataBuffer

bitmap

...

Offset

0xc

Height pScan0

Now,bitmap->pScan0hasbennchangedtothevalueweset.sowegotRead/Writeprimary1.GetBitmapbits(....)2.SetBitmapbits(....)

Replacepstoken,exploited!

Page 37: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Complier Warning?

WARNING!!�

Page 38: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 39: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Mitigation & bypass

Page 40: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Read/Write ability object

Page 41: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

1. tagWND abuse Write what? tagWND.strName ? (UNICODE_STRING)

GetWindowText ? NtUserDefSetText ?

Unfortunately, the destination address has been modify when write to, just desktop heap range is legal.

Page 42: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Maybe

2014

Pwn2Own:KeenTeam used once. HackingTeam leaked 0day. Someone write it to a public paper

2015.3

Pwn2Own: We used Twice. Pwn2Own: KeenTeam used Once.

2016.3

2016.8

2.BITMAP ABUSED

2016.10 We use Acclerator Object To Guess Bitmap Object Address. Then We used Twice again in PwnFast. Coresecurity guys release a paper to talk about is.

Page 43: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

Page 44: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 45: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 46: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

14393VS15xxx: �

Page 47: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 48: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 49: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

A New way

Page 50: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 51: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

ButOnlyTheObjectwhichAllocateatdesktopheap:1.  Window2.  Menu3.  InputContext4.  CallProc

limitation

ButItisenough,Ibelieveyouguyscouldfindsomethinguseful!!�

Page 52: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 53: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
Page 54: CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark

We are just on the way. Thank you.