ninja_retardado

firewall_iptables

Sep 13th, 2013
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.84 KB | None | 0 0
  1. #!/bin/bash
  2. # Este script pode ser usado em outras distribuicoes Linux que utilizam o Kernel 2.4 em diante
  3. # Por militares da secao de informatica bo 62 BI
  4.  
  5. firewall_start(){
  6.  
  7. # Compartilhando a conexao
  8. modprobe iptable_nat
  9. echo 1 > /proc/sys/net/ipv4/ip_forward
  10. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  11.  
  12. # Ativando proxy transparente
  13. iptables -t nat -A PREROUTING -i eth3 -p tcp --dport 80 -j REDIRECT --to-port 3128
  14.  
  15. # Abre para uma faixa de enderecos da rede local
  16. iptables -A INPUT -s 192.168.0.0/255.255.255.0 -j ACCEPT
  17.  
  18.  
  19. ###########################################################################
  20. #----- A regra abaixo bloqueia qualquer host da rede ao conectar no MSN --#
  21. ###########################################################################
  22.  
  23. # Bloqueando os Demais
  24. #iptables -A FORWARD -s 192.168.0.0/24 -p tcp --dport 1863 -j REJECT
  25. #iptables -A FORWARD -s 192.168.0.0/24 -d loginnet.passport.com -j REJECT
  26.  
  27.  
  28.  
  29. #-------------------------- Hosts Liberados ------------------------------#
  30.  
  31. # impressao
  32. #iptables -A FORWARD -s 192.168.0.3/24 -p tcp --dport 1863 -j ACCEPT
  33. #iptables -A FORWARD -s 192.168.0.3/24 -d loginnet.passport.com -j ACCEPT
  34.  
  35. # secinfoweb
  36. #iptables -A FORWARD -s 192.168.0.5/24 -p tcp --dport 1863 -j ACCEPT
  37. #iptables -A FORWARD -s 192.168.0.5/24 -d loginnet.passport.com -j ACCEPT
  38.  
  39. # secinfomnt
  40. #iptables -A FORWARD -s 192.168.0.7/24 -p tcp --dport 1863 -j ACCEPT
  41. #iptables -A FORWARD -s 192.168.0.7/24 -d loginnet.passport.com -j ACCEPT
  42.  
  43. # secinfochf
  44. #iptables -A FORWARD -s 192.168.0.8/24 -p tcp --dport 1863 -j ACCEPT
  45. #iptables -A FORWARD -s 192.168.0.8/24 -d loginnet.passport.com -j ACCEPT
  46.  
  47. # secinfoadm
  48. #iptables -A FORWARD -s 192.168.0.9/24 -p tcp --dport 1863 -j ACCEPT
  49. #iptables -A FORWARD -s 192.168.0.9/24 -d loginnet.passport.com -j ACCEPT
  50.  
  51. # ajudchf
  52. #iptables -A FORWARD -s 192.168.0.14/24 -p tcp --dport 1863 -j ACCEPT
  53. #iptables -A FORWARD -s 192.168.0.14/24 -d loginnet.passport.com -j ACCEPT
  54.  
  55. # ajud1
  56. #iptables -A FORWARD -s 192.168.0.16/24 -p tcp --dport 1863 -j ACCEPT
  57. #iptables -A FORWARD -s 192.168.0.16/24 -d loginnet.passport.com -j ACCEPT
  58.  
  59.  
  60.  
  61. #------------------- Bloqueando WebMensseger ------------------------------#
  62.  
  63. #iptables -A FORWARD -s 192.168.0.0/24 -d webmessenger.msn.com -j REJECT
  64.  
  65. #--------------- Hosts Liberados webmessenger -----------------------------#
  66.  
  67. # impressao
  68. #iptables -A FORWARD -s 192.168.0.3/24 -d webmessenger.msn.com -j ACCEPT
  69.  
  70. # secinfoweb
  71. #iptables -A FORWARD -s 192.168.0.5/24 -d webmessenger.msn.com -j ACCEPT
  72.  
  73. # secinfomnt
  74. #iptables -A FORWARD -s 192.168.0.7/24 -d webmessenger.msn.com -j ACCEPT
  75.  
  76. #secinfochf
  77. #iptables -A FORWARD -s 192.168.0.8/24 -d webmessenger.msn.com -j ACCEPT
  78.  
  79. #secinfoadm
  80. #iptables -A FORWARD -s 192.168.0.9/24 -d webmessenger.msn.com -j ACCEPT
  81.  
  82. #ajudchf
  83. #iptables -A FORWARD -s 192.168.0.14/24 -d webmessenger.msn.com -j ACCEPT
  84.  
  85. #ajud1
  86. #iptables -A FORWARD -s 192.168.0.16/24 -d webmessenger.msn.com -j ACCEPT
  87.  
  88. # Bloqueando os Demais webmessenger
  89. #iptables -A FORWARD -s 192.168.0.0/24 -d webmessenger.msn.com -j REJECT
  90.  
  91. ###############################################################################
  92. ###############################################################################
  93.  
  94.  
  95.  
  96.  
  97. #################################################################################
  98. #################################################################################
  99. # Abre uma porta (inclusive para a Internet)
  100. iptables -A INPUT -p tcp --dport 2631 -j ACCEPT
  101.  
  102. # Abre uma porta (inclusive para a Internet)
  103. iptables -A INPUT -p tcp --dport 21 -j ACCEPT
  104.  
  105. # Abre uma porta (inclusive para a Internet)
  106. iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  107.  
  108. # Abre uma porta (para acesso externo via ssh)
  109. iptables -A INPUT -p tcp -s 0/0 --dport 22 -j ACCEPT
  110.  
  111. # Abre uma porta (inclusive para a Internet)
  112. iptables -A INPUT -p tcp --dport 25 -j ACCEPT
  113.  
  114. # Abre uma porta (inclusive para a Internet)
  115. iptables -A INPUT -p tcp --dport 53 -j ACCEPT
  116. iptables -A INPUT -p udp --dport 53 -j ACCEPT
  117.  
  118. # Abre uma porta (inclusive para a Internet)
  119. iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  120.  
  121. # Abre uma porta (inclusive para a Internet)
  122. iptables -A INPUT -p tcp --dport 138 -j ACCEPT
  123.  
  124. # Abre uma porta (inclusive para a Internet)
  125. iptables -A INPUT -p tcp --dport 139 -j ACCEPT
  126.  
  127. # Abre uma porta (inclusive para a Internet)
  128. iptables -A INPUT -p tcp --dport 137 -j ACCEPT
  129.  
  130. # Abre uma porta (inclusive para a Internet)
  131. iptables -A INPUT -p tcp --dport 143 -j ACCEPT
  132.  
  133. # Abre uma porta (inclusive para a Internet)
  134. iptables -A INPUT -p tcp --dport 389 -j ACCEPT
  135.  
  136. # Abre uma porta (inclusive para a Internet)
  137. iptables -A INPUT -p tcp --dport 631 -j ACCEPT
  138. iptables -A INPUT -p udp --dport 631 -j ACCEPT
  139.  
  140. # Abre uma porta (inclusive para a Internet)
  141. iptables -A INPUT -p tcp --dport 110 -j ACCEPT
  142.  
  143. # Abre uma porta (inclusive para a Internet)
  144. iptables -A INPUT -p tcp --dport 1024 -j ACCEPT
  145.  
  146. # Abre uma porta (inclusive para a Internet)
  147. iptables -A INPUT -p tcp --dport 123 -j ACCEPT
  148.  
  149. # Abre uma porta (inclusive para a Internet)
  150. iptables -A INPUT -p tcp --dport 143 -j ACCEPT
  151.  
  152. # Abre uma porta (inclusive para a Internet)
  153. iptables -A INPUT -p tcp --dport 443 -j ACCEPT
  154. iptables -A INPUT -p udp --dport 443 -j ACCEPT
  155.  
  156. # Abre uma porta (inclusive para a Internet)
  157. iptables -A INPUT -p tcp --dport 1194 -j ACCEPT
  158.  
  159. # Abre uma porta (inclusive para a Internet)
  160. iptables -A INPUT -p tcp --dport 5901 -j ACCEPT
  161.  
  162. # Abre uma porta (inclusive para a Internet)
  163. iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  164.  
  165. # Abre uma porta (inclusive para a Internet)
  166. iptables -A INPUT -p tcp --dport 53 -j ACCEPT
  167. iptables -A INPUT -p udp --dport 53 -j ACCEPT
  168.  
  169. # Abre uma porta (inclusive para a Internet)
  170. iptables -A INPUT -p tcp --dport 1080 -j ACCEPT
  171.  
  172. # Abre uma porta (inclusive para a Internet)
  173. iptables -A INPUT -p tcp --dport 1028 -j ACCEPT
  174.  
  175. # Abre uma porta (inclusive para a Internet)
  176. iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
  177.  
  178. # Abre uma porta (inclusive para a Internet)
  179. iptables -A INPUT -p udp --dport 1701 -j ACCEPT
  180.  
  181. # Abre uma porta (inclusive para a Internet)
  182. iptables -A INPUT -p tcp --dport 47 -j ACCEPT
  183. iptables -A INPUT -p udp --dport 47 -j ACCEPT
  184.  
  185. # -------------------- SERPRO
  186. # Abre uma porta (inclusive para a Internet)
  187. iptables -A INPUT -p tcp --dport 23 -j ACCEPT
  188. iptables -A OUTPUT -p tcp --dport 23 -j ACCEPT
  189.  
  190. # Abre uma porta (inclusive para a Internet)
  191. iptables -A INPUT -p tcp --dport 8999 -j ACCEPT
  192. iptables -A OUTPUT -p tcp --dport 8999 -j ACCEPT
  193.  
  194. # Abre uma porta (inclusive para a Internet)
  195. iptables -A INPUT -p tcp --dport 23000 -j ACCEPT
  196. iptables -A OUTPUT -p tcp --dport 23000 -j ACCEPT
  197. # --------------------
  198.  
  199. # Abre uma porta (inclusive para a Internet)
  200. iptables -A INPUT -p tcp --dport 1863 -j ACCEPT
  201.  
  202. # Abre uma porta (inclusive para a Internet)
  203. iptables -A INPUT -p tcp --dport 2631 -j ACCEPT
  204.  
  205. # Abre uma porta (inclusive para a Internet)
  206. iptables -A INPUT -p udp --dport 67 -j ACCEPT
  207.  
  208. # Abre uma porta (inclusive para a Internet)
  209. iptables -A INPUT -p udp --dport 3456 -j ACCEPT
  210.  
  211. # Abre uma porta (inclusive para a Internet)
  212. iptables -A INPUT -p udp --dport 465 -j ACCEPT
  213.  
  214. # Abre uma porta (inclusive para a Internet)
  215. iptables -A INPUT -p udp --dport 955 -j ACCEPT
  216.  
  217. # Ignora pings
  218. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  219. # Protecao contra IP spoofing
  220. echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
  221.  
  222. # Protege contra synflood
  223. echo "1" > /proc/sys/net/ipv4/tcp_syncookies
  224.  
  225. # Protecao contra ICMP Broadcasting
  226. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
  227.  
  228. # Bloqueia traceroute
  229. iptables -A INPUT -p udp --dport 33435:33525 -j DROP
  230.  
  231.  
  232. # Protecoes diversas contra portscanners, ping of death, ataques DoS, etc.
  233. iptables -A INPUT -m state --state INVALID -j DROP
  234.  
  235.  
  236. # Abre para a interface de loopback.
  237. # Esta regra e essencial para o KDE e outros programas graficos funcionarem adequadamente.
  238. iptables -A INPUT -i lo -j ACCEPT
  239.  
  240.  
  241. # Fecha as portas udp de 1 a 1024
  242. iptables -A INPUT -p udp --dport 1:1024 -j DROP
  243. iptables -A INPUT -p udp --dport 59229 -j DROP
  244.  
  245.  
  246.  
  247. # Esta regra e o coracao do firewall do Debian-Lenny,
  248. # ela bloqueia qualquer conexao que nao tenha sido permitida acima, justamente por isso ela e a ultima da cadeia.
  249. iptables -A INPUT -p tcp --syn -j DROP
  250.  
  251. echo "O Firewall 62 BI esta sendo carregado..."
  252. sleep 1
  253. echo "Tudo pronto!"
  254. sleep 1
  255. }
  256. firewall_stop(){
  257. iptables -F
  258. iptables -X
  259. iptables -P INPUT ACCEPT
  260. iptables -P FORWARD ACCEPT
  261. iptables -P OUTPUT ACCEPT
  262. }
  263.  
  264. case "$1" in
  265. "start")
  266. firewall_start
  267. ;;
  268. "stop")
  269. firewall_stop
  270. echo "O Firewall 62 BI esta sendo desativado"
  271. sleep 2
  272. echo "ok."
  273. ;;
  274. "restart")
  275. echo "O Firewall 62 BI esta sendo desativado"
  276. sleep 1
  277. echo "ok."
  278. firewall_stop; firewall_start
  279. ;;
  280. *)
  281. iptables -L -n
  282. esac
Add Comment
Please, Sign In to add comment