Jump to content

shell_exec permission


aravin

Recommended Posts

i have a problem run following script

 

<?php

$output=shell_exec("echo 'password' | sudo -S  <command>").

echo $output;

?>

 

i already adding "www-data ALL=NOPASSWD: ALL” in my etc/sudoers folder but it still not working. i really appreciate if somebody can help me and give step to solve it.

 

:(

Link to comment
https://forums.phpfreaks.com/topic/195168-shell_exec-permission/
Share on other sites

i have a problem run following script

 

<?php

$output=shell_exec("echo 'password' | sudo -S  <command>").

echo $output;

?>

 

i already adding "www-data ALL=NOPASSWD: ALL” in my etc/sudoers folder but it still not working. i really appreciate if somebody can help me and give step to solve it.

 

:(

 

it's not safe to remove ALL restrictions, so you should instead remove restrictions from the functions you're calling.

 

for example, if you wanted to remove root prerequisite for fdisk, you'd type 'sudo visudo' in terminal and add this line:

www-data ALL=(root) NOPASSWD: /sbin/fdisk

 

then you can do a shell_exec("sudo fdisk"); and get results.  now i haven't tested it but i add the entire command, including arguments in the sudoers (the file you edit when you do a sudo visudo) might unlock just the command with that specific set of arguments, but i'm not sure of this, i didn't feel like testing it.

 

make sure you only edit sudoers with sudo visudo from terminal, if you do a gksudo gedit sudoers, and you edit it incorrectly and save it, you're going to be in ALOT of trouble lol

 

good luck

I get some out put by tring this coding. But my password is not correct even i have try many possible password.

 

code:

<?php

$output=shell_exec("echo 'password' | sudo -S  <command> 2>&1" );

echo $output;

?>

 

 

error:

[sudo] password for nobody:

Sorry, try again.

[sudo] password for nobody:

sudo: 1 incorrect password attempt

 

any idea to solve it?

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.