Apache em chroot + MySQL + PHP + mod_security + mod_evasive + vsftpd + Fail2ban + Debian Squeeze
Aqui abordarei a implementação de um Apache trabalhando em modo chroot, dando suporte a PHP 5, MySQL, Fail2ban, mod_security, mod_evasive e vsftpd.
Parte 4: Configurando o Fail2ban e ajustando o Apache
Agora vamos configurar o Fail2ban para cuidar de nosso servidor:
# vim /etc/fail2ban/jail.conf
Reiniciar o serviço para que o nosso servidor esteja com um agente analisando os logs e bloqueando quando necessário:
# /etc/init.d/fail2ban restart
Agora vamos fazer mais alguns ajustes em nosso Apache. Abra e deixe como abaixo o arquivo /etc/apache2/conf.d/security:
# vim /etc/apache2/conf.d/security
E na jaula também:
# vim /var/chroot/etc/apache2/conf.d/security
Agora é só reiniciar o Apache:
# /etc/init.d/apache2 restart
E é só acessar o site em:
Artigo também publicado em:
Espero ter ajudado. ;)
# vim /etc/fail2ban/jail.conf
#/etc/fail2ban/jail.conf
[DEFAULT]
ignoreip = 127.0.0.1, 10.0.0.0/23
bantime = 600
maxretry = 3
backend = polling
destemail = douglas@douglas.wiki.br
banaction = iptables-multiport
mta = sendmail
protocol = tcp
action_ = %(banaction)s[name=%(__name__)s, port=\"%(port)s\", protocol=\"%(protocol)s]
action_mw = %(banaction)s[name=%(__name__)s, port=\"%(port)s\", protocol=\"%(protocol)s]
%(mta)s-whois[name=%(__name__)s, dest=\"%(destemail)s\", protocol=\"%(protocol)s]
action_mwl = %(banaction)s[name=%(__name__)s, port=\"%(port)s\", protocol=\"%(protocol)s]
%(mta)s-whois-lines[name=%(__name__)s, dest=\"%(destemail)s\", logpath=%(logpath)s]
action = %(action_mwl)s
[ssh]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
[pam-generic]
enabled = true
filter = pam-generic
port = all
banaction = iptables-allports
port = anyport
logpath = /var/log/auth.log
maxretry = 3
[ssh-ddos]
enabled = true
port = ssh
filter = sshd-ddos
logpath = /var/log/auth.log
maxretry = 3
[apache]
enabled = true
port = http,https
filter = apache-auth
logpath = /var/log/apache*/*error.log
maxretry = 3
[dominio.com.br]
enabled = true
port = http,https
filter = apache-auth
logpath = /var/www/website/logs/*error.log
maxretry = 3
[vsftpd]
enabled = true
port = ftp,ftp-data,ftps,ftps-data
filter = vsftpd
logpath = /var/log/vsftpd.log
maxretry = 3
[postfix]
enabled = true
port = smtp,ssmtp
filter = postfix
logpath = /var/log/mail.log
[sasl]
enabled = true
port = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
filter = sasl
logpath = /var/log/mail.log
[DEFAULT]
ignoreip = 127.0.0.1, 10.0.0.0/23
bantime = 600
maxretry = 3
backend = polling
destemail = douglas@douglas.wiki.br
banaction = iptables-multiport
mta = sendmail
protocol = tcp
action_ = %(banaction)s[name=%(__name__)s, port=\"%(port)s\", protocol=\"%(protocol)s]
action_mw = %(banaction)s[name=%(__name__)s, port=\"%(port)s\", protocol=\"%(protocol)s]
%(mta)s-whois[name=%(__name__)s, dest=\"%(destemail)s\", protocol=\"%(protocol)s]
action_mwl = %(banaction)s[name=%(__name__)s, port=\"%(port)s\", protocol=\"%(protocol)s]
%(mta)s-whois-lines[name=%(__name__)s, dest=\"%(destemail)s\", logpath=%(logpath)s]
action = %(action_mwl)s
[ssh]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
[pam-generic]
enabled = true
filter = pam-generic
port = all
banaction = iptables-allports
port = anyport
logpath = /var/log/auth.log
maxretry = 3
[ssh-ddos]
enabled = true
port = ssh
filter = sshd-ddos
logpath = /var/log/auth.log
maxretry = 3
[apache]
enabled = true
port = http,https
filter = apache-auth
logpath = /var/log/apache*/*error.log
maxretry = 3
[dominio.com.br]
enabled = true
port = http,https
filter = apache-auth
logpath = /var/www/website/logs/*error.log
maxretry = 3
[vsftpd]
enabled = true
port = ftp,ftp-data,ftps,ftps-data
filter = vsftpd
logpath = /var/log/vsftpd.log
maxretry = 3
[postfix]
enabled = true
port = smtp,ssmtp
filter = postfix
logpath = /var/log/mail.log
[sasl]
enabled = true
port = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
filter = sasl
logpath = /var/log/mail.log
Reiniciar o serviço para que o nosso servidor esteja com um agente analisando os logs e bloqueando quando necessário:
# /etc/init.d/fail2ban restart
Agora vamos fazer mais alguns ajustes em nosso Apache. Abra e deixe como abaixo o arquivo /etc/apache2/conf.d/security:
# vim /etc/apache2/conf.d/security
[...]
ServerTokens Prod
[...]
ServerSignature Off
ServerTokens Prod
[...]
ServerSignature Off
E na jaula também:
# vim /var/chroot/etc/apache2/conf.d/security
[...]
ServerTokens Prod
[...]
ServerSignature Off
ServerTokens Prod
[...]
ServerSignature Off
Agora é só reiniciar o Apache:
# /etc/init.d/apache2 restart
E é só acessar o site em:
Referências
- Welcome to The Apache Software Foundation!
- Welcome! - The Apache HTTP Server Project
- FrontPage - Httpd Wiki
- FAQ - Httpd Wiki
- Reporting Security Problems with Apache - The Apache HTTP Server Project
- Apache HTTP Server Version 2.2
- PHP: Installation on Unix systems - Manual
- PHP: Installation and Configuration - Manual
- PHP: Apache 2.x on Unix systems - Manual
- MySQL :: The world's most popular open source database
- MySQL :: MySQL Downloads (Generally Available)
- MySQL :: Developer Zone
- MySQL :: MySQL Documentation: MySQL Reference Manuals
- vsftpd - Secure, fast FTP server for UNIX-like systems
- Index of /users/cevans/untar/vsftpd-2.3.4 on vsftpd.beasts.org:21
- Manpage of VSFTPD.CONF
- Aurium :: Usando Chroot
- Best Practices for UNIX chroot() Operations
- Criação de ambientes em chroot
- pt_BR/Debootstrap - Debian Wiki
- Installing new Debian systems with debootstrap
- Fail2ban.org
- MANUAL 0 8 - Fail2ban
Artigo também publicado em:
Espero ter ajudado. ;)