blockt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/bash
  2. clear
  3. IP=$(wget -qO- ipv4.icanhazip.com)
  4. arq="/etc/Plus-torrent"
  5. echo -e "\E[44;1;37m FIREWALL BLOQUEIO TORRENT \E[0m"
  6. echo ""
  7. if [[ -e "$arq" ]]; then
  8. fun_fireoff () {
  9. iptables -P INPUT ACCEPT
  10. iptables -P OUTPUT ACCEPT
  11. iptables -P FORWARD ACCEPT
  12. iptables -t mangle -F
  13. iptables -t mangle -X
  14. iptables -t nat -F
  15. iptables -t nat -X
  16. iptables -t filter -F
  17. iptables -t filter -X
  18. iptables -F
  19. iptables -X
  20. rm $arq
  21. sleep 3
  22. }
  23. fun_spn1 () {
  24. helice () {
  25. fun_fireoff > /dev/null 2>&1 &
  26. tput civis
  27. while [ -d /proc/$! ]
  28. do
  29. for i in / - \\ \|
  30. do
  31. sleep .1
  32. echo -ne "\e[1D$i"
  33. done
  34. done
  35. tput cnorm
  36. }
  37. echo -ne "\033[1;31mREMOVENDO FIREWALL\033[1;32m.\033[1;33m.\033[1;31m. \033[1;32m"
  38. helice
  39. echo -e "\e[1DOk"
  40. }
  41. read -p "$(echo -e "\033[1;32mDESEJA REMOVER REGRAS FIREWALL? \033[1;33m[s/n]:\033[1;37m") " -e -i n resp
  42. if [[ "$resp" = 's' ]]; then
  43. echo ""
  44. fun_spn1
  45. echo ""
  46. echo -e "\033[1;33mTORRENT LIBERADO !\033[0m"
  47. echo ""
  48. echo -e "\033[1;32mFIREWALL REMOVIDO COM SUCESSO !"
  49. echo ""
  50. if [[ -e /etc/openvpn/openvpn-status.log ]]; then
  51. echo -e "\033[1;31m[\033[1;33m!\033[1;31m]\033[1;33m REINICIE O SISTEMA PRA CONCLUIR"
  52. echo ""
  53. read -p "$(echo -e "\033[1;32mREINICIAR AGORA \033[1;31m? \033[1;33m[s/n]:\033[1;37m ")" -e -i s respost
  54. echo ""
  55. if [[ "$respost" = 's' ]]; then
  56. echo -ne "\033[1;31mReiniciando"
  57. for i in $(seq 1 1 5); do
  58. echo -n "."
  59. sleep 01
  60. echo -ne ""
  61. done
  62. reboot
  63. fi
  64. fi
  65. sleep 2
  66. menu
  67. else
  68. sleep 1
  69. menu
  70. fi
  71. else
  72. echo -e "\033[1;31m[\033[1;33m!\033[1;31m]\033[1;33m FUNCAO BETA ULTILIZE POR SUA CONTA EM RISCO"
  73. echo ""
  74. read -p "$(echo -ne "\033[1;32mDESEJA APLICAR REGRAS FIREWALL ? \033[1;33m[s/n]:\033[1;37m") " -e -i n resp
  75. if [[ "$resp" = 's' ]]; then
  76. echo ""
  77. echo -ne "\033[1;33mPARA CONTINUAR CONFIRME SEU IP: \033[1;37m"; read -e -i $IP IP
  78. if [[ -z "$IP" ]];then
  79. echo ""
  80. echo -e "\033[1;31mIP invalido\033[1;32m"
  81. sleep 1
  82. echo ""
  83. read -p "Digite seu IP: " IP
  84. fi
  85. echo ""
  86. sleep 1
  87. fun_fireon () {
  88. mportas () {
  89. unset portas
  90. portas_var=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
  91. while read port; do
  92. var1=$(echo $port | awk '{print $1}') && var2=$(echo $port | awk '{print $9}' | awk -F ":" '{print $2}')
  93. [[ "$(echo -e $portas|grep "$var1 $var2")" ]] || portas+="$var1 $var2\n"
  94. done <<< "$portas_var"
  95. i=1
  96. echo -e "$portas"
  97. }
  98. [[ $(iptables -h|wc -l) -lt 5 ]] && apt-get install iptables -y > /dev/null 2>-1
  99. NIC=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | head -1)
  100. echo 'iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  101. iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  102. iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
  103. iptables -t filter -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT' > $arq
  104. echo 'iptables -A OUTPUT -p tcp --dport 53 -m state --state NEW -j ACCEPT
  105. iptables -A OUTPUT -p udp --dport 53 -m state --state NEW -j ACCEPT' >> $arq
  106. echo 'iptables -A OUTPUT -p tcp --dport 67 -m state --state NEW -j ACCEPT
  107. iptables -A OUTPUT -p udp --dport 67 -m state --state NEW -j ACCEPT' >> $arq
  108. list_ips=$(mportas|awk '{print $2}')
  109. while read PORT; do
  110. echo "iptables -A INPUT -p tcp --dport $PORT -j ACCEPT
  111. iptables -A INPUT -p udp --dport $PORT -j ACCEPT
  112. iptables -A OUTPUT -p tcp --dport $PORT -j ACCEPT
  113. iptables -A OUTPUT -p udp --dport $PORT -j ACCEPT
  114. iptables -A FORWARD -p tcp --dport $PORT -j ACCEPT
  115. iptables -A FORWARD -p udp --dport $PORT -j ACCEPT
  116. iptables -A OUTPUT -p tcp -d $IP --dport $PORT -m state --state NEW -j ACCEPT
  117. iptables -A OUTPUT -p udp -d $IP --dport $PORT -m state --state NEW -j ACCEPT" >> $arq
  118. done <<< "$list_ips"
  119. echo 'iptables -A INPUT -p icmp --icmp-type echo-request -j DROP' >> $arq
  120. echo 'iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
  121. iptables -A OUTPUT -p tcp --dport 10000 -j ACCEPT' >> $arq
  122. echo "iptables -t nat -A PREROUTING -i $NIC -p tcp --dport 6881:6889 -j DNAT --to-dest $IP
  123. iptables -A FORWARD -p tcp -i $NIC --dport 6881:6889 -d $IP -j REJECT
  124. iptables -A OUTPUT -p tcp --dport 6881:6889 -j DROP
  125. iptables -A OUTPUT -p udp --dport 6881:6889 -j DROP" >> $arq
  126. echo 'iptables -A FORWARD -m string --algo bm --string "BitTorrent" -j DROP
  127. iptables -A FORWARD -m string --algo bm --string "BitTorrent protocol" -j DROP
  128. iptables -A FORWARD -m string --algo bm --string "peer_id=" -j DROP
  129. iptables -A FORWARD -m string --algo bm --string ".torrent" -j DROP
  130. iptables -A FORWARD -m string --algo bm --string "announce.php?passkey=" -j DROP
  131. iptables -A FORWARD -m string --algo bm --string "torrent" -j DROP
  132. iptables -A FORWARD -m string --algo bm --string "announce" -j DROP
  133. iptables -A FORWARD -m string --algo bm --string "info_hash" -j DROP
  134. iptables -A FORWARD -m string --string "get_peers" --algo bm -j DROP
  135. iptables -A FORWARD -m string --string "announce_peer" --algo bm -j DROP
  136. iptables -A FORWARD -m string --string "find_node" --algo bm -j DROP' >> $arq
  137. sleep 2
  138. chmod +x $arq
  139. /etc/Plus-torrent > /dev/null
  140. }
  141. fun_spn2 () {
  142. helice () {
  143. fun_fireon > /dev/null 2>&1 &
  144. tput civis
  145. while [ -d /proc/$! ]
  146. do
  147. for i in / - \\ \|
  148. do
  149. sleep .1
  150. echo -ne "\e[1D$i"
  151. done
  152. done
  153. tput cnorm
  154. }
  155. echo -ne "\033[1;32mAPLICANDO FIREWALL\033[1;32m.\033[1;33m.\033[1;31m. \033[1;32m"
  156. helice
  157. echo -e "\e[1DOk"
  158. }
  159. fun_spn2
  160. echo ""
  161. echo -e "\033[1;33mBLOQUEIO\033[1;37m TORRENT \033[1;33mAPLICADO !\033[0m"
  162. echo ""
  163. echo -e "\033[1;32mFIREWALL APLICADO COM SUCESSO !"
  164. sleep 3
  165. menu
  166. else
  167. sleep 1
  168. menu
  169. fi
  170. fi