Cover | Table of Contents
http://httpd.apache.org/docs-2.0/)http://httpd.apache.org/docs-2.0/misc/security_tips.html)http://www.cisecurity.org/bench_apache.html)# location of the web server files ServerRoot /usr/local/apache # location of the web server tree DocumentRoot /var/www/htdocs # path to the process ID (PID) file, which # stores the PID of the main Apache process PidFile /var/www/logs/httpd.pid # which port to listen at Listen 80 # do not resolve client IP addresses to names HostNameLookups Off
# groupadd httpd # useradd httpd -g httpd -d /dev/null -s /sbin/nologin
Server header field, and
some poor soul tries to influence Apache developers to add it.
Because no clear technical reasons support either opinion,
discussions continue.Server response header field defined in the HTTP
standard, so a first step in our effort to avoid this will be to fake
its contents. As you will see later, this is often not
straightforward, but it can be done. Suppose we try to be funny and
replace our standard response "Apache/1.3.30
(Unix)" with
"Microsoft-IIS/5.0" (it makes no
difference to us that Internet Information Server has a worse
security record than Apache; our goal is to hide who we are). An
attacker sees this but sees no trace of Active Server Pages (ASP) on
the server, and that makes him suspicious. He decides to employ
operating system
fingerprinting. This technique uses the variations in the
implementations of the TCP/IP protocol to figure out which operating
system is behind an IP address. This functionality comes with the
popular network scanner NMAP. Running NMAP against a Linux server
will sometimes reveal that the server is not running Windows.
Microsoft IIS running on a Linux server—not likely!chroot(2) system
call. This system call allows restrictions to be put on a process,
limiting its access to the filesystem. It works by choosing a folder
to become the new filesystem root. Once the system call is executed,
a process cannot go back (in most cases, and provided the jail was
properly constructed).chroot(2) system call. On Linux systems, the
meanings of chroot and jail
are close enough. BSD systems have a separate
jail( ) call, which implements additional security
mechanisms. For more details about the jail( )
call, see the following: http://docs.freebsd.org/44doc/papers/jail/jail.html.chroot(2) or jail( )) into your
web server defense gives the following advantages:http://www.php.net/manual/en/security.php)http://www.phpsec.org)http://www.php.net.$ ./configure --with-apxs=/usr/local/apache/bin/apxs $ make # make install
--with-apxs with
--with-apxs2 if you are running Apache 2. If you
plan to use PHP only from within the web server, it may be useful to
put the installation together with Apache. Use the
http://www.php.net.$ ./configure --with-apxs=/usr/local/apache/bin/apxs $ make # make install
--with-apxs with
--with-apxs2 if you are running Apache 2. If you
plan to use PHP only from within the web server, it may be useful to
put the installation together with Apache. Use the
--prefix configuration parameter for that:$ ./configure \ > --with-apxs=/usr/local/apache/bin/apxs \ > --prefix=/usr/local/apache/php
# Load the PHP module (the module is in # subdirectory modules/ in Apache 2) LoadModule php5_module libexec/libphp5.so # Activate the module (not needed with Apache 2) AddModule mod_php5.c # Associate file extensions with PHP AddHandler application/x-httpd-php .php AddHandler application/x-httpd-php .php3 AddHandler application/x-httpd-php .inc AddHandler application/x-httpd-php .class AddHandler application/x-httpd-php .module
register_globals. This option is off by default as
of PHP 4.2.0, but I am mentioning it here because:name parameter:http://www.apachesecurity.net/sayhello.php?name=Ivan
<? echo "Hello $name!"; ?>
<?
if (isset($admin) = = false) {
die "This page is for the administrator only!";
}
?>$admin
variable to true when it authenticates the user
and figures out the user has administration privileges. In practice,
appending ?admin=1 to the URL would cause PHP to
create the $admin variable where one is absent.
And it gets worse.input_filter
treat_data
default_post_reader
input_filter hook is the most useful of all
three. A new implementation of this hook can be added through a
custom PHP extension and registered with the engine using the
sapi_register_input_filter( ) function. The PHP 5
distribution comes with an input filter example (the file
README.input_filter also available at
http://cvs.php.net/co.php/php-src/README.input_filter),
which is designed to strip all HTML markup (using the
strip_tags( ) function) from script parameters.
You can use this file as a starting point for your own extension.auto_prepend_file
configuration option to prepend input sanitization code for every
script that is executed will have similar results in most cases.
However, only the direct, native-code approach works in the following
situations:http://www.ietf.org/rfc/rfc2246.txt). TLS is
currently at version 1.0, but that version is practically the same as
SSLv3.1. In spite of the official standard having a different name
everyone continues to call the technology SSL, so that is what I will
do, too.
Host request header. However,
SSL still requires one exclusive IP address per web site. Looking at
the OSI model, it is easy to see why. The HTTP request is wrapped
inside the encrypted channel, which can be decrypted with the correct
server key. But without looking into the request, the web server
cannot access the Hosthttp://www.openssl.org). The installation is
easy:$ ./config $ make # make install
$ openssl s_client -host www.thawte.com -port 443
www.thawte.com, in the
example above) to a trusted root certificate. In this case, the chain
references two certificates, as shown in the following output. For
each certificate, the first line shows the information about the
certificate itself, and the second line shows information about the
certificate it was signed with. Certificate information is displayed
in condensed format: the forward slash is a separator, and the
uppercase letters stand for certificate fields (e.g.,
http://www.modssl.org) or Apache-SSL
(http://www.apache-ssl.org).
Neither of these two web sites discusses why you would choose one
instead of the other. Historically, mod_ssl was
created out of Apache-SSL, but that was a long time ago and the two
implementations have little in common (in terms of source code) now.
The mod_ssl implementation made it into Apache 2
and is more widely used, so it makes sense to make it our choice
here.$ cd /usr/local/src $ wget -q http://www.modssl.org/source/mod_ssl-2.8.19-1.3.31.tar.gz $ tar zxvf mod_ssl-2.8.19-1.3.31.tar.gz $ cd mod_ssl-2.8.19-1.3.31 $ ./configure --with-apache=../apache_1.3.31
cd
../apache_1.3.31) and configure Apache, adding a
--enable-module=ssl switch to the
configure command. Proceed to compile and
install Apache as usual:$ ./configure --prefix=/usr/local/apache --enable-module=ssl $ make # make install
--enable-ssl switch to the
configure line. Again, recompile and reinstall. I
advise you to look at the configuration generated by the installation
(in httpd.conf for Apache 1 or
ssl.conf for Apache 2) and familiarize yourself
with the added configuration options. I will cover these options in
the following sections.http://www.openca.org/openca/)http://tinyca.sm-zone.net)$ ./configure --prefix=/opt/openssl $ make $ make test # make install
$ openssl speed
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes md2 1841.78k 3965.80k 5464.83k 5947.39k 6223.19k md4 17326.58k 55490.11k 138188.97k 211403.09k 263528.45k md5 12795.17k 41788.59k 117776.81k 234883.07k 332759.04k hmac(md5) 8847.31k 32256.23k 101450.50k 217330.69k 320913.41k sha1 9529.72k 29872.66k 75258.54k 117943.64k 141710.68k rmd160 10551.10k 31148.82k 62616.23k 116250.38k 101944.89k rc4 90858.18k 102016.45k 104585.22k 105199.27k 105250.82k des cbc 45279.25k 47156.76k 47537.41k 47827.29k 47950.51k des ede3 17932.17k 18639.27k 18866.43k 18930.35k 18945.37k rc2 cbc 11813.34k 12087.81k 12000.34k 12156.25k 12113.24k blowfish cbc 80290.79k 83618.41k 84170.92k 84815.87k 84093.61k cast cbc 30767.63k 32477.40k 32840.53k 32925.35k 32863.57k aes-128 cbc 51152.56k 52996.52k 54039.55k 54286.68k 53947.05k aes-192 cbc 45540.74k 46613.01k 47561.56k 47818.41k 47396.18k aes-256 cbc 40427.22k 41204.46k 42097.83k 42277.21k 42125.99k
http://www.grc.com fame, when a 13-year-old
felt offended by the "script
kiddies" term he used.)
MaxClients
directive, which is set to 256 by default. This default value is
often used in production and that can cause problems if the server
cannot cope with that many processes.# ps -A -o pid,vsz,rsz,command
PID VSZ RSZ COMMAND
3587 9580 3184 /usr/local/apache/bin/httpd
3588 9580 3188 /usr/local/apache/bin/httpd
3589 9580 3188 /usr/local/apache/bin/httpd
3590 9580 3188 /usr/local/apache/bin/httpd
3591 9580 3188 /usr/local/apache/bin/httpd
3592 9580 3188 /usr/local/apache/bin/httpdAccept-Encoding: gzip,deflate
http://www.schroepl.net/projekte/mod_gzip/)
is used for content compression. For Apache 2,
mod_deflate does the same and is distributed
with the server. However, compression does not have to be implemented
on the web server level. It can work just as well in the application
server (e.g., PHP; see http://www.php.net/zlib) or in the
application.