Question

I have the code and everything which is:

     pkill python

However I wanted to run it from a php script like this:

  echo shell_exec("pkill python");

I get an output which says:

bash: pkill: (1503) - Operation not permitted

I know what the problem is, which is that pkill is su command. Anyway to change this so that the php script can run it?

Était-ce utile?

La solution

The problem is, that the process you want to kill does not belong to the apache user (apache usually runs as www-data with group www-data). If you give apache more rights (say run it as user root), your PHP script would run with more rights and could do things like this. But this would be dangerous, because if there is a security flaw in apache or your php script, a malicious attacker could take over your system.

Instead I suggest using the setuid bit.

  1. Create a file kill.sh with the content pkill python
  2. Make it executable (chmod a+x kill.sh)
  3. Make it belong to root (chown root:root kill.sh)
  4. Make it setuid (chmod u+s kill.sh)
  5. Invoke this script from your php script
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top