|
||||||||||||||
|
||||||||||||||
Configuring your Apache2 server in accordance to the specifications laid out in this howto will result in limited functionality. The following will be available:
This howto does not cover such things as relational databases (MySQL, PostgreSQL, etc.), scripting languages (Python, Perl, PHP, Tcl, etc.), or any of a myriad of server side gadgets for interaction with web services. The reasons for this are beyond the scope of this howto, but involve security on multiple levels. For a better explanation to this and a number of other good security oriented observations, read Artur's article. SetupThe rest of this howto has been performed on my LFS 3.3 ( Linux from scratch) based distribution of Linux called Jinx, running on a i586-pc-linux-gnu, with the 2.4.18 kernel (I know it's not the latest kernel patch, but I'm such a lazy bastard). I'm sure most of the stuff in this howto will be applicable in most unixes, but some variations may occur. I'll try to add them, if you report them, with the exclusion of anything involving the microsoft corporation. The first step in securing any service is to close as many security holes in the operating system and then start closing holes in the service itself. This so called hardening of the OS is beyond the scope of this article, but there are some very good articles about the issue on e.g. the SecurityFocus site. So feel free to stop by there and come back later for the Apache2 part. Installation and settingsOnce all the other planned hardening has been executed we can begin the process of bolting up Apache2. The first thing is to create a new username and usergroup to be used only by Apache2. We can use the name for both "apache2" and create the new group and regular user like this: groupadd apache2 This sets the home directory to nada and gives no shell. Thus if the user account is compromised the cracker will have a hard time obtaining a shell from which to launch any serious attack. Also, by default, the Apache2 processes run with privileges of user nobody (except the main process, which runs with root privileges) and GID of group nogroup. If the account was compromised the intruder would gain access to all processed running under user nobody and group nogroup. Hence we run Apache2 under the UID/GID of a unique regular user/group, dedicated to Apache2. Getting Apache2Next you need to download the latest stable version of the Apache2 web server from your nearest mirror. Since some of the options of Apache2 can only be disabled during compilation, you need to download the source instead of a binary release. It is also good practice to always compile your own software, since then you'll know what crap got put in and what got left out, right? If you download the software from a mirror, be sure to verify the authenticity of the packages with PGP, GPG or MD5 as instructed here. After downloading and verifying the packets, you need to unpack them. Then you need to decide which modules are to remain enabled. All the modules available in the latest version of Apache 2.0.X (currently 2.0.47) can be found at http://httpd.apache.org/docs-2.0/mod. Apache2 modulesThe choice of modules is one of the most important steps in securing Apache2. The fewer you have, the better. In order to not incapasitate Apache2 completely and fulfill the functionality and security assumptions stated in the beginning, the following modules must remain enabled:
All of the aforementioned modules are installed by default, but a number of other modules are also installed by default. Since configure for Apache2 doesn't seem to support the
This will leave the wanted modules listed before and use the default MPM, Now, you may choose to include some more modules and change the MPM to suit your needs better. It is, however, worth to note that some Apache2 modules are more dangerous than others. For a discussion of these, please refer to the original Securing Apache: Step-by-Step article or any number of security related sites for example SecurityFocus. The next issue is whether to compile the modules dynamically or statically. Static is better. If new vulnerabilities in Apache2 are found, you will probably have to recompile the whole thing anyway and by choosing the static method, you eliminate the need of one more module, Compiling Apache2The latest distribution should have all necessary security patches included, but if for some reason it does not, you need to apply all these patches. After this, the server can be compiled as follows: ./configure --prefix=/opt/apache \ The choice of prefix is naturally up to you, but I happen to use that one. It is a good idea not to leave any marks about the version of apache in use, thus for example After configure, run make The actual Chrooting of Apache2The next phase is to limit Apache2's access to the filesystem. This can be achieved by chrooting it's main daemon, First you need to create the new root directory structure. I've done it under mkdir -p /chroot/httpd/dev && \ Naturally you'd want to put the zoneinfo, that's relevant for you. The owner of all these directories must be mknod /chroot/httpd/dev/null c 1 3 Note: for FreeBSD systems this would be: mknod /chroot/httpd/dev/null c 2 2 Also a log device must be created under the chroot jail. This can be achieved by adding the line syslogd_flags="-l chroot/httpd/dev/log" to the kill -SIGHUP 'cat /var/run/syslogd.pid' Note: for FreeBSD systems you would need to change the After these comes the time consuming part. You need to check each and every program and library for dependancies. I used ldd /opt/apache/bin/httpd If you then run ldd /opt/apache/lib/libaprutil-0.so.0 You then strace -o /opt/httpd-trace /opt/apache/bin/httpd The reason why we As you can see from the output of the So, moving on. You copy the libraries to the chroot jail and put them in the cp /lib/ld-linux.so.2 /chroot/httpd/lib/ && \ The next step is to copy the rest of the files mentioned in the cp /etc/nsswitch.conf /chroot/httpd/etc/ You need to remove all other lines from the If you now try to run cp /opt/apache/conf/mime.types /chroot/httpd/opt/apache/conf/ Obviously you want to use the zoneinfo, that's correct for you time zone. I just happen to live in Helsinki. You might also want to put in these files, although Apache2 will run without them (or at least seems to): cp /etc/resolv.conf /chroot/httpd/etc/ TestingNow it's time to see if the bugger works. Copy one of the cp /opt/apache/htdocs/index.html.en /chroot/httpd/web/index.html Change your /usr/sbin/chroot /chroot/httpd/ /opt/apache/bin/httpd If you made use of the virtual hosts then you need to make the directories to which you point i.e. I have the directories If Apache2 still won't work, try to You can also try to increase the level of Apache2's logging by changing the TuningFine tuning the
ServerRoot "/opt/apache"
PidFile /opt/apache/logs/httpd.pid
ScoreBoardFile /opt/apache/logs/httpd.scoreboard
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
Listen 80
User apache
Group apache
ServerAdmin webmaster@xnuxer.or.id
UseCanonicalName Off
ServerSignature Off
HostnameLookups Off
ServerTokens Prod
DirectoryIndex index.html
DocumentRoot "/web/vhosts"
<Directory />
Options None
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/web/vhosts/xnuxer.or.id">
Order allow,deny
Allow from all
</Directory>
<Directory "/web/vhosts/www.videoxnuxer.com.com">
Order allow,deny
Allow from all
</Directory>
AccessFileName .htaccess
<Files ~ "^.ht">
Order allow,deny
Deny from all
</Files>
TypesConfig /opt/apache/conf/mime.types
DefaultType text/plain
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz
AddType application/x-tar .tgz
TypesConfig /opt/apache/conf/mime.types
DefaultType text/plain
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz
AddType application/x-tar .tgz
LogLevel warn
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
ErrorLog /opt/apache/logs/error_log
NameVirtualHost *
<VirtualHost *>
DocumentRoot "/web/vhosts/xnuxer.or.id"
ServerName "xnuxer.or.id"
ServerAlias "www.xnuxer.or.id"
ErrorLog logs/xnuxer.or.id/error_log
CustomLog logs/xnuxer.or.id/access_log combined
</VirtualHost>
<VirtualHost *>
DocumentRoot "/web/vhosts/www.videoxnuxer.com"
ServerName "www.videoxnuxer.com"
ServerAlias "videoxnuxer.com"
ErrorLog logs/www.videoxnuxer.com/error_log
CustomLog logs/www.videoxnuxer.com/access_log combined
</VirtualHost>
| ||||||||||||||
|
Please register, you are currently just a guest here.
|
||||||||||||||
| Similar Articles: | ||||||||||||||
|
|
|||
|
|||
|
|||
|
|
|||
|
|||
|
|||
|
|
|||
|
|||
|
|||
|
|
|||
Members of Guest cannot leave comments. |
|||
Welcome to XNUXER.OR.ID, by visit our site we like to help you to get main information about internet security and opensource so dont forget to update your knowledge every time using our website.
To access file download or private information here you must register, please register here.
| Top Contributors: | |||
| 1 | webmaster | 166 | |
Articles: |
| This Hour: 0 |
| Today: 0 |
| This Month: 0 |
| All Time: 164 |
| Membership: |
| Registered Today :18 |
| This Hour:1 |
| This Month:333 |
| Total:4540 |
| Banned:0 |
| What do you think about our website? |