Once an iOS device is jailbroken, we can build jailbreak apps (with theos) and it gets installed in the /Applications
directory where the preloaded apps run with root privileges. If an app is built with Xcode, once it is installed, it gets into the /private/var/mobile/Applications/
folder, which is supposed to have Apple sandbox enforced (before jailbreak).
So, the questions I have are:
For a jailbroken device, will the apps in
/private/var/mobile/Applications/
execute with root privileges or withmobile
user privileges?In case of Android, once rooted, the apps will have to gain root privileges by executing the
su
command. Is it the case when it comes to iOS as well?
I would like to understand the difference between these two development options (Theos / Xcode) and how it affects what operations my app can perform.
Not disagreeing with anything H2CO3 said, but to add some further clarification ...
Apps installed in
/private/var/mobile/Applications/
(†) with Xcode will run with usermobile
privileges, even on jailbroken phones.Even on a jailbroken phone, apps installed to
/private/var/mobile/Applications/
(†) will be sandboxed almost (‡) like apps on a jailed phone. So, no reading other (normal) apps' data, even if those files are owned by usermobile
.For a good description of the process that apps like Cydia use to run as root, see this answer. Or, just ssh into your phone, and take a look inside
/Applications/Cydia.app/
yourself.If you simply copy/install an app (without doing what H2CO3 suggested) to
/Applications/
, it won't be sandboxed, but it will still run withmobile
(UID=501) privileges:(‡) Here's a good discussion, with input from Saurik, about how different jailbreaks may affect the sandbox. Long story short: it depends.
(†) Update: in recent versions of iOS, the location of 3rd-party apps has been moved to
/var/mobile/Containers
, and later to/var/containers/
, but the same basic sandbox issues remain.Long story short: no.
Jailbreaking is a necessary but not sufficient condition for gaining root. Apps will still be sandboxed by default.
What you can do for making your app run with root privileges is creating a startup shell script that has
root:wheel
ownership and755
permissions, then create your actual executable with the same ownership,7555
as permissions (i. e. set its "setuid" bit), then callsetuid(0);
from withinmain()
, before callingUIApplicationMain()
.