Enviado por admin el
Una vez que tengamos el servidor con FusionPBX instalado en CentOS 6.7 64bit, seguimos con la configuración del cortafuegos; utilizaremos Iptables. Si el servidor viene con una configuración por defecto la quitamos y lo volvemos a configurar:
mv /etc/sysconfig/iptables /etc/sysconfig/iptables.old
service iptables restart
iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Iptables se encarga de gestionar todos los paquetes que entren y salgan del servidor Linux. Para eso utiliza tres tipos de tablas:
-
la tabla filter donde pasan todos los paquetes en entrada y salida. La tabla filter acepta tres tipos de opciones (cadenas):
-
INPUT para los paquetes en entrada
-
OUTPUT para los paquetes en salida
-
FORWARD para redireccionar los paquetes
-
la tabla NAT se utiliza para rescribir las direcciones y/o los puertos de los paquetes
-
la tabla MANGLE se utiliza para modificar algunos parámetros de los paquetes (un ejemplo es marcar los paquetes para que vengan procesados y enviados con una prioridad más alta)
Las reglas se definen una por línea y serán procesadas por IPTABLES siguiendo la misma secuencia.
Cuando no se especifica diversamente, todas las reglas aplican a la tabla filter.
Se acepta todo el trafico en entrada dirigido a la interfaz lookpack
iptables -A INPUT -i lo -j ACCEPT
Se rechaza (REJECT) todo el trafico entrante dirigido a las IP 127.0.0.0/127.255.255.255 menos los paquetes para la interfaz -lo
iptables -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
Se aceptan todos los paquetes en entrada de conexiones ya establecidas, o relacionados con conexiones establecidas. Véase protocolo TCP
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Se dejan pasar todos los paquetes salientes.
iptables -A OUTPUT -j ACCEPT
Se deja pasar todo el trafico en entrada para el protocolo SSH (puerto 22 tcp)
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
Se deja pasar todo el trafico en entrada para el protocolo Http y Https (servidor Web)
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
Se bloquea el trafico sobre el puerto 5060 procedente de los más conocidos programas de escaneo de servidores SIP utilizados para ataques y fraudes de llamadas:
iptables -A INPUT -p udp -m udp --dport 5060 -m string --string "friendly-scanner" --algo bm -j DROP
iptables -A INPUT -p udp -m udp --dport 5060 -m string --string "sipcli" --algo bm -j DROP
iptables -A INPUT -p udp -m udp --dport 5060 -m string --string "VaxSIPUserAgent" --algo bm -j DROP
iptables -A INPUT -p udp -m udp --dport 5060 -m string --string "sipvicious" --algo bm -j DROP
Se deja pasar todo el trafico en entrada destinado al puerto udp 5060 (protocolo SIP) utilizado por FreeSWITCH para registro y llamadas de las extensiones:
iptables -A INPUT -p udp --dport 5060 -j ACCEPT
Se bloquea el trafico sobre el puerto 5080 procedente de los más conocidos programas de escaneo de servidores SIP utilizados para ataques y fraudes de llamadas:
iptables -A INPUT -p udp -m udp --dport 5080 -m string --string "friendly-scanner" --algo bm -j DROP
iptables -A INPUT -p udp -m udp --dport 5080 -m string --string "sipcli" --algo bm -j DROP
iptables -A INPUT -p udp -m udp --dport 5080 -m string --string "VaxSIPUserAgent" --algo bm -j DROP
iptables -A INPUT -p udp -m udp --dport 5080 -m string --string "sipvicious" --algo bm -j DROP
Se deja pasar todo el trafico en entrada destinado al puerto udp 5080 (protocolo SIP) utilizado por FreeSWITCH para troncales entrantes/salientes:
iptables -A INPUT -p udp --dport 5080 -j ACCEPT
Se deja pasar todo el trafico en entrada destinado a los puertos udp que van de 16384 a 32768 (Flujo media o protocolo RTP). Puertos predefinidos de FreeSWITCH
iptables -A INPUT -p udp --dport 16384:32768 -j ACCEPT
Se dejan pasar las solicitudes de ping
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
Ahora que se han definido los puertos base que se necesitan abiertos, se bloquea todo el trafico restante.
iptables -A INPUT -j REJECT
iptables -A FORWARD -j REJECT
Se revisa la configuración:
iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- lo any anywhere anywhere
0 0 REJECT all -- !lo any anywhere loopback/8 reject-with icmp-port-unreachable
76 6616 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:ssh
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:http
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:https
0 0 DROP udp -- any any anywhere anywhere udp dpt:sip STRING match "friendly-scanner" ALGO name bm TO 65535
0 0 DROP udp -- any any anywhere anywhere udp dpt:sip STRING match "sipcli" ALGO name bm TO 65535
0 0 DROP udp -- any any anywhere anywhere udp dpt:sip STRING match "VaxSIPUserAgent" ALGO name bm TO 65535
0 0 DROP udp -- any any anywhere anywhere udp dpt:sip STRING match "sipvicious" ALGO name bm TO 65535
0 0 ACCEPT udp -- any any anywhere anywhere udp dpt:sip
0 0 DROP udp -- any any anywhere anywhere udp dpt:onscreen STRING match "friendly-scanner" ALGO name bm TO 65535
0 0 DROP udp -- any any anywhere anywhere udp dpt:onscreen STRING match "sipcli" ALGO name bm TO 65535
0 0 DROP udp -- any any anywhere anywhere udp dpt:onscreen STRING match "VaxSIPUserAgent" ALGO name bm TO 65535
0 0 DROP udp -- any any anywhere anywhere udp dpt:onscreen STRING match "sipvicious" ALGO name bm TO 65535
0 0 ACCEPT udp -- any any anywhere anywhere udp dpt:onscreen
0 0 ACCEPT udp -- any any anywhere anywhere udp dpts:connected:filenet-tms
0 0 ACCEPT icmp -- any any anywhere anywhere icmp echo-request
0 0 REJECT all -- any any anywhere anywhere reject-with icmp-port-unreachable
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REJECT all -- any any anywhere anywhere reject-with icmp-port-unreachable
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
56 7417 ACCEPT all -- any any anywhere anywhere
Se guarda:
service iptables save
Se reinicia el Cortafuegos:
service iptables restart
En la próxima parte veremos como aumentar la seguridad instalando y configurando fail2ban.
Comentarios recientes