Documente Academic
Documente Profesional
Documente Cultură
html
The main benefit of a chroot jail is that the jail will limit the portion of the file system the daemon can see to the root directory of the jail. Additionally, since
the jail only needs to support Apache, the programs available in the jail can be extremely limited. Most importantly, there is no need for setuid-root
programs, which can be used to gain root access and break out of the jail.
Chrooting apache is no easy task and has a tendency to break things. Before we embark on this, we need to first decide whether it is beneficial for you to do
so. Some pros and cons are there, but most certainly not limited to, the following:
i. If apache is ever compromised, the attacker will not have access to the entire file system.
ii. Poorly written CGI scripts that may allow someone to access your server will not work.
i. There are extra libraries you'll need to have in the chroot jail for Apache to work.
ii. If you use any Perl/CGI features with Apache, you will need to copy the needed binaries, Perl libraries and files to the appropriate spot within the
chroot space. The same applies for SSL, PHP, LDAP, PostgresSQL and other third-party programs.
The chrooted configuration listed below supposes that you've compiled your Apache server with the external program mod_ssl. The differences in what
you've compiled with your Apache web server reside in which libraries and binaries you'll need to copy to the chrooted directory.
: Remember that if you've compiled Apache to use mod_perl, you must copy all the related binaries and Perl libraries to the chrooted
directory. Perl resides in /usr/lib/perl5 and in case you use Perl features, copy the Perl directories to /chroot/httpd/usr/lib/perl5/.
Don't forget to create the directory /chroot/httpd/usr/lib/perl5 in your chrooted structure before copying.
The following are the necessary steps to run Apache Web Server in a chroot jail:
We must find the shared library dependencies of httpd. These will need to be copied into the chroot jail later. To find the shared library dependencies of
httpd, execute the following command:
Make a note of the files listed above, you will need these later in our steps.
Add a new UID and a new GID if this is not already done for running Apache httpd. This is important because running it as root defeats the purpose of the
jail, and using a different UID that already exists on the system i.e. nobody can allow your services to access each others' resources. Consider the scenario
where a web server is running as nobody, or any other overly used UID/GID and compromised. The cracker can now access any other processes running as
nobody from within the chroot.
1. These are sample UID/GIDs. Check the /etc/passwd and /etc/group files for a free UID/GID number. In our configuration we'll use the numeric
value 80 and UID/GID www.
1 de 2 28/02/2010 16:03
Apache in a chroot jail http://www.faqs.org/docs/securing/chap29sec254.html
The above commands will create the group www with the numerical GID value 80, and the user www with the numerical UID value 80.
2. Set up the chroot environment. First we need to create the chrooted Apache structure. We use /chroot/httpd for the chrooted Apache. The /chroot
/httpd is just a directory on a different partition where we've decided to put apache for more security.
(1)
Only if Apache is already installed and run on your system.
4. Copy the main configuration directory, the configuration files, the cgi-bin directory, the root directory and the httpd program to the chroot jail:
[root@deep ]/# cp -r /etc/httpd /chroot/httpd/etc/ [root@deep ]/# cp -r /home/httpd/cgi-bin /chroot/httpd/home/httpd/ [root@deep ]/# cp -r
/home/httpd/your-DocumentRoot /chroot/httpd/home/httpd/ [root@deep ]/# mknod /chroot/httpd/dev/null c 1 3 [root@deep ]/# chmod 666 /chroot
/httpd/dev/null [root@deep ]/# cp /usr/sbin/httpd /chroot/httpd/usr/sbin/ We need the /chroot/httpd/etc, /chroot/httpd/dev, /chroot
/httpd/lib, /chroot/httpd/usr/sbin /chroot/httpd/var/run, /chroot/httpd/home/httpd and /chroot/httpd/var/log/httpd directories
because, from the point of the chroot, we're sitting at /.
5. If you have compiled your Apache web server with SSL support, you must copy the entire /etc/ssl directory that handles all private and public keys
to the chroot jail.
[root@deep ]/# cp -r /etc/ssl /chroot/httpd/etc/ ß require only if you use mod_ssl feature.
[root@deep ]/# chmod 600 /chroot/httpd/etc/ssl/certs/ca.crt ß require only if you use mod_ssl feature.
[root@deep ]/# chmod 600 /chroot/httpd//etc/ssl/certs/server.crt ß require only if you use mod_ssl feature.
[root@deep ]/# chmod 600 /chroot/httpd/etc/ssl/private/ca.key ß require only if you use mod_ssl feature.
[root@deep ]/# chmod 600 /chroot/httpd/etc/ssl/private/server.key ß require only if you use mod_ssl feature.
2 de 2 28/02/2010 16:03