views:

692

answers:

4

Hi there. I am developing for Jailbroken iPhone. I need to write(copy) a file to iPhone System Folders (/Library/LaunchDaemons) to which only ROOT has write access. How can i write a file to such folders through my Code. I know i can use NSFileManager's copyItemAtPath:toPath method to copy the file, but i cant write as i dont have permission to write on such folders.

Any Suggestions??

A: 

Your app could run as root or setuid root.

Rhythmic Fistman
and how to do that? Any examples on how to do this??
raziiq
And expect to hear later that your program is being used for exploits on iPhones where it is installed.
Darron
Good point. I heard that standard issue iPhoneOS has no setuid apps, that the iphone way is via launchd + a daemon.
Rhythmic Fistman
thanks for the replies. If i cant run my app as root, then what is the best way to write on private directories?Remember i am developing for JB iphones.
raziiq
Create a small privileged daemon that does it for you.
Rhythmic Fistman
I have created a Daemon which i need to paste into /Library/LaunchDaemons/ , but since /Library/LaunchDaemons dont have a write access for my app, so i cant write to that folder. This is what i want to do but dont know how to. Any suggestions on how to do this?
raziiq
Since you're working on JB you've got a bit more flexibility. You could require the user to install your app as root, via a script.
Rhythmic Fistman
I want my app to be efficient. Asking user to SSH and then place the Daemon into /Library/LaunchDaemons will make user feel a little uncomfortable. Also all the users dont know about running scripts or SSH. The app should do such stuff on its own
raziiq
How is your app distributed and installed? BTW if you're on JB, most root passwords are "alpine", so just sudo and install the file yourself. Voilà!
Rhythmic Fistman
App is gonna install through Cydia. And most of the JB phones these days have their default password changed, because of the security threats.
raziiq
Maybe there's some kind of install hook you can use in Cydia.
Rhythmic Fistman
And what hook is that?
raziiq
I don't know. I haven't released any apps through Cydia, but maybe it's got a package manager that lets you do something like that.
Rhythmic Fistman
A: 

Instead of running your whole app as root it is much better design to have a small helper tool that will install the files. Then only that helper tool has to run as root.

For more info about SUID binaries check http://en.wikipedia.org/wiki/Setuid as a good start.

St3fan
If you do this you should make the helper application *very* limited. It shouldn't be able to write any file to any directory or someone will figure out how to exploit it to take over iPhones where your program is installed.
Darron
A: 

i think i have found the answer to this question. In order to write to System folders you need to have permission to write on that folder. My app had a Daemon attached to it, so i had to copy that Daemon to /System/Library/LaunchDaemons to make that Daemon work. So as i am developing for JB iphone and people are going to install my app using Cydia, why not to make Cydia install the files of my app to proper locations. I made Cydia to copy the Daemon file into /System/Library/LaunchDaemon folder. Now the question is how Cydia will know where to paste the files. Answer is simple, just make the proper folders in .deb file and cydia will paste the files located in the folders inside the .deb file.

For Example if you have a Daemon and you want Cydia to paste it to /System/Library/LaunchDaemons , make the file structure like this before making a .deb

+- MyApp
   +- Applications
      +Myapp.app
   +-DEBIAN
    -control
   +-System
     +-Library
       +-LaunchDaemons
         +- com.myLaunchDaemon.plist

Cydia while installing your app will paste the com.myLaunchDaemon.plist file in System/Library/LaunchDaemons, reboot and you are good to go.

raziiq
A: 

Hi , According to your instruction i made my cydia based directory and my files are copied successfully , but when i ssh my iphone ,and check plist group and its owner then both owner and group are mobile and remaining all files in the launchdamenons having root owner and wheel group, my plist is not run when i reboot my iphone , but when i changed manually its file owner and group then plist works fine , so how can i solve this problem. thanx

devjangir
You have to set the permissions of your app before copying to iPhone. I recommend you write a script that will set the permissions while you are on your Mac, and then copy your app to iPhone or deb package however you want.
raziiq