How to run subprograms with root permissions on iOS?

拟墨画扇 提交于 2019-12-10 12:27:48

问题


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.


回答1:


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,




回答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.



来源:https://stackoverflow.com/questions/21676583/how-to-run-subprograms-with-root-permissions-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!