tags:

views:

72

answers:

3

I've tried these:

<?php
  $r = shell_exec('sudo -u root -S /etc/init.d/apache2 restart < /home/$user/passfile');
  echo $rin;
?>

(password on passfile) DIDNT GET

<?php
  (php$output4=shell_exec('echo "$x" | whoami 1>/dev/null && sudo /etc/init.d/ssh restart');
?>
<html>
  <body>
    <script type="text/javascript">
      x=prompt("entr");
    </script>
  <body>
</html>
<html>
  <form id="form1" name="form1" method="post" action="">
    <input type="submit" name="b1" value="click"  />
  </form>
</html>
<?php
  if(isset($_POST['b1'])) {
    echo "<pre>$output4</pre>";
  }

?>

Please help.

+1  A: 

You can't invoke sudo this way; it reads it's password directly from the keyboard (via /dev/tty), not from STDIN.

If you want to execute something as a root user, you have to run the script as the root user.

meagar
+2  A: 

From man sudo on OS X:

-S          The -S (stdin) option causes sudo to read the password from the standard input instead of the
                   terminal device.
too much php
Also true on debian.
icco
+1  A: 

You can't invoke sudo this way, for security reasons. If there is a workaround, please forget about it as quickly as possible. What you are trying to do is a terrible idea. You do not want to restart your server from a web page. You really don't. Yes, I'm sure. Put your keyboard down and walk away slowly.

Maybe if you tell us what you're trying to do, we can help you come up with a better way.

JSBangs