Práctica 5 Firewall y OpenVPN Alexandre Ramilo Conde Pablo Prol Sobrado
Shorewall Se busca configurar las siguientes reglas: 1. Enmascaramiento (SNAT) de la red interna (10.10.10.0/24) y de la DMZ (10.20.20.0/24) 2. Redireccionamiento (DNAT) de los servicios públicos que ofrecerá la red hacia la máquina dentro (10.20.20.22) de la DMZ a. peticiones WEB (http y https) b. tráfico de correo saliente (smtp) y entrante (pop3) 3. Control de tráfico con política ''denegar por defecto'' (DROP) a. desde la red externa sólo se permiten las conexiones hacia la DMZ contempladas en las redirecciones del punto anterior (http, https, smtp, pop3) b. desde la red interna hacia la red externa sólo se permite tráfico de tipo WEB y SSH c. desde la red interna hacia la DMZ sólo se permite tráfico WEB (http, https), e- mail (smtp, pop3) y SSH d. desde la máquina dmz (10.20.20.22) se permiten conexiones MySQL hacia la máquina dentro (10.10.10.11) de la red interna e. se permite la salida a la red externa de las consultas DNS originadas en la red interna f. firewall sólo admite conexiones SSH desde la red interna 4. Registro (log) de intentos de acceso no contemplados desde red externa a firewall3 (193.147.87.47) y a equipos internos con la etiqueta Acceso no autorizado Configuramos shorewall según las instrucciones de la práctica, y chequeamos la configuración de iptables que se ha generado, obteniendo: Chain INPUT (policy DROP) dynamic all -- anywhere anywhere ctstate INVALID,NEW net2fw all -- anywhere anywhere loc2fw all -- anywhere anywhere dmz2fw all -- anywhere anywhere ACCEPT all -- anywhere anywhere `Shorewall:INPUT:REJECT:' Chain FORWARD (policy DROP) dynamic all -- anywhere anywhere ctstate INVALID,NEW
TCPMSS tcp -- anywhere anywhere tcp flags:syn,rst/syn TCPMSS clamp to PMTU net_frwd all -- anywhere anywhere loc_frwd all -- anywhere anywhere dmz_frwd all -- anywhere anywhere `Shorewall:FORWARD:REJECT:' Chain OUTPUT (policy DROP) fw2net all -- anywhere anywhere fw2loc all -- anywhere anywhere fw2dmz all -- anywhere anywhere ACCEPT all -- anywhere anywhere `Shorewall:OUTPUT:REJECT:' Chain Drop (4 references) all -- anywhere anywhere reject tcp -- anywhere anywhere tcp dpt:auth /* Auth */ dropbcast all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere icmp fragmentation-needed /* Needed ICMP types */ ACCEPT icmp -- anywhere anywhere icmp time-exceeded /* Needed ICMP types */ dropinvalid all -- anywhere anywhere DROP udp -- anywhere anywhere multiport dports loc-srv,microsoft-ds /* SMB */ DROP udp -- anywhere anywhere udp dpts:netbios-ns:netbios-ssn /* SMB */ DROP udp -- anywhere anywhere udp spt:netbios-ns dpts:1024:65535 /* SMB */ DROP tcp -- anywhere anywhere multiport dports loc-srv,netbiosssn,microsoft-ds /* SMB */ DROP udp -- anywhere anywhere udp dpt:1900 /* UPnP */ dropnotsyn tcp -- anywhere anywhere DROP udp -- anywhere anywhere udp spt:domain /* Late DNS Replies */
Chain Reject (11 references) all -- anywhere anywhere reject tcp -- anywhere anywhere tcp dpt:auth /* Auth */ dropbcast all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere icmp fragmentation-needed /* Needed ICMP types */ ACCEPT icmp -- anywhere anywhere icmp time-exceeded /* Needed ICMP types */ dropinvalid all -- anywhere anywhere reject udp -- anywhere anywhere multiport dports loc-srv,microsoft-ds /* SMB */ reject udp -- anywhere anywhere udp dpts:netbios-ns:netbios-ssn /* SMB */ reject udp -- anywhere anywhere udp spt:netbios-ns dpts:1024:65535 /* SMB */ reject tcp -- anywhere anywhere multiport dports loc-srv,netbios-ssn,microsoftds /* SMB */ DROP udp -- anywhere anywhere udp dpt:1900 /* UPnP */ dropnotsyn tcp -- anywhere anywhere DROP udp -- anywhere anywhere udp spt:domain /* Late DNS Replies */ Chain dmz2fw (1 references) ACCEPT icmp -- anywhere anywhere icmp echo-request /* Ping */ `Shorewall:dmz2fw:REJECT:' Chain dmz2loc (1 references) ACCEPT icmp -- anywhere anywhere icmp echo-request /* Ping */ ACCEPT tcp -- dmz.ssi.net dentro.ssi.net tcp dpt:mysql `Shorewall:dmz2loc:REJECT:' Chain dmz2net (1 references)
ACCEPT icmp -- anywhere anywhere icmp echo-request /* Ping */ `Shorewall:dmz2net:REJECT:' Chain dmz_frwd (1 references) dmz2net all -- anywhere anywhere dmz2loc all -- anywhere anywhere Chain dropbcast (2 references) ADDRTYPE match dst-type BROADCAST DROP all -- anywhere 224.0.0.0/4 Chain dropinvalid (2 references) ctstate INVALID Chain dropnotsyn (2 references) DROP tcp -- anywhere anywhere tcp flags:!fin,syn,rst,ack/syn Chain dynamic (2 references) Chain fw2dmz (1 references) ACCEPT icmp -- anywhere anywhere `Shorewall:fw2dmz:REJECT:' Chain fw2loc (1 references) ACCEPT icmp -- anywhere anywhere
`Shorewall:fw2loc:REJECT:' Chain fw2net (1 references) ACCEPT udp -- anywhere anywhere udp dpts:bootps:bootpc ACCEPT udp -- anywhere anywhere udp dpt:domain /* DNS */ ACCEPT tcp -- anywhere anywhere tcp dpt:domain /* DNS */ ACCEPT icmp -- anywhere anywhere `Shorewall:fw2net:REJECT:' Chain loc2dmz (1 references) ACCEPT tcp -- anywhere anywhere tcp dpt:ssh /* SSH */ ACCEPT icmp -- anywhere anywhere icmp echo-request /* Ping */ ACCEPT tcp -- anywhere dmz.ssi.net multiport dports www,https ACCEPT tcp -- anywhere dmz.ssi.net multiport dports smtp,pop3 `Shorewall:loc2dmz:REJECT:' Chain loc2fw (1 references) ACCEPT tcp -- anywhere anywhere tcp dpt:ssh /* SSH */ ACCEPT icmp -- anywhere anywhere icmp echo-request /* Ping */ `Shorewall:loc2fw:REJECT:' Chain loc2net (1 references) ACCEPT tcp -- anywhere anywhere multiport dports www,https
ACCEPT udp -- anywhere anywhere udp dpt:domain /* DNS */ ACCEPT tcp -- anywhere anywhere tcp dpt:domain /* DNS */ Drop all -- anywhere anywhere Chain loc_frwd (1 references) loc2net all -- anywhere anywhere loc2dmz all -- anywhere anywhere Chain logdrop (0 references) Chain logflags (5 references) LOG all -- anywhere anywhere LOG level info ip-options prefix `Shorewall:logflags:DROP:' Chain logreject (0 references) reject all -- anywhere anywhere Chain net2dmz (1 references) ACCEPT tcp -- anywhere dmz.ssi.net multiport dports www,https ACCEPT tcp -- anywhere dmz.ssi.net multiport dports smtp,pop3 Drop all -- anywhere anywhere `Shorewall:net2dmz:DROP:' Chain net2fw (1 references) ACCEPT udp -- anywhere anywhere udp dpts:bootps:bootpc DROP icmp -- anywhere anywhere icmp echo-request /* Ping */ Drop all -- anywhere anywhere
`Shorewall:net2fw:DROP:' Chain net2loc (1 references) Drop all -- anywhere anywhere `Shorewall:net2loc:DROP:' Chain net_frwd (1 references) net2loc all -- anywhere anywhere net2dmz all -- anywhere anywhere Chain reject (18 references) ADDRTYPE match src-type BROADCAST DROP all -- 224.0.0.0/4 anywhere DROP igmp -- anywhere anywhere REJECT tcp -- anywhere anywhere reject-with tcp-reset REJECT udp -- anywhere anywhere reject-with icmp-port-unreachable REJECT icmp -- anywhere anywhere reject-with icmp-host-unreachable REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain shorewall (0 references) Chain smurflog (2 references) `Shorewall:smurfs:DROP:' Chain smurfs (6 references) RETURN all -- default anywhere smurflog all -- anywhere anywhere [goto] ADDRTYPE match src-type BROADCAST smurflog all -- 224.0.0.0/4 anywhere [goto] Chain tcpflags (6 references)
logflags tcp -- anywhere anywhere [goto] tcp flags:fin,syn,rst,psh,ack,urg/ FIN,PSH,URG logflags tcp -- anywhere anywhere [goto] tcp flags:fin,syn,rst,psh,ack,urg/ NONE logflags tcp -- anywhere anywhere [goto] tcp flags:syn,rst/syn,rst logflags tcp -- anywhere anywhere [goto] tcp flags:fin,syn/fin,syn logflags tcp -- anywhere anywhere [goto] tcp spt:0 flags:fin,syn,rst,ack/syn También comprobamos NAT, que nos devuelve: Chain PREROUTING (policy ACCEPT) dnat all -- anywhere anywhere Chain POSTROUTING (policy ACCEPT) eth2_masq all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) Chain dnat (1 references) net_dnat all -- anywhere anywhere Chain eth2_masq (1 references) MASQUERADE all -- 10.10.10.0/24 anywhere MASQUERADE all -- 10.20.20.0/24 anywhere Chain net_dnat (1 references) DNAT tcp -- anywhere anywhere multiport dports www,https to:10.20.20.22 DNAT tcp -- anywhere anywhere multiport dports smtp,pop3 to:10.20.20.22 OpenVPN (Enlace) Mediante certificados digitales, configuramos el enlace VP entre el servidor interno y los clientes que se quieran unir a la red desde la red externa (Desde internet). Se necesita: Para el servidor:
certificado digital de la Autoridad Certificadora (CA) reconocida por ambos participantes: cacert.crt clave privada del servidor: firewall3.key certificado digital del servidos: firewall3.crt (emitido por la CA) parámetros para intercambio de clave Diffie-Hellam: dh1024.pem Para cada uno de los clientes que se conecten con OpenVPN: certificado digital de la Autoridad Certificadora reconocida por ambos participantes: cacert.crt clave privada del servidor: fuera.key certificado digital del servidor: fuera.crt (emitido por la CA) En el sevidor, nos dispondremos a generar la autoridad certificadora, que una vez preconfigurada, podremos empezar a crear con el script /etc/openvpn/easy-rsa/#./build_ca. Aunque se ha usado este procedimiento, se podría también utilizar TinyCA que ofrece un interfaz gráfico sobre openssl para la gestión de autoridades de certificación y la generación de certificados digitales. Una vez realizado, copiamos los certificados a los directorios dentro del servidor y al cliente que quiera establecer el túnerl OpenVPN, y creamos y configuramos los archivos de configuración del cliente y del servidor, activamos el ip_forwarding en el servidor. Podremos ya activar el túnel OpenVPN para que se establezca la conexión. OpenVPN (Shorewall) Para que shorewall reconozca la OpenVPN, creamos una nueva zona en el fichero zones, asociando la interfaz virtual tun a dicha zona. Configuramos las políticas y reglas de shorwall para esta zona de manera similar a lo que se ha hecho con la red interna (Es decir, que tengan las mismas reglas y políticas).