Frida Trace (frida-trace)
frida-trace is a frida script used to trace the classes and functions within an application
Using frida-trace it is possible to create hooking functions. To use frida-trace you need to first find the functions to hook into. To do this you can use frida-ps to find the correct process running, like so:
$ frida-ps -Ua
PID Name Identifier
----- -------- ---------------------------------
15929 DVIA-v2 com.highaltitudehacks.DVIAswiftv2
15916 Settings com.apple.Preferences Once you have identified the application you want to hook in to you can start either tracing all of the functions within the application, which could take a long time, or you can filter them out by specifying exactly what you want to look for. frida-trace also accepts wild card searching.
$ frida-trace -U -m "*[*cryp* *]" -p 15929  ✔
Instrumenting...
-[NEIKEv2EncryptionProtocol isEqual:]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/isEqual_.js"
-[NEIKEv2EncryptionProtocol hash]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/hash.js"
-[NEIKEv2EncryptionProtocol description]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/description.js"
-[NEIKEv2EncryptionProtocol copyWithZone:]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/copyWithZone_.js"
-[NEIKEv2EncryptionProtocol isAuthenticated]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/isAuthenticated.js"
-[NEIKEv2EncryptionProtocol setWireType:]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/setWireType_.js"
-[NEIKEv2EncryptionProtocol setIs256Bit:]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/setIs256Bit_.js"
-[NEIKEv2EncryptionProtocol wireType]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/wireType.js"
-[NEIKEv2EncryptionProtocol is256Bit]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/is256Bit.js"
-[NEIKEv2EncryptionProtocol initWithEncryptionWireType:is256Bit:]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/initWithEncryptionWireType_is256Bit_.js"
-[NEIKEv2EncryptionProtocol isGCM]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/isGCM.js"
-[NEIKEv2EncryptionProtocol initWithEncryptionType:]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/initWithEncryptionType_.js"
-[NEIKEv2EncryptionProtocol keyLength]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/keyLength.js"
-[NEIKEv2EncryptionProtocol blockLength]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/blockLength.js"
-[NEIKEv2EncryptionProtocol ccAlgorithm]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/ccAlgorithm.js"
-[NEIKEv2EncryptionProtocol ivLength]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/ivLength.js"
-[NEIKEv2EncryptionProtocol icvLength]: Auto-generated handler at "/home/mantis/__handlers__/NEIKEv2EncryptionProtocol/icvLength.js"
+[RNOpenSSLDecryptor decryptData:withSettings:password:error:]: Auto-generated handler at "/home/mantis/__handlers__/RNOpenSSLDecryptor/decryptData_withSettings_password_error_.js"
+[RNOpenSSLDecryptor decryptData:withPassword:error:]: Auto-generated handler at "/home/mantis/__handlers__/RNOpenSSLDecryptor/decryptData_withPassword_error_.js"
+[RNOpenSSLDecryptor decryptData:withEncryptionKey:HMACKey:error:]: Auto-generated handler at "/home/mantis/__handlers__/RNOpenSSLDecryptor/decryptData_withEncryptionKey_HM_72d173d3.js"
+[RNOpenSSLDecryptor decryptData:withSettings:encryptionKey:IV:error:]: Auto-generated handler at "/home/mantis/__handlers__/RNOpenSSLDecryptor/decryptData_withSettings_encrypt_7a7b5d2a.js"
<Removed for brevity>
Started tracing 406 functions. Press Ctrl+C to stop.
Once these functions have been instrumented you can go back to using the application until you find where and how these functions are called. frida-trace automatically creates a handler for each class and method it finds. This means that you can modify the handler script to do more useful actions such as dumping the arguments and return values.
The example below shows that we have instrumented all of the *[RNDecryptor *] functions.
We can use the handler functions to grab the password from the password function as an example. So we open up the __handlers__/RNDecryptor/password.js file, as this is where the function can be manipulated.
As seen in the onLeave function we can log out the return value of the hooked function call. Due to the way that frida works we have to cast the return value to a string. This means that we have to use the ObjC.Object(retval).toString() method.
When we perform the action again within the application we can see that frida-trace has successfully logged out the encryption password.
Last updated
Was this helpful?