I was going through the checkra1n exploit which jailbreaks the iOS and looked at a few open-source libraries that alert's the user that your device is compromised.
Is there a security certificate that can recognize that the device is jailbroken or a direct link/API to Apple's servers that our app verifies before it goes through a critical transaction?
Basically, the problem statement here is that a malicious user should not be able to access the critical transactional data from the rooted device or the app's sandboxed environment.
There is no API for checking jailbreak device, all checks are made local, but there are quite a few checks that you can implement to make the attacker's job harder:
You can make your app "ask" the OS not to be run on debugger and if it is, it just crashes. You can read more here.
You can check the file system for presence of specific files, that exist only on jailbroken phones with FileManager
(NSFileManager
):
/private/var/lib/apt/
"cydia://package/com.example.package"
If you decide to implement these checks, be careful for several things like how you store your strings in the binary. If your executable Mach-O file is looked in dissasembler like Hopper and you have stored lets say the string "MobileSubstrate" the attacker can easily see it there in the __TEXT area of the executable look where this address is used and guess that you are trying to perform a jailbreak check, and NOP out your whole jailbreak test function. Keep Strings like that encoded in some way, lets say Base64.
Other dead giveaways that you do a jailbreak test, is function names, do not name your func like isJailbroken()
because these symbols can be seen again, use meaningless names (the opposite of good programming practise). Also add the tag __attribute__((always_inline))
to the declarations of your c functions that are related to jailbreak checks and @inline(__always)
to the ones in Swift. If you are not familiar with function inlining you can read more about it here.
I have build a framework containing all these checks, obfuscated but with a lot of comments, if you would like you can check it out here 🙂
The jailbreak scene is a constant cat and mouse chase, who is going to win the chase really depends on who is willing to spend more efforts into it.
Hope this helps!