I'm looking for some advice..
I've managed to get a php script to call another page which in turn runs system commands as root.
This is what I've done, I'd like to see if I can secure it.
In etc/sudoers.d I've added a file which contains a list of files the wwwrun user can run as root without needing a password. It contain entries similar to :
wwwrun ALL=(ALL) NOPASSWD: /Web/scripts/helper/filea
wwwrun ALL=(ALL) NOPASSWD: /Web/scripts/helper/fileb
wwwrun ALL=(ALL) NOPASSWD: /Web/scripts/helper/filec
My main web site has an test.php page, permissions on this are 777 & wwwrun:root
Within test.php I have some jquery, which is using ajax to call action.php&action=aaa
In action.php I have :
if ($_REQUEST['action']) == 'aaa') {
exec('/Web/scripts/helper/filea', $res);
}
if ($_REQUEST['action']) == 'bbb') {
exec('/Web/scripts/helper/fileb', $res);
}
if ($_REQUEST['action']) == 'bbb') {
exec('/Web/scripts/helper/filec', $res);
}
filea contains a couple of bash commands. This file has 655 & root:root permissions.
The commands in filea, fileb and filec are fixed and if a variable is passed it's only to tell it to run another fixed command with in the file.
How can I make this more secure ? Obviously not having root access would be best, but I need to run some commands for moving, editing, updating, installing files etc.
UPDATE
Just to confirm this is working. I'd like to make it a little more secure.
I have tried changing the ownership to wwwrun:root and permissions to 744
This has made it so only root can edit the files, I assume that is a good idea..
Thanks