-5

With the Android SDK, I can run a process as a superuser by invoking su and then running my code. How can I do the same on iOS?

Here's what I use on Android:

// Elevate to root
Process localProcess = Runtime.getRuntime().exec( "su");

// Now run some command as root
DataOutputStream localDataOutputStream = new DataOutputStream( localProcess.getOutputStream());
localDataOutputStream.writeBytes( "chmod 666 file.name\n");
localDataOutputStream.writeBytes( "exit\n");
localDataOutputStream.flush();

I've tried the following C commands, but I receive an error stating that my password is incorrect.

system( "ls -l /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // read start permissions
system( "sudo -s alpine | chmod 666 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // trying change permissions
system( "ls -l /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist"); // read changes

The log looks like this:

-rw-r--r-- 1 root wheel 7813 Dec 16 10:47 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist

chmod: changing permissions of `/System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist': Operation not permitted

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

Password:

-rw-r--r-- 1 root wheel 7813 Dec 16 10:47 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist

How can I programmatically run any script with root permissions on iOS? I'm looking for an answer that will work on jailbroken devices, but would be happy with something that also works on stock devices, if that's possible.

Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
Tapa Save
  • 4,769
  • 5
  • 32
  • 54
  • 14
    with jailbreak: easily, without jailbreak: in no way. –  Feb 10 '14 at 11:58
  • @H2CO3 please any example with jailbreak, and question: in android i need install superuser application for run this code. In iOS I must install any programm before? – Tapa Save Feb 10 '14 at 12:01
  • You have no chance to make the legal way. Apple does not such apps in the store. What also, because of security reasons, is very good. Why are viewing categories at all in such a deep level in? – Mirko Brunner Feb 12 '14 at 13:48
  • @Mirko Brunner, I create In-house app without publish in the store. I need run scripts with root permissions (change files and directories, change his attributes, etc) on devices with jailbreak. – Tapa Save Feb 12 '14 at 14:08
  • 4
    I don't understand why my question have many downvotes!!??? I don't break any rules with this question. And I think peoples with answer "with jailbreak: easily, without jailbreak: in no way" and don't give answer with examples is a big flooders. – Tapa Save Feb 16 '14 at 16:32
  • @cpburnz, Thank you, i will trying this code apply in my app... please wait few moments for result – Tapa Save Feb 19 '14 at 18:30

2 Answers2

4

One major feature of IOS is sandboxing which means that apps reside in their own file system which is not visible to other apps. What you want to do goes against the Security design of IOS.

If what you need to do is allow a set of apps to talk to one another and share data, there are ways and means to do this through shared Document types, Exported UTIs and the DocumentInteraction class,

Paulo
  • 1,245
  • 10
  • 8
  • I know few apps with sudo permissions. For example, iFile. This app can similar function like i need. What I need make to get permissions for my app like iFile? – Tapa Save Feb 14 '14 at 07:39
  • 1
    Yes, I know about jailbreak. And I ask: How I can PROGRAMMATICALLY run script with SUDO permissions on iOS WITH jailbreak? – Tapa Save Feb 16 '14 at 16:23
2

Your sudo command is malformed:

sudo -s alpine | chmod 666 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist

Which is interpreted as:

sudo -s <sudo-command> | <non-sudo-command>

This is attempting to run the alpine command with sudo, and piping its output to chmod which doesn't make sense. Since chmod does not get run as root, it outputs:

chmod: changing permissions of `/System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist': Operation not permitted

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

And since sudo was not provided a password (the -S argument), it prompts for the password by outputting:

Password:

I think you intended to do:

echo <password> | sudo -S <command>

Where I believe you intended to use alpine as the password which would then be:

echo 'alpine' | sudo -S chmod 666 /System/Library/TextInput/TextInput_zh.bundle/Keyboard-zh.plist

See man(8) sudo for additional information on sudo.

Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144