上次朋友被DDOS了大约4天,被打了6T➕的流量:
朋友的环境CF免费套餐+杜甫;杜甫应该自带有部分防护,发现被DDOS后,检查了之前CF中的设置,果然是被D,以下为被打到后期的数量:
记录下我的操作
(1)CF中安全-WAF-自定义DDOS防御,威胁分数直接>7都属于,宁可误杀不放过
(2)针对DDOS来源地区,直接拒绝该地区访问
(3)通过CF的API获取捕获到的DDOS的来源IP,并添加到BT的黑名单管理中,并同时添加到CF列表拒绝中:
def dov6(ip):
url ='http://BT/plugin?action=a&name=btwaf&s=set_ipv6_back'
pdata='addr={}'.format(ip)
res =requests.post(url,data=pdata,headers=headers).json()
rr = "\tv6:"+ip+res["msg"]
tempstr=''
if "成功" in rr:
tempstr='\t\t\t-------------------------'
print(rr+tempstr)
def dov4(ip):
url ='http://BT/plugin?action=a&name=btwaf&s=add_ip_black'
pdata='start_ip={}&end_ip={}'.format(ip,ip)
res=requests.post(url,headers=headers,data=pdata).json()
rr = "\tv4:"+ip+res["msg"]
tempstr=''
if "成功" in rr:
tempstr='\t\t\t-------------------------'
print(rr+tempstr)
def start(oldtime,newtime):
num=5000
url ='https://api.cloudflare.com/client/v4/graphql'
//以下抓包获取即可,
pdata='{"operationName":"ActivityLogQuery","variables":{"accountTag":"**","zoneTag":"***"***************************************8888'
print('[+]',oldtime,newtime)
#print(json_data)
res= requests.post(url,headers=headersCF,data=pdata,verify=False).json()
res1 = (res["data"]["viewer"]["scope"][0]["activity"])
ips=[]
for i in res1:
#print(i["clientIP"])
ips.append(i["clientIP"])
#print(set(ips))
for ip in set(ips):
#print('\t'+ip)
if ":" in ip:
try:
dov6(ip)
except:
print('\t'+"error:v6:"+ip)
else:
try:
dov4(ip)
except:
print('\t'+"error:v4:"+ip)
CF请求时,需要带headers必备要素:
headersCF={
********************
'X-Auth-Key':'*****',
'X-Auth-Email':'******',
'Authorization':'Bearer ***',
********************
}
最后估计双方扛不住(不想僵持了),“友好结束” ;
最后CF是真牛逼!!!