0

If I do the following command, I get an 'hey' output:

echo shell_exec("echo 'hey'");

But If I do the following command, it will not kill any screen:

echo shell_exec("killall screen");

Or if I do

echo shell_exec("sh /var/www/html/run.sh");

It will not run that file at all (that file does the screen killing aswell)

And If I even get that file with get contents, it successfully reads the content in it.

If it can execute echo so whats wrong?

13
  • 4
    It's probably permissions. killall usually needs su/sudo permission, if it's not your own process. Commented Oct 19, 2017 at 13:42
  • Most likely the user your website runs as does not have permission to execute kill and similar commands. Commented Oct 19, 2017 at 13:42
  • Is giving the permission something PHP sided, or server? Commented Oct 19, 2017 at 13:43
  • There's a good reason for this type of protection...try to imagine how catastrophic it would be to let any user run any command in a shared hosting environment: "Today i feel like taking a break..." shell_exec("poweroff") ;) Commented Oct 19, 2017 at 13:45
  • @Mikk3lRo I know it's risky, but I am wondering how can I whitelist some commands Commented Oct 19, 2017 at 13:46

1 Answer 1

0

To run such powerful commands, I had to use this library as stated in this question. This allows me to login into the SSH with root access and execute any command!

function ssh_script($script, $ip, $user, $pass) {
            $ssh = new Net_SSH2($ip);
    if (!$ssh->login($user, $pass)) {
        exit('Login Failed');
    }

    if ($ssh !== false) {
        echo $ssh->exec("sh " . $script);
    }
    else {
        echo "fail";
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.