Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    Question Prevent users from reading each others webroots when using PHP system functions?

    Hi!

    What would be the best way to prevent system functions such as shell_exec, exec and so on from acessing other users webroots, besides actually disabling them? suPHP + open_basedir aren't compatible as it seems.

    Any suggestions on what route to take?

    /Sonician

  2. #2
    Member
    Join Date
    Mar 2007
    Posts
    123

    Default Re: Prevent users from reading each others webroots when using PHP system functions?

    I'm testing 1h.com's HIVE on some of my servers, and it's working really well. One of the things it does is employ "a chroot mechanism where each user is limited to its own directory". So far, it's looking really good.

  3. #3
    Member
    Join Date
    Apr 2011
    Posts
    145
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Prevent users from reading each others webroots when using PHP system functions?

    The best option is to disable those functions if you can find a work-around. Another option may seem a little crazy, but this is what I've done with mod_fcgid + suEXEC:

    1. Edit /etc/group so that "nobody" is in each web users's group. (Only web users!!) So:
    useracct:x:537:useracct,nobody
    2. Restart Apache

    3. Modify permissions (for each account):

    # cd /home/useracct/public_html/
    # find . -type d -exec chmod 710 {} \;
    # find . -type f -exec chmod 640 {} \;
    # find . -type f -name "*.php" -exec chmod 600 {} \;
    The above will set:
    1. read/write/traverse on all directories for the owner, and traverse only for the group (needed because "nobody" is in the group), but no rights for "everyone".
    2. read/write for all files for owner, read-only for group (so apache can serve image, html, css, etc), and no rights for "everyone"
    3. read/write for PHP files for owner, and absolutely no rights for anyone else. This makes it impossible for apache to ever read a php config script directly and expose your passwords.
    As always, test this somewhere unimportant before doing it live. You'll also want to check the permissions within the users home directory and make sure the user's group doesn't have access to places it shouldn't.

  4. #4
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    6,303
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Prevent users from reading each others webroots when using PHP system functions?

    I wouldn't recommend editing /etc/group (or /etc/passwd) manually in any way at all. You can corrupt the file and then no users will be able to function on the system.

    Please note that any steps that can possibly put your system into a state of dysfunction along with customizing to the point it doesn't fall under the typical cPanel setup would mean we no longer support that system. If you choose to follow recommendations such as the above without considering this caveat and then break the system, we cannot restore those settings for you. You would want to make certain to have full backups that can be restored to a clean system that hasn't been fundamentally altered.
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Forums Technical Analyst, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  5. #5
    Member
    Join Date
    Apr 2011
    Posts
    145
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Prevent users from reading each others webroots when using PHP system functions?

    I did say that the best option was just to disable those functions. But perhaps some additional warning was warranted.

    If you break it you're on your own -- test in your own test environment before going live -- and if you don't know how to revert these changes, you should not make them!

    Re: Editing /etc/group - I did it manually because it was quicker for multiple accounts, but there is the safer command line option:
    (replace webacct with the account)
    Code:
    # useradd -G {webacct} nobody
    As said above -- if you do any of this you are on your own re: support.

Similar Threads & Tags
Similar threads

  1. how do you usesuphp and prevent overriding system php.ini?
    By Kaydiddle in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 04-06-2009, 04:35 PM
  2. Prevent full backup for users
    By _xandih in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 01-15-2008, 10:40 AM
  3. Prevent Users from reading other webroots
    By mediawrap in forum Database Discussions
    Replies: 5
    Last Post: 07-14-2007, 07:30 AM
  4. Could not find functions file, your system may be broken???
    By Jeff75 in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 09-04-2006, 09:59 AM
  5. Replies: 11
    Last Post: 02-15-2004, 11:11 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube