text
stringlengths
0
1.99k
size_t inputStructCnt, // Size of inputStruct buffer
uint64_t *output, // Scalar output values array
uint32_t *outputCnt, // Max/actual elements in output
void *outputStruct, // Structured output data buffer
size_t *outputStructCnt // Max/actual size of outputStruct
);
````````````````````````````````````````````````````````````````````````````
Invalid sizes for inputCnt, inputStructCnt, outputCnt, or outputStructCnt
will cause verification failure and dropped calls. Only with valid sizes
are input and inputStruct values passed to the target function. Without
knowing these values, testing is impossible. Automation is impractical due
to (2^32-1)^4 = ~3.4*10^38 possibilities, and identical error codes make
brute force ineffective. Manual analysis is required. Valid sizes are found
in dispatch tables, which appear complex in disassemblers:
````````````````````````````````````````````````````````````````````````````
__const:FFFFFE0007F57BC8 DCQ
__ZN18H11ANEInUserClient23_ANE_ProgramSendRequestE...
;
H11ANEInUserClient::_ANE_ProgramSendRequest(...)
__const:FFFFFE0007F57BD0 DCB 1 ; inputCnt
__const:FFFFFE0007F57BD1 DCB 0
__const:FFFFFE0007F57BD2 DCB 0
__const:FFFFFE0007F57BD3 DCB 0
__const:FFFFFE0007F57BD4 DCB 0x48 ; inputStructCnt (72 bytes)
__const:FFFFFE0007F57BD5 DCB 9
__const:FFFFFE0007F57BD6 DCB 0
__const:FFFFFE0007F57BD7 DCB 0
__const:FFFFFE0007F57BD8 DCB 0 ; outputCnt
__const:FFFFFE0007F57BD9 DCB 0
__const:FFFFFE0007F57BDA DCB 0
__const:FFFFFE0007F57BDB DCB 0
__const:FFFFFE0007F57BDC DCB 0x28 ; outputStructCnt (40 bytes)
__const:FFFFFE0007F57BDD DCB 0
...
````````````````````````````````````````````````````````````````````````````
To make it easier, I created this IDA script[32] that prints valid pointers
for the exposed methods, their selectors, and valid sizes:
````````````````````````````````````````````````````````````````````````````
print_methods(0xfffffe0007f57b78, 50)
Method summary (ID: [SCALAR_IN, IN_SIZE, SCALAR_OUT, OUT_SIZE]):
0: [0, 96, 0, 96]
1: [0, 0, 0, 0]
2: [1, 2376, 0, 40]
3: [0, 3480, 0, 0]
4: [0, 56, 0, 56]
...
49: [2, 0, 0, 0]
````````````````````````````````````````````````````````````````````````````
This way, we mapped everything we needed to reach the logic of the exposed
functions. At this point, our map is complete, and we can start dumb
fuzzing with random data in inputStruct. However, to be more efficient, we
should find valid data sent to these exposed methods and store it as our
corpus. For that, we need to do some runtime analysis.
===================
--[ 2.2 - Runtime Enumeration
============================================================================
In the previous section, we covered how to map drivers using static
analysis. Now, let's look at a few runtime techniques to enumerate all
instantiated IOKit services and gather useful data for calling methods via
IOConnectCallMethod. This section may seem short, but don't underestimate
its value. These runtime tricks have saved me countless hours during
research. They also make a huge difference in the accuracy and coverage of
my fuzzer. I recommend completing Section "2.1 KEXT Analysis" before using
runtime tools. While these tools can help verify service names, we still
need to reverse-engineer the User Client logic regardless of the method
used. Performing static analysis first ensures that we do not rely solely
on partial runtime results, which may overlook unregistered services!
============================
--[ 2.2.1 - Service Discovery Automation
============================================================================
The main tool used here is Siguza's ioscan[33]. It enumerates all
currently instantiated IOKit services, showing their class names, instance
names, associated UserClient class (if specified in properties), and
whether the UserClient can be successfully opened from user space.
Below is an example output:
````````````````````````````````````````````````````````````````````````````
Class                     Name            UC          Spawn
------------------------ --------------- -------------- --------------------
IORegistryEntry          Root            -              invalid argument
IOPlatformExpertDevice   J314cAP         -              invalid argument
IODTNVRAM                options         -              unsupported function
IODTNVRAMDiags           IODTNVRAMDiags  -              unsupported function
IODTNVRAMVariables       options-system  -              unsupported function
IODTNVRAMVariables       options-common  -              unsupported function
AppleARMPE               AppleARMPE      -              unsupported function
IOPMrootDomain           IOPMrootDomain  RootDomainUserClient    successful
IORootParent             IORootParent    -              unsupported function
IOUSBHostInterface       HID I2C         AppleUSBHostFWIntfClt   successful
````````````````````````````````````````````````````````````````````````````
Most importantly, the "Name" column displays instantiated services. After
reading this paper, you know it is not so trivial to get them. By using
this tool, we can list them all. However, another problem arises here: we
have the names, but how do we assign them to a valid User Client logic?
To illustrate this, there is the AppleUSBHostFrameworkInterfaceClient,
which is assigned to the names IOUSBHostInterface, HID I2C, and