LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-25-2008, 04:28 PM   #1
5ury4
LQ Newbie
 
Registered: May 2008
Posts: 3

Rep: Reputation: 0
Smile Output issue with sudo and php system/shell_exec functions


Hello,

I've tried doing a whoami using PHP exec and got the user 'nobody' on my box. I edited the passwd file and provided nobody with bash access (I'm aware of the security risk here). I edited the sudoers file using visudo and created an entry for nobody to run ALL commands using root (again, I know the security risk but it doesn't matter in my case).

In SSH, after a 'su - nobody' while I'm on root I can run any command using sudo. Say :

Code:
root@server [~]# su - nobody
-bash-3.1$ sudo whoami
root
-bash-3.1$ sudo foo
sudo: foo: command not found
But when I do the same with a PHP file using the code :
Code:
<?php
echo shell_exec('sudo foo');
echo system('sudo foo');
echo passthru('sudo foo');
echo exec('sudo foo');
echo system('id');
echo system('uname');
?>
I get NO output for any of the line containing sudo, but I get output for the last two lines (id and uname).

I don't know where I'm wrong here, my sudoers entry reads ->
Code:
nobody ALL=(root) NOPASSWD: ALL
So, there's no hostname/FQDN restriction. I've also tried executing the script from an IP instead of a FQDN. There might be some other restriction or problem which I'm overlooking or of which I'm not aware of. Please help me.

Thanks your for inputs.
 
Old 05-25-2008, 05:28 PM   #2
5ury4
LQ Newbie
 
Registered: May 2008
Posts: 3

Original Poster
Rep: Reputation: 0
I got it working. It was a statement in the sudoers 'Defaults requiretty' which required a real tty to operate sudo. Using an exec() with php for the command 'tty' printed 'not a tty'. Therefore removing/commenting that line solved the problem. There's still no output, however the sudo action/command is carried out and I've also seen that the php waits for the execution to complete before carrying out other commands beyond that line.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run PHP shell_exec as root maneeshsethi Linux - General 5 12-30-2008 07:25 AM
PHP function system() - format the output fatrandy13 Programming 5 09-20-2006 08:53 AM
shell_exec() and friends terminate PHP script (or time out?) MicahCarrick Programming 3 09-05-2006 04:37 AM
PHP exec() and shell_exec() and SELinux Cottsay Programming 1 06-25-2005 09:47 PM
PHP: what's wrong with this line (shell_exec, find, xargs, grep)? J_Szucs Programming 3 11-19-2003 07:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration