Closed sushi2k closed 4 years ago
Hey @sushi2k,
I have to investigate that.
Probably that Frida's mode gets the task port
of the inspected process and does not load any new module :-)
Was just surprised that the frida-gadget wasn't detected in memory. Seems we need to dig a little bit deeper into that :-)
Seems that Frida acts like a debugger and uses the com.apple.debugserver
to inject to the processes (https://github.com/frida/frida-core/blob/69f9f1baf0bdb744ed651652b0e546eae624b071/src/fruity/fruity-host-session.vala#L405)
You can use IOSSecuritySuite.denyDebugger()
and see that Frida will be unable to inject its gadget.
Alright, I probably have a solution :-)
I monitored what flags in the process' kp_proc structure are modified when Frida is attached. Turns out that P_SELECT is set, so we can detect that.
The code below should work (requires further testing, I'm afraid of possible false positives):
private static func checkPSelectFlag() -> Bool {
var kinfo = kinfo_proc()
var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
var size = MemoryLayout<kinfo_proc>.stride
let sysctlRet = sysctl(&mib, UInt32(mib.count), &kinfo, &size, nil, 0)
if sysctlRet != 0 {
print("Error occured when calling sysctl(). This check may be not reliable")
}
return (kinfo.kp_proc.p_flag & P_SELECT) != 0
}
Awesome! Thanks for sharing. That is very helpful. We also have a ticket for that, to add this new Frida feature into the MSTG in case you are interested in that ;-) https://github.com/OWASP/owasp-mstg/issues/1624
Unfortunately, I'm currently totally out of time. :-(
I'll try to test and add this check to the ISS soon.
Hi,
I was just testing the new feature since Frida 12.7.12, where the Frida Gadget can be installed in a running iOS app on a non-jailbroken device that is running in debug mode (repackaing with the Frida-gadget is not needed anymore):
See also: https://www.nowsecure.com/blog/2020/01/02/how-to-conduct-jailed-testing-with-frida/
I was testing this with the sample app that I created (https://github.com/sushi2k/SwiftSecurity). There was no Frida server running on the iOS device, the app was not re-packaged with Frida and just in debug mode. When I was attaching Frida to the running process the frida-gadget was injecting and I got the Frida CLI:
But in the app when I press the button "Check for RE Tools" it's not detecting Frida, and it looks like this https://github.com/sushi2k/SwiftSecurity/blob/master/swiftsecurity.png?raw=true
If I start the Frida-server on the jailbroken phone, the button turn's red. As the frida-gadget is injected into the app the library should be able to detect it (see https://github.com/securing/IOSSecuritySuite/blob/master/IOSSecuritySuite/ReverseEngineeringToolsChecker.swift#L18).
Any idea why your library is not detecting this "new" injection mechanism in Frida?
Sorry if this post became a bit too long and complicated...