root/limitar-https/trunk/deny_https @ 420
6 | antoniojas | #! /bin/sh
|
|
#----------------------------------------------------------------------------------------
|
|||
# Antonio J. Abasolo Sierra (Mayo-2010)
|
|||
#----------------------------------------------------------------------------------------
|
|||
# Controla la activación/desactivación de reglas iptables
|
|||
# que cortan el tráfico https para todas las webs externas, e ips del centro
|
|||
# que indiquemos en su fichero de configuración.
|
|||
#
|
|||
205 | antoniojas | # Depende del fichero de configuración "/etc/network/deny_https".
|
|
6 | antoniojas | #
|
|
# La regla "iptables-restore < /etc/network/iptables" se pone por seguridad:
|
|||
# ya que se ejecuta tras eliminar las reglas, en cuyo momento la situación
|
|||
205 | antoniojas | # ya debería ser la misma que plantea esta línea.
|
|
6 | antoniojas | #----------------------------------------------------------------------------------------
|
|
205 | antoniojas | #----------------------------------------------------------------------------------------
|
|
6 | antoniojas | IPTABLES=/sbin/iptables
|
|
DENY_HTTPS=/etc/network/deny_https.conf
|
|||
RED=`ifconfig | grep Bcast | cut -f2 -d: | awk '{print }' | cut -f1 -d.`
|
|||
205 | antoniojas | #iptables -A FORWARD -p tcp --dport 443 -d WEB -j DROP
|
|
#iptables -A FORWARD -p tcp --dport 443 -s IP -j DROP
|
|||
12 | antoniojas | ||
6 | antoniojas | # Bail out if no iptables binary or no configuration
|
|
[ -x ${IPTABLES} -a "$DENY_HTTPS" ] || exit 0
|
|||
205 | antoniojas | clear
|
|
6 | antoniojas | #----------------------------------------------------------------------------------------
|
|
do_status() {
|
|||
echo ""
|
|||
echo "ESTADO ACTUAL DE LAS REGLAS ..."
|
|||
echo "----------------------------------------------------"
|
|||
$IPTABLES -L
|
|||
echo "----------------------------------------------------"
|
|||
}
|
|||
#----------------------------------------------------------------------------------------
|
|||
do_start() {
|
|||
echo "ACTIVANDO reglas para controlar el tráfico https:"
|
|||
echo "-------------------------------------------------"
|
|||
iptables-restore < /etc/network/iptables
|
|||
205 | antoniojas | egrep -v '#|^$' $DENY_HTTPS | awk '{print $1}' | while read LINEA; do
|
|
6 | antoniojas | if [ `echo $LINEA | grep $RED` ]; then OPCION="-s"; else OPCION="-d"; fi
|
|
echo " * Denegando https a $LINEA ..."
|
|||
$IPTABLES -A FORWARD -p tcp --dport 443 $OPCION $LINEA -j REJECT 2> /dev/null
|
|||
done
|
|||
205 | antoniojas | cortar_facebook
|
|
6 | antoniojas | echo " ----------------------------------------------"
|
|
echo " * EL TRAFICO HTTPS ESTA RESTRINGIDO."
|
|||
27 | antoniojas | echo ""
|
|
6 | antoniojas | }
|
|
do_stop() {
|
|||
echo "DESACTIVANDO reglas para controlar el tráfico https:"
|
|||
echo "-------------------------------------------------"
|
|||
205 | antoniojas | egrep -v '#|^$' $DENY_HTTPS | awk '{print $1}' | while read LINEA; do
|
|
6 | antoniojas | if [ `echo $LINEA | grep $RED` ]; then OPCION="-s"; else OPCION="-d"; fi
|
|
echo " * Eliminando regla https para $LINEA ..."
|
|||
$IPTABLES -D FORWARD -p tcp --dport 443 $OPCION $LINEA -j REJECT 2> /dev/null
|
|||
done
|
|||
205 | antoniojas | echo " * Eliminando reglas https para facebook (rangos) ..."
|
|
6 | antoniojas | iptables-restore < /etc/network/iptables
|
|
echo " -----------------------------------------------"
|
|||
echo " * EL TRAFICO HTTPS ESTA LIBERADO."
|
|||
27 | antoniojas | echo ""
|
|
6 | antoniojas | }
|
|
do_restart() {
|
|||
do_stop
|
|||
do_start
|
|||
}
|
|||
205 | antoniojas | cortar_facebook() {
|
|
iptables -N FACEBOOK
|
|||
echo " * Denegando https para facebook (rangos) ..."
|
|||
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 66.220.144.0-66.220.159.255 --dport 443 -j FACEBOOK
|
|||
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 69.63.176.0-69.63.191.255 --dport 443 -j FACEBOOK
|
|||
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 69.171.0.0-69.171.242.255 --dport 443 -j FACEBOOK
|
|||
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 184.50.162.0-184.50.162.255 --dport 443 -j FACEBOOK
|
|||
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 204.15.20.0-204.15.23.255 --dport 443 -j FACEBOOK
|
|||
iptables -A FACEBOOK -j REJECT
|
|||
}
|
|||
#----------------------------------------------------------------------------------------
|
|||
6 | antoniojas | case "$1" in
|
|
start)
|
|||
do_start
|
|||
27 | antoniojas | # do_status
|
|
6 | antoniojas | ;;
|
|
stop)
|
|||
do_stop
|
|||
27 | antoniojas | # do_status
|
|
6 | antoniojas | ;;
|
|
restart|force-reload)
|
|||
do_restart
|
|||
27 | antoniojas | # do_status
|
|
6 | antoniojas | ;;
|
|
status)
|
|||
do_status
|
|||
;;
|
|||
*)
|
|||
echo "Usage: $0 {start|stop|restart|force-reload|status}"
|
|||
exit 2
|
|||
;;
|
|||
esac
|
|||
exit 0
|
|||
205 | antoniojas | #----------------------------------------------------------------------------------------
|