jueves, 22 de diciembre de 2016

BLOKEO A FACEBOOK por IPs desde DEBIAN (AUTOMATICO, cada vez que encienda y cada hora)




#1 bloque al inicio


editamos  con la terminal desde ROOT



#  nano  /etc/rc.local
 
 
 #### FIN SCRIPT #### 
 
 #!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing. 
 #default 
 
 
 
# BLOQUEANDO FACE 1
 
 iptables -A OUTPUT -p tcp -d www.facebook.com -j DROP
iptables -A OUTPUT -p tcp -d facebook.com -j DROP
iptables -A OUTPUT -p tcp -d 173.252.64.0/18  -j DROP

******************************

# BLOQUEANDO FACE 2

iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 66.220.144.0-66.220.159.255 --dport 443 -j DROP && echo " regla-03 ok"
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 69.63.176.0-69.63.191.255 --dport 443 -j DROP && echo " regla-04 ok"
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 204.15.20.0-204.15.23.255 --dport 443 -j DROP && echo " regla-05 ok"
iptables -I FORWARD -p tcp -m string --string www.facebook.com --dport 443 --algo bm -j DROP && echo " regla-06 ok"
iptables -A FORWARD -s www.facebook.com -p tcp --dport 443 -j DROP && echo " regla-08 ok"

********
iptables -I FORWARD -p tcp -m string --string "facebook" --algo bm -j DROP



# BLOQUEANDO FACE 3

iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 66.220.144.0-66.220.159.255 --dport 443 -j DROP
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 69.63.176.0-69.63.191.255 --dport 443 -j DROP
iptables -I FORWARD -m tcp -p tcp -m iprange --dst-range 204.15.20.0-204.15.23.255 --dport 443 -j DROP
iptables -I FORWARD -p tcp -m string --string www.facebook.com --dport 443 --algo bm -j DROP
iptables -A FORWARD -s www.facebook.com -p tcp --dport 443 -j DROP


# bloquear FACE 4 
/usr/bin/whois -h whois.radb.net '!gAS32934' | head -n -1 | tail -n -1 | /usr/bin/xargs --max-args=1 | /usr/bin/xargs -I {} --max-args=1 /sbin/iptables -t mangle -I POSTROUTING -d {} -j DROP

 

exit 0
 
#### FIN SCRIPT #### 
### NOTA:  MUY IMPORTANTE AL FINAL TIENE QUE DECIR  "exit 0" ############
 
 
 
 
 
#2 bloque CADA HORA
    esto con el fin de revisar ,
 en caso que facebook saque otra ip nueva 
 
hacemos un script  con el mismo  contenido que  /etc/rc.local 
en algun folder  con acceso a root 
 
mas informacion; el sigueinte link
http://blog.desdelinux.net/cron-crontab-explicados/ 
 
 
 
 /algun/folder-con-accesosolo-ROOT/./nofb.sh
EJEMPLO EN RAIZ
# mkdir /alex-programas 
 
/alex-programas/./nofb.sh
 
 
editamos y agregamos el script a CRON
para que se ejecute el scrip cada hora
(en mi caso lo puse a los 15 min de cada hora 7:15  8:15 9:15,etc)   
 
 
nano /etc/crontab
 
 
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root    cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

15 *  * * * root  /algun/folder-con-accesosolo-ROOT/./nofb.sh
 
 
 ########  FIN   SCRIPT  #####
 #### NOTA:   ES OBLIGATORIO PORNER EL PUNTO antes del script      ...."/./"nofb.sh  ###
  #### NOTA 2:  algun folder donde , solo root tenga acceso, y asi lo usuarios normales no lo editen ###
 
 
 
 
#3  DESBLOQUEO 
en caso que los usuarios  ROOT  nesecitemos desbloquear el FACEBOOK 
 
de misma manera  hacer un script  en 
 
 /algun/folder-con-accesosolo-ROOT/./sifb.sh 
 
 
 
 
 
####INICI  SCRIPT #### 
 



#!/bin/bash


echo "permitiendo FACEBOOK..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

sleep 1
Verificar con iptables -L
 beep && beep && beep 


exit 0
 
 #####   fin  ##
 
 
 
 

No hay comentarios:

Publicar un comentario

Donarme :->

Donar a AlexLikeRock
muchas gracias por tu ayuda :->

2022

stand by ... PD: "Viva México!"