Enviado por admin el
En la versión 11 de Asterisk es presente un nuevo canal de los eventos de registros: el canal security. En este nuevo canal se registran todo lo relacionado con la seguridad del sistema y para que se pueda integrar con Fail2ban, hay que realizar unos cambios que veremos en este articulo.
Primero descargamos e instalamos la ultima versión de Fail2Ban:
cd /usr/src
wget http://downloads.sourceforge.net/project/fail2ban/fail2ban-stable/fail2b...
tar -xf fail2ban-0.8.11.tar.gz
cd fail2ban-0.8.11
python setup.py install
Luego instalamos el script del servicio:
cp files/redhat-initd /etc/init.d/fail2ban
chkconfig --add fail2ban
chkconfig fail2ban on
Seguimos con la configuración:
cd /etc/fail2ban/filter.d
En esta carpeta ya está presente un archivo de configuración para Asterisk. Si queremos lo modificamos aunque funciona perfectamente como está.
nano asterisk.conf
Guardamos los cambios.
Luego pasamos al archivo de configuración de Fail2Ban:
nano /etc/fail2ban/jail.conf
Al final del archivo añadimos este bloque:
[asterisk-iptables]
enabled = true
filter = asterisk
action = iptables-allports[name=ASTERISK, protocol=all]
mail-whois[name=ASTERISK, dest=admin@voztovoice.org, sender=fail2ban@miodominio.org]
logpath = /var/log/asterisk/security
maxretry = 3
bantime = 10800
Una descripción de las líneas:
- Etiqueta que da inicio al bloque
- Activado
- Nombre de la cadena que se creará en IPtables
- La acción que se ejecutará cuando se verifique el evento configurado. En este caso se bloqueará la IP para todos los puertos y se enviará un correo electrónico al destinatario indicado conteniente el Whois de la IP bloqueada. Personalizar el parámetro dest y el parámetro sender. Para que el envío del correo electrónico funcione, SendMail o otro servidor de correo electrónico tiene que estar instalado y corriendo.
- Carpeta y nombre del archivo que leerá Fail2Ban
- Después de cuantos intentos sin éxito se bloqueará la IP
- Numero de segundos que la IP quedará bloqueada; 10800 = 3 horas
Guardamos los cambios y modificamos la configuración de Asterisk:
nano /etc/asterisk/logger.conf
bajo la etiqueta:
[logfiles]
añadimos:
security => notice,security
Guardamos los cambios y entramos en la consola de asterisk:
asterisk -rvvvvvvv
Recargamos la configuración de modulo de LOG de Asterisk:
CLI> logger reload
== Parsing '/etc/asterisk/logger.conf': Found
Asterisk Queue Logger restarted
Miramos si el nuevo canal está activo:
CLI> logger show channels
Channel Type Status Configuration
------- ---- ------ -------------
/var/log/asterisk/messages File Enabled - NOTICE WARNING ERROR FAX
Console Enabled - DEBUG NOTICE WARNING ERROR DTMF FAX
/var/log/asterisk/security File Enabled - NOTICE SECURITY
/var/log/asterisk/verbose File Enabled - VERBOSE
/var/log/asterisk/debug File Enabled - DEBUG
Iniciamos Fail2ban:
service fail2ban restart
¡Listo!
4 comentarios
error
Enviado por Andres (no verificado) el
algo falta creo o yo me equivoque en algo....
me arroja este error:
root@server.desarrollagroup.com [~]# cd /usr/src
root@server.desarrollagroup.com [src]# wget http://downloads.sourceforge.net/project/fail2ban/fail2ban-stable/fail2b...
--2014-03-18 23:02:18-- http://downloads.sourceforge.net/project/fail2ban/fail2ban-stable/fail2b...
Resolving downloads.sourceforge.net... 216.34.181.59
Connecting to downloads.sourceforge.net|216.34.181.59|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://softlayer-dal.dl.sourceforge.net/project/fail2ban/fail2ban-stable... [following]
--2014-03-18 23:02:18-- http://softlayer-dal.dl.sourceforge.net/project/fail2ban/fail2ban-stable...
Resolving softlayer-dal.dl.sourceforge.net... 67.228.157.232
Connecting to softlayer-dal.dl.sourceforge.net|67.228.157.232|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 204752 (200K) [application/x-gzip]
Saving to: `fail2ban-0.8.11.tar.gz.1'
100%[==============================================================>] 204,752 617K/s in 0.3s
2014-03-18 23:02:19 (617 KB/s) - `fail2ban-0.8.11.tar.gz.1' saved [204752/204752]
root@server.desarrollagroup.com [src]# tar -xf fail2ban-0.8.11.tar.gz
root@server.desarrollagroup.com [src]# cd fail2ban-0.8.11
root@server.desarrollagroup.com [fail2ban-0.8.11]# python setup.py build
running build
running build_py
running build_scripts
root@server.desarrollagroup.com [fail2ban-0.8.11]# cp files/redhat-initd /etc/init.d/fail2ban
cp: overwrite `/etc/init.d/fail2ban'? yes
root@server.desarrollagroup.com [fail2ban-0.8.11]# chkconfig --add fail2ban
root@server.desarrollagroup.com [fail2ban-0.8.11]# chkconfig fail2ban on
root@server.desarrollagroup.com [fail2ban-0.8.11]# cd /etc/fail2ban/filter.d
-bash: cd: /etc/fail2ban/filter.d: No existe el fichero o el directorio
Algo te faltó en la
Enviado por Fabian Mestre (no verificado) el
Algo te faltó en la instalación, por que no prueba haciendolo por yum? Creo que debes tener epel instalado, pero es una opción, saludos.
En lugar de ejecutar
Enviado por fprior (no verificado) el
En lugar de ejecutar
python setup.py build
hay que ejecutar
python setup.py install
Saludos.
segui todos los pasos pero no bloque las ip
Enviado por hugo (no verificado) el
segui todos los pasos pero no bloque las ip, tengo freepbx 2.11 y asterisk 11.11.0 y fail2ban 0.8.13
[root@ ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
fail2ban-SSHDDOS tcp -- anywhere anywhere tcp dpt:ssh
fail2ban-asterisk-tcp tcp -- anywhere anywhere multipo rt dports sip,sip-tls
fail2ban-asterisk-udp udp -- anywhere anywhere multipo rt dports sip,sip-tls
fail2ban-SSH tcp -- anywhere anywhere tcp dpt:ssh
fail2ban-mysql tcp -- anywhere anywhere tcp dpt:mysql
ACCEPT udp -- anywhere anywhere udp dpts:ndmp:dnp
ACCEPT udp -- anywhere anywhere udp dpt:sip
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere loopback/8 reject-with icmp-po rt-unreachable
ACCEPT all -- anywhere anywhere state RELATED,ESTAB LISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:s sh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:s mtp
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:h ttp
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:h ttps
ACCEPT udp -- anywhere anywhere udp dpt:iax
ACCEPT icmp -- anywhere anywhere icmp echo-request
REJECT all -- anywhere anywhere reject-with icmp-po rt-unreachable
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-po rt-unreachable
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain fail2ban-SSH (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Chain fail2ban-SSHDDOS (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Chain fail2ban-asterisk-tcp (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Chain fail2ban-asterisk-udp (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Chain fail2ban-mysql (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere