Intercepting Objective-C methods is a useful iOS security testing technique. For example, you may be interested in data storage operations or network requests. In the following example, we'll write a simple tracer for logging HTTP(S) requests made via iOS standard HTTP APIs. We'll also show you how to inject the tracer into the Safari web browser.
In the following examples, we'll assume that you are working on a jailbroken device. If that's not the case, you first need to follow the steps outlined in section Repackaging and Re-Signing to repackage the Safari app.
Frida comes with
frida-trace, a function tracing tool.
frida-trace accepts Objective-C methods via the
-m flag. You can pass it wildcards as well-given
-[NSURL *], for example,
frida-trace will automatically install hooks on all
NSURL class selectors. We'll use this to get a rough idea about which library functions Safari calls when the user opens a URL.
Run Safari on the device and make sure the device is connected via USB. Then start
frida-trace as follows:
$ frida-trace -U -m "-[NSURL *]" Safari Instrumenting functions... -[NSURL isMusicStoreURL]: Loaded handler at "/Users/berndt/Desktop/__handlers__/__NSURL_isMusicStoreURL_.js" -[NSURL isAppStoreURL]: Loaded handler at "/Users/berndt/Desktop/__handlers__/__NSURL_isAppStoreURL_.js" (...) Started tracing 248 functions. Press Ctrl+C to stop.
Next, navigate to a new website in Safari. You should see traced function calls on the
frida-trace console. Note that the
initWithURL: method is called to initialize a new URL request object.
/* TID 0xc07 */ 20313 ms -[NSURLRequest _initWithCFURLRequest:0x1043bca30 ] 20313 ms -[NSURLRequest URL] (...) 21324 ms -[NSURLRequest initWithURL:0x106388b00 ] 21324 ms | -[NSURLRequest initWithURL:0x106388b00 cachePolicy:0x0 timeoutInterval:0x106388b80