当服务器受到攻击时,系统负载就会爆增,利用脚本自动检测系统负载,当压力超过一定的值时就可以切换为” I’m Under Attack! “模式了。操作步骤如下:
jboss-cli
1 2 3 4 5 6 7 8 9 10
#下载 cd/root && git clone https://github.com/Machou/Cloudflare-Block.git DDoS #打开Cloudflare.sh,修改配置 API_KEY You're Global API Key (https://dash.cloudflare.com/profile) MAIL_ACCOUNT Email of your Cloudflare account DOMAIN Zone ID (https://dash.cloudflare.com/_zone-id_/domain.com) #设置定时任务 crontab -e */1 * * * * /root/DDoS/Cloudflare.sh 0 # check every 1 minute if protection is not enabled */20 * * * * /root/DDoS/Cloudflare.sh 1 # check every 20 minutes if prot
完整源代码,脚本默认的是检测系统负载为 10,启动” I’m Under Attack! “模式,你以根据需要来调整。脚本如下:
# load is 10, you can modify this if you want load more than 10 maxload=10
# Configuration API Cloudflare # You're Global API Key (https://dash.cloudflare.com/profile) api_key= # Email of your account Cloudflare email= # Zone ID (https://dash.cloudflare.com/_zone-id_/domain.com) zone_id=
# create file attacking if doesn't exist if [ ! -e $attacking ]; then echo 0 > $attacking fi
attacking=./attacking
hasattack=$(cat$attacking)
if [ $(echo"$loadavg > $maxload"|bc) -eq 1 ]; then