Instalando o
PHP5, ele não precisa ficar na jaula:
# aptitude install php5 libapache2-mod-php5 php5-gd php5-ps php5-cli php-pear php5-gd php5-mysql php5-imap php5-mcrypt php5-json -y
# aptitude install php5-xmlrpc php5-dev php5-common fail2ban libapache2-mod-security2 vsftpd postfix mysql-client-5.1 mysql-client -y
# chroot /var/chroot apt-get install imagemagick php5-common -y
Acertando permissões:
# rm -rf /var/chroot/dev/*
# for SEC in $(echo $(find /var/chroot/ -type f \( -perm -04000 -o -perm -02000 \) -print)); do chmod -s ${SEC}; done
# chmod -x /var/chroot/bin/su
# chmod -x /var/chroot/bin/stty
Configurando o módulo evasive para nos ajudar a prevenir os ataques do tipo DoS:
# apt-get install libapache2-mod-evasive
# echo "LoadModule evasive20_module /usr/lib/apache2/modules/mod_evasive20.so" > /etc/apache2/mods-available/evasive.load
Configurando o módulo /etc/apache2/mods-available/evasive.conf:
# vim /etc/apache2/mods-available/evasive.conf
<IfModule mod_evasive.c>
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 900
DOSWhitelist 66.249.65.*
DOSWhitelist 66.249.66.*
# As ultimas são as que o google usa para indexar.
</IfModule>
Acertando o idioma do sistema:
# sed -i 's/# pt_BR.UTF-8 UTF-8/pt_BR.UTF-8 UTF-8/' /etc/locale.gen
# locale-gen
Vamos montar um virtualhost para testarmos o nosso chroot /etc/apache2/sites-available/www.douglas.wiki.br:
# vim /etc/apache2/sites-available/www.douglas.wiki.br
<VirtualHost *:80>
ServerName www.douglas.wiki.br
ServerAlias douglas.wiki.br
DocumentRoot "/var/www/website/frontend/"
<Directory "/var/www/website/frontend/">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ "/var/www/website/frontend/cgi-bin/"
<Directory "/var/www/website/frontend/cgi-bin/">
AllowOverride All
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/www.douglas.wiki.br-error.log
CustomLog ${APACHE_LOG_DIR}/www.douglas.wiki.br-access.log common
ServerSignature Off
IndexIgnore .??* *~ *# README RCS CVS *,v *,t *
# Possible values include: debug, info, notice, info, error, crit,
# alert, emerg.
LogLevel info
</VirtualHost>
Montar a base do nosso site:
# mkdir -p /var/chroot/var/www/website/frontend/cgi-bin
# mkdir -p /var/chroot/var/www/website/logs
# ln -sf /var/chroot/var/www/website /var/www/website
Criando o arquivo index de teste:
# echo "<?php phpinfo(); ?>" > /var/www/website/frontend/index.php
Incluindo o shell /bin/true para o usuário ftp:
# echo "/bin/true" >> /etc/shells
Criando o usuário ftp para o nosso site:
# useradd -m -d /var/www/website -s /bin/true usuarioftp
Agora vamos definir uma senha para ele:
# passwd usuarioftp
Carregando o nosso site e descarregando os sites defaults:
# a2ensite www.douglas.wiki.br
# a2dissite default
# a2dissite default-ssl
# a2enmod rewrite
Agora vamos configurar o
mod_security. Insira no final do arquivo
/etc/apache2/apache2.conf o conteúdo abaixo:
# vim /etc/apache2/apache2.conf
[...]
#Final do arquivo
<IfModule mod_security.c>
# Turn the filtering engine On or Off
SecFilterEngine On
# Make sure that URL encoding is valid
SecFilterCheckURLEncoding On
# Unicode encoding check
SecFilterCheckUnicodeEncoding Off
# Only allow bytes from this range
SecFilterForceByteRange 0 255
# Only log suspicious requests
SecAuditEngine RelevantOnly
# The name of the audit log file
SecAuditLog /var/log/apache2/audit_log
# Debug level set to a minimum
SecFilterDebugLog /var/log/apache2/modsec_debug_log
SecFilterDebugLevel 0
# Should mod_security inspect POST payloads
SecFilterScanPOST On
# By default log and deny suspicious requests
# with HTTP status 500
SecFilterDefaultAction "deny,log,status:500"
</IfModule>
Reiniciar o Apache:
# /etc/init.d/apache2 restart
Vamos analisar os logs do Apache:
# tail -f /var/log/apache2/error.log
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/ps.ini on line 1 in Unknown on line 0
[Fri Jun 24 09:50:34 2011] [notice] ModSecurity for Apache/2.5.12 (http: www.modsecurity.org/) configured.
[Fri Jun 24 09:50:34 2011] [notice] Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze1 with Suhosin-Patch configured -- resuming normal operations
[Fri Jun 24 09:51:55 2011] [notice] Graceful restart requested, doing restart
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/ps.ini on line 1 in Unknown on line 0
[Fri Jun 24 09:51:56 2011] [notice] Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze1 with Suhosin-Patch configured -- resuming normal operations
[Fri Jun 24 10:44:51 2011] [notice] caught SIGTERM, shutting down
[Fri Jun 24 10:44:53 2011] [notice] ModSecurity for Apache/2.5.12 (http: www.modsecurity.org/) configured.
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/ps.ini on line 1 in Unknown on line 0
[Fri Jun 24 10:44:54 2011] [notice] Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze1 with Suhosin-Patch configured -- resuming normal operations
Como pode ser notado, temos um aviso sobre o tipo de comentário no arquivo de configuração do PHP5: /etc/php5/apache2/conf.d/ps.ini. Vamos corrigir isso, só temos que trocar na linha 1 o "#" por ";", que é o tipo de comentário para arquivos de configuração do PHP5:
# vim /etc/php5/apache2/conf.d/ps.ini
; configuration for php ps module
extension=ps.so
Vamos também tirar a assinatura do nosso PHP:
# vim /etc/php5/apache2/php.ini
[...]
expose_php = Off
[...]
Agora já podemos reiniciar o nosso Apache novamente para ver se vamos ter mais algum aviso ou erro:
# /etc/init.d/apache2 restart
Vamos verificar os logs agora:
# tail -f /var/log/apache2/error.log
[Fri Jun 24 10:49:12 2011] [notice] caught SIGTERM, shutting down
[Fri Jun 24 10:49:14 2011] [notice] ModSecurity for Apache/2.5.12 (http: www.modsecurity.org/) configured.
[Fri Jun 24 10:49:15 2011] [notice] Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze1 with Suhosin-Patch configured -- resuming normal operations