Revisión 514
Añadido por Antonio J. Abasolo Sierra hace más de 11 años
limitar-https/trunk/deny_https.all | ||
---|---|---|
# Lista de web's https prohibidas para todos
|
||
www.tuenti.com
|
||
www.facebook.com
|
||
www.meebo.com
|
||
www.imo.im
|
||
www.badoo.com
|
||
www.twitter.com
|
||
www.hi5.com
|
||
www.suresome.com
|
||
www.bebo.com
|
||
www.ning.com
|
||
|
limitar-https/trunk/deny_https.sh | ||
---|---|---|
#!/bin/sh
|
||
|
||
RUTA=http://desarrollo.educarex.es/linex/projects/servidoressecundaria/repository/entry/limitar-https/trunk/
|
||
FICHERO=deny_https
|
||
|
||
# Descarga el script para tratar el tráfico https en los IES
|
||
wget -q -O $FICHERO $RUTA/$FICHERO?format=raw
|
||
|
||
chmod +x $FICHERO
|
||
mv $FICHERO /etc/init.d/
|
||
|
||
#update-rc.d $FICHERO defaults (nivel 20)
|
||
#if [ -e /etc/init.d/deny_https ] && [ -e /etc/rc2.d/S99deny_https ]; then
|
||
# update-rc.d -f $FICHERO remove 2>&1 /dev/null
|
||
#fi
|
||
|
||
update-rc.d $FICHERO start 31 2 3 4 5 . stop 31 0 1 6 .
|
||
|
||
# Descarga el fichero con webs iniciales a cortar
|
||
FICHERO=deny_https.all
|
||
wget -q -O $FICHERO $RUTA/$FICHERO?format=raw
|
||
if [ -e $FICHERO ]; then
|
||
cp $FICHERO /etc/network/deny_https.ies
|
||
fi
|
||
|
||
/etc/init.d/deny_https start
|
||
|
||
limitar-https/trunk/limitar_https.class | ||
---|---|---|
notify => Exec["configurar-https"]
|
||
}
|
||
|
||
file { "/etc/network/deny_https.ies":
|
||
file { "/etc/squid/acl/deny_https":
|
||
owner => root, group=>root, mode=>644,
|
||
ensure => exists,
|
||
notify => Exec["configurar-https"],
|
||
}
|
||
|
||
file { "/etc/init.d/deny_https":
|
||
file { "/etc/init.d/deny-https":
|
||
owner => root, group=>root, mode=>755,
|
||
source => "puppet:///puppet.educarex.es/files/deny_https",
|
||
source => "puppet:///puppet.educarex.es/files/deny-https",
|
||
notify => Exec["configurar-https"],
|
||
}
|
||
|
||
exec { "configurar-https":
|
||
command => "/usr/sbin/update-rc.d deny_https start 31 2 3 4 5 . stop 01 0 1 6 . ; /etc/init.d/deny_https start",
|
||
require => File["/etc/init.d/deny_https"],
|
||
unless => "/bin/ls /etc/rc2.d/S31deny_https",
|
||
command => "/usr/sbin/update-rc.d deny-https start 31 2 3 4 5 . stop 01 0 1 6 . ; /etc/init.d/deny-https start",
|
||
require => File["/etc/init.d/deny-https"],
|
||
unless => "/bin/ls /etc/rc2.d/S31deny-https",
|
||
refreshonly => true,
|
||
}
|
||
|
limitar-https/trunk/deny-https | ||
---|---|---|
#! /bin/sh
|
||
### BEGIN INIT INFO
|
||
# Provides: deny-https
|
||
# Required-Start: $all
|
||
# Required-Stop:
|
||
# Default-Start: 2 3 4 5
|
||
# Default-Stop: 0 1 6
|
||
# Short-Description: Denegar el tráfico https (puerto 443)
|
||
# Description: Deniega la navegación web segura, no controlada por squid.
|
||
### END INIT INFO
|
||
#----------------------------------------------------------------------------------------
|
||
# Creado por: Antonio J. Abasolo Sierra (Mayo-2010)
|
||
# Modificado por:
|
||
# - Francisco Rodrigo López (Oct-2011)
|
||
# - Antonio J. Abasolo Sierra (Mar-2012)
|
||
#----------------------------------------------------------------------------------------
|
||
# 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.
|
||
#
|
||
# Depende del fichero de configuración "/etc/squid/acl/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.
|
||
# Con esto también nos garantizamos que partimos y dejamos la situación justo
|
||
# donde estaba antes de iniciar/parar este script, por lo que es muy importante
|
||
# el contenido de dicho archivo, el cual se aconseja que esté tal cual nos lo dejaron, sin cambios.
|
||
#
|
||
# Se incluye cortar el tráfico facebook mediante rangos. Si no se desea cortar basta con comentar
|
||
# la línea donde se encuentra la llamada a dicha función.
|
||
# También se puede dar permiso en facebook a un rango de ip's, y denegarselo al resto.
|
||
#
|
||
#----------------------------------------------------------------------------------------
|
||
|
||
#----------------------------------------------------------------------------------------
|
||
# Ubicación del ejecutable de iptables
|
||
IPTABLES=/sbin/iptables
|
||
|
||
# Ubicación del fichero con web https a cortar
|
||
DENY_HTTPS=/etc/squid/acl/deny_https
|
||
|
||
RED=`ifconfig eth0 | grep Bcast | cut -f2 -d: | cut -f1 -d.`
|
||
|
||
#iptables -A FORWARD -p tcp --dport 443 -d WEB -j DROP
|
||
#iptables -A FORWARD -p tcp --dport 443 -s IP -j DROP
|
||
|
||
# Bail out if no iptables binary or no configuration
|
||
[ -x ${IPTABLES} -a "$DENY_HTTPS" ] || exit 0
|
||
|
||
clear
|
||
|
||
#----------------------------------------------------------------------------------------
|
||
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
|
||
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
|
||
|
||
#aceptar_facebook --> hay que definir el rango de ip's al que se le permite (RANGO_LIBRE): ver código
|
||
cortar_facebook
|
||
cortar_twitter
|
||
|
||
echo " ----------------------------------------------"
|
||
echo " * EL TRAFICO HTTPS ESTA RESTRINGIDO."
|
||
echo ""
|
||
}
|
||
|
||
do_stop() {
|
||
echo "DESACTIVANDO reglas para controlar el tráfico https:"
|
||
echo "-------------------------------------------------"
|
||
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) ..."
|
||
echo " * Eliminando reglas https para twitter (rangos) ..."
|
||
iptables-restore < /etc/network/iptables
|
||
echo " -----------------------------------------------"
|
||
echo " * EL TRAFICO HTTPS ESTA LIBERADO."
|
||
echo ""
|
||
}
|
||
|
||
do_restart() {
|
||
do_stop
|
||
do_start
|
||
}
|
||
|
||
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
|
||
}
|
||
|
||
aceptar_facebook() {
|
||
iptables -N AFACEBOOKSI
|
||
RANGO_LIBRE=172.x1.y1.z1-172.x2.y2.z2
|
||
echo " * Activando salida para facebook para $RANGO_LIBRE ... "
|
||
iptables -I FORWARD 1 -m tcp -p tcp -m iprange --src-range $RANGO_LIBRE -m iprange --dst-range 66.220.144.0-66.220.159.255 --dport 443 -j AFACEBOOKSI
|
||
iptables -I FORWARD 2 -m tcp -p tcp -m iprange --src-range $RANGO_LIBRE -m iprange --dst-range 69.63.176.0-69.63.191.255 --dport 443 -j AFACEBOOKSI
|
||
iptables -I FORWARD 3 -m tcp -p tcp -m iprange --src-range $RANGO_LIBRE -m iprange --dst-range 69.171.0.0-69.171.242.255 --dport 443 -j AFACEBOOKSI
|
||
iptables -I FORWARD 4 -m tcp -p tcp -m iprange --src-range $RANGO_LIBRE -m iprange --dst-range 184.50.162.0-184.50.162.255 --dport 443 -j AFACEBOOKSI
|
||
iptables -I FORWARD 5 -m tcp -p tcp -m iprange --src-range $RANGO_LIBRE -m iprange --dst-range 204.15.20.0-204.15.23.255 --dport 443 -j AFACEBOOKSI
|
||
|
||
iptables -A AFACEBOOKSI -j ACCEPT
|
||
}
|
||
|
||
cortar_twitter() {
|
||
iptables -N TWITTER
|
||
echo " * Denegando https para twitter (rangos) ..."
|
||
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 199.59.148.0-199.59.150.255 --dport 443 -j TWITTER
|
||
|
||
iptables -A TWITTER -j REJECT
|
||
}
|
||
|
||
#----------------------------------------------------------------------------------------
|
||
case "$1" in
|
||
start)
|
||
do_start
|
||
# do_status
|
||
;;
|
||
stop)
|
||
do_stop
|
||
# do_status
|
||
;;
|
||
restart|force-reload)
|
||
do_restart
|
||
# do_status
|
||
;;
|
||
status)
|
||
do_status
|
||
;;
|
||
*)
|
||
echo "Usage: $0 {start|stop|restart|force-reload|status}"
|
||
exit 2
|
||
;;
|
||
esac
|
||
exit 0
|
||
#----------------------------------------------------------------------------------------
|
||
|
||
limitar-https/trunk/deny_https | ||
---|---|---|
#! /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.
|
||
#
|
||
# 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.
|
||
#----------------------------------------------------------------------------------------
|
||
# Lista de web's https prohibidas para todos
|
||
www.tuenti.com
|
||
www.imo.im
|
||
www.badoo.com
|
||
www.twitter.com
|
||
www.hi5.com
|
||
www.suresome.com
|
||
www.bebo.com
|
||
www.ning.com
|
||
www.pornhub.com
|
||
|
||
#----------------------------------------------------------------------------------------
|
||
IPTABLES=/sbin/iptables
|
||
DENY_HTTPS=/etc/network/deny_https.conf
|
||
RED=`ifconfig | grep Bcast | cut -f2 -d: | awk '{print }' | cut -f1 -d.`
|
||
199.59.148.82
|
||
62.171.224.11
|
||
|
||
#iptables -A FORWARD -p tcp --dport 443 -d WEB -j DROP
|
||
#iptables -A FORWARD -p tcp --dport 443 -s IP -j DROP
|
||
|
||
# Bail out if no iptables binary or no configuration
|
||
[ -x ${IPTABLES} -a "$DENY_HTTPS" ] || exit 0
|
||
|
||
clear
|
||
|
||
#----------------------------------------------------------------------------------------
|
||
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
|
||
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 "-------------------------------------------------"
|
||
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."
|
||
echo ""
|
||
}
|
||
|
||
do_restart() {
|
||
do_stop
|
||
do_start
|
||
}
|
||
|
||
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
|
||
# do_status
|
||
;;
|
||
stop)
|
||
do_stop
|
||
# do_status
|
||
;;
|
||
restart|force-reload)
|
||
do_restart
|
||
# do_status
|
||
;;
|
||
status)
|
||
do_status
|
||
;;
|
||
*)
|
||
echo "Usage: $0 {start|stop|restart|force-reload|status}"
|
||
exit 2
|
||
;;
|
||
esac
|
||
exit 0
|
||
#----------------------------------------------------------------------------------------
|
||
|
||
#facebook.com
|
||
#www.facebook.com
|
||
#www.meebo.com
|
Exportar a: Unified diff
limitar-https