Advertisement
MagnusArias

ZBWSK dialog-iptables

Oct 11th, 2017
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. #!/bin/bash
  2. INPUT=/tmp/menu.sh.$$
  3. OUTPUT=/tmp/output.sh.$$
  4. OUTPUT2=/tmp/output2.sh.$$
  5. OUTPUT3=/tmp/output3.sh.$$
  6.  
  7. while [ true ]; do
  8. dialog --title "iptables - mgmt" \
  9. --menu "Select table:" 40 80 25 \
  10. 1 "* Wyświetl reguły dla wybranego łancucha"\
  11. 2 "* Stwórz nowy łańcuch"\
  12. 3 "* Stwórz nowy łańcuch w wybranej tablicy"\
  13. 4 "* Zablokuj adres IP w godzinach 17-22" \
  14. 5 "* Proxy dla całej sieci na wybranym porcie" \
  15. 6 "* Przekieruj port \"XXX\" dla wybranego IP"\
  16. 7 "* Zablokuj wybrany adres MAC" \
  17. 8 "* Zablokuj wybrany adres IP" \
  18. 9 "* Ogranicz ilość połączeń" \
  19. 10 "* Zablokuj porty 600-800 dla wybranego adresu IP" \
  20. 11 "* Zablokuj możliwość dalszego udostępniania dla wybranego IP" \
  21. 12 "* Zablokuj możliwość dalszego udostępniania dla całej sieci" \
  22. 13 "* Otwórz port \"xxxx\" na interfejsie eth0" \
  23. 14 "* Zablokuj wysyłanie poczty na porcie 25 dla wybranego IP" \
  24. 15 "* Przekieruj wszystkie porty na wirtualny serwer www BLOKADA" \
  25. 16 "* Zablokuj wybraną witrynę" \
  26. 17 "* Zablokuj pulę wybranych publicznych adresów IP" \
  27. 18 "Wyczyść reguły ze wszystkich tablic" \
  28. 19 "Usuń utworzone łańcuchy" \
  29. 20 "Zmień politykę dla ruchu wchodzącego na DROP" \
  30. 21 "Zezwól na połączenia ICMP" \
  31. 22 "Zezwól na ruch wchodzący inicjowany lokalnie" \
  32. 23 "Zezwól na ruch do Twojego serwera WWW" \
  33. 24 "Zezwól na ruch do Twojego serwera FTP" \
  34. 25 "Zezwól na wchodzące połączenia SMTP" \
  35. EXIT "Wyjdź z menu" \
  36. 2>"${INPUT}"
  37.  
  38. menuitem=$(<"${INPUT}")
  39.  
  40. case $menuitem in
  41. 0) clear && echo "Canceled" ;;
  42.  
  43. 1) dialog --inputbox "Wpisz nazwę: (pozostaw puste, jeśli chcesz wyświetlić wszystkie)" 8 40 2>"${OUTPUT}"
  44. clear
  45. iptables -L $(<"${OUTPUT}") ;;
  46.  
  47. 2) dialog --inputbox "Wpisz nazwę dla nowego łańcucha" 8 40 2>"${OUTPUT}"
  48. clear
  49. iptables -N $(<"${OUTPUT}")
  50. iptables -L ;;
  51.  
  52. 3) dialog --inputbox "Podaj tablicę" 8 40 2>"${OUTPUT}"
  53. dialog --inputbox "Wpisz nazwę dla nowego łańcucha" 8 40 2>"${OUTPUT2}"
  54. clear
  55. iptables -t $(<"${OUTPUT}") -N $(<"${OUTPUT2}")
  56. iptables -t $(<"${OUTPUT}") -L ;;
  57.  
  58. 4) dialog --inputbox "Podaj adress IP" 8 40 2>"${OUTPUT}"
  59. clear
  60. iptables -I FORWARD -s $(<"${OUTPUT}") -m time --timestart 17:00 --timestop 22:00 -j DROP
  61. iptables -L FORWARD ;;
  62.  
  63. 5) dialog --inputbox "Wybierz port" 8 40 2>"${OUTPUT}"
  64. clear
  65. iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port $(<"${OUTPUT}")
  66. iptables -t nat -L PREROUTING ;;
  67.  
  68. 6) dialog --inputbox "Podaj adres IP" 8 40 2>"${OUTPUT}"
  69. dialog --inputbox "Podaj port" 8 40 2>"${OUTPUT2}"
  70. clear
  71. iptables -I FORWARD -p tcp -d $(<"${OUTPUT}") --dport $(<"${OUTPUT2}") -j ACCEPT
  72. iptables -t nat -A PREROUTING -p tcp -i eth0 --dport $(<"${OUTPUT2}") -j DNAT --to $(<"${OUTPUT}");;
  73.  
  74. 7) dialog --inputbox "Podaj MAC address (format- aa:bb:cc:dd:ee:ff)" 8 40 2>"${OUTPUT}"
  75. clear
  76. iptables -A INPUT -m mac --mac-source $(<"${OUTPUT}") -j DROP
  77. iptables -A FORWARD -m mac --mac-source $(<"${OUTPUT}") -j DROP
  78. iptables -L INPUT
  79. iptables -L FORWARD ;;
  80.  
  81. 8) dialog --inputbox "Podaj adres IP" 8 40 2>"${OUTPUT}"
  82. clear
  83. iptables -A INPUT -s $(<"${OUTPUT}") -j DROP
  84. iptables -A FORWARD -s $(<"${OUTPUT}") -j DROP
  85. iptables -A INPUT -d $(<"${OUTPUT}") -j DROP
  86. iptables -A FORWARD -d $(<"${OUTPUT}") -j DROP
  87. iptables -L INPUT
  88. iptables -L FORWARD ;;
  89.  
  90. 9) dialog --inputbox "Wpisz górny limit połączeń" 8 40 2>"${OUTPUT}"
  91. clear
  92. iptables -A FORWARD -p tcp -m connlimit --connlimit-above $(<"${OUTPUT}") --connlimit-mask 32 -j DROP
  93. iptables -L FORWARD ;;
  94.  
  95. 10) dialog --inputbox "Podaj adres IP " 8 40 2>"${OUTPUT}"
  96. dialog --inputbox "Podaj dolny zakres" 8 40 2>"${OUTPUT2}"
  97. dialog --inputbox "Podaj górny zakres" 8 40 2>"${OUTPUT3}"
  98. clear
  99. iptables -I FORWARD -s $(<"${OUTPUT}") -p tcp --dport $(<"${OUTPUT2}"):$(<"${OUTPUT3}") -j DROP
  100. iptables -I FORWARD -s $(<"${OUTPUT}") -p udp --dport $(<"${OUTPUT2}"):$(<"${OUTPUT3}") -j DROP
  101. iptables -L FORWARD ;;
  102.  
  103. 11) dialog --inputbox "Podaj adres IP" 8 40 2>"${OUTPUT}"
  104. clear
  105. iptables -t mangle -A POSTROUTING -d $(<"${OUTPUT}") -j TTL --ttl-set 1
  106. iptables -t mangle -L POSTROUTING ;;
  107.  
  108. 12) clear
  109. iptables -t mangle -A POSTROUTING -o eth1 -j TTL --ttl-set 1
  110. iptables -t mangle -L POSTROUTING ;;
  111.  
  112. 13) dialog --inputbox "Wybierz port do zablokowania (eth0)" 8 40 2>"${OUTPUT}"
  113. clear
  114. iptables -A INPUT -p tcp -i eth0 --dport $(<"${OUTPUT}") -j ACCEPT
  115. iptables -L INPUT ;;
  116.  
  117. 14) dialog --inputbox "Wpisz IP" 8 40 2>"${OUTPUT}"
  118. clear
  119. iptables -I FORWARD -p tcp --dport 25 -s $(<"${OUTPUT}") -j DROP
  120. iptables -L FORWARD ;;
  121.  
  122. 15) clear
  123. iptables -A PREROUTING -t nat -s 192.168.1.12 -p tcp --dport 1:65535 -j DNAT --to- 192.168.1.1:83
  124. iptables -L PREROUTING ;;
  125.  
  126. 16) dialog --inputbox "Wpisz nazwę domeny" 8 40 2>"${OUTPUT}"
  127. clear
  128. iptables -A OUTPUT -m string --algo bm --string $(<"${OUTPUT}") -j DROP
  129. iptables -L OUTPUT ;;
  130.  
  131. 17) dialog --inputbox "Wpisz dolny zakres" 8 40 2>"${OUTPUT}"
  132. dialog --inputbox "Wpisz górny zakres" 8 40 2>"${OUTPUT2}"
  133. clear
  134. iptables -I FORWARD -m iprange --dst-rang $(<"${OUTPUT}")-$(<"${OUTPUT2}") -j DROP
  135. iptables -L FORWARD ;;
  136.  
  137. 18) iptables -F;;
  138.  
  139. 19) dialog --inputbox "Wpisz nazwę tablicy" 8 40 2>"${OUTPUT}"
  140. dialog --inputbox "Wpisz nazwę łańcucha do usunięcia" 8 40 2>"${OUTPUT2}"
  141. clear
  142. iptables -t $(<"${OUTPUT}") -F $(<"${OUTPUT2}") ;;
  143.  
  144. 20) clear
  145. iptables -A OUTPUT -p tcp -j DROP
  146. iptables -L OUTPUT ;;
  147.  
  148. 21) echo "21" ;;
  149.  
  150. 22) echo "22" ;;
  151.  
  152. 23) echo "23" ;;
  153.  
  154. 24) echo "24" ;;
  155.  
  156. 25) clear
  157. iptables -A OUTPUT -p tcp --sport 25 -j ACCEPT
  158. iptables -A OUTPUT -p tcp --sport 587 -j ACCEPT
  159. iptables -L OUTPUT;;
  160.  
  161. EXIT) clear
  162. exit 0 ;;
  163. *) clear
  164. exit 0 ;;
  165. esac
  166. sleep 5;
  167. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement