I am trying to execute a shell script when loading a .php in a web-server, I've already been struggling with this for a while so I will ask for help.
What I've tried so far is to make a wrapper as explained in this post: Execute root commands via PHP
But I couldn't really get it to work making the wrapper execute a shell script, even when the script worked when being executed from the console with root privileges.
So the only solution I could found is to convert the shell code to a C code using "system ("") as using system(" ")
I don't really know if it's possible, what the shell script used to do is check the PID of the process running in the port 12321 and then kill it.
The shell script alone worked, so I am asking if anyone knows if it's possible to convert to C, here is the shell script I want to convert:
#!/bin/sh
pid=$(/bin/fuser -n tcp 12321 | /usr/bin/awk '{print $1}');
/bin/kill -9 $pid;
And here is the wrapper.c being used, that used to execute the code above called in my machine (testversion.sh), but I don't know why, isn't working.
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main (int argc, char *argv[]) {
setuid (0);
system ("/bin/bash /var/www/html/scrip/debugport/testversion.sh");
return 0;
}
As this doesn't seem to work, someone got a way of executing it all in the C code?