eFishy Posted January 2, 2010 Share Posted January 2, 2010 Hi everyone, I am currently writing a script that I want to be able to run shell commands as a specified and constantly changing user on the system, also I don't want to use root. Basically when a user registers for an account the script creates an account for them on the local Linux system (matching the user they gave for the mySQL login), they are then given a /home/$username/ directory, obviously this is owned by the user "username" and the rest of the script will allow them to modify files and folders within this directory (much like the way cPanel works I suppose). To allow my PHP script to edit the directory I could just allow my PHP root access to the system... Overriding the Linux security... but I would rather use some kind of suPHP to define run this command as this "$username therefore adding more secuirty so if a injection attack was possible through the user inputs they would still only be allowed access to their local system resources... not things like shadow files and other user files. Hope that makes sence, look forward to any other ideas you may have as well. Thanks, Tom Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/ Share on other sites More sharing options...
trq Posted January 2, 2010 Share Posted January 2, 2010 So, whats wrong with using suPHP? That really is the only solution, without it any scripts will be executed by the same user Apache uses. Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987088 Share on other sites More sharing options...
eFishy Posted January 2, 2010 Author Share Posted January 2, 2010 executed by the same user Apache uses. Basically that was the problem, suPHP uses the same user for all actions. Say I have two users /home/user1/ and /home/user2/ I wanted it so that when user1 does a command even if they got to inject something into the shell commands such as "rm -rf" it would still only effect their own directory /home/user1/. Giving php sudo access to the entire home directory would allow them to run it in any users directory's like /home/user2/ Basically I wanted to keep the built in Linux layer of security plus my other security methods. But if suPHP under a single sudo'ed user is the only option suppose I will have to do that... Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987100 Share on other sites More sharing options...
eFishy Posted January 2, 2010 Author Share Posted January 2, 2010 Might be able to get something like this to do the job. http://www.debian-administration.org/article/Running_PHP_scripts_as_specific_users_with_suphp Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987127 Share on other sites More sharing options...
Daniel0 Posted January 2, 2010 Share Posted January 2, 2010 eFishy, I think you misunderstood thorpe. He said that without it, everything would be executed as Apache's user. Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987172 Share on other sites More sharing options...
eFishy Posted January 2, 2010 Author Share Posted January 2, 2010 eFishy, I think you misunderstood thorpe. He said that without it, everything would be executed as Apache's user. Yes but with it wouldn't everything be run as a single pre defined in the config sudo user with appropriate rights? Or can you dynamically change the user that suPHP sets within the PHP script at run time? if so any examples? Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987196 Share on other sites More sharing options...
Daniel0 Posted January 2, 2010 Share Posted January 2, 2010 Or can you dynamically change the user that suPHP sets within the PHP script at run time? if so any examples? That's pretty much the point of suPHP. Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987197 Share on other sites More sharing options...
eFishy Posted January 2, 2010 Author Share Posted January 2, 2010 Cool, that will make things a lot easier! Now just to learn the syntax, do you know of any suPHP tutorials? or examples? doesn't seem to be many and their own documentation only appears to cover the installation and configuration of the module and not so much the use of it. Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987202 Share on other sites More sharing options...
eFishy Posted January 2, 2010 Author Share Posted January 2, 2010 Ok from what I am reading suPHP looks at who owns a file (for example "tom" owns the file) and then runs the file using the permissions inherited by that user. But say I have a single file "move.php" this will run this shell command "cp /file/source /file/destination" For protection I want to lock different users out of directories they do not own. So when run by user1 who wants to move /home/user1/old.txt to /home/user1/new.txt I want it to run using the permissions of "user1" which would be allowed. Yet when the same PHP file is run by user2 I want it to run using the user2 permissions... So if the user1 tried to move /home/user2/creditcard to /home/user1/ they wouldn't be allowed as they are running under user1 permissions... Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987208 Share on other sites More sharing options...
Daniel0 Posted January 2, 2010 Share Posted January 2, 2010 Assuming you set the permissions on your filesystem correctly, that shouldn't be a problem. Quote Link to comment https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/#findComment-987221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.