Native function hooking with Frida
Last updated
Last updated
I have some certain device that uses a generic driver, which is included in Linux and Windows. But there is no such driver on MacOS. So I started to find a driver and I found a working one. Then I realized they will charge me $59 US dollar per year, and since this driver is unstable, I don't want to pay for it.
I decided to put my reverse engineering skill into use. After digging inside of the binary, I found it is really easy to patch the binary and bypass the verification. But why not try some new tools that I haven't used before? (I haven't reversing on a mac before, especially a ARM one)
Frida is a framework used by a lot of mobile reverse engineers, and it supports ARM architecture pretty well. It can use javascript to make the hooking easier. ()
After some retrial, I found I couldn't attach the debugger (LLDB) to the running binary. This is because of the security mechanism on MacOS (SIP). To disable it, we need to reboot into the recovery mode, and then run this command.
This will turn off the debug protection of SIP. But it is not a good practice to turn off SIP once and for all. So after we finished our work, we should:
To hook a function, we can use frida's interceptor module, and it can map function argument into javascript pretty well (if the function uses standard calling convention).
Even if the function uses custom calling convention, we can get the arguments by access the registers manually as well.
For more information, please check frida's API document .
In this driver application, there is a hidden logging operation. It will be really helpful if we can extract these logging messages even when the debug option has turned off.
To hook this function in frida, we need to know its function signature. IDA has parsed the symbol for us.
We can use the code below to read the log out. And then execute it with frida -l script.js -f <binary>
.
The license check logic used a lot of string comparison. We would like to know what string that it compared to.
Qt was used for string comparison. How do we read out QString? Simple, frida also supports calling native functions. Qt has a lot of functions to convert string objects into NSString.
Finally, we can hook the QCryptographicHash::addData
to see what has been added into the hash.
Unfortunately I could not write much about this specific software. But here, we successfully bypassed the hash check, and installed our own key!