Cloudflare切换5秒盾脚本防CC攻击

作者:老刘 发布时间:November 30, 2018 分类:学习笔记 阅读次数:115

5秒盾是cloudflare防CC攻击的最佳手段
当使用Cloudflare被攻击时,可以使用这个脚本直接切换到5秒盾

下载脚本后,按说明配置后,可以运行

STEP 1 配置脚本里面的API

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)

STEP 2 设置计划任务
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 protection is enabled

脚本备份

#!/bin/bash


# $1 = 1min, $2 = 5min, $3 = 15min
loadavg=$(cat /proc/loadavg|awk '{printf "%f", $1}')


# 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

	if [[ $hasattack = 0 && $1 = 0 ]]; then

		# Active protection
		echo 1 > $attacking
		curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$zone_id/settings/security_level" \
						-H "X-Auth-Email: $email" \
						-H "X-Auth-Key: $api_key" \
						-H "Content-Type: application/json" \
						--data '{"value":"under_attack"}'
	fi

	else
		if [[ $hasattack = 1 && $1 = 1 ]]; then

		# Disable Protection
		echo 0 > $attacking
		curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$zone_id/settings/security_level" \
						-H "X-Auth-Email: $email" \
						-H "X-Auth-Key: $api_key" \
						-H "Content-Type: application/json" \
						--data '{"value":"high"}'
	fi
fi

exit 0

来源: https://github.com/Machou/Cloudflare-Block

标签: 脚本, cloudflare, cc, 攻击

前一篇:centos6升级GCC版本到4.8.5

后一篇:udpspeederV2+udp2raw串联加速UDP网络访问

添加新评论 »