I host a very small hosting site that hosts a type of chat software. I give each user a /home/ jailed ftp but they have their own www folder they can upload things to.
One of my users uploaded this php file: http://pastebin.com/YAJW8weh - which seems to be able to save php files and allow him to download them.
Using this I think he was able to access some of my files and one of my php files had my MySQL password in the php, which he then gained access to a database with all my clients passwords.
How can I stop this from happening again? What precautions should I take when giving users their own /home/ directory.
You'll have to protect your website and Linux/Unix does this very well, set minimal permissions for group and others on your website's root directory:
Restrict access to files in PHP with open_basedir:
Disable dangerous functions from PHP:
Use su - user to test permissions they have on your website.
You want to disable php for the home folder.
When using PHP as an Apache module (default on Ubuntu 10.04), add the following to your Apache configuration
You should probably also use
Options -ExecCGI
andAllowOverride None
there for safety. See the official Apache security tips. If your webserver have other kinds of scripts enabled (likemod_perl
), be sure to disable them for the home folder too.suPHP is really your best bet here. You would setup each user to run their scripts as their own user, then chmod their directories so that other users cannot read them. Do not rely on open_basedir, it's not going to work 100%.
Since you are allowing uploads, you are always going to have to worry about people uploading things they shouldn't. I'd suggest running something like Linux Malware Detect. It alerts you when things like shells and DoS scripts get uploaded to your servers.