security.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. clear
  3. if [[ "$EUID" -ne 0 ]]; then
  4. echo -e "\033[1;31mScript need to be run as root!\033[0m"; exit 1
  5. fi
  6. echo '/bin/false
  7. /usr/bin/false
  8. /usr/sbin/nologin' >> /etc/shells
  9. echo '# Configuration file for setting system variables
  10. kernel.printk = 3 4 1 3
  11. net.ipv4.conf.default.rp_filter=1
  12. net.ipv4.conf.all.rp_filter=1
  13. net.ipv4.ip_forward=1
  14. #net.ipv6.conf.all.forwarding=1
  15. net.ipv4.conf.all.accept_redirects = 0
  16. net.ipv6.conf.all.accept_redirects = 0
  17. fs.file-max = 51200
  18. net.core.rmem_max = 67108864
  19. net.core.wmem_max = 67108864
  20. net.core.netdev_max_backlog = 250000
  21. net.core.somaxconn = 4096
  22. net.ipv4.tcp_syncookies = 1
  23. net.ipv4.tcp_tw_reuse = 1
  24. # net.ipv4.tcp_tw_recycle = 0
  25. net.ipv4.tcp_fin_timeout = 30
  26. net.ipv4.tcp_keepalive_time = 1200
  27. net.ipv4.ip_local_port_range = 10000 65000
  28. net.ipv4.tcp_max_syn_backlog = 8192
  29. net.ipv4.tcp_max_tw_buckets = 5000
  30. net.ipv4.tcp_fastopen = 3
  31. net.ipv4.tcp_mem = 25600 51200 102400
  32. net.ipv4.tcp_rmem = 4096 87380 67108864
  33. net.ipv4.tcp_wmem = 4096 65536 67108864
  34. net.ipv4.tcp_mtu_probing = 1
  35. net.ipv4.tcp_congestion_control = hybla' > /etc/sysctl.conf
  36. sysctl -p &>/dev/null
  37. apt-get -y -qq install fail2ban
  38. cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
  39. # ddos-deflates
  40. apt-get -y -qq install dnsutils net-tools tcpdump dsniff grepcidr
  41. wget -q https://github.com/jgmdev/ddos-deflate/archive/master.zip -O /root/ddos.zip
  42. unzip /root/ddos.zip && rm /root/ddos.zip
  43. cd /root/ddos-deflate-master
  44. ./install.sh
  45. systemctl enable ddos
  46. systemctl start ddos
  47. # iptables rules
  48. iptables -F
  49. iptables -X
  50. iptables -Z
  51. iptables -A INPUT -i lo -j ACCEPT
  52. iptables -A OUTPUT -o lo -j ACCEPT
  53. iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  54. iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
  55. iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
  56. iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
  57. iptables -A INPUT -m string --string "BitTorrent" --algo bm --to 65535 -j DROP
  58. iptables -A INPUT -m string --string "BitTorrent protocol" --algo bm --to 65535 -j DROP
  59. iptables -A INPUT -m string --string "peer_id=" --algo bm --to 65535 -j DROP
  60. iptables -A INPUT -m string --string ".torrent" --algo bm --to 65535 -j DROP
  61. iptables -A INPUT -m string --string "announce.php?passkey=" --algo bm --to 65535 -j DROP
  62. iptables -A INPUT -m string --string "torrent" --algo bm --to 65535 -j DROP
  63. iptables -A INPUT -m string --string "announce" --algo bm --to 65535 -j DROP
  64. iptables -A INPUT -m string --string "info_hash" --algo bm --to 65535 -j DROP
  65. iptables -A INPUT -m string --string "get_peers" --algo bm --to 65535 -j DROP
  66. iptables -A INPUT -m string --string "find_node" --algo bm --to 65535 -j DROP
  67. iptables-save > /etc/firewall.conf
  68. iptables-restore < /etc/firewall.conf
  69. cat > /etc/cron.d/firewall <<EOL
  70. reboot root iptables-restore < /etc/firewall.conf
  71. EOL
  72. DEBIAN_FRONTEND=noninteractive apt-get -y -qq install iptables-persistent
  73. echo
  74. echo -e "\033[1;32mTahniah, Kami telah selesai dengan pemasangan fail2ban, ddos-deflate & Firewall.\033[0m"
  75. echo
  76. echo 'Use my referral link https://m.do.co/c/a28a40414d6a'
  77. echo 'to gets $100 credit into your DigitalOcean account.'
  78. echo
  79. echo 'Hak Cipta 2021 Doctype, Dikuasakan oleh Cybertize.'
  80. sleep 5