SlideShare a Scribd company logo
SUBVERTING	APPLE	GRAPHICS:	PRACTICAL	
APPROACHES	TO	REMOTELY	GAINING	ROOT
Liang	Chen	(@chenliang0817)
Qidan He	(@flanker_hqd)
Marco Grassi (@marcograss)
Yubin Fu	(@fuyubin1993)
About	us
• Tencent KEEN	Security	Lab (Previously	known	as	KeenTeam)
• 8	Pwn2Own	winners	in	3	years
• Mobile	Pwn2Own	2013	iOS,	Pwn2Own	2014	OS	X,	Pwn2Own	2014	Flash,	
Pwn2Own	2015	Flash,	Pwn2Own	2015	Adobe	Reader,	Pwn2Own	2016	Edge,	
Pwn2Own	2016	OS	X	*	2
• We	pwn OS	X	twice	in	Pwn2Own	2016	with	root	privilege	escalation
• KeenLab with	TencentPC	Manager	(Tencent Security	Team	Sniper)	
won	“Master	of	Pwn”	in	Pwn2Own	2016
Agenda
• Apple Graphics	Overview
• Userland Attack	Surface
• Kernel	Attack	Surface
Apple Graphics	Overview
Apple	graphics	architecture
Sandboxed	App WindowServer Service
User	land
Kernel	land
User	land	
Graphics
IGAccelSurface IGAccelGLContext IGAccelVideoContext…
IOAcceleratorFamily2
Nvidia Graphics	
Implementation
Intel	Graphics	
Implementation
Why	graphics?
• On	OS	X,	stored	in	
/System/Library/Frameworks/We-
bKit.framework/Versions/A/Resources/com.apple.
WebProcess.sb
• On	iOS,	binary	file	embed	in	kernel:
• Sandbox_toolkit:
https://github.com/sektioneins/sandbox_tool
kit
• What’s in sandbox profile:
• File opration
• IPC
• IOKit
• Sharedmem
• Etc.
Graphic	components	allowed	in Safari sandbox profile
• Userland:	
Com.apple.windowserver.active
• Apple Graphics usermode daemon
• Manage
window/shape/session/workspace, etc.
• Running as _windowserver context
Graphic	components	allowed	in Safari sandbox profile
• Kernel
• (iokit-connection	"IOAccelerator")
• iokit-connection	allows	the	sandboxed	
process	to	open	all	the	userclient
under	the	target	IOService(much	less	
restrictive	than	iokit-user-client-class	)
UserClient Name Type
IGAccelSurface 0
IGAccelGLContext 1
IGAccel2DContext	 2
IOAccelDisplayPipeUserClient
2	
4
IGAccelSharedUserClient 5
IGAccelDevice 6
IOAccelMemoryInfoUserClien
t
7
IGAccelCLContext 8
IGAccelCommandQueue 9
IGAccelVideoContext 0x100
Userland Attack	Surface
MIG overview
• Apple’s	IPC	implementation
mach_msg_header_t msg
• msg is	the	key	to	send	message	to	another	process
• Msgh_bits
• Simple	message	if	0x00xxxxxx
• Complex(descriptor)	message	if	0x8xxxxxxx
Simple message + 3 types of descriptor
• Simple message
• Easy to understand
• Port descriptor
• Send a port to the remote process
• Similar to DuplicateHandlein Windows(can be seen in Chrome sandbox)
• OOL descriptor
• Send a pointerto the remote process
• OOL Port descriptor
• Send a pointercontainingan array of ports to the remote process
WindowServer overview
• Two private framework:
• CoreGraphics
• QuartzCore
• Safari sandbox allows to open com.apple.windowserver.active service
• Implemented by CoreGraphics framework
• QuartzCore framework not allowed by Safari sandbox, but…
CoreGraphics API
• Client side API
• Starts with CGSxxxx
• Service side API
• Starts with __X
CoreGraphics API grouping
• Workspace
• Window
• Transitions
• Session
• Region
• Surface
• Notifications
• Hotkeys
• Display
• Cursor
• Connection
• CIFilter
• Event Tap
• Misc
Thinking as a hacker
• Before OS X Lion, no apple sandbox
• But there is WindowServer
• From OS X Lion, apple sandbox is introduced
• What we can do to WindowServer service with sandbox by easy
thinking?
• Move mouse position– Yes, by calling _XWarpCursorPosition
• Click – Yes, by calling event tap APIs like __XPostFilteredEventTapDataSync
• WindowServer will then call IOKit IOHIDFamily to handle the event
• Set hotkey – Yes, by calling _XSetHotKey
Bypass sandbox
• Move mouse + click == bypass sandbox
• Set hotkey == bypass sandbox
• After Apple sandbox is introduced, whole windowserver.active API is
allowed by safari, Apple might forget to enhance windowserver?
Reality
• You are wrong, Apple is not	that	bad
• Move mouse – Still allowed
• Click – checked, no way from sandbox
• SetHotKey – checked, no way from
sandbox
How about Window related API
• Why thinking about Window API
• Easy to cause UAF issues (in MS
Windows)
• Connection_holds_rights_on_window
check
• Only the window creator holds this
writer
• Some tricks to bypass this check in
history
• Many other API doesn’t have this
check, worthwhile for further
research (Fuzzing, code auditing)
Why windowserver?
• Running in root? No
• Running in user account? No
• It is running in _windowserver
• _windowserver is nothing, nothing, nothing
_windowserver 174			6.6		0.8		6910400		67708			??		Ss 三07下午
69:35.83	
/System/Library/Frameworks/ApplicationServices.framework/Framewo
rks/CoreGraphics.framework/Resources/WindowServer -daemon
But,	WindowServer is privilege	chameleon	!
CVE-2014-1314: Design issue
• Session related API
• _XCreateSession
• Create a new login session
• Fork a new process
• By default is
/System/Library/CoreServices/loginwindow.a
pp/Contents/MacOS/loginwindow
• But user can specify the customized login
path by sending a mach message
• The forked process will be setuid to the
current user’s context
• Wow, we bypassed sandbox and run a sub-
process under user’s context, outside
sandbox!
CVE-2014-1314: the fix
• Deny all	request from a sandboxed process to call _XCreateSession
• Effective, no way to bypass
• Sandbox_check everywhere,	makes	me	tired…It	is	obvious	that	Apple	realized	it	is	
dangerous	in	CoreGraphics
QuartzCore – The hidden interface
• What is QuartzCore?
• Also known as CoreAnimation
• More	complex	graphics	operation	
• Animation	
• Multi-layer handling
• But… Safari sandbox doesn’t allow open com.apple.CARenderServer
• Challenge? Sandbox doesn’t allow == we cannot open?
• If you think yes, you stop here
• If you think no and make it open, then you own a new territory.
• Chrome JS renderer cannot open any file, but in fact it can do operation in
cache folder, why?
• Duplicatea handle!
QuartzCore – The hidden interface
• Another way is: a port descriptor message!
• Yes, that is CGSCreateLayerContext
• It sends a mach_msg to WindowServer
• __XCreateLayerContext handles the request in
WindowServer
• Open a port of com.apple.CARenderServer
• Send a reply message with a port descriptor to
client
• Yay, we got the QuartzCore - Running at a
separate and new thread in WindowServer
Sandboxed process calls
CGSCreateLayerContext
WindowServer server creates
QuartzCore Client Port
Send the message back with port
descriptor
Sandboxed process obtains the Port
QuartzCore – a new territory
• No sandbox check
• Nothing…
• 3 minutes code auditing, I find something…
CVE-????-???? Logic issue
• In _XSetMessageFile
• Can specify arbitrary file path
• And append content to that file
• Content cannot be controlled
• No use?
Chameleon – Now I want you to be root!
CVE-2016-1804 :	UAF	in	multi-touch (Pwnie 2016	Nomination)
• Misc API	in	CoreGraphics:	
_XSetGlobalForceConfig
• Introduced	for	force	touch	purpose
• Newly	introduced	API	is	easier	to	
cause	problem
• In	_mthid_unserializeGestureConfiguration it	
called	CFRelease to	free	the	CFData
• After	that,	the	CFData is	freed	again
• Double	free
Exploitable?
• Problems	to	be	solved
• Fill	in	the	controllable	data	between	two	FREEs
• Especially	the	first	8	bytes	of	the	CFData
• Heap	spraying	in	64bit	process	/	info	leak
• First	8	bytes	pointing	to	the	user	controllable	data	(vtable like	object)
• ASLR
• ROP
Exploitation of CVE-2016-1804:	Fill	in	the	data
• Looks	like	hard
• Two	frees	too	close
• No	way	to	fill	in	between	the	two	frees	in	the	same	thread
• Race	condition?
• All	CoreGraphics server	API	runs	in	a	server	loop	at	a	single	thread	(Gated	and	
queued)
• What	happened	if	race	failed?	(Crash?	Of	course!	Of	course!	Are	you	sure)
• Give	up?	(Yes,	we	give	up	this	vulnerability	for	quite	some	days)
An	interesting	and	legacy	double	free	problem
• If this is the case
• Result is:
• time window too small,
crashed in case of race
failure
• If the case is like this
• No crash!
• First 8 bytes of CFData unchanged
• Windows LFH like
• Means we can try again and
again until successful
• CoreGraphics server APIs are all
processed in a single thread…
• Any other way
QuartzCore - The	hidden	interface
• Yes,	we	need	hidden	
interface’s	help	
• That	is,	QuartzCore
• QuartzCore server	
APIs	are	singled	
threaded	also	but	it	is	
a	separate	thread	
against	CoreGraphics
Thread1: CoreGraphics Thread2:QuartzCore
First Free
Double Free
Allocate memory
with same size
Fill
Next	question?	What	server	APIs	you	choose	to	fill	in	data
• APIs	must	meet	the	following	criteria:
• Create	some	structure	that	size	is	0x30	(same	as	CFData)
• Every	byte	of	the	0x30	structure	can	be	controlled	(Or	at	least	the	first	8	byte)
• What	kind	of	message	you	choose?
• Simple	message?	Of	course	not,	at	least	the	first	8	byte	cannot	be	controlled	
fully.
• Port	descriptor?	Of	course	not.
• OOL	descriptor?	Yes,	because	it	allows	specifying	a	pointer	to	a	buffer	and	
pass	to	the	remote	process.
Bad	news	once	more
• How	many	APIs	in	QuartzCore accepts	
OOL	descriptor?
• Only	one…
• That	is	_XRegisterClientOptions(It	accepts	3	
port	descriptor	followed	by		an	OOL	
descriptor)
What’s	in	_XRegisterClientOptions
• Accept	a	serialized	PropertyList
(Same	concept	as	List	vs	JSON)	
• What	is	CFPropertyList?
• Check	what	Apple	says
• Can	be	CFData,	CFString,	CFArray,	
CFDictionary,	CFDate,	CFBoolean,	
and	CFNumber
• Which	one	we	choose?
• Of	course	CFDictionary,	
because	this	API	only	accepts	
CFDictionary as	valid	data
• So	CFArray also	good
Again,	what	structure	to	fill	in
• First	thinking
• Use	CFDictionary and	put	many	CFData/CFString into	the	CFDictionary
(Because	you	can	control	content	of	CFData/CFString)
• Bad	news:	CFData not	good	because	itself	is	0x30	in	length,	the	first	8	bytes	
struct CFData itself	is	not	controllable,	but	only	its	content.	Reduce	the	
reliability	by	half
• Worse	news:	Only	CFMutableDataand	CFMutableStringhave	separate
controlledbuffer. Deserialized CFxxxx are not mutable, which the controlled
data is inlined…(Except for large data, but those are not good to fill in 0x30
data)
Our last hope
• Rely on CFPropertyListCreateWithData
• Cannot rely on CFData/CFString
• What if the CFPropertyListCreateWithData
creates some internal struct and free it
• Also useful?
• Ok, let’s focus on
CFPropertyListCreateWithData
implementation
• Wow, it is open sourced!
What is CFPropertyListCreateWithData
• Deserialization logic
• Parse serialized buffer data and
transform to basic CFxxxx structures
• A complicated implementationwith
recursive functions
• _CFPropertyListCreateWithData-
>__CFTryParseBinaryPlist ->	
__CFBinaryPlistCreateObjectFiltered
• CFBinaryPlistCreateObjectFiltered
• Token	parsing
Oh,	Unicode	saves	the	world	again!
• Case	kCFBinaryPlistMarkerUnicode16String
• A	temp	buffer	is	allocated	and	freed	after	
processing
Allocate	the	buffer,	size	
user	controlled
Copy	the	user	
controlled	data	to	the	
buffer
Free	the	buffer
Exploitation of CVE-2016-1804:Fill	in	the	data
• Wrap	up:
• Create	thread	1,	triggering	the	
vulnerability	again	and	again
• Create	thread	2,	send	a	request	to	
_XRegisterClientOptions
• With	a	CFDictionary/CFArrayfull of
controlled Unicode CFString
• CFStringCreateWithCharacters creates
Unicode16CFString
Exploitation of CVE-2016-1804:Fill	in	the	data
Exploitation of CVE-2016-1804:Heap	spray
• A	simple	test
• Run	it	3	times
• The	5th byte	is	random..
• It	means	you	need	256*4G	for	reliable	heap	spray
• Bad…
Exploitation of CVE-2016-1804:Heap	spray
• Another	test
• Run	it	3	times
• 5th byte	always	0x1
• Spraying	will	be	very	reliable
Exploitation of CVE-2016-1804:Heap	spray
• Strategy is different
• Need persistent in memory
• Need to allocate large block of memory (Memory is less randomized)
• Both CoreGraphics API and QuartzCore API are good candidate
• Something is same
• Need to pick up a OOL descriptor message
Exploitation of CVE-2016-1804:Heap	spray
• CGXSetConnectionProperty is a
good candidate
• Get the CFDictionary object from
global, if not exist then create
• Set the key/value pair according to
user’s input
• Can set the value many times by
sending multiple messages where
keys are different
Exploitation of CVE-2016-1804: ASLR / Code
execution
• ASLR is easy as it shares the same base address with Safari webkit
• Code execution:
• http://phrack.org/issues/66/4.html
• ROP
Exploitation of CVE-2016-1804: Root?
• Wait wait, we got only _windowserver context?
• Really? Nono
• We can setuid to current user as we get code
execution, just similar as CVE-2016-1314
• Why not setuid and setgid to 0? Crazy! Let‘s
try…
• Successful…
• Why?
• _windowserver is	process	euid,	uid is	still	root!
• Three bugs , three different privilege
obtained… So I call it Chameleon.
Demo
Kernel	Attack	Surface
The	IOAccelSurface Family
• IOAccelSurface family	plays	an	important	role	in	Apple's	Graphics	
Driver	System
• However	the	interface	was	originally	designed	for	WindowServer use	
solely	and	vulnerabilities	are	introduced	when	normal	processes	can	
call	into	this	interface
• CVE-2016-1815	– `Blitzard`	our	p2o	bug
Key	Functions
• Set_id_mode
• The	function	is	responsible	in	initialization	of	the	surface.	Bitwised presentation	type	
flags	are	specified,	buffers	are	allocated	and	framebuffers connected	with	this	
surface	are	reserved.	This	interface	must	be	called	prior	to	all	other	surface	
interfaces	to	ensure	this	surface	is	valid	to	be	worked	on.
• surface_control
• Basic	attributes	for	the	current	surface	are	specified	via	this	function,	i.e.	the	flushing	
rectangle	of	current	surface.
• surface_lock_options
• Specifies	lock	options	the	current	surface	which	are	required	for	following	
operations.	For	example,	a	surface	must	first	be	locked	before	it's	submitted	for	
rendering.
• surface_flush
• Exchange	backup	and	current	buffer.	Triple	buffering	is	enabled	for	certain	surfaces.
Basic	render	unit
• The	basic	representing	region	unit	in	IOAccelerator subsystem	is	a	8	
bytes	rectangle	structure	with	fields	specified	in	surface_control
function.
• int16	x;				
• int16	y;				
• int16	w;				
• int16	h;
Typical	Graphics	Pipeline
set_scale and	submit_swap
• The	surface’s	holding	drawing	region	can	be	scaled	and	combined	
with	the	original	rectangle	region	to	form	a	rectangle	pair,	rect_pair_t
• The	drawing	region	specified	in	surface_controlis	represented	in	
int16
• After	scaling	it’s	represented	as	IEEE.754	float.	
• Submit_swap submits	the	surface	for	rendering	purpose	and	it	will	
finally	calls	into	blit opertion.
Blit_param_t
• The	pair	and	blit_param_t from	submit_swap will	be	passed	to	
blit3d_submit_commands.
• The	two	most	interesting	fields	are	two	ints at	offset	0x14	and	0x34,	
which	is	the	current	and	target	(physical)	surface’s	width	and	height.
Blit3d_submit_commands	
• Different	incoming	surface	are	cropped	and	resized	and	merged	to	
match	the	display	coordinate	system	with	calculated	scaling	factor.	
• After	normalization	two	flushing	rectangles	are	submitted	to	GPU	via	
BlitRectList
Overflow	in	blit3d_submit_commands	
• The	OSX	graphics	coordinate	system	only	accepts	rectangles	in	range	
[0,0,0x4000,0x4000]	to	draw	on	the	physical	screen
• However	a	logical	surface	can	hold	rectangle	of	negative	coordinate	
and	length.
• represented	by	a	signed	16bit	integer,	translates	to	range	[-0x8000,	0x7fff].	
• The	blit function	needs	to	scale	the	logical	rectangle	to	fit	it	in	the	
specific	range.
blit3d_submit_commands	check	for	current	surface's	width	and	target	surface's	height.
If	either	of	them	is	larger	than	0x4000,	Huston	we	need	to	scale	the	rectangles	now.
• a	vector	array	is	allocated	with	size	height/0x4000	hoping	to	store	the	scaled	output	
valid	rectangles.	
• The	target	surface's	height	always	comes	from	a	full-screen	resource,	i.e.	the	
physical	screen	resolution.	Like	for	non-retina	Macbook Air,	the	height	will	be	900.	
• As	non	mac	has	a	resolution	of	larger	than	0x4000,	the	vector	array's	length	is	fixed	
to	1.
Rectangle	transformations	on	X	axis
I	believe	you	won’t	want	to	read	this…
• Decompiled	blit3d_submit_commands	function
Rewritten	as	IDA	hex-rays	cannot	properly	handle	SSE	floating	point
instructions
Rewritten	as	IDA	hex-rays	cannot	properly	handle	SSE	floating	point
instructions
OOB	leads	the	way
• The	code	implicitly	assumes	that	if	the	width	is	smaller	than	0x4000,	
the	incoming	surface's	height	will	also	be	smaller	than	0x4000,	which	
is	the	case	for	benign	client	like	WindowServer,	but	not	sure	for	funky	
clients.	
• By	supplying	a	surface	with	rect2.x	set	to	value	larger	than	0x4000,	
LINE1	will	perform	access	at	vector_array[1],	which	definitely	goes	
out-of-bound	with	function	IGVector::add	called	on	this	oob location,
Determine	the	surface	attributes
• By	supplying	size	(0x4141,	0x4141,	0xffff,	0xffff)	for	surface	and	
carefully	prepare	other	surface	options,	we	hit	the	above	code	path	
with	rectangle	(16705,	16705,	-1,	-1).	
• These	arguments	will	lead	to	out-of-bound	access	at	vec[1]
• After	preprocessing,	the	rectangle	is	transformed	to	y	16705,	x	321,	
height	-1,	len -1,	triggering	one	oob write
• Then	bail	out	in	while	condition	in	next	loop
Revisit	the	IGVector
• struct IGVector{			
• int64	currentSize;				
• int64	capacity;				
• void*	storage;
• }
• The	vulnerable	allocation	of	blit3d_submit_commands	allocation	falls	
at	kalloc.48,	which	is	crucial	for	our	next	Heap	Feng	Shui.
Us 16-subverting apple-graphics_practical_approaches_to_remotely_gaining_root_chen_he_grassi_fu
Heap	Fengshui in	kalloc.48
• kalloc.48	is	a	zone	used	frequently	in	Kernel	with	IOMachPort acting	
as	the	most	commonly	seen	object	in	this	zone	and	we	must	get	rid	of	
it
• Previous	work	mainly	comes	up	with	openServiceExtended and	
vm_map_copy to	prepare	the	kernel	heap.
• However	these	are	not	suitable	for	our	exploitation
Heap	Fengshui in	kalloc.48	(cont.)
• ool_msg spray	has	small	heap	side-effect	
• but	vm_map_copy’s head	0x18	bytes	is	not	controllable	while	we	need	
control	of	8	bytes	at	the	head	0x8	position
• io_open_service_extended has	massive	side	effect	in	kalloc.48	zone	
by	producing	an	IOMachPort in	every	opened	spraying	connection		
• io_open_service_extended has	the	limitation	of	spraying	at	most	37	
items,	constrained	by	the	maximum	properties	count	per	
IOServiceConnection can	hold
• The	more	items	we	can	fill,	the	less	side	effect	we	will	need	to	consider
IOCatalogueSendData
• The	addDrivers functions	accepts	an	OSArray with	the	following	easy-
to-meet	conditions:
• OSArray contains	an	OSDict
• OSDict has	key	IOProviderClass
• incoming	OSDict must	not	be	exactly	same	as	any	other	pre-exists	OSDict in	
Catalogue
IOCatalogueSendData (cont.)
• prepare	our	sprayed	content	in	the	array	part	as	the	XML	shows,	and	
slightly	changes	one	char	at	end	of	per	spray	to	satisfy	condition	3
• We	only	need	control	of	+8-+16	bytes	region
Final	spray	routine	in	kalloc.48
• Spray	0x8000	combination	of	1	vm_map_copy and	50	
IOCatalogueSendData content	of	which	totally	controllable	(both	of	
size	0x30),	pushing	allocations	to	continuous	stable	region
• free	vm_map_copys at	1/3	to	2/3	part,	leaving	holes	in	allocation
• trigger	vulnerable	function,	vulnerable	allocation	will	fall	in	hole	we	
previously	left
Us 16-subverting apple-graphics_practical_approaches_to_remotely_gaining_root_chen_he_grassi_fu
In	a	nearly	100%	chance	the	heap	will	layout	as	this	figure	illustrated,	which	exactly	match	what	we	expected.	
Spraying	50	or	more	0x30	sized	controllable	content	in	one	roll	can	reduce	the	possibility	of	some	other	irrelevant	
0x30	content	such	as	IOMachPort to	accidentally	be	just	placed	after	free	block	occupied	in.
KALLOC.8192 ZONE
vm_map_copy header
+0x1140
niddle(filled 0x41414141) filled with 0x41414141
+0x1288
IGAccelVideoCont
ext
IGAccelVideoCont
ext
vm_map_copy vm_map_copy…
0xff… 62388000
0xff… bf800000
IntelAccelerator …
+0x1528
vm_map_copy …
0xff… bf801000
0xff… 62389000
+0x528
+0x288
0xff… bf800000
vm_map_copy
0xff… bf7ff000
+0x140
0xff… 6238a000
Exploitation:	now	what?
• We	have	an	arbitrary-write-where	but	our	value	written	is	
constrained.
• For	example	we	can	use	this	4	byte	overwrite	with	value	“0xbf800000”	
to	do	a	partial	overwrite	of	the	less	significant	4	bytes	of	the	“service”	
pointer	of	a	IOUserClient.
• This	new	overwritten	pointer	will	be	“0xffffff80bf800000”.
• We	control	this	heap	location	at	”0xffffff80bf800000”!
A0	00	AD	DE	80	FF	FF	FF 00	00	80	BF	80	FF	FF	FF
BEFORE	OOB	WRITE AFTER	OOB	WRITE
Exploitation:	kASLR bypass	turning	this	into	a	
infoleak
• On	OS	X	the	kernel	is	randomized,	we	need	to	bypass	kASLR.
• Our	target	IOUserclient is	of	type	IGAccelVideoContext
• We	overwrite	the	“accelerator”	field	of	this	userclient (offset	0x528),	
like	explained	in	the	previous	slide	pointing	it	to	our	controlled	
location
• We	then	abuse	the	external	method	
IGAccelVideoContext::get_hw_steppings to	leak	1	byte	to	userspace,	
to	read	a	vtable 1	byte	at	a	time.
• With	the	vtable address	we	follow	it	to	read	a	TEXT	address	
(OSObject::release)	to	finally	get	the	kASLR slide,	bypassing	it.
Exploitation:	kASLR bypass	turning	this	into	a	
infoleak (2)
IGAccelVideoContext::get_hw_steppings( __int64
this, _DWORD *a2) {
…
__int64 accelerator = *(this + 0x528); //
accelerator is 0xffffff80bf800000
...
a2[3] = *(unsigned __int8 *)(*(_QWORD
*)(accelerator + 0x1230) + D0); // this is
returned to userspace!
…
}
Exploitation:	1	byte	infoleak	
memory	layout
Exploitation:	rebasing	and	ROP	Chain
• Now	with	the	kASLR slide	we	can	dynamically	rebase	our	ROP	Chain	
that	we	use	for	kernel	code	execution.
• At	the	end	of	the	ROP	chain	we	will	abuse	kern_return_t
KUNCExecute(char executionPath[1024], int uid,
int gid) to	spawn	a	arbitrary	executable	as	root	in	userspace,	
bypassing	all	the	mitigations	(SMEP/SMAP,	SIP)
• Spawn	a	root	OS	X	Calculator	for	teh lulz!	Microsoft	Windows	
calculators	sucks	:D
Exploitation:	gaining	RIP	control
• The	last	missing	piece	of	the	puzzle	is	to	get	RIP	control	and	execute	
our	ROP	payload	in	kernel	and	gain	kernel	codexec
• We	will	again	abuse	a	IGAccelVideoContext and	his	superclass	
IOAccelContext2.
• If	you	recall	from	the	previous	slides,	we	corrupted	a	pointer	at	offset	
0x528	to	point	to	our	controlled	location.
• We	choose	then	to	target	another	method,	named	“context_finish”,	
which	will	make	a	virtual	function	call	that	we	can	totally	control.
• RIP	Control	is	achieved	and	we	start	execute
Exploitation:	gaining	RIP	control	(2)
IOAccelContext2::context_finish
push rbp
mov rbp, rsp
…
mov rbx, rdi //this
mov rax, [rbx+528h] // rax is a location with
controlled content
…
call qword ptr [rax+180h] // RIP control
…
Exploitation
You	can	check	more	details	of	the	exploitation	in	our	WhitePaper
Unfortunately	here	we	have	time	and	space	constraints
But	now..	A	COOL	DEMO	J!
An	interesting	fact	is	that	you	cannot	pop	a	root	Calc by	sudoJ
If	you	see	a	root	Calc on	your	system,	u’re doomed	by	kernel	exploit	L
Demo
Acknowledgements
• Wushi
• Windknown
• Luca	Todesco
• Ufotalent
Thank you!

More Related Content

PDF
Recon2016 shooting the_osx_el_capitan_kernel_like_a_sniper_chen_he
PDF
Rainbow Over the Windows: More Colors Than You Could Expect
PPTX
Security research over Windows #defcon china
PPTX
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
PPTX
Memory Corruption: from sandbox to SMM
PDF
Csw2016 macaulay eh_trace-rop_hooks
PDF
50 Shades of Fuzzing by Peter Hlavaty & Marco Grassi
Recon2016 shooting the_osx_el_capitan_kernel_like_a_sniper_chen_he
Rainbow Over the Windows: More Colors Than You Could Expect
Security research over Windows #defcon china
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Memory Corruption: from sandbox to SMM
Csw2016 macaulay eh_trace-rop_hooks
50 Shades of Fuzzing by Peter Hlavaty & Marco Grassi

What's hot (20)

PDF
When is something overflowing
PDF
DeathNote of Microsoft Windows Kernel
PPTX
Power of linked list
PPTX
Attack on the Core
PDF
Integrating web archiving in preservation workflows. Louise Fauduet, Clément ...
PPTX
Racing with Droids
PDF
Bypassing patchguard on Windows 8.1 and Windows 10
PDF
Exploitation and State Machines
PDF
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
PDF
Csw2016 chen grassi-he-apple_graphics_is_compromised
PDF
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
PPTX
Injection on Steroids: Codeless code injection and 0-day techniques
PPTX
Shall we play a game?
PPTX
Hacking - high school intro
PPTX
Изучаем миллиард состояний программы на уровне профи. Как разработать быстрый...
PPTX
Steelcon 2014 - Process Injection with Python
PDF
Csw2016 d antoine_automatic_exploitgeneration
PPTX
Back to the CORE
PPTX
How Safe is your Link ?
PPTX
Practical Windows Kernel Exploitation
When is something overflowing
DeathNote of Microsoft Windows Kernel
Power of linked list
Attack on the Core
Integrating web archiving in preservation workflows. Louise Fauduet, Clément ...
Racing with Droids
Bypassing patchguard on Windows 8.1 and Windows 10
Exploitation and State Machines
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
Csw2016 chen grassi-he-apple_graphics_is_compromised
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
Injection on Steroids: Codeless code injection and 0-day techniques
Shall we play a game?
Hacking - high school intro
Изучаем миллиард состояний программы на уровне профи. Как разработать быстрый...
Steelcon 2014 - Process Injection with Python
Csw2016 d antoine_automatic_exploitgeneration
Back to the CORE
How Safe is your Link ?
Practical Windows Kernel Exploitation
Ad

Viewers also liked (13)

PPT
Client Side Exploits using PDF
PDF
Software Requirement Spesification
PPTX
Hacking and securing ios applications
PDF
NCC Group 44Con Workshop: How to assess and secure ios apps
PDF
Fluorochemical Solutions for the Automotive Industry
PDF
10 influencer marketing facts
PPTX
The Travelling Pentester: Diaries of the Shortest Path to Compromise
PPTX
Comunidades virtuales
PDF
Estrategias efectivas de diseño para tus Campañas de Email Marketing - Promoc...
PPTX
Docker for azure tri aug - feb 2017
PPTX
EKFiddle: a framework to study Exploit Kits
PPTX
Watch out, it's behind you: publishers' tactics and the challenge they pose f...
PPT
Comprehensive in cerebral palsy
Client Side Exploits using PDF
Software Requirement Spesification
Hacking and securing ios applications
NCC Group 44Con Workshop: How to assess and secure ios apps
Fluorochemical Solutions for the Automotive Industry
10 influencer marketing facts
The Travelling Pentester: Diaries of the Shortest Path to Compromise
Comunidades virtuales
Estrategias efectivas de diseño para tus Campañas de Email Marketing - Promoc...
Docker for azure tri aug - feb 2017
EKFiddle: a framework to study Exploit Kits
Watch out, it's behind you: publishers' tactics and the challenge they pose f...
Comprehensive in cerebral palsy
Ad

Similar to Us 16-subverting apple-graphics_practical_approaches_to_remotely_gaining_root_chen_he_grassi_fu (20)

PDF
Cansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_Compromised
PDF
2a Analyzing iOS Apps Part 1
PDF
CNIT 128 2. Analyzing iOS Applications (Part 1)
PPTX
Pentesting iOS Applications
PDF
Practical iOS App Security
PPTX
Beyond the 'cript practical i os reverse engineering lascon
PDF
YOW! Connected 2014 - Developing Secure iOS Applications
PPTX
Apple Presentation.pptx
PDF
Hacking and Securing iOS Apps : Part 1
PDF
ASFWS 2012 - Audit d’applications iOS par Julien Bachmann
PPTX
iOS application (in)security
PDF
Poc2015 os x_kernel_is_as_strong_as_its_weakest_part_liang_shuaitian
PDF
Yow connected developing secure i os applications
PDF
Escaping the Mac App Store Sandbox (or at least a small part of it)
PDF
iOS malware: what's the risk and how to reduce it
PDF
Breaking Secure Mobile Applications - Hack In The Box 2014 KL
PDF
AusCERT - Developing Secure iOS Applications
PPTX
Summer of Fuzz: macOS
PDF
OWASP Melbourne - Introduction to iOS Application Penetration Testing
PPTX
Hacking and Securing iOS Applications by Satish Bomisstty
Cansecwest_16_Dont_Trust_Your_Eye_Apple_Graphics_Is_Compromised
2a Analyzing iOS Apps Part 1
CNIT 128 2. Analyzing iOS Applications (Part 1)
Pentesting iOS Applications
Practical iOS App Security
Beyond the 'cript practical i os reverse engineering lascon
YOW! Connected 2014 - Developing Secure iOS Applications
Apple Presentation.pptx
Hacking and Securing iOS Apps : Part 1
ASFWS 2012 - Audit d’applications iOS par Julien Bachmann
iOS application (in)security
Poc2015 os x_kernel_is_as_strong_as_its_weakest_part_liang_shuaitian
Yow connected developing secure i os applications
Escaping the Mac App Store Sandbox (or at least a small part of it)
iOS malware: what's the risk and how to reduce it
Breaking Secure Mobile Applications - Hack In The Box 2014 KL
AusCERT - Developing Secure iOS Applications
Summer of Fuzz: macOS
OWASP Melbourne - Introduction to iOS Application Penetration Testing
Hacking and Securing iOS Applications by Satish Bomisstty

Recently uploaded (20)

PPTX
Internet___Basics___Styled_ presentation
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
The Internet -By the Numbers, Sri Lanka Edition
PPTX
Funds Management Learning Material for Beg
DOCX
Unit-3 cyber security network security of internet system
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
innovation process that make everything different.pptx
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
Internet___Basics___Styled_ presentation
Introuction about WHO-FIC in ICD-10.pptx
SAP Ariba Sourcing PPT for learning material
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
WebRTC in SignalWire - troubleshooting media negotiation
The Internet -By the Numbers, Sri Lanka Edition
Funds Management Learning Material for Beg
Unit-3 cyber security network security of internet system
An introduction to the IFRS (ISSB) Stndards.pdf
innovation process that make everything different.pptx
Slides PPTX World Game (s) Eco Economic Epochs.pptx
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Design_with_Watersergyerge45hrbgre4top (1).ppt
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Module 1 - Cyber Law and Ethics 101.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx
522797556-Unit-2-Temperature-measurement-1-1.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf
Unit-1 introduction to cyber security discuss about how to secure a system

Us 16-subverting apple-graphics_practical_approaches_to_remotely_gaining_root_chen_he_grassi_fu