Security for "Free Home Page" Linux Web Service
Anonymous Coward writes "I have a couple of Web servers (running RedHat 5.0) which I'm using to offer free Web hosting on, and I've been giving the users standard accounts, the only exception being that their HOME directory is also set to their HTML directory. This means that telnet is active, as well as ftp, which I didn't consider a problem (that's how I learned, after all), but I was wrong.
One of these boxes was hacked, by someone telnetting in and installing a sniffer. We've had to take the box down and scrub it clean, and before I bring it back online, I'd like to know the best way to give users relatively unfettered access to their own files via ftp, while disabling their ability to do anything else, on a box running any brand of Linux." I know we've touched on this aspect of security before in several Slashdot forums, but this question has been asked (and will be asked again) many times. I figure it may as well have its own forum for discussion.
While I'm sure there are some generic rules to follow, I've never really researched this area much (you can bet I will be keeping an eye on this posting). Exactly how was the box cracked? Did they simply telnet into an account and run a user-mode program? Did they exploit a crond bug (unchecked buffer, or whatever)? I'm not asking for a step-by-step-how-to-root-our-boxen speech, but depending on how they got in, advice might vary.
First off.. Do not just "Scrub" the system. Wipe the HD, LLFing if possible. Backup data files first, via the network to a known good server first (via anon FTP so any remaining sniffers, etc, will not read any important password).
:-)
:-)
Then go and reinstall a recent Linux distro. I recommend Slackware. It may not have the bells & whistles of Red Hat, but its BSD-style init scripts are easy (easy as config.sys and autoexec.bat) to learn, and tends to ship with reasonably secure daemons. Of course, OpenBSD is another possible solution
Now, if you want to just give them FTP access (and nothing else), ProFTPD provides a nice solution. Granted, earlier versions had some interesting security holes (poke), recent versions have been a lot better security wise. Set it up with mod_linuxprivs (which uses the POSIX.1e interface of 2.2.x and later kernels to drop all root privs except for the ability to bind to ports less than 1024). (For the configure impaired, try "./configure --prefix=/usr --with-modules=mod_linuxprivs").. This lets them have ftp access (I'd also recommend you setup ProFTPD to chroot the various users to their homedirs). Disable telnet. Install SSH or OpenSSH and only allow your own login to use it (login.access allows this). Only allow your user to execpt su (perhaps as part of the wheel group), and have your root password as something other than your normal account password. At this point, you will have a secure system, FTP access for normal users, and secure remote access for your own administration. Of course, this doesn't get you out of your duties to monitor Bugtraq for possible advisories. I also recommend (very much so) that you read LASG -- the Linux Administrator's Security Guide. It's very good
---
--
Internet Explorer (n): Another bug -- that is, a feature that can't be turned off -- in Windows.
You can set up Lynx as the user shell.
There are a lot of features of Lynx that makes this a great idea. Users can upload/manage/edit files, and it can be set up to only run programs that are specifically set in Lynx. You can also disable the access to a shell in it (the keystroke is '!', I think).
Check out the well documented system-wide lynx.cfg file. You can use TRUSTED_EXEC to limit what local commands may be run and TRUSTED_LYNXCGI to limit what local CGIs the users can run. Set SYSTEM_EDITOR to force the user to only use the editor that specifies. Uploader definitions allow uploading using rzsz or kermit though ftp appears to be safe enough (as long as you make sure the version of the daemon you're running has no known holes). KEYMAP allows you to disable certain commands (shell, and possibly goto). The DIRED_MENU definitions allow you to set what users can do in their directories (copy, move, edit, compress, etc). Yes, you can tag multiple items for file operations.
I've seen systems with this setup and they work really well. Newbie users who are scared of CLIs will find it nice as well.
For extra-extra security, try removing the all-execute bit for all of your regular shells and set it so that only a trusted group may execute them, just to make it *that* much harder to screw with the system.
I wouldn't allow telnet access because obviously people's passwords are being transmitted in the clear. Install sshd - 1.2.27 I think is the last version before SSH2. You can get sshd from openssh.org (?) or www.ssh.fi. SSH2 is an extension of SSH1 and more complex, so some security holes may turn up in the future for it, although they will be patched and maintained (I don't know how much longer people will be interested in SSH1 for). ssh runs on port 22 (telnet is port 23). There are many clients available for people using unix, and there are also windows clients available - PuTTY is one (written by an English chap I know, so no need for export law concerns here). Once you have ssh running, then disable telnet access, there is no excuse to have it.
Here in England I am still waiting for a proper secure FTP client, although you can use scp which is part of the ssh suite. There is plenty of secure FTP stuff in America though. You could be paranoid and run S/Key which generates new passwords per login per user. I haven't ever used this before, so I don't know how much hassle it is to run.
Keep uptodate with security bugs. http://www.securityfocus.com/ has a list of vulnerabilities categorised by product/manufacturer etc. They put up the patches there which you SHOULD apply ASAP.
Good Luck :-)
Making a secure multi-user Unix box is difficult with any Unix. It requires a good clean start, perferably professionally audited, with as few services running as possible, as few setuid programs as possible, and as draconian as possible restrictions on the access and activities of users as possible. Then add robust monitoring of critical system files and users activities and be constantly vigilent to spot any abnomalities and apply security patches when vulnerabilites are discovered.
/etc/inetd.conf and comment out every line except the in.ftpd line. Edit your rc scripts and disable all nonessential services. Check yourself with nmap. Don't install X or gnome/kde since they tend to have security problems. If you must have X (or even if you don't), make sure that you don't have any setuid programs on the system. You can find them with
/usr/bin/perl.
/etc/passwd. This will lock their ftp sessions in a chrooted jail.
/var. This could mean, minimally, using tripwire or something of that nature to monitor file changes, but it is a very good idea to use a read only (hardware read only is the best) file system.
This is a job for a professional, and since you are asking for help in this forum, you would be wise to pay for some professional assistance. If you do not wish to do this, at least follow these steps:
First of all read the linux security HOWTO.
Start with a minimal install of a Linux you are comfortable with. RedHat is probably ok if you use the latest version and keep up with patches. I'd consider using OpenBSD for this kind of server since it's more secure by default, but it's not better if you don't know how to administer it properly. The only visible services you should need are ftp, apache, and sshd. That means no sendmail, nfs, linuxconf, talk etc. Edit
find . -type f -perm ++s -print
In fact, you can gain a little peace of mind by running the command
chmod -R o-rwx *
Which will remove normal user read, write, and execute permissions from every file and directory.
Then reinstall the ftp daemon because otherwise people won't be able to list their files etc. Other things may break. Add things back as needed. For instance if you allow CGI scripting, you would need to give execute permissions on
If you use wu-ftpd (default with RedHat) then add '/./' (that's slash dot slash) to the end of their home directory path in
Secure apache with appropriate configuration. I don't recommend allowing CGI scripts, but if you do, at least use cgiwrap
Now that you have everything setup, freeze everything except
Log the heck out of user activity, preferably onto a box that is not connected to the internet. Read Bugtraq religiously and follow your distributions security lists.
And finally, get help, really. Paying somebody upfront, even if it is only to review your actions and policies is a very good idea.
--
"L'IT c'est moi!"
1) low-level format the hard drive(s). Do it a couple times for good luck.
2) Install Windows 2000.
If you follow these 2 steps, you will NEVER have another problem with shoddy linux security. To be fair, the linux kernel proper isn't the cause of most "linux" security problems, though ....
there are many ways to limit shell access while still allowing ftp access. the main things to keep in mind are:
these things (especially number 1) let you do some neat things--you can create a user called ''nslookup'' with /usr/bin/nslookup as their shell and no password; when someone connects to your box as nslookup, they can execute the command, and then they get disconncted when they are done. the university of washington has a test account for people to try out pine that does this. any other interactive program can be used in the same way: provide a telnet gateway via /usr/bin/telnet, a news reader via /usr/bin/tin, and so on.
hope this was helpful
darren
(darren)
Second consider using OpenBSD as the OS on the web server. Use the included IP Filter software that ships with OpenBSD, in addition to the packet filter in step 1.
If you are using Apache for your HTTPd, compile it with as few modules as possible, and no dynamic module support.
To really go whole-hog on security, you could block ALL protocols except HTTP and HTTPS, and have all user uploads and other account management go through cgiwrap on a HTTPSD instance.
Personally what I do for friends who want FTP access is use a One Time Password (S/Key or the like), but the average user probably won't be willing to deal with OTP.
I do not deploy Linux. Ever.
Set the shell to /bin/false or something so that telnet is effectively disabled. Setup the ftp server so that each account is chroot'ed, that way users will not be able to look around on the file system.