ios-run-application-with-root-privileges

前言

正文

  • Put your .app bundle in the ./Applications folder of your debian package.
  • Set ownership of your app binary to “root:wheel”:

after-install::
	# Taokeceshiji1:~ root# uicache
	install.exec "killall \"KNcreateOnDisk\"" || true
	install.exec "uicache "


#Finally, make sure to set the ownership of the script to "root:wheel" and its permissions to "755".

	install.exec "chmod 775 /Applications/KNcreateOnDisk.app/fake"

#要先设置用户属主,再设置文件执行权限
	install.exec "chown root:wheel /Applications/KNcreateOnDisk.app/KNcreateOnDisk"

	#Give your app binary the "set user ID" and "set group ID" flags.
	install.exec "chmod 6775 /Applications/KNcreateOnDisk.app/KNcreateOnDisk"

  • Explicitly call “setuid(0)” and “setgid(0)” very early in your code (specifically in “main”, somewhere before calling “UIApplicationMain”). Here’s a quick example:

#import "KNAppDelegate.h"

int main(int argc, char *argv[]) {
	@autoreleasepool {



		        // Set uid and gid
        if (!(setuid(0) == 0 && setgid(0) == 0))
        {
            NSLog(@"Failed to gain root privileges, aborting...");
            exit(EXIT_FAILURE);
        }

        // Launch app

		return UIApplicationMain(argc, argv, nil, NSStringFromClass(KNAppDelegate.class));
	}
}
  • add a “launch script” fake to the app bundle, which will be called when you tap on the SpringBoard icon, and will actually launch the app.

#!/bin/bash
root=$(dirname "$0")
exec "${root}"/KNcreateOnDisk


<!-- Finally, make sure to set the ownership of the script to "root:wheel" and its permissions to "755".
 -->

可以放在deb 包的postinst ,或者makefile

fake

  • devzkndeMacBook-Pro:Resources devzkn$ touch fake

cd /Users/devzkn/code/github/kncreateondisk/Resources

devzkndeMacBook-Pro:Resources devzkn$ chmod +x fake

devzkndeMacBook-Pro:Resources devzkn$ cat fake
#!/bin/bash
root=$(dirname "$0")
exec "${root}"/KNcreateOnDisk

<!-- Taokeceshiji1:/Applications/KNcreateOnDisk.app root# ls -lrt -->

-rwxrwxr-x 1 root   wheel     63 Mar 29 17:40 fake
-rw-r--r-- 1 mobile staff   4313 Mar 29 17:57 Info.plist
-rwsrwsr-x 1 root   wheel 138688 Mar 29 18:00 KNcreateOnDisk

  • Info.plist
<!-- CFBundleExecutable -->

	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>

修改为 

	<key>CFBundleExecutable</key>
	<string>fake</string>

see also

<!-- https://git.saurik.com/uikittools.git/blob/HEAD:/uicache.mm -->



Its bundle must be located in "/Applications".

Its executable must belong to the root user.

Its executable must be able to set user and group IDs.

It has to explicitly set user and group ID at runtime.

It must not be run directly. Rather, something else should launch it (keep reading to learn how to do this).

转载请注明: > ios-run-application-with-root-privileges

在操作过程或者文章有问题的话欢迎在 原文 里提问或指正。

赞赏支持

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少
最近的文章

setupVPNActive

前言我们常常需要知道本地VPN或者其他类型的VPN连接状态,通过是监听对应的通知进行处理正文 SBVPNConnectionChangedNotification 如果是VPN服务器超时、断网、鉴权失败或者自定义VPN(对接系统的VPN接口)等情况, 通常是不会触发这个SBVPNConnectionChangedNotification。<!-- 因此需要监听其他进程的动态---CFUserNotificationCreate -->因为连接失败系统总要和用户交互...…

iOSre继续阅读
更早的文章

find

前言 find / -size +10000c  :~ root# find / -amin -1 Taokeceshiji1:/var/mobile/Library/Preferences root# find / -mmin -1 正文 find命令 *    基本格式:find path expression<!--     1.按照文件名查找 -->     find /etc -name '*srm*'  #使用通配符*(...…

linux继续阅读
更多