Enviado por admin el
Después de la primera parte donde hemos configurado IPtables, en esta segunda parte veremos como mejorar la seguridad de FusionPBX con Fail2Ban. Iniciamos con la instalación del programa:
cd /usr/src
wget https://github.com/fail2ban/fail2ban/archive/0.9.3.tar.gz
lo descomprimimos:
tar -xf 0.9.3.tar.gz
entramos en la carpeta creada:
cd fail2ban-0.9.3
lo instalamos:
python setup.py install
Activamos el script para iniciarlo como servicio:
cp /usr/src/fail2ban-0.9.3/files/redhat-initd /etc/init.d/fail2ban
chkconfig --add fail2ban
chkconfig fail2ban on
Lo utilizaremos para bloquear los intentos de acceso/registro a FreeSWITCH, para ataque DDoS siempre hacia FreeSWITCH y para los bloquear los intentos de acceso a la pagina de administración de FusionPBX. Empezamos creando los archivos con las expresiones regulares que se utilizarán para analizar los registros (LOG) de FreeSWITCH y de Apache:
nano /etc/fail2ban/filter.d/freeswitch.conf
Este archivo ya existe y lo dejamos con la configuración predefinida. Seguimos con el segundo archivo:
nano /etc/fail2ban/filter.d/freeswitch-dos.conf
Pegamos las siguientes líneas:
# Fail2Ban configuration file
#
# Author: soapee01
#
[Definition]
# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named "host". The tag "<HOST>" can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
# Values: TEXT
#
failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth challenge \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
Seguimos con el ultimo archivo relativo a la parte Web:
nano /etc/fail2ban/filter.d/fusionpbx.conf
Pegamos las siguientes líneas:
# Fail2Ban configuration file
#
# Author: soapee01
#
[Definition]
# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named "host". The tag "<HOST>" can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
# Values: TEXT
#
#failregex = [hostname] FusionPBX: \[<HOST>\] authentication failed
#[hostname] variable doesn't seem to work in every case. Do this instead:
failregex = .* FusionPBX: \[<HOST>\] authentication failed for
= .* FusionPBX: \[<HOST>\] provision attempt bad password for
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
Guardamos los cambios y terminamos modificando el archivo de configuración general de fail2ban:´
nano /etc/fail2ban/jail.conf
al final del archivo pegamos las siguientes líneas:
[freeswitch-udp]
enabled = true
port = 5060,5061,5080,5081
protocol = udp
filter = freeswitch
logpath = /var/log/freeswitch/freeswitch.log
action = iptables-allports[name=freeswitch-udp, protocol=all]
mail-whois[name=FreeSwitch, dest=root@miodominio.org, sender=fail2ban@miodominio.org]
maxretry = 5
findtime = 600
bantime = 600
[freeswitch-dos]
enabled = true
port = 5060,5061,5080,5081
protocol = udp
filter = freeswitch-dos
logpath = /var/log/freeswitch/freeswitch.log
action = iptables-allports[name=freeswitch-dos, protocol=all]
mail-whois[name=FreeSwitch, dest=root@miodominio.org, sender=fail2ban@miodominio.org]
maxretry = 50
findtime = 30
bantime = 6000
[fusionpbx]
enabled = true
port = 80,443
protocol = tcp
filter = fusionpbx
logpath = /var/log/secure
action = iptables-allports[name=fusionpbx, protocol=all]
mail-whois[name=FreeSwitch, dest=root@miodominio.org, sender=fail2ban@miodominio.org]
maxretry = 5
findtime = 600
bantime = 600
Antes de guardan los cambios personalizamos, en cada bloque, el parámetro dest= con el correo electrónico donde se quieren recibir la notificaciones y el parámetro sender= con el correo electrónico del remitente de las notificaciones que se enviarán. Antes de iniciar Fail2Ban modificamos un parámetro de este archivo:
nano /etc/fail2ban/action.d/iptables-common.conf
cambiando esta línea:
lockingopt = -w
para que quede:
lockingopt =
De esta forma Fail2Ban trabajará correctamente con IPtables. Guardamos los cambios. Si queremos utilizar SendMail en lugar de PostFix para enviar las notificaciones:
service postfix stop
chkconfig postfix off
yum install sendmail* mailx -y
chkconfig sendmail on
service sendmail start
Ya podemos iniciar Fail2Ban:
service fail2ban start
Iniciando fail2ban: [ OK ]
y revisar el log:
nano /var/log/fail2ban.log
para tener la certeza que no haya errores de configuración. FELIZ AÑO A TODOS!!!
Comentarios recientes