Revisión 205
Añadido por Antonio J. Abasolo Sierra hace más de 13 años
limitar-https/trunk/deny_https | ||
---|---|---|
# que cortan el tráfico https para todas las webs externas, e ips del centro
|
||
# que indiquemos en su fichero de configuración.
|
||
#
|
||
# Depende del fichero de configuración "/etc/network/deny_https.conf",
|
||
# el cual se genera a partir del fichero "/etc/network/deny_https.all"
|
||
# obtenido del repositorio general, mas el fichero "/etc/network/deny_https.ies",
|
||
# el cual será modificado por cada IES según sus necesidades.
|
||
# Dichos ficheros podrán tener dos tipos de líneas (no importa el orden):
|
||
# - web's de destino que queremos bloquear vía https
|
||
# iptables -A FORWARD -p tcp --dport 443 -d WEB -j REJECT
|
||
# - ip's de equipos locales del IES a los que queremos restringir el tráfico https
|
||
# iptables -A FORWARD -p tcp --dport 443 -s IP -j REJECT
|
||
# Depende del fichero de configuración "/etc/network/deny_https".
|
||
#
|
||
# 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
|
||
# ya debería ser la misma que plantea esta línea; y justo antes de añadir las reglas,
|
||
# para garantizar que partimos del estado inicial.
|
||
# Dicho fichero, a partir de ahora, se gestionará vía puppet para garantizar el mismo
|
||
# contenido en todos los IES.
|
||
# ya debería ser la misma que plantea esta línea.
|
||
#----------------------------------------------------------------------------------------
|
||
|
||
# Variables
|
||
#----------------------------------------------------------------------------------------
|
||
IPTABLES=/sbin/iptables
|
||
FICHERO=deny_https.all
|
||
DENY_HTTPS=/etc/network/deny_https.conf
|
||
DENY_HTTPS_ALL=/etc/network/$FICHERO
|
||
DENY_HTTPS_IES=/etc/network/deny_https.ies
|
||
RUTA=http://desarrollo.educarex.es/linex/projects/servidoressecundaria/repository/entry/limitar-https/trunk
|
||
#RUTA=http://172.16.16.254/linex/projects/servidoressecundaria/repository/entry/limitar-https/trunk
|
||
RED=`ifconfig | grep Bcast | cut -f2 -d: | awk '{print }' | cut -f1 -d.`
|
||
#----------------------------------------------------------------------------------------
|
||
|
||
# Descarga el fichero general de https a denegar por todos los IES
|
||
#if [ -s $DENY_HTTPS_ALL ]; then mv $DENY_HTTPS_ALL $DENY_HTTPS_ALL.old; fi
|
||
#wget -T 10 -q -O $DENY_HTTPS_ALL $RUTA/$FICHERO?format=raw
|
||
#if [ ! -s $DENY_HTTPS_ALL ]; then
|
||
# if [ -s $DENY_HTTPS_ALL.old ]; then
|
||
# cat $DENY_HTTPS_ALL.old >> $DENY_HTTPS_ALL
|
||
# fi
|
||
#fi
|
||
#iptables -A FORWARD -p tcp --dport 443 -d WEB -j DROP
|
||
#iptables -A FORWARD -p tcp --dport 443 -s IP -j DROP
|
||
|
||
if [ ! -f $DENY_HTTPS_ALL ]; then touch $DENY_HTTPS_ALL; fi
|
||
|
||
# Unimos y filtramos los ficheros de configuración
|
||
cat $DENY_HTTPS_ALL $DENY_HTTPS_IES | egrep -v '#|^$' | awk '{print $1}' | sort | uniq > $DENY_HTTPS
|
||
|
||
# Bail out if no iptables binary or no configuration
|
||
[ -x ${IPTABLES} -a "$DENY_HTTPS" ] || exit 0
|
||
#----------------------------------------------------------------------------------------
|
||
|
||
clear
|
||
|
||
#----------------------------------------------------------------------------------------
|
||
do_status() {
|
||
echo ""
|
||
... | ... | |
echo "ACTIVANDO reglas para controlar el tráfico https:"
|
||
echo "-------------------------------------------------"
|
||
iptables-restore < /etc/network/iptables
|
||
cat $DENY_HTTPS | while read LINEA; do
|
||
egrep -v '#|^$' $DENY_HTTPS | awk '{print $1}' | while read LINEA; do
|
||
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
|
||
cortar_facebook
|
||
echo " ----------------------------------------------"
|
||
echo " * EL TRAFICO HTTPS ESTA RESTRINGIDO."
|
||
echo ""
|
||
... | ... | |
do_stop() {
|
||
echo "DESACTIVANDO reglas para controlar el tráfico https:"
|
||
echo "-------------------------------------------------"
|
||
cat $DENY_HTTPS | while read LINEA; do
|
||
egrep -v '#|^$' $DENY_HTTPS | awk '{print $1}' | while read LINEA; do
|
||
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
|
||
echo " * Eliminando reglas https para facebook (rangos) ..."
|
||
iptables-restore < /etc/network/iptables
|
||
echo " -----------------------------------------------"
|
||
echo " * EL TRAFICO HTTPS ESTA LIBERADO."
|
||
... | ... | |
do_start
|
||
}
|
||
|
||
# INICIO --------------------------------------------------------------------------------
|
||
clear
|
||
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
|
||
}
|
||
|
||
#----------------------------------------------------------------------------------------
|
||
case "$1" in
|
||
start)
|
||
do_start
|
||
... | ... | |
;;
|
||
esac
|
||
exit 0
|
||
# FIN -----------------------------------------------------------------------------------
|
||
#----------------------------------------------------------------------------------------
|
||
|
Exportar a: Unified diff
Añadido cortar facebook por rangos de ip's