PDA

View Full Version : php exec, sudo....


sojic
31st October 2008, 19:07
I have some problem with php function exec.

I'm trying to execute


exec("whoami");
echo exec("whoami");
....



but, I do not "receive" anything. Also I should use sudo.

I have /root/start, /root/stop

#!/bin/sh
#touch /var/lock/subsys/local
# Firewall za port forward
iptables -I FORWARD -p tcp -s $1 -d 192.168.168.2 -j ACCEPT


I should execute from php:

exec("sudo /root/start ".$_SERVER['REMOTE_ADDR']);


So... exec do not work, and how to set "sudo with apache"

till
31st October 2008, 22:38
Exec is not returnung any output. Please take a look in the php documentation, there are other functions like system and passthru that give you the output back.

Leszek
1st November 2008, 01:51
For example shell_exec:

<?php
$output = shell_exec('ls -lah');
echo "<pre>$output</pre>";
?>



Functions mentioned in this thread are often blocked by admins because they can be dangerous for the server. It's ok as long as You run them on Your own server without such restrictions.

sojic
10th November 2008, 23:35
Still same problem, I get only <pre></pre>

Leszek
10th November 2008, 23:40
Make sure that "shell_exec" isn't disabled on Your server.

sojic
11th November 2008, 21:32
How to check it?

Leszek
12th November 2008, 00:56
Create a test page in document_root with <?php phpinfo(); ?> as the content and look for "disable_functions" in "PHP Core" section after opening it in the browser. It contains the names of blocked functions.

sojic
14th November 2008, 22:48
This is result:


disable_functions no value no value

falko
15th November 2008, 13:43
Please make sure that PHP Safe Mode is disabled.