text stringlengths 0 1.99k |
|---|
Thus, not only does the selected service name determine which newUserClient |
logic is triggered, but the type parameter allows additional branching |
within that logic. It is commonly used to expose limited or privileged |
functionality through different user-client implementations. |
Automating type enumeration through dynamic analysis is often impossible, |
as the logic is frequently structured to return the same kernel code for |
both valid and invalid types. To ensure we map all possible types, we must |
reverse these NewUserClients and verify them by hand. |
================ |
--[ 2.1.5 - External Methods |
============================================================================ |
For each previously identified IOUserClient subclass, we can extract |
user-accessible methods by locating either externalMethod or |
getTargetAndMethodForIndex. These functions define how the driver |
dispatches incoming method calls from user space. To locate them, I use IDA |
and search for symbol names like H11ANEInDirectPathClient::externalMethod. |
It can also be done in the terminal: |
```````````````````````````````````````````````````````````````````````````` |
ipsw macho info --symbols KEXT_NAME | grep |
"externalMethod\|getTargetAndMethodForIndex" |
```````````````````````````````````````````````````````````````````````````` |
Based on the previous example, this would yield: |
```````````````````````````````````````````````````````````````````````````` |
0xfffffe0009a796c0: H11ANEInUserClient::externalMethod(unsigned int, |
IOExternalMethodArgumentsOpaque*) |
0xfffffe0009a788a0: H11ANEInDirectPathClient::externalMethod(unsigned int, |
IOExternalMethodArgumentsOpaque*) |
```````````````````````````````````````````````````````````````````````````` |
As discussed in Part 1, there are several common dispatch patterns, but |
ultimately, most of them rely on a method array and a fixed number of |
entries. In our case, the decompiled dispatcher looks like this: |
```````````````````````````````````````````````````````````````````````````` |
IOReturn H11ANEInUserClient::externalMethod( |
uint32_t selector, |
IOExternalMethodArguments *args) |
{ |
return IOUserClient2022::dispatchExternalMethod( |
selector, |
args, |
&H11ANEInUserClient::sMethods, |
0x32, // Number of supported methods |
this, |
nullptr |
); |
} |
```````````````````````````````````````````````````````````````````````````` |
We're specifically interested in H11ANEInUserClient::sMethods, which is the |
method dispatch table. The symbol name for this array may vary, so manual |
inspection is required. If you know the symbol name, you can locate it with: |
```````````````````````````````````````````````````````````````````````````` |
ipsw macho info --symbols KEXT_NAME | grep "sMethods" |
0xfffffe0007f57b78: __ZN18H11ANEInUserClient8sMethodsE |
0xfffffe0007f57a10: __ZN24H11ANEInDirectPathClient8sMethodsE |
```````````````````````````````````````````````````````````````````````````` |
This tells us the dispatch table for H11ANEInUserClient is at |
0xfffffe0007f57b78, and it contains 0x32 method entries. To parse the table |
correctly, we must know the size of each entry, which depends on the |
dispatcher used. After reversing all macOS drivers I found these possible |
dispatchers and sizes: |
```````````````````````````````````````````````````````````````````````````` |
IOExternalMethodDispatch2022 == 0x28 |
IOExternalMethodDispatch == 0x18 |
getTargetAndMethodForIndex == 0x30 |
Custom == ??? |
```````````````````````````````````````````````````````````````````````````` |
Note that some custom implementations require manual handling. With this |
information, we can iterate over the array and identify each method. In |
IDA, double-clicking works. In other tools, manually add the entry size to |
the base address: |
```````````````````````````````````````````````````````````````````````````` |
Method 0 == 0xfffffe0007f57b78 + 0x28 |
Method 1 == 0xfffffe0007f57b78 + (0x28 * 2) |
... |
Method 49 == 0xfffffe0007f57b78 + (0x28 * 0x31) |
```````````````````````````````````````````````````````````````````````````` |
By doing this, we can find the addresses of all functions exposed to user |
space for IOConnectCallMethod(), as well as the selectors to use for |
calling them. The final question is, what arguments do they expect? |
========= |
--[ 2.1.6 - Arguments |
============================================================================ |
Even with the correct driver name, service matching, user client type, |
and external method selector, calls can still fail due to argument size |
validation. Most functions validate sizes to prevent buffer overflows |
(though some historically lacked this protection). IOConnectCallMethod() |
expects these arguments: |
```````````````````````````````````````````````````````````````````````````` |
kern_return_t IOConnectCallMethod( |
mach_port_t connection, // Connection handler from |
IOServiceOpen |
uint32_t selector, // Method index on user client |
const uint64_t *input, // Scalar input parameters array |
uint32_t inputCnt, // Number of scalar inputs |
const void *inputStruct, // Structured input data buffer |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.