text
stringlengths
0
1.99k
...
QuartzCore`thread_fun(void*)+0x20
libsystem_pthread.dylib`_pthread_start+0x88
libsystem_pthread.dylib`thread_start+0x8
----------------------------------------
PID: 97690
Path:
/System/Library/Frameworks/VideoToolbox.framework/Versions/A/XPCServices/VTE
ncoderXPCService.xpc/Contents/MacOS/VTEncoderXPCService
Function: AppleAVE2UserClient::IO_Process(AppleAVE2UserClient*, void*,
IOExternalMethodArguments*)
--- Call Stack---
libsystem_kernel.dylib`mach_msg2_trap+0x8
IOKit`io_connect_method+0x208
IOKit`IOConnectCallMethod+0xec
IOKit`IOConnectCallStructMethod+0x38
AppleVideoEncoder`0x00000001033ee040+0x80
AppleVideoEncoder`0x0000000103330a70+0x128
...
libdispatch.dylib`_dispatch_worker_thread+0x10c
libsystem_pthread.dylib`_pthread_start+0x88
````````````````````````````````````````````````````````````````````````````
It displays a massive output with exact function names and the executables
that call them, which is real gold. Yet, DTrace shows us only the Kernel
Space, and we do not see what data is being sent in the
IOConnectCallMethod. So, there is one last step we need to do in User Space.
============================
--[ 2.2.3 - Driver Hooking in User Space
============================================================================
Using DTrace, we can obtain system-wide information on executables and
services they call. Now, we'll hook the user-space interfaces that
ultimately trigger kernel interactions. These are IOServiceOpen and
IOConnectCallMethod. It allows us to trace how processes open services and
invoke methods without modifying the kernel or tracing the kernel handlers.
We can use LLDB to monitor calls to IOServiceOpen and IOConnectCallMethod
to see which processes connect to which services using what types, selector
IDs, argument buffers, and their sizes.
The IOServiceOpen(), as the first argument, uses service: io_service_t. The
io_service_t is an alias of io_object_t, which is an alias of the
mach_port_t. So we deal here with a number. This number is, in fact,
io_registry_entry_t, which also comes down to mach_port_t. Like most
things, it is a mach port! The point is we can use IORegistryEntryGetName
on that mach port to get returns a C-string name assigned to a registry
entry. This string is the Driver Name (or, in other words, the name of the
instantiated service). It is a reverse lookup.
To achieve this manually on a breakpoint, we could set a breakpoint in LLDB:
````````````````````````````````````````````````````````````````````````````
breakpoint set --name IOServiceOpen
````````````````````````````````````````````````````````````````````````````
Then, on a breakpoint, hit extracts the service name like this:
````````````````````````````````````````````````````````````````````````````
expr -l c -o -- extern int IORegistryEntryGetName(void*, char*); char
name[128] = {0}; IORegistryEntryGetName((void *)$x0, name); name
````````````````````````````````````````````````````````````````````````````
To get the type, just read the x2 register:
````````````````````````````````````````````````````````````````````````````
reg read x2
````````````````````````````````````````````````````````````````````````````
I prepared the trace_ioserviceopen.py[36] script for that:
````````````````````````````````````````````````````````````````````````````
lldb -o "command script import trace_ioserviceopen.py" -o
"setup_ioserviceopen --pid 81203"
````````````````````````````````````````````````````````````````````````````
Example output on breakpoint hit (when a process calls IOServiceOpen)
````````````````````````````````````````````````````````````````````````````
PID: 81203
EXE PATH: /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder
SERVICE: AppleAPFSContainer
TYPE: 0
````````````````````````````````````````````````````````````````````````````
This way, we know what executable calls what service with a proper name and
the type of the user client spawned.
======
--[ 2.2.4 - Corpus
============================================================================
The last step is to monitor external method calls by inspecting
IOConnectCallMethod. By doing so, we can get exact information on what
selector is used (what exposed function we call) and the exact data sent
(which can be used for testing as the corpus for fuzzer). In LLDB, when we
set the breakpoint on the IOConnectCallMethod, we can see the arguments in
the x0-x9, so it is easy to extract each argument value.
I made an iokit_dump.py[37] for that:
````````````````````````````````````````````````````````````````````````````
command script import ~/.lldb/iokit_dump.py
breakpoint set -n IOConnectCallMethod
iokit_dump
kern_return_t IOConnectCallMethod