Advertisement
YeiZeta

Ban Facebook SSL Script 1.0

Oct 8th, 2012
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. Esta herramienta se baja todo bloques de red de acceso y bloqueo de Facebook al sitio vía IPTables.
  2. ----------------------------------------------------------------------------------------------------------
  3.  
  4. #!/bin/bash
  5. #
  6. #############################################################################
  7. #
  8. # Copyright (C) 2012 Alexandru Cuciureanu
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. #############################################################################
  24.  
  25. IPT="iptables"
  26. BACKUP_FILENAME="iptables.backup.$(date +"%d%m%y%H%M%S")"
  27. RULE_TAG="ANTI-FACEBOOK-RULE"
  28. IPTABLES_RULE_FILENAME="iptables"
  29.  
  30. # clear up the screen and showoff the brand
  31.  
  32. clear
  33.  
  34. echo ' ___________ '
  35. echo -e ' |.---------.| \e[1;41m_____,BAN FACEBOOK SSL,____\e[00m'
  36. echo -e ' || || \e[1;41m ! TO EMPLOYERS ONLY ! \e[00m '
  37. echo -e ' || \e[1;33m BFSSL \e[00m || '
  38. echo -e ' || || \e[1;32mTHIS WILL INCREASE THE PRODUCTIVITY\e[00m '
  39. echo -e ' |`---------' '| \e[1;32mDROP THE ACCESS THROUGH SSL TO FACEBOOK!\e[00m '
  40. echo ' `)__ ____(; '
  41. echo ' [=== -- o ]--. author: Alexandru Cuciureanu '
  42. echo ' __' '---------' '__ \ greetings to: Gabriel Buleac (best sysadmin) '
  43. echo ' [::::::::::: :::] ) '
  44. echo ' `"""""""""""""`/T\ contact me: alexandru.cuciureanu[at]gmail.com '
  45. echo ' \_/ '
  46. echo
  47.  
  48. # dumping the ip4v classes of Facebook.com
  49.  
  50. echo -ne "[+] Welcome to BAN FACEBOOK SSL !!!\n"
  51.  
  52. # Checking if the Linux distro is CentOS
  53. echo -n "[*] Verifying if this is CentOS..."
  54. if cat /etc/*-release | grep CentOS >/dev/null 2>&1 ; then
  55. echo -e "\t[\e[01;32mVERSION OK\e[00m]"
  56. else
  57. echo -e "\t[\e[01;31mThis is NOT CentOS\e[00m]"
  58. exit 1
  59. fi
  60.  
  61. # Checking if there's wget installed on the machine, otherwise
  62. # BAN-FACEBOOK-SSL will install it for the user
  63.  
  64. hash wget &> /dev/null
  65. if [ $? -eq 1 ]; then
  66. echo -ne "\tInstalling wget on your machine..."
  67. yum -q -y install wget
  68. if (( !$? )); then
  69. echo -e "\t[\e[01;32mDONE\e[00m]"
  70. else
  71. echo -e "\t[\e[01;31mFAILED\e[00m]"
  72. echo -n "Please install wget to make BAN FACEBOOK SSL work. :)"
  73. exit 1
  74. fi
  75. fi
  76. echo -n "[+] Downloading the classes of Facebook.com..."
  77. wget -q -O ipv4_fb_classes.yaml http://stat.ripe.net/data/prefix-list/AS32934
  78. if (( $? )); then
  79. echo -e "\t[\e[01;31mFAILED\e[00m]"
  80. exit 1
  81. else
  82. echo -e "\t[\e[01;32mDONE\e[00m]"
  83. fi
  84. echo -ne "\t[~] Dumping classes..."
  85. cat ipv4_fb_classes.yaml | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,3}' > ipv4_fb_classes.res
  86. if (( !$? )); then
  87. echo -e "\t[\e[01;32mDONE\e[00m]"
  88. else
  89. echo -e "\t[\e[01;31mFAILED\e[00m]"
  90. exit 1
  91. fi
  92. rm -rf ipv4_fb_classes.yaml
  93.  
  94. ###############################################################
  95.  
  96. if [ -f $IPTABLES_RULE_FILENAME ]; then
  97.  
  98. #check if Anti-Facebook RULE is applied
  99. if grep -q "ANTI-FACEBOOK-RULE" iptables.save
  100. then
  101. echo -e "\e[41m\e[1;37mAnti\e[00m\e[44mFacebook\e[00m \e[01;32mSSL Rules are applied!\e[00m"
  102. exit 1
  103. fi
  104. fi
  105. # let's backup iptables.conf to the local folder
  106.  
  107. echo -en "\n[+] Creating backup of iptables.conf to the local folder..."
  108. iptables-save > backups/$BACKUP_FILENAME
  109. echo -e "\t[\e[01;32mDONE\e[00m]"
  110.  
  111. # setting rules for iptables to DROP the Facebook classes
  112.  
  113. ipv4_class_dump=( $(< "ipv4_fb_classes.res" ) )
  114. ipv4_class_dump_size="${#ipv4_class_dump[@]}"
  115.  
  116. if ! iptables -L "ANTI-FACEBOOK-CHAIN" -n >/dev/null 2>&1 ; then
  117. echo -ne "\t\e[-1;31m[!] ANTI-FACEBOOK-CHAIN doesn't exist!\e[00m\n"
  118. sleep 0.5
  119. echo -ne "\t[>] Creating ANTI-FACEBOOK-CHAIN..."
  120. iptables -N "ANTI-FACEBOOK-CHAIN" >/dev/null 2>&1
  121. if (( !$? )); then
  122. echo -e "\t[\e[01;32mDONE\e[00m]"
  123. iptables -t filter -A OUTPUT -j ANTI-FACEBOOK-CHAIN #adding a jump to our ANTI-FACEBOOK-CHAIN
  124. echo -ne "\t[+] Adding the jump to our ANTI-FACEBOOK-CHAIN..."
  125. if (( !$? )) ; then
  126. echo -e "\t[\e[01;32mDONE\e[00m]"
  127. else
  128. echo -e "\t[\e[01;31mFAILED\e[00m]"
  129. fi
  130. else
  131. echo -e "\t[\e[01;31mFAILED\e[00m]"
  132. echo -ne "FAILED to write the ANTI-FACEBOOK-CHAIN in iptables."
  133. exit 1
  134. fi
  135. else
  136. echo -ne "{!} There are ANTI-FACEBOOK-RULEs applied already.\nPlease double check and try again!\n"
  137. rm -rf ipv4_fb_classes.res
  138. exit 1
  139. fi
  140. for ((i=0;i<$ipv4_class_dump_size;i++));
  141. do
  142. echo -ne "\t[+] Setting up blocking rule for class" ${ipv4_class_dump[${i}]}
  143. $IPT -A ANTI-FACEBOOK-CHAIN -p tcp --destination ${ipv4_class_dump[${i}]} --dport 443 -m comment --comment "ANTI-FACEBOOK-RULE" -j DROP
  144. sleep 0.10
  145.  
  146. if (( !$? )); then
  147. echo -e "\t[\e[01;32mOK\e[00m]"
  148. else
  149. echo -e "\t[\e[01;31mFAILED\e[00m]"
  150. fi
  151. done
  152. rm -rf ipv4_fb_classes.res
  153. # do you want to save iptables?
  154. echo -n "Would you like to save iptables? (y/n) "
  155. read yn
  156.  
  157. if [ "$yn" == "y" ] ; then
  158. echo -ne "\t[+] Initiating iptables-save..."
  159. ## service iptables save
  160. echo -e "\t[\e[01;32mPROCEEDING\e[00m]"
  161. service iptables save
  162. echo -n "Do you want to restart your firewall now? (y/n) "
  163. read restartfwyn
  164. if [ "$restartfwyn" == "y" ] ; then
  165. service iptables restart
  166. fi
  167. else
  168. echo -ne "GoodBye!\n"
  169. exit 1
  170. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement