On a jailbroken iPhone, how can I run commands as root? - iphone

I want to login as a root using system call in Xcode. I try this code without success:
System("su");
System("alpine");
or
System("su root");
System("alpine");
or
System("su root alpine");
When I google it I came to know that this is done using NSTask or NSPipe.
Can anybody tell me how it possible to run multiple system commands using NSTask and NSPipe?
Please give me some hints about this or another method to do this. I am using this application on jailbroken iPhone.
Some more details are here.

If you want to launch something as root you may use sudo.
Example of it's usage in one line with the password:
echo <password> | sudo -S <command>

Related

How to capture iPhone app debug logs

I was researching libimobiledevice to basically capture the specific iPhone app logs. I have tried with the idevicesyslog command, but it gives me all the system logs along with my app.
I tried with idevicesyslog -d | grep com.example.Example but does not give me the info I am looking for.
I am interested in the debug logs of my app.
I know there is a way to capture it from the organizer in Xcode but I don't want to do it that way. I am planning to do it programmatically and then integrate with Appium automation script.
I was able to achieve this with idevicesyslog -d | grep '"https://ac.XYZ.COM" >& t' write to the file "t" and then clear the file and move on to the next step.
This I was able to achieve but the only issue I am facing here is that I need to update the command, like it wont write to log on real time basis when I am interacting with the device. If someone can suggest a way where it log to the file in a real time that would be great.
You can use -m option from idevicesyslog, this option is for "only print messages that contain STRING"
Example:
idevicesyslog -m "Vantage"
Hope this method is work for you :)

Xcode - Passing Bash Commands With A Jailbroken Device

I'd like to know how it would be possible to execute bash commands on a jailbroken iOS device with Xcode? I'm not bothered about the code signing process because I already have a developer account.
I've tried using these 2 commands:
system("cd /var/mobile/Documents");
system("mkdir myNewFolder");
But Xcode returns "Cannot create directory, permission denied".
I know for definite that this is possible. Basically, I want to be using commands such as dpkg and apt commands.
Thanks in advance,
Declan
In UNIX like OS's like iOS you can use the 'Sudo' command to run as root.
To use in one line you need to use UNIX pipes like this:
system("echo yourPassword | sudo -S yourCommand");
You need to make sure sudo is installed on your device, not sure if it is by default.
Some more info here: On a jailbroken iPhone, how can I run commands as root?

Installing Meteor - Couldn't write the launcher script

I am front-end developer attempting to crossover into the world of web app development. I've come a long way in learning Javascript, and now I'm looking to toy around with frameworks.
I still have a bit to learn about using the OSX terminal, but I was hoping somebody could help me with this first stumble I'm having....
I try to install meteor using:
$ curl https://install.meteor.com | /bin/sh
Then I get the following:
Meteor 0.6.4 has been installed in your home directory (~/.meteor).
Writing a launcher script to /usr/local/bin/meteor for your convenience.
This may prompt for your password.
cp: /usr/local/bin/meteor: No such file or directory
Couldn't write the launcher script. Please either:
(1) Run the following as root:
cp ~/.meteor/tools/latest/launch-meteor /usr/bin/meteor
(2) Add ~/.meteor to your path, or
(3) Rerun this command to try again.
Then to get started, take a look at 'meteor --help' or see the docs at
docs.meteor.com.
If it's still helpful to anyone, going into /usr/local/bin, running "sudo rm meteor" then running the install gets it to work for me
Yeah try one of the three suggestions or:
sudo curl https://install.meteor.com | /bin/sh
I had the same problem heres how I fixed it!
Delete all meteor folders
In finder (cmd +shft+g)
type in "~/.meteor"
on the top of the finder window where is has the folder.meteor click and drag folder to trash
In finder (cmd +shft+g) type in "/usr/bin/meteor" then drag the meteor folder to trash
3.In /usr/ create a new folder "local" (password required) and inside "local" create a folder "bin"
Go back to terminal a run curl https://install.meteor.com | /bin/sh

Run command that requires UAC trough command line

I have a bunch of virtual machines that I need to update from time to time. I found this VirtuaBox command
VBoxManage guestcontrol
that works great. problem is that updating requires UAC. Is there any way to bypass the UAC check
The way I found to do it quickly was to buy this software:
http://www.ntwind.com/software/hstart.html
If I had more time I would probably develop something myself. What the software does is install a scheduled task and then run the program through the scheduled task. A brief description of this can be found here:
http://www.howtogeek.com/howto/windows-vista/create-administrator-mode-shortcuts-without-uac-prompts-in-windows-vista/
If I understand correctly, you are requested to type in the root password every time, right?
If so, to bypass that by adding the command to the sudoers file, then when using the command (with sudo) it will not ask for a password but will elevate you to root right away.
To allow a specific program or shell script to run as root but without typing the password (like during boot), add to /etc/sudoers the following line:
(username) ALL = NOPASSWD: /path/to/cmd
for example:
Mac ALL = NOPASSWD: /usr/bin/vboxmanage
After doing that, when typing sudo vboxmanage you will not be ask for root password anymore.
Hope that helps!

iphone run app as root

I am writing a gui wrapper for gcc for a jailbroken iphone, etc. and it is almost done. However, I get this output when it is run ld: can't open output file for writing : a.out, errno=1 collect2:ld return 1 exit status.
I believe this has to do with the privelages the app runs with. I have tried the setuid trick in the cydia developer faq. Can anyone please help?
EDIT
this is the wrapper I am currently using:
#!/usr/bin/bash
dir=$(dirname "$0")
exec "${dir}"/GUI\ GCC_ "$0"
also I used chmod 4777 and changes the owner:group to root:wheel.
Am i doing everything right?
It worked when I did it like this:
setuid(0);
system("Do root stuff");
// To check who you are
system("whoami");
You can install the Package for "ps -U root" to see if you are root, or
Be sure your have your setuid binary hidden behind a wrapper that is not setuid. See Cydia or iFile for an example of how it's done.