Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/186916-run-shell-commands-as-current-user/
Share on other sites

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...

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?

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.

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...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.