Bài viết này mình xin chia sẻ một đoạn shell chống ddos trên server họ linux. Dạo rùi server chạy dịch vụ web bên mình lượng ip connect tới lên tới hơn 12 nghìn ip. => chắc mẩm bị ddos server ssh rất chậm có khi treo và mình đã thử với cách trình bày bên dưới đây và đạt hiệu quả tức thì. Câu lệnh kiểm tra lượng ip đang kết nối port 80 server: netstat -an|grep 80|wc -l Với trường hợp của mình số ip connect tới port 80 lên trên 12k.
Xử lý: cd /usr/local
mkdir ddos
cd ddos
Tạo các file sau: 1. ddos.conf
Nội dung:
##### Paths of the script and other files PROGDIR="/usr/local/ddos" PROG="/usr/local/ddos/ddos.sh" IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list" CRON="/etc/cron.d/ddos.cron" APF="/etc/apf/apf" IPT="/sbin/iptables"
##### frequency in minutes for running the script ##### Caution: Every time this setting is changed, run the script with --cron ##### option so that the new frequency takes effect FREQ=1
##### How many connections define a bad IP? Indicate that below. NO_OF_CONNECTIONS=150
##### APF_BAN=1 (Make sure your APF version is atleast 0.96) ##### APF_BAN=0 (Uses iptables for banning ips instead of APF) APF_BAN=1
##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script) ##### KILL=1 (Recommended setting) KILL=1
##### An email is sent to the following address when an IP is banned. ##### Blank would suppress sending of mails EMAIL_TO="root"
##### Number of seconds the banned ip should remain in blacklist. BAN_PERIOD=600 2. ignore.ip.list
Nội dung:
127.0.0.1
3.ddos.sh #!/bin/sh################################################ ############################## # DDoS-Deflate version 0.6 Author: Zaf <zaf@vsnl.com> # ################################################## ############################ # This program is distributed under the "Artistic License" Agreement # # # # The LICENSE file is located in the same directory as this program. Please # # read the LICENSE file before you make copies or distribute this program # ################################################## ############################ load_conf() { CONF="/usr/local/ddos/ddos.conf" if [ -f "$CONF" ] && [ ! "$CONF" == "" ]; then source $CONF else head echo "\$CONF not found." exit 1 fi }
showhelp() { head echo 'Usage: ddos.sh [OPTIONS] [N]' echo 'N : number of tcp/udp connections (default 150)' echo 'OPTIONS:' echo '-h | --help: Show this help screen' echo '-c | --cron: Create cron job to run this script regularly (default 1 mins)' echo '-k | --kill: Block the offending ip making more than N connections' }
Mọi bình luận sai nội quy sẽ bị xóa mà không cần báo trước (xem nội quy)
Bấm Thông báo cho tôi bên dưới khung bình luận để nhận thông báo khi admin trả lời
Để bình luận một đoạn code, hãy mã hóa code trước nhé
Về Plus Thủ Thuật
Được thành lập vào ngày 5/3/2017, Plus Thủ Thuật (PTT) là Blog tổng hợp chia sẻ PSD, PSD Facebook, thủ thuật Blogspot, Facebook, máy tính, thủ thuật mạng, công nghệ web và nhiều tiện ích, thủ thuật khác...
Blog hoạt động với mục đích chia sẻ, học hỏi, trao đổi kinh nghiệm nên trong thời gian blog hoạt động mong các bạn luôn ủng hộ PLus Thủ Thuật để blog ngày càng phát triển!
TP.Huế, Việt Nam
0126 654 7401
plusthuthuat@gmail.com
fb.com/HoangHien.Offical.Account
Liên hệ, góp ý, báo lỗi, hợp tác hoặc quảng cáo tại đây
BÌNH LUẬN (0)
Một số lưu ý khi bình luận
Mọi bình luận sai nội quy sẽ bị xóa mà không cần báo trước (xem nội quy)
Bấm Thông báo cho tôi bên dưới khung bình luận để nhận thông báo khi admin trả lời
Để bình luận một đoạn code, hãy mã hóa code trước nhé